Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1841631
Plan.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
Plan.php
View Options
<?php
namespace
App
;
use
App\Traits\BelongsToTenantTrait
;
use
App\Traits\UuidStrKeyTrait
;
use
Illuminate\Database\Eloquent\Model
;
use
Spatie\Translatable\HasTranslations
;
/**
* The eloquent definition of a Plan.
*
* A Plan is a grouping of packages, such as a "Family Plan".
*
* A "Family Plan" as such may exist of "2 or more Kolab packages",
* and apply a discount for the third and further Kolab packages.
*
* @property string $description
* @property int $discount_qty
* @property int $discount_rate
* @property int $free_months
* @property string $id
* @property string $mode Plan signup mode (Plan::MODE_*)
* @property string $name
* @property \App\Package[] $packages
* @property datetime $promo_from
* @property datetime $promo_to
* @property ?int $tenant_id
* @property string $title
*/
class
Plan
extends
Model
{
use
BelongsToTenantTrait
;
use
HasTranslations
;
use
UuidStrKeyTrait
;
public
const
MODE_EMAIL
=
'email'
;
public
const
MODE_TOKEN
=
'token'
;
public
const
MODE_MANDATE
=
'mandate'
;
/** @var bool Indicates if the model should be timestamped. */
public
$timestamps
=
false
;
/** @var array<int, string> The attributes that are mass assignable */
protected
$fillable
=
[
'title'
,
'mode'
,
'name'
,
'description'
,
// a start and end datetime for this promotion
'promo_from'
,
'promo_to'
,
// discounts start at this quantity
'discount_qty'
,
// the rate of the discount for this plan
'discount_rate'
,
// minimum number of months this plan is for
'months'
,
// number of free months (trial)
'free_months'
,
];
/** @var array<string, string> The attributes that should be cast */
protected
$casts
=
[
'promo_from'
=>
'datetime:Y-m-d H:i:s'
,
'promo_to'
=>
'datetime:Y-m-d H:i:s'
,
'discount_qty'
=>
'integer'
,
'discount_rate'
=>
'integer'
,
'months'
=>
'integer'
,
'free_months'
=>
'integer'
];
/** @var array<int, string> Translatable properties */
public
$translatable
=
[
'name'
,
'description'
,
];
/**
* The list price for this plan at the minimum configuration.
*
* @return int The costs in cents.
*/
public
function
cost
():
int
{
$costs
=
0
;
// TODO: What about plan's discount_qty/discount_rate?
foreach
(
$this
->
packages
as
$package
)
{
$costs
+=
$package
->
pivot
->
cost
();
}
// TODO: What about plan's free_months?
return
$costs
*
$this
->
months
;
}
/**
* The relationship to packages.
*
* The plan contains one or more packages. Each package may have its minimum number (for
* billing) or its maximum (to allow topping out "enterprise" customers on a "small business"
* plan).
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public
function
packages
()
{
return
$this
->
belongsToMany
(
Package
::
class
,
'plan_packages'
)
->
using
(
PlanPackage
::
class
)
->
withPivot
([
'qty'
,
'qty_min'
,
'qty_max'
,
'discount_qty'
,
'discount_rate'
]);
}
/**
* Checks if the plan has any type of domain SKU assigned.
*
* @return bool
*/
public
function
hasDomain
():
bool
{
foreach
(
$this
->
packages
as
$package
)
{
if
(
$package
->
isDomain
())
{
return
true
;
}
}
return
false
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Aug 25, 3:32 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
217748
Default Alt Text
Plan.php (3 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment