Add cancellation request

This commit is contained in:
Deon George
2020-04-22 22:54:05 +10:00
parent 6480f40b22
commit 1934c6dfeb
6 changed files with 207 additions and 3 deletions

View File

@@ -165,6 +165,34 @@ class Service extends Model
],
// Order Confirmed by Supplier
'ORDERED' => ['update_reference'=>'ORDER-SENT'],
'ACTIVE' => [
'fail'=>FALSE,
'next'=>[
'UPGRADE-REQUEST'=>['customer'],
'CANCEL-REQUEST'=>['customer'],
],
'system'=>FALSE,
'method'=>'action_active',
'title'=>'Service Active',
],
'UPGRADE-REQUEST' => [
'fail'=>FALSE,
'next'=>[
'UPGRADE-PENDING'=>[],
],
'system'=>FALSE,
'method'=>FALSE,
'title'=>'Upgrade Service',
],
'CANCEL-REQUEST' => [
'fail'=>FALSE,
'next'=>[
'CANCEL-PENDING'=>[],
],
'system'=>FALSE,
'method'=>'action_cancel_request',
'title'=>'Cancel Service',
],
];
/**
@@ -467,6 +495,10 @@ class Service extends Model
default: throw new Exception('Unknown recur_schedule');
}
// If the invoice has an end date, our invoice period shouldnt be greater than that.
if ($this->date_end AND $date > $this->date_end)
$date = $this->date_end;
return $date;
}
@@ -789,6 +821,28 @@ class Service extends Model
// The action methods will return: NULL for no progress|FALSE for a failed status|next stage name.
/**
* Action required before order can leave the ACTIVE status.
*
* @return bool
*/
private function action_active(): ?bool
{
// N/A
return TRUE;
}
/**
* Request cancellation for an order when status ACTIVE stage.
* This method should have the client confirm/accept the cancellation, if it was placed by a reseller/wholesaler.
*
* @return bool
*/
private function action_cancel_request(): ?bool
{
throw new HttpException(301,url('u/service/cancel',$this->id));
}
/**
* Process for an order when status ORDER-ACCEPT stage.
* This method should have the client confirm/accept the order, if it was placed by a reseller/wholesaler.
@@ -962,7 +1016,7 @@ class Service extends Model
} else {
// Cant do anything, dont have a method to check if we can leave
$stage = NULL;
abort(500,'NO Method Cannot Proceed to leave this stage: '.$next['method']);
abort(500,'NO Method Cannot Proceed to leave this stage: '.$current['method']);
}
// If valid, call the method to start the next stage
@@ -1092,9 +1146,13 @@ class Service extends Model
// If the service is active, there will be service charges
if ((! $this->invoice_items->filter(function($item) { return $item->item_type==0 AND ! $item->exists; })->count())
AND ($this->active OR $this->isPending())
AND ($future == TRUE OR ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)))))
AND (
($future == TRUE AND $this->invoice_next < $this->invoice_next_end) OR
($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30))))
))
{
do {
dump(['next'=>$this->invoice_next,'stop'=>$this->invoice_next_end]);
$o = new InvoiceItem;
$o->active = TRUE;
$o->service_id = $this->id;
@@ -1111,7 +1169,7 @@ class Service extends Model
$o->addTaxes($this->account->country->taxes);
$this->invoice_items->push($o);
} while ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)));
} while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30))));
}
// Add additional charges