File Controller, Booking Organisation, import Draft, old arrangements

This commit is contained in:
Kevin Adametz 2025-09-04 10:35:45 +02:00
parent 4eb83def39
commit 8fd1f4d451
289 changed files with 36649 additions and 10877 deletions

View file

@ -207,27 +207,27 @@ class Booking extends Model
protected $table = 'booking';
protected $casts = [
'customer_id' => 'int',
'lead_id' => 'int',
'new_drafts' => 'bool',
'sf_guard_user_id' => 'int',
'branch_id' => 'int',
protected $casts = [
'customer_id' => 'int',
'lead_id' => 'int',
'new_drafts' => 'bool',
'sf_guard_user_id' => 'int',
'branch_id' => 'int',
'airport_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',
'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',
@ -240,55 +240,55 @@ class Booking extends Model
'participant_pass' => 'bool'
];
protected $dates = [
'booking_date',
'start_date',
'end_date',
'participant_birthdate',
'final_payment_date',
protected $dates = [
'booking_date',
'start_date',
'end_date',
'participant_birthdate',
'final_payment_date',
'refund_date',
'lawyer_date',
'xx_tkt_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',
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',
'comfort',
'start_date',
'end_date',
'website_id',
'travel_number',
'participant_name',
'participant_firstname',
'participant_birthdate',
'participant_salutation_id',
'start_date',
'end_date',
'website_id',
'travel_number',
'participant_name',
'participant_firstname',
'participant_birthdate',
'participant_salutation_id',
'participant_pass',
'nationality_id',
'ev_number',
'merlin_knr',
'merlin_order_number',
'travel_company_id',
'travel_documents',
'price',
'ev_number',
'merlin_knr',
'merlin_order_number',
'travel_company_id',
'travel_documents',
'price',
'price_canceled',
'price_total',
'price_total',
'price_balance',
'deposit_total',
'final_payment',
'final_payment_date',
'travelagenda_id',
'deposit_total',
'final_payment',
'final_payment_date',
'travelagenda_id',
'insurance_offer',
'paying_out',
'paying_out_status',
@ -304,10 +304,10 @@ class Booking extends Model
'filekey',
'is_rail_fly',
'notice',
];
];
public static $paying_out_types = [
0 => '-',
public static $paying_out_types = [
0 => '-',
1 => 'Gutschein',
2 => 'Auszahlung',
3 => 'Umbuchung',
@ -345,8 +345,8 @@ class Booking extends Model
];
public static $customer_mail_dirs = [
11 => ['name' => 'Entwürfe', 'icon'=>'ion-md-create'],
12 => ['name' => 'Papierkorb', 'icon'=>'ion-md-trash'],
11 => ['name' => 'Entwürfe', 'icon' => 'ion-md-create'],
12 => ['name' => 'Papierkorb', 'icon' => 'ion-md-trash'],
];
protected $paying_out_colors = [
0 => '',
@ -377,47 +377,47 @@ class Booking extends Model
protected $passolutionPDFs = [];
/*public function branch()
/*public function branch()
{
return $this->belongsTo(Branch::class);
}*/
public function coupon()
{
return $this->belongsTo(Coupon::class);
}
public function coupon()
{
return $this->belongsTo(Coupon::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function sf_guard_user()
{
return $this->belongsTo(SfGuardUser::class);
}
public function sf_guard_user()
{
return $this->belongsTo(SfGuardUser::class);
}
public function travel_category()
{
return $this->belongsTo(TravelCategory::class);
}
public function travel_category()
{
return $this->belongsTo(TravelCategory::class);
}
public function travel_company()
{
return $this->belongsTo(TravelCompany::class);
}
public function travel_company()
{
return $this->belongsTo(TravelCompany::class);
}
public function airport()
{
return $this->belongsTo(Airport::class, 'airport_id');
}
{
return $this->belongsTo(Airport::class, 'airport_id');
}
/* public function travel_country()
/* public function travel_country()
{
return $this->belongsTo(TravelCountry::class, 'travel_country_id', 'crm_id');
}*/
@ -428,64 +428,64 @@ class Booking extends Model
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()
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 arrangements()
{
return $this->hasMany(Arrangement::class)->orderBy('view_position', 'DESC');
}
public function arrangement_types()
{
return $this->hasMany(ArrangementType::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_draft_items()
{
return $this->hasMany(BookingDraftItem::class)->orderBy('pos', 'ASC');
}
public function booking_service_items()
{
return $this->hasMany(BookingServiceItem::class);
}
public function booking_service_items()
{
return $this->hasMany(BookingServiceItem::class);
}
public function coupons()
{
return $this->hasMany(Coupon::class);
}
public function coupons()
{
return $this->hasMany(Coupon::class);
}
public function insurance_certificates()
{
return $this->hasMany(InsuranceCertificate::class);
}
public function insurance_certificates()
{
return $this->hasMany(InsuranceCertificate::class);
}
public function participants()
{
return $this->hasMany(Participant::class);
}
public function participants()
{
return $this->hasMany(Participant::class);
}
public function participant_salutation()
{
return $this->belongsTo(Salutation::class, 'participant_salutation_id');
}
{
return $this->belongsTo(Salutation::class, 'participant_salutation_id');
}
public function service_provider_entries()
{
return $this->hasMany(ServiceProviderEntry::class);
}
public function service_provider_entries()
{
return $this->hasMany(ServiceProviderEntry::class);
}
public function customer_mails()
@ -519,9 +519,9 @@ class Booking extends Model
}
public function booking_stornos()
{
return $this->hasMany(BookingStorno::class);
}
{
return $this->hasMany(BookingStorno::class);
}
/*public function booking_invoices()
{
@ -529,19 +529,19 @@ class Booking extends Model
}*/
public function booking_vouchers()
{
return $this->hasMany(BookingVoucher::class);
}
{
return $this->hasMany(BookingVoucher::class);
}
public function booking_voucher_agencys()
{
return $this->hasMany(BookingVoucherAgency::class);
}
{
return $this->hasMany(BookingVoucherAgency::class);
}
public function travel_insurances()
{
return $this->hasMany(TravelInsurance::class);
}
public function travel_insurances()
{
return $this->hasMany(TravelInsurance::class);
}
public function booking_files()
{
@ -592,17 +592,17 @@ class Booking extends Model
}
public function booking_strono()
{
return $this->hasOne(BookingStorno::class);
}
{
return $this->hasOne(BookingStorno::class);
}
public function getAirlinesAsNames()
{
$ret = "";
if($this->airline_ids){
foreach($this->airline_ids as $airline_id){
if($Airline = Airline::find($airline_id)){
$ret .= $Airline->name." ";
if ($this->airline_ids) {
foreach ($this->airline_ids as $airline_id) {
if ($Airline = Airline::find($airline_id)) {
$ret .= $Airline->name . " ";
}
}
}
@ -610,13 +610,13 @@ class Booking extends Model
}
public function getAirlinesIds()
{
if($this->airline_ids){
if ($this->airline_ids) {
return implode('', $this->airline_ids);
}
return "";
}
public function hasBookingServicesUnchecked(){
public function hasBookingServicesUnchecked()
{
$country_services = true;
$provider_services = true;
$company_services = true;
@ -625,101 +625,102 @@ class Booking extends Model
$has_provider_services = false;
$has_company_services = false;
if($this->travel_country){
foreach($this->travel_country->getContactLandsModels() as $TravelCountry){
if($TravelCountry->stern_travel_country){
if($TravelCountry->stern_travel_country->travel_country_services->count()){
if ($this->travel_country) {
foreach ($this->travel_country->getContactLandsModels() as $TravelCountry) {
if ($TravelCountry->stern_travel_country) {
if ($TravelCountry->stern_travel_country->travel_country_services->count()) {
$has_country_services = true;
}
}
}
}
if($has_country_services && !$this->booking_country_services->count() || $this->booking_country_services_checked->count() ||
($this->booking_country_services->count() !== TravelCountryService::where('crm_travel_country_id', '=', $this->travel_country_id)->count())){
$country_services = false;
if (
$has_country_services && !$this->booking_country_services->count() || $this->booking_country_services_checked->count() ||
($this->booking_country_services->count() !== TravelCountryService::where('crm_travel_country_id', '=', $this->travel_country_id)->count())
) {
$country_services = false;
}
foreach($this->service_provider_entries as $service_provider_entry){
if($service_provider_entry->service_provider && $service_provider_entry->service_provider->service_provider_services->count()){
foreach ($this->service_provider_entries as $service_provider_entry) {
if ($service_provider_entry->service_provider && $service_provider_entry->service_provider->service_provider_services->count()) {
$has_provider_services = true;
}
}
if($has_provider_services && !$this->booking_provider_services->count() || $this->booking_provider_services_checked->count()){
if($this->service_provider_entries->count()){
if ($has_provider_services && !$this->booking_provider_services->count() || $this->booking_provider_services_checked->count()) {
if ($this->service_provider_entries->count()) {
$provider_services = false;
}
}
foreach($this->booking_service_items as $booking_service_item){
if($booking_service_item->travel_company && $booking_service_item->travel_company->travel_company_services->count()){
foreach ($this->booking_service_items as $booking_service_item) {
if ($booking_service_item->travel_company && $booking_service_item->travel_company->travel_company_services->count()) {
$has_company_services = true;
}
}
if($has_company_services && !$this->booking_company_services->count() || $this->booking_company_services_checked->count()){
if($this->booking_service_items->count()){
$company_services = false;
if ($has_company_services && !$this->booking_company_services->count() || $this->booking_company_services_checked->count()) {
if ($this->booking_service_items->count()) {
$company_services = false;
}
}
if(!$has_country_services && !$has_provider_services && !$has_company_services){
if (!$has_country_services && !$has_provider_services && !$has_company_services) {
return false;
}
if($country_services && $provider_services && $company_services){
if ($country_services && $provider_services && $company_services) {
return true;
}
return false;
}
public function hasBookingParticipantsPass(){
if($this->participant_firstname){
if(!$this->participant_pass){
public function hasBookingParticipantsPass()
{
if ($this->participant_firstname) {
if (!$this->participant_pass) {
return false;
}
}
if($this->participants->count()){
foreach($this->participants as $participant){
if(!$participant->participant_pass){
if ($this->participants->count()) {
foreach ($this->participants as $participant) {
if (!$participant->participant_pass) {
return false;
}
}
}
return true;
}
public function getPassolutionPDF($create = false, $resync = false){
public function getPassolutionPDF($create = false, $resync = false)
{
$nats = [];
if(count($this->passolutionPDFs)){
return $this->passolutionPDFs;
if (count($this->passolutionPDFs)) {
return $this->passolutionPDFs;
}
if(!$this->travel_country){
return $this->passolutionPDFs;
if (!$this->travel_country) {
return $this->passolutionPDFs;
}
$destco = $this->travel_country->destco;
if($this->travel_nationality){
if ($this->travel_nationality) {
$nats[$this->travel_nationality->nat] = $this->travel_nationality->nat;
}
if($this->participants->count()){
foreach ($this->participants as $participant){
if($participant->travel_nationality){
if ($this->participants->count()) {
foreach ($this->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){
if (empty($nats)) {
$nats['de'] = 'de';
}
foreach ($nats as $nat) {
$data = [
'nat' => $nat,
'destco' => $destco,
@ -728,11 +729,12 @@ class Booking extends Model
$passolution = new Passolution($data);
$this->passolutionPDFs[] = $passolution->findOrCreatePDF($create, $resync);
}
return $this->passolutionPDFs;
return $this->passolutionPDFs;
}
public function resyncPassolutionPDF(){
return $this->getPassolutionPDF(true, true);
public function resyncPassolutionPDF()
{
return $this->getPassolutionPDF(true, true);
}
public function calculate_price_total()
@ -746,13 +748,13 @@ class Booking extends Model
$travel_children = 0;
foreach ($this->booking_draft_items as $booking_draft_item) {
//24 Rundreise ist der Grundeintrag für die Reise
if($booking_draft_item->draft_type_id == 24){
if ($booking_draft_item->draft_type_id == 24) {
$travel_draft_item = $booking_draft_item;
continue;
}
$prices = $booking_draft_item->getItemPrice();
//Grundpreis Reise //pro Persopn im Zimmer
if($booking_draft_item->draft_type_id == 30){
if ($booking_draft_item->draft_type_id == 30) {
$travel_price_adult += $prices['adult'];
$travel_price_children += $prices['children'];
$travel_adult += $booking_draft_item->adult;
@ -762,9 +764,9 @@ class Booking extends Model
$total_children += $prices['children'];
}
if($travel_draft_item){
if ($travel_draft_item) {
$travel_draft_item->setPriceAdultRaw($travel_price_adult);
$travel_draft_item->setPriceChildrenRaw($travel_price_children);
$travel_draft_item->adult = $travel_adult;
@ -774,7 +776,6 @@ class Booking extends Model
$this->price = $total_adult + $total_children;
$this->price_total = $this->getPriceRaw() + $this->getServiceTotal(true);
$this->save();
}
public function getPriceAttribute()
@ -845,7 +846,7 @@ class Booking extends Model
public function findBeforeDraftItemRelation($reid)
{
$before = false;
foreach($this->booking_draft_items as $booking_draft_items) {
foreach ($this->booking_draft_items as $booking_draft_items) {
if ($booking_draft_items->id == $reid) {
return $before;
}
@ -857,8 +858,8 @@ class Booking extends Model
public function findAfterDraftItemRelation($reid)
{
$next = false;
foreach($this->booking_draft_items as $booking_draft_items) {
if($next){
foreach ($this->booking_draft_items as $booking_draft_items) {
if ($next) {
return $booking_draft_items;
}
if ($booking_draft_items->id == $reid) {
@ -868,41 +869,54 @@ class Booking extends Model
return false;
}
public function getStartDateFormat(){
if(!$this->attributes['start_date']){ return ""; }
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 ""; }
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 ""; }
public function getBookingDateFormat()
{
if (!$this->attributes['booking_date']) {
return "";
}
return Carbon::parse($this->attributes['booking_date'])->format(\Util::formatDateDB());
}
public function getFinalPaymentDateFormat(){
if(!$this->attributes['final_payment_date']){ return ""; }
public function getFinalPaymentDateFormat()
{
if (!$this->attributes['final_payment_date']) {
return "";
}
return Carbon::parse($this->attributes['final_payment_date'])->format(\Util::formatDateDB());
}
public function isCanceled(){
public function isCanceled()
{
return ($this->attributes['canceled'] !== null);
}
//erlös #getRevenueFactor
public function proceeds($raw = false){
public function proceeds($raw = false)
{
$proceeds = $this->attributes['price'] - $this->attributes['price_balance'] - $this->getServiceProviderPaymentsFactorTotal(true);
return $raw ? $proceeds : Util::_number_format($proceeds);
}
public function getServiceTotal($raw = false)
{
$total = 0;
foreach ($this->booking_service_items as $booking_service_item){
foreach ($this->booking_service_items as $booking_service_item) {
$total += $booking_service_item->getServicePriceRaw();
}
return $raw ? $total : Util::_number_format($total);
@ -912,7 +926,7 @@ class Booking extends Model
public function getServiceProviderPaymentsFactorTotal($raw = false)
{
$total = 0;
foreach ($this->service_provider_entries as $entry){
foreach ($this->service_provider_entries as $entry) {
$total += $entry->getAmountRaw() / $entry->getFactortRaw();
}
return $raw ? $total : Util::_number_format($total);
@ -921,15 +935,16 @@ class Booking extends Model
public function getServiceProviderPaymentsTotal($raw = false)
{
$total = 0;
foreach ($this->service_provider_entries as $entry){
foreach ($this->service_provider_entries as $entry) {
$total += $entry->getAmountRaw();
}
return $raw ? $total : Util::_number_format($total);
}
public function getKontoNumber(){
public function getKontoNumber()
{
switch ($this->ev_number){
switch ($this->ev_number) {
case 'E01':
return '4011';
break;
@ -942,44 +957,48 @@ class Booking extends Model
case 'E04':
return '4014';
break;
}
return $this->ev_number;
}
public function getBookingNumber()
{
if ($this->lead)
{
if ($this->lead) {
return $this->lead->id;
}
return null;
}
public function getPayingOutType(){
public function getPayingOutType()
{
return isset(self::$paying_out_types[$this->paying_out]) ? self::$paying_out_types[$this->paying_out] : '-';
}
public function getInsuranceOfferType(){
public function getInsuranceOfferType()
{
return isset(self::$insurance_offer_types[$this->insurance_offer]) ? self::$insurance_offer_types[$this->insurance_offer] : '-';
}
public function getPayingOutStatusType(){
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(){
public function getRefundType()
{
return isset(self::$refund_types[$this->refund]) ? self::$refund_types[$this->refund] : '-';
}
public function getXxTktType(){
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){
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];
@ -987,9 +1006,10 @@ class Booking extends Model
return "-";
}
public function getRefundTypeList(){
if(isset(self::$refund_types[$this->refund])){
if($this->refund == 1 && $this->refund_date){
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];
@ -997,57 +1017,65 @@ class Booking extends Model
return "-";
}
public function getPayingOutColor(){
public function getPayingOutColor()
{
return isset($this->paying_out_colors[$this->paying_out]) ? $this->paying_out_colors[$this->paying_out] : '';
}
public function getPayingOutStatusColor(){
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(){
public function getRefundColor()
{
return isset($this->refund_colors[$this->refund]) ? $this->refund_colors[$this->refund] : '-';
}
public function getXxTktColor(){
public function getXxTktColor()
{
return isset($this->xx_tkt_colors[$this->xx_tkt]) ? $this->xx_tkt_colors[$this->xx_tkt] : '-';
}
public function countCustomerMailsBy($dir, $subdir=false){
public function countCustomerMailsBy($dir, $subdir = false)
{
if($dir === 11){
if ($dir === 11) {
return $this->customer_mails->where('draft', true)->where('dir', '!=', 12)->count();
}
if($subdir){
return $this->customer_mails->where('dir', $dir)->where('subdir', $subdir)->count();
if ($subdir) {
return $this->customer_mails->where('dir', $dir)->where('subdir', $subdir)->count();
}
return $this->customer_mails->where('dir', $dir)->count();
}
/*DOCUMENTS*/
public function hasDocument($identifier){
public function hasDocument($identifier)
{
return $this->booking_documents->where('identifier', $identifier)->count() ? true : false;
}
public function getDocument($identifier){
public function getDocument($identifier)
{
return $this->booking_documents->where('identifier', $identifier)->first();
}
public function isDepositPossible($maxIntervalDays = false)
{
$maxIntervalDays = $maxIntervalDays ? $maxIntervalDays : config('booking.max_interval_days');
$diffInDays = $this->booking_date->diffInDays($this->start_date, false);
return $diffInDays > $maxIntervalDays;
$maxIntervalDays = $maxIntervalDays ? $maxIntervalDays : config('booking.max_interval_days');
$diffInDays = $this->booking_date->diffInDays($this->start_date, false);
return $diffInDays > $maxIntervalDays;
}
public function getConfirmationDeposit($percentageRate = false){
public function getConfirmationDeposit($percentageRate = false)
{
$percentageRate = $percentageRate ? $percentageRate : config('booking.deposit_percentage_rate');
return ($this->isDepositPossible() ? round($this->getPriceRaw() * $percentageRate / 100) : 0);
}
public function getConfirmationFinalPayment(){
public function getConfirmationFinalPayment()
{
return $this->getPriceRaw() - $this->getConfirmationDeposit();
}
}