Add "From/To Account Rate" fields in transfer create/edit page

This commit is contained in:
Cüneyt Şentürk
2021-03-18 20:00:55 +03:00
parent 84e0e51620
commit a9ab37d4dd
7 changed files with 149 additions and 15 deletions

View File

@ -38,11 +38,11 @@ class UpdateTransfer extends Job
public function handle()
{
\DB::transaction(function () {
$expense_currency_code = Account::where('id', $this->request->get('from_account_id'))->pluck('currency_code')->first();
$income_currency_code = Account::where('id', $this->request->get('to_account_id'))->pluck('currency_code')->first();
$expense_currency_code = $this->getCurrencyCode('from');
$income_currency_code = $this->getCurrencyCode('to');
$expense_currency_rate = config('money.' . $expense_currency_code . '.rate');
$income_currency_rate = config('money.' . $income_currency_code . '.rate');
$expense_currency_rate = $this->getCurrencyRate('from');
$income_currency_rate = $this->getCurrencyRate('to');
$expense_transaction = Transaction::findOrFail($this->transfer->expense_transaction_id);
$income_transaction = Transaction::findOrFail($this->transfer->income_transaction_id);
@ -93,4 +93,26 @@ class UpdateTransfer extends Job
return $this->transfer;
}
protected function getCurrencyCode($type)
{
$currency_code = $this->request->get($type . '_account_currency_code');
if (empty($currency_code)) {
$currency_code = Account::where('id', $this->request->get($type . '_account_id'))->pluck('currency_code')->first();
}
return $currency_code;
}
protected function getCurrencyRate($type)
{
$currency_rate = $this->request->get($type . '_account_rate');
if (empty($currency_rate)) {
$currency_rate = config('money.' . $this->getCurrencyCode($type) . '.rate');
}
return $currency_rate;
}
}