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

61 lines
1.5 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
{
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',
'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',
'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);
$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
{
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
}