Fixes for service change, validation added for date and product_id
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 32s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
Deon George 2024-08-17 15:10:50 +10:00
parent 23f23dfe40
commit 283ae06a5c
6 changed files with 85 additions and 42 deletions

View File

@ -17,7 +17,7 @@ use Illuminate\Validation\ValidationException;
use Illuminate\View\View; use Illuminate\View\View;
use Symfony\Component\HttpKernel\Exception\HttpException; 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\Mail\{CancelRequest,ChangeRequest};
use App\Models\{Charge,Invoice,Product,Service}; use App\Models\{Charge,Invoice,Product,Service};
@ -219,45 +219,31 @@ class ServiceController extends Controller
/** /**
* Process a request to cancel a service * Process a request to cancel a service
* *
* @param Request $request * @param ServiceChange $request
* @param Service $o * @param Service $o
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|RedirectResponse|\Illuminate\Routing\Redirector * @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()) { $o->changes()->attach([$o->id=>[
$request->validate([ 'site_id'=> $o->site_id,
'product_id'=>'required|exists:products,id', 'ordered_by' => Auth::id(),
'change_date'=>'required|date', 'ordered_at' => Carbon::now(),
'notes'=>'nullable|min:10', '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=>[ $o->order_status = 'CHANGE-REQUEST';
'site_id'=> $o->site_id, $o->save();
'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'; Mail::to(config('osb.ticket_admin'))
$o->save(); ->queue((new ChangeRequest($o,$request->validated('notes')))->onQueue('email'));
Mail::to(config('osb.ticket_admin')) return redirect('u/service/'.$o->id)
->queue((new ChangeRequest($o,$request->notes))->onQueue('email')); ->with('success','Upgrade requested');
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);
}
} }
/** /**

View File

@ -0,0 +1,45 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
/**
* Editing Suppliers
*/
class ServiceChange 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()
{
return [
'change_date'=> [
'required',
'date',
'after:today',
],
'product_id' => [
'required',
'exists:products,id',
Rule::notIn([request()->route('o')->product_id]),
],
'notes' => 'nullable|min:5',
];
}
}

View File

@ -1065,6 +1065,11 @@ class Service extends Model implements IDs
return ! is_null($this->price); 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 * Identify if a service is being ordered, ie: not active yet nor cancelled
* *

View File

@ -3,17 +3,17 @@
@extends('adminlte::layouts.app') @extends('adminlte::layouts.app')
@section('htmlheader_title') @section('htmlheader_title')
{{ $o->sid }} {{ $so->sid }}
@endsection @endsection
@section('page_title') @section('page_title')
{{ $o->sid }} {{ $so->sid }}
@endsection @endsection
@section('contentheader_title') @section('contentheader_title')
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong> Service: {{ $so->sid }} <strong>{{ $so->product->name }}</strong>
@endsection @endsection
@section('contentheader_description') @section('contentheader_description')
{{ $o->name }} {{ $so->name }}
@endsection @endsection
@section('main-content') @section('main-content')
@ -32,17 +32,22 @@
<div class="col-8 col-sm-5 col-md-12 col-lg-6"> <div class="col-8 col-sm-5 col-md-12 col-lg-6">
<x-leenooks::form.date name="change_date" icon="fa-calendar" label="Request Change Date" :value="Carbon::now()->addDays(7)->format('Y-m-d')"/> <x-leenooks::form.date name="change_date" icon="fa-calendar" label="Request Change Date" :value="Carbon::now()->addDays(7)->format('Y-m-d')"/>
</div> </div>
@if($so->isContract())
<div class="col-12 col-sm-7 col-md-12 col-lg-6">
<strong>NOTE</strong>: This service is in a contract until <strong>{{ $so->contract_end->format('Y-m-d') }}</strong>, thus it may not be able to change plans.
</div>
@endif
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
@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])
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<x-leenooks::form.textarea name="notes" label="Notes" placeholder="Please let us know what you would like to change your service to" :value="$o->order_info_notes ?? ''"/> <x-leenooks::form.textarea name="notes" label="Notes" placeholder="Please let us know what you would like to change your service to" :value="$so->order_info_notes ?? ''"/>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,8 +1,8 @@
@use(App\Models\Product) @use(App\Models\Product)
@use(App\Models\Product\Broadband) @use(App\Models\Product\Broadband)
<x-leenooks::form.select id="product_id" name="product_id" icon="fa-list" label="Product" :helper="$o->category_name" <x-leenooks::form.select id="product_id" name="product_id" icon="fa-list" label="Product" :helper="$o->category_name" :choose="true"
:value="$o->id" :value="$o->service->product_id"
:options="Product::active()->get()->filter(fn($item)=>get_class($item->type) === Broadband::class)->sortBy('name')->sortByDesc('active')->transform(fn($item)=>['id'=>$item->id,'active'=>$item->active,'value'=>$item->name])" required/> :options="Product::active()->get()->filter(fn($item)=>get_class($item->type) === Broadband::class)->sortBy('name')->sortByDesc('active')->transform(fn($item)=>['id'=>$item->id,'active'=>$item->active,'value'=>$item->name])" required/>
<strong>NOTE</strong>: A plan setup fee is normally not applicable to Broadband changes, but a plan change fee normally is. <strong>NOTE</strong>: A plan setup fee is normally not applicable to Broadband changes, but a plan change fee normally is.

View File

@ -198,7 +198,9 @@ Route::group(['middleware'=>['auth'],'prefix'=>'u'],function() {
Route::post('service/{o}/cancel-request',[ServiceController::class,'cancel_request']) Route::post('service/{o}/cancel-request',[ServiceController::class,'cancel_request'])
->middleware('can:progress,o,"cancel-request"') ->middleware('can:progress,o,"cancel-request"')
->where('o','[0-9]+'); ->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"') ->middleware('can:progress,o,"change-request"')
->where('o','[0-9]+'); ->where('o','[0-9]+');
// @todo This shouldnt be a user privilege. // @todo This shouldnt be a user privilege.