From 2590997b1a8d62d552d7abe83cce01efc8d20763 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 13 Jun 2022 14:21:48 +1000 Subject: [PATCH] Bring back some services logic to still needed by charges --- .../ResellerServicesController.php | 19 +++++++++++ app/Models/Service.php | 32 +++++++++++++++++++ .../adminlte/a/charge/addedit.blade.php | 2 +- .../a/charge/widgets/pending.blade.php | 4 +-- routes/api.php | 8 ++++- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/ResellerServicesController.php diff --git a/app/Http/Controllers/ResellerServicesController.php b/app/Http/Controllers/ResellerServicesController.php new file mode 100644 index 0000000..9874a38 --- /dev/null +++ b/app/Http/Controllers/ResellerServicesController.php @@ -0,0 +1,19 @@ +services + ->filter(function($item) use ($request) { + return $item->active || ($item->id == $request->include); + }); + } +} \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index adc7b1c..8d86b5a 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -33,6 +33,7 @@ use App\Traits\SiteID; * + billing_interval_string : The period that this service is billed for by default as a name * + billed_to : When this service has been billed to // @todo rename all references to invoice_to * + category : The type of service this is, eg: broadband, phone + * + category_name : The type of service this is, eg: Broadband, Telephone (in human friendly) * + contract_term : The term that this service must be active * + contract_end : The date that the contract ends for this service * + name : Service short name with service address @@ -65,6 +66,27 @@ class Service extends Model implements IDs 'stop_at', ]; + protected $appends = [ + 'category_name', + 'name_short', + ]; + + protected $visible = [ + // 'account_name', + // 'admin_service_id_url', + 'active', + 'category_name', + // 'billing_price', + // 'data_orig', + 'id', + 'name_short', + // 'next_invoice', + // 'product.name', + // 'service_id', + // 'service_id_url', + // 'status', + ]; + protected $with = [ 'invoice_items', 'product.type.supplied', @@ -483,6 +505,16 @@ class Service extends Model implements IDs return number_format($this->getBillingChargeAttribute()/Arr::get(Invoice::billing_periods,$this->recur_schedule.'.interval',1),2); } + public function getCategoryAttribute(): string + { + return $this->product->category; + } + + public function getCategoryNameAttribute(): string + { + return $this->product->category_name; + } + /** * The date the contract ends * diff --git a/resources/views/theme/backend/adminlte/a/charge/addedit.blade.php b/resources/views/theme/backend/adminlte/a/charge/addedit.blade.php index e27ee37..c821319 100644 --- a/resources/views/theme/backend/adminlte/a/charge/addedit.blade.php +++ b/resources/views/theme/backend/adminlte/a/charge/addedit.blade.php @@ -284,7 +284,7 @@ success: function(data) { $("select[name=service_id]").empty(); $.each(data,function(i,j) { - var row = ''; + var row = ''; $(row).appendTo("select[name=service_id]"); }); diff --git a/resources/views/theme/backend/adminlte/a/charge/widgets/pending.blade.php b/resources/views/theme/backend/adminlte/a/charge/widgets/pending.blade.php index 1e4376c..1012499 100644 --- a/resources/views/theme/backend/adminlte/a/charge/widgets/pending.blade.php +++ b/resources/views/theme/backend/adminlte/a/charge/widgets/pending.blade.php @@ -22,8 +22,8 @@ @foreach ($x as $co) {{ $co->id }} - {{ $co->date_orig->format('Y-m-d') }} - {{ $co->charge_date->format('Y-m-d') }} + {{ $co->created_at->format('Y-m-d') }} + {{ $co->charged_at ? $co->charged_at->format('Y-m-d') : '-' }} {{ $co->service->sid }} {{ $co->type }} {{ $co->description }} diff --git a/routes/api.php b/routes/api.php index d1d83b7..0f7f854 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,6 @@ ['auth:api','role:wholesaler']], function() { Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']); }); +// Reseller API calls +Route::group(['middleware'=>['auth:api','role:reseller']], function() { + Route::get('/r/services/{o}',[ResellerServicesController::class,'services']) + ->where('o','[0-9]+'); +}); + Route::group(['middleware'=>'auth:api'], function() { Route::post('/u/checkout/fee/{o}',[CheckoutController::class,'fee']) ->where('o','[0-9]+');