firefly-iii/app/Http/Controllers/TransactionController.php

121 lines
3.6 KiB
PHP
Raw Normal View History

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
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
2016-04-30 23:37:47 -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;
use FireflyIII\Helpers\Collector\JournalCollector;
2015-02-25 14:19:06 -06:00
use FireflyIII\Models\TransactionJournal;
2015-02-24 15:53:38 -06:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
2016-10-15 05:39:34 -05:00
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
2016-05-15 05:08:41 -05:00
use Illuminate\Http\Request;
use Preferences;
2016-04-30 23:59:08 -05:00
use Response;
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-10-21 12:20:03 -05:00
* TransactionController constructor.
2015-02-23 14:55:52 -06:00
*/
public function __construct()
{
2015-04-28 08:26:30 -05:00
parent::__construct();
2016-10-29 00:44:46 -05:00
$this->middleware(
function ($request, $next) {
View::share('title', trans('firefly.transactions'));
View::share('mainTitleIcon', 'fa-repeat');
return $next($request);
}
);
2015-02-27 07:27:04 -06:00
}
2016-04-30 23:59:08 -05:00
/**
2016-11-05 05:47:21 -05:00
* @param Request $request
* @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-11-05 04:26:57 -05:00
public function index(Request $request, string $what)
2016-04-30 23:59:08 -05:00
{
2016-11-05 05:47:21 -05:00
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what);
$subTitle = trans('firefly.title_' . $what);
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
2016-11-05 05:47:21 -05:00
$collector = new JournalCollector(auth()->user());
2016-11-05 04:26:57 -05:00
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
2016-04-30 23:59:08 -05:00
$journals = $collector->getPaginatedJournals();
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;
2016-10-10 00:49:39 -05:00
$ids = array_unique($ids);
2016-04-30 23:59:08 -05:00
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
/**
* @param TransactionJournal $journal
* @param JournalTaskerInterface $tasker
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
*/
public function show(TransactionJournal $journal, JournalTaskerInterface $tasker)
2015-02-25 14:19:06 -06:00
{
$events = $tasker->getPiggyBankEvents($journal);
2016-10-15 05:39:34 -05:00
$transactions = $tasker->getTransactionsOverview($journal);
2016-05-15 05:08:41 -05:00
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
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
}
2016-04-30 23:59:08 -05:00
}