1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Requests/Statements/CreateStatementRequest.php

57 lines
1.4 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);
$this->merge([
'show_payments_table' => $this->has('show_payments_table') ? \boolval($this->show_payments_table) : false,
'show_aging_table' => $this->has('show_aging_table') ? \boolval($this->show_aging_table) : false,
]);
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
{
return Client::with('company')->where('id', $this->client_id)->withTrashed()->first();
2021-08-25 03:41:07 +02:00
}
2021-08-24 13:18:32 +02:00
}