Files
pollux/app/AccountType.php
T
Lukas Halbritter f8eb022403 Added AccountType method numberAndName().
Fixed bug in bookings.index view: There is no error anymore when a booking has
no project assigned.
2018-10-04 19:53:59 +02:00

78 lines
2.3 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class AccountType extends Model
{
/**************************************************************************
* DIRECT RELATIONS *
**************************************************************************/
/**
* Get the account class of the account type.
*
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function accountClass()
{
return $this->belongsTo('App\AccountClass');
}
/**************************************************************************
* INDIRECT RELATIONS *
**************************************************************************/
/**
* Get the IO-type of the account type.
*
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function ioType()
{
return $this->accountClass->ioType();
}
/*
* Get all account types which are expeditures.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public static function expeditures()
{
return AccountType::whereHas('accountClass', function ($query) {
$query->whereHas('ioType', function ($query) {
$query->where('i_o_types.name', 'Ausgabe');
});
})->get();
}
/*
* Get all account types which are incomes.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public static function incomes() {
return AccountType::whereHas('accountClass', function ($query) {
$query->whereHas('ioType', function ($query) {
$query->where('i_o_types.name', 'Einnahme');
});
})->get();
}
/**************************************************************************
* INDIRECT PROPERTIES *
**************************************************************************/
/**
* Returns the name and number of the account-type as string.
*
* @return string
*/
public function numberAndName()
{
return $this->number . ' - ' . $this->name;
}
}