Added some basic methods to the models to get roperties from related models or
the related models themselfes.
This commit is contained in:
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AccountClass extends Model
|
||||
{
|
||||
//
|
||||
/*
|
||||
* Get the IO-type of the account class.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function ioType()
|
||||
{
|
||||
return $this->belongsTo('App\IOType');
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -6,5 +6,23 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AccountType extends Model
|
||||
{
|
||||
//
|
||||
/*
|
||||
* Get the account class of the account type.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function accountClass()
|
||||
{
|
||||
return $this->belongsTo('App\AccountClass');
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the IO-type of the account type.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function ioType()
|
||||
{
|
||||
return $this->accountClass->ioType();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Booking extends Model
|
||||
{
|
||||
//
|
||||
public function amount()
|
||||
{
|
||||
return $this->hasMany('App\SubBooking')->amount;
|
||||
}
|
||||
|
||||
public function signedAmount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
}
|
||||
|
||||
+65
-2
@@ -6,13 +6,76 @@ 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 getBookings()
|
||||
public function bookings()
|
||||
{
|
||||
return $this->hasMany('\App\SubBooking')->get();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
+74
-9
@@ -6,13 +6,78 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SubBooking extends Model
|
||||
{
|
||||
/*
|
||||
* Get the booking date for a sub-booking.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function date()
|
||||
{
|
||||
return $this->belongsTo('\App\Booking', 'booking_id')->first()->date;
|
||||
}
|
||||
/**************************************************************************
|
||||
* BOOKINGS *
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
* Get the booking which contains the sub-booking.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function booking() {
|
||||
return $this->belongsTo('\App\Booking', 'booking_id');
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the booking date for a sub-booking.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function date()
|
||||
{
|
||||
return $this->booking->date;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* ACCOUNT TYPES *
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
* Get the account type related to the sub-booking.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function accountType()
|
||||
{
|
||||
return $this->belongsTo('App\AccountType', 'account_type_id');
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the IO-type of the sub-booking.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function ioType()
|
||||
{
|
||||
return $this->accountType->ioType();
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* PERSON TARGETS *
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
* Get the person-target related to the sub-booking.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function personTarget()
|
||||
{
|
||||
return $this->belongsTo('App\PersonTarget', 'person_target_id');
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* PROJECTS *
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
* Get the project related to the sub-booking.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\belongsTo
|
||||
*/
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo('App\Project', 'project_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user