From 2d7437fc0d43f163e5f54787d11f14aabaffc357 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 12 May 2022 09:09:49 +1000 Subject: [PATCH] Fix some missing date_* attributes for Service that have been missed --- app/Http/Controllers/ServiceController.php | 8 ++-- app/Models/Payment.php | 47 ++++++++++++------- app/Models/Service.php | 8 ++-- .../u/service/cancel_request.blade.php | 2 +- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index a81a59d..94b3395 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -80,13 +80,13 @@ class ServiceController extends Controller { if ($request->post()) { $request->validate([ - 'date_end'=>'required|date', + 'stop_at'=>'required|date', ]); if (! $o->order_info) $o->order_info = collect(); - $o->date_end = $request->date_end; + $o->stop_at = $request->stop_at; $o->order_info->put('cancel_note',$request->notes); $o->order_status = 'CANCEL-REQUEST'; $o->save(); @@ -298,8 +298,8 @@ class ServiceController extends Controller $o->type->forceFill($request->post($o->type->type))->save(); } - if ($request->post('date_start')) - $o->date_start = $request->post('date_start'); + if ($request->post('start_at')) + $o->date_start = $request->start_at; $o->save(); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 18373d7..79902d4 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -36,6 +36,28 @@ class Payment extends Model implements IDs // Any balance below this we'll assume its all used. private const threshold = 0.05; + /* INTERFACES */ + + /** + * Payment Local ID + * + * @return string + */ + public function getLIDattribute(): string + { + return sprintf('%06s',$this->id); + } + + /** + * Payment System ID + * + * @return string + */ + public function getSIDAttribute(): string + { + return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute()); + } + /* RELATIONS */ public function account() @@ -81,6 +103,11 @@ class Payment extends Model implements IDs /* ATTRIBUTES */ + /** + * Work out the remaining amount from this payment that has not been allocated. + * + * @return float + */ public function getBalanceAttribute(): float { $balance = $this->getTotalAttribute()-$this->items->sum('amount'); @@ -89,25 +116,11 @@ class Payment extends Model implements IDs } /** - * Payment Local ID + * The total of the payment. * - * @return string + * @return float + * @todo Change the DB column to total */ - public function getLIDattribute(): string - { - return sprintf('%06s',$this->id); - } - - /** - * Payment System ID - * - * @return string - */ - public function getSIDAttribute(): string - { - return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute()); - } - public function getTotalAttribute(): float { return sprintf('%3.2f',$this->total_amt); diff --git a/app/Models/Service.php b/app/Models/Service.php index 083ce95..1957e3f 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -636,8 +636,8 @@ class Service extends Model implements IDs } // If the invoice has an end date, our invoice period shouldnt be greater than that. - if ($this->date_end AND $this->date_end < $date) - $date = $this->date_end; + if ($this->stop_at AND $this->stop_at < $date) + $date = $this->stop_at; return $date; } @@ -1211,7 +1211,7 @@ class Service extends Model implements IDs AND ($this->active OR $this->isPending()) AND ( (($future == TRUE) AND $this->invoice_next < $this->invoice_next_end) OR - (($future == FALSE) AND ($this->invoice_to < ($this->date_end ?: $billdate))) + (($future == FALSE) AND ($this->invoice_to < ($this->stop_at ?: $billdate))) )) { do { @@ -1231,7 +1231,7 @@ class Service extends Model implements IDs $o->addTaxes($this->account->country->taxes); $this->invoice_items->push($o); - } while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: $billdate))); + } while ($future == FALSE AND ($this->invoice_to < ($this->stop_at ?: $billdate))); } // Add additional charges diff --git a/resources/views/theme/backend/adminlte/u/service/cancel_request.blade.php b/resources/views/theme/backend/adminlte/u/service/cancel_request.blade.php index 5dccd9c..84f15c4 100644 --- a/resources/views/theme/backend/adminlte/u/service/cancel_request.blade.php +++ b/resources/views/theme/backend/adminlte/u/service/cancel_request.blade.php @@ -38,7 +38,7 @@
- +