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

313 lines
No EOL
14 KiB
PHP

<?php
namespace App\Helper;
use App\Models\Booking;
use App\Models\BookingDocument as BookingDocumentModel;
class BookingDocument
{
private static $files_count = 0;
public static function showButton($identifier, Booking $booking){
switch($identifier){
case 'registration':
return $booking->price > 0 ? true : false;
break;
case 'confirmation':
return $booking->hasDocument('registration') > 0 ? true : false;
break;
case 'storno':
return $booking->hasDocument('confirmation') > 0 ? true : false;
break;
case 'coupon':
return $booking->hasDocument('confirmation') > 0 ? true : false;
case 'voucher':
return $booking->hasDocument('confirmation') > 0 ? true : false;
case 'voucher_agency':
return $booking->hasDocument('confirmation') > 0 ? true : false;
}
return false;
}
/*
functions to make the html table for the booking documents
*/
public static function getFilesCount(){
return self::$files_count++;
}
public static function getBookingDocumentsHTMLTable($identifier, Booking $booking, $look = 'show'){
$ret = "";
$files = self::getBookingDocuments($identifier, $booking->id);
if($files && $files->count() > 0){
$ret .= self::makeHTMLTable($files, $identifier, 'v3', $look);
}
$files = self::getV2BookingDocuments($identifier, $booking);
if($files && $files->count() > 0){
$ret .= self::makeHTMLTable($files, $identifier, 'v2', $look);
}
return $ret;
}
public static function getBookingDocuments($identifier, $booking_id){
switch($identifier){
case 'registration':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'registration')->get();
break;
case 'confirmation':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'confirmation')->get();
break;
case 'storno':
$files = null; //BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'storno')->get();
break;
case 'coupon':
$files = null; //BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'coupon')->get();
break;
case 'voucher':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'voucher')->get();
break;
case 'voucher_agency':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'voucher_agency')->get();
break;
default:
$files = null;
}
return $files;
}
public static function getV2BookingDocuments($identifier, Booking $booking){
switch($identifier){
case 'registration':
$files = $booking->booking_applications;
break;
case 'confirmation':
$files = $booking->booking_confirmations;
break;
case 'storno':
$files = $booking->booking_stornos;
break;
case 'coupon':
$files = $booking->coupons;
break;
case 'voucher':
$files = $booking->booking_vouchers;
break;
case 'voucher_agency':
$files = $booking->booking_voucher_agencys;
break;
default:
$files = null;
}
return $files;
}
private static function makeHTMLTable($files, $identifier, $version, $look){
$ret = "";
foreach($files as $file){
;
if($version === 'v2'){
$file_details = self::getV2FileDetails($file, $identifier, $look);
}
if($version === 'v3'){
$file_details = self::getV3FileDetails($file, $identifier, $look);
}
if(isset($file_details)){
$ret .= "<tr>";
$ret .= "<th scope='row'>".self::getFilesCount()."</th>";
$ret .= "<td>";
$ret .= "<a href='".$file_details->route."' target='_blank' class='badge badge-md badge-".$file_details->color."'>";
$ret .= "<i class='fa fa-file-pdf mr-1 ".(($file_details->opacity) ? 'opacity-50' : '')."'></i> ".$file_details->name;
$ret .= "</a>";
$ret .= "</td>";
$ret .= "<td>".$file_details->cell."</td>";
$ret .= "<td>".$file_details->date."</td>";
$ret .= "<td>";
if($look === 'show'){
$ret .= "<a href='".$file_details->donwload."' class='btn btn-xs btn-default' title='Download' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-download'></i>";
$ret .= "</a>";
}
if($look === 'mail'){
$ret .= "<button data-target='".$file_details->route."' data-name='".$file_details->name.".pdf' class='btn btn-xs btn-primary add-file-to-attachment'";
$ret .= " title='als Anhang hinzufügen' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-cloud-download-alt'></i>";
$ret .= "</button>";
}
$ret .= "</td>";
$ret .= "</tr>";
}
}
return $ret;
}
private static function getV3FileDetails($file, $identifier, $look){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Buchnungsauftrag ".$file->data->number;
$ret->color = "primary";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format((float) $file->data->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung ".$file->data->number;
$ret->color = "success";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->data->total)." &euro; <br>
".self::getCellLabel($look, 'AZ').": ".\App\Services\Util::_number_format($file->data->deposit)." &euro; <br>
".self::getCellLabel($look, 'RZ').": ".\App\Services\Util::_number_format($file->data->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung ".$file->data->number;
$ret->color = "danger";
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "warning";
$ret->cell = self::getCellLabel($look, 'GW').": ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
break;
case 'voucher':
$ret->name = " Voucher ".$file->data->number;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VC');
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ".$file->data->number;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VA');
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
$ret->route = $file->getURL('file');
$ret->donwload = $file->getURL('download');
$ret->opacity = false;
return $ret;
}
private static function getV2FileDetails($file, $identifier, $look){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung";
$ret->color = "success";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->total)." &euro; <br>
".self::getCellLabel($look, 'AZ').": ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
".self::getCellLabel($look, 'RZ').": ".\App\Services\Util::_number_format($file->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung";
$ret->color = "danger";
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
if($file->booking_document){
$ret->name .= " ".$file->booking_document->data->number;
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->storno)." &euro;";
$ret->route = $file->booking_document->getURL('file');
$ret->donwload = $file->booking_document->getURL('download');
$ret->opacity = false;
return $ret;
}
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "warning";
$ret->cell = self::getCellLabel($look, 'GW').": ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
if($file->booking_document){
$ret->route = $file->booking_document->getURL('file');
$ret->donwload = $file->booking_document->getURL('download');
$ret->opacity = false;
return $ret;
}
break;
case 'voucher':
$ret->name = " Voucher ID ".$file->id;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VC');
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ID ".$file->id;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VA');
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
$ret->route = route('customer_file_show', [$identifier, $file->id]);
$ret->donwload = route('customer_file_show', [$identifier, $file->id, true]);
$ret->opacity = true;
return $ret;
}
public static function getCellLabel($look, $identifier){
switch($identifier){
case 'GP':
return $look === 'mail' ? 'GP' : 'Reise | Gesamtpreis';
break;
case 'AZ':
return $look === 'mail' ? 'AZ' : 'Anzahlung';
break;
case 'RZ':
return $look === 'mail' ? 'RZ' : 'Restzahlung';
break;
case 'SB':
return $look === 'mail' ? 'GB' : 'Storno | Betrag';
break;
case 'GW':
return $look === 'mail' ? 'W' : 'Gutschein | Wert';
break;
case 'VC':
return $look === 'mail' ? 'für Kunden' : 'Voucher für den Kunden';
break;
case 'VA':
return $look === 'mail' ? 'für Agentur' : 'Voucher für die Agentur';
break;
}
}
}