Reimplmement service changes going to the service__change table

This commit is contained in:
2023-05-06 13:53:14 +10:00
parent 691180b3f0
commit 013bb632d3
9 changed files with 181 additions and 26 deletions

View File

@@ -67,7 +67,11 @@ class ServiceController extends Controller
if (! $o->order_info)
$o->order_info = collect();
$o->order_info->put('change_cancel',Carbon::now()->format('Y-m-d H:i:s'));
// @todo add some validation if this doesnt return a result
$np = $o->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop();
$np->pivot->active = FALSE;
$np->pivot->save();
$o->order_status = 'ACTIVE';
return $o->save();
@@ -91,6 +95,9 @@ class ServiceController extends Controller
public function change_pending(ServiceChangeRequest $request,Service $o)
{
// @todo add some validation if this doesnt return a result
$np = $o->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop();
if ($request->post()) {
foreach ($this->service_change_charges($request,$o) as $co)
$co->save();
@@ -100,12 +107,17 @@ class ServiceController extends Controller
$o->order_status = 'ACTIVE';
$o->save();
$np->pivot->complete = TRUE;
$np->pivot->effective_at = Carbon::now();
$np->pivot->save();
return redirect()->to(url('u/service',[$o->id]));
}
return view('service.change_pending')
->with('breadcrumb',collect()->merge($o->account->breadcrumb))
->with('o',$o);
->with('o',$o)
->with('np',$np);
}
/**
@@ -218,16 +230,22 @@ class ServiceController extends Controller
{
if ($request->post()) {
$request->validate([
'product_id'=>'required|exists:products,id',
'change_date'=>'required|date',
'notes'=>'required|min:10',
'notes'=>'nullable|min:10',
]);
if (! $o->order_info)
$o->order_info = collect();
$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_info->put('change_note',$request->notes);
$o->order_info->put('change_date',$request->change_date);
$o->order_info->put('change_product_id',$request->product_id);
$o->order_status = 'CHANGE-REQUEST';
$o->save();