More Product Model optimisation

This commit is contained in:
Deon George 2023-05-05 15:48:24 +10:00
parent 96f799f535
commit 820ff2be00
37 changed files with 161 additions and 592 deletions

View File

@ -20,30 +20,6 @@ interface ProductItem
*/ */
public function allowance_string(): string; public function allowance_string(): string;
/**
* Return the contract term for this product when sold as a service
*
* @return int Months
*/
public function getContractTermAttribute(): int;
/**
* Return the product cost
*
* @return float
*/
public function getCostAttribute(): float;
/**
* Return the supplier class
* If there is a model relationship return:
* return $this->getRelationValue('supplier');
* otherwise return a stdClass with name
*
* @return mixed
*/
public function getSupplierAttribute();
/** /**
* Does this offering capture usage information * Does this offering capture usage information
* *

View File

@ -1,81 +0,0 @@
<?php
namespace App\Interfaces;
interface SupplierItem
{
/* RELATIONS */
/**
* Supplier that provides this offering
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function supplier_detail();
/**
* Available products created from this supplier offering
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function products();
/* ATTRIBUTES */
/**
* Return the billing interval base cost including tax
*
* @return float
*/
public function getBaseCostTaxableAttribute(): float;
/**
* Return the billing interval that the supplier charges
*
* @return string
* @deprecated use Product::normalizeBillingInterval()
*/
public function getBillingIntervalAttribute(): int;
/**
* The term that the supplier imposes on this service being connected
*
* @return int
*/
public function getContractTermAttribute(): int;
/**
* The minimum cost of ordering this offering
*
* @return float
*/
public function getMinCostAttribute(): float;
/**
* The minimum cost of ordering this offering including taxes
*
* @return float
*/
public function getMinCostTaxableAttribute(): float;
/**
* Suppliers offering name (short)
*
* @return string
*/
public function getNameAttribute(): string;
/**
* Suppliers offering name (long)
*
* @return string
*/
public function getNameLongAttribute(): string;
/**
* Return the setup cost including tax
*
* @return float
*/
public function getSetupCostTaxableAttribute(): float;
}

View File

@ -193,4 +193,15 @@ class Account extends Model implements IDs
return $item->active AND $item->due > 0; return $item->active AND $item->due > 0;
}); });
} }
/**
* Return the taxed value of a value
*
* @param float $value
* @return float
*/
public function taxed(float $value): float
{
return Tax::calc($value,$this->taxes);
}
} }

View File

