212 lines
9 KiB
PHP
212 lines
9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Models\Booking
|
|
*
|
|
* @property int $id
|
|
* @property string|null $booking_date
|
|
* @property int $customer_id
|
|
* @property int|null $lead_id
|
|
* @property int|null $new_drafts
|
|
* @property int $sf_guard_user_id
|
|
* @property int $branch_id
|
|
* @property float|null $service_fee
|
|
* @property int|null $travel_country_id
|
|
* @property int|null $travel_category_id
|
|
* @property int|null $pax
|
|
* @property int|null $coupon_id
|
|
* @property \Illuminate\Support\Carbon $created_at
|
|
* @property \Illuminate\Support\Carbon $updated_at
|
|
* @property string|null $title
|
|
* @property string|null $start_date
|
|
* @property string|null $end_date
|
|
* @property int|null $website_id
|
|
* @property string|null $travel_number
|
|
* @property string|null $participant_name
|
|
* @property string|null $participant_firstname
|
|
* @property string|null $participant_birthdate
|
|
* @property int|null $participant_salutation_id
|
|
* @property string|null $ev_number
|
|
* @property string|null $merlin_knr
|
|
* @property string|null $merlin_order_number
|
|
* @property int|null $travel_company_id
|
|
* @property int|null $travel_documents
|
|
* @property float|null $price
|
|
* @property float|null $price_total
|
|
* @property float|null $deposit_total
|
|
* @property float|null $final_payment
|
|
* @property string|null $final_payment_date
|
|
* @property int|null $travelagenda_id
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Sym\Arrangement[] $arrangements
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\BookingDraftItem[] $booking_draft_items
|
|
* @property-read \App\Models\TravelCountry|null $lead
|
|
* @property-read \App\Models\SfGuardUser $sf_guard_user
|
|
* @property-read \App\Models\TravelAgenda|null $travel_agenda
|
|
* @property-read \App\Models\TravelCountry|null $travel_country
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereBookingDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereBranchId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereCouponId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereCustomerId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereDepositTotal($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereEndDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereEvNumber($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereFinalPayment($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereFinalPaymentDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereLeadId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereMerlinKnr($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereMerlinOrderNumber($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereNewDrafts($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereParticipantBirthdate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereParticipantFirstname($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereParticipantName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereParticipantSalutationId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePax($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePrice($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePriceTotal($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereServiceFee($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereSfGuardUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereStartDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTitle($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelCategoryId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelCompanyId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelCountryId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelDocuments($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelNumber($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereTravelagendaId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereWebsiteId($value)
|
|
* @mixin \Eloquent
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking query()
|
|
*/
|
|
class Booking extends Model
|
|
{
|
|
protected $connection = 'mysql';
|
|
|
|
protected $table = 'booking';
|
|
|
|
/*protected $fillable = [
|
|
'pos',
|
|
];*/
|
|
|
|
public function booking_draft_items()
|
|
{
|
|
return $this->hasMany('App\Models\BookingDraftItem', 'booking_id', 'id')->orderBy('pos', 'ASC');
|
|
}
|
|
|
|
//on crm
|
|
public function travel_agenda()
|
|
{
|
|
return $this->belongsTo('App\Models\TravelAgenda', 'travelagenda_id', 'id');
|
|
}
|
|
|
|
public function travel_country()
|
|
{
|
|
return $this->belongsTo('App\Models\TravelCountry', 'travel_country_id', 'crm_id');
|
|
}
|
|
|
|
public function lead()
|
|
{
|
|
return $this->belongsTo('App\Models\Lead', 'lead_id', 'id');
|
|
}
|
|
|
|
public function sf_guard_user()
|
|
{
|
|
return $this->belongsTo('App\Models\SfGuardUser', 'sf_guard_user_id', 'id');
|
|
}
|
|
|
|
public function arrangements()
|
|
{
|
|
return $this->hasMany('App\Models\Sym\Arrangement', 'booking_id', 'id')->orderBy('view_position', 'DESC');
|
|
}
|
|
|
|
|
|
public function calculate_price_total()
|
|
{
|
|
$travel_draft_item = false;
|
|
$travel_price_adult = 0;
|
|
$travel_price_children = 0;
|
|
$total_adult = 0;
|
|
$total_children = 0;
|
|
foreach ($this->booking_draft_items as $booking_draft_item) {
|
|
//24 Rundreise
|
|
if($booking_draft_item->draft_type_id == 24){
|
|
$travel_draft_item = $booking_draft_item;
|
|
continue;
|
|
}
|
|
$prices = $booking_draft_item->getItemPrice();
|
|
//Grundpreis Reise
|
|
if($booking_draft_item->draft_type_id == 30){
|
|
$travel_price_adult += $prices['adult'];
|
|
$travel_price_children += $prices['children'];
|
|
}
|
|
$total_adult += $prices['adult'];
|
|
$total_children += $prices['children'];
|
|
}
|
|
|
|
if($travel_draft_item){
|
|
$travel_draft_item->setPriceAdultRaw($travel_price_adult);
|
|
$travel_draft_item->setPriceChildrenRaw($travel_price_children);
|
|
$travel_draft_item->save();
|
|
}
|
|
|
|
$this->price = $total_adult + $total_children;
|
|
$this->save();
|
|
|
|
}
|
|
|
|
public function _format_number($value){
|
|
return preg_replace("/[^0-9,]/", "", $value);
|
|
}
|
|
|
|
public function getPriceAttribute()
|
|
{
|
|
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
|
|
return number_format(($this->attributes['price']), 2, ',', '.');
|
|
}
|
|
|
|
public function findBeforeDraftItemRelation($reid)
|
|
{
|
|
$before = false;
|
|
foreach($this->booking_draft_items as $booking_draft_items) {
|
|
if ($booking_draft_items->id == $reid) {
|
|
return $before;
|
|
}
|
|
$before = $booking_draft_items;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function findAfterDraftItemRelation($reid)
|
|
{
|
|
$next = false;
|
|
foreach($this->booking_draft_items as $booking_draft_items) {
|
|
if($next){
|
|
return $booking_draft_items;
|
|
}
|
|
if ($booking_draft_items->id == $reid) {
|
|
$next = true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getStartDateFormat(){
|
|
if(!$this->attributes['start_date']){ return ""; }
|
|
return Carbon::parse($this->attributes['start_date'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
public function getEndDateFormat(){
|
|
if(!$this->attributes['end_date']){ return ""; }
|
|
return Carbon::parse($this->attributes['end_date'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
}
|