Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | protected $fillable = [ | ||||
'description' | 'description' | ||||
]; | ]; | ||||
protected $casts = [ | protected $casts = [ | ||||
'cost' => 'integer', | 'cost' => 'integer', | ||||
]; | ]; | ||||
/** | /** | ||||
* Return the costs per day for this entitlement. | |||||
* | |||||
* @return float | |||||
*/ | |||||
public function costsPerDay() | |||||
{ | |||||
if ($this->cost == 0) { | |||||
return (float) 0; | |||||
} | |||||
$discount = $this->wallet->getDiscountRate(); | |||||
$daysInLastMonth = \App\Utils::daysInLastMonth(); | |||||
$costsPerDay = (float) ($this->cost * $discount) / $daysInLastMonth; | |||||
return $costsPerDay; | |||||
} | |||||
/** | |||||
* Create a transaction record for this entitlement. | * Create a transaction record for this entitlement. | ||||
* | * | ||||
* @param string $type The type of transaction ('created', 'billed', 'deleted'), but use the | * @param string $type The type of transaction ('created', 'billed', 'deleted'), but use the | ||||
* \App\Transaction constants. | * \App\Transaction constants. | ||||
* @param int $amount The amount involved in cents | * @param int $amount The amount involved in cents | ||||
* | * | ||||
* @return string The transaction ID | * @return string The transaction ID | ||||
*/ | */ | ||||
Show All 14 Lines | class Entitlement extends Model | ||||
/** | /** | ||||
* Principally entitleable objects such as 'Domain' or 'User'. | * Principally entitleable objects such as 'Domain' or 'User'. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function entitleable() | public function entitleable() | ||||
{ | { | ||||
return $this->morphTo()->withTrashed(); | return $this->morphTo(); | ||||
} | } | ||||
/** | /** | ||||
* The SKU concerned. | * The SKU concerned. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
*/ | */ | ||||
public function sku() | public function sku() | ||||
Show All 22 Lines |