diff --git a/app/Http/Controllers/ResellerServicesController.php b/app/Http/Controllers/ResellerServicesController.php index c168765..7e523f0 100644 --- a/app/Http/Controllers/ResellerServicesController.php +++ b/app/Http/Controllers/ResellerServicesController.php @@ -25,9 +25,4 @@ class ResellerServicesController extends Controller { return ['data'=>Auth::user()->all_client_service_inactive()->values()]; } - - public function service_movements() - { - return ['data'=>Auth::user()->all_client_service_movements()->values()]; - } } \ No newline at end of file diff --git a/app/User.php b/app/User.php index a027946..06ee618 100644 --- a/app/User.php +++ b/app/User.php @@ -104,7 +104,7 @@ class User extends Authenticatable return $this->belongsTo(Models\Language::class); } - /**b + /** * This users invoices * * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough @@ -313,7 +313,7 @@ class User extends Authenticatable // Build our where clause // First Name, Last name if (preg_match('/\ /',$term)) { - list($fn,$ln) = explode(' ',$term,2); + [$fn,$ln] = explode(' ',$term,2); $query->where(function($query1) use ($fn,$ln,$term) { $query1->where(function($query2) use ($fn,$ln) { @@ -417,16 +417,6 @@ class User extends Authenticatable }); } - public function all_client_service_movements() - { - $s = Service::active()->where('order_status','!=','ACTIVE'); - $aa = $this->all_accounts()->pluck('id')->unique()->toArray(); - - return $s->get()->filter(function($item) use ($aa) { - return in_array($item->account_id,$aa); - }); - } - /** * List of all this users agents, recursively * @@ -452,6 +442,23 @@ class User extends Authenticatable return $result->flatten(); } + /** + * Show this user's clients with service movements + * + * A service movement, is an active service where the status is not ACTIVE + * + * @return DatabaseCollection + */ + public function client_service_movements(): DatabaseCollection + { + return Service::active() + ->select(['id','account_id','product_id','order_status']) + ->where('order_status','!=','ACTIVE') + ->whereIN('account_id',$this->all_accounts()->pluck('id')->unique()->toArray()) + ->with(['account','product']) + ->get(); + } + /** * Determine if the logged in user is a reseller or wholesaler * @@ -475,7 +482,8 @@ class User extends Authenticatable /** * Get all the items for the next invoice * - * @return Collection + * @param bool $future + * @return DatabaseCollection */ public function next_invoice_items(bool $future=FALSE): DatabaseCollection { diff --git a/resources/views/theme/backend/adminlte/r/service/widget/movement.blade.php b/resources/views/theme/backend/adminlte/r/service/widget/movement.blade.php index f7768d7..75dff1b 100644 --- a/resources/views/theme/backend/adminlte/r/service/widget/movement.blade.php +++ b/resources/views/theme/backend/adminlte/r/service/widget/movement.blade.php @@ -1,3 +1,4 @@ +
Product | |||||
---|---|---|---|---|---|
{{ $o->id }} | +{{ $o->account->name }} | +{{ $o->name }} | +{{ $o->status }} | +{{ $o->product->name }} | +|
Count {{ $user->all_client_service_movements()->count() }} | +Count {{ $x->count() }} |