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

85 lines
3.2 KiB
PHP
Raw Normal View History

2015-02-25 08:19:14 -06:00
<?php
/**
2020-06-30 12:06:05 -05:00
* BillUpdateRequest.php
2020-01-31 00:32:04 -06: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 01:40:00 -05:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 01:40:00 -05: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 01:40:00 -05: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 09:15:12 -05:00
declare(strict_types=1);
2015-02-25 08:19:14 -06:00
namespace FireflyIII\Http\Requests;
2018-08-07 12:24:07 -05:00
use FireflyIII\Models\Bill;
2020-10-24 00:55:09 -05:00
use FireflyIII\Support\Request\ChecksLogin;
2020-07-18 01:42:13 -05:00
use FireflyIII\Support\Request\ConvertsDataTypes;
2020-10-24 00:55:09 -05:00
use Illuminate\Foundation\Http\FormRequest;
2018-08-07 12:24:07 -05:00
2015-02-25 08:19:14 -06:00
/**
2020-06-30 12:06:05 -05:00
* Class BillUpdateRequest.
2015-02-25 08:19:14 -06:00
*/
2020-10-24 00:55:09 -05:00
class BillUpdateRequest extends FormRequest
2015-02-25 08:19:14 -06:00
{
2020-10-24 00:55:09 -05:00
use ConvertsDataTypes, ChecksLogin;
2015-02-25 08:19:14 -06:00
2015-03-29 04:51:26 -05:00
/**
2018-07-22 01:10:16 -05:00
* Returns the data required by the controller.
*
2015-03-29 04:51:26 -05:00
* @return array
*/
2018-07-08 05:28:42 -05:00
public function getBillData(): array
2015-03-29 04:51:26 -05:00
{
return [
2022-05-02 12:35:35 -05:00
'name' => $this->convertString('name'),
'amount_min' => $this->convertString('amount_min'),
2021-03-15 01:45:46 -05:00
'currency_id' => $this->integer('transaction_currency_id'),
'currency_code' => '',
2022-05-02 12:35:35 -05:00
'amount_max' => $this->convertString('amount_max'),
2021-12-28 13:42:50 -06:00
'date' => $this->getCarbonDate('date'),
2022-03-28 05:23:46 -05:00
'end_date' => $this->getCarbonDate('bill_end_date'),
'extension_date' => $this->getCarbonDate('extension_date'),
2022-05-02 12:35:35 -05:00
'repeat_freq' => $this->convertString('repeat_freq'),
2021-03-15 01:45:46 -05:00
'skip' => $this->integer('skip'),
2021-04-06 06:30:09 -05:00
'notes' => $this->stringWithNewlines('notes'),
2021-03-15 01:45:46 -05:00
'active' => $this->boolean('active'),
2022-05-02 12:35:35 -05:00
'object_group_title' => $this->convertString('object_group'),
2015-03-29 04:51:26 -05:00
];
}
2015-02-25 08:19:14 -06:00
/**
2018-07-22 01:10:16 -05:00
* Rules for this request.
*
2015-02-25 08:19:14 -06:00
* @return array
*/
2018-07-02 13:17:50 -05:00
public function rules(): array
2015-02-25 08:19:14 -06:00
{
2018-08-07 12:24:07 -05:00
/** @var Bill $bill */
$bill = $this->route()->parameter('bill');
2020-06-30 12:06:05 -05:00
return [
'name' => sprintf('required|between:1,255|uniqueObjectForUser:bills,name,%d', $bill->id),
2020-07-05 23:55:27 -05:00
'amount_min' => 'required|numeric|gt:0|max:1000000000',
'amount_max' => 'required|numeric|gt:0|max:1000000000',
2018-04-08 09:27:52 -05:00
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'date' => 'required|date',
2022-03-28 05:23:46 -05:00
'bill_end_date' => 'nullable|date',
'extension_date' => 'nullable|date',
2022-02-05 01:53:45 -06:00
'repeat_freq' => sprintf('required|in:%s', join(',', config('firefly.bill_periods'))),
'skip' => 'required|integer|gte:0|lte:31',
2018-06-24 09:17:42 -05:00
'active' => 'boolean',
2015-02-25 08:19:14 -06:00
];
}
2015-03-29 01:14:32 -05:00
}