Move base_cost/base_charge product::class methods into __get(), and base_charge(), no functional changes
This commit is contained in:
parent
c8f1c97078
commit
04ae35b1dd
@ -343,7 +343,7 @@ class ServiceController extends Controller
|
||||
$co->type = $iio->item_type;
|
||||
$co->start_at = $start_at;
|
||||
$co->stop_at = $iio->stop_at;
|
||||
$co->amount = Arr::get($request->broadband,'price') ?: $po->base_charge;
|
||||
$co->amount = Arr::get($request->broadband,'price') ?: $po->base_charge();
|
||||
$co->taxable = TRUE; // @todo this should be determined
|
||||
$co->quantity = $start_at->diffInDays($iio->stop_at)/$iio->start_at->diffInDays($iio->stop_at);
|
||||
$charges->push($co);
|
||||
|
@ -34,6 +34,7 @@ use App\Traits\{ProductDetails,ProviderRef};
|
||||
* + lid : Local ID for product (part number)
|
||||
* + sid : System ID for product (part number)
|
||||
* + base_charge : Default billing amount
|
||||
*
|
||||
* + billing_interval : Default Billing Interval
|
||||
* + billing_interval_string: Default Billing Interval in human-readable form
|
||||
* + category : Type of product supplied
|
||||
@ -62,8 +63,6 @@ use App\Traits\{ProductDetails,ProviderRef};
|
||||
* group => [ pricing/setup ]
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Product extends Model implements IDs
|
||||
{
|
||||
@ -73,6 +72,15 @@ class Product extends Model implements IDs
|
||||
'pricing' => CollectionOrNull::class,
|
||||
];
|
||||
|
||||
public function __get($key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'base_cost' => round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0,
|
||||
|
||||
default => parent::__get($key),
|
||||
};
|
||||
}
|
||||
|
||||
/* STATIC */
|
||||
|
||||
/**
|
||||
@ -162,28 +170,6 @@ class Product extends Model implements IDs
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* The amount we invoice each time period for this service
|
||||
*
|
||||
* @param int|NULL $timeperiod
|
||||
* @param Group|NULL $go
|
||||
* @return float
|
||||
*/
|
||||
public function getBaseChargeAttribute(int $timeperiod=NULL,Group $go=NULL): float
|
||||
{
|
||||
return $this->_charge('base',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* The base cost of this product at the appropriate billing interval
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getBaseCostAttribute(): float
|
||||
{
|
||||
return round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our default billing interval
|
||||
* Its the max of what we define, or what the supplier bills us at
|
||||
@ -248,7 +234,7 @@ class Product extends Model implements IDs
|
||||
public function getMinChargeAttribute(int $timeperiod=NULL,Group $go=NULL): float
|
||||
{
|
||||
return $this->getSetupChargeAttribute($timeperiod,$go)
|
||||
+ $this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_change($this->billing_interval,$this->type->billing_interval)*$this->type->contract_term;
|
||||
+ $this->base_charge($timeperiod,$go)*Invoice::billing_change($this->billing_interval,$this->type->billing_interval)*$this->type->contract_term;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,6 +369,18 @@ class Product extends Model implements IDs
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount we invoice each time period for this service
|
||||
*
|
||||
* @param int|NULL $timeperiod
|
||||
* @param Group|NULL $go
|
||||
* @return float
|
||||
*/
|
||||
public function base_charge(?int $timeperiod=NULL,?Group $go=NULL): float
|
||||
{
|
||||
return $this->_charge('base',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the charge from the pricing table for the specific time period and group
|
||||
*
|
||||
|
@ -291,7 +291,7 @@ class Service extends Model implements IDs
|
||||
'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' => $this->product->base_charge($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(),
|
||||
@ -908,7 +908,7 @@ class Service extends Model implements IDs
|
||||
private function billing_cost(): float
|
||||
{
|
||||
return is_null($this->cost)
|
||||
? $this->product->getBaseCostAttribute()
|
||||
? $this->product->base_cost
|
||||
: $this->cost*Invoice::billing_change($this->product->type->billing_interval,$this->billing_interval);
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,6 @@ abstract class Type extends Model
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getBaseCostAttribute(?float $val): float
|
||||
{
|
||||
return $val ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
|
||||
* other logic of these types.
|
||||
|
@ -73,7 +73,7 @@
|
||||
<td @class(['text-danger'=>$o->is_cost_overridden])>${{ number_format($a=$o->billing_cost_taxed,2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if($p->exists)
|
||||
<td @if($o->is_charge_overridden)class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }}</td>
|
||||
<td @if($o->is_charge_overridden)class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge()),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->base_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
@ -97,7 +97,7 @@
|
||||
</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if($p->exists)
|
||||
<td @class(['text-danger'=>$o->is_charge_overridden])>${{ number_format($b=$o->account->taxed($p->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td @class(['text-danger'=>$o->is_charge_overridden])>${{ number_format($b=$o->account->taxed($p->base_charge())*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td @class(['text-danger'=>$o->is_cost_overridden])>${{ number_format($a=$o->account->taxed($p->base_cost)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
|
@ -57,7 +57,7 @@
|
||||
'id'=>$item->id,
|
||||
'value'=>sprintf('%s $%3.2f [%s/%3.2f]',
|
||||
$item->name,
|
||||
$o->account->taxed($item->base_charge)*Invoice::billing_change($item->billing_interval,Invoice::BILL_MONTHLY),
|
||||
$o->account->taxed($item->base_charge())*Invoice::billing_change($item->billing_interval,Invoice::BILL_MONTHLY),
|
||||
$item->supplied->name,
|
||||
$o->account->taxed($item->base_cost)*Invoice::billing_change($item->billing_interval,Invoice::BILL_MONTHLY),
|
||||
)])" :required="true"/>
|
||||
|
@ -47,7 +47,7 @@
|
||||
<td class="text-right">{{ number_format($site->taxed($po->setup_cost),2) }}</td>
|
||||
<td class="text-right">{{ number_format($site->taxed($po->base_cost),2) }}</td>
|
||||
<td class="text-right">{{ number_format($site->taxed($po->setup_charge),2) }}</td>
|
||||
<td class="text-right">{{ number_format($site->taxed($po->base_charge),2) }}</td>
|
||||
<td class="text-right">{{ number_format($site->taxed($po->base_charge()),2) }}</td>
|
||||
<td class="text-right">{{ number_format($po->services->count()) }}</td>
|
||||
<td class="text-right">{{ number_format($po->services->where('active')->count()) }}</td>
|
||||
</tr>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<tr>
|
||||
<th>Cost <sup>+</sup></th>
|
||||
{{-- @todo this should use account::taxed() when the user is known --}}
|
||||
<td class="text-right">${{ number_format($user->exists ? Config::get('site')->taxed($pdo->base_charge) : Config::get('site')->taxed($pdo->base_charge),2) }}</td>
|
||||
<td class="text-right">${{ number_format($user->exists ? Config::get('site')->taxed($pdo->base_charge()) : Config::get('site')->taxed($pdo->base_charge()),2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Default Billing</th>
|
||||
|
Loading…
x
Reference in New Issue
Block a user