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;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-08-24 13:18:32 +02:00
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2022-04-02 07:13:31 +02:00
|
|
|
// return auth()->user()->isAdmin();
|
|
|
|
|
|
|
|
return auth()->user()->can('view', $this->client());
|
2021-08-24 13:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
2022-06-21 11:57:17 +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',
|
2023-04-19 04:31:27 +02:00
|
|
|
'show_credits_table' => 'boolean',
|
2022-01-03 08:22:10 +01:00
|
|
|
'status' => 'string',
|
2021-08-24 13:18:32 +02:00
|
|
|
];
|
|
|
|
}
|
2021-09-14 13:55:41 +02:00
|
|
|
|
2022-06-24 03:55:41 +02:00
|
|
|
public function prepareForValidation()
|
2021-08-25 03:41:07 +02:00
|
|
|
{
|
|
|
|
$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-09-20 14:54:44 +02:00
|
|
|
|
|
|
|
$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,
|
2023-04-26 02:56:23 +02:00
|
|
|
'show_credits_table' => $this->has('show_credits_table') ? \boolval($this->show_credits_table) : false,
|
2021-09-20 14:54:44 +02:00
|
|
|
]);
|
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
|
|
|
{
|
2022-04-02 07:13:31 +02:00
|
|
|
return Client::without('company')->where('id', $this->client_id)->withTrashed()->first();
|
2021-08-25 03:41:07 +02:00
|
|
|
}
|
2021-08-24 13:18:32 +02:00
|
|
|
}
|