More works on products
This commit is contained in:
@@ -2,23 +2,14 @@
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Traits\ProductDetails;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\{Invoice,Supplier,SupplierDetail,Tax};
|
||||
use App\Models\Product\Broadband as ProductBroadband;
|
||||
use App\Traits\SiteID;
|
||||
|
||||
class Broadband extends Model implements SupplierItem
|
||||
class Broadband extends Type implements SupplierItem
|
||||
{
|
||||
use SiteID,ScopeActive,ProductDetails;
|
||||
|
||||
protected $casts = [
|
||||
'offpeak_start' => 'datetime:H:i',
|
||||
'offpeak_end' => 'datetime:H:i',
|
||||
@@ -44,19 +35,9 @@ class Broadband extends Model implements SupplierItem
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function supplier_detail(): BelongsTo
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsTo(SupplierDetail::class);
|
||||
}
|
||||
|
||||
public function types(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ProductBroadband::class,'supplier_broadband','id','id','id','supplier_broadband_id');
|
||||
}
|
||||
|
||||
public function getBaseCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['base_cost'],config('site')->taxes);
|
||||
return $this->belongsToMany(ProductBroadband::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
@@ -64,48 +45,6 @@ class Broadband extends Model implements SupplierItem
|
||||
return 1; // Monthly
|
||||
}
|
||||
|
||||
/**
|
||||
* This contract term is the highest of
|
||||
* + The defined contract_term
|
||||
* + The default months in a billing interval
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContractTermAttribute(): int
|
||||
{
|
||||
return max(Invoice::billing_period(self::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term'));
|
||||
}
|
||||
|
||||
public function getMinCostAttribute(): float
|
||||
{
|
||||
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
|
||||
{
|
||||
return $this->product_id ?: 'Supplier PID Unknown';
|
||||
}
|
||||
|
||||
public function getNameLongAttribute(): string
|
||||
{
|
||||
return $this->product_desc ?: 'Supplier NAME Unknown';
|
||||
}
|
||||
|
||||
public function getSetupCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['setup_cost'],config('site')->taxes);
|
||||
}
|
||||
|
||||
public function getTypeAttribute(): string
|
||||
{
|
||||
return Arr::get(collect(Supplier::offering_types)->firstWhere('class',get_class($this)),'name','Unknown');
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
|
36
app/Models/Supplier/Domain.php
Normal file
36
app/Models/Supplier/Domain.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\Domain as ProductDomain;
|
||||
use App\Models\TLD;
|
||||
|
||||
final class Domain extends Type implements SupplierItem
|
||||
{
|
||||
protected $table = 'supplier_domain';
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsToMany(ProductDomain::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return 4; // Yearly
|
||||
}
|
||||
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return sprintf('%s: %s',$this->product_id,$this->tld->name);
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function tld()
|
||||
{
|
||||
return $this->belongsTo(TLD::class);
|
||||
}
|
||||
}
|
23
app/Models/Supplier/Generic.php
Normal file
23
app/Models/Supplier/Generic.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\Generic as ProductGeneric;
|
||||
|
||||
final class Generic extends Type implements SupplierItem
|
||||
{
|
||||
protected $table = 'supplier_generic';
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsToMany(ProductGeneric::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return 1; // Monthly
|
||||
}
|
||||
}
|
23
app/Models/Supplier/Host.php
Normal file
23
app/Models/Supplier/Host.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\Host as ProductHost;
|
||||
|
||||
final class Host extends Type implements SupplierItem
|
||||
{
|
||||
protected $table = 'supplier_host';
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsToMany(ProductHost::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return 4; // Yearly
|
||||
}
|
||||
}
|
23
app/Models/Supplier/SSL.php
Normal file
23
app/Models/Supplier/SSL.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\SSL as ProductSSL;
|
||||
|
||||
final class SSL extends Type implements SupplierItem
|
||||
{
|
||||
protected $table = 'supplier_ssl';
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsToMany(ProductSSL::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return 4; // Yearly
|
||||
}
|
||||
}
|
71
app/Models/Supplier/Type.php
Normal file
71
app/Models/Supplier/Type.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Models\{Invoice,Supplier,SupplierDetail,Tax};
|
||||
use App\Traits\{ProductDetails,SiteID};
|
||||
|
||||
abstract class Type extends Model
|
||||
{
|
||||
use SiteID,ScopeActive,ProductDetails;
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function supplier_detail()
|
||||
{
|
||||
return $this->belongsTo(SupplierDetail::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getBaseCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['base_cost'],config('site')->taxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* This contract term is the highest of
|
||||
* + The defined contract_term
|
||||
* + The default months in a billing interval
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContractTermAttribute(): int
|
||||
{
|
||||
return max(Invoice::billing_period(static::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term'));
|
||||
}
|
||||
|
||||
public function getMinCostAttribute(): float
|
||||
{
|
||||
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
|
||||
{
|
||||
return $this->product_id ?: 'Supplier PID Unknown';
|
||||
}
|
||||
|
||||
public function getNameLongAttribute(): string
|
||||
{
|
||||
return $this->product_desc ?: 'Supplier NAME Unknown';
|
||||
}
|
||||
|
||||
public function getSetupCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['setup_cost'],config('site')->taxes);
|
||||
}
|
||||
|
||||
public function getTypeAttribute(): string
|
||||
{
|
||||
return Arr::get(collect(Supplier::offering_types)->firstWhere('class',get_class($this)),'name','Unknown');
|
||||
}
|
||||
}
|
23
app/Models/Supplier/Voip.php
Normal file
23
app/Models/Supplier/Voip.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\Voip as ProductVoip;
|
||||
|
||||
final class Voip extends Type implements SupplierItem
|
||||
{
|
||||
protected $table = 'supplier_voip';
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsToMany(ProductVoip::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return 1; // Monthly
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user