mein-sterntours/app/Models/TravelUserBookingFewo.php
Kevin Adametz 881fc84207 08 2024
2024-08-05 11:58:09 +02:00

779 lines
30 KiB
PHP

<?php
/**
* Created by Reliese Model.
* Date: Thu, 21 Mar 2019 13:40:13 +0100.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Storage;
use App\Services\Util;
/**
* Class TravelUserBookingFewo
*
* @property int $id
* @property int $travel_user_id
* @property int $fewo_lodging_id
* @property string $invoice_number
* @property int $persons
* @property int $adults
* @property int $children
* @property \Carbon\Carbon $booking_date
* @property \Carbon\Carbon $from_date
* @property \Carbon\Carbon $to_date
* @property string $daily_prices
* @property float $price_travel
* @property float $price_deposit
* @property float $price_service
* @property float $price_total
* @property int $travel_booking_fewo_channel_id
* @property string $notice
* @property bool $is_calendar_fewo_direct
* @property bool $is_calendar_hrs
* @property bool $is_calendar_stern_tours
* @property int $status
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $deleted_at
* @property \App\Models\FewoLodging $fewo_lodging
* @property \App\Models\TravelBookingFewoChannel $travel_booking_fewo_channel
* @property \App\Models\TravelUser $travel_user
* @package App\Models
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Query\Builder|\App\Models\TravelUserBookingFewo onlyTrashed()
* @method static bool|null restore()
* @method static \Illuminate\Database\Query\Builder|\App\Models\TravelUserBookingFewo withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\TravelUserBookingFewo withoutTrashed()
* @mixin \Eloquent
* @property int|null $fewo_reservation_id
* @property float|null $price_balance
* @property float|null $price_extra
* @property float|null $price_travel_total
* @property string|null $status_text
* @property array|null $send_user_mail
* @property array|null $send_service_mail
* @property array|null $send_info_mail
* @property array|null $send_employee_mail
* @property string|null $info_mail_text
* @property-read \App\Models\FewoReservation|null $fewo_reservation
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereAdults($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereBookingDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereChildren($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereDailyPrices($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereFewoLodgingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereFewoReservationId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereFromDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereInfoMailText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereInvoiceNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereIsCalendarFewoDirect($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereIsCalendarHrs($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereIsCalendarSternTours($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereNotice($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePersons($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceBalance($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceDeposit($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceExtra($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceService($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceTravel($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo wherePriceTravelTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereSendEmployeeMail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereSendInfoMail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereSendServiceMail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereSendUserMail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereStatusText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereToDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereTravelBookingFewoChannelId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereTravelUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereUpdatedAt($value)
* @property string|null $last_change_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFewo whereLastChangeAt($value)
* @property-read \App\Models\CustomerFewoMail|null $customer_fewo_mail_last
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CustomerFewoMail[] $customer_fewo_mails
* @property-read int|null $customer_fewo_mails_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CustomerFewoMail[] $customer_fewo_mails_sent_at
* @property-read int|null $customer_fewo_mails_sent_at_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelUserBookingFile[] $booking_files
* @property-read int|null $booking_files_count
* @property-read \App\Models\TravelUser $customer
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelUserBookingFewoNotice[] $booking_fewo_notices
* @property-read int|null $booking_fewo_notices_count
*/
class TravelUserBookingFewo extends Model
{
use \Illuminate\Database\Eloquent\SoftDeletes;
protected static $statues = [
0 => 'Anfrage von STERN TOURS',
1 => 'Angebot versandt',
2 => 'Rückfrage Agentur',
3 => 'Rückfrage Kunden',
5 => 'Nachfrage Angebot',
7 => 'gebucht',
8 => 'Absage',
9 => 'Option',
10 => 'Angebot erstellen',
11 => 'Storno durch VA',
12 => 'Storno durch Kunde',
13 => 'Reiseanmeldung verschickt',
];
protected $connection = 'mysql_stern';
protected $table = 'travel_user_booking_fewos';
protected $casts = [
'travel_user_id' => 'int',
'fewo_lodging_id' => 'int',
'fewo_reservation_id' => 'int',
'persons' => 'int',
'adults' => 'int',
'children' => 'int',
'daily_prices' => 'array', //!
'price_travel' => 'float',
'price_deposit' => 'float',
'price_service' => 'float',
'price_balance' => 'float',
'price_extra' => 'float',
'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',
'send_user_mail' => 'array',
'send_service_mail' => 'array',
'send_info_mail' => 'array',
'send_employee_mail' => 'array',
];
protected $dates = [
'booking_date',
'from_date',
'to_date',
'deleted_at'
];
protected $fillable = [
'travel_user_id',
'fewo_lodging_id',
'fewo_reservation_id',
'invoice_number',
'adults',
'children',
'persons',
'booking_date',
'from_date',
'to_date',
'daily_prices',
'price_travel',
'price_balance',
'price_extra',
'price_travel_total',
'price_deposit',
'price_service',
'price_total',
'travel_booking_fewo_channel_id',
'notice',
'is_calendar_fewo_direct',
'is_calendar_traum_fewo',
'is_calendar_hrs',
'is_calendar_stern_tours',
'status',
'status_text'
];
protected static function boot() {
parent::boot();
static::deleting(function($model) {
foreach ($model->customer_fewo_mails as $relation)
{
$relation->delete();
}
});
}
public static $customer_mail_dirs = [
11 => ['name' => 'Entwürfe', 'icon'=>'ion-md-create'],
12 => ['name' => 'Papierkorb', 'icon'=>'ion-md-trash'],
];
public function fewo_lodging()
{
return $this->belongsTo(\App\Models\FewoLodging::class);
}
public function fewo_reservation()
{
return $this->belongsTo(\App\Models\FewoReservation::class, 'fewo_reservation_id');
}
public function travel_booking_fewo_channel()
{
return $this->belongsTo(\App\Models\TravelBookingFewoChannel::class);
}
public function travel_user()
{
return $this->belongsTo(\App\Models\TravelUser::class);
}
public function customer()
{
return $this->belongsTo(\App\Models\TravelUser::class, 'travel_user_id');
}
public function booking_files()
{
return $this->hasMany(TravelUserBookingFile::class, 'travel_user_booking_fewo_id');
}
public function customer_fewo_mails()
{
return $this->hasMany(CustomerFewoMail::class, 'travel_user_booking_fewo_id', 'id');
}
public function customer_fewo_mails_sent_at()
{
return $this->hasMany(CustomerFewoMail::class, 'travel_user_booking_fewo_id')->orderBy('sent_at', 'ASC');
}
public function customer_fewo_mail_last()
{
return $this->hasOne(CustomerFewoMail::class, 'travel_user_booking_fewo_id')->latest();
}
public function booking_fewo_notices()
{
return $this->hasMany(TravelUserBookingFewoNotice::class, 'travel_user_booking_fewo_id')->orderBy('updated_at', 'DESC');
}
public function getStatuesName(){
if(isset(self::$statues[$this->status])){
return self::$statues[$this->status];
}
return "";
}
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;
}
public function getPersonsAttribute()
{
$this->attributes['persons'] = $this->adults + $this->children;
return $this->attributes['persons'];
}
public function setPersonsAttribute($value) {
$this->attributes['persons'] = $this->adults + $this->children;
}
public function getAdultsAttribute()
{
return isset($this->attributes['adults']) ? $this->attributes['adults'] : 0;
}
public function setAdultsAttribute( $value ) {
$this->attributes['persons'] = $this->adults + $this->children;
$this->attributes['adults'] = $value;
}
public function getChildrenAttribute()
{
return isset($this->attributes['children']) ? $this->attributes['children'] : 0;
}
public function setChildrenAttribute( $value ) {
$this->attributes['persons'] = $this->adults + $this->children;
$this->attributes['children'] = $value;
}
public static function getStatuesOptions($setKey = false){
$options = self::$statues;
$ret = '';
foreach ($options as $key => $option){
$attr = ($key == $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public function getBookingDateAttribute()
{
return isset($this->attributes['booking_date']) ? Carbon::parse($this->attributes['booking_date'])->format(Util::formatDateDB()) : NULL;
}
public function setBookingDateAttribute( $value ) {
$this->attributes['booking_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
//from_date
public function getFromDateAttribute()
{
return isset($this->attributes['from_date']) ? Carbon::parse($this->attributes['from_date'])->format(Util::formatDateDB()) : NULL;
}
public function setFromDateAttribute( $value ) {
$this->attributes['from_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getFromDateRaw()
{
return isset($this->attributes['from_date']) ? $this->attributes['from_date'] : "";
}
//to_date
public function getToDateAttribute()
{
return isset($this->attributes['to_date']) ? Carbon::parse($this->attributes['to_date'])->format(Util::formatDateDB()) : NULL;
}
public function setToDateAttribute( $value ) {
$this->attributes['to_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getToDateRaw()
{
return isset($this->attributes['to_date']) ? $this->attributes['to_date'] : "";
}
//price_travel
public function setPriceTravelAttribute($value)
{
$this->attributes['price_travel'] = Util::_clean_float($value);
}
public function getPriceTravelAttribute($value)
{
return isset($this->attributes['price_travel']) ? number_format(($this->attributes['price_travel']), 2, ',', '.') : 0;
}
public function getPriceTravelRaw()
{
return isset($this->attributes['price_travel']) ? $this->attributes['price_travel'] : 0;
}
//price_extra
public function setPriceExtraAttribute($value)
{
$this->attributes['price_extra'] = Util::_clean_float($value);
}
public function getPriceExtraAttribute($value)
{
if(!$value){ return 0; }
return number_format(($this->attributes['price_extra']), 2, ',', '.');
}
public function getPriceExtraRaw()
{
return isset($this->attributes['price_extra']) ? $this->attributes['price_extra'] : 0;
}
//price_balance
public function setPriceBalanceAttribute($value)
{
$this->attributes['price_balance'] = Util::_clean_float($value);
}
public function getPriceBalanceAttribute($value)
{
return isset($this->attributes['price_balance']) ? number_format(($this->attributes['price_balance']), 2, ',', '.') : 0;
}
public function getPriceBalanceRaw()
{
return isset($this->attributes['price_balance']) ? $this->attributes['price_balance'] : 0;
}
//price_travel_total
public function setPriceTravelTotalAttribute($value)
{
$this->attributes['price_travel_total'] = Util::_clean_float($value);
}
public function getPriceTravelTotalAttribute($value)
{
if(!isset($this->attributes['price_travel_total']) || $this->attributes['price_travel_total'] == 0){
$this->attributes['price_travel_total'] = $this->getPriceTravelRaw() + $this->getPriceBalanceRaw() + $this->getPriceExtraRaw();
}
return isset($this->attributes['price_travel_total']) ? number_format(($this->attributes['price_travel_total']), 2, ',', '.') : 0;
}
public function getPriceTravelTotalRaw()
{
if(!isset($this->attributes['price_travel_total']) || $this->attributes['price_travel_total'] == 0){
$this->attributes['price_travel_total'] = $this->getPriceTravelRaw() + $this->getPriceBalanceRaw() + $this->getPriceExtraRaw();
}
return isset($this->attributes['price_travel_total']) ? $this->attributes['price_travel_total'] : 0;
}
//price_deposit
public function setPriceDepositAttribute($value)
{
$this->attributes['price_deposit'] = Util::_clean_float($value);
}
public function getPriceDepositAttribute($value)
{
return isset($this->attributes['price_deposit']) ? number_format(($this->attributes['price_deposit']), 2, ',', '.') : 0;
}
public function getPriceDepositRaw()
{
return isset($this->attributes['price_deposit']) ? $this->attributes['price_deposit'] : 0;
}
//price_service
public function setPriceServiceAttribute($value)
{
$this->attributes['price_service'] = Util::_clean_float($value);
}
public function getPriceServiceAttribute($value)
{
return isset($this->attributes['price_service']) ? number_format(($this->attributes['price_service']), 2, ',', '.') : 0;
}
public function getPriceServiceRaw()
{
return isset($this->attributes['price_service']) ? $this->attributes['price_service'] : 0;
}
//price_total
public function setPriceTotalAttribute($value)
{
$this->attributes['price_total'] = Util::_clean_float($value);
}
public function getPriceTotalAttribute($value)
{
return isset($this->attributes['price_total']) ? number_format(($this->attributes['price_total']), 2, ',', '.') : 0;
}
public function getPriceTotalRaw()
{
return isset($this->attributes['price_total']) ? $this->attributes['price_total'] : 0;
}
public function calculate_price(){
$this->attributes['price_travel_total'] = $this->getPriceTravelRaw() + $this->getPriceBalanceRaw() + $this->getPriceExtraRaw();
$this->attributes['price_total'] = $this->getPriceTravelTotalRaw() + $this->getPriceServiceRaw() + $this->getPriceDepositRaw();
}
public function getPriceTravelTotalFirstPay(){
if($this->attributes['price_travel'] == 0){
return 0;
}
$first_pay = ($this->getPriceTravelTotalRaw() + $this->getPriceServiceRaw()) / 2;
return number_format(($first_pay), 2, ',', '.');
}
public function getPriceTravelTotalSecondPay(){
if($this->attributes['price_travel'] == 0){
return 0;
}
$total_pay = ($this->getPriceTravelTotalRaw() + $this->getPriceServiceRaw());
$first_pay = $total_pay/2;
return number_format(($total_pay - $first_pay + $this->getPriceDepositRaw()), 2, ',', '.');
}
public function getPriceTravelTotalPay(){
if($this->attributes['price_travel'] == 0){
return 0;
}
$total_pay = ($this->getPriceTravelTotalRaw() + $this->getPriceServiceRaw());
return number_format(($total_pay + $this->getPriceDepositRaw()), 2, ',', '.');
}
public function getDepartureInDays()
{
if(isset($this->attributes['from_date'])){
return Carbon::now()->diffInDays(Carbon::parse($this->attributes['from_date']), false);
}
return 0;
}
public function isFromDateAfterDays($days = 30){
if(($this->getDepartureInDays() - $days) > 0){
return true;
}
return false;
}
public function getLastChangeAt(){
if(!isset($this->attributes['last_change_at']) || !$this->attributes['last_change_at']){ return ""; }
return Carbon::parse($this->attributes['last_change_at'])->format("H:i d.m.Y");
}
public function getBookingDateYear(){
return Carbon::parse($this->booking_date)->format('Y');
}
//get Invoice Name / Paths / ...
public function getInvoiceFileName(){
if($this->invoice_number) {
return Util::sanitize($this->invoice_number).".pdf";
}
return false;
}
public function getInvoicePath(){
$dir = $this->getBookingDateYear()."/";
if(!Storage::disk('fewo_invoices')->exists( $dir )){
Storage::disk('fewo_invoices')->makeDirectory($dir); //creates directory
}
$path = Storage::disk('fewo_invoices')->getAdapter()->getPathPrefix();
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()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return true;
}
}
return false;
}
public function getInvoicePathFile(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Storage::disk('fewo_invoices')->path($dir.$filename);
}
return false;
}
public function getInvoiceUrlFile(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Storage::disk('fewo_invoices')->url($dir.$filename);
}
return false;
}
public function getInvoiceLastModified(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_invoices')->lastModified($dir.$filename))->format("H:i d.m.Y");
}
return false;
}
public function isChangeLowerInvoiceCreate(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_invoices')->lastModified($dir.$filename))->gt($this->last_change_at);
}
return false;
}
//get TravelInfos Name / Paths / ...
public function getTravelInfoFileName(){
if($this->invoice_number) {
return "Anreiseinfo-".Util::sanitize($this->invoice_number).".pdf";
}
return false;
}
public function getTravelInfoPath(){
$dir = $this->getBookingDateYear()."/";
if(!Storage::disk('fewo_infos')->exists( $dir )){
Storage::disk('fewo_infos')->makeDirectory($dir); //creates directory
}
$path = Storage::disk('fewo_infos')->getAdapter()->getPathPrefix();
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()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
return true;
}
}
return false;
}
public function getTravelInfoPathFile(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
return Storage::disk('fewo_infos')->path($dir.$filename);
}
return false;
}
public function getTravelInfoUrlFile(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
return Storage::disk('fewo_infos')->url($dir.$filename);
}
return false;
}
public function getTravelInfoLastModified(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_infos')->lastModified($dir.$filename))->format("H:i d.m.Y");
}
return false;
}
public function isChangeLowerTravelInfoCreate(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_infos')->lastModified($dir.$filename))->gt($this->last_change_at);
}
return false;
}
//get strings
public function getBookingUserAddress(){
if($this->travel_user){
$company = $this->travel_user->company ? $this->travel_user->company ."\n" : "";
$title = $this->travel_user->title ? $this->travel_user->title."\n" : "";
$nationality = $this->travel_user->travel_nationality_id ? "\n".$this->travel_user->travel_nationality->name : "";
return $company.$title.$this->travel_user->first_name." ".$this->travel_user->last_name."\n".$this->travel_user->street."\n".$this->travel_user->zipcode." ".$this->travel_user->city.$nationality;
}
return "";
}
public function getNameAddressLocation($sep = "\n"){
if($this->fewo_lodging){
$name = trim($this->fewo_lodging->single_name).$sep;
$address = trim($this->fewo_lodging->adress1);
$address .= $this->fewo_lodging->adress2 ? " ".$this->fewo_lodging->adress2.$sep : ", ";
$city = trim($this->fewo_lodging->zipcode)." ".trim($this->fewo_lodging->city);
return $name.$address.$city;
}
return "";
}
public function getUserSalutation(){
$salutation = __('Dear customer');
if($this->travel_user){
if($this->travel_user->salutation_id == 1){
$salutation = __('Dear Sir')." ".$this->travel_user->last_name;
}
if($this->travel_user->salutation_id == 2){
$salutation = __('Dear Mrs')." ".$this->travel_user->last_name;
}
if($this->travel_user->salutation_id == 4){
$salutation = __('Dear customer')." ".$this->travel_user->last_name;
}
}
return $salutation;
}
public function getServiceMailSubject(){
if($this->fewo_lodging){
return "Neue Anmietung ".$this->fewo_lodging->name." mit Anreise ".$this->from_date;
}
return "Neue Anmietung Anreise ".$this->from_date;
}
public function getServiceMailContent(){
return $this->adults." + ".$this->children." (Erwachsene + Kinder)\n".
$this->from_date." - ".$this->to_date." ".$this->travel_user->first_name." ".$this->travel_user->last_name;
}
public function getEmployeeMailSubject(){
if($this->fewo_lodging){
return "CRM Fewo Buchung: ".$this->fewo_lodging->name." | Anreise ".$this->from_date;
}
return "CRM Fewo Buchung | Anreise ".$this->from_date;
}
public function getEmployeeMailContent(){
return ($this->travel_user_id ? "Kunde: ".route('travel_user_detail', [$this->travel_user_id])."\n" : "").
"Buchung: ".route('travel_user_booking_fewo_detail', [$this->id])."\n".
$this->travel_user->first_name." ".$this->travel_user->last_name." | ".$this->from_date." - ".$this->to_date." | ".$this->adults." + ".$this->children." (Erwachsene + Kinder)";
}
public function isSendUserMail(){
if($this->send_user_mail != NULL){
return true;
}
return false;
}
public function isSendInfoMail(){
if($this->send_info_mail != NULL){
return true;
}
return false;
}
public function isSendServiceMail(){
if($this->send_service_mail != NULL){
return true;
}
return false;
}
public function countCustomerMailsBy($dir, $subdir=false){
if($dir === 11){
return $this->customer_fewo_mails->where('draft', true)->where('dir', '!=', 12)->count();
}
if($subdir){
return $this->customer_fewo_mails->where('dir', $dir)->where('subdir', $subdir)->count();
}
return $this->customer_fewo_mails->where('dir', $dir)->count();
}
}