Add validation to service cancellation, and displaying cancellation costs if any
This commit is contained in:
54
app/Http/Requests/ServiceCancel.php
Normal file
54
app/Http/Requests/ServiceCancel.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
*/
|
||||
class ServiceCancel extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Gate::allows('view',$this->route('o'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
//dd(request()->post());
|
||||
return [
|
||||
'stop_at'=> [
|
||||
'required',
|
||||
'date',
|
||||
'after:today',
|
||||
'exclude_unless:extra_charges,null',
|
||||
function($attribute,$value,$fail) {
|
||||
if ($this->route('o')->cancel_date->greaterThan($value))
|
||||
$fail(sprintf('Service cannot be cancelled before: %s',$this->route('o')->cancel_date->format('Y-m-d')));
|
||||
}
|
||||
],
|
||||
'extra_charges_amount' => [
|
||||
'nullable',
|
||||
'exclude_unless:extra_charges,null',
|
||||
function($attribute,$value,$fail) {
|
||||
if ($this->route('o')->cancel_date->greaterThan(request('stop_at')) && (request('extra_charges') !== 1))
|
||||
$fail('Extra charges must be accepted if cancelling before contract end');
|
||||
},
|
||||
],
|
||||
'extra_charges' => 'sometimes|required|accepted',
|
||||
'notes' => 'nullable|min:5',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user