2016-05-01 06:37:47 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-01 06:59:08 +02:00
|
|
|
* TransactionController.php
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-01 06:37:47 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 14:41:58 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-01 06:37:47 +02:00
|
|
|
*/
|
2018-07-08 12:08:53 +02:00
|
|
|
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
|
|
|
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
2017-03-24 15:01:53 +01:00
|
|
|
declare(strict_types=1);
|
2016-05-20 12:27:31 +02:00
|
|
|
|
2016-05-01 06:59:08 +02:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-23 21:55:52 +01:00
|
|
|
|
2016-05-01 06:59:08 +02:00
|
|
|
use Carbon\Carbon;
|
2018-11-11 07:03:36 +01:00
|
|
|
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
2015-02-24 22:53:38 +01:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2018-08-09 16:13:13 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
2018-08-11 06:39:29 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
2018-06-09 07:09:43 +02:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2016-05-15 12:08:41 +02:00
|
|
|
use Illuminate\Http\Request;
|
2016-11-19 12:57:35 +01:00
|
|
|
use Log;
|
2015-02-27 14:27:04 +01:00
|
|
|
|
2015-02-23 21:55:52 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class TransactionController.
|
2018-07-20 14:34:56 +02:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
2015-02-23 21:55:52 +01:00
|
|
|
*/
|
2016-05-01 06:59:08 +02:00
|
|
|
class TransactionController extends Controller
|
2015-02-23 21:55:52 +01:00
|
|
|
{
|
2018-08-11 06:39:29 +02:00
|
|
|
use ModelInformation, PeriodOverview;
|
2018-11-11 07:03:36 +01:00
|
|
|
/** @var AttachmentRepositoryInterface */
|
|
|
|
private $attachmentRepository;
|
2018-07-20 20:53:48 +02:00
|
|
|
/** @var JournalRepositoryInterface Journals and transactions overview */
|
2018-03-25 13:30:55 +02:00
|
|
|
private $repository;
|
|
|
|
|
2015-02-23 21:55:52 +01:00
|
|
|
/**
|
2016-10-21 19:20:03 +02:00
|
|
|
* TransactionController constructor.
|
2015-02-23 21:55:52 +01:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-04-28 15:26:30 +02:00
|
|
|
parent::__construct();
|
2016-10-29 07:44:46 +02:00
|
|
|
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-07-15 09:38:49 +02:00
|
|
|
app('view')->share('title', (string)trans('firefly.transactions'));
|
2017-12-16 19:46:36 +01:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-repeat');
|
2018-11-11 07:03:36 +01:00
|
|
|
$this->repository = app(JournalRepositoryInterface::class);
|
|
|
|
$this->attachmentRepository = app(AttachmentRepositoryInterface::class);
|
2016-10-29 07:44:46 +02:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2015-02-27 14:27:04 +01:00
|
|
|
}
|
|
|
|
|
2018-03-25 13:30:55 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Do a reconciliation.
|
|
|
|
*
|
2018-03-25 13:30:55 +02:00
|
|
|
* @param Request $request
|
2017-12-17 14:30:53 +01:00
|
|
|
*
|
2018-06-09 07:09:43 +02:00
|
|
|
* @return JsonResponse
|
2017-11-05 19:48:43 +01:00
|
|
|
*/
|
2018-06-09 07:09:43 +02:00
|
|
|
public function reconcile(Request $request): JsonResponse
|
2017-11-05 19:48:43 +01:00
|
|
|
{
|
|
|
|
$transactionIds = $request->get('transactions');
|
|
|
|
foreach ($transactionIds as $transactionId) {
|
2018-03-25 13:30:55 +02:00
|
|
|
$transactionId = (int)$transactionId;
|
|
|
|
$transaction = $this->repository->findTransaction($transactionId);
|
2018-07-09 19:24:08 +02:00
|
|
|
if (null !== $transaction) {
|
|
|
|
Log::debug(sprintf('Transaction ID is %d', $transaction->id));
|
|
|
|
$this->repository->reconcile($transaction);
|
|
|
|
}
|
2017-11-05 19:48:43 +01:00
|
|
|
}
|
2017-12-22 18:32:43 +01:00
|
|
|
|
2018-03-10 20:30:09 +01:00
|
|
|
return response()->json(['ok' => 'reconciled']);
|
2017-11-05 19:48:43 +01:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:59:08 +02:00
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Reorder transactions.
|
|
|
|
*
|
2018-03-25 13:30:55 +02:00
|
|
|
* @param Request $request
|
2016-05-01 06:59:08 +02:00
|
|
|
*
|
2016-05-15 12:08:41 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2018-07-20 14:34:56 +02:00
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
2016-05-01 06:59:08 +02:00
|
|
|
*/
|
2018-07-08 12:28:42 +02:00
|
|
|
public function reorder(Request $request): JsonResponse
|
2016-05-01 06:59:08 +02:00
|
|
|
{
|
2016-05-15 12:08:41 +02:00
|
|
|
$ids = $request->get('items');
|
|
|
|
$date = new Carbon($request->get('date'));
|
2019-05-30 12:31:19 +02:00
|
|
|
if (count($ids) > 0) {
|
2016-05-01 06:59:08 +02:00
|
|
|
$order = 0;
|
2016-10-10 07:49:39 +02:00
|
|
|
$ids = array_unique($ids);
|
2016-05-01 06:59:08 +02:00
|
|
|
foreach ($ids as $id) {
|
2018-07-08 07:59:58 +02:00
|
|
|
$journal = $this->repository->findNull((int)$id);
|
|
|
|
if (null !== $journal && $journal->date->isSameDay($date)) {
|
2018-03-25 13:30:55 +02:00
|
|
|
$this->repository->setOrder($journal, $order);
|
2017-11-15 12:25:49 +01:00
|
|
|
++$order;
|
2016-05-01 06:59:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-08 12:08:53 +02:00
|
|
|
app('preferences')->mark();
|
2016-05-01 06:59:08 +02:00
|
|
|
|
2018-03-10 20:30:09 +01:00
|
|
|
return response()->json([true]);
|
2016-05-01 06:59:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 19:10:17 +01:00
|
|
|
|
2016-05-01 06:59:08 +02:00
|
|
|
}
|