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

234 lines
No EOL
9.9 KiB
PHP

<?php
namespace App\Helper;
use App\Models\BookingDocument;
class BookingDocument
{
private static $files_count = 0;
public static function getFilesCount(){
return self::$files_count++;
}
public static function getBookingDocumentsHTMLTable($identifier, $booking){
$ret = "";
$files = self::getV2BookingDocuments($identifier, $booking);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v2');
}
return $ret;
//TODO !!! v3 save data and output
$files = self::getBookingDocuments($identifier, $booking->id);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v3');
}else{
$files = self::getV2BookingDocuments($identifier, $booking);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v2');
}
}
return $ret;
}
public static function getBookingDocuments($identifier, $booking_id){
switch($identifier){
case 'registration':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'registration')->get();
break;
case 'confirmation':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'confirmation')->get();
break;
case 'storno':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'storno')->get();
break;
case 'coupon':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'coupon')->get();
break;
case 'voucher':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'voucher')->get();
break;
case 'voucher_agency':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'voucher_agency')->get();
break;
default:
$files = null;
}
return $files;
}
public static function getV2BookingDocuments($identifier, $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){
$ret = "";
foreach($files as $file){
;
if($version === 'v2'){
$file_details = self::getV2FileDetails($file, $identifier);
}
if($version === 'v3'){
$file_details = self::getV2FileDetails($file, $identifier);
}
if(isset($file_details)){
$ret .= "<tr>";
$ret .= "<th scope='row'>".self::getFilesCount()."</th>";
$ret .= "<td>";
$ret .= "<a href='".route('customer_file_show', [$identifier, $file->id])."' target='_blank' class='badge badge-md badge-".$file_details->color."'>";
$ret .= "<i class='fa fa-file-pdf mr-1'></i> ".$file_details->name;
$ret .= "</a>";
$ret .= "</td>";
$ret .= "<td>".$file_details->cell."</td>";
$ret .= "<td>".$file_details->date."</td>";
$ret .= "<td>";
$ret .= "<a href='".route('customer_file_show', [$identifier, $file->id, true])."' class='btn btn-xs btn-default' title='Download' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-download'></i>";
$ret .= "</a>";
$ret .= "</td>";
$ret .= "</tr>";
}
}
return $ret;
}
private static function getV3FileDetails($file, $identifier){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = "Reise | Gesamtpreis: ".\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 = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro; <br>
Anzahlung: ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
Restzahlung: ".\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 = "Storno | Betrag: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "danger";
$ret->cell = "Gutschein | Wert: ".\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 ID ".$file->id;
$ret->color = "dark";
$ret->cell = " Voucher für den Kunden";
$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 = "Voucher für die Agentur";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
return $ret;
return $ret;
}
private static function getV2FileDetails($file, $identifier){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = "Reise | Gesamtpreis: ".\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 = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro; <br>
Anzahlung: ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
Restzahlung: ".\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 = "Storno | Betrag: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "danger";
$ret->cell = "Gutschein | Wert: ".\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 ID ".$file->id;
$ret->color = "dark";
$ret->cell = " Voucher für den Kunden";
$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 = "Voucher für die Agentur";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
return $ret;
}
}