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

View file

@ -0,0 +1,314 @@
<?php
namespace App\Repositories;
use stdClass;
use App\Models\Coupon;
use App\Models\Booking;
use App\Libraries\CreatePDF;
use App\Models\BookingStorno;
use App\Libraries\MyPDFMerger;
use App\Models\BookingDocument;
use App\Libraries\CreatePDFCoupon;
use Carbon;
use Illuminate\Support\Facades\Storage;
class BookingPDFRepository extends BaseRepository {
protected $prepath;
public function __construct(Booking $model)
{
$this->model = $model;
$this->prepath = Storage::disk('public')->getAdapter()->getPathPrefix();
}
public function update($data)
{
return $this->model;
}
public function createPDF($id, $data){
$this->model = Booking::findOrFail($id);
switch ($data['action']) {
case 'createPDF_Registration':
return $this->createPDF_Registration();
break;
case 'createPDF_Confirmation':
return $this->createPDF_Confirmation();
break;
case 'createPDF_Coupon':
return $this->createPDF_Coupon($data);
break;
case 'createPDF_Voucher':
$this->createPDF_Voucher(false); //client
return $this->createPDF_Voucher(true); //acency
break;
case 'createPDF_VoucherAgency':
return $this->createPDF_Voucher(true);
break;
case 'createPDF_Storno':
return $this->createPDF_Storno($data);
break;
}
}
public function createPDF_Registration(){
$document = new stdClass();
$document->name = 'registration';
$document->number = $this->model->lead_id;
$document->title = 'BUCHUNGSAUFTRAG';
$document->voucher = null;
$document->date = now();
$document->total = $this->model->getPriceRaw();
$dir = $this->getDirPath('pdf', 'booking', $document->date->format('Y'));
$filename = "Buchnungsauftrag-".$this->model->lead_id.".pdf";
$pdf_file = new CreatePDF('pdf.booking_registration');
$data = [
'booking' => $this->model,
'document' => $document,
];
$pdf_file->create($data, $filename, 'save', $this->prepath.$dir);
$booking_document = $this->savePDF($dir, $filename, 'sterntours-template', 'registration', $document);
return $booking_document;
}
public function createPDF_Confirmation(){
$document = new stdClass();
$document->name = 'confirmation';
$document->number = $this->model->lead_id;
$document->title = 'REISEBESTÄTIGUNG';
$document->voucher = null;
$document->date = now();
$document->total = $this->model->getPriceRaw();
$document->deposit = $this->model->getConfirmationDeposit();
$document->final_payment = $this->model->getConfirmationFinalPayment();
if ($this->model->isDepositPossible())
{
$document->deposit_payment_date = date('Y-m-d');
$maxDepositIntervalDays = config('booking.max_deposit_interval_days');
$_start_date = clone $this->model->start_date;
$_start_date->modify('-'.$maxDepositIntervalDays.' days');
$document->final_payment_date = $_start_date->format('Y-m-d');
}
else {
$document->final_payment_date = date('Y-m-d');
}
$dir = $this->getDirPath('pdf', 'booking', $document->date->format('Y'));
$filename = "Reisebestätigung-".$this->model->lead_id.".pdf";
$pdf_file = new CreatePDF('pdf.booking_confirmation');
$data = [
'booking' => $this->model,
'document' => $document,
];
$pdf_file->create($data, $filename, 'save', $this->prepath.$dir);
$booking_document = $this->savePDF($dir, $filename, 'sterntours-template', 'confirmation', $document);
return $booking_document;
}
public function createPDF_Coupon($data){
$document = new stdClass();
$document->name = 'coupon';
$document->title = 'COUPON';
$document->voucher = null;
$document->date = now();
$coupon = new Coupon();
$coupon->booking_id = $this->model->id;
$coupon->customer_id = $this->model->customer->id;
$coupon->value = $data['value'];
$coupon->issue_date = $data['issue_date'];
$coupon->valid_date = $data['valid_date'];
$coupon->is_redeemed = false;
$coupon->save();
$document->number = $coupon->number;
$document->value = $coupon->value;
$document->issue_date = $coupon->issue_date;
$document->valid_date = $coupon->valid_date;
$document->coupon_id = $coupon->id;
$dir = $this->getDirPath('pdf', 'coupon', $document->date->format('Y'));
$filename = "Gutschein-".$coupon->number.".pdf";
$pdf_file = new CreatePDFCoupon('pdf.booking_coupon');
$data = [
'booking' => $this->model,
'document' => $document,
'coupon' => $coupon,
];
$pdf_file->create($data, $filename, 'save', $this->prepath.$dir);
$booking_document = $this->savePDF($dir, $filename, 'sterntours-coupon', 'coupon', $document);
return $booking_document;
}
public function createPDF_Voucher($agency = false){
$document = new stdClass();
$document->name = 'voucher';
$document->number = $this->model->lead_id;
$document->name = 'voucher';
$document->title = $agency ? 'VOUCHER Agentur': 'VOUCHER';
$document->voucher = $agency ? 'agency': 'client';
$document->date = now();
$dir = $this->getDirPath('pdf', 'voucher', $document->date->format('Y'));
$filename = ($agency ? 'VoucherAgentur': 'Voucher')."-".$this->model->lead_id.".pdf";
$pdf_file = new CreatePDF('pdf.booking_voucher');
$data = [
'booking' => $this->model,
'document' => $document,
];
$pdf_file->create($data, $filename, 'save', $this->prepath.$dir);
$identifier = $agency ? 'voucher_agency': 'voucher';
$booking_document = $this->savePDF($dir, $filename, 'sterntours-template', $identifier, $document);
return $booking_document;
}
public function createPDF_Storno($data){
//Storno Values
$storno_status_id = (int) $data['storno_status_id'];
$storno_level = (float) $data['storno_level'];
$storno_level_number = \Util::_clean_float($data['storno_level_number']);
$storno_total_price = \Util::_clean_float($data['storno_total_price']);
$price = $this->model->getPriceRaw();
if($storno_level_number > 0 && $storno_level_number < 100 ){
$storno_level = $storno_level_number;
}
//calculate price canceled
if($storno_total_price > 0){
$price_canceled = $storno_total_price;
$storno_level = ((100 / $price) * $storno_total_price);
}else{
$price_canceled = round($price / 100 * $storno_level, 2);
}
//init identifier
$identifier = 'storno';
//create / update BookingStorno
$fill = [
'booking_id' => $this->model->id,
'total' => $price,
'storno' => $price_canceled,
'storno_date' => $data['storno_date'],
'storno_print' => $data['storno_print']
];
if($this->model->hasDocument($identifier)){
$booking_document = $this->model->getDocument($identifier);
$booking_storno = $booking_document->booking_storno;
$booking_storno->update($fill);
}else{
$booking_storno = BookingStorno::create($fill);
}
//init document
$document = new stdClass();
$document->name = $identifier;
$document->number = $this->model->lead_id;
$document->title = 'STORNOBESTÄTIGUNG';
$document->voucher = null;
$document->date = Carbon::parse($data['storno_print']);
$document->total = $price;
$document->storno = $price_canceled;
$document->storno_date = $data['storno_date'];
$document->storno_print = $data['storno_print'];
$document->storno_status_id = $storno_status_id;
$document->booking_storno_id = $booking_storno->id;
$document->storno_level = $storno_level;
//update Booking // Lead Status
if($storno_status_id){
$this->model->lead->status_id = $storno_status_id;
$this->model->lead->save();
}
$this->model->canceled = $storno_level;
$this->model->price_canceled = $price_canceled; //must pay
$this->model->price_total = $price_canceled; //is the same as Canceled( ...
$this->model->price_balance = round($price - $price_canceled, 2); //is the Rest - must not pay
$this->model->save();
$dir = $this->getDirPath('pdf', 'storno', $document->date->format('Y'));
$filename = "Reisestornierung -".$this->model->lead_id.".pdf";
$pdf_file = new CreatePDF('pdf.booking_storno');
$data = [
'booking' => $this->model,
'document' => $document,
];
$pdf_file->create($data, $filename, 'save', $this->prepath.$dir);
$this->savePDF($dir, $filename, 'sterntours-template', $identifier, $document);
}
//get Invoice Name / Paths / ...
private function getDirPath($file, $dir, $year){
$path = $file.'/'.$dir.'/'.$year.'/';
if(!Storage::disk('public')->exists( $path )){
Storage::disk('public')->makeDirectory($path); //creates directory
}
return $path;
}
private function savePDF($dir, $filename, $template, $identifier, $document = null, $status = 0){
$pdfMerger = new MyPDFMerger();
$pdfMerger->addPDF($this->prepath.$dir.$filename);
$file = $pdfMerger->myMerge('string', $filename, $template);
Storage::disk('public')->put($dir.$filename, $file);
$fill = [
'booking_id' => $this->model->id,
'customer_id' => $this->model->customer_id,
'lead_id' => $this->model->lead_id,
'identifier' => $identifier,
'filename' => $filename,
'dir' => $dir,
'original_name' => $filename,
'ext' => 'pdf',
'mine' => 'application/pdf',
'size' => Storage::disk('public')->size($dir.$filename),
'date' => now(),
'data' => $document,
'status' => $status,
'booking_storno_id' => isset($document->booking_storno_id) ? $document->booking_storno_id : null,
'coupon_id' => isset($document->coupon_id) ? $document->coupon_id : null,
];
if($this->model->hasDocument($identifier)){
$booking_document = $this->model->getDocument($identifier);
$booking_document->update($fill);
}else{
$booking_document = BookingDocument::create($fill);
}
return $booking_document;
//return $pdfMerger->myMerge('browser', $filename, $template);
}
}

View file

@ -87,7 +87,8 @@ class BookingRepository extends BaseRepository {
'travel_documents' => $data['travel_documents'],
'paying_out' => $data['paying_out'],
'paying_out_status' => $data['paying_out_status'],
'branch_id' => $data['branch_id'],
'branch_id' => isset($data['branch_id']) ? $data['branch_id'] : 4,
'airport_id' => (isset($data['airport_id']) && $data['airport_id']>0) ? $data['airport_id'] : null,
'travel_company_id' => $data['travel_company_id'],
//'airline_id' => $data['airline_id'],
'airline_ids' => isset($data['airline_ids']) ? $data['airline_ids'] : null,
@ -227,7 +228,10 @@ class BookingRepository extends BaseRepository {
$this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : null;
$this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : null;
$this->model->participant_pass = isset($data['participant_pass']) ? true : false;
//update pax
if($this->model->participants->count() > 0){
$this->model->pax = $this->model->participants->where('participant_storno', false)->count();
}
$this->model->save();
return $this->model;
}

View file

@ -3,8 +3,9 @@
namespace App\Repositories;
use App\Models\Customer;
use App\Models\Lead;
use App\Models\Booking;
use App\Models\Customer;
class CustomerRepository extends BaseRepository {
@ -22,7 +23,7 @@ class CustomerRepository extends BaseRepository {
return $this->model;
}
//by Lead ID
public function updateCustomerFromLead($id, $data){
$lead = Lead::findOrFail($id);
@ -30,5 +31,14 @@ class CustomerRepository extends BaseRepository {
return $this->updateCustomer($lead->customer->id, $data['customer']);
}
}
//by Booking ID
public function updateCustomerFromBooking($id, $data){
$booking = Booking::findOrFail($id);
if(isset($data['customer']) && $booking->customer){
return $this->updateCustomer($booking->customer->id, $data['customer']);
}
}
}

View file

@ -125,6 +125,7 @@ class FileRepository extends BaseRepository {
}
return false;
}
private function makeFilename(){
$originalNameWithoutExt = substr($this->originalName, 0, strlen($this->originalName) - strlen($this->extension) - 1);
$this->filename = Util::sanitize($originalNameWithoutExt, true, false, true);

View file

@ -117,7 +117,9 @@ class LeadRepository extends BaseRepository {
$this->model->participant_firstname = isset($data['participant_firstname']) ? $data['participant_firstname'] : null;
//$this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : null;
$this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : null;
/*if($this->model->lead_participants->count() > 0){
$this->model->pax = $this->model->lead_participants->count();
}*/
$this->model->save();
return $this->model;
}

View file

@ -73,7 +73,7 @@ class TravelProgramRepository extends BaseRepository {
'discount_is_percent_value' => $data['discount_is_percent_value'] ? $data['discount_is_percent_value'] : null,
'travel_arrival_point_id' => $data['travel_arrival_point_id'] ? $data['travel_arrival_point_id'] : null,
'max_age_for_children' => $data['max_age_for_children'] ? $data['max_age_for_children'] : null,
'url' => $data['url'] ? $data['url'] : null,
//'url' => $data['url'] ? $data['url'] : null,
'generalnote' => $data['generalnote'] ? $data['generalnote'] : null,
'payment_conditions' => $data['payment_conditions'] ? $data['payment_conditions'] : null,
];
@ -83,6 +83,24 @@ class TravelProgramRepository extends BaseRepository {
}
public function updatePage($id, $data){
//weekdays
$this->model = TravelProgram::findOrFail($id);
if(!$this->model->page){
return $this->model;
}
$fill = [
'title' => $data['page_title'] ? $data['page_title'] : null,
'pagetitle' => $data['page_pagetitle'] ? $data['page_pagetitle'] : null,
'description' => $data['page_description'] ? $data['page_description'] : null,
'slug' => $data['page_slug'] ? $data['page_slug'] : null,
];
$this->model->page->fill($fill);
$this->model->page->save();
return $this->model;
}
/*
'profit_margin',

View file

@ -4,20 +4,21 @@ namespace App\Repositories;
use App\Models\FewoPrice;
use App\Models\FewoReservation;
use App\Models\FewoSeason;
use App\Models\TravelClass;
use App\Models\TravelProgram;
use App\Models\TravelProgramDraft;
use App\Models\TravelUserBookingFewo;
use App\Models\TravelUserBookingFewoNotice;
use App\Services\Util;
use PDF;
use Carbon\Carbon;
use Request;
use Storage;
use Validator;
use Carbon\Carbon;
use App\Services\Util;
use App\Models\FewoPrice;
use App\Models\FewoSeason;
use App\Models\TravelClass;
use App\Libraries\CreatePDF;
use App\Models\TravelProgram;
use App\Models\FewoReservation;
use App\Models\TravelProgramDraft;
use App\Models\TravelUserBookingFewo;
use App\Models\TravelUserBookingFewoNotice;
class TravelUserBookingFewoRepository extends BaseRepository {
@ -51,7 +52,7 @@ class TravelUserBookingFewoRepository extends BaseRepository {
public function createTravelInfoPDF($id, $travel_info_user_text){
$model = TravelUserBookingFewo::findOrFail($id);
$travel_info_user_text = str_replace("", "&euro;", $travel_info_user_text);
$model->info_mail_text = $travel_info_user_text;
$model->save();
@ -59,15 +60,14 @@ class TravelUserBookingFewoRepository extends BaseRepository {
'model' => $model,
'travel_info_user_text' => $travel_info_user_text,
];
$pdf = PDF::loadView('pdf.travel_info_fewo', $data);
$pdf->setPaper('A4', 'portrait');
$path =$model->getTravelInfoPath();
$dir = $model->getTravelInfoDir();
$filename = $model->getTravelInfoFileName();
$pdf->save($path.$filename);
$pdf_file = new CreatePDF('pdf.travel_info_fewo', 'fewo_infos');
$pdf_file->create($data, $filename, 'save', $path);
$pdf_file->merger($dir, $filename, 'sterntours-template-logo');
return $path.$filename;
//return $pdf->stream('invoice.pdf');
}
public function createInvoicePDF($id){
@ -76,13 +76,14 @@ class TravelUserBookingFewoRepository extends BaseRepository {
$data = [
'model' => $model,
];
$pdf = PDF::loadView('pdf.invoice_fewo', $data);
$pdf->setPaper('A4', 'portrait');
$path =$model->getInvoicePath();
$dir = $model->getInvoiceDir();
$filename = $model->getInvoiceFileName();
$pdf->save($path.$filename);
$pdf_file = new CreatePDF('pdf.invoice_fewo', 'fewo_invoices');
$pdf_file->create($data, $filename, 'save', $path);
$pdf_file->merger($dir, $filename, 'sterntours-template-logo');
return $path.$filename;
//return $pdf->stream('invoice.pdf');
}
public function check($id,$data)
{
@ -210,6 +211,7 @@ class TravelUserBookingFewoRepository extends BaseRepository {
}
$data['is_calendar_fewo_direct'] = isset($data['is_calendar_fewo_direct']) ? true : false;
$data['is_calendar_traum_fewo'] = isset($data['is_calendar_traum_fewo']) ? true : false;
$data['is_calendar_hrs'] = isset($data['is_calendar_hrs']) ? true : false;
$data['is_calendar_stern_tours'] = isset($data['is_calendar_stern_tours']) ? true : false;