2023-02-08 16:49:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Orders;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Order\DeliveryStatus;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
|
|
|
|
|
|
class ChangeOrderDeliveryStatusRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize()
|
|
|
|
|
{
|
|
|
|
|
return auth('backend')->check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'delivery_status' => [
|
2023-05-19 15:17:33 +02:00
|
|
|
'required',
|
|
|
|
|
new EnumIsValidRule(DeliveryStatus::class),
|
2023-02-08 16:49:28 +01:00
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
|
|
|
function ($attribute, $value, $fail) {
|
|
|
|
|
$deliveryStatus = DeliveryStatus::make(\intval($this->delivery_status));
|
2023-03-15 17:51:01 +01:00
|
|
|
// * Ignorer commande en préparation.
|
|
|
|
|
if ($deliveryStatus->equals(DeliveryStatus::preparation())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-08 16:49:28 +01:00
|
|
|
if ($this->order->delivery_status->value > $deliveryStatus->value) {
|
|
|
|
|
$fail(trans(':attribute Il n\'est pas possible de revenir en arrière sur le statut'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($deliveryStatus->value - $this->order->delivery_status->value !== 1) {
|
|
|
|
|
$fail(trans(':attribute Il n\'est possible de modifier le statut que sur le statut suivant'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'delivery_status' => trans('Statut de livraison')
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-05-19 15:17:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom messages for validator errors.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function messages()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'delivery_status.required' => \trans(
|
|
|
|
|
'Le champ :attribute ne peut être modifié qu\'en sélectionnant une valeur non grisée'
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-02-08 16:49:28 +01:00
|
|
|
}
|