2016-04-30 23:37:47 -05:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-30 23:59:08 -05:00
|
|
|
* TransactionController.php
|
2016-04-30 23:37:47 -05:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
2016-05-20 05:27:31 -05:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2016-04-30 23:59:08 -05:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-23 14:55:52 -06:00
|
|
|
|
2016-04-30 23:59:08 -05:00
|
|
|
use Carbon\Carbon;
|
2015-02-24 14:10:25 -06:00
|
|
|
use ExpandedForm;
|
2016-01-12 14:38:05 -06:00
|
|
|
use FireflyIII\Events\TransactionJournalStored;
|
|
|
|
use FireflyIII\Events\TransactionJournalUpdated;
|
2015-07-18 02:49:59 -05:00
|
|
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
2015-02-24 15:53:38 -06:00
|
|
|
use FireflyIII\Http\Requests\JournalFormRequest;
|
2016-05-15 09:13:05 -05:00
|
|
|
use FireflyIII\Models\AccountType;
|
2015-02-25 14:19:06 -06:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2015-12-09 18:39:50 -06:00
|
|
|
use FireflyIII\Models\TransactionType;
|
2015-02-24 15:53:38 -06:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2016-05-15 05:08:41 -05:00
|
|
|
use Illuminate\Http\Request;
|
2015-06-02 10:44:50 -05:00
|
|
|
use Preferences;
|
2016-04-30 23:59:08 -05:00
|
|
|
use Response;
|
2015-02-24 14:10:25 -06:00
|
|
|
use Session;
|
2015-07-19 07:30:20 -05:00
|
|
|
use Steam;
|
2015-03-31 13:22:51 -05:00
|
|
|
use URL;
|
2015-04-01 02:16:41 -05:00
|
|
|
use View;
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2015-02-23 14:55:52 -06:00
|
|
|
/**
|
2016-04-30 23:59:08 -05:00
|
|
|
* Class TransactionController
|
2015-02-23 14:55:52 -06:00
|
|
|
*
|
2016-04-30 23:59:08 -05:00
|
|
|
* @package FireflyIII\Http\Controllers
|
2015-02-23 14:55:52 -06:00
|
|
|
*/
|
2016-04-30 23:59:08 -05:00
|
|
|
class TransactionController extends Controller
|
2015-02-23 14:55:52 -06:00
|
|
|
{
|
|
|
|
/**
|
2016-02-04 00:27:03 -06:00
|
|
|
*
|
2015-02-23 14:55:52 -06:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-04-28 08:26:30 -05:00
|
|
|
parent::__construct();
|
2015-05-14 08:53:56 -05:00
|
|
|
View::share('title', trans('firefly.transactions'));
|
2015-02-23 14:55:52 -06:00
|
|
|
View::share('mainTitleIcon', 'fa-repeat');
|
|
|
|
}
|
|
|
|
|
2015-02-24 14:10:25 -06:00
|
|
|
/**
|
2016-01-01 05:41:00 -06:00
|
|
|
* @param string $what
|
2015-02-24 14:10:25 -06:00
|
|
|
*
|
2016-08-26 02:30:52 -05:00
|
|
|
* @return View
|
2015-02-24 14:10:25 -06:00
|
|
|
*/
|
2016-05-15 08:08:59 -05:00
|
|
|
public function create(string $what = TransactionType::DEPOSIT)
|
2015-02-24 14:10:25 -06:00
|
|
|
{
|
2016-05-20 05:02:19 -05:00
|
|
|
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
|
|
|
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
|
|
|
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
|
|
|
$what = strtolower($what);
|
|
|
|
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
|
|
|
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
|
|
|
|
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
|
|
|
$piggyBanks = $piggyRepository->getPiggyBanksWithAmount();
|
|
|
|
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
|
|
|
|
$preFilled = Session::has('preFilled') ? session('preFilled') : [];
|
|
|
|
$subTitle = trans('form.add_new_' . $what);
|
|
|
|
$subTitleIcon = 'fa-plus';
|
2016-09-04 09:21:51 -05:00
|
|
|
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
2015-02-24 14:10:25 -06:00
|
|
|
|
|
|
|
Session::put('preFilled', $preFilled);
|
|
|
|
|
2015-04-01 02:12:49 -05:00
|
|
|
// put previous url in session if not redirect from store (not "create another").
|
2016-02-04 00:27:03 -06:00
|
|
|
if (session('transactions.create.fromStore') !== true) {
|
2016-05-15 05:08:41 -05:00
|
|
|
$url = URL::previous();
|
|
|
|
Session::put('transactions.create.url', $url);
|
2015-04-01 02:12:49 -05:00
|
|
|
}
|
|
|
|
Session::forget('transactions.create.fromStore');
|
2015-05-25 01:12:31 -05:00
|
|
|
Session::flash('gaEventCategory', 'transactions');
|
|
|
|
Session::flash('gaEventAction', 'create-' . $what);
|
2015-04-01 02:12:49 -05:00
|
|
|
|
2015-02-24 14:10:25 -06:00
|
|
|
asort($piggies);
|
|
|
|
|
|
|
|
|
2016-09-04 09:21:51 -05:00
|
|
|
return view('transactions.create', compact('assetAccounts', 'subTitleIcon', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields'));
|
2015-02-24 14:10:25 -06:00
|
|
|
}
|
|
|
|
|
2015-02-27 07:27:04 -06:00
|
|
|
/**
|
|
|
|
* Shows the form that allows a user to delete a transaction journal.
|
|
|
|
*
|
|
|
|
* @param TransactionJournal $journal
|
|
|
|
*
|
2016-08-26 02:30:52 -05:00
|
|
|
* @return View
|
2015-02-27 07:27:04 -06:00
|
|
|
*/
|
|
|
|
public function delete(TransactionJournal $journal)
|
|
|
|
{
|
2016-03-02 06:37:28 -06:00
|
|
|
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
2015-06-06 16:09:12 -05:00
|
|
|
$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2015-04-01 02:23:51 -05:00
|
|
|
// put previous url in session
|
|
|
|
Session::put('transactions.delete.url', URL::previous());
|
2015-05-25 01:12:31 -05:00
|
|
|
Session::flash('gaEventCategory', 'transactions');
|
2015-06-06 16:09:12 -05:00
|
|
|
Session::flash('gaEventAction', 'delete-' . $what);
|
2015-04-01 02:23:51 -05:00
|
|
|
|
2015-06-13 03:02:36 -05:00
|
|
|
return view('transactions.delete', compact('journal', 'subTitle', 'what'));
|
2015-02-27 07:27:04 -06:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-05 00:48:34 -05:00
|
|
|
* @param JournalRepositoryInterface $repository
|
|
|
|
* @param TransactionJournal $transactionJournal
|
2015-02-27 07:27:04 -06:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-05-04 16:46:14 -05:00
|
|
|
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
|
2015-02-27 07:27:04 -06:00
|
|
|
{
|
2016-05-15 05:08:41 -05:00
|
|
|
$type = TransactionJournal::transactionTypeStr($transactionJournal);
|
2016-03-20 05:38:01 -05:00
|
|
|
Session::flash('success', strval(trans('firefly.deleted_' . $type, ['description' => e($transactionJournal->description)])));
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2015-05-04 16:46:14 -05:00
|
|
|
$repository->delete($transactionJournal);
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2015-06-02 10:44:50 -05:00
|
|
|
Preferences::mark();
|
|
|
|
|
2015-04-01 02:23:51 -05:00
|
|
|
// redirect to previous URL:
|
2016-02-04 00:27:03 -06:00
|
|
|
return redirect(session('transactions.delete.url'));
|
2015-02-27 07:27:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-01 05:41:00 -06:00
|
|
|
* @param TransactionJournal $journal
|
2015-02-27 07:27:04 -06:00
|
|
|
*
|
2016-03-20 11:12:34 -05:00
|
|
|
* @return mixed
|
2015-02-27 07:27:04 -06:00
|
|
|
*/
|
2016-03-20 11:12:34 -05:00
|
|
|
public function edit(TransactionJournal $journal)
|
2015-02-27 07:27:04 -06:00
|
|
|
{
|
2016-05-11 16:03:13 -05:00
|
|
|
$count = $journal->transactions()->count();
|
|
|
|
if ($count > 2) {
|
|
|
|
return redirect(route('split.journal.edit', [$journal->id]));
|
|
|
|
}
|
2016-05-15 08:24:23 -05:00
|
|
|
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
|
|
|
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
2016-05-20 05:03:28 -05:00
|
|
|
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
|
|
|
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
|
2016-05-15 08:24:23 -05:00
|
|
|
$budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
|
|
|
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks());
|
|
|
|
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
|
|
|
|
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
|
|
|
|
$uploadSize = min($maxFileSize, $maxPostSize);
|
|
|
|
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
|
|
|
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
|
|
|
$sourceAccounts = TransactionJournal::sourceAccountList($journal);
|
|
|
|
$destinationAccounts = TransactionJournal::destinationAccountList($journal);
|
2016-09-04 09:21:51 -05:00
|
|
|
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
2016-05-15 08:24:23 -05:00
|
|
|
$preFilled = [
|
2016-04-30 05:46:21 -05:00
|
|
|
'date' => TransactionJournal::dateAsString($journal),
|
|
|
|
'interest_date' => TransactionJournal::dateAsString($journal, 'interest_date'),
|
|
|
|
'book_date' => TransactionJournal::dateAsString($journal, 'book_date'),
|
|
|
|
'process_date' => TransactionJournal::dateAsString($journal, 'process_date'),
|
|
|
|
'category' => TransactionJournal::categoryAsString($journal),
|
|
|
|
'budget_id' => TransactionJournal::budgetId($journal),
|
|
|
|
'piggy_bank_id' => TransactionJournal::piggyBankId($journal),
|
|
|
|
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
2016-05-15 08:24:23 -05:00
|
|
|
'source_account_id' => $sourceAccounts->first()->id,
|
|
|
|
'source_account_name' => $sourceAccounts->first()->name,
|
|
|
|
'destination_account_id' => $destinationAccounts->first()->id,
|
|
|
|
'destination_account_name' => $destinationAccounts->first()->name,
|
2016-04-30 05:46:21 -05:00
|
|
|
'amount' => TransactionJournal::amountPositive($journal),
|
2015-02-27 07:27:04 -06:00
|
|
|
];
|
|
|
|
|
2016-05-15 09:13:05 -05:00
|
|
|
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
|
2016-04-30 05:46:21 -05:00
|
|
|
$preFilled['destination_account_name'] = '';
|
|
|
|
}
|
2016-05-15 08:24:23 -05:00
|
|
|
|
2016-05-15 09:13:05 -05:00
|
|
|
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type == AccountType::CASH) {
|
2016-04-30 05:46:21 -05:00
|
|
|
$preFilled['source_account_name'] = '';
|
2015-06-16 11:26:17 -05:00
|
|
|
}
|
|
|
|
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2015-04-28 08:26:30 -05:00
|
|
|
Session::flash('preFilled', $preFilled);
|
2015-05-25 01:12:31 -05:00
|
|
|
Session::flash('gaEventCategory', 'transactions');
|
|
|
|
Session::flash('gaEventAction', 'edit-' . $what);
|
2015-04-28 03:36:13 -05:00
|
|
|
|
2015-04-01 02:12:49 -05:00
|
|
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
2016-02-04 00:27:03 -06:00
|
|
|
if (session('transactions.edit.fromUpdate') !== true) {
|
2015-04-01 02:12:49 -05:00
|
|
|
Session::put('transactions.edit.url', URL::previous());
|
|
|
|
}
|
2015-04-01 02:40:19 -05:00
|
|
|
Session::forget('transactions.edit.fromUpdate');
|
2015-04-01 02:12:49 -05:00
|
|
|
|
2016-09-04 09:21:51 -05:00
|
|
|
return view(
|
|
|
|
'transactions.edit',
|
|
|
|
compact('journal', 'optionalFields', 'uploadSize', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle')
|
|
|
|
)->with('data', $preFilled);
|
2015-02-27 07:27:04 -06:00
|
|
|
}
|
|
|
|
|
2016-04-30 23:59:08 -05:00
|
|
|
/**
|
2016-05-15 05:08:41 -05:00
|
|
|
* @param Request $request
|
2016-04-30 23:59:08 -05:00
|
|
|
* @param JournalRepositoryInterface $repository
|
2016-05-15 05:08:41 -05:00
|
|
|
* @param string $what
|
2016-04-30 23:59:08 -05:00
|
|
|
*
|
2016-05-15 05:08:41 -05:00
|
|
|
* @return View
|
2016-04-30 23:59:08 -05:00
|
|
|
*/
|
2016-05-15 05:08:41 -05:00
|
|
|
public function index(Request $request, JournalRepositoryInterface $repository, string $what)
|
2016-04-30 23:59:08 -05:00
|
|
|
{
|
2016-08-02 12:12:18 -05:00
|
|
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
2016-04-30 23:59:08 -05:00
|
|
|
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
|
|
|
$types = config('firefly.transactionTypesByWhat.' . $what);
|
|
|
|
$subTitle = trans('firefly.title_' . $what);
|
2016-05-15 05:08:41 -05:00
|
|
|
$page = intval($request->get('page'));
|
2016-05-01 02:42:08 -05:00
|
|
|
$journals = $repository->getJournals($types, $page, $pageSize);
|
2016-04-30 23:59:08 -05:00
|
|
|
|
|
|
|
$journals->setPath('transactions/' . $what);
|
|
|
|
|
|
|
|
return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-15 05:08:41 -05:00
|
|
|
* @param Request $request
|
2016-04-30 23:59:08 -05:00
|
|
|
* @param JournalRepositoryInterface $repository
|
|
|
|
*
|
2016-05-15 05:08:41 -05:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2016-04-30 23:59:08 -05:00
|
|
|
*/
|
2016-05-15 05:08:41 -05:00
|
|
|
public function reorder(Request $request, JournalRepositoryInterface $repository)
|
2016-04-30 23:59:08 -05:00
|
|
|
{
|
2016-05-15 05:08:41 -05:00
|
|
|
$ids = $request->get('items');
|
|
|
|
$date = new Carbon($request->get('date'));
|
2016-04-30 23:59:08 -05:00
|
|
|
if (count($ids) > 0) {
|
|
|
|
$order = 0;
|
|
|
|
foreach ($ids as $id) {
|
2016-06-15 02:58:33 -05:00
|
|
|
$journal = $repository->find(intval($id));
|
2016-05-01 02:42:08 -05:00
|
|
|
if ($journal && $journal->date->format('Y-m-d') == $date->format('Y-m-d')) {
|
2016-04-30 23:59:08 -05:00
|
|
|
$journal->order = $order;
|
|
|
|
$order++;
|
|
|
|
$journal->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Preferences::mark();
|
|
|
|
|
|
|
|
return Response::json([true]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:19:06 -06:00
|
|
|
/**
|
2016-05-15 05:08:41 -05:00
|
|
|
* @param TransactionJournal $journal
|
|
|
|
* @param JournalRepositoryInterface $repository
|
2015-02-25 14:19:06 -06:00
|
|
|
*
|
2016-05-15 05:08:41 -05:00
|
|
|
* @return View
|
2015-02-25 14:19:06 -06:00
|
|
|
*/
|
2016-05-13 02:55:06 -05:00
|
|
|
public function show(TransactionJournal $journal, JournalRepositoryInterface $repository)
|
2015-02-25 14:19:06 -06:00
|
|
|
{
|
2016-05-15 05:08:41 -05:00
|
|
|
$events = $repository->getPiggyBankEvents($journal);
|
|
|
|
$transactions = $repository->getTransactions($journal);
|
|
|
|
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
|
|
|
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
|
2015-12-28 00:27:16 -06:00
|
|
|
|
2016-05-15 05:08:41 -05:00
|
|
|
if ($transactions->count() > 2) {
|
|
|
|
return view('split.journals.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
|
2016-05-14 06:51:33 -05:00
|
|
|
}
|
|
|
|
|
2016-05-15 05:08:41 -05:00
|
|
|
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
|
2016-05-13 02:55:06 -05:00
|
|
|
|
2015-02-25 14:19:06 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-26 11:45:03 -05:00
|
|
|
/**
|
|
|
|
* @param JournalFormRequest $request
|
|
|
|
* @param JournalRepositoryInterface $repository
|
|
|
|
*
|
2015-05-26 13:57:31 -05:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2015-03-26 11:45:03 -05:00
|
|
|
*/
|
2016-05-15 08:08:59 -05:00
|
|
|
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
|
2015-02-24 15:53:38 -06:00
|
|
|
{
|
2016-05-15 08:08:59 -05:00
|
|
|
$att = app('FireflyIII\Helpers\Attachments\AttachmentHelperInterface');
|
2016-04-29 10:29:13 -05:00
|
|
|
$doSplit = intval($request->get('split_journal')) === 1;
|
2015-03-29 04:51:26 -05:00
|
|
|
$journalData = $request->getJournalData();
|
2016-05-15 05:08:41 -05:00
|
|
|
|
|
|
|
// store the journal only, flash the rest.
|
2016-04-29 10:29:13 -05:00
|
|
|
if ($doSplit) {
|
2016-08-26 01:21:31 -05:00
|
|
|
$journal = $repository->storeJournal($journalData);
|
2016-08-02 12:12:18 -05:00
|
|
|
$journal->completed = false;
|
|
|
|
$journal->save();
|
2016-04-29 10:29:13 -05:00
|
|
|
|
2016-05-15 05:08:41 -05:00
|
|
|
// store 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'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Session::put('journal-data', $journalData);
|
|
|
|
|
|
|
|
return redirect(route('split.journal.create', [$journal->id]));
|
2016-04-29 10:29:13 -05:00
|
|
|
}
|
2016-05-15 05:08:41 -05:00
|
|
|
|
2015-07-17 14:03:13 -05:00
|
|
|
|
|
|
|
// if not withdrawal, unset budgetid.
|
2015-12-09 18:39:50 -06:00
|
|
|
if ($journalData['what'] != strtolower(TransactionType::WITHDRAWAL)) {
|
2015-07-17 14:03:13 -05:00
|
|
|
$journalData['budget_id'] = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-18 02:49:59 -05:00
|
|
|
$journal = $repository->store($journalData);
|
|
|
|
$att->saveAttachmentsForModel($journal);
|
|
|
|
|
2015-07-19 06:46:34 -05:00
|
|
|
// flash errors
|
|
|
|
if (count($att->getErrors()->get('attachments')) > 0) {
|
|
|
|
Session::flash('error', $att->getErrors()->get('attachments'));
|
2015-07-18 02:49:59 -05:00
|
|
|
}
|
2015-07-19 06:46:34 -05:00
|
|
|
// flash messages
|
|
|
|
if (count($att->getMessages()->get('attachments')) > 0) {
|
|
|
|
Session::flash('info', $att->getMessages()->get('attachments'));
|
2015-07-18 02:49:59 -05:00
|
|
|
}
|
|
|
|
|
2016-05-05 00:09:12 -05:00
|
|
|
event(new TransactionJournalStored($journal, intval($journalData['piggy_bank_id'])));
|
2015-03-01 01:34:59 -06:00
|
|
|
|
2016-03-20 05:38:01 -05:00
|
|
|
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));
|
2015-06-02 10:44:50 -05:00
|
|
|
Preferences::mark();
|
2015-03-02 13:05:28 -06:00
|
|
|
|
2016-05-15 05:08:41 -05:00
|
|
|
if (intval($request->get('create_another')) === 1) {
|
2015-04-01 02:12:49 -05:00
|
|
|
// set value so create routine will not overwrite URL:
|
2015-04-01 02:16:41 -05:00
|
|
|
Session::put('transactions.create.fromStore', true);
|
|
|
|
|
2015-07-06 09:27:21 -05:00
|
|
|
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
2015-03-01 03:44:10 -06:00
|
|
|
}
|
2015-02-24 15:53:38 -06:00
|
|
|
|
2015-04-01 02:12:49 -05:00
|
|
|
// redirect to previous URL.
|
2016-02-04 00:27:03 -06:00
|
|
|
return redirect(session('transactions.create.url'));
|
2015-02-23 14:55:52 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-30 23:59:08 -05:00
|
|
|
|
2015-02-27 07:27:04 -06:00
|
|
|
/**
|
2015-05-03 05:54:39 -05:00
|
|
|
* @param JournalFormRequest $request
|
|
|
|
* @param JournalRepositoryInterface $repository
|
2015-07-18 14:46:16 -05:00
|
|
|
* @param AttachmentHelperInterface $att
|
2015-05-03 05:54:39 -05:00
|
|
|
* @param TransactionJournal $journal
|
2015-02-27 07:27:04 -06:00
|
|
|
*
|
2016-08-26 02:30:52 -05:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
2015-02-27 07:27:04 -06:00
|
|
|
*/
|
2015-07-18 14:46:16 -05:00
|
|
|
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
|
2015-02-27 07:27:04 -06:00
|
|
|
{
|
2015-03-29 04:51:26 -05:00
|
|
|
$journalData = $request->getJournalData();
|
2015-02-27 07:27:04 -06:00
|
|
|
$repository->update($journal, $journalData);
|
2015-03-01 01:34:59 -06:00
|
|
|
|
2015-07-18 14:46:16 -05:00
|
|
|
// save attachments:
|
|
|
|
$att->saveAttachmentsForModel($journal);
|
|
|
|
|
2015-07-19 07:30:20 -05:00
|
|
|
// flash errors
|
|
|
|
if (count($att->getErrors()->get('attachments')) > 0) {
|
|
|
|
Session::flash('error', $att->getErrors()->get('attachments'));
|
2015-07-18 14:46:16 -05:00
|
|
|
}
|
2015-07-19 07:30:20 -05:00
|
|
|
// flash messages
|
|
|
|
if (count($att->getMessages()->get('attachments')) > 0) {
|
|
|
|
Session::flash('info', $att->getMessages()->get('attachments'));
|
2015-07-18 14:46:16 -05:00
|
|
|
}
|
|
|
|
|
2016-01-12 14:38:05 -06:00
|
|
|
event(new TransactionJournalUpdated($journal));
|
2015-03-02 13:05:28 -06:00
|
|
|
// update, get events by date and sort DESC
|
2015-03-01 01:34:59 -06:00
|
|
|
|
2016-03-20 05:38:01 -05:00
|
|
|
$type = strtolower($journal->transaction_type_type ?? TransactionJournal::transactionTypeStr($journal));
|
|
|
|
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($journalData['description'])])));
|
2015-06-02 10:44:50 -05:00
|
|
|
Preferences::mark();
|
2015-02-27 07:27:04 -06:00
|
|
|
|
2016-05-15 05:08:41 -05:00
|
|
|
if (intval($request->get('return_to_edit')) === 1) {
|
2015-04-01 02:12:49 -05:00
|
|
|
// set value so edit routine will not overwrite URL:
|
2015-04-01 02:40:19 -05:00
|
|
|
Session::put('transactions.edit.fromUpdate', true);
|
2015-04-01 02:16:41 -05:00
|
|
|
|
2015-07-06 09:27:21 -05:00
|
|
|
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
2015-03-01 03:44:10 -06:00
|
|
|
}
|
|
|
|
|
2015-04-01 02:12:49 -05:00
|
|
|
// redirect to previous URL.
|
2016-02-04 00:27:03 -06:00
|
|
|
return redirect(session('transactions.edit.url'));
|
2015-02-27 07:27:04 -06:00
|
|
|
|
|
|
|
}
|
2016-04-30 23:59:08 -05:00
|
|
|
}
|