akaunting/app/Http/Requests/Banking/Transaction.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2019-11-16 10:21:14 +03:00
namespace App\Http\Requests\Banking;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\FormRequest;
use App\Utilities\Date;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
class Transaction extends FormRequest
2017-09-14 22:21:00 +03:00
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2019-11-16 10:21:14 +03:00
$attachment = 'nullable';
2021-05-14 18:29:24 +03:00
if ($this->files->get('attachment')) {
2019-11-16 10:21:14 +03:00
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}
2017-09-14 22:21:00 +03:00
return [
2019-11-16 10:21:14 +03:00
'type' => 'required|string',
2017-09-14 22:21:00 +03:00
'account_id' => 'required|integer',
2018-09-05 16:43:50 +03:00
'paid_at' => 'required|date_format:Y-m-d H:i:s',
'amount' => 'required|amount',
'currency_code' => 'required|string|currency',
'currency_rate' => 'required|gt:0',
2019-11-16 10:21:14 +03:00
'document_id' => 'nullable|integer',
'contact_id' => 'nullable|integer',
2017-09-14 22:21:00 +03:00
'category_id' => 'required|integer',
'payment_method' => 'required|string',
2021-02-10 12:08:16 +03:00
'attachment.*' => $attachment,
'recurring_count' => 'gte:0',
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
2017-09-14 22:21:00 +03:00
];
}
public function withValidator($validator)
{
if ($validator->errors()->count()) {
$paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
$this->request->set('paid_at', $paid_at);
}
}
2017-09-14 22:21:00 +03:00
}