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

68 lines
1.8 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
{
2023-09-25 05:19:08 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2022-04-02 07:13:31 +02:00
2023-09-25 05:19:08 +02:00
return $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()
{
2023-09-25 05:19:08 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2021-08-24 13:18:32 +02:00
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',
2023-09-25 05:19:08 +02:00
'client_id' => 'bail|required|exists:clients,id,company_id,'.$user->company()->id,
2021-08-25 03:41:07 +02:00
'show_payments_table' => 'boolean',
'show_aging_table' => 'boolean',
'show_credits_table' => 'boolean',
'status' => 'string',
2023-09-25 05:19:08 +02:00
'template' => 'sometimes|string|nullable',
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);
$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-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
{
2023-08-06 09:35:19 +02:00
return Client::query()->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
}