1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Requests/Statements/CreateStatementRequest.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2021-08-24 13:18:32 +02:00
<?php
namespace App\Http\Requests\Statements;
2021-08-25 03:41:07 +02:00
use App\Http\Requests\Request;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
2021-08-24 13:18:32 +02:00
2021-08-25 03:41:07 +02:00
class CreateStatementRequest extends Request
2021-08-24 13:18:32 +02:00
{
2021-08-25 03:41:07 +02:00
use MakesHash;
2021-08-24 13:18:32 +02:00
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return auth()->user()->isAdmin();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
2021-08-25 04:03:58 +02:00
'start_date' => 'required|date_format:Y-m-d',
'end_date' => 'required|date_format:Y-m-d',
2021-09-14 13:55:41 +02:00
'client_id' => 'bail|required|exists:clients,id,company_id,' . auth()->user()->company()->id,
2021-08-25 03:41:07 +02:00
'show_payments_table' => 'boolean',
'show_aging_table' => 'boolean',
2021-08-24 13:18:32 +02:00
];
}
2021-09-14 13:55:41 +02:00
2021-08-25 03:41:07 +02:00
protected function prepareForValidation()
{
$input = $this->all();
2021-08-24 15:31:40 +02:00
2021-08-25 03:41:07 +02:00
$input = $this->decodePrimaryKeys($input);
2021-08-24 15:31:40 +02:00
2021-09-14 13:55:41 +02:00
$this->replace($input);
2021-08-24 15:31:40 +02:00
}
2021-09-14 13:55:41 +02:00
public function client(): ?Client
2021-08-25 03:41:07 +02:00
{
2021-09-14 13:55:41 +02:00
return Client::where('id', $this->client_id)->first();
2021-08-25 03:41:07 +02:00
}
2021-08-24 13:18:32 +02:00
}