@ -41,11 +41,8 @@ use App\Traits\{ProductDetails,SiteID};
* + billing_interval : Default Billing Interval * + billing_interval : Default Billing Interval
* + billing_interval_string: Default Billing Interval in human-readable form * + billing_interval_string: Default Billing Interval in human-readable form
* + setup_charge : Charge to setup this product * + setup_charge : Charge to setup this product
* + setup_charge_taxable : Charge to setup this product including taxes
* + base_charge : Default billing amount * + base_charge : Default billing amount
* + base_charge_taxable : Default billing amount including taxes
* + min_charge : Minimum charge taking into account billing interval and setup charges * + min_charge : Minimum charge taking into account billing interval and setup charges
* + min_charge_taxable : Minimum charge taking into account billing interval and setup charges including taxes
* *
* Attributes for product types (type - Product/*) * Attributes for product types (type - Product/*)
* + name : Short Name for our Product * + name : Short Name for our Product
@ -65,7 +62,6 @@ use App\Traits\{ProductDetails,SiteID};
* ] * ]
* ] * ]
* *
* @todo doesnt appear that price_type is used - but could be used to have different offering types billed differently
* @package App\Models * @package App\Models
*/ */
class Product extends Model implements IDs class Product extends Model implements IDs
@ -170,20 +166,6 @@ class Product extends Model implements IDs
return $this->_charge('base',$timeperiod,$go); return $this->_charge('base',$timeperiod,$go);
} }
/**
* The amount we invoice each time period for this service, including taxes
*
* @param int|null $timeperiod
* @param Group|null $go
* @param Collection|NULL $taxes
* @return float
* @deprecated move to account::tax_calc
*/
public function getBaseChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
{
return Tax::tax_calc($this->getBaseChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
}
/** /**
* The base cost of this product at the appropriate billing interval * The base cost of this product at the appropriate billing interval
* *
@ -191,19 +173,7 @@ class Product extends Model implements IDs
*/ */
public function getBaseCostAttribute(): float public function getBaseCostAttribute(): float
{ {
return $this->supplied->base_cost*Invoice::billing_change($this->supplied->billing_interval,$this->billing_interval) ?: 0; return $this->supplied->base_cost*Invoice::billing_change($this->type->normalizeBillingInterval(),$this->billing_interval) ?: 0;
}
/**
* The base cost of this product at the appropriate billing interval including taxes
*
* @param Collection|NULL $taxes
* @return float
* @deprecated move to account::tax_calc
*/
public function getBaseCostTaxableAttribute(Collection $taxes=NULL): float
{
return Tax::tax_calc($this->getBaseCostAttribute(),$taxes ?: config('site')->taxes);;
} }
/** /**
@ -214,7 +184,7 @@ class Product extends Model implements IDs
*/ */
public function getBillingIntervalAttribute(): int public function getBillingIntervalAttribute(): int
{ {
return max($this->price_recur_default,$this->supplied->billing_interval); return max($this->price_recur_default,$this->type->normalizeBillingInterval());
} }
/** /**
@ -272,20 +242,6 @@ class Product extends Model implements IDs
return $this->getSetupChargeAttribute($timeperiod,$go)+$this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_term($this->type->contract_term,$this->getBillingIntervalAttribute()); return $this->getSetupChargeAttribute($timeperiod,$go)+$this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_term($this->type->contract_term,$this->getBillingIntervalAttribute());
} }
/**
* Get the minimum cost of this product with taxes
*
* @param int|null $timeperiod
* @param Group|null $go
* @param Collection|NULL $taxes
* @return float
* @deprecated move to account::tax_calc
*/
public function getMinChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
{
return Tax::tax_calc($this->getMinChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
}
/** /**
* Our products short descriptive name * Our products short descriptive name
* *
@ -348,20 +304,6 @@ class Product extends Model implements IDs
return $this->_charge('setup',$timeperiod,$go); return $this->_charge('setup',$timeperiod,$go);
} }
/**
* The charge to setup this service including taxes
*
* @param int|null $timeperiod
* @param Group|null $go
* @param Collection|null $taxes
* @return float
* @deprecated move to account::tax_calc
*/
public function getSetupChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
{
return Tax::tax_calc($this->getSetupChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
}
/** /**
* The cost to setup this service * The cost to setup this service
* *
@ -372,18 +314,6 @@ class Product extends Model implements IDs
return $this->supplied->setup_cost ?: 0; return $this->supplied->setup_cost ?: 0;
} }
/**
* The charge to setup this service
*
* @param Collection|null $taxes
* @return float
* @deprecated move to account::tax_calc
*/
public function getSetupCostTaxableAttribute(Collection $taxes=NULL): float
{
return Tax::tax_calc($this->getSetupCostAttribute(),$taxes ?: config('site')->taxes);;
}
/* METHODS */ /* METHODS */
/** /**
@ -457,11 +387,10 @@ class Product extends Model implements IDs
* *
* @note: By definition products are normalised, as their cost price is based on the default billing interval * @note: By definition products are normalised, as their cost price is based on the default billing interval
* @return float * @return float
* @todo Move tax calculations out
*/ */
public function cost_normalized(): float public function cost_normalized(): float
{ {
return number_format(Tax::tax_calc($this->supplied->base_cost,config('site')->taxes),2); return number_format(config('site')->taxed($this->supplied->base_cost),2);
} }
/** /**

View File

@ -118,31 +118,6 @@ final class Broadband extends Type implements ProductItem
return $result; return $result;
} }
/**
* The product contract term is the highest of
* + This defined contract_term
* + The suppliers contract_term
*
* @return int
*/
public function getContractTermAttribute(): int
{
return max($this->attributes['contract_term'],$this->supplied->getContractTermAttribute());
}
public function getCostAttribute(): float
{
abort(500,'deprecated');
// @todo Tax shouldnt be hard coded
return ($this->supplied->base_cost+$this->allowance_cost())*1.1;
}
public function getSupplierAttribute()
{
abort(500,'deprecated');
return $this->getRelationValue('supplier');
}
public function hasUsage(): bool public function hasUsage(): bool
{ {
return TRUE; return TRUE;

View File

@ -51,22 +51,6 @@ final class Domain extends Type implements ProductItem
return ''; return '';
} }
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
return '';
}
public function hasUsage(): bool public function hasUsage(): bool
{ {
return FALSE; return FALSE;

View File

@ -35,22 +35,6 @@ final class Email extends Type implements ProductItem
return ''; return '';
} }
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
return '';
}
public function hasUsage(): bool public function hasUsage(): bool
{ {
return FALSE; return FALSE;

View File

@ -23,16 +23,6 @@ final class Generic extends Type implements ProductItem
/* INTERFACES */ /* INTERFACES */
public function getContractTermAttribute(): int
{
return 0;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection public function allowance(): Collection
{ {
// TODO: Implement allowance() method. // TODO: Implement allowance() method.
@ -43,13 +33,8 @@ final class Generic extends Type implements ProductItem
// TODO: Implement allowance_string() method. // TODO: Implement allowance_string() method.
} }
public function getCostAttribute(): float public function hasUsage(): bool
{ {
// TODO: Implement getCostAttribute() method. return FALSE;
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
} }
} }

View File

@ -23,16 +23,6 @@ final class Host extends Type implements ProductItem
/* INTERFACES */ /* INTERFACES */
public function getContractTermAttribute(): int
{
return 12;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection public function allowance(): Collection
{ {
// TODO: Implement allowance() method. // TODO: Implement allowance() method.
@ -44,14 +34,8 @@ final class Host extends Type implements ProductItem
return ''; return '';
} }
public function getCostAttribute(): float public function hasUsage(): bool
{ {
// TODO: Implement getCostAttribute() method. return FALSE;
return 0;
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
} }
} }

View File

@ -50,17 +50,6 @@ final class Phone extends Type implements ProductItem
/* INTERFACES */ /* INTERFACES */
public function getContractTermAttribute(): int
{
// @todo Get this from the DB
return 12;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection public function allowance(): Collection
{ {
// TODO: Implement allowance() method. // TODO: Implement allowance() method.
@ -71,13 +60,8 @@ final class Phone extends Type implements ProductItem
return "(TBA)"; return "(TBA)";
} }
public function getCostAttribute(): float public function hasUsage(): bool
{ {
// TODO: Implement getCostAttribute() method. return FALSE;
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
} }
} }

