Fixes for service change, validation added for date and product_id
This commit is contained in:
parent
23f23dfe40
commit
283ae06a5c
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
45
app/Http/Requests/ServiceChange.php
Normal file
45
app/Http/Requests/ServiceChange.php
Normal 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',
|
||||
];
|
||||
}
|
||||
}
|
@ -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
|
||||
*
|
||||
|
@ -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 }} <strong>{{ $o->product->name }}</strong>
|
||||
Service: {{ $so->sid }} <strong>{{ $so->product->name }}</strong>
|
||||
@endsection
|
||||
@section('contentheader_description')
|
||||
{{ $o->name }}
|
||||
{{ $so->name }}
|
||||
@endsection
|
||||
|
||||
@section('main-content')
|
||||
@ -32,17 +32,22 @@
|
||||
<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')"/>
|
||||
</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 class="row">
|
||||
<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 class="row">
|
||||
<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>
|
||||
|
@ -1,8 +1,8 @@
|
||||
@use(App\Models\Product)
|
||||
@use(App\Models\Product\Broadband)
|
||||
|
||||
<x-leenooks::form.select id="product_id" name="product_id" icon="fa-list" label="Product" :helper="$o->category_name"
|
||||
:value="$o->id"
|
||||
<x-leenooks::form.select id="product_id" name="product_id" icon="fa-list" label="Product" :helper="$o->category_name" :choose="true"
|
||||
: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/>
|
||||
|
||||
<strong>NOTE</strong>: A plan setup fee is normally not applicable to Broadband changes, but a plan change fee normally is.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user