Added in email hosting, and other misc cosmetic fixes
This commit is contained in:
@@ -2,16 +2,18 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Interfaces\{IDs,ProductItem};
|
||||
use App\Traits\{ProductDetails,SiteID};
|
||||
|
||||
/**
|
||||
@@ -23,6 +25,7 @@ use App\Traits\{ProductDetails,SiteID};
|
||||
*
|
||||
* Attributes for products:
|
||||
* + lid : Local ID for product (part number)
|
||||
* + sid : System ID for product (part number)
|
||||
* + supplied : Supplier product provided for this offering
|
||||
* + supplier : Supplier for this offering
|
||||
* + name : Brief Name for our product
|
||||
@@ -36,6 +39,7 @@ use App\Traits\{ProductDetails,SiteID};
|
||||
* + base_charge_taxable : Default billing amount including taxes
|
||||
* + min_charge : Minimum cost taking into account billing interval and setup costs
|
||||
* + min_charge_taxable : Minimum cost taking into account billing interval and setup costs including taxes
|
||||
* + type : Returns the underlying product object, representing the type of product
|
||||
*
|
||||
* Attributes for product types (type - Product/*)
|
||||
* + name : Short Name for our Product
|
||||
@@ -66,6 +70,8 @@ class Product extends Model implements IDs
|
||||
'pricing'=>'collection',
|
||||
];
|
||||
|
||||
protected $with = ['description'];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
@@ -145,7 +151,7 @@ class Product extends Model implements IDs
|
||||
*/
|
||||
public function getBaseCostAttribute(): float
|
||||
{
|
||||
return round($this->type->supplied->base_cost*Invoice::billing_change($this->type->supplied->getBillingIntervalAttribute(),$this->getBillingIntervalAttribute()) ?: 0,2);
|
||||
return round($this->getSuppliedAttribute()->base_cost*Invoice::billing_change($this->getSuppliedAttribute()->getBillingIntervalAttribute(),$this->getBillingIntervalAttribute()) ?: 0,2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +173,7 @@ class Product extends Model implements IDs
|
||||
*/
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return max($this->price_recur_default,$this->type->supplied->getBillingIntervalAttribute());
|
||||
return max($this->price_recur_default,$this->getSuppliedAttribute()->getBillingIntervalAttribute());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,10 +245,31 @@ class Product extends Model implements IDs
|
||||
* Get our product type
|
||||
*
|
||||
* @return string
|
||||
* @todo is the test of type and type->supplied necessary?
|
||||
*/
|
||||
public function getProductTypeAttribute(): string
|
||||
{
|
||||
return ($this->type && $this->type->supplied) ? $this->type->supplied->getTypeAttribute() : 'Unknown';
|
||||
return ($this->type && $this->type->supplied) ? $this->getSuppliedAttribute()->getTypeAttribute() : 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppliers
|
||||
*
|
||||
* @return Model
|
||||
*/
|
||||
public function getSupplierAttribute(): Model
|
||||
{
|
||||
return $this->getSuppliedAttribute()->supplier_detail->supplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppliers product
|
||||
*
|
||||
* @return Model
|
||||
*/
|
||||
public function getSuppliedAttribute(): Model
|
||||
{
|
||||
return $this->type->supplied;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +304,7 @@ class Product extends Model implements IDs
|
||||
*/
|
||||
public function getSetupCostAttribute(): float
|
||||
{
|
||||
return $this->type->supplied->setup_cost ?: 0;
|
||||
return $this->getSuppliedAttribute()->setup_cost ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,13 +321,33 @@ class Product extends Model implements IDs
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Return if this product captures usage data
|
||||
* Return a list of available product types
|
||||
*
|
||||
* @return bool
|
||||
* @return Collection
|
||||
*/
|
||||
public function hasUsage(): bool
|
||||
function availableTypes(): Collection
|
||||
{
|
||||
return $this->type->hasUsage();
|
||||
$models = collect(File::allFiles(app_path()))
|
||||
->map(function ($item) {
|
||||
$path = $item->getRelativePathName();
|
||||
$class = sprintf('%s%s',
|
||||
Container::getInstance()->getNamespace(),
|
||||
strtr(substr($path, 0, strrpos($path, '.')), '/', '\\'));
|
||||
|
||||
return $class;
|
||||
})
|
||||
->filter(function ($class) {
|
||||
$valid = FALSE;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$valid = $reflection->isSubclassOf(ProductItem::class) && (! $reflection->isAbstract());
|
||||
}
|
||||
|
||||
return $valid;
|
||||
});
|
||||
|
||||
return $models->values();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,6 +394,16 @@ class Product extends Model implements IDs
|
||||
return round($price,2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this product captures usage data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUsage(): bool
|
||||
{
|
||||
return $this->type->hasUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* When receiving an order, validate that we have all the required information for the product type
|
||||
*
|
||||
|
Reference in New Issue
Block a user