Files
pollux/app/PersonTarget.php
T

82 lines
2.2 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PersonTarget extends Model
{
/*
* Get the signed amount of the target.
*
* @return float
*/
public function signedAmount()
{
return $this->amount * $this->ioType->factor;
}
/**************************************************************************
* BOOKINGS *
**************************************************************************/
/*
* Get all bookings associated with a target.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public function bookings()
{
return $this->hasMany('\App\SubBooking');
}
/**************************************************************************
* IOTYPES *
**************************************************************************/
/*
* Get the IOType of the target.
*
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function ioType()
{
return $this->belongsTo('App\IOType');
}
/**************************************************************************
* ACTUALS *
**************************************************************************/
/*
* Get the actuals connected with the target.
*
* @return Illuminate\Database\Eloquent\Relations\HasMany
*/
public function actuals()
{
return $this->hasMany('App\SubBooking');
}
/*
* Return the sum of all actuals belonging to this target
*
* @return float
*/
public function actualsSum() {
return $this->actuals->each(function ($item, $key) {
$item['signedAmount'] = $item->signedAmount();
})->sum('signedAmount');
}
/*
* Get the difference of target and actually payed amount so far. I. e.
* return the amount still to be payed.
*
* @return float
*/
public function difference() {
return $this->actualsSum() + $this->signedAmount();
}
}