'int', 'travelperiod_length' => 'int', 'travelcountry_id' => 'int', 'travelagenda_id' => 'int', 'sf_guard_user_id' => 'int', 'is_closed' => 'bool', 'is_rebook' => 'bool', 'initialcontacttype_id' => 'int', 'searchengine_id' => 'int', 'status_id' => 'int', 'website_id' => 'int', 'travelcategory_id' => 'int', 'price' => 'float', 'pax' => 'int', 'participant_salutation_id' => 'int', 'request_date' => 'datetime', 'travelperiod_start' => 'datetime', 'travelperiod_end' => 'datetime', 'next_due_date' => 'datetime', 'participant_birthdate' => 'datetime', ]; protected $fillable = [ 'customer_id', 'request_date', 'travelperiod_start', 'travelperiod_end', 'travelperiod_length', 'travelcountry_id', 'travelagenda_id', 'remarks', 'sf_guard_user_id', 'is_closed', 'is_rebook', 'initialcontacttype_id', 'searchengine_id', 'searchengine_keywords', 'status_id', 'next_due_date', 'website_id', 'travelcategory_id', 'price', 'pax', 'participant_name', 'participant_firstname', 'participant_birthdate', 'participant_salutation_id' ]; protected $passolutionPDFs = []; public static $lead_mail_dirs = [ 11 => ['name' => 'Entwürfe', 'icon'=>'ion-md-create'], 12 => ['name' => 'Papierkorb', 'icon'=>'ion-md-trash'], ]; public function updateNextDueDate($date = false){ if(!$date){ $carbon = Carbon::now(); }else{ $carbon = Carbon::parse($date); } $this->next_due_date = $carbon->modify('+ '.$this->status->handling_days.' days')->format("Y-m-d"); $this->save(); } public function customer() { return $this->belongsTo(Customer::class); } public function initial_contact_type() { return $this->belongsTo(InitialContactType::class, 'initialcontacttype_id'); } public function salutation() { return $this->belongsTo(Salutation::class, 'participant_salutation_id'); } public function searchengine() { return $this->belongsTo(Searchengine::class); } public function sf_guard_user() { return $this->belongsTo(SfGuardUser::class); } public function status() { return $this->belongsTo(Status::class); } public function travel_agenda() { return $this->belongsTo(TravelAgenda::class, 'travelagenda_id'); } public function travel_category() { return $this->belongsTo(TravelCategory::class, 'travelcategory_id'); } //on crm public function travel_country_crm() { return $this->belongsTo('App\Models\Sym\TravelCountry', 'travelcountry_id', 'id'); } //on stern other DB public function travel_country() { return $this->belongsTo('App\Models\TravelCountry', 'travelcountry_id', 'crm_id'); } public function website() { return $this->belongsTo(Website::class); } public function bookings() { return $this->hasMany(Booking::class); } public function inquiries() { return $this->hasMany(Inquiry::class); } public function lead_participants() { return $this->hasMany(LeadParticipant::class); } public function offers() { return $this->hasMany(Offer::class); } public function status_histories() { return $this->hasMany(StatusHistory::class)->orderByDesc('id')->orderByDesc('date'); } public function lead_files() { //no lead_mail_id return $this->hasMany(LeadFile::class, 'lead_id')->where('lead_mail_id', null); } public function lead_mails() { return $this->hasMany(LeadMail::class, 'lead_id', 'id'); } public function lead_mails_sent_at() { return $this->hasMany(LeadMail::class, 'lead_id')->orderBy('sent_at', 'ASC'); } public function lead_mail_last() { return $this->hasOne(LeadMail::class, 'lead_id')->latest(); } public function lead_notices() { return $this->hasMany(LeadNotice::class, 'lead_id')->orderBy('updated_at', 'DESC'); } public static function getSfGuardUserArray(){ return SfGuardUser::where('is_active', 1)->get()->pluck('fullname', 'id'); } public static function getTravelCountryArray($emtpy = false){ $TravelCountry = TravelCountry::where('active_backend', 1)->orderBy('name')->get()->pluck('name', 'id'); return $emtpy ? $TravelCountry->prepend('-', 0) : $TravelCountry; } public static function getTravelCategoryArray($emtpy = false){ $TravelCategory = TravelCategory::orderBy('name')->get()->pluck('name', 'id'); return $emtpy ? $TravelCategory->prepend('-', 0) : $TravelCategory; } public static function getTravelAgendaArray($emtpy = false){ $TravelAgenda = TravelAgenda::orderBy('name')->get()->pluck('name', 'id'); return $emtpy ? $TravelAgenda->prepend('-', 0) : $TravelAgenda; } public static function getStatusArray($emtpy = false){ $Status = Status::orderBy('name')->get()->pluck('name', 'id'); return $emtpy ? $Status->prepend('-', 0) : $Status; } public function getStatusBadge($booking = null) { if($this->status_id && $this->status){ $color = $this->status->color; $icon = ""; if($this->status_id == 14 && $this->is_rebook){ $color = '#94ae59'; $icon = ' '; } if($this->status_id == 14 && !$this->is_rebook){ $icon = ' '; } if($this->status_id == 15){ $icon = ' '; if($booking && $booking->lawyer_date){ return ''.$icon.$booking->lawyer_date->format('d.m.Y').''; } } return ''.$icon.$this->status->name.''; } return '-'; } public function getTravelCountryDestco($badge = true){ $out = ""; if($this->bookings->count()){ $out .= $badge ? '' : ''; foreach ($this->bookings as $booking){ if($booking->travel_country_id && $booking->travel_country) { $out .= $booking->travel_country->destco; } } $out .= $badge ? '' : ''; return $out; } if($this->travel_country){ return $badge ? ''.$this->travel_country->destco.'' : $this->travel_country->destco; } return "-"; } public function countLeadMailsBy($dir, $subdir=false){ if($dir === 11){ return $this->lead_mails->where('draft', true)->where('dir', '!=', 12)->count(); } if($subdir){ return $this->lead_mails->where('dir', $dir)->where('subdir', $subdir)->count(); } return $this->lead_mails->where('dir', $dir)->count(); } public function getPassolutionPDF($create = false, $resync = false){ $nats = []; if(count($this->passolutionPDFs)){ return $this->passolutionPDFs; } if(!$this->travel_country){ return $this->passolutionPDFs; } $destco = $this->travel_country->destco; //default no travel_nationality $nats['de'] = 'de'; if($this->lead_participants->count()){ foreach ($this->lead_participants as $participant){ if($participant->travel_nationality){ $nats[$participant->travel_nationality->nat] = $participant->travel_nationality->nat; } } } if(empty($nats)){ $nats['de'] = 'de'; } foreach ($nats as $nat){ $data = [ 'nat' => $nat, 'destco' => $destco, ]; $passolution = new Passolution($data); $this->passolutionPDFs[] = $passolution->findOrCreatePDF($create, $resync); } return $this->passolutionPDFs; } public function resyncPassolutionPDF(){ return $this->getPassolutionPDF(true, true); } }