From b0843151b1bc0d20bb10dd5dfa2e442f7c65d7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Wed, 10 Jun 2020 16:29:55 +0300 Subject: [PATCH] formatting --- app/Abstracts/DocumentModel.php | 6 +++++- app/Models/Banking/Transaction.php | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Abstracts/DocumentModel.php b/app/Abstracts/DocumentModel.php index 2bb94e137..7d76b08c3 100644 --- a/app/Abstracts/DocumentModel.php +++ b/app/Abstracts/DocumentModel.php @@ -87,11 +87,15 @@ abstract class DocumentModel extends Model return false; } + static $currencies; + $paid = 0; $reconciled = $reconciled_amount = 0; if ($this->transactions->count()) { - $currencies = Currency::enabled()->pluck('rate', 'code')->toArray(); + if (empty($currencies)) { + $currencies = Currency::enabled()->pluck('rate', 'code')->toArray(); + } foreach ($this->transactions as $item) { if ($this->currency_code == $item->currency_code) { diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 99bc0d84b..a949878d4 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -4,12 +4,12 @@ namespace App\Models\Banking; use App\Abstracts\Model; use App\Models\Setting\Category; +use App\Models\Setting\Currency; use App\Traits\Currencies; use App\Traits\DateTime; use App\Traits\Media; use App\Traits\Recurring; use Bkwld\Cloner\Cloneable; -use Date; class Transaction extends Model { @@ -40,8 +40,6 @@ class Transaction extends Model */ public $cloneable_relations = ['recurring']; - public static $currencies; - public function account() { return $this->belongsTo('App\Models\Banking\Account')->withDefault(['name' => trans('general.na')]); @@ -254,14 +252,16 @@ class Transaction extends Model */ public function getPriceAttribute() { - if (empty($this->currencies)) { - $this->currencies = \App\Models\Setting\Currency::enabled()->pluck('rate', 'code')->toArray(); - } + static $currencies; $amount = $this->amount; // Convert amount if not same currency if ($this->account->currency_code != $this->currency_code) { + if (empty($currencies)) { + $currencies = Currency::enabled()->pluck('rate', 'code')->toArray(); + } + $default_currency = setting('default.currency', 'USD'); $default_amount = $this->amount; @@ -282,7 +282,7 @@ class Transaction extends Model $transfer_amount->default_currency_code = $this->currency_code; $transfer_amount->amount = $default_amount; $transfer_amount->currency_code = $this->account->currency_code; - $transfer_amount->currency_rate = $this->currencies[$this->account->currency_code]; + $transfer_amount->currency_rate = $currencies[$this->account->currency_code]; $amount = $transfer_amount->getAmountConvertedFromDefault(); }