mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-03 12:10:42 -06:00
Fix #820
This commit is contained in:
parent
f704ade86b
commit
336fb5f5a6
@ -18,6 +18,7 @@ use ExpandedForm;
|
||||
use FireflyIII\Events\UpdatedTransactionJournal;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -126,25 +127,24 @@ class SplitController extends Controller
|
||||
compact(
|
||||
'subTitleIcon', 'currencies', 'optionalFields',
|
||||
'preFilled', 'subTitle', 'uploadSize', 'assetAccounts',
|
||||
'budgets', 'journal', 'accountArray'
|
||||
'budgets', 'journal', 'accountArray', 'previous'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param SplitJournalFormRequest $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||
public function update(SplitJournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||
{
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
|
||||
$data = $this->arrayFromInput($request);
|
||||
$journal = $repository->updateSplitJournal($journal, $data);
|
||||
/** @var array $files */
|
||||
@ -178,11 +178,11 @@ class SplitController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param SplitJournalFormRequest $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function arrayFromInput(Request $request): array
|
||||
private function arrayFromInput(SplitJournalFormRequest $request): array
|
||||
{
|
||||
$array = [
|
||||
'journal_description' => $request->get('journal_description'),
|
||||
@ -211,8 +211,8 @@ class SplitController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param TransactionJournal $journal
|
||||
* @param SplitJournalFormRequest $request
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -245,6 +245,8 @@ class SplitController extends Controller
|
||||
// transactions.
|
||||
'transactions' => $this->getTransactionDataFromJournal($journal),
|
||||
];
|
||||
// update transactions array with old request data.
|
||||
$array['transactions'] = $this->updateWithPrevious($array['transactions'], $request->old());
|
||||
|
||||
return $array;
|
||||
}
|
||||
@ -297,7 +299,7 @@ class SplitController extends Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getTransactionDataFromRequest(Request $request): array
|
||||
private function getTransactionDataFromRequest(SplitJournalFormRequest $request): array
|
||||
{
|
||||
$return = [];
|
||||
$transactions = $request->get('transactions');
|
||||
@ -323,5 +325,36 @@ class SplitController extends Controller
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @param $old
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function updateWithPrevious($array, $old): array
|
||||
{
|
||||
if (count($old) === 0 || !isset($old['transactions'])) {
|
||||
return $array;
|
||||
}
|
||||
$old = $old['transactions'];
|
||||
foreach ($old as $index => $row) {
|
||||
if (isset($array[$index])) {
|
||||
$array[$index] = array_merge($array[$index], $row);
|
||||
continue;
|
||||
}
|
||||
// take some info from first transaction, that should at least exist.
|
||||
$array[$index] = $row;
|
||||
$array[$index]['transaction_currency_id'] = $array[0]['transaction_currency_id'];
|
||||
$array[$index]['transaction_currency_code'] = $array[0]['transaction_currency_code'];
|
||||
$array[$index]['transaction_currency_symbol'] = $array[0]['transaction_currency_symbol'];
|
||||
$array[$index]['foreign_amount'] = round($array[0]['foreign_destination_amount'] ?? '0', 12);
|
||||
$array[$index]['foreign_currency_id'] = $array[0]['foreign_currency_id'];
|
||||
$array[$index]['foreign_currency_code'] = $array[0]['foreign_currency_code'];
|
||||
$array[$index]['foreign_currency_symbol'] = $array[0]['foreign_currency_symbol'];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class JournalFormRequest extends Request
|
||||
// foreign currency amounts
|
||||
'native_amount' => 'numeric|more:0',
|
||||
'source_amount' => 'numeric|more:0',
|
||||
'destination_amount' => 'numeric|more:0',
|
||||
'destination_amount' => 'numeric',
|
||||
];
|
||||
|
||||
// some rules get an upgrade depending on the type of data:
|
||||
|
@ -61,23 +61,23 @@ class SplitJournalFormRequest extends Request
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'what' => 'required|in:withdrawal,deposit,transfer',
|
||||
'journal_description' => 'required|between:1,255',
|
||||
'id' => 'numeric|belongsToUser:transaction_journals,id',
|
||||
'journal_source_account_id' => 'numeric|belongsToUser:accounts,id',
|
||||
'journal_source_account_name.*' => 'between:1,255',
|
||||
'journal_currency_id' => 'required|exists:transaction_currencies,id',
|
||||
'date' => 'required|date',
|
||||
'interest_date' => 'date',
|
||||
'book_date' => 'date',
|
||||
'process_date' => 'date',
|
||||
'description.*' => 'required|between:1,255',
|
||||
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
|
||||
'destination_account_name.*' => 'between:1,255',
|
||||
'amount.*' => 'required|numeric',
|
||||
'budget_id.*' => 'belongsToUser:budgets,id',
|
||||
'category.*' => 'between:1,255',
|
||||
'piggy_bank_id.*' => 'between:1,255',
|
||||
'what' => 'required|in:withdrawal,deposit,transfer',
|
||||
'journal_description' => 'required|between:1,255',
|
||||
'id' => 'numeric|belongsToUser:transaction_journals,id',
|
||||
'journal_source_account_id' => 'numeric|belongsToUser:accounts,id',
|
||||
'journal_source_account_name.*' => 'between:1,255',
|
||||
'journal_currency_id' => 'required|exists:transaction_currencies,id',
|
||||
'date' => 'required|date',
|
||||
'interest_date' => 'date',
|
||||
'book_date' => 'date',
|
||||
'process_date' => 'date',
|
||||
'transactions.*.description' => 'required|between:1,255',
|
||||
'transactions.*.destination_account_id' => 'numeric|belongsToUser:accounts,id',
|
||||
'transactions.*.destination_account_name' => 'between:1,255',
|
||||
'transactions.*.amount' => 'required|numeric',
|
||||
'transactions.*.budget_id' => 'belongsToUser:budgets,id',
|
||||
'transactions.*.category' => 'between:1,255',
|
||||
'transactions.*.piggy_bank_id' => 'between:1,255',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="id" value="{{ journal.id }}"/>
|
||||
<input type="hidden" name="what" value="{{ preFilled.what }}"/>
|
||||
<input type="hidden" name="journal_currency_id" value="{{ journal.transaction_currency_id }}"/>
|
||||
|
||||
{% if errors.all()|length > 0 %}
|
||||
<div class="row">
|
||||
|
Loading…
Reference in New Issue
Block a user