Reimplmement service changes going to the service__change table
This commit is contained in:
@@ -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();
|
||||
|
||||
|
@@ -26,7 +26,7 @@ class ChangeRequest extends Mailable
|
||||
public function __construct(Service $o,string $notes='')
|
||||
{
|
||||
$this->service = $o;
|
||||
$this->notes = $notes;
|
||||
$this->notes = $notes ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,6 +28,11 @@ use App\Traits\SiteID;
|
||||
* Class Service
|
||||
* Services that belong to an account
|
||||
*
|
||||
* So each service attribute has:
|
||||
* - Offering, what product we supply (we make offerings from supplier's supplied products) - in the DB these are products/*
|
||||
* - Supplied, our supplier's product that is providing the service - in the DB these are supplier/*
|
||||
* - Type, what service we are providing, made up of a product we supply - in the DB these are service/*
|
||||
*
|
||||
* Attributes for services:
|
||||
* + additional_cost : Pending additional charges for this service (excluding setup) //@todo check all these are still valid
|
||||
* + billing_charge : Charge for this service each invoice period // @todo change to "charge"
|
||||
@@ -46,14 +51,10 @@ use App\Traits\SiteID;
|
||||
* + sid : System ID for service
|
||||
* + supplied : The model of the supplier's product used for this service.
|
||||
*
|
||||
* = Terminology:
|
||||
* - Offering, what product we supply (we make offerings from supplier's supplied products) - in the DB these are products/*
|
||||
* - Supplied, our supplier's product that is providing the service - in the DB these are supplier/*
|
||||
* - Type, what service we are providing, made up of a product we supply - in the DB these are service/*
|
||||
*
|
||||
* @package App\Models
|
||||
* @todo "Billing Start Date" = "connection date" for sub types??
|
||||
* @todo Add min_charge
|
||||
* @todo deprecate price_override, and if price < what would be billed, show it striked through, otherwise show it as if it was the price
|
||||
*/
|
||||
class Service extends Model implements IDs
|
||||
{
|
||||
@@ -356,6 +357,14 @@ class Service extends Model implements IDs
|
||||
->orderBy('created_at');
|
||||
}
|
||||
|
||||
public function changes()
|
||||
{
|
||||
return $this->belongsToMany(Product::class,'service__change','service_id','product_id','id','id')
|
||||
->where('service__change.site_id',$this->site_id)
|
||||
->withPivot(['ordered_at','effective_at','ordered_by','active','complete','notes'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
// @todo changed to invoiced_items
|
||||
public function invoice_items($active=TRUE)
|
||||
{
|
||||
|
@@ -12,5 +12,4 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class ServiceChange extends Model
|
||||
{
|
||||
protected $table = 'service__change';
|
||||
public $timestamps = FALSE;
|
||||
}
|
Reference in New Issue
Block a user