View File

@ -35,26 +35,6 @@ final class SSL extends Type implements ProductItem
return ''; return '';
} }
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
abort(500,'deprecated');
$o = new \stdClass();
$o->name = 'Internal';
return $o;
}
public function hasUsage(): bool public function hasUsage(): bool
{ {
return FALSE; return FALSE;

View File

@ -3,14 +3,11 @@
namespace App\Models\Product; namespace App\Models\Product;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use App\Models\Product; use App\Models\Product;
use App\Traits\{OrderServiceOptions,SiteID}; use App\Traits\{OrderServiceOptions,SiteID};
/**
* @todo These tables have a base_cost/setup_cost/contract_term columns - how is that different to the supplier_tables?
* @todo Ensure our terminology is consistent - we have a "cost", we "charge" clients, and we have a "price" which is not official charges nor a cost.
*/
abstract class Type extends Model abstract class Type extends Model
{ {
use SiteID,OrderServiceOptions; use SiteID,OrderServiceOptions;
@ -37,9 +34,22 @@ abstract class Type extends Model
return $this->hasOne(static::SupplierModel,'id','supplier_item_id'); return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
} }
/* ATTRIBUTES */
/**
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
* contract term (defined in Supplier/*).
*
* @return int
*/
public function getContractTermAttribute(): int
{
return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term);
}
/* METHODs */ /* METHODs */
final function normalizeBillingInterval(): int final public function normalizeBillingInterval(): int
{ {
return static::DefaultBill; return static::DefaultBill;
} }

View File

@ -10,7 +10,7 @@ class ProductTranslate extends Model
public $timestamps = FALSE; public $timestamps = FALSE;
public function getDescriptionAttribute(string $val): string public function getDescriptionAttribute(?string $val): string
{ {
return $val ?: 'No Description'; return $val ?: 'No Description';
} }

View File

@ -114,4 +114,15 @@ class Site extends Model
? $this->details->get($x)->value ? $this->details->get($x)->value
: NULL; : NULL;
} }
/**
* Return the taxed value of a value
*
* @param float $value
* @return float
*/
public function taxed(float $value): float
{
return Tax::calc($value,$this->taxes);
}
} }

View File

