Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | class Entitlement extends Model | ||||
/** @var array<string, string> The attributes that should be cast */ | /** @var array<string, string> The attributes that should be cast */ | ||||
protected $casts = [ | protected $casts = [ | ||||
'cost' => 'integer', | 'cost' => 'integer', | ||||
'fee' => 'integer' | 'fee' => '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 20 Lines • Show All 80 Lines • Show Last 20 Lines |