Reconciliations multi currency and calculate fixed.

This commit is contained in:
Cüneyt Şentürk
2020-06-08 19:08:13 +03:00
parent a884e06b72
commit d4923b4414
7 changed files with 118 additions and 37 deletions

View File

@ -96,6 +96,28 @@ class Transaction extends Model
return $query->whereIn($this->table . '.type', (array) $types);
}
/**
* Scope to include only income.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIncome($query)
{
return $query->where($this->table . '.type', '=', 'income');
}
/**
* Scope to include only expense.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeExpense($query)
{
return $query->where($this->table . '.type', '=', 'expense');
}
/**
* Get only transfers.
*
@ -196,6 +218,11 @@ class Transaction extends Model
return $query->where('reconciled', 0);
}
public function onCloning($src, $child = null)
{
$this->document_id = null;
}
/**
* Convert amount to double.
*
@ -218,6 +245,23 @@ class Transaction extends Model
$this->attributes['currency_rate'] = (double) $value;
}
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function getPriceAttribute($value)
{
if ($this->account->currency_code != $this->currency_code) {
$this->default_currency_code = $this->account->currency_code;
return $this->convertFromDefault($this->amount, $this->currency_code, $this->currency_rate);
}
return $this->amount;
}
/**
* Get the current balance.
*