Fixes for service change, validation added for date and product_id
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\{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',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user