Add validation to service cancellation, and displaying cancellation costs if any
This commit is contained in:
@@ -17,7 +17,7 @@ use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
use App\Http\Requests\ServiceChangeRequest;
|
||||
use App\Http\Requests\{ServiceCancel,ServiceChangeRequest};
|
||||
use App\Mail\{CancelRequest,ChangeRequest};
|
||||
use App\Models\{Charge,Invoice,Product,Service};
|
||||
|
||||
@@ -124,34 +124,29 @@ class ServiceController extends Controller
|
||||
/**
|
||||
* Process a request to cancel a service
|
||||
*
|
||||
* @param Request $request
|
||||
* @param ServiceCancel $request
|
||||
* @param Service $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function cancel_request(Request $request,Service $o)
|
||||
public function cancel_request(ServiceCancel $request,Service $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$request->validate([
|
||||
'stop_at'=>'required|date',
|
||||
]);
|
||||
if (! $o->order_info)
|
||||
$o->order_info = collect();
|
||||
|
||||
if (! $o->order_info)
|
||||
$o->order_info = collect();
|
||||
$o->stop_at = $request->stop_at;
|
||||
$o->order_info->put('cancel_note',$request->validated('notes'));
|
||||
|
||||
$o->stop_at = $request->stop_at;
|
||||
$o->order_info->put('cancel_note',$request->notes);
|
||||
$o->order_status = 'CANCEL-REQUEST';
|
||||
$o->save();
|
||||
if ($request->validated('extra_charges'))
|
||||
$o->order_info->put('cancel_extra_charges_accepted',$request->extra_charges_amount);
|
||||
|
||||
//@todo Get email from DB.
|
||||
Mail::to('help@graytech.net.au')
|
||||
->queue((new CancelRequest($o,$request->notes))->onQueue('email'));
|
||||
$o->order_status = 'CANCEL-REQUEST';
|
||||
$o->save();
|
||||
|
||||
return redirect('u/service/'.$o->id)->with('success','Cancellation lodged');
|
||||
}
|
||||
Mail::to(config('osb.ticket_admin'))
|
||||
->queue((new CancelRequest($o,$request->notes))->onQueue('email'));
|
||||
|
||||
return view('theme.backend.adminlte.service.cancel_request')
|
||||
->with('o',$o);
|
||||
return redirect('u/service/'.$o->id)
|
||||
->with('success','Cancellation lodged');
|
||||
}
|
||||
|
||||
/**
|
||||
|
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