diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index cbb75ee2291f..1d0e3b0ca559 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -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', diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index cb712890bc9a..df3cc60f8a7c 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -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(); + + } + + } }