diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index b607fcc..ef39597 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -58,18 +58,44 @@ class ServiceController extends Controller return $this->update_order_status($o); + case 'PROVISION-PLANNED': + if ($request->post()) { + foreach (['provision_notes'] as $key) { + $o->setOrderInfo($key,$request->post($key)); + } + + $o->date_start = $request->post('date_start'); + + $o->save(); + + foreach ($request->post($o->stype) as $k=>$v) { + $o->type->{$k} = $v; + } + + $o->type->save(); + + return redirect()->to(url('u/service',$o->id))->with('updated','Order sent notes updated.'); + } + + return $this->update_provision_planned($o); + default: abort(499,'Not yet implemented'); } } + private function update_order_status(Service $o) + { + return View('r.service.order.sent',['o'=>$o]); + } + private function update_request_cancel(Service $o) { return View('u.service.order.cancel',['o'=>$o]); } - private function update_order_status(Service $o) + private function update_provision_planned(Service $o) { - return View('r.service.order.sent',['o'=>$o]); + return View('r.service.order.provision_plan',['o'=>$o]); } } \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index 8ae2b81..10e302f 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -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); diff --git a/app/User.php b/app/User.php index 09beaea..c3c62f6 100644 --- a/app/User.php +++ b/app/User.php @@ -462,7 +462,6 @@ class User extends Authenticatable public function client_service_movements(): DatabaseCollection { return Service::active() - ->select(['id','account_id','product_id','order_status','model','order_info']) ->where('order_status','!=','ACTIVE') ->whereIN('account_id',$this->all_accounts()->pluck('id')->unique()->toArray()) ->with(['account','product']) diff --git a/resources/views/theme/backend/adminlte/r/service/order/provision_plan.blade.php b/resources/views/theme/backend/adminlte/r/service/order/provision_plan.blade.php new file mode 100644 index 0000000..63b8790 --- /dev/null +++ b/resources/views/theme/backend/adminlte/r/service/order/provision_plan.blade.php @@ -0,0 +1,92 @@ +@extends('adminlte::layouts.app') + +@section('htmlheader_title') + {{ $o->sid }} +@endsection +@section('page_title') + {{ $o->sid }} +@endsection + +@section('contentheader_title') + Service: {{ $o->sid }} {{ $o->product->name }} +@endsection +@section('contentheader_description') + {{ $o->sname }}: {{ $o->sdesc }} +@endsection + +@section('main-content') +