mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +00:00
FF3 will now correctly store exchanged / foreign amounts.
This commit is contained in:
@@ -92,7 +92,7 @@ class AccountController extends Controller
|
|||||||
$request->session()->flash('gaEventCategory', 'accounts');
|
$request->session()->flash('gaEventCategory', 'accounts');
|
||||||
$request->session()->flash('gaEventAction', 'create-' . $what);
|
$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'),
|
'destination_account_name' => $this->string('destination_account_name'),
|
||||||
'piggy_bank_id' => $this->integer('piggy_bank_id'),
|
'piggy_bank_id' => $this->integer('piggy_bank_id'),
|
||||||
|
|
||||||
|
// amount for exchanged data:
|
||||||
|
'exchanged_amount' => $this->float('exchanged_amount'),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@@ -41,7 +41,10 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/** @var array */
|
/** @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
|
* @param TransactionJournal $journal
|
||||||
@@ -165,12 +168,34 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
public function store(array $data): TransactionJournal
|
public function store(array $data): TransactionJournal
|
||||||
{
|
{
|
||||||
// find transaction type.
|
// find transaction type.
|
||||||
|
/** @var TransactionType $transactionType */
|
||||||
$transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
|
$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,
|
'user_id' => $this->user->id,
|
||||||
'transaction_type_id' => $transactionType->id,
|
'transaction_type_id' => $transactionType->id,
|
||||||
'transaction_currency_id' => $data['currency_id'],
|
'transaction_currency_id' => $currencyId,
|
||||||
'description' => $data['description'],
|
'description' => $data['description'],
|
||||||
'completed' => 0,
|
'completed' => 0,
|
||||||
'date' => $data['date'],
|
'date' => $data['date'],
|
||||||
@@ -181,13 +206,13 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
// store stuff:
|
// store stuff:
|
||||||
$this->storeCategoryWithJournal($journal, $data['category']);
|
$this->storeCategoryWithJournal($journal, $data['category']);
|
||||||
$this->storeBudgetWithJournal($journal, $data['budget_id']);
|
$this->storeBudgetWithJournal($journal, $data['budget_id']);
|
||||||
$accounts = $this->storeAccounts($transactionType, $data);
|
|
||||||
|
|
||||||
// store two transactions:
|
// store two transactions:
|
||||||
$one = [
|
$one = [
|
||||||
'journal' => $journal,
|
'journal' => $journal,
|
||||||
'account' => $accounts['source'],
|
'account' => $accounts['source'],
|
||||||
'amount' => bcmul(strval($data['amount']), '-1'),
|
'amount' => bcmul($amount, '-1'),
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'category' => null,
|
'category' => null,
|
||||||
'budget' => null,
|
'budget' => null,
|
||||||
@@ -198,7 +223,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
$two = [
|
$two = [
|
||||||
'journal' => $journal,
|
'journal' => $journal,
|
||||||
'account' => $accounts['destination'],
|
'account' => $accounts['destination'],
|
||||||
'amount' => $data['amount'],
|
'amount' => $amount,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'category' => null,
|
'category' => null,
|
||||||
'budget' => null,
|
'budget' => null,
|
||||||
|
@@ -275,7 +275,7 @@ class ExpandedForm
|
|||||||
$classes = $this->getHolderClasses($name);
|
$classes = $this->getHolderClasses($name);
|
||||||
$value = $this->fillFieldValue($name, $value);
|
$value = $this->fillFieldValue($name, $value);
|
||||||
$options['step'] = 'any';
|
$options['step'] = 'any';
|
||||||
$options['min'] = '0.01';
|
$options['min'] = '0.01';
|
||||||
$selectedCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
|
$selectedCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
|
||||||
unset($options['currency']);
|
unset($options['currency']);
|
||||||
unset($options['placeholder']);
|
unset($options['placeholder']);
|
||||||
@@ -312,7 +312,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
// make sure value is formatted nicely:
|
// make sure value is formatted nicely:
|
||||||
if (!is_null($value) && $value !== '') {
|
if (!is_null($value) && $value !== '') {
|
||||||
$value = round($value, $selectedCurrency->decimal_places);
|
$decimals = $selectedCurrency->decimal_places ?? 2;
|
||||||
|
$value = round($value, $decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user