2018-02-23 15:13:01 +01:00
|
|
|
<?php
|
2024-11-25 04:18:55 +01:00
|
|
|
|
2018-02-23 15:13:01 +01:00
|
|
|
/**
|
|
|
|
* ReconciliationStoreRequest.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-02-23 15:13:01 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-02-23 15:13:01 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-02-23 15:13:01 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-02-23 15:13:01 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-02-23 15:13:01 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-02-23 15:13:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
2024-01-02 14:33:17 +01:00
|
|
|
use FireflyIII\Rules\IsValidAmount;
|
2019-06-23 05:53:01 +02:00
|
|
|
use FireflyIII\Rules\ValidJournals;
|
2020-10-24 07:55:09 +02:00
|
|
|
use FireflyIII\Support\Request\ChecksLogin;
|
2020-07-18 08:42:13 +02:00
|
|
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
2020-10-24 07:55:09 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2024-01-09 21:03:26 +01:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Validation\Validator;
|
2018-02-23 15:13:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ReconciliationStoreRequest
|
|
|
|
*/
|
2020-10-24 07:55:09 +02:00
|
|
|
class ReconciliationStoreRequest extends FormRequest
|
2018-02-23 15:13:01 +01:00
|
|
|
{
|
2022-10-30 14:24:28 +01:00
|
|
|
use ChecksLogin;
|
2023-11-04 14:18:49 +01:00
|
|
|
use ConvertsDataTypes;
|
2018-02-23 15:13:01 +01:00
|
|
|
|
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Returns the data required by the controller.
|
2018-02-23 15:13:01 +01:00
|
|
|
*/
|
|
|
|
public function getAll(): array
|
|
|
|
{
|
2019-06-22 13:09:25 +02:00
|
|
|
$transactions = $this->get('journals');
|
|
|
|
if (!is_array($transactions)) {
|
2021-09-18 10:26:12 +02:00
|
|
|
$transactions = [];
|
2018-02-23 15:13:01 +01:00
|
|
|
}
|
2024-01-01 14:43:56 +01:00
|
|
|
$data = [
|
2021-12-28 20:42:50 +01:00
|
|
|
'start' => $this->getCarbonDate('start'),
|
|
|
|
'end' => $this->getCarbonDate('end'),
|
2022-05-02 19:35:35 +02:00
|
|
|
'start_balance' => $this->convertString('startBalance'),
|
|
|
|
'end_balance' => $this->convertString('endBalance'),
|
|
|
|
'difference' => $this->convertString('difference'),
|
2019-06-23 05:53:01 +02:00
|
|
|
'journals' => $transactions,
|
2022-05-02 19:35:35 +02:00
|
|
|
'reconcile' => $this->convertString('reconcile'),
|
2018-02-23 15:13:01 +01:00
|
|
|
];
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('In ReconciliationStoreRequest::getAll(). Will now return data.');
|
2018-02-23 15:13:01 +01:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Rules for this request.
|
2018-02-23 15:13:01 +01:00
|
|
|
*/
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'start' => 'required|date',
|
|
|
|
'end' => 'required|date',
|
2024-01-02 14:33:17 +01:00
|
|
|
'startBalance' => ['nullable', new IsValidAmount()],
|
|
|
|
'endBalance' => ['nullable', new IsValidAmount()],
|
|
|
|
'difference' => ['required', new IsValidAmount()],
|
2022-10-30 14:24:28 +01:00
|
|
|
'journals' => [new ValidJournals()],
|
2018-02-23 15:13:01 +01:00
|
|
|
'reconcile' => 'required|in:create,nothing',
|
|
|
|
];
|
|
|
|
}
|
2024-01-09 21:03:26 +01:00
|
|
|
|
|
|
|
public function withValidator(Validator $validator): void
|
|
|
|
{
|
2024-02-22 01:29:01 +01:00
|
|
|
if ($validator->fails()) {
|
2024-01-09 21:03:26 +01:00
|
|
|
Log::channel('audit')->error(sprintf('Validation errors in %s', __CLASS__), $validator->errors()->toArray());
|
|
|
|
}
|
|
|
|
}
|
2018-03-05 19:35:58 +01:00
|
|
|
}
|