File Controller, Booking Organisation, import Draft, old arrangements
This commit is contained in:
parent
4eb83def39
commit
8fd1f4d451
289 changed files with 36649 additions and 10877 deletions
|
|
@ -14,7 +14,8 @@ use App\Libraries\CreatePDFCoupon;
|
|||
use Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BookingPDFRepository extends BaseRepository {
|
||||
class BookingPDFRepository extends BaseRepository
|
||||
{
|
||||
|
||||
protected $prepath;
|
||||
|
||||
|
|
@ -29,7 +30,8 @@ class BookingPDFRepository extends BaseRepository {
|
|||
return $this->model;
|
||||
}
|
||||
|
||||
public function createPDF($id, $data){
|
||||
public function createPDF($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
|
||||
|
|
@ -57,7 +59,8 @@ class BookingPDFRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public function createPDF_Registration(){
|
||||
public function createPDF_Registration()
|
||||
{
|
||||
$document = new stdClass();
|
||||
$document->name = 'registration';
|
||||
$document->number = $this->model->lead_id;
|
||||
|
|
@ -65,22 +68,21 @@ class BookingPDFRepository extends BaseRepository {
|
|||
$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";
|
||||
|
||||
$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);
|
||||
];
|
||||
$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(){
|
||||
public function createPDF_Confirmation()
|
||||
{
|
||||
$document = new stdClass();
|
||||
$document->name = 'confirmation';
|
||||
$document->number = $this->model->lead_id;
|
||||
|
|
@ -92,32 +94,31 @@ class BookingPDFRepository extends BaseRepository {
|
|||
$document->deposit = $this->model->getConfirmationDeposit();
|
||||
$document->final_payment = $this->model->getConfirmationFinalPayment();
|
||||
|
||||
if ($this->model->isDepositPossible())
|
||||
{
|
||||
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 {
|
||||
$_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";
|
||||
$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);
|
||||
];
|
||||
$pdf_file->create($data, $filename, 'save', $this->prepath . $dir);
|
||||
$booking_document = $this->savePDF($dir, $filename, 'sterntours-template', 'confirmation', $document);
|
||||
|
||||
return $booking_document;
|
||||
return $booking_document;
|
||||
}
|
||||
|
||||
public function createPDF_Coupon($data){
|
||||
public function createPDF_Coupon($data)
|
||||
{
|
||||
|
||||
$document = new stdClass();
|
||||
$document->name = 'coupon';
|
||||
|
|
@ -133,7 +134,7 @@ class BookingPDFRepository extends BaseRepository {
|
|||
$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;
|
||||
|
|
@ -142,61 +143,63 @@ class BookingPDFRepository extends BaseRepository {
|
|||
|
||||
|
||||
$dir = $this->getDirPath('pdf', 'coupon', $document->date->format('Y'));
|
||||
$filename = "Gutschein-".$coupon->number.".pdf";
|
||||
$filename = "Gutschein-" . $coupon->number . ".pdf";
|
||||
|
||||
$pdf_file = new CreatePDFCoupon('pdf.booking_coupon');
|
||||
$data = [
|
||||
$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;
|
||||
];
|
||||
$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){
|
||||
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->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";
|
||||
$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);
|
||||
];
|
||||
$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;
|
||||
return $booking_document;
|
||||
}
|
||||
|
||||
public function createPDF_Storno($data){
|
||||
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 ){
|
||||
if ($storno_level_number > 0 && $storno_level_number < 100) {
|
||||
$storno_level = $storno_level_number;
|
||||
}
|
||||
//calculate price canceled
|
||||
if($storno_total_price > 0){
|
||||
if ($storno_total_price > 0) {
|
||||
$price_canceled = $storno_total_price;
|
||||
$storno_level = ((100 / $price) * $storno_total_price);
|
||||
}else{
|
||||
} else {
|
||||
$price_canceled = round($price / 100 * $storno_level, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//init identifier
|
||||
$identifier = 'storno';
|
||||
|
|
@ -210,11 +213,11 @@ class BookingPDFRepository extends BaseRepository {
|
|||
'storno_print' => $data['storno_print'],
|
||||
'binary_data' => NULL,
|
||||
];
|
||||
if($this->model->hasDocument($identifier)){
|
||||
if ($this->model->hasDocument($identifier)) {
|
||||
$booking_document = $this->model->getDocument($identifier);
|
||||
$booking_storno = $booking_document->booking_storno;
|
||||
$booking_storno->update($fill);
|
||||
}else{
|
||||
} else {
|
||||
$booking_storno = BookingStorno::create($fill);
|
||||
}
|
||||
|
||||
|
|
@ -233,53 +236,54 @@ class BookingPDFRepository extends BaseRepository {
|
|||
$document->booking_storno_id = $booking_storno->id;
|
||||
$document->storno_level = $storno_level;
|
||||
|
||||
|
||||
|
||||
|
||||
//update Booking // Lead Status
|
||||
if($storno_status_id){
|
||||
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";
|
||||
$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);
|
||||
|
||||
];
|
||||
$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 )){
|
||||
//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){
|
||||
private function savePDF($dir, $filename, $template, $identifier, $document = null, $status = 0)
|
||||
{
|
||||
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($this->prepath.$dir.$filename);
|
||||
$pdfMerger->addPDF($this->prepath . $dir . $filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, $template);
|
||||
Storage::disk('public')->put($dir.$filename, $file);
|
||||
Storage::disk('public')->put($dir . $filename, $file);
|
||||
|
||||
$fill = [
|
||||
'booking_id' => $this->model->id,
|
||||
|
|
@ -291,25 +295,23 @@ class BookingPDFRepository extends BaseRepository {
|
|||
'original_name' => $filename,
|
||||
'ext' => 'pdf',
|
||||
'mine' => 'application/pdf',
|
||||
'size' => Storage::disk('public')->size($dir.$filename),
|
||||
'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)){
|
||||
if ($this->model->hasDocument($identifier)) {
|
||||
$booking_document = $this->model->getDocument($identifier);
|
||||
$booking_document->update($fill);
|
||||
}else{
|
||||
} else {
|
||||
$booking_document = BookingDocument::create($fill);
|
||||
}
|
||||
return $booking_document;
|
||||
|
||||
//return $pdfMerger->myMerge('browser', $filename, $template);
|
||||
//return $pdfMerger->myMerge('browser', $filename, $template);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue