This commit is contained in:
Kevin Adametz 2024-08-05 11:58:09 +02:00
parent c1c613a4b9
commit 881fc84207
384 changed files with 50679 additions and 990 deletions

43
app/Models/Airport.php Normal file
View file

@ -0,0 +1,43 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class Airport
*
* @property int $id
* @property string $code
* @property string $name
* @property string $city
* @property string $country
* @property bool $active
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @package App\Models
*/
class Airport extends Model
{
protected $connection = 'mysql';
protected $table = 'airports';
protected $casts = [
'active' => 'bool'
];
protected $fillable = [
'code',
'name',
'city',
'country',
'active'
];
}

View file

@ -85,4 +85,52 @@ class Arrangement extends Model
{
return $this->belongsTo(ArrangementTemplate::class, 'template_id');
}
public function arrangement_type()
{
return $this->belongsTo(ArrangementType::class, 'type_id');
}
public function getDataAsMap()
{
$rawData = $this->attributes['data_s'];
$data = json_decode('{'. $rawData .'}', true);
if (is_array($data))
{
return $data;
}
$entries = preg_split("/[\r\n;]+\s*/", $rawData, -1, PREG_SPLIT_NO_EMPTY);
$ret = array();
foreach ($entries as $entry)
{
$map = preg_split('/:\s*/', $entry, -1, PREG_SPLIT_NO_EMPTY);
if (count($map) == 2)
{
$ret[$map[0]] = $map[1];
}
}
return $ret;
}
public function getDataS()
{
$rawData = $this->attributes['data_s'];
$data = json_decode('{'. $rawData .'}', true);
if (is_array($data))
{
$str = '';
$i = 0;
foreach ($data as $k => $v)
{
if (++$i > 0)
{
$str .= '';
}
$str .= $k .' '. $v;
}
return $str;
}
return $rawData;
}
}

View file

@ -203,6 +203,7 @@ class Booking extends Model
'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',
@ -282,6 +283,7 @@ class Booking extends Model
'paying_out',
'paying_out_status',
//'airline_id',
'airport_id',
'airline_ids',
'refund',
'refund_date',
@ -400,6 +402,11 @@ class Booking extends Model
return $this->belongsTo(TravelCompany::class);
}
public function airport()
{
return $this->belongsTo(Airport::class, 'airport_id');
}
/* public function travel_country()
{
return $this->belongsTo(TravelCountry::class, 'travel_country_id', 'crm_id');
@ -460,6 +467,11 @@ class Booking extends Model
return $this->hasMany(Participant::class);
}
public function participant_salutation()
{
return $this->belongsTo(Salutation::class, 'participant_salutation_id');
}
public function service_provider_entries()
{
return $this->hasMany(ServiceProviderEntry::class);
@ -471,6 +483,11 @@ class Booking extends Model
return $this->hasMany(CustomerMail::class, 'booking_id', 'id');
}
public function customer_mails_reverse()
{
return $this->hasMany(CustomerMail::class, 'booking_id', 'id')->orderBy('id', 'DESC');
}
public function customer_mails_sent_at()
{
return $this->hasMany(CustomerMail::class, 'booking_id')->orderBy('sent_at', 'ASC');
@ -521,6 +538,11 @@ class Booking extends Model
return $this->hasMany(BookingFile::class);
}
public function booking_documents()
{
return $this->hasMany(BookingDocument::class, 'booking_id');
}
public function booking_country_services()
{
return $this->hasMany(BookingCountryService::class, 'booking_id');
@ -991,4 +1013,31 @@ class Booking extends Model
}
return $this->customer_mails->where('dir', $dir)->count();
}
/*DOCUMENTS*/
public function hasDocument($identifier){
return $this->booking_documents->where('identifier', $identifier)->count() ? true : false;
}
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;
}
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(){
return $this->getPriceRaw() - $this->getConfirmationDeposit();
}
}

View file

@ -0,0 +1,134 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class BookingDocument
*
* @property int $id
* @property int|null $booking_id
* @property int|null $customer_id
* @property int|null $lead_id
* @property string $identifier
* @property string $filename
* @property string $dir
* @property string $original_name
* @property string $ext
* @property string $mine
* @property int $size
* @property Carbon $date
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Booking|null $booking
* @property Customer|null $customer
* @property Lead|null $lead
*
* @package App\Models
*/
class BookingDocument extends Model
{
protected $table = 'booking_documents';
protected $casts = [
'booking_id' => 'int',
'customer_id' => 'int',
'lead_id' => 'int',
'size' => 'int',
'data' => 'object',
'status' => 'int',
'booking_storno_id' => 'int',
'coupon_id' => 'int',
];
protected $dates = [
'date'
];
protected $fillable = [
'booking_id',
'customer_id',
'lead_id',
'coupon_id',
'booking_storno_id', //
'identifier',
'filename',
'dir',
'original_name',
'ext',
'mine',
'size',
'date',
'data',
'status'
];
/* Je nach identifier können verschiebene stati gesetzt werden
coupon 0 = nicht eingelöst 1 = eingelöst
*/
protected $status_type = [
0 => 'offen',
1 => 'erledigt',
];
public function booking()
{
return $this->belongsTo(Booking::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function coupon_id()
{
return $this->belongsTo(Coupon::class);
}
public function booking_storno()
{
return $this->belongsTo(BookingStorno::class);
}
public function getURL($do=false){
return route('storage_file', [$this->id, 'booking_document', $do]);
}
public function getPath(){
return \Storage::disk('public')->path($this->dir.$this->filename);
}
public function deleteFile(){
if(\Storage::disk('public')->exists($this->dir.$this->filename)){
\Storage::disk('public')->delete($this->dir.$this->filename);
}
}
public function formatBytes($precision = 2)
{
$size = $this->size;
if ($size > 0) {
$size = (int) $size;
$base = log($size) / log(1024);
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
} else {
return $size;
}
}
}

View file

@ -115,7 +115,7 @@ class BookingDraftItem extends Model
return $this->belongsTo('App\Models\DraftType', 'draft_type_id');
}
public function getItemPrice(){
public function getItemPrice($return = false){
$adult = 0;
$children = 0;
@ -138,9 +138,20 @@ class BookingDraftItem extends Model
$price = $this->price;
}
*/
return ['adult'=>$adult, 'children'=>$children];
}
if($return == 'adult'){
return $adult;
}
if($return == 'children'){
return $children;
}
if($return == 'total'){
return $adult + $children;
}
return ['adult'=>$adult, 'children'=>$children];
}
public function getStartDateAttribute(){
return isset($this->attributes['start_date']) ? Carbon::parse($this->attributes['start_date'])->format("d.m.Y") : '';

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Services\Util;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@ -69,4 +70,72 @@ class BookingStorno extends Model
{
return $this->belongsTo(Booking::class);
}
public function booking_document()
{
return $this->hasOne(BookingDocument::class, 'booking_storno_id', 'id');
}
public function getTotalFormatted()
{
return Util::_number_format($this->attributes['total']);
}
public function getTotalRaw()
{
return $this->attributes['total'];
}
public function setTotalAttribute($value)
{
$this->attributes['total'] = Util::_clean_float($value);
}
public function getStornoFormatted()
{
return Util::_number_format($this->attributes['storno']);
}
public function getStornoRaw()
{
return $this->attributes['storno'];
}
public function setStornoAttribute($value)
{
$this->attributes['storno'] = Util::_clean_float($value);
}
public function getStornoDateFormatted()
{
return isset($this->attributes['storno_date']) ? Carbon::parse($this->attributes['storno_date'])->format('d.m.Y') : '';
}
public function setStornoDateAttribute($value)
{
if (!$value) {
$this->attributes['storno_date'] = null;
} else {
$this->attributes['storno_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
public function getStornoPrintFormatted()
{
return isset($this->attributes['storno_print']) ? Carbon::parse($this->attributes['storno_print'])->format('d.m.Y') : '';
}
public function setStornoPrintAttribute($value)
{
if (!$value) {
$this->attributes['storno_print'] = null;
} else {
$this->attributes['storno_print'] = Carbon::parse($value)->format('Y-m-d');
}
}
}

View file

@ -2,7 +2,7 @@
namespace App\Models;
use App\Services\HTMLHelper;
use App\Helper\HTMLHelper;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

View file

@ -7,8 +7,9 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Class Coupon
@ -78,6 +79,32 @@ class Coupon extends Model
'text'
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::created(function ($model) {
$model->number = sprintf(
'%02u-%05u-%05u-%02u%02u',
date('y'),
$model->customer_id,
$model->id,
date('H'),
date('i')
);
$model->save();
});
}
public function create($product)
{
logger($product->id);
}
public function booking()
{
return $this->belongsTo(Booking::class);
@ -88,6 +115,12 @@ class Coupon extends Model
return $this->belongsTo(Customer::class);
}
public function booking_document()
{
return $this->hasOne(BookingDocument::class, 'coupon_id', 'id');
}
public function bookings()
{
return $this->hasMany(Booking::class);
@ -95,6 +128,67 @@ class Coupon extends Model
public function isLegal(){
//TODO
// return strtotime(date('Y-m-d')) <= strtotime($this->getValidDate());
return false;
}
public function getValueFormatted()
{
return Util::_number_format($this->attributes['value']);
}
public function getValueRaw()
{
return $this->attributes['value'];
}
public function setValueAttribute($value)
{
$this->attributes['value'] = Util::_clean_float($value);
}
public function getIssueDateFormatted()
{
return isset($this->attributes['issue_date']) ? Carbon::parse($this->attributes['issue_date'])->format('d.m.Y') : '';
}
public function setIssueDateAttribute($value)
{
if (!$value) {
$this->attributes['issue_date'] = null;
} else {
$this->attributes['issue_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
public function getValidDateFormatted()
{
return isset($this->attributes['valid_date']) ? Carbon::parse($this->attributes['valid_date'])->format('d.m.Y') : '';
}
public function setValidDateAttribute($value)
{
if (!$value) {
$this->attributes['valid_date'] = null;
} else {
$this->attributes['valid_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
public function getRedeemDateFormatted()
{
return isset($this->attributes['redeem_date']) ? Carbon::parse($this->attributes['redeem_date'])->format('d.m.Y') : '';
}
public function setRedeemDateAttribute($value)
{
if (!$value) {
$this->attributes['redeem_date'] = null;
} else {
$this->attributes['redeem_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
}

View file

@ -110,6 +110,12 @@ class Feedback extends Page
{
protected $table = 'page';
protected $fillable = [
'title', 'status', 'slug', 'date', 'content', 'content_new', 'box_body', 'description', 'pagetitle', 'keywords', 'order', 'active',
];
protected $casts = ['box_body' => 'array', 'date' => 'date', 'status' => 'boolean', 'active' => 'boolean'];
public static function boot()
{
parent::boot();
@ -150,6 +156,24 @@ class Feedback extends Page
}
}
public function getContentAttribute()
{
return $this->attributes['content_new'] === null ? $this->attributes['content'] : $this->attributes['content_new'];
}
public function setContentNewAttribute($value)
{
if (!$value) {
$this->attributes['content_new'] = $value;
} else {
$this->attributes['content_new'] = HTMLHelper::filterHTML($value, ['src' => ['removeHost']], true);
}
}
public function getContentNewAttribute()
{
return $this->attributes['content_new'] === null ? $this->attributes['content'] : $this->attributes['content_new'];
}
public function getParentsArray(){
@ -173,8 +197,19 @@ class Feedback extends Page
if (!$value) {
$this->attributes['date'] = null;
} else {
$this->attributes['date'] = (new Carbon($value))->format('Y-m-d');
try {
$this->attributes['date']= Carbon::parse($value);
} catch (\Exception $e) {
$this->attributes['date'] = Carbon::now();
}
}
}
public function getImage($key){
//use box_body for images
if(isset($this->box_body[$key])){
return $this->box_body[$key];
}
return "";
}
}

View file

@ -342,6 +342,25 @@ class Lead extends Model
return '<span data-order="0">-</span>';
}
public function getTravelCountryDestco($badge = true){
$out = "";
if($this->bookings->count()){
$out .= $badge ? '<span class="badge badge-success">' : '';
foreach ($this->bookings as $booking){
if($booking->travel_country_id && $booking->travel_country) {
$out .= $booking->travel_country->destco;
}
}
$out .= $badge ? '</span>' : '';
return $out;
}
if($this->travel_country){
return $badge ? '<span class="badge badge-secondary">'.$this->travel_country->destco.'</span>' : $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();

View file

@ -260,6 +260,11 @@ class TravelProgram extends Model
return $this->hasOne(Option::class, 'program_id');
}
public function page()
{
return $this->hasOne(Page::class, 'travel_program');
}
public function classes()
{
return $this->hasMany(TravelClass::class, 'program_id');

View file

@ -149,6 +149,7 @@ class TravelUserBookingFewo extends Model
'price_total' => 'float',
'travel_booking_fewo_channel_id' => 'int',
'is_calendar_fewo_direct' => 'bool',
'is_calendar_traum_fewo' => 'bool',
'is_calendar_hrs' => 'bool',
'is_calendar_stern_tours' => 'bool',
'status' => 'int',
@ -187,6 +188,7 @@ class TravelUserBookingFewo extends Model
'travel_booking_fewo_channel_id',
'notice',
'is_calendar_fewo_direct',
'is_calendar_traum_fewo',
'is_calendar_hrs',
'is_calendar_stern_tours',
'status',
@ -268,6 +270,7 @@ class TravelUserBookingFewo extends Model
public function getCheckedBadgeCalendar(){
$back = "";
$back .= $this->is_calendar_fewo_direct ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
$back .= $this->is_calendar_traum_fewo ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
$back .= $this->is_calendar_hrs ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
$back .= $this->is_calendar_stern_tours ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
return $back;
@ -544,6 +547,14 @@ class TravelUserBookingFewo extends Model
return $path.$dir;
}
public function getInvoiceDir(){
$dir = $this->getBookingDateYear()."/";
if(!Storage::disk('fewo_invoices')->exists( $dir )){
Storage::disk('fewo_invoices')->makeDirectory($dir); //creates directory
}
return $dir;
}
public function isInvoice(){
if($this->invoice_number){
$dir = $this->getBookingDateYear()."/";
@ -612,6 +623,14 @@ class TravelUserBookingFewo extends Model
return $path.$dir;
}
public function getTravelInfoDir(){
$dir = $this->getBookingDateYear()."/";
if(!Storage::disk('fewo_infos')->exists( $dir )){
Storage::disk('fewo_infos')->makeDirectory($dir); //creates directory
}
return $dir;
}
public function isTravelInfo(){
if($this->invoice_number){
$dir = $this->getBookingDateYear()."/";