Clean up and consistency in foreign and native amounts.

This commit is contained in:
James Cole
2017-04-14 15:42:54 +02:00
parent bd917f6484
commit ea3fdb0668
10 changed files with 312 additions and 187 deletions

View File

@@ -250,8 +250,8 @@ class SingleController extends Controller
'source_account_name' => $sourceAccounts->first()->edit_name,
'destination_account_id' => $destinationAccounts->first()->id,
'destination_account_name' => $destinationAccounts->first()->edit_name,
'amount' => $journal->amountPositive(),
'currency' => $journal->transactionCurrency,
'amount' => $journal->amountPositive(),
'currency' => $journal->transactionCurrency,
// new custom fields:
'due_date' => $journal->dateAsString('due_date'),
@@ -261,16 +261,16 @@ class SingleController extends Controller
'notes' => $journal->getMeta('notes'),
// exchange rate fields
'exchanged_amount' => $journal->amountPositive(),
'exchanged_currency' => $journal->transactionCurrency,
'native_amount' => $journal->amountPositive(),
'native_currency' => $journal->transactionCurrency,
];
// catch possibly exchanged currencies and what-not.
$originalCurrencyId = intval($journal->getMeta('original_currency_id'));
if ($originalCurrencyId > 0) {
// if user has entered a foreign currency, update some fields
$foreignCurrencyId = intval($journal->getMeta('foreign_currency_id'));
if ($foreignCurrencyId > 0) {
// update some fields in pre-filled.
$preFilled['amount'] = $journal->getMeta('original_amount');
$preFilled['currency'] = $this->currency->find(intval($journal->getMeta('original_currency_id')));
$preFilled['amount'] = $journal->getMeta('foreign_amount');
$preFilled['currency'] = $this->currency->find(intval($journal->getMeta('foreign_currency_id')));
}
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {

View File

@@ -182,15 +182,15 @@ class TransactionController extends Controller
$transactions = $tasker->getTransactionsOverview($journal);
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
$originalCurrency = null;
$foreignCurrency = null;
if ($journal->hasMeta('original_currency_id')) {
if ($journal->hasMeta('foreign_currency_id')) {
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$originalCurrency = $repository->find(intval($journal->getMeta('original_currency_id')));
$repository = app(CurrencyRepositoryInterface::class);
$foreignCurrency = $repository->find(intval($journal->getMeta('foreign_currency_id')));
}
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'originalCurrency'));
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'foreignCurrency'));
}

View File

@@ -67,8 +67,8 @@ 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'),
// native amount
'native_amount' => $this->float('native_amount'),
];
@@ -106,7 +106,7 @@ class JournalFormRequest extends Request
'piggy_bank_id' => 'between:1,255',
// exchange rate data:
'exchanged_amount' => 'numeric|required|more:0',
'native_amount' => 'numeric|more:0',
];
// some rules get an upgrade depending on the type of data: