114 lines
3.7 KiB
PHP
Executable file
114 lines
3.7 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Models\BookingApplication;
|
|
use App\Models\BookingConfirmation;
|
|
use App\Models\BookingStorno;
|
|
use App\Models\BookingVoucher;
|
|
use App\Models\Coupon;
|
|
use App\Models\InsuranceCertificate;
|
|
use App\Models\TravelInsurance;
|
|
use App\Repositories\CustomerFileRepository;
|
|
use App\Services\CreateCouponPDF;
|
|
use Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Request;
|
|
use Response;
|
|
|
|
class CustomerFileController extends Controller
|
|
{
|
|
|
|
protected $customerFileRepo;
|
|
|
|
public function __construct(CustomerFileRepository $customerFileRepo)
|
|
{
|
|
$this->middleware('admin');
|
|
$this->customerFileRepo = $customerFileRepo;
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$data = [
|
|
|
|
];
|
|
return view('customer.mail.index', $data);
|
|
}
|
|
|
|
public function show($model, $id, $cd = false){
|
|
|
|
$content_disposition = $cd ? 'attachment' : 'inline';
|
|
|
|
$file = false;
|
|
$filename = "";
|
|
switch ($model){
|
|
case 'booking_application':
|
|
if($booking_application = BookingApplication::find($id)){
|
|
$filename = "Buchungsauftrag-".$booking_application->booking->getBookingNumber().".pdf";
|
|
$file = base64_decode($booking_application->binary_data);
|
|
}
|
|
break;
|
|
case 'booking_confirmation':
|
|
if($booking_confirmation = BookingConfirmation::find($id)){
|
|
$filename = "Reisebestaetigung-".$booking_confirmation->booking->getBookingNumber().".pdf";
|
|
$file = base64_decode($booking_confirmation->binary_data);
|
|
}
|
|
break;
|
|
case 'booking_storno':
|
|
if($booking_stornos = BookingStorno::find($id)){
|
|
$filename = "Reisestornierung-".$booking_stornos->booking->getBookingNumber().".pdf";
|
|
$file = base64_decode($booking_stornos->binary_data);
|
|
}
|
|
break;
|
|
case 'coupon':
|
|
if($coupon = Coupon::find($id)){
|
|
$filename = "Gutschein-".$coupon->number.".pdf";
|
|
|
|
$pdf = new CreateCouponPDF($coupon);
|
|
$pdf->create();
|
|
return $pdf->output($filename, $cd);
|
|
|
|
}
|
|
break;
|
|
case 'booking_voucher':
|
|
if($booking_vouchers = BookingVoucher::find($id)){
|
|
$filename = "Voucher-".$booking_vouchers->booking->getBookingNumber().".pdf";
|
|
$file = base64_decode($booking_vouchers->binary_data);
|
|
}
|
|
break;
|
|
case 'insurance_certificate':
|
|
if($insurance_certificate = InsuranceCertificate::find($id)){
|
|
$filename = $insurance_certificate->filename;
|
|
$file = base64_decode($insurance_certificate->binary_data);
|
|
}
|
|
break;
|
|
case 'travel_insurance':
|
|
if($booking_application = TravelInsurance::find($id)){
|
|
$filename = "Buchungsauftrag-".$booking_application->booking->getBookingNumber().".pdf";
|
|
$file = base64_decode($booking_application->binary_data);
|
|
}
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
if($file){
|
|
return Response::make($file, 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => $content_disposition.'; filename="'.$filename.'"'
|
|
]);
|
|
}
|
|
|
|
die( 'error' );
|
|
}
|
|
|
|
|
|
//$path = storage_path($filename); //file_get_contents($path)
|
|
|
|
//return response()->file($pathToFile, $headers);
|
|
//return response()->download($pathToFile, $name, $headers);
|
|
}
|
|
|
|
|