diff --git a/app/Models/Service.php b/app/Models/Service.php index 30a0f5d..db0b5e6 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -29,12 +29,18 @@ use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive,SiteID}; * - Type, what service we are providing, made up of a product we supply - in the DB these are service/* * * Attributes for services: - * + billing_orig : Charge for this service before being overridden by $this->price (ex TAX) - * + billing_orig_normalised_taxed: Charge for this service before being overridden by $this->price, normalised to MONTHLY (with Account TAX) - * + billing_orig_taxed : Charge for this service before being overridden by $this->price (with Account TAX) * + billing_charge : Charge for this service each invoice period (ex TAX) * + billing_charge_normalised_taxed: Charge for this service each invoice period, normalised to MONTHLY (with Account TAX) * + billing_charge_taxed : Charge for this service each invoice period (with Account TAX) + * + billing_charge_orig : Charge for this service before being overridden by $this->price (ex TAX) + * + billing_charge_orig_normalised_taxed: Charge for this service before being overridden by $this->price, normalised to MONTHLY (with Account TAX) + * + billing_charge_orig_taxed : Charge for this service before being overridden by $this->price (with Account TAX) + * + billing_cost : Cost for this service each invoice period (ex TAX) + * + billing_cost_normalised_taxed: Cost for this service each invoice period, normalised to MONTHLY (with Account TAX) + * + billing_cost_taxed : Cost for this service each invoice period (with Account TAX) + * + billing_cost_orig : Cost for this service before being overridden by $this->cost (ex TAX) + * + billing_cost_orig_normalised_taxed: Cost for this service before being overridden by $this->cost, normalised to MONTHLY (with Account TAX) + * + billing_cost_orig_taxed : Cost for this service before being overridden by $this->cost (with Account TAX) * + billing_interval : The period that this service is billed * + billing_interval_name : The period that this service is billed as a name * + is_billed : Does this service generate an invoice @@ -278,14 +284,23 @@ class Service extends Model implements IDs public function __get($key): mixed { return match ($key) { - 'billing_orig' => $this->product->getBaseChargeAttribute($this->billing_interval,$this->account->group), - 'billing_orig_normalised_taxed' => $this->billing_orig_taxed*Invoice::billing_change($this->billing_interval,Invoice::BILL_MONTHLY), - 'billing_orig_taxed' => $this->account->taxed($this->billing_orig), + 'billing_cost' => $this->billing_cost(), + 'billing_cost_normalised_taxed' => $this->billing_cost_taxed*Invoice::billing_change($this->billing_interval,Invoice::BILL_MONTHLY), + 'billing_cost_taxed' => $this->account->taxed($this->billing_cost), + 'billing_cost_orig' => $this->product->base_cost, + 'billing_cost_orig_normalised_taxed' => $this->billing_cost_orig_taxed*Invoice::billing_change($this->product->type->billing_interval,Invoice::BILL_MONTHLY), + 'billing_cost_orig_taxed' => $this->account->taxed($this->billing_cost_orig), + + 'billing_charge_orig' => $this->product->getBaseChargeAttribute($this->billing_interval,$this->account->group), + 'billing_charge_orig_normalised_taxed' => $this->billing_charge_orig_taxed*Invoice::billing_change($this->billing_interval,Invoice::BILL_MONTHLY), + 'billing_charge_orig_taxed' => $this->account->taxed($this->billing_charge_orig), 'billing_charge' => $this->billing_charge(), 'billing_charge_normalised_taxed' => $this->billing_charge_taxed*Invoice::billing_change($this->billing_interval,Invoice::BILL_MONTHLY), 'billing_charge_taxed' => $this->account->taxed($this->billing_charge), + 'billing_interval' => $this->recur_schedule ?: $this->product->billing_interval, 'billing_interval_name' => Invoice::billing_name($this->billing_interval), + 'is_billed' => (! ($this->external_billing || $this->suspend_billing || ($this->price === 0))), 'is_charge_overridden' => (! is_null($this->price)), 'is_cost_overridden' => (! is_null($this->cost)), @@ -519,18 +534,6 @@ class Service extends Model implements IDs /* ATTRIBUTES */ - public function getBillingCostAttribute(): float - { - return $this->account->taxed($this->billing_cost()); - } - - public function getBillingCostNormalisedAttribute(): float - { - return number_format( - $this->getBillingCostAttribute()*Invoice::billing_change($this->billing_interval,$this->offering->billing_interval), - 2); - } - /** * Return the earliest date that the service can be canceled as per contract/billing intervals * @@ -874,7 +877,7 @@ class Service extends Model implements IDs $this->price = 0; return is_null($this->price) - ? $this->billing_orig + ? $this->billing_charge_orig : $this->price; } @@ -911,11 +914,11 @@ class Service extends Model implements IDs * * @return float */ - public function billing_cost(): float + private function billing_cost(): float { return is_null($this->cost) ? $this->product->getBaseCostAttribute() - : $this->cost*Invoice::billing_change($this->product->type->billing_interval,$this->product->billing_interval); + : $this->cost*Invoice::billing_change($this->product->type->billing_interval,$this->billing_interval); } /** @@ -935,12 +938,12 @@ class Service extends Model implements IDs $max = max($date,$this->getCancelDateAttribute())->clone(); if (! $this->getInvoicedToAttribute()) - return $this->account->taxed($this->getContractTermAttribute()*$this->getBillingCostNormalisedAttribute()); + return $this->getContractTermAttribute()*$this->billing_cost_normalised_taxed; if ($this->getInvoicedToAttribute()->lessThan($max)) { $d = $this->getInvoicedToAttribute()->diffInDays($max); - return $this->account->taxed($d/30*$this->getBillingCostNormalisedAttribute()); + return $d/30*$this->billing_cost_normalised_taxed; } return 0; diff --git a/resources/views/theme/backend/adminlte/service/report.blade.php b/resources/views/theme/backend/adminlte/service/report.blade.php index b141836..180fb8c 100644 --- a/resources/views/theme/backend/adminlte/service/report.blade.php +++ b/resources/views/theme/backend/adminlte/service/report.blade.php @@ -41,7 +41,7 @@ {{ $o->product->name }} {{ $o->supplierid }} {{ number_format($o->billing_charge_normalised_taxed,2) }} - {{ number_format($o->billing_cost_normalised,2) }} + {{ number_format($o->billing_cost_normalised_taxed,2) }} {{ $o->product->hasUsage() ? number_format($o->type->usage_summary(0)->sum()/1000,1) : '-' }} {{ $o->product->supplier->name }} diff --git a/resources/views/theme/backend/adminlte/service/widget/information.blade.php b/resources/views/theme/backend/adminlte/service/widget/information.blade.php index 0ee3a3e..1701d85 100644 --- a/resources/views/theme/backend/adminlte/service/widget/information.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/information.blade.php @@ -48,7 +48,7 @@ Amount @if($o->is_charge_overridden) - @if($o->billing_charge < $o->billing_orig)${{ number_format($o->billing_orig_taxed,2) }} @endif${{ number_format($o->billing_charge_taxed,2) }} + @if($o->billing_charge < $o->billing_charge_orig)${{ number_format($o->billing_charge_orig_taxed,2) }} @endif${{ number_format($o->billing_charge_taxed,2) }} @else ${{ number_format($o->billing_charge_taxed,2) }} @endif 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 4101f96..53fd7bf 100644 --- a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php @@ -16,6 +16,7 @@   @endif +   Client @@ -32,13 +33,14 @@ Product - #{{ $o->product_id }}: {{ $o->product->name }} - #{{ $c->supplied->id }}: {{ $c->supplied->name_long }} - @if($p->exists) -   - #{{ $p->supplied->id }}: {{ $p->supplied->name_long }} - @endif + #{{ $o->product_id }}: {{ $o->product->name }} + #{{ $c->supplied->id }}: {{ $c->supplied->name_long }} {{ $c->category_name }} + @if($p->exists) + #{{ $p->id }}: {{ $p->name }} + #{{ $p->supplied->id }}: {{ $p->supplied->name_long }} +   + @endif @@ -68,7 +70,7 @@ Billing Price $o->is_charge_overridden])>${{ number_format($b=$o->billing_charge_taxed,2) }} - $o->is_cost_overridden])>${{ number_format($a=$o->billing_cost,2) }} + $o->is_cost_overridden])>${{ number_format($a=$o->billing_cost_taxed,2) }} {!! markup($a,$b) !!} @if($p->exists) is_charge_overridden)class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }} @@ -81,22 +83,22 @@ Monthly Price $o->is_charge_overridden])> @if($o->is_charge_overridden) - ${{ number_format($b=$o->billing_charge_normalised_taxed,2) }} + ${{ number_format($b=$o->billing_charge_normalised_taxed,2) }} @else ${{ number_format($b=$o->billing_charge_normalised_taxed,2) }} @endif $o->is_cost_overridden])> @if($o->is_cost_overridden) - ${{ number_format($b=$o->billing_cost_normalised,2) }} + ${{ number_format($a=$o->billing_cost_normalised_taxed,2) }} @else - ${{ number_format($a=$o->billing_cost_normalised,2) }} + ${{ number_format($a=$o->billing_cost_normalised_taxed,2) }} @endif {!! markup($a,$b) !!} @if($p->exists) - is_charge_overridden) class="text-danger" @endif>${{ number_format($b=$o->account->taxed($p->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }} - ${{ number_format($a=$o->account->taxed($p->base_cost)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }} + $o->is_charge_overridden])>${{ number_format($b=$o->account->taxed($p->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }} + $o->is_cost_overridden])>${{ number_format($a=$o->account->taxed($p->base_cost)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }} {!! markup($a,$b) !!} @endif @@ -133,11 +135,14 @@ ${{ number_format($o->billing_charge_to($o->contract_end),2) }} ({{ $o->paid_to?->format('Y-m-d') }}) ${{ number_format($o->billing_cost_to($o->contract_end),2) }} ({{ $o->invoiced_to?->format('Y-m-d') }}) {{ $o->contract_end->format('Y-m-d') }}
({{ $o->contract_end->diffForHumans(now(),CarbonInterface::DIFF_RELATIVE_TO_OTHER,FALSE,2) }} today) - @else Not on contract   @endif + + @if($p->exists) +   + @endif \ No newline at end of file