Merge pull request #6099 from turbo124/v5-develop

Set Exchange Rates on invoice when marked as paid
This commit is contained in:
David Bomba 2021-06-22 11:24:29 +10:00 committed by GitHub
commit ceefde5378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 9 deletions

View File

@ -28,6 +28,7 @@ class CompanySettings extends BaseSettings
public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented
public $enable_client_portal_tasks = false; //@ben to implement
public $show_all_tasks_client_portal = 'all'; // all, uninvoiced, invoiced
public $enable_client_portal_password = false; //@implemented
public $enable_client_portal = true; //@implemented
public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending
@ -268,6 +269,7 @@ class CompanySettings extends BaseSettings
public $hide_empty_columns_on_pdf = false;
public static $casts = [
'show_all_tasks_client_portal' => 'string',
'entity_send_time' => 'int',
'shared_invoice_credit_counter' => 'bool',
'reply_to_name' => 'string',

View File

@ -1,5 +1,4 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
@ -98,6 +97,7 @@ class StripeConnectController extends BaseController
$company_gateway->gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34';
$company_gateway->fees_and_limits = $fees_and_limits;
$company_gateway->setConfig([]);
$company_gateway->token_billing = 'always';
// $company_gateway->save();
$payload = [

View File

@ -29,7 +29,6 @@ class StripeController extends BaseController
}
return response()->json(['message' => 'Unauthorized'], 403);
}
@ -44,7 +43,6 @@ class StripeController extends BaseController
return response()->json(['message' => 'Processing'], 200);
}
return response()->json(['message' => 'Unauthorized'], 403);
}

View File

@ -1,5 +1,4 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*

View File

@ -105,6 +105,7 @@ class WepaySignup extends Component
$cg->update_details = false;
$cg->config = encrypt(config('ninja.testvars.checkout'));
$cg->fees_and_limits = $fees_and_limits;
$cg->token_billing = 'always';
$cg->save();
}

View File

@ -55,8 +55,15 @@ class QueryLogging
//nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time);
// if($count > 50)
//nlog($queries);
$ip = '';
LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, request()->ip()))
if(request()->header('Cf-Connecting-Ip'))
$ip = request()->header('Cf-Connecting-Ip');
else{
$ip = request()->ip();
}
LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, $ip))
->batch();
}

View File

@ -43,7 +43,7 @@ class RecurringInvoicesCron
nlog("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s'));
if (! config('ninja.db.multi_db_enabled')) {
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now())
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date')
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('remaining_cycles', '!=', '0')
@ -64,7 +64,7 @@ class RecurringInvoicesCron
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now())
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date')
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('remaining_cycles', '!=', '0')

View File

@ -55,7 +55,7 @@ class ReminderJob implements ShouldQueue
{
nlog("Sending invoice reminders " . now()->format('Y-m-d h:i:s'));
Invoice::whereDate('next_send_date', '<=', now())
Invoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
->where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0)

View File

@ -1,5 +1,4 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*

View File

@ -16,12 +16,14 @@ use App\Events\Payment\PaymentWasCreated;
use App\Factory\PaymentFactory;
use App\Jobs\Invoice\InvoiceWorkflowSettings;
use App\Jobs\Payment\EmailPayment;
use App\Libraries\Currency\Conversion\CurrencyApi;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\AbstractService;
use App\Services\Client\ClientService;
use App\Utils\Ninja;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Support\Carbon;
class MarkPaid extends AbstractService
{
@ -63,6 +65,8 @@ class MarkPaid extends AbstractService
/* Create a payment relationship to the invoice entity */
$payment->save();
$this->setExchangeRate($payment);
$payment->invoices()->attach($this->invoice->id, [
'amount' => $payment->amount,
]);
@ -70,6 +74,7 @@ class MarkPaid extends AbstractService
$this->invoice->next_send_date = null;
$this->invoice->service()
->setExchangeRate()
->updateBalance($payment->amount * -1)
->updatePaidToDate($payment->amount)
->setStatus(Invoice::STATUS_PAID)
@ -96,4 +101,22 @@ class MarkPaid extends AbstractService
return $this->invoice;
}
private function setExchangeRate(Payment $payment)
{
$client_currency = $payment->client->getSetting('currency_id');
$company_currency = $payment->client->company->settings->currency_id;
if ($company_currency != $client_currency) {
$exchange_rate = new CurrencyApi();
$payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date));
$payment->exchange_currency_id = $client_currency;
$payment->save();
}
}
}