251 lines
9.2 KiB
PHP
251 lines
9.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Util;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Models\BookingDraftItem
|
|
*
|
|
* @property int $id
|
|
* @property int $booking_id
|
|
* @property int $travel_program_id
|
|
* @property int|null $travel_class_id
|
|
* @property int|null $draft_item_id
|
|
* @property int|null $draft_type_id
|
|
* @property string|null $request_date
|
|
* @property int|null $days_start
|
|
* @property int|null $days_duration
|
|
* @property string|null $start_date
|
|
* @property string|null $end_date
|
|
* @property string|null $service
|
|
* @property float|null $price_adult
|
|
* @property int|null $adult
|
|
* @property float|null $price_children
|
|
* @property int|null $children
|
|
* @property int|null $pos
|
|
* @property int $in_pdf
|
|
* @property int $status
|
|
* @property int $comfort
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\DraftItem|null $draft_item
|
|
* @property-read \App\Models\DraftType|null $draft_type
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereAdult($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereBookingId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereChildren($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereComfort($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereDaysDuration($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereDaysStart($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereDraftItemId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereDraftTypeId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereEndDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereInPdf($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem wherePos($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem wherePriceAdult($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem wherePriceChildren($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereRequestDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereService($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereStartDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereStatus($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereTravelClassId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereTravelProgramId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @property int|null $fewo_lodging_id
|
|
* @property float|null $price
|
|
* @property-read \App\Models\Booking $booking
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem whereFewoLodgingId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem wherePrice($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingDraftItem query()
|
|
*/
|
|
class BookingDraftItem extends Model
|
|
{
|
|
protected $connection = 'mysql';
|
|
|
|
protected $table = 'booking_draft_items';
|
|
|
|
protected $fillable = [
|
|
'booking_id',
|
|
'travel_program_id',
|
|
'fewo_lodging_id',
|
|
'travel_class_id',
|
|
'draft_item_id',
|
|
'draft_type_id',
|
|
'request_date',
|
|
'days_start',
|
|
'days_duration',
|
|
'start_date',
|
|
'end_date',
|
|
'service',
|
|
'price_adult',
|
|
'adult',
|
|
'price_children',
|
|
'children',
|
|
'price',
|
|
'pos',
|
|
'in_pdf',
|
|
'comfort',
|
|
];
|
|
|
|
/* public function booking()
|
|
{
|
|
return $this->belongsTo('App\Models\Booking', 'booking_id');
|
|
}
|
|
*/
|
|
|
|
public function booking()
|
|
{
|
|
return $this->belongsTo('App\Models\Booking', 'booking_id');
|
|
}
|
|
|
|
public function draft_item()
|
|
{
|
|
return $this->belongsTo('App\Models\DraftItem', 'draft_item_id');
|
|
}
|
|
|
|
public function draft_type()
|
|
{
|
|
return $this->belongsTo('App\Models\DraftType', 'draft_type_id');
|
|
}
|
|
|
|
public function getItemPrice($return = false){
|
|
$adult = 0;
|
|
$children = 0;
|
|
|
|
$days_duration = 1;
|
|
if(isset($this->attributes['days_duration']) && in_array($this->draft_type_id, [36, 37])){
|
|
$days_duration = intval($this->days_duration);
|
|
}
|
|
|
|
if(isset($this->attributes['adult'])){
|
|
$adult = $this->attributes['price_adult'] * $this->attributes['adult'] * $days_duration;
|
|
}
|
|
|
|
|
|
if(isset($this->attributes['children'])){
|
|
$children = $this->attributes['price_children'] * $this->attributes['children'] * $days_duration;
|
|
}
|
|
/*
|
|
if(in_array($this->draft_type_id, [38, 39,40])){
|
|
$days_duration = $this->days_duration;
|
|
$price = $this->price;
|
|
}
|
|
*/
|
|
|
|
if($return == 'adult'){
|
|
return $adult;
|
|
}
|
|
if($return == 'children'){
|
|
return $children;
|
|
}
|
|
if($return == 'total'){
|
|
return $adult + $children;
|
|
}
|
|
return ['adult'=>$adult, 'children'=>$children];
|
|
|
|
|
|
}
|
|
|
|
public function getStartDateAttribute(){
|
|
return isset($this->attributes['start_date']) ? Carbon::parse($this->attributes['start_date'])->format("d.m.Y") : '';
|
|
}
|
|
public function getStartDateRow(){
|
|
return isset($this->attributes['start_date']) ? Carbon::parse($this->attributes['start_date']) : null;
|
|
}
|
|
public function getEndDateAttribute(){
|
|
return isset($this->attributes['end_date']) ? Carbon::parse($this->attributes['end_date'])->format("d.m.Y") : '';
|
|
}
|
|
public function getEndDateRow(){
|
|
return isset($this->attributes['end_date']) ? Carbon::parse($this->attributes['end_date']) : null;
|
|
}
|
|
|
|
public function setStartDateAttribute($value)
|
|
{
|
|
if (!$value) {
|
|
$this->attributes['start_date'] = null;
|
|
} else {
|
|
$this->attributes['start_date'] = (new Carbon($value))->format('Y-m-d');
|
|
}
|
|
}
|
|
public function setStartDateRow($value)
|
|
{
|
|
$this->attributes['start_date'] = $value;
|
|
}
|
|
public function setEndDateAttribute($value){
|
|
if (!$value) {
|
|
$this->attributes['end_date'] = null;
|
|
} else {
|
|
$this->attributes['end_date'] = (new Carbon($value))->format('Y-m-d');
|
|
}
|
|
}
|
|
public function setEndDateRow($value){
|
|
$this->attributes['end_date'] = $value;
|
|
}
|
|
|
|
//price_adult
|
|
public function setPriceAdultAttribute($value)
|
|
{
|
|
$this->attributes['price_adult'] = Util::_clean_float($value);
|
|
}
|
|
public function getPriceAdultAttribute()
|
|
{
|
|
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
|
|
return number_format(($this->attributes['price_adult']), 2, ',', '.');
|
|
}
|
|
public function getPriceAdultRaw()
|
|
{
|
|
return isset($this->attributes['price_adult']) ? $this->attributes['price_adult'] : 0;
|
|
}
|
|
public function setPriceAdultRaw($value)
|
|
{
|
|
return $this->attributes['price_adult'] = $value;
|
|
}
|
|
|
|
//price_children
|
|
public function setPriceChildrenAttribute($value)
|
|
{
|
|
$this->attributes['price_children'] = Util::_clean_float($value);
|
|
}
|
|
public function getPriceChildrenAttribute()
|
|
{
|
|
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
|
|
return number_format(($this->attributes['price_children']), 2, ',', '.');
|
|
}
|
|
public function getPriceChildrenRaw()
|
|
{
|
|
return isset($this->attributes['price_children']) ? $this->attributes['price_children'] : 0;
|
|
}
|
|
public function setPriceChildrenRaw($value)
|
|
{
|
|
return $this->attributes['price_children'] = $value;
|
|
}
|
|
|
|
//price
|
|
public function setPriceAttribute($value)
|
|
{
|
|
$this->attributes['price'] = Util::_clean_float($value);
|
|
}
|
|
public function getPriceAttribute()
|
|
{
|
|
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
|
|
return number_format(($this->attributes['price']), 2, ',', '.');
|
|
}
|
|
public function getPriceRaw()
|
|
{
|
|
return isset($this->attributes['price']) ? $this->attributes['price'] : 0;
|
|
}
|
|
public function setPriceRaw($value)
|
|
{
|
|
return $this->attributes['price'] = $value;
|
|
}
|
|
|
|
|
|
|
|
}
|