From b33c0529953a7afe251475ffb8613c985243adcd Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 16 May 2025 20:36:27 +1000 Subject: [PATCH] Add cost/price/supplierid to service, update service report to show supplerid and overridden costs (if any) --- app/Http/Controllers/ServiceController.php | 6 ++- app/Models/Service.php | 5 ++- app/Models/Service/Broadband.php | 17 ++----- .../migrations/2025_05_16_135847_add_cost.php | 30 +++++++++++++ .../backend/adminlte/service/report.blade.php | 44 ++++++++++--------- .../service/widget/broadband/update.blade.php | 2 +- .../service/widget/internal.blade.php | 6 +-- .../adminlte/service/widget/update.blade.php | 11 ++++- 8 files changed, 78 insertions(+), 43 deletions(-) create mode 100644 database/migrations/2025_05_16_135847_add_cost.php diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index fd50053..cb316d7 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -412,7 +412,9 @@ class ServiceController extends Controller 'suspend_billing' => 'nullable|in:on', 'recur_schedule' => ['required',Rule::in(collect(Invoice::billing_periods)->keys())], 'invoice_next_at' => 'nullable|date', - 'price' => 'nullable|numeric', + 'price' => 'nullable|numeric|min:0', // Price we charge the client, if we dont charge supplied/price + 'cost' => 'nullable|numeric|min:0', // Price we are charged by supplier, if we arent charged supplier/price + 'supplierid' => 'nullable|string|min:1', // As used on invoices $o->product->category => 'array|min:1', ] ) @@ -456,6 +458,8 @@ class ServiceController extends Controller $o->suspend_billing = ($validated->get('suspend_billing') == 'on'); $o->external_billing = ($validated->get('external_billing') == 'on'); $o->price = $validated->get('price'); + $o->cost = $validated->get('cost'); + $o->supplierid = $validated->get('supplierid'); // Also update our service start_at date. // @todo We may want to make start_at/stop_at dynamic values calculated by the type records diff --git a/app/Models/Service.php b/app/Models/Service.php index d6388f0..3075f7d 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -955,13 +955,14 @@ class Service extends Model implements IDs /** * The amount we are charged for the client to have this service + * * @return float */ public function billing_cost(): float { return is_null($this->cost) ? $this->product->getBaseCostAttribute() - : $this->cost; + : $this->cost*Invoice::billing_change($this->product->type->billing_interval,$this->product->billing_interval); } /** @@ -1127,7 +1128,7 @@ class Service extends Model implements IDs public function isContract(): bool { - return $this->getContractEndAttribute()->greaterThan(Carbon::now()); + return $this->getContractEndAttribute() && $this->getContractEndAttribute()->greaterThan(Carbon::now()); } /** diff --git a/app/Models/Service/Broadband.php b/app/Models/Service/Broadband.php index 864ee15..93dd0dd 100644 --- a/app/Models/Service/Broadband.php +++ b/app/Models/Service/Broadband.php @@ -57,16 +57,6 @@ class Broadband extends Type implements ServiceUsage /* ATTRIBUTES */ - /** - * @deprecated use $o->service_name; - * @return mixed|string - */ - public function getNameAttribute() - { - abort(500,'deprecated - use $o->service_name'); - return $this->service_number ?: $this->service_address; - } - /** * The type of technology used to provide this Internet Service * @@ -104,15 +94,14 @@ class Broadband extends Type implements ServiceUsage /* METHODS */ /** - * Return the suppliers offering that this service is providing + * Return the supplier's offering that this service is providing * * @return SupplierType - * @todo This column provided_adsl_plan_id should either be deprecated or renamed. */ public function supplied(): SupplierType { - return $this->provided_adsl_plan_id - ? SupplierBroadband::findOrFail($this->provided_adsl_plan_id) + return $this->provided_supplier_broadband_id + ? SupplierBroadband::findOrFail($this->provided_supplier_broadband_id) : $this->service->offering->supplied; } diff --git a/database/migrations/2025_05_16_135847_add_cost.php b/database/migrations/2025_05_16_135847_add_cost.php new file mode 100644 index 0000000..48c7671 --- /dev/null +++ b/database/migrations/2025_05_16_135847_add_cost.php @@ -0,0 +1,30 @@ +float('cost')->nullable(); + $table->string('supplierid')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('service_broadband', function (Blueprint $table) { + $table->dropColumn('cost'); + $table->dropColumn('supplierid'); + }); + } +}; diff --git a/resources/views/theme/backend/adminlte/service/report.blade.php b/resources/views/theme/backend/adminlte/service/report.blade.php index b1d38bf..886b1f5 100644 --- a/resources/views/theme/backend/adminlte/service/report.blade.php +++ b/resources/views/theme/backend/adminlte/service/report.blade.php @@ -25,6 +25,7 @@ ID Service Product + Supplier ID Monthly Cost Usage @@ -38,8 +39,9 @@ {{ $o->id }} {{ $o->name }} {{ $o->product->name }} + {{ $o->supplierid }} {{ number_format($o->billing_charge_normalised,2) }} - {{ number_format($o->product->cost_normalized(),2) }} + {{ number_format($o->billing_cost_normalised,2) }} {{ $o->product->hasUsage() ? number_format($o->type->usage_summary(0)->sum()/1000,1) : '-' }} {{ $o->product->supplier->name }} @@ -49,6 +51,7 @@ TOTAL: + @@ -101,22 +104,23 @@ // Total over all pages let month = rows .data() - .pluck(3) + .pluck(4) .reduce((a, b) => intVal(a) + intVal(b), 0); let cost = rows .data() - .pluck(4) + .pluck(5) .reduce((a, b) => intVal(a) + intVal(b), 0); let usage = rows .data() - .pluck(5) + .pluck(6) .reduce((a, b) => intVal(a) + intVal(b), 0); return $('') .append('') .append('SUB-TOTAL:') + .append('') .append(''+month.toFixed(2)+'') .append(''+cost.toFixed(2)+'') .append(''+usage.toFixed(2)+'') @@ -129,7 +133,7 @@ visible: false, }, { - targets: [0,1,3,4,5], + targets: [0,1,4,5,6], searchPanes: { show: false, } @@ -163,31 +167,31 @@ // Total over all pages month = api - .column(3,{ search: 'applied' }) - .data() - .reduce((a, b) => intVal(a) + intVal(b), 0); - - // Total over this page - monthTotal = api - .column(3, { page: 'current' }) - .data() - .reduce((a, b) => intVal(a) + intVal(b), 0); - - // Total over all pages - cost = api .column(4,{ search: 'applied' }) .data() .reduce((a, b) => intVal(a) + intVal(b), 0); // Total over this page - costTotal = api + monthTotal = api .column(4, { page: 'current' }) .data() .reduce((a, b) => intVal(a) + intVal(b), 0); + // Total over all pages + cost = api + .column(5,{ search: 'applied' }) + .data() + .reduce((a, b) => intVal(a) + intVal(b), 0); + + // Total over this page + costTotal = api + .column(5, { page: 'current' }) + .data() + .reduce((a, b) => intVal(a) + intVal(b), 0); + // Update footer - api.column(3).footer().innerHTML = monthTotal.toFixed(2)+'
('+month.toFixed(2)+')'; - api.column(4).footer().innerHTML = costTotal.toFixed(2)+'
('+cost.toFixed(2)+')'; + api.column(4).footer().innerHTML = monthTotal.toFixed(2)+'
('+month.toFixed(2)+')'; + api.column(5).footer().innerHTML = costTotal.toFixed(2)+'
('+cost.toFixed(2)+')'; } }); }); diff --git a/resources/views/theme/backend/adminlte/service/widget/broadband/update.blade.php b/resources/views/theme/backend/adminlte/service/widget/broadband/update.blade.php index cfc79c6..923c5c3 100644 --- a/resources/views/theme/backend/adminlte/service/widget/broadband/update.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/broadband/update.blade.php @@ -10,7 +10,7 @@
-
+
Connection Type
diff --git a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php index 98cf62e..a5f2c5f 100644 --- a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php @@ -1,7 +1,7 @@ -@use(App\Models\Invoice) @use(Carbon\CarbonInterface) +@use(App\Models\Invoice) @php($c=$o->product) @@ -68,7 +68,7 @@ Billing Price isChargeOverridden())class="text-danger"@endif>${{ number_format($b=$o->billing_charge,2) }} - ${{ number_format($a=$o->account->taxed($c->base_cost),2) }} + isCostOverridden())class="text-danger"@endif>${{ number_format($a=$o->billing_cost,2) }} {!! markup($a,$b) !!} @if($p->exists) isChargeOverridden())class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }} @@ -90,7 +90,7 @@ @if($x) ${{ number_format($b=$o->billing_cost_normalised,2) }} @else - ${{ number_format($o->billing_cost_normalised,2) }} + ${{ number_format($a=$o->billing_cost_normalised,2) }} @endif {!! markup($a,$b) !!} diff --git a/resources/views/theme/backend/adminlte/service/widget/update.blade.php b/resources/views/theme/backend/adminlte/service/widget/update.blade.php index 925ee01..b8aa960 100644 --- a/resources/views/theme/backend/adminlte/service/widget/update.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/update.blade.php @@ -3,7 +3,7 @@
-

Update Service details

+

Update Service Details


@@ -29,11 +29,18 @@
-
+
+ +
+ + +
+ +