56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Booking extends Model
|
|
{
|
|
public function amount()
|
|
{
|
|
return $this->subBookings()->sum('amount');
|
|
}
|
|
|
|
public function signedAmount()
|
|
{
|
|
return $this->subBookings()->withSignedAmount()->get()
|
|
->sum('signedAmount');
|
|
}
|
|
|
|
public function subBookings()
|
|
{
|
|
return $this->hasMany('App\SubBooking');
|
|
}
|
|
|
|
/**
|
|
* Return true, if the booking consists only of one sub-booking.
|
|
* NOTICE: The book instance has to be loaded with the
|
|
* ->withCount('subBookings') method to be able to access the comments
|
|
* count.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function isSimple()
|
|
{
|
|
return $this->sub_bookings_count === 1;
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
if ($this->isSimple()) {
|
|
return $this->subBookings()->first()->project();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function accountType()
|
|
{
|
|
if ($this->isSimple()) {
|
|
return $this->subBookings()->first()->accountType();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|