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 @@