Update edit and submit routines for transactions.

This commit is contained in:
James Cole
2018-02-24 14:31:20 +01:00
parent ac66e89edb
commit 211caa07dc
7 changed files with 440 additions and 66 deletions

View File

@@ -242,53 +242,56 @@ class SingleController extends Controller
*
* @return mixed
*/
public function edit(TransactionJournal $journal)
public function edit(TransactionJournal $journal, JournalRepositoryInterface $repository)
{
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) {
$transactionType = $repository->getTransactionType($journal);
// redirect to account:
if ($transactionType === TransactionType::OPENING_BALANCE) {
return $this->redirectToAccount($journal);
}
// @codeCoverageIgnoreEnd
// redirect to reconcile edit:
if ($transactionType === TransactionType::RECONCILIATION) {
return redirect(route('accounts.reconcile.edit', [$journal->id]));
}
// redirect to split edit:
if ($this->isSplitJournal($journal)) {
return redirect(route('transactions.split.edit', [$journal->id]));
}
$what = strtolower($journal->transactionTypeStr());
$what = strtolower($transactionType);
$assetAccounts = $this->groupedAccountList();
$budgetList = ExpandedForm::makeSelectListWithEmpty($this->budgets->getBudgets());
if (TransactionType::RECONCILIATION === $journal->transactionType->type) {
return redirect(route('accounts.reconcile.edit', [$journal->id]));
}
// view related code
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
// journal related code
$sourceAccounts = $journal->sourceAccountList();
$destinationAccounts = $journal->destinationAccountList();
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$pTransaction = $journal->positiveTransaction();
$pTransaction = $repository->getFirstPosTransaction($journal);
$foreignCurrency = null !== $pTransaction->foreignCurrency ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency;
$preFilled = [
'date' => $journal->dateAsString(),
'interest_date' => $journal->dateAsString('interest_date'),
'book_date' => $journal->dateAsString('book_date'),
'process_date' => $journal->dateAsString('process_date'),
'category' => $journal->categoryAsString(),
'budget_id' => $journal->budgetId(),
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
'date' => $repository->getJournalDate($journal, null), // $journal->dateAsString()
'interest_date' => $repository->getJournalDate($journal, 'interest_date'),
'book_date' => $repository->getJournalDate($journal, 'book_date'),
'process_date' => $repository->getJournalDate($journal, 'process_date'),
'category' => $repository->getJournalCategoryName($journal),
'budget_id' => $repository->getJournalBudgetId($journal),
'tags' => join(',', $repository->getTags($journal)),
'source_account_id' => $sourceAccounts->first()->id,
'source_account_name' => $sourceAccounts->first()->edit_name,
'destination_account_id' => $destinationAccounts->first()->id,
'destination_account_name' => $destinationAccounts->first()->edit_name,
// new custom fields:
'due_date' => $journal->dateAsString('due_date'),
'payment_date' => $journal->dateAsString('payment_date'),
'invoice_date' => $journal->dateAsString('invoice_date'),
'interal_reference' => $journal->getMeta('internal_reference'),
'notes' => '',
'due_date' => $repository->getJournalDate($journal, 'due_date'),
'payment_date' => $repository->getJournalDate($journal, 'payment_date'),
'invoice_date' => $repository->getJournalDate($journal, 'invoice_date'),
'interal_reference' => $repository->getMetaField($journal, 'internal_reference'),
'notes' => $repository->getNoteText($journal),
// amount fields
'amount' => $pTransaction->amount,
@@ -301,11 +304,6 @@ class SingleController extends Controller
'foreign_currency' => $foreignCurrency,
'destination_currency' => $foreignCurrency,
];
/** @var Note $note */
$note = $this->repository->getNote($journal);
if (null !== $note) {
$preFilled['notes'] = $note->text;
}
// amounts for withdrawals and deposits:
// amount, native_amount, source_amount, destination_amount
@@ -333,17 +331,12 @@ class SingleController extends Controller
* @param JournalRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
{
$doSplit = 1 === intval($request->get('split_journal'));
$createAnother = 1 === intval($request->get('create_another'));
$data = $request->getJournalData();
var_dump($data);exit;
$journal = $repository->store($data);
@@ -405,16 +398,7 @@ class SingleController extends Controller
}
// @codeCoverageIgnoreEnd
$data = $request->getJournalData();
$data['transactions'][0]['currency_id'] = $journal->transaction_currency_id;
if ($data['currency_id'] !== $journal->transaction_currency_id) {
// currency ID is changed by user. Update transaction:
$data['transactions'][0]['amount'] = $data['native_amount'];
$data['transactions'][0]['foreign_currency_id'] = $data['currency_id'];
$data['transactions'][0]['foreign_amount'] = $data['amount'];
}
$data = $request->getJournalData();
$journal = $repository->update($journal, $data);
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;