diff --git a/app/Http/Controllers/ResellerServicesController.php b/app/Http/Controllers/ResellerServicesController.php index 0c3e587..c168765 100644 --- a/app/Http/Controllers/ResellerServicesController.php +++ b/app/Http/Controllers/ResellerServicesController.php @@ -21,6 +21,11 @@ class ResellerServicesController extends Controller return ['data'=>Auth::user()->all_clients()->values()]; } + public function service_inactive() + { + return ['data'=>Auth::user()->all_client_service_inactive()->values()]; + } + public function service_movements() { return ['data'=>Auth::user()->all_client_service_movements()->values()]; diff --git a/app/Models/Service.php b/app/Models/Service.php index 8c00112..7b526dc 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -49,6 +49,7 @@ class Service extends Model private $inactive_status = [ 'CANCELLED', + 'ORDER-REJECTED', ]; public function account() @@ -96,6 +97,19 @@ class Service extends Model return $this->belongsTo(Product::class); } + /** + * Find inactive services. + * + * @param $query + * @return mixed + */ + public function scopeInActive($query) + { + return $query->where(function () use ($query) { + return $query->where('active',FALSE)->orWhereIn('order_status',$this->inactive_status); + }); + } + /** * Only query active categories */ @@ -118,7 +132,8 @@ class Service extends Model public function getCategoryAttribute() { - return $this->product->category; + // @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product. + return is_object($this->product) ? $this->product->category : 'Unknown Product'; } public function getNameAttribute() @@ -136,7 +151,8 @@ class Service extends Model public function getProductNameAttribute() { - return $this->product->name($this->account->language); + // @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product. + return is_object($this->product) ? $this->product->name($this->account->language) : 'Unknown Product'; } public function getServiceExpireAttribute() @@ -197,6 +213,10 @@ class Service extends Model */ private function ServicePlugin() { + // @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product. + if (! is_object($this->product)) + return NULL; + switch ($this->product->prod_plugin_file) { case 'ADSL': return $this->service_adsl; diff --git a/app/User.php b/app/User.php index 1842ede..cadfa81 100644 --- a/app/User.php +++ b/app/User.php @@ -246,6 +246,16 @@ class User extends Authenticatable return $result->flatten(); } + public function all_client_service_inactive() + { + $s = Service::InActive(); + $aa = $this->all_accounts()->pluck('id')->unique()->toArray(); + + return $s->get()->filter(function($item) use ($aa) { + return in_array($item->account_id,$aa); + }); + } + public function all_client_service_movements() { $s = Service::active()->where('order_status','!=','ACTIVE'); diff --git a/resources/theme/backend/adminlte/r/home.blade.php b/resources/theme/backend/adminlte/r/home.blade.php index 2f4db2e..761080d 100644 --- a/resources/theme/backend/adminlte/r/home.blade.php +++ b/resources/theme/backend/adminlte/r/home.blade.php @@ -52,6 +52,9 @@
ID | +Account | +Name | +Status | +Product | +
---|---|---|---|---|
Count {{ $user->all_client_service_inactive()->count() }} | ++ |
No Inactive Services
+ @endif +