Mail and Booking

This commit is contained in:
Kevin Adametz 2020-04-15 12:11:42 +02:00
parent 62e84637b6
commit 5daea268f7
250 changed files with 5377 additions and 1473 deletions

View file

@ -8,7 +8,7 @@ namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Reliese\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Model;
/**
* Class Booking
@ -116,6 +116,44 @@ use Reliese\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereWebsiteId($value)
* @mixin \Eloquent
* @property-read int|null $service_provider_entries_count
* @property float|null $canceled
* @property float|null $price_canceled
* @property int|null $paying_out
* @property int|null $paying_out_status
* @property int|null $airline_id
* @property int|null $refund
* @property \Illuminate\Support\Carbon|null $refund_date
* @property int|null $hold
* @property int|null $xx_tkt
* @property string|null $xx_tkt_date
* @property string|null $filekey
* @property-read \App\Models\Airline|null $airline
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CustomerMail[] $customer_mails
* @property-read int|null $customer_mails_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CustomerMail[] $customer_mails_sent_at
* @property-read int|null $customer_mails_sent_at_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereAirlineId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereCanceled($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereFilekey($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereHold($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePayingOut($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePayingOutStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking wherePriceCanceled($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereRefund($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereRefundDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereXxTkt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereXxTktDate($value)
* @property int|null $is_rail_fly
* @property string|null $notice
* @property-read \App\Models\CustomerMail $customer_mail_last
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereIsRailFly($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Booking whereNotice($value)
* @property-read int|null $booking_applications_count
* @property-read int|null $booking_confirmations_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\BookingStorno[] $booking_stornos
* @property-read int|null $booking_stornos_count
* @property-read int|null $booking_vouchers_count
* @property-read int|null $travel_insurances_count
*/
class Booking extends Model
{
@ -144,6 +182,8 @@ class Booking extends Model
'final_payment' => 'float',
'travelagenda_id' => 'int',
'paying_out' => 'int',
'hold' => 'int',
'airline_id' => 'int',
'refund' => 'int',
'xx_tkt' => 'int',
@ -192,6 +232,8 @@ class Booking extends Model
'travelagenda_id',
'paying_out',
'paying_out_status',
'airline_id',
'hold',
'refund',
'refund_date',
'xx_tkt',
@ -225,7 +267,14 @@ class Booking extends Model
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',
@ -252,6 +301,38 @@ class Booking extends Model
1 => 'danger',
2 => 'success',
];
/*
*
* <ul class="tabscontrol flatlist clearfix" id="tabscontrol">
<li class="tab"><a href="#customer" class="active"><?php echo __('Kunde') ?></a></li>
<?php if ($booking->relatedExists('Application')): ?>
<li class="tab"><a href="#application" class="active"><?php echo __('Reiseanmeldung') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('Confirmation')): ?>
<li class="tab"><a href="#confirmation" class="active"><?php echo __('Reisebestätigung') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('Invoice')): ?>
<li class="tab"><a href="#invoice" class="active"><?php echo __('Rechnung') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('Storno')): ?>
<li class="tab"><a href="#storno" class="active"><?php echo __('Storno') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('TravelInsurance')): ?>
<li class="tab"><a href="#travelinsurance" class="active"><?php echo __('Versicherung') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('InsuranceCertificate')): ?>
<li class="tab"><a href="#insurance" class="active"><?php echo __('Sicherungsschein') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('Voucher')): ?>
<li class="tab"><a href="#voucher" class="active"><?php echo __('Voucher') ?></a></li>
<?php endif; ?>
<?php if ($booking->relatedExists('Coupon')): ?>
<li class="tab"><a href="#coupon" class="active"><?php echo __('Gutscheine') ?></a></li>
<?php endif; ?>
*/
/*public function branch()
{
return $this->belongsTo(Branch::class);
@ -303,6 +384,11 @@ class Booking extends Model
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);
@ -313,35 +399,18 @@ class Booking extends Model
return $this->hasMany(ArrangementType::class);
}
/*public function booking_applications()
{
return $this->hasMany(BookingApplication::class);
}
public function booking_confirmations()
{
return $this->hasMany(BookingConfirmation::class);
}*/
public function booking_draft_items()
{
return $this->hasMany(BookingDraftItem::class)->orderBy('pos', 'ASC');
}
/*public function booking_invoices()
{
return $this->hasMany(BookingInvoice::class);
}*/
public function booking_service_items()
{
return $this->hasMany(BookingServiceItem::class);
}
/*public function booking_vouchers()
{
return $this->hasMany(BookingVoucher::class);
}*/
public function coupons()
{
@ -373,11 +442,41 @@ class Booking extends Model
{
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()
@ -461,6 +560,21 @@ class Booking extends Model
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(){
@ -483,6 +597,16 @@ class Booking extends Model
return $total;
}
public function getServiceProviderPaymentsTotalRaw()
{
$total = 0;
foreach ($this->service_provider_entries as $entry)
{
$total += $entry->amount;
}
return $total;
}
public function getServiceProviderPaymentsTotal()
{
$total = 0;
@ -513,6 +637,16 @@ class Booking extends Model
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] : '-';
}
@ -565,5 +699,14 @@ class Booking extends Model
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();
}
}