/** * @param JournalRepositoryInterface $repository * @param TransactionJournal $journal * * @return \Illuminate\View\View */ public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) { /** @var Collection $set */ $events = $journal->piggyBankEvents()->get(); $events->each(function (PiggyBankEvent $event) { $event->piggyBank = $event->piggyBank()->withTrashed()->first(); }); bcscale(2); $journal->transactions->each(function (Transaction $t) use($journal, $repository) { $t->before = $repository->getAmountBefore($journal, $t); $t->after = bcadd($t->before, $t->amount); }); $what = strtolower($journal->getTransactionType()); $subTitle = trans('firefly.' . $journal->getTransactionType()) . ' "' . e($journal->description) . '"'; return view('transactions.show', compact('journal', 'events', 'subTitle', 'what')); }
/** * Shows the view to edit a transaction. * * @param AccountRepositoryInterface $repository * @param TransactionJournal $journal * * @return $this */ public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal) { // cannot edit opening balance if ($journal->transactionType->type == 'Opening balance') { return view('error')->with('message', 'Cannot edit this transaction. Edit the account instead!'); } $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize')); $maxPostSize = Steam::phpBytes(ini_get('post_max_size')); $uploadSize = min($maxFileSize, $maxPostSize); $what = strtolower($journal->transactionType->type); $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); $budgets[0] = trans('form.noBudget'); $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); $piggies[0] = trans('form.noPiggybank'); $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); $preFilled = ['date' => $journal->date->format('Y-m-d'), 'category' => '', 'budget_id' => 0, 'piggy_bank_id' => 0]; // get tags: $tags = []; foreach ($journal->tags as $tag) { $tags[] = $tag->tag; } $preFilled['tags'] = join(',', $tags); $category = $journal->categories()->first(); if (!is_null($category)) { $preFilled['category'] = $category->name; } $budget = $journal->budgets()->first(); if (!is_null($budget)) { $preFilled['budget_id'] = $budget->id; } if ($journal->piggyBankEvents()->count() > 0) { $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; } $preFilled['amount'] = $journal->amount_positive; if ($journal->transactionType->type == 'Withdrawal') { $preFilled['account_id'] = $journal->source_account->id; $preFilled['expense_account'] = $journal->destination_account->name_for_editform; } else { $preFilled['account_id'] = $journal->destination_account->id; $preFilled['revenue_account'] = $journal->source_account->name_for_editform; } $preFilled['account_from_id'] = $journal->source_account->id; $preFilled['account_to_id'] = $journal->destination_account->id; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'transactions'); Session::flash('gaEventAction', 'edit-' . $what); // put previous url in session if not redirect from store (not "return_to_edit"). if (Session::get('transactions.edit.fromUpdate') !== true) { Session::put('transactions.edit.url', URL::previous()); } Session::forget('transactions.edit.fromUpdate'); return view('transactions.edit', compact('journal', 'uploadSize', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled); }
/** * @param TransactionJournal $journal * * @return Collection */ public function getPiggyBankEvents(TransactionJournal $journal) : Collection { /** @var Collection $set */ $events = $journal->piggyBankEvents()->get(); $events->each(function (PiggyBankEvent $event) { $event->piggyBank = $event->piggyBank()->withTrashed()->first(); }); return $events; }
/** * @param TransactionJournal $journal * * @return int */ public static function piggyBankId(TransactionJournal $journal) : int { if ($journal->piggyBankEvents()->count() > 0) { return $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; } return 0; }