From 60daf3d3fcc648a5d83d545e5d62633767dcf900 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Jul 2023 15:22:12 +1000 Subject: [PATCH] Force exchange rates --- app/DataMapper/Tax/AU/Rule.php | 2 +- app/Models/Client.php | 26 +++++++++++-------- app/Repositories/BaseRepository.php | 1 + app/Services/Invoice/InvoiceService.php | 4 +-- .../Export/ProfitAndLossReportTest.php | 2 -- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/DataMapper/Tax/AU/Rule.php b/app/DataMapper/Tax/AU/Rule.php index 8150f3e96c..aa11658ae1 100644 --- a/app/DataMapper/Tax/AU/Rule.php +++ b/app/DataMapper/Tax/AU/Rule.php @@ -251,7 +251,7 @@ class Rule extends BaseRule implements RuleInterface // } $this->tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate; - $this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate; + $this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate; return $this; diff --git a/app/Models/Client.php b/app/Models/Client.php index 5896488cce..6ed484be32 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -11,21 +11,22 @@ namespace App\Models; +use App\Utils\Traits\AppSetup; +use App\Utils\Traits\MakesHash; +use App\Utils\Traits\MakesDates; +use App\DataMapper\FeesAndLimits; +use App\Models\Traits\Excludable; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; -use App\DataMapper\FeesAndLimits; -use App\Models\Presenters\ClientPresenter; -use App\Models\Traits\Excludable; -use App\Services\Client\ClientService; -use App\Utils\Traits\AppSetup; -use App\Utils\Traits\ClientGroupSettingsSaver; -use App\Utils\Traits\GeneratesCounter; -use App\Utils\Traits\MakesDates; -use App\Utils\Traits\MakesHash; -use Illuminate\Contracts\Translation\HasLocalePreference; -use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Cache; +use App\Services\Client\ClientService; +use App\Utils\Traits\GeneratesCounter; use Laracasts\Presenter\PresentableTrait; +use App\Models\Presenters\ClientPresenter; +use Illuminate\Database\Eloquent\SoftDeletes; +use App\Utils\Traits\ClientGroupSettingsSaver; +use App\Libraries\Currency\Conversion\CurrencyApi; +use Illuminate\Contracts\Translation\HasLocalePreference; /** * App\Models\Client @@ -820,6 +821,9 @@ class Client extends BaseModel implements HasLocalePreference $defaults['public_notes'] = $this->public_notes; } + $exchange_rate = new CurrencyApi(); + $defaults['exchange_rate'] = 1/$exchange_rate->exchangeRate($this->getSetting('currency_id'), $this->company->settings->currency_id); + return $defaults; } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 15c93b5fe5..13df4b4d84 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -165,6 +165,7 @@ class BaseRepository if (! $model->id) { $company_defaults = $client->setCompanyDefaults($data, lcfirst($resource)); + $data['exchange_rate'] = $company_defaults['exchange_rate']; $model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes'); $data = array_merge($company_defaults, $data); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index d5a0715ee7..fa4fb40361 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -78,9 +78,9 @@ class InvoiceService * Sets the exchange rate on the invoice if the client currency * is different to the company currency. */ - public function setExchangeRate() + public function setExchangeRate($force = false) { - if ($this->invoice->exchange_rate != 1) { + if ($this->invoice->exchange_rate != 1 || $force) { return $this; } diff --git a/tests/Feature/Export/ProfitAndLossReportTest.php b/tests/Feature/Export/ProfitAndLossReportTest.php index be680c1604..890848151f 100644 --- a/tests/Feature/Export/ProfitAndLossReportTest.php +++ b/tests/Feature/Export/ProfitAndLossReportTest.php @@ -194,8 +194,6 @@ class ProfitAndLossReportTest extends TestCase $this->account->delete(); - - } public function testSimpleInvoiceIncome()