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 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()); } }