From 28c44c03f6dbb1f9702ea8f73cdf9cd06076b709 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 28 Feb 2020 15:51:33 +0300 Subject: [PATCH] monitor default currency --- app/Jobs/Setting/DeleteCurrency.php | 8 +++++++- app/Jobs/Setting/UpdateCurrency.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Setting/DeleteCurrency.php b/app/Jobs/Setting/DeleteCurrency.php index 0c0c56cc9..7ea36011f 100644 --- a/app/Jobs/Setting/DeleteCurrency.php +++ b/app/Jobs/Setting/DeleteCurrency.php @@ -56,6 +56,12 @@ class DeleteCurrency extends Job 'transactions' => 'transactions', ]; - return $this->countRelationships($this->currency, $rels); + $relationships = $this->countRelationships($this->currency, $rels); + + if ($this->currency->code == setting('default.currency')) { + $relationships[] = strtolower(trans_choice('general.companies', 1)); + } + + return $relationships; } } diff --git a/app/Jobs/Setting/UpdateCurrency.php b/app/Jobs/Setting/UpdateCurrency.php index 056283299..b11410436 100644 --- a/app/Jobs/Setting/UpdateCurrency.php +++ b/app/Jobs/Setting/UpdateCurrency.php @@ -32,8 +32,19 @@ class UpdateCurrency extends Job { $this->authorize(); + // Force the rate to be 1 for default currency + if ($this->request->get('default_currency')) { + $this->request['rate'] = '1'; + } + $this->currency->update($this->request->all()); + // Update default currency setting + if ($this->request->get('default_currency')) { + setting()->set('default.currency', $this->request->get('code')); + setting()->save(); + } + return $this->currency; }