'int',
'lead_id' => 'int',
'new_drafts' => 'bool',
'sf_guard_user_id' => 'int',
'branch_id' => 'int',
'service_fee' => 'float',
'travel_country_id' => 'int',
'travel_category_id' => 'int',
'pax' => 'int',
'coupon_id' => 'int',
'website_id' => 'int',
'participant_salutation_id' => 'int',
'travel_company_id' => 'int',
'travel_documents' => 'bool',
'price' => 'float',
'price_total' => 'float',
'deposit_total' => 'float',
'final_payment' => 'float',
'travelagenda_id' => 'int',
'paying_out' => 'int',
'hold' => 'int',
'airline_id' => 'int',
'refund' => 'int',
'xx_tkt' => 'int',
];
protected $dates = [
'booking_date',
'start_date',
'end_date',
'participant_birthdate',
'final_payment_date',
'refund_date'
];
protected $fillable = [
'booking_date',
'customer_id',
'lead_id',
'new_drafts',
'sf_guard_user_id',
'branch_id',
'service_fee',
'travel_country_id',
'travel_category_id',
'pax',
'coupon_id',
'title',
'start_date',
'end_date',
'website_id',
'travel_number',
'participant_name',
'participant_firstname',
'participant_birthdate',
'participant_salutation_id',
'ev_number',
'merlin_knr',
'merlin_order_number',
'travel_company_id',
'travel_documents',
'price',
'price_total',
'deposit_total',
'final_payment',
'final_payment_date',
'travelagenda_id',
'paying_out',
'paying_out_status',
'airline_id',
'hold',
'refund',
'refund_date',
'xx_tkt',
'xx_tkt_date',
];
public static $paying_out_types = [
0 => '-',
1 => 'Gutschein',
2 => 'Auszahlung',
3 => 'Umbuchung',
4 => 'AZ + GS',
5 => 'AZ o. FP',
];
public static $refund_types = [
0 => '-',
1 => 'eingereicht',
2 => 'erledigt',
];
public static $xx_tkt_types = [
0 => '-',
1 => 'offen',
2 => 'erledigt',
];
public static $paying_out_status_types = [
0 => '-',
1 => 'offen',
2 => 'erledigt',
];
public static $customer_mail_dirs = [
0 => ['name' => 'Reisender', 'icon'=>'ion-ios-filing'],
1 => ['name' => 'Agentur', 'icon'=>'ion-ios-folder-open'],
2 => ['name' => 'Flug', 'icon'=>'ion-ios-airplane'],
3 => ['name' => 'Versicherung', 'icon'=>'ion-ios-help-buoy'],
11 => ['name' => 'Entwürfe', 'icon'=>'ion-md-create'],
12 => ['name' => 'Papierkorb', 'icon'=>'ion-md-trash'],
];
protected $paying_out_colors = [
0 => '',
1 => 'info',
2 => 'dark',
3 => 'warning',
4 => 'warning',
5 => 'warning',
];
protected $refund_colors = [
0 => '',
1 => 'warning',
2 => 'success',
];
protected $xx_tkt_colors = [
0 => '',
1 => 'danger',
2 => 'success',
];
protected $paying_out_status_colors = [
0 => '',
1 => 'danger',
2 => 'success',
];
/*
*
*
relatedExists('Application')): ?>
relatedExists('Confirmation')): ?>
relatedExists('Invoice')): ?>
relatedExists('Storno')): ?>
relatedExists('TravelInsurance')): ?>
relatedExists('InsuranceCertificate')): ?>
relatedExists('Voucher')): ?>
relatedExists('Coupon')): ?>
*/
/*public function branch()
{
return $this->belongsTo(Branch::class);
}*/
public function coupon()
{
return $this->belongsTo(Coupon::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function sf_guard_user()
{
return $this->belongsTo(SfGuardUser::class);
}
public function travel_category()
{
return $this->belongsTo(TravelCategory::class);
}
public function travel_company()
{
return $this->belongsTo(TravelCompany::class);
}
/* public function travel_country()
{
return $this->belongsTo(TravelCountry::class, 'travel_country_id', 'crm_id');
}*/
public function travel_country()
{
return $this->belongsTo(\App\Models\Sym\TravelCountry::class, 'travel_country_id', 'id');
}
public function travel_agenda()
{
return $this->belongsTo(TravelAgenda::class, 'travelagenda_id');
}
public function airline()
{
return $this->belongsTo(Airline::class, 'airline_id');
}
public function arrangements()
{
return $this->hasMany(Arrangement::class);
}
public function arrangement_types()
{
return $this->hasMany(ArrangementType::class);
}
public function booking_draft_items()
{
return $this->hasMany(BookingDraftItem::class)->orderBy('pos', 'ASC');
}
public function booking_service_items()
{
return $this->hasMany(BookingServiceItem::class);
}
public function coupons()
{
return $this->hasMany(Coupon::class);
}
public function insurance_certificates()
{
return $this->hasMany(InsuranceCertificate::class);
}
public function participants()
{
return $this->hasMany(Participant::class);
}
public function service_provider_entries()
{
return $this->hasMany(ServiceProviderEntry::class);
}
public function customer_mails()
{
return $this->hasMany(CustomerMail::class, 'booking_id', 'id');
}
public function customer_mails_sent_at()
{
return $this->hasMany(CustomerMail::class, 'booking_id')->orderBy('sent_at', 'ASC');
}
public function customer_mail_last()
{
return $this->hasOne(CustomerMail::class, 'booking_id')->latest();
}
public function booking_applications()
{
return $this->hasMany(BookingApplication::class);
}
public function booking_confirmations()
{
return $this->hasMany(BookingConfirmation::class);
}
public function booking_stornos()
{
return $this->hasMany(BookingStorno::class);
}
/*public function booking_invoices()
{
return $this->hasMany(BookingInvoice::class);
}*/
public function booking_vouchers()
{
return $this->hasMany(BookingVoucher::class);
}
public function travel_insurances()
{
return $this->hasMany(TravelInsurance::class);
}
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 getPriceRaw()
{
return $this->attributes['price'];
}
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());
}
public function getBookingDateFormat(){
if(!$this->attributes['booking_date']){ return ""; }
return Carbon::parse($this->attributes['booking_date'])->format(\Util::formatDateDB());
}
//erlös #getRevenueFactor
public function proceedsRaw(){
$total = 0;
foreach ($this->service_provider_entries as $entry)
{
$total += $entry->amount / $entry->factor;
}
return $this->attributes['price'] - $total;
}
//erlös #getRevenueFactor
public function proceeds(){
$proceeds = $this->attributes['price']
// - $this->getServiceTotal()
// - $this->getServiceFee()
- $this->getServiceProviderEntriesAmountFactorTotal();
return number_format(($proceeds), 2, ',', '.');
}
public function getServiceProviderEntriesAmountFactorTotal()
{
$total = 0;
foreach ($this->service_provider_entries as $entry)
{
$total += $entry->amount / $entry->factor;
}
return $total;
}
public function getServiceProviderPaymentsTotalRaw()
{
$total = 0;
foreach ($this->service_provider_entries as $entry)
{
$total += $entry->amount;
}
return $total;
}
public function getServiceProviderPaymentsTotal()
{
$total = 0;
foreach ($this->service_provider_entries as $entry)
{
$total += $entry->amount;
}
return number_format(($total), 2, ',', '.');
}
public function getKontoNumber(){
switch ($this->ev_number){
case 'E01':
return '4011';
break;
case 'E02':
return '4012';
break;
case 'E03':
return '4013';
break;
case 'E04':
return '4014';
break;
}
return $this->ev_number;
}
public function getBookingNumber()
{
if ($this->lead)
{
return $this->lead->id;
}
return null;
}
public function getPayingOutType(){
return isset(self::$paying_out_types[$this->paying_out]) ? self::$paying_out_types[$this->paying_out] : '-';
}
public function getPayingOutStatusType(){
return isset(self::$paying_out_status_types[$this->paying_out_status]) ? self::$paying_out_status_types[$this->paying_out_status] : '-';
}
public function getRefundType(){
return isset(self::$refund_types[$this->refund]) ? self::$refund_types[$this->refund] : '-';
}
public function getXxTktType(){
return isset(self::$xx_tkt_types[$this->xx_tkt]) ? self::$xx_tkt_types[$this->xx_tkt] : '-';
}
public function getXxTktTypeList(){
if(isset(self::$xx_tkt_types[$this->xx_tkt])){
if($this->xx_tkt == 1 && $this->xx_tkt_date){
return Carbon::parse($this->xx_tkt_date)->format('d.m.Y');
}
return self::$xx_tkt_types[$this->xx_tkt];
}
return "-";
}
public function getRefundTypeList(){
if(isset(self::$refund_types[$this->refund])){
if($this->refund == 1 && $this->refund_date){
return Carbon::parse($this->refund_date)->format('d.m.Y');
}
return self::$refund_types[$this->refund];
}
return "-";
}
public function getPayingOutColor(){
return isset($this->paying_out_colors[$this->paying_out]) ? $this->paying_out_colors[$this->paying_out] : '';
}
public function getPayingOutStatusColor(){
return isset($this->paying_out_status_colors[$this->paying_out_status]) ? $this->paying_out_status_colors[$this->paying_out_status] : '';
}
public function getRefundColor(){
return isset($this->refund_colors[$this->refund]) ? $this->refund_colors[$this->refund] : '-';
}
public function getXxTktColor(){
return isset($this->xx_tkt_colors[$this->xx_tkt]) ? $this->xx_tkt_colors[$this->xx_tkt] : '-';
}
public function countCustomerMailsBy($dir, $country=false){
if($dir === 11){
return $this->customer_mails->where('draft', true)->count();
}
if($country){
return $this->customer_mails->where('dir', $dir)->where('travel_country_id', $country)->count();
}
return $this->customer_mails->where('dir', $dir)->count();
}
}