formatting
This commit is contained in:
parent
8b7ee416a6
commit
b0843151b1
@ -87,11 +87,15 @@ abstract class DocumentModel extends Model
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static $currencies;
|
||||||
|
|
||||||
$paid = 0;
|
$paid = 0;
|
||||||
$reconciled = $reconciled_amount = 0;
|
$reconciled = $reconciled_amount = 0;
|
||||||
|
|
||||||
if ($this->transactions->count()) {
|
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) {
|
foreach ($this->transactions as $item) {
|
||||||
if ($this->currency_code == $item->currency_code) {
|
if ($this->currency_code == $item->currency_code) {
|
||||||
|
@ -4,12 +4,12 @@ namespace App\Models\Banking;
|
|||||||
|
|
||||||
use App\Abstracts\Model;
|
use App\Abstracts\Model;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
use App\Models\Setting\Currency;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
use App\Traits\Media;
|
use App\Traits\Media;
|
||||||
use App\Traits\Recurring;
|
use App\Traits\Recurring;
|
||||||
use Bkwld\Cloner\Cloneable;
|
use Bkwld\Cloner\Cloneable;
|
||||||
use Date;
|
|
||||||
|
|
||||||
class Transaction extends Model
|
class Transaction extends Model
|
||||||
{
|
{
|
||||||
@ -40,8 +40,6 @@ class Transaction extends Model
|
|||||||
*/
|
*/
|
||||||
public $cloneable_relations = ['recurring'];
|
public $cloneable_relations = ['recurring'];
|
||||||
|
|
||||||
public static $currencies;
|
|
||||||
|
|
||||||
public function account()
|
public function account()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Banking\Account')->withDefault(['name' => trans('general.na')]);
|
return $this->belongsTo('App\Models\Banking\Account')->withDefault(['name' => trans('general.na')]);
|
||||||
@ -254,14 +252,16 @@ class Transaction extends Model
|
|||||||
*/
|
*/
|
||||||
public function getPriceAttribute()
|
public function getPriceAttribute()
|
||||||
{
|
{
|
||||||
if (empty($this->currencies)) {
|
static $currencies;
|
||||||
$this->currencies = \App\Models\Setting\Currency::enabled()->pluck('rate', 'code')->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
$amount = $this->amount;
|
$amount = $this->amount;
|
||||||
|
|
||||||
// Convert amount if not same currency
|
// Convert amount if not same currency
|
||||||
if ($this->account->currency_code != $this->currency_code) {
|
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_currency = setting('default.currency', 'USD');
|
||||||
|
|
||||||
$default_amount = $this->amount;
|
$default_amount = $this->amount;
|
||||||
@ -282,7 +282,7 @@ class Transaction extends Model
|
|||||||
$transfer_amount->default_currency_code = $this->currency_code;
|
$transfer_amount->default_currency_code = $this->currency_code;
|
||||||
$transfer_amount->amount = $default_amount;
|
$transfer_amount->amount = $default_amount;
|
||||||
$transfer_amount->currency_code = $this->account->currency_code;
|
$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();
|
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user