From 3784de855a764600fdbf27c65aba5b2d2e723c9b Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 14 Apr 2020 17:40:47 +1000 Subject: [PATCH] Changed service movements rendering --- .../ResellerServicesController.php | 5 --- app/User.php | 34 +++++++++------ .../r/service/widget/movement.blade.php | 42 ++++++++----------- routes/api.php | 1 - 4 files changed, 38 insertions(+), 44 deletions(-) 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 @@ +

Service Movements

@@ -9,7 +10,7 @@
- @if ($user->all_client_service_movements()->count()) + @if (($x=$user->client_service_movements())->count()) @@ -20,9 +21,20 @@ + + @foreach ($x as $o) + + + + + + + + @endforeach + - + @@ -47,31 +59,11 @@ $(document).ready(function() { $('#service_movements').DataTable( { responsive: true, - ajax: { - url: "/api/r/service_movements" - }, - columns: [ - { data: - @if($user->isWholesaler()) - "admin_service_id_url" - @else - "service_id_url" - @endif - }, - { data: "account_name" }, - { data: "name_short" }, - { data: "status" }, - { data: "product_name" } - ], - language: { - emptyTable: "No Service Movements" - }, order: [3, 'asc'], rowGroup: { - dataSrc: 'account_name', - startRender: null, - endRender: function ( rows, group ) { - return rows.count()+' x ' + group; + dataSrc: 1, + startRender: function ( rows, group ) { + return group+': '+rows.count()+' Services'; }, }, orderFixed: [1, 'asc'] diff --git a/routes/api.php b/routes/api.php index 6a6ecbf..306b823 100644 --- a/routes/api.php +++ b/routes/api.php @@ -23,7 +23,6 @@ Route::group(['middleware'=>['auth:api','role:reseller']], function() { Route::get('/r/agents','ResellerServicesController@agents'); Route::get('/r/accounts','ResellerServicesController@accounts'); Route::get('/r/clients','ResellerServicesController@clients'); - Route::get('/r/service_movements','ResellerServicesController@service_movements'); Route::get('/r/service_inactive','ResellerServicesController@service_inactive'); });
Product
{{ $o->id }}{{ $o->account->name }}{{ $o->name }}{{ $o->status }}{{ $o->product->name }}
Count {{ $user->all_client_service_movements()->count() }}Count {{ $x->count() }}