49 lines
1.9 KiB
PHP
49 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Invoices;
|
|
|
|
use App\Enums\Invoices\InvoiceStatusEnum;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class UpdateInvoiceRequest extends StoreInvoiceRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [];
|
|
$model = $this->route('invoice');
|
|
if ($model->status->value === InvoiceStatusEnum::opened->value) {
|
|
if (!$model->sent_client_date) {
|
|
$rules = array_merge($rules, parent::rules());
|
|
}
|
|
$rules = array_merge($rules, [
|
|
'comment' => 'sometimes|nullable|string|min:15',
|
|
'sent_client_date' => 'required_with:signed_date,sent_accounting_date|sometimes|nullable|date',
|
|
'signed_date' => 'required_with:sent_accounting_date|sometimes|nullable|date',
|
|
'sent_accounting_date' => 'sometimes|nullable|date',
|
|
'status' => [
|
|
'required',
|
|
new Enum(InvoiceStatusEnum::class),
|
|
//phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) use ($model) {
|
|
if (
|
|
(intval($value) === InvoiceStatusEnum::archived->value) &&
|
|
(is_null($model->sent_client_date) ||
|
|
is_null($model->signed_date) ||
|
|
is_null($model->sent_accounting_date))
|
|
) {
|
|
$fail(__('Le status :status doit être assigné lorsque les 3 dates sont saisies', [
|
|
'status' => InvoiceStatusEnum::archived->label()
|
|
]));
|
|
}
|
|
},
|
|
],
|
|
]);
|
|
} //end if
|
|
return $rules;
|
|
}
|
|
}
|