refactored calculations
This commit is contained in:
@ -250,41 +250,16 @@ class Transaction extends Model
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPriceAttribute()
|
||||
public function getAmountForAccountAttribute()
|
||||
{
|
||||
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();
|
||||
}
|
||||
$to_code = $this->account->currency_code;
|
||||
$to_rate = config('money.' . $this->account->currency_code . '.rate');
|
||||
|
||||
$default_currency = setting('default.currency', 'USD');
|
||||
|
||||
$default_amount = $this->amount;
|
||||
|
||||
if ($default_currency != $this->currency_code) {
|
||||
$default_amount_model = new Transaction();
|
||||
|
||||
$default_amount_model->default_currency_code = $default_currency;
|
||||
$default_amount_model->amount = $this->amount;
|
||||
$default_amount_model->currency_code = $this->currency_code;
|
||||
$default_amount_model->currency_rate = $this->currency_rate;
|
||||
|
||||
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
$transfer_amount = new Transaction();
|
||||
|
||||
$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 = $currencies[$this->account->currency_code];
|
||||
|
||||
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||
$amount = $this->convertBetween($amount, $this->currency_code, $this->currency_rate, $to_code, $to_rate);
|
||||
}
|
||||
|
||||
return $amount;
|
||||
|
Reference in New Issue
Block a user