mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Set exchange rates on invoices/payments when marking as paid
This commit is contained in:
parent
f258ccec16
commit
823d23df24
@ -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',
|
||||
|
@ -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,
|
||||
]);
|
||||
@ -96,4 +100,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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user