Extra fix to cover for #1091

This commit is contained in:
James Cole 2018-01-02 19:53:22 +01:00
parent fa676f60fb
commit cdeabaaf9a
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 33 additions and 24 deletions

View File

@ -146,6 +146,7 @@ class UpgradeDatabase extends Command
// both 0? set to default currency:
if (0 === $accountCurrency && 0 === $obCurrency) {
AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $defaultCurrency->id]);
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
@ -508,11 +509,13 @@ class UpgradeDatabase extends Command
*
* @return string
*/
private function var_dump_ret($mixed = null): string {
private function var_dump_ret($mixed = null): string
{
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
return $content;
}

View File

@ -91,33 +91,33 @@ class JournalFormRequest extends Request
{
$what = $this->get('what');
$rules = [
'what' => 'required|in:withdrawal,deposit,transfer',
'date' => 'required|date',
'what' => 'required|in:withdrawal,deposit,transfer',
'date' => 'required|date',
'amount_currency_id_amount' => 'exists:transaction_currencies,id|required',
// then, custom fields:
'interest_date' => 'date|nullable',
'book_date' => 'date|nullable',
'process_date' => 'date|nullable',
'due_date' => 'date|nullable',
'payment_date' => 'date|nullable',
'invoice_date' => 'date|nullable',
'internal_reference' => 'min:1,max:255|nullable',
'notes' => 'min:1,max:50000|nullable',
'interest_date' => 'date|nullable',
'book_date' => 'date|nullable',
'process_date' => 'date|nullable',
'due_date' => 'date|nullable',
'payment_date' => 'date|nullable',
'invoice_date' => 'date|nullable',
'internal_reference' => 'min:1,max:255|nullable',
'notes' => 'min:1,max:50000|nullable',
// and then transaction rules:
'description' => 'required|between:1,255',
'amount' => 'numeric|required|more:0',
'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
'category' => 'between:1,255|nullable',
'source_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
'source_account_name' => 'between:1,255|nullable',
'destination_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
'destination_account_name' => 'between:1,255|nullable',
'piggy_bank_id' => 'between:1,255|nullable',
'description' => 'required|between:1,255',
'amount' => 'numeric|required|more:0',
'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
'category' => 'between:1,255|nullable',
'source_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
'source_account_name' => 'between:1,255|nullable',
'destination_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
'destination_account_name' => 'between:1,255|nullable',
'piggy_bank_id' => 'between:1,255|nullable',
// foreign currency amounts
'native_amount' => 'numeric|more:0|nullable',
'source_amount' => 'numeric|more:0|nullable',
'destination_amount' => 'numeric|more:0|nullable',
'native_amount' => 'numeric|more:0|nullable',
'source_amount' => 'numeric|more:0|nullable',
'destination_amount' => 'numeric|more:0|nullable',
];
// some rules get an upgrade depending on the type of data:

View File

@ -249,6 +249,10 @@ trait SupportJournalsTrait
case TransactionType::WITHDRAWAL:
// continue:
$nativeCurrencyId = intval($accounts[$check]->getMeta('currency_id'));
if ($nativeCurrencyId === 0) {
// fall back to given ID (not everybody upgrades nicely).
$nativeCurrencyId = $submittedCurrencyId;
}
// does not match? Then user has submitted amount in a foreign currency:
if ($nativeCurrencyId !== $submittedCurrencyId) {

View File

@ -72,6 +72,7 @@ class Steam
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);
@ -114,6 +115,7 @@ class Steam
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);