get('confirm_mass_delete'); $set = new Collection; if (is_array($ids)) { /** @var int $journalId */ foreach ($ids as $journalId) { /** @var TransactionJournal $journal */ $journal = $repository->find($journalId); if (!is_null($journal->id) && $journalId == $journal->id) { $set->push($journal); } } } unset($journal); $count = 0; /** @var TransactionJournal $journal */ foreach ($set as $journal) { $repository->delete($journal); $count++; } Preferences::mark(); Session::flash('success', trans('firefly.mass_deleted_transactions_success', ['amount' => $count])); // redirect to previous URL: return redirect(session('transactions.mass-delete.url')); } /** * @param Collection $journals * * @return View */ public function massEdit(Collection $journals) { $subTitle = trans('firefly.mass_edit_journals'); $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); $accountList = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); // skip transactions that have multiple destinations // or multiple sources: $filtered = new Collection; $messages = []; /** * @var int $index * @var TransactionJournal $journal */ foreach ($journals as $index => $journal) { $sources = TransactionJournal::sourceAccountList($journal); $destinations = TransactionJournal::destinationAccountList($journal); if ($sources->count() > 1) { $messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]); continue; } if ($destinations->count() > 1) { $messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]); continue; } $filtered->push($journal); } if (count($messages)) { Session::flash('info', $messages); } // put previous url in session Session::put('transactions.mass-edit.url', URL::previous()); Session::flash('gaEventCategory', 'transactions'); Session::flash('gaEventAction', 'mass-edit'); // set some values to be used in the edit routine: $filtered->each( function (TransactionJournal $journal) { $journal->amount = TransactionJournal::amountPositive($journal); $sources = TransactionJournal::sourceAccountList($journal); $destinations = TransactionJournal::destinationAccountList($journal); $journal->transaction_count = $journal->transactions()->count(); if (!is_null($sources->first())) { $journal->source_account_id = $sources->first()->id; $journal->source_account_name = $sources->first()->name; } if (!is_null($destinations->first())) { $journal->destination_account_id = $destinations->first()->id; $journal->destination_account_name = $destinations->first()->name; } } ); if ($filtered->count() === 0) { Session::flash('error', trans('firefly.no_edit_multiple_left')); } $journals = $filtered; return view('transactions.mass-edit', compact('journals', 'subTitle', 'accountList')); } /** * @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 = $journal->categories->first() ? $journal->categories->first()->name : ''; $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' => intval($destAccountId), 'destination_account_id' => $sourceAccountName, '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')); } }