From 683aa2c038f30024b4472a93f8aefea297491d7f Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 17 Aug 2024 15:10:50 +1000 Subject: [PATCH] Fixes for service change, validation added for date and product_id --- app/Http/Controllers/ServiceController.php | 52 +++++++------------ app/Models/Service.php | 5 ++ .../adminlte/service/change_request.blade.php | 17 +++--- .../service/widget/broadband/change.blade.php | 4 +- routes/web.php | 4 +- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index 2f4520b..c9fc269 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -17,7 +17,7 @@ use Illuminate\Validation\ValidationException; use Illuminate\View\View; use Symfony\Component\HttpKernel\Exception\HttpException; -use App\Http\Requests\{ServiceCancel,ServiceChangeRequest}; +use App\Http\Requests\{ServiceCancel,ServiceChange,ServiceChangeRequest}; use App\Mail\{CancelRequest,ChangeRequest}; use App\Models\{Charge,Invoice,Product,Service}; @@ -219,45 +219,31 @@ class ServiceController extends Controller /** * Process a request to cancel a service * - * @param Request $request + * @param ServiceChange $request * @param Service $o * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|RedirectResponse|\Illuminate\Routing\Redirector */ - public function change_request(Request $request,Service $o) + public function change_request(ServiceChange $request,Service $o) { - if ($request->post()) { - $request->validate([ - 'product_id'=>'required|exists:products,id', - 'change_date'=>'required|date', - 'notes'=>'nullable|min:10', - ]); + $o->changes()->attach([$o->id=>[ + 'site_id'=> $o->site_id, + 'ordered_by' => Auth::id(), + 'ordered_at' => Carbon::now(), + 'effective_at' => $request->validated('change_date'), + 'product_id' => $request->validated('product_id'), + 'notes' => $request->validated('notes'), + 'active' => TRUE, + 'complete' => FALSE, + ]]); - $o->changes()->attach([$o->id=>[ - 'site_id'=> $o->site_id, - 'ordered_by' => Auth::id(), - 'ordered_at' => Carbon::now(), - 'effective_at' => $request->change_date, - 'product_id' => $request->product_id, - 'notes' => $request->notes, - 'active' => TRUE, - 'complete' => FALSE, - ]]); + $o->order_status = 'CHANGE-REQUEST'; + $o->save(); - $o->order_status = 'CHANGE-REQUEST'; - $o->save(); + Mail::to(config('osb.ticket_admin')) + ->queue((new ChangeRequest($o,$request->validated('notes')))->onQueue('email')); - Mail::to(config('osb.ticket_admin')) - ->queue((new ChangeRequest($o,$request->notes))->onQueue('email')); - - return redirect('u/service/'.$o->id)->with('success','Upgrade requested'); - } - - switch (get_class($o->type)) { - default: - return view('theme.backend.adminlte.service.change_request') - ->with('breadcrumb',collect()->merge($o->account->breadcrumb)) - ->with('o',$o); - } + return redirect('u/service/'.$o->id) + ->with('success','Upgrade requested'); } /** diff --git a/app/Models/Service.php b/app/Models/Service.php index 5ece2a1..16a6441 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -1065,6 +1065,11 @@ class Service extends Model implements IDs return ! is_null($this->price); } + public function isContract(): bool + { + return $this->getContractEndAttribute()->greaterThan(Carbon::now()); + } + /** * Identify if a service is being ordered, ie: not active yet nor cancelled * diff --git a/resources/views/theme/backend/adminlte/service/change_request.blade.php b/resources/views/theme/backend/adminlte/service/change_request.blade.php index e0c9022..47b0b5f 100644 --- a/resources/views/theme/backend/adminlte/service/change_request.blade.php +++ b/resources/views/theme/backend/adminlte/service/change_request.blade.php @@ -3,17 +3,17 @@ @extends('adminlte::layouts.app') @section('htmlheader_title') - {{ $o->sid }} + {{ $so->sid }} @endsection @section('page_title') - {{ $o->sid }} + {{ $so->sid }} @endsection @section('contentheader_title') - Service: {{ $o->sid }} {{ $o->product->name }} + Service: {{ $so->sid }} {{ $so->product->name }} @endsection @section('contentheader_description') - {{ $o->name }} + {{ $so->name }} @endsection @section('main-content') @@ -32,17 +32,22 @@
+ @if($so->isContract()) +
+ NOTE: This service is in a contract until {{ $so->contract_end->format('Y-m-d') }}, thus it may not be able to change plans. +
+ @endif
- @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.change',['o'=>$o->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$so->product->category.'.change',['o'=>$so->type])
- +
diff --git a/resources/views/theme/backend/adminlte/service/widget/broadband/change.blade.php b/resources/views/theme/backend/adminlte/service/widget/broadband/change.blade.php index 27f854f..7d3d888 100644 --- a/resources/views/theme/backend/adminlte/service/widget/broadband/change.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/broadband/change.blade.php @@ -1,8 +1,8 @@ @use(App\Models\Product) @use(App\Models\Product\Broadband) - NOTE: A plan setup fee is normally not applicable to Broadband changes, but a plan change fee normally is. diff --git a/routes/web.php b/routes/web.php index b0de248..2bd8cd9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -198,7 +198,9 @@ Route::group(['middleware'=>['auth'],'prefix'=>'u'],function() { Route::post('service/{o}/cancel-request',[ServiceController::class,'cancel_request']) ->middleware('can:progress,o,"cancel-request"') ->where('o','[0-9]+'); - Route::match(['get','post'],'service/{o}/change-request',[ServiceController::class,'change_request']) + Route::view('service/{so}/change-request','theme.backend.adminlte.service.change_request') + ->where('so','[0-9]+'); + Route::post('service/{o}/change-request',[ServiceController::class,'change_request']) ->middleware('can:progress,o,"change-request"') ->where('o','[0-9]+'); // @todo This shouldnt be a user privilege.