Files
firefly-iii/app/Http/Requests/BillUpdateRequest.php

88 lines
3.3 KiB
PHP
Raw Normal View History

2015-02-25 15:19:14 +01:00
<?php
2022-12-29 19:42:26 +01:00
/**
2020-06-30 19:06:05 +02:00
* BillUpdateRequest.php
2020-01-31 07:32:04 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* 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.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +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/>.
*/
2017-03-24 15:15:12 +01:00
declare(strict_types=1);
2015-02-25 15:19:14 +01:00
namespace FireflyIII\Http\Requests;
2018-08-07 19:24:07 +02:00
use FireflyIII\Models\Bill;
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;
2018-08-07 19:24:07 +02:00
2015-02-25 15:19:14 +01:00
/**
2020-06-30 19:06:05 +02:00
* Class BillUpdateRequest.
2015-02-25 15:19:14 +01:00
*/
2020-10-24 07:55:09 +02:00
class BillUpdateRequest extends FormRequest
2015-02-25 15:19:14 +01:00
{
2022-10-30 14:24:28 +01:00
use ConvertsDataTypes;
use ChecksLogin;
2015-02-25 15:19:14 +01:00
2015-03-29 11:51:26 +02:00
/**
2018-07-22 08:10:16 +02:00
* Returns the data required by the controller.
*
2015-03-29 11:51:26 +02:00
* @return array
*/
2018-07-08 12:28:42 +02:00
public function getBillData(): array
2015-03-29 11:51:26 +02:00
{
return [
2022-05-02 19:35:35 +02:00
'name' => $this->convertString('name'),
'amount_min' => $this->convertString('amount_min'),
2022-09-30 20:07:01 +02:00
'currency_id' => $this->convertInteger('transaction_currency_id'),
2021-03-15 07:45:46 +01:00
'currency_code' => '',
2022-05-02 19:35:35 +02:00
'amount_max' => $this->convertString('amount_max'),
2021-12-28 20:42:50 +01:00
'date' => $this->getCarbonDate('date'),
2022-03-28 12:23:46 +02:00
'end_date' => $this->getCarbonDate('bill_end_date'),
'extension_date' => $this->getCarbonDate('extension_date'),
2022-05-02 19:35:35 +02:00
'repeat_freq' => $this->convertString('repeat_freq'),
2022-09-30 20:07:01 +02:00
'skip' => $this->convertInteger('skip'),
2021-04-06 13:30:09 +02:00
'notes' => $this->stringWithNewlines('notes'),
2021-03-15 07:45:46 +01:00
'active' => $this->boolean('active'),
2022-05-02 19:35:35 +02:00
'object_group_title' => $this->convertString('object_group'),
2015-03-29 11:51:26 +02:00
];
}
2015-02-25 15:19:14 +01:00
/**
2018-07-22 08:10:16 +02:00
* Rules for this request.
*
2015-02-25 15:19:14 +01:00
* @return array
*/
2018-07-02 20:17:50 +02:00
public function rules(): array
2015-02-25 15:19:14 +01:00
{
2018-08-07 19:24:07 +02:00
/** @var Bill $bill */
$bill = $this->route()->parameter('bill');
2020-06-30 19:06:05 +02:00
return [
'name' => sprintf('required|between:1,255|uniqueObjectForUser:bills,name,%d', $bill->id),
2020-07-06 06:55:27 +02:00
'amount_min' => 'required|numeric|gt:0|max:1000000000',
'amount_max' => 'required|numeric|gt:0|max:1000000000',
2018-04-08 16:27:52 +02:00
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'date' => 'required|date',
2022-03-28 12:23:46 +02:00
'bill_end_date' => 'nullable|date',
'extension_date' => 'nullable|date',
2022-02-05 08:53:45 +01:00
'repeat_freq' => sprintf('required|in:%s', join(',', config('firefly.bill_periods'))),
'skip' => 'required|integer|gte:0|lte:31',
2018-06-24 16:17:42 +02:00
'active' => 'boolean',
'notes' => 'between:1,65536|nullable',
2015-02-25 15:19:14 +01:00
];
}
2015-03-29 08:14:32 +02:00
}