2015-02-25 15:19:14 +01:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* BillFormRequest.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
|
|
|
|
2016-02-05 12:08:25 +01:00
|
|
|
declare(strict_types = 1);
|
2015-02-25 15:19:14 +01:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
2015-03-29 11:51:26 +02:00
|
|
|
use Carbon\Carbon;
|
2015-02-25 15:19:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BillFormRequest
|
|
|
|
*
|
2016-02-04 07:28:39 +01:00
|
|
|
*
|
2015-02-25 15:19:14 +01:00
|
|
|
* @package FireflyIII\Http\Requests
|
|
|
|
*/
|
|
|
|
class BillFormRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
// Only allow logged in users
|
2016-09-16 12:07:45 +02:00
|
|
|
return auth()->check();
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
|
|
|
|
2015-03-29 11:51:26 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBillData()
|
|
|
|
{
|
|
|
|
return [
|
2015-12-26 08:12:44 +01:00
|
|
|
'name' => $this->get('name'),
|
|
|
|
'match' => $this->get('match'),
|
2016-12-30 13:45:02 +01:00
|
|
|
'amount_min' => round($this->get('amount_min'), 12),
|
2015-12-26 08:12:44 +01:00
|
|
|
'amount_currency_id_amount_min' => intval($this->get('amount_currency_id_amount_min')),
|
|
|
|
'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')),
|
2016-12-30 13:45:02 +01:00
|
|
|
'amount_max' => round($this->get('amount_max'), 12),
|
2015-12-26 08:12:44 +01:00
|
|
|
'date' => new Carbon($this->get('date')),
|
|
|
|
'repeat_freq' => $this->get('repeat_freq'),
|
|
|
|
'skip' => intval($this->get('skip')),
|
|
|
|
'automatch' => intval($this->get('automatch')) === 1,
|
|
|
|
'active' => intval($this->get('active')) === 1,
|
2015-03-29 11:51:26 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-02-25 15:19:14 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2015-06-05 12:34:45 +02:00
|
|
|
$nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name';
|
|
|
|
$matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match';
|
2016-10-23 12:19:32 +02:00
|
|
|
if (intval($this->get('id')) > 0) {
|
|
|
|
$nameRule .= ',' . intval($this->get('id'));
|
|
|
|
$matchRule .= ',' . intval($this->get('id'));
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$rules = [
|
2015-12-26 08:12:44 +01:00
|
|
|
'name' => $nameRule,
|
|
|
|
'match' => $matchRule,
|
|
|
|
'amount_min' => 'required|numeric|min:0.01',
|
|
|
|
'amount_max' => 'required|numeric|min:0.01',
|
|
|
|
'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 15:19:14 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
2015-03-29 08:14:32 +02:00
|
|
|
}
|