Progress on order progress to provisioning

This commit is contained in:
Deon George
2020-04-23 17:38:09 +10:00
parent 3b168af492
commit 4935a9f5ff
8 changed files with 229 additions and 15 deletions

View File

@@ -164,7 +164,38 @@ class Service extends Model
'title'=>'Send Order',
],
// Order Confirmed by Supplier
'ORDERED' => ['update_reference'=>'ORDER-SENT'],
'ORDERED' => [
'fail'=>false,
'next'=>[
'PROVISION-HOLD'=>['wholesaler'],
'PROVISION-PLANNED'=>['wholesaler'],
'PROVISIONED'=>['wholesaler'],
],
'system'=>FALSE,
'method'=>'action_ordered',
'title'=>'Service Ordered',
],
// Service confirmed by supplier, optional connection date
'PROVISION-PLANNED' => [
'fail'=>false,
'next'=>[
'PROVISIONED'=>['wholesaler'],
],
'system'=>FALSE,
'method'=>'action_provision_planned',
'title'=>'Provision Planned',
],
// Service has been provisioned by supplier
'PROVISIONED' => [
'fail'=>false,
'next'=>[
'ACTIVE'=>['wholesaler'],
],
'system'=>FALSE,
'method'=>'action_provisioned',
'title'=>'Provisioned',
],
// Service is Active
'ACTIVE' => [
'fail'=>FALSE,
'next'=>[
@@ -175,6 +206,7 @@ class Service extends Model
'method'=>'action_active',
'title'=>'Service Active',
],
// Service to be Upgraded
'UPGRADE-REQUEST' => [
'fail'=>FALSE,
'next'=>[
@@ -184,6 +216,7 @@ class Service extends Model
'method'=>FALSE,
'title'=>'Upgrade Service',
],
// Service to be Cancelled
'CANCEL-REQUEST' => [
'fail'=>FALSE,
'next'=>[
@@ -436,7 +469,8 @@ class Service extends Model
$last = $this->getInvoiceToAttribute();
$date = $last
? $last->addDay()
: ($this->date_next_invoice ? $this->date_next_invoice->clone() : Carbon::now());
: ($this->date_next_invoice ? $this->date_next_invoice->clone()
: ($this->date_start ?: Carbon::now()));
return request()->wantsJson() ? $date->format('Y-m-d') : $date;
}
@@ -843,6 +877,17 @@ class Service extends Model
throw new HttpException(301,url('u/service/cancel',$this->id));
}
/**
* Processing when service has been ordered.
*
* @return bool|null
*/
private function action_ordered(): ?bool
{
// N/A
return TRUE;
}
/**
* 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.
@@ -859,8 +904,12 @@ class Service extends Model
* Action method when status ORDER_SENT
* This method redirects to a form, where updating the form will progress to the next stage.
*/
private function action_order_sent()
private function action_order_sent(string $next)
{
// We can proceed to the ordered status
if ($next == 'ORDERED' AND $this->order_info_reference)
return TRUE;
throw new HttpException(301,url('r/service/update',$this->id));
}
@@ -875,6 +924,17 @@ class Service extends Model
return TRUE;
}
/**
* Action when supplier has confirmed provisioning.
*
* @param string $next
* @return bool
*/
private function action_provision_planned(string $next)
{
throw new HttpException(301,url('r/service/update',$this->id));
}
/**
* Process for an order when status SETUP-PAYMENT-WAIT stage.
* This method should collect any setup fees payment.
@@ -939,13 +999,12 @@ class Service extends Model
// Can the current user do this role?
$cando = FALSE;
foreach ($roles as $role) {
if ($myrole < array_search($role,User::$role_order)) {
if ($myrole <= array_search($role,User::$role_order)) {
$cando = TRUE;
break;
}
}
//dd($action,$roles,$result);
if ($cando OR $result->get('system')) {
$next->put($action,$roles);
}
@@ -981,7 +1040,7 @@ class Service extends Model
// If valid, call the method to confirm that the current stage is complete
if (method_exists($this,$current['method'])) {
try {
$result = $this->{$current['method']}();
$result = $this->{$current['method']}($stage);
// If we have a form to complete, we need to return with a URL, so we can catch that with an Exception
} catch (HttpException $e) {
@@ -1225,7 +1284,7 @@ class Service extends Model
* @param string $key
* @param string $value
*/
public function setOrderInfo(string $key,string $value): void
public function setOrderInfo(string $key,?string $value): void
{
$x = is_null($this->order_info) ? collect() : $this->order_info;
$x->put($key,$value);