Added some basic methods to the models to get roperties from related models or

the related models themselfes.
This commit is contained in:
Lukas Halbritter
2018-09-14 11:27:08 +02:00
parent 11775170d6
commit ac080eb485
5 changed files with 176 additions and 14 deletions
+9 -1
View File
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
class AccountClass extends 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
View File
@@ -6,5 +6,23 @@ use Illuminate\Database\Eloquent\Model;
class AccountType extends 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
View File
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
class Booking extends Model class Booking extends Model
{ {
// public function amount()
{
return $this->hasMany('App\SubBooking')->amount;
}
public function signedAmount()
{
return $this->amount;
}
} }
+65 -2
View File
@@ -6,13 +6,76 @@ use Illuminate\Database\Eloquent\Model;
class PersonTarget extends 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. * Get all bookings associated with a target.
* *
* @return Illuminate\Database\Eloquent\Collection * @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();
} }
} }
+66 -1
View File
@@ -6,6 +6,19 @@ use Illuminate\Database\Eloquent\Model;
class SubBooking extends Model class SubBooking extends Model
{ {
/**************************************************************************
* 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. * Get the booking date for a sub-booking.
* *
@@ -13,6 +26,58 @@ class SubBooking extends Model
*/ */
public function date() public function date()
{ {
return $this->belongsTo('\App\Booking', 'booking_id')->first()->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');
} }
} }