@ -5,20 +5,22 @@ namespace App\Models\Supplier;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use App\Interfaces\SupplierItem;
use App\Models\Product\Broadband as ProductBroadband; use App\Models\Product\Broadband as ProductBroadband;
class Broadband extends Type implements SupplierItem class Broadband extends Type
{ {
protected const category_name = 'Broadband'; protected const category_name = 'Broadband';
protected $table = 'supplier_broadband';
// The model of the product that is supplied by this model
const ProductModel = ProductBroadband::class;
protected $casts = [ protected $casts = [
'offpeak_start' => 'datetime:H:i', 'offpeak_start' => 'datetime:H:i',
'offpeak_end' => 'datetime:H:i', 'offpeak_end' => 'datetime:H:i',
]; ];
protected $table = 'supplier_broadband';
// Map the table fields, with the extra fields // Map the table fields, with the extra fields
public const traffic_map = [ public const traffic_map = [
'base_up_offpeak' => 'extra_up_offpeak', 'base_up_offpeak' => 'extra_up_offpeak',
@ -35,22 +37,6 @@ class Broadband extends Type implements SupplierItem
'extra_down_peak' => 'base_down_peak', 'extra_down_peak' => 'base_down_peak',
]; ];
/* INTERFACES */
/**
* @return int
* @deprecated use Product::normalizeBillingInterval()
*/
public function getBillingIntervalAttribute(): int
{
return 1; // Monthly
}
public function products()
{
return $this->hasMany(ProductBroadband::class,'supplier_item_id','id');
}
/* METHODS */ /* METHODS */
/** /**

View File

@ -4,33 +4,25 @@ namespace App\Models\Supplier;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use App\Interfaces\SupplierItem;
use App\Models\Product\Domain as ProductDomain; use App\Models\Product\Domain as ProductDomain;
use App\Models\TLD; use App\Models\TLD;
final class Domain extends Type implements SupplierItem final class Domain extends Type
{ {
protected const category_name = 'Domain Name'; protected const category_name = 'Domain';
protected $table = 'supplier_domain'; protected $table = 'supplier_domain';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductDomain::class;
public function getBillingIntervalAttribute(): int /* INTERFACES */
{
return 4; // Yearly
}
public function getNameAttribute(): string public function getNameAttribute(): string
{ {
return sprintf('%s: %s',$this->product_id,$this->tld->name); return sprintf('%s: %s',$this->product_id,$this->tld->name);
} }
public function products()
{
return $this->hasMany(ProductDomain::class,'supplier_item_id','id');
}
/* STATIC */ /* STATIC */
/** /**

View File

@ -2,24 +2,14 @@
namespace App\Models\Supplier; namespace App\Models\Supplier;
use App\Interfaces\SupplierItem;
use App\Models\Product\Email as ProductEmail; use App\Models\Product\Email as ProductEmail;
final class Email extends Type implements SupplierItem final class Email extends Type
{ {
protected const category_name = 'Email Hosting'; protected const category_name = 'Email';
protected $table = 'supplier_email'; protected $table = 'supplier_email';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductEmail::class;
public function getBillingIntervalAttribute(): int
{
return 4; // Yearly
}
public function products()
{
return $this->hasMany(ProductEmail::class,'supplier_item_id','id');
}
} }

View File

@ -4,5 +4,5 @@ namespace App\Models\Supplier;
class Ethernet extends Broadband class Ethernet extends Broadband
{ {
protected const category_name = 'Broadband Ethernet'; protected const category_name = 'Ethernet';
} }

View File

@ -2,24 +2,14 @@
namespace App\Models\Supplier; namespace App\Models\Supplier;
use App\Interfaces\SupplierItem;
use App\Models\Product\Generic as ProductGeneric; use App\Models\Product\Generic as ProductGeneric;
final class Generic extends Type implements SupplierItem final class Generic extends Type
{ {
protected const category_name = 'Generic'; protected const category_name = 'Generic';
protected $table = 'supplier_generic'; protected $table = 'supplier_generic';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductGeneric::class;
public function getBillingIntervalAttribute(): int
{
return 1; // Monthly
}
public function products()
{
return $this->hasMany(ProductGeneric::class,'supplier_item_id','id');
}
} }

View File

@ -2,24 +2,14 @@
namespace App\Models\Supplier; namespace App\Models\Supplier;
use App\Interfaces\SupplierItem;
use App\Models\Product\Host as ProductHost; use App\Models\Product\Host as ProductHost;
final class Host extends Type implements SupplierItem final class Host extends Type
{ {
protected const category_name = 'Web Hosting'; protected const category_name = 'Hosting';
protected $table = 'supplier_host'; protected $table = 'supplier_host';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductHost::class;
public function getBillingIntervalAttribute(): int
{
return 4; // Yearly
}
public function products()
{
return $this->hasMany(ProductHost::class,'supplier_item_id','id');
}
} }

View File

@ -2,24 +2,14 @@
namespace App\Models\Supplier; namespace App\Models\Supplier;
use App\Interfaces\SupplierItem;
use App\Models\Product\Phone as ProductVoip; use App\Models\Product\Phone as ProductVoip;
final class Phone extends Type implements SupplierItem final class Phone extends Type
{ {
protected const category_name = 'Telephone'; protected const category_name = 'Phone';
protected $table = 'supplier_phone'; protected $table = 'supplier_phone';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductVoip::class;
public function getBillingIntervalAttribute(): int
{
return 1; // Monthly
}
public function products()
{
return $this->hasMany(ProductVoip::class,'supplier_item_id','id');
}
} }

View File

@ -2,24 +2,14 @@
namespace App\Models\Supplier; namespace App\Models\Supplier;
use App\Interfaces\SupplierItem;
use App\Models\Product\SSL as ProductSSL; use App\Models\Product\SSL as ProductSSL;
final class SSL extends Type implements SupplierItem final class SSL extends Type
{ {
protected const category_name = 'SSL Certificate'; protected const category_name = 'SSL';
protected $table = 'supplier_ssl'; protected $table = 'supplier_ssl';
/* INTERFACES */ // The model of the product that is supplied by this model
const ProductModel = ProductSSL::class;
public function getBillingIntervalAttribute(): int
{
return 4; // Yearly
}
public function products()
{
return $this->belongsToMany(ProductSSL::class,'supplier_item_id','id');
}
} }

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Leenooks\Traits\ScopeActive; use Leenooks\Traits\ScopeActive;
use App\Models\{Invoice,Supplier,SupplierDetail,Tax}; use App\Models\{Invoice,SupplierDetail};
use App\Traits\{ProductDetails,SiteID}; use App\Traits\{ProductDetails,SiteID};
abstract class Type extends Model abstract class Type extends Model
@ -15,16 +15,26 @@ abstract class Type extends Model
/* RELATIONS */ /* RELATIONS */
public function supplier_detail() /**
* The offering supplied with this product
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
final public function products()
{
return $this->hasMany(static::ProductModel,'supplier_item_id','id');
}
final public function supplier_detail()
{ {
return $this->belongsTo(SupplierDetail::class); return $this->belongsTo(SupplierDetail::class);
} }
/* ATTRIBUTES */ /* ATTRIBUTES */
public function getBaseCostTaxableAttribute(): float public function getBaseCostAttribute(?float $val): float
{ {
return Tax::tax_calc($this->attributes['base_cost'],config('site')->taxes); return $val ?: 0;
} }
/** /**
@ -57,7 +67,7 @@ abstract class Type extends Model
*/ */
public function getContractTermAttribute(): int public function getContractTermAttribute(): int
{ {
return max(Invoice::billing_period(static::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term')); return max(Invoice::billing_period(static::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term',0));
} }
public function getMinCostAttribute(): float public function getMinCostAttribute(): float
@ -65,11 +75,6 @@ abstract class Type extends Model
return $this->attributes['setup_cost']+$this->attributes['base_cost']*Invoice::billing_term($this->getContractTermAttribute(),$this->getBillingIntervalAttribute()); return $this->attributes['setup_cost']+$this->attributes['base_cost']*Invoice::billing_term($this->getContractTermAttribute(),$this->getBillingIntervalAttribute());
} }
public function getMinCostTaxableAttribute(): float
{
return Tax::tax_calc($this->getMinCostAttribute(),config('site')->taxes);
}
public function getNameAttribute(): string public function getNameAttribute(): string
{ {
return $this->product_id ?: 'Supplier PID Unknown'; return $this->product_id ?: 'Supplier PID Unknown';
@ -80,9 +85,9 @@ abstract class Type extends Model
return $this->product_desc ?: 'Supplier NAME Unknown'; return $this->product_desc ?: 'Supplier NAME Unknown';
} }
public function getSetupCostTaxableAttribute(): float public function getSetupCostAttribute(?float $val): float
{ {
return Tax::tax_calc($this->attributes['setup_cost'],config('site')->taxes); return $val ?: 0;
} }
public function getSupplierAttribute(): Model public function getSupplierAttribute(): Model

View File

@ -19,16 +19,14 @@ class Tax extends Model
/* METHODS */ /* METHODS */
/** /**
* Calculate Tax on a value * Calculate Tax on a value, and return that value with tax applied
* *
* @param float $value * @param float $value
* @param Collection $taxes * @param Collection $taxes
* @return void * @return float
*/ */
public static function tax_calc(?float $value,Collection $taxes): float public static function calc(float $value,Collection $taxes): float
{ {
if (! $value)
$value = 0;
$tax = 0; $tax = 0;
foreach ($taxes as $o) { foreach ($taxes as $o) {

View File

@ -33,7 +33,6 @@ class ProductFactory extends Factory
'taxable' => TRUE, 'taxable' => TRUE,
'active' => TRUE, 'active' => TRUE,
// 'position' // 'position'
// 'price_type'
'pricing'=>json_encode([ 'pricing'=>json_encode([
[ [
'show'=>true, 'show'=>true,

View File

@ -19,6 +19,10 @@ return new class extends Migration
DB::statement('ALTER TABLE supplier_generic MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL'); DB::statement('ALTER TABLE supplier_generic MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL');
DB::statement('ALTER TABLE supplier_phone MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL'); DB::statement('ALTER TABLE supplier_phone MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL');
DB::statement('ALTER TABLE supplier_ssl MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL'); DB::statement('ALTER TABLE supplier_ssl MODIFY product_id varchar(32) NOT NULL, MODIFY product_desc text DEFAULT NULL');
Schema::table('products', function (Blueprint $table) {
$table->dropColumn(['price_type']);
});
} }
/** /**

View File

@ -29,13 +29,14 @@
</thead> </thead>
<tbody> <tbody>
@foreach (\App\Models\Service::active()->get() as $o) {{-- @todo This query is expensive still --}}
@foreach (\App\Models\Service::active()->with(['type','product.type.supplied.supplier_detail.supplier','product.translate'])->get() as $o)
<tr> <tr>
<td><a href="{{ url('u/service',[$o->id]) }}">{{ $o->id }}</a></td> <td><a href="{{ url('u/service',[$o->id]) }}">{{ $o->id }}</a></td>
<td>{{ $o->name }}</td> <td>{{ $o->name }}</td>
<td>{{ $o->product->name }}</td> <td>{{ $o->product->name }}</td>
<td class="text-right">{{ number_format($o->billing_monthly_price,2) }}</td> <td class="text-right">{{ number_format($o->billing_monthly_price,2) }}</td>
<td class="text-right">{{ number_format(\App\Models\Tax::tax_calc(($s=$o->supplied)->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1),$o->account->taxes),2) }}</td> <td class="text-right">{{ number_format($o->product->cost_normalized(),2) }}</td>
<td class="text-right">{{ $o->category == 'broadband' ? number_format($o->type->usage_summary(0)->sum()/1000,1) : '-' }}</td> <td class="text-right">{{ $o->category == 'broadband' ? number_format($o->type->usage_summary(0)->sum()/1000,1) : '-' }}</td>
<td>{{ $o->product->supplier->name }}</td> <td>{{ $o->product->supplier->name }}</td>
</tr> </tr>

View File

@ -27,13 +27,14 @@
<tr> <tr>
<th>Setup</th> <th>Setup</th>
@if ($s->exists) @if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->setup_cost,$o->account->taxes),2) }}</td> <td>${{ number_format($a=$o->account->taxed($s->setup_cost),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($p->setup_charge,$o->account->taxes),2) }}</td> <td>${{ number_format($b=$o->account->taxed($p->setup_charge),2) }}</td>
<td>{!! markup($a,$b) !!}</td> <td>{!! markup($a,$b) !!}</td>
@else @else
<td>-</td> <td>-</td>
@endif @endif
</tr> </tr>
{{--
<tr> <tr>
<th>Billed</th> <th>Billed</th>
@if ($s->exists) @if ($s->exists)
@ -47,7 +48,7 @@
<tr> <tr>
<th>Billing Price</th> <th>Billing Price</th>
@if ($s->exists) @if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval),$o->account->taxes),2) }}</td> <td>${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval)),2) }}</td>
@endif @endif
<td>${{ number_format($b=$o->billing_charge,2) }}</td> <td>${{ number_format($b=$o->billing_charge,2) }}</td>
@if ($s->exists) @if ($s->exists)
@ -57,9 +58,9 @@
<tr> <tr>
<th>Monthly Price</th> <th>Monthly Price</th>
@if ($s->exists) @if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1),$o->account->taxes),2) }}</td> <td>${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1)),2) }}</td>
@endif @endif
<td @if($x=$o->isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $p->base_charge_taxable : $o->billing_monthly_price),2) }}</td> <td @if($x=$o->isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $o->account->taxed($p->base_charge) : $o->billing_monthly_price),2) }}</td>
@if ($s->exists) @if ($s->exists)
<td>{!! markup($a,$b) !!}</td> <td>{!! markup($a,$b) !!}</td>
@endif @endif
@ -77,12 +78,13 @@
<tr> <tr>
<th>Min Price</th> <th>Min Price</th>
@if ($s->exists) @if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->min_cost,$o->account->taxes),2) }}</td> <td>${{ number_format($a=$o->account->taxed($s->min_cost),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($p->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }}</td> <td>${{ number_format($b=$o->account->taxed($p->getMinChargeAttribute($o->billing_interval)),2) }}</td>
<td>{!! markup($a,$b) !!}</td> <td>{!! markup($a,$b) !!}</td>
@else @else
<td>-</td> <td>-</td>
@endif @endif
</tr> </tr>
--}}
</tbody> </tbody>
</table> </table>

View File

@ -39,8 +39,8 @@
<td>{{ $oo->name }}</td> <td>{{ $oo->name }}</td>
<td>{{ $oo->name_long }}</td> <td>{{ $oo->name_long }}</td>
<td class="text-right">{{ $oo->active ? 'YES' : 'NO' }}</td> <td class="text-right">{{ $oo->active ? 'YES' : 'NO' }}</td>
<td class="text-right">{{ number_format($oo->setup_cost_taxable,2) }}</td> <td class="text-right">{{ number_format($site->taxed($oo->setup_cost),2) }}</td>
<td class="text-right">{{ number_format($oo->base_cost_taxable,2) }}</td> <td class="text-right">{{ number_format($site->taxed($oo->base_cost),2) }}</td>
<td class="text-right">{{ number_format($oo->products->count()) }}</td> <td class="text-right">{{ number_format($oo->products->count()) }}</td>
<td class="text-right">{{ number_format($oo->products->pluck('products')->filter()->count()) }}</td> <td class="text-right">{{ number_format($oo->products->pluck('products')->filter()->count()) }}</td>
<td class="text-right">{{ number_format(($x=$oo->products->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td> <td class="text-right">{{ number_format(($x=$oo->products->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td>

View File

@ -42,10 +42,10 @@
<td>{{ $po->name }}</td> <td>{{ $po->name }}</td>
<td class="text-right">{{ $po->active ? 'YES' : 'NO' }}</td> <td class="text-right">{{ $po->active ? 'YES' : 'NO' }}</td>
<td class="text-right">{{ $po->billing_interval_string }}</td> <td class="text-right">{{ $po->billing_interval_string }}</td>
<td class="text-right">{{ number_format($po->setup_cost_taxable,2) }}</td> <td class="text-right">{{ number_format($site->taxed($po->setup_cost),2) }}</td>
<td class="text-right">{{ number_format($po->base_cost_taxable,2) }}</td> <td class="text-right">{{ number_format($site->taxed($po->base_cost),2) }}</td>
<td class="text-right">{{ number_format($po->setup_charge_taxable,2) }}</td> <td class="text-right">{{ number_format($site->taxed($po->setup_charge),2) }}</td>
<td class="text-right">{{ number_format($po->base_charge_taxable,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->count()) }}</td>
<td class="text-right">{{ number_format($po->services->where('active')->count()) }}</td> <td class="text-right">{{ number_format($po->services->where('active')->count()) }}</td>
</tr> </tr>

View File

@ -29,7 +29,7 @@
<div id="accordion"> <div id="accordion">
<!-- Reseller Choose Client --> <!-- Reseller Choose Client -->
@if ($user && $user->isReseller()) @if ($user && $user->exists && $user->isReseller())
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4 class="panel-title">Account</h4> <h4 class="panel-title">Account</h4>
@ -78,7 +78,7 @@
</div> </div>
<!-- Non-Authed User --> <!-- Non-Authed User -->
@elseif ($user) @elseif ($user && $user->exists)
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4 class="panel-title"> <h4 class="panel-title">

View File

@ -8,13 +8,15 @@
<th>Type</th> <th>Type</th>
<td class="text-right">{{ $o->category_name }}</td> <td class="text-right">{{ $o->category_name }}</td>
</tr> </tr>
@if ($o->setup_charge)
<tr> <tr>
<th>Setup Charges <sup>*</sup></th> <th>Setup Charges <sup>*</sup></th>
<td class="text-right">${{ number_format($o->setup_charge_taxable,2) }}</td> <td class="text-right">${{ number_format($user->exists ? $user->taxed($o->setup_charge) : Config::get('site')->taxed($o->setup_charge),2) }}</td>
</tr> </tr>
@endif
<tr> <tr>
<th>Cost <sup>+</sup></th> <th>Cost <sup>+</sup></th>
<td class="text-right">${{ number_format($o->base_charge_taxable,2) }}</td> <td class="text-right">${{ number_format($user->exists ? $user->taxed($o->base_charge) : Config::get('site')->taxed($o->base_charge),2) }}</td>
</tr> </tr>
<tr> <tr>
<th>Default Billing</th> <th>Default Billing</th>
@ -26,8 +28,14 @@
</tr> </tr>
<tr> <tr>
<th>Minimum Costs <sup>+*</sup></th> <th>Minimum Costs <sup>+*</sup></th>
<td class="text-right">${{ number_format($o->min_charge_taxable,2) }}</td> <td class="text-right">${{ number_format($user->exists ? $user->taxed($o->min_charge) : Config::get('site')->taxed($o->min_charge),2) }}</td>
</tr> </tr>
<tfoot> <tfoot>
<tr>
<td colspan="2">
{!! $footer !!}
</td>
</tr>
</tfoot>
</table> </table>

View File

@ -1,42 +1,7 @@
<!-- $o = Product::class --> <!-- $o = Product::class -->
<div class="col-md-12"> @include('order.widget.info.base',['footer'=>'
<p>{!! $o->name_detail !!}</p> <sup>
</div> * Additional setup charges may apply for complex installations.<br>
+ Additional charges may apply for regional installations.
<table class="table table-condensed"> </sup>
<tr> '])
<th>Type</th>
<td class="text-right">{{ $o->category_name }}</td>
</tr>
<tr>
<th>Setup Charges <sup>*</sup></th>
<td class="text-right">${{ number_format($o->setup_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Cost <sup>+</sup></th>
<td class="text-right">${{ number_format($o->base_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Default Billing</th>
<td class="text-right">{{ $o->billing_interval_string }}</td>
</tr>
<tr>
<th>Contract Term</th>
<td class="text-right">{{ $o->contract_term }} mths</td>
</tr>
<tr>
<th>Minimum Costs <sup>+*</sup></th>
<td class="text-right">${{ number_format($o->min_charge_taxable,2) }}</td>
</tr>
<tfoot>
<tr>
<td colspan="2">
<sup>
* Additional setup charges may apply for complex installations.<br>
+ Additional charges may apply for regional installations.
</sup>
</td>
</tr>
</tfoot>
</table>

View File

@ -1,33 +1,6 @@
<!-- $o = Product::class --> <!-- $o = Product::class -->
<div class="col-md-12"> @include('order.widget.info.base',['footer'=>'
<p>{!! $o->name_detail !!}</p> <sup>
</div> * Depends on domain availability.<br>
+ Domain availability may change the initial cost.
<table class="table table-condensed"> </sup>'])
<tr>
<th>Type</th>
<td class="text-right">{{ $o->category_name }}</td>
</tr>
<tr>
<th>Setup Charges <sup>*</sup></th>
<td class="text-right">${{ number_format($o->setup_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Cost <sup>+</sup></th>
<td class="text-right">${{ number_format($o->base_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Default Billing</th>
<td class="text-right">{{ $o->billing_interval_string }}</td>
</tr>
<tr>
<th>Contract Term</th>
<td class="text-right">{{ $o->contract_term }} mths</td>
</tr>
<tr>
<th>Minimum Costs <sup>+*</sup></th>
<td class="text-right">${{ number_format($o->min_charge_taxable,2) }}</td>
</tr>
<tfoot>
</table>

View File

@ -1,33 +1,6 @@
<!-- $o = Product::class --> <!-- $o = Product::class -->
<div class="col-md-12"> @include('order.widget.info.base',['footer'=>'
<p>{!! $o->name_detail !!}</p> <sup>
</div> * Depends on domain availability.<br>
+ Domain availability may change the initial cost.
<table class="table table-condensed"> </sup>'])
<tr>
<th>Type</th>
<td class="text-right">{{ $o->category_name }}</td>
</tr>
<tr>
<th>Setup Charges <sup>*</sup></th>
<td class="text-right">${{ number_format($o->setup_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Cost <sup>+</sup></th>
<td class="text-right">${{ number_format($o->base_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Default Billing</th>
<td class="text-right">{{ $o->billing_interval_string }}</td>
</tr>
<tr>
<th>Contract Term</th>
<td class="text-right">{{ $o->contract_term }} mths</td>
</tr>
<tr>
<th>Minimum Costs <sup>+*</sup></th>
<td class="text-right">${{ number_format($o->min_charge_taxable,2) }}</td>
</tr>
<tfoot>
</table>

View File

@ -0,0 +1,6 @@
<!-- $o = Product::class -->
@include('order.widget.info.base',['footer'=>'
<sup>
* Depends on domain availability.<br>
+ Domain availability may change the initial cost.
</sup>'])

View File

@ -1,31 +1,6 @@
<!-- $o = Product::class --> <!-- $o = Product::class -->
<div class="col-md-12"> @include('order.widget.info.base',['footer'=>'
<p>{!! $o->name_detail !!}</p> <sup>
</div> * Depends on complex porting.<br>
+ Complex porting involves additional charges.
<table class="table table-condensed"> </sup>'])
<tr>
<th>Type</th>
<td class="text-right">{{ $o->category_name }}</td>
</tr>
<tr>
<th>Setup Charges</th>
<td class="text-right">${{ number_format($o->setup_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Cost</th>
<td class="text-right">${{ number_format($o->base_charge_taxable,2) }}</td>
</tr>
<tr>
<th>Default Billing</th>
<td class="text-right">{{ $o->billing_interval_string }}</td>
</tr>
<tr>
<th>Contract Term</th>
<td class="text-right">{{ $o->contract_term }} mths</td>
</tr>
<tr>
<th>Minimum Costs</th>
<td class="text-right">${{ number_format($o->min_charge_taxable,2) }}</td>
</tr>
</table>