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

89 lines
3.3 KiB
PHP
Raw Normal View History

2015-02-25 08:19:14 -06:00
<?php
/**
* BillFormRequest.php
2017-10-21 01:40:00 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
2017-10-21 01:40:00 -05: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 07:44:05 -06:00
* along with Firefly III. If not, see <http://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;
/**
2017-11-15 05:25:49 -06:00
* Class BillFormRequest.
2015-02-25 08:19:14 -06:00
*/
class BillFormRequest extends Request
{
/**
* @return bool
*/
public function authorize()
{
// Only allow logged in users
2016-09-16 05:07:45 -05:00
return auth()->check();
2015-02-25 08:19:14 -06:00
}
2015-03-29 04:51:26 -05:00
/**
* @return array
*/
public function getBillData()
{
return [
2017-01-21 01:32:23 -06:00
'name' => $this->string('name'),
'match' => $this->string('match'),
2017-11-17 22:45:58 -06:00
'amount_min' => $this->string('amount_min'),
2017-01-21 01:32:23 -06:00
'amount_currency_id_amount_min' => $this->integer('amount_currency_id_amount_min'),
'amount_currency_id_amount_max' => $this->integer('amount_currency_id_amount_max'),
2017-11-17 22:45:58 -06:00
'amount_max' => $this->string('amount_max'),
2017-01-21 01:32:23 -06:00
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
'automatch' => $this->boolean('automatch'),
'active' => $this->boolean('active'),
2017-11-25 13:54:42 -06:00
'notes' => $this->string('notes'),
2015-03-29 04:51:26 -05:00
];
}
2015-02-25 08:19:14 -06:00
/**
* @return array
*/
public function rules()
{
2015-06-05 05:34:45 -05:00
$nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name';
$matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match';
2017-12-23 10:42:07 -06:00
if ($this->integer('id') > 0) {
$nameRule .= ',' . $this->integer('id');
$matchRule .= ',' . $this->integer('id');
2015-02-25 08:19:14 -06:00
}
2017-09-12 14:44:31 -05:00
// is OK
2015-02-25 08:19:14 -06:00
$rules = [
2015-12-26 01:12:44 -06:00
'name' => $nameRule,
'match' => $matchRule,
2017-01-04 10:25:28 -06:00
'amount_min' => 'required|numeric|more:0',
'amount_max' => 'required|numeric|more:0',
2015-12-26 01:12:44 -06:00
'amount_currency_id_amount_min' => 'required|exists:transaction_currencies,id',
'amount_currency_id_amount_max' => 'required|exists:transaction_currencies,id',
'date' => 'required|date',
'repeat_freq' => 'required|in:weekly,monthly,quarterly,half-year,yearly',
'skip' => 'required|between:0,31',
'automatch' => 'in:1',
'active' => 'in:1',
2015-02-25 08:19:14 -06:00
];
return $rules;
}
2015-03-29 01:14:32 -05:00
}