Changeset View
Changeset View
Standalone View
Standalone View
src/app/Package.php
Show All 15 Lines | |||||
* * ... | * * ... | ||||
* | * | ||||
* users can simply select a 'package'; | * users can simply select a 'package'; | ||||
* | * | ||||
* * Kolab package: mailbox + quota + groupware, | * * Kolab package: mailbox + quota + groupware, | ||||
* * Free package: mailbox + quota. | * * Free package: mailbox + quota. | ||||
* | * | ||||
* Selecting a package will therefore create a set of entitlments from SKUs. | * Selecting a package will therefore create a set of entitlments from SKUs. | ||||
* | |||||
* @property string $description | |||||
* @property int $discount_rate | |||||
* @property string $id | |||||
* @property string $name | |||||
* @property ?int $tenant_id | |||||
* @property string $title | |||||
*/ | */ | ||||
class Package extends Model | class Package extends Model | ||||
{ | { | ||||
use HasTranslations; | use HasTranslations; | ||||
public $incrementing = false; | public $incrementing = false; | ||||
protected $keyType = 'string'; | protected $keyType = 'string'; | ||||
Show All 32 Lines | public function cost() | ||||
$ppu = $sku->cost * ((100 - $this->discount_rate) / 100); | $ppu = $sku->cost * ((100 - $this->discount_rate) / 100); | ||||
$costs += $units * $ppu; | $costs += $units * $ppu; | ||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
public function isDomain() | /** | ||||
* Checks whether the package contains a domain SKU. | |||||
*/ | |||||
public function isDomain(): bool | |||||
{ | { | ||||
foreach ($this->skus as $sku) { | foreach ($this->skus as $sku) { | ||||
if ($sku->handler_class::entitleableClass() == \App\Domain::class) { | if ($sku->handler_class::entitleableClass() == \App\Domain::class) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* SKUs of this package. | * SKUs of this package. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
*/ | */ | ||||
public function skus() | public function skus() | ||||
{ | { | ||||
return $this->belongsToMany( | return $this->belongsToMany( | ||||
'App\Sku', | 'App\Sku', | ||||
'package_skus' | 'package_skus' | ||||
)->using('App\PackageSku')->withPivot( | )->using('App\PackageSku')->withPivot( | ||||
['qty'] | ['qty'] | ||||
); | ); | ||||
} | } | ||||
/** | |||||
* The tenant for this package. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function tenant() | |||||
{ | |||||
return $this->belongsTo('App\Tenant', 'tenant_id', 'id'); | |||||
} | |||||
} | } |