mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -06:00
FF3 will now correctly store exchanged / foreign amounts.
This commit is contained in:
parent
9a69ce309e
commit
7e31a29b12
@ -92,7 +92,7 @@ class AccountController extends Controller
|
||||
$request->session()->flash('gaEventCategory', 'accounts');
|
||||
$request->session()->flash('gaEventAction', 'create-' . $what);
|
||||
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencySelectList','allCurrencies', 'roles'));
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencySelectList', 'allCurrencies', 'roles'));
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,9 @@ class JournalFormRequest extends Request
|
||||
'destination_account_name' => $this->string('destination_account_name'),
|
||||
'piggy_bank_id' => $this->integer('piggy_bank_id'),
|
||||
|
||||
// amount for exchanged data:
|
||||
'exchanged_amount' => $this->float('exchanged_amount'),
|
||||
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
@ -41,7 +41,10 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/** @var array */
|
||||
private $validMetaFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes'];
|
||||
private $validMetaFields
|
||||
= ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes', 'original_amount',
|
||||
'original_currency_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
@ -165,12 +168,34 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
public function store(array $data): TransactionJournal
|
||||
{
|
||||
// find transaction type.
|
||||
/** @var TransactionType $transactionType */
|
||||
$transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
|
||||
$journal = new TransactionJournal(
|
||||
$accounts = $this->storeAccounts($transactionType, $data);
|
||||
$currencyId = $data['currency_id'];
|
||||
$amount = strval($data['amount']);
|
||||
// switch type to find what account to verify for currency stuff
|
||||
switch ($transactionType->type) {
|
||||
case TransactionType::WITHDRAWAL:
|
||||
/*
|
||||
* Overrule the currency selection and the amount:
|
||||
*/
|
||||
$accountCurrencyId = intval($accounts['source']->getMeta('currency_id'));
|
||||
if ($accountCurrencyId !== $currencyId) {
|
||||
$currencyId = $accountCurrencyId;
|
||||
$amount = strval($data['exchanged_amount']);
|
||||
$data['original_amount'] = $data['amount'];
|
||||
$data['original_currency_id'] = $currencyId;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException(sprintf('Currency exchange routine cannot handle %s', $transactionType->type));
|
||||
}
|
||||
|
||||
$journal = new TransactionJournal(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'transaction_type_id' => $transactionType->id,
|
||||
'transaction_currency_id' => $data['currency_id'],
|
||||
'transaction_currency_id' => $currencyId,
|
||||
'description' => $data['description'],
|
||||
'completed' => 0,
|
||||
'date' => $data['date'],
|
||||
@ -181,13 +206,13 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
// store stuff:
|
||||
$this->storeCategoryWithJournal($journal, $data['category']);
|
||||
$this->storeBudgetWithJournal($journal, $data['budget_id']);
|
||||
$accounts = $this->storeAccounts($transactionType, $data);
|
||||
|
||||
|
||||
// store two transactions:
|
||||
$one = [
|
||||
'journal' => $journal,
|
||||
'account' => $accounts['source'],
|
||||
'amount' => bcmul(strval($data['amount']), '-1'),
|
||||
'amount' => bcmul($amount, '-1'),
|
||||
'description' => null,
|
||||
'category' => null,
|
||||
'budget' => null,
|
||||
@ -198,7 +223,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$two = [
|
||||
'journal' => $journal,
|
||||
'account' => $accounts['destination'],
|
||||
'amount' => $data['amount'],
|
||||
'amount' => $amount,
|
||||
'description' => null,
|
||||
'category' => null,
|
||||
'budget' => null,
|
||||
|
@ -275,7 +275,7 @@ class ExpandedForm
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$options['min'] = '0.01';
|
||||
$options['min'] = '0.01';
|
||||
$selectedCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
|
||||
unset($options['currency']);
|
||||
unset($options['placeholder']);
|
||||
@ -312,7 +312,8 @@ class ExpandedForm
|
||||
|
||||
// make sure value is formatted nicely:
|
||||
if (!is_null($value) && $value !== '') {
|
||||
$value = round($value, $selectedCurrency->decimal_places);
|
||||
$decimals = $selectedCurrency->decimal_places ?? 2;
|
||||
$value = round($value, $decimals);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user