/** * @param MassEditJournalRequest $request * @param JournalRepositoryInterface $repository * * @return mixed */ public function massUpdate(MassEditJournalRequest $request, JournalRepositoryInterface $repository) { $journalIds = $request->get('journals'); $count = 0; if (is_array($journalIds)) { foreach ($journalIds as $journalId) { $journal = $repository->find(intval($journalId)); if ($journal) { // get optional fields: $what = strtolower(TransactionJournal::transactionTypeStr($journal)); $sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0; $sourceAccountName = $request->get('source_account_name')[$journal->id] ?? ''; $destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0; $destAccountName = $request->get('destination_account_name')[$journal->id] ?? ''; $budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0; $category = $request->get('category')[$journal->id]; $tags = $journal->tags->pluck('tag')->toArray(); // build data array $data = ['id' => $journal->id, 'what' => $what, 'description' => $request->get('description')[$journal->id], 'source_account_id' => intval($sourceAccountId), 'source_account_name' => $sourceAccountName, 'destination_account_id' => intval($destAccountId), 'destination_account_name' => $destAccountName, 'amount' => round($request->get('amount')[$journal->id], 4), 'user' => auth()->user()->id, 'amount_currency_id_amount' => intval($request->get('amount_currency_id_amount_' . $journal->id)), 'date' => new Carbon($request->get('date')[$journal->id]), 'interest_date' => $journal->interest_date, 'book_date' => $journal->book_date, 'process_date' => $journal->process_date, 'budget_id' => $budgetId, 'category' => $category, 'tags' => $tags]; // call repository update function. $repository->update($journal, $data); $count++; } } } Preferences::mark(); Session::flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count])); // redirect to previous URL: return redirect(session('transactions.mass-edit.url')); }
/** * @param JournalFormRequest $request * @param JournalRepositoryInterface $repository * @param AttachmentHelperInterface $att * @param TransactionJournal $journal * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal) { $journalData = $request->getJournalData(); $repository->update($journal, $journalData); // save attachments: $att->saveAttachmentsForModel($journal); // flash errors if (count($att->getErrors()->get('attachments')) > 0) { Session::flash('error', $att->getErrors()->get('attachments')); } // flash messages if (count($att->getMessages()->get('attachments')) > 0) { Session::flash('info', $att->getMessages()->get('attachments')); } event(new TransactionJournalUpdated($journal)); // update, get events by date and sort DESC Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.'); Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: Session::put('transactions.edit.fromUpdate', true); return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]); } // redirect to previous URL. return redirect(Session::get('transactions.edit.url')); }
/** * @param JournalFormRequest $request * @param JournalRepositoryInterface $repository * @param TransactionJournal $journal * * @return \Illuminate\Http\RedirectResponse */ public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal) { $journalData = $request->getJournalData(); $repository->update($journal, $journalData); event(new JournalSaved($journal)); // update, get events by date and sort DESC Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.'); Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: Session::put('transactions.edit.fromUpdate', true); return Redirect::route('transactions.edit', [$journal->id])->withInput(['return_to_edit' => 1]); } // redirect to previous URL. return Redirect::to(Session::get('transactions.edit.url')); }