08 2024
This commit is contained in:
parent
c1c613a4b9
commit
881fc84207
384 changed files with 50679 additions and 990 deletions
176
app/Libraries/CreateCouponPDF.php
Normal file
176
app/Libraries/CreateCouponPDF.php
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Services\Util;
|
||||
use App\Libraries\CouponPDF;
|
||||
|
||||
class CreateCouponPDF {
|
||||
|
||||
protected $pdfRenderer;
|
||||
protected $coupon;
|
||||
protected $styles = array();
|
||||
protected $pdf;
|
||||
|
||||
|
||||
public function __construct(Coupon $coupon)
|
||||
{
|
||||
$this->coupon = $coupon;
|
||||
}
|
||||
|
||||
public function create(){
|
||||
|
||||
// initiate FPDI
|
||||
$pdf = new CouponPDF();
|
||||
if($this->coupon->text == NULL && $this->coupon->value == 50.00){
|
||||
$is_static_coupon = true;
|
||||
|
||||
$pdf->_set('is_static_coupon', true);
|
||||
}else{
|
||||
$is_static_coupon = false;
|
||||
$pdf->_set('is_static_coupon', false);
|
||||
}
|
||||
|
||||
$pdf->AddFont('Helvetica', '', 'helvetica.php');
|
||||
$pdf->AddPage('P', array(210, 297));
|
||||
if ($this->coupon->isLegal()) {
|
||||
$pdf->SetXY(20, 90);
|
||||
$pdf->SetTextColor(230, 10, 10);
|
||||
$pdf->SetFont('Helvetica', 'B', 28);
|
||||
$pdf->Cell(80, 20, utf8_decode('Der Gutschein ist nicht mehr gültig!'), 0, 0, 'L');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$is_static_coupon){
|
||||
$pdf->SetXY(30, 55);
|
||||
$pdf->SetTextColor(16, 77, 140);
|
||||
$pdf->SetFont('Helvetica', 'B', 50);
|
||||
$pdf->Cell(80, 20, Util::_number_format($this->coupon->value), 0, 0, 'L');
|
||||
}
|
||||
|
||||
$pdf->SetDrawColor(16, 77, 140);
|
||||
$pdf->SetFillColor(16, 77, 140);
|
||||
$pdf->SetLineWidth(0.4);
|
||||
$pdf->Rect(126, 31, 74, 20, 'DF');
|
||||
|
||||
$pdf->SetTextColor(255,255,255);
|
||||
$x = 128;
|
||||
$y = 32;
|
||||
$border = 0;
|
||||
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
$pdf->Cell(30, 6, "Nummer:", $border, 0, 'L');
|
||||
$pdf->SetFont('Helvetica', '', 10);
|
||||
$pdf->Cell(40, 6, $this->coupon->number, $border, 0, 'R');
|
||||
$y += 6;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
$pdf->Cell(30, 6, utf8_decode('Gültig vom:'), $border, 0, 'L');
|
||||
$pdf->SetFont('Helvetica', '', 10);
|
||||
$pdf->Cell(40, 6, Util::_format_date($this->coupon->issue_date), $border, 0, 'R');
|
||||
$y += 6;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
$pdf->Cell(30, 6, utf8_decode('Gültig bis:'), $border, 0, 'L');
|
||||
$pdf->SetFont('Helvetica', '', 10);
|
||||
$pdf->Cell(40, 6, Util::_format_date($this->coupon->valid_date), $border, 0, 'R');
|
||||
|
||||
|
||||
//$pdf->SetDrawColor(16, 77, 140);
|
||||
$pdf->SetFillColor(16, 77, 140);
|
||||
$pdf->Rect(126, 56, 74, 7.5, 'DF');
|
||||
$pdf->Rect(126, 56, 74, 35, 'D');
|
||||
|
||||
$x = 128;
|
||||
$y = 56;
|
||||
$pdf->SetXY($x, $y);
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
$pdf->Cell(40, 7.5, utf8_decode('Ausgestellt für:'), $border, 0, 'L');
|
||||
|
||||
$pdf->SetTextColor(16, 77, 140);
|
||||
$pdf->SetFont('Helvetica', '', 10);
|
||||
|
||||
$customerName = ($this->coupon->customer && $this->coupon->customer->salutation ? $this->coupon->customer->salutation->name . ' ' : '' )
|
||||
. ($this->coupon->customer->title ? $this->coupon->customer->title . ' ' : '' )
|
||||
. $this->coupon->customer->fullName();
|
||||
$customerStreet = $this->coupon->customer ? $this->coupon->customer->street : '';
|
||||
$customerRegion = $this->coupon->customer->zip ? $this->coupon->customer->zip." " : '';
|
||||
$customerRegion .= $this->coupon->customer->city ? $this->coupon->customer->city : '';
|
||||
|
||||
$y += 12;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->Cell(70, 5.5, utf8_decode($customerName), $border, 0, 'L');
|
||||
$y += 5.5;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->Cell(70, 5.5, utf8_decode($customerStreet), $border, 0, 'L');
|
||||
$y += 5.5;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->Cell(70, 5.5, utf8_decode($customerRegion), $border, 0, 'L');
|
||||
|
||||
$x = 128;
|
||||
$y = 106;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
|
||||
$sender = 'STERN TOURS GmbH'."\n".
|
||||
'Emser Straße 3'."\n".
|
||||
'10719 Berlin'."\n\n".
|
||||
'Fon: +49 (0) 30 700 9410 0'."\n".
|
||||
'Fax: +49 (0) 30 700 9410 44'."\n".
|
||||
'e-Mail: stern@sterntours.de'."\n".
|
||||
'Internet: www.sterntours.de'."\n";
|
||||
$pdf->MultiCell(70, 5.5, utf8_decode($sender), $border, 'L');
|
||||
|
||||
|
||||
if($is_static_coupon) {
|
||||
$x = 12;
|
||||
$y = 155.5;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
$pdf->SetFont('Helvetica', 'B', 10);
|
||||
$pdf->Cell(130, 5.5, utf8_decode('Gutscheinbedingungen:'), $border, 0, 'L');
|
||||
$pdf->SetFont('Helvetica', '', 7);
|
||||
$terms = '- gültig bei Pauschalreisen, Last Minute & More, Hotel und Ferienhäuser'."\n".
|
||||
'- nur Einlösbar bei Buchungen mit einem Gesamtreisepreis von mind. Euro 750,-'."\n".
|
||||
'- Der Gutscheinbetrag wird Ihnen nach Reiseantritt der nächsten Reise per'."\n".
|
||||
' Banküberweisung zugestellt'."\n".
|
||||
'- der Reise-Gutschein kann bis einen Tag vor Abreise eingelöst werden'."\n".
|
||||
'- pro Buchung kann nur ein Reise-Gutschein eingelöst werden'."\n".
|
||||
'- der Reise-Gutschein kann nicht auf Stornokosten angerechnet werden'."\n".
|
||||
'- bei Stornierung der Reise wird der Reise-Gutschein ungültig und nicht ausgezahlt'."\n".
|
||||
'- der Reise-Gutschein ist nicht übertragbar'."\n";
|
||||
|
||||
$y += 5.5;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->MultiCell(130, 3.5, utf8_decode($terms), $border, 'L');
|
||||
|
||||
}else{
|
||||
$x = 12;
|
||||
$y = 157;
|
||||
$pdf->SetXY($x, $y);
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
$pdf->SetFont('Helvetica', '', 9);
|
||||
if( $this->coupon->text !== ""){
|
||||
$text = $this->coupon->text;
|
||||
$text = preg_replace("/\r\n|\n|\r/", "\n", $text);
|
||||
|
||||
$pdf->MultiCell(180, 4.2, utf8_decode($text), 0, 'L');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
$this->pdf = $pdf;
|
||||
}
|
||||
|
||||
public function output($filename, $cd){
|
||||
if($cd){
|
||||
return $this->pdf->Output($filename, 'D');
|
||||
}
|
||||
return $this->pdf->Output();
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
app/Libraries/CreatePDF.php
Normal file
63
app/Libraries/CreatePDF.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Libraries\CouponPDF;
|
||||
use App\Models\Coupon;
|
||||
use Storage;
|
||||
|
||||
class CreatePDF{
|
||||
|
||||
protected $view;
|
||||
protected $pdf;
|
||||
protected $prepath;
|
||||
protected $disk;
|
||||
|
||||
|
||||
public function __construct($view, $disk = 'public')
|
||||
{
|
||||
$this->view = $view;
|
||||
$this->disk = $disk;
|
||||
$this->prepath = Storage::disk($disk)->getAdapter()->getPathPrefix();
|
||||
|
||||
}
|
||||
|
||||
public function create($data, $name='test.pdf', $output='stream', $path = false){
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8') ;//chrome
|
||||
//dd($data);
|
||||
|
||||
$pdf = app('dompdf.wrapper');
|
||||
$pdf->getDomPDF()->set_option("enable_php", true);
|
||||
$pdf->loadView($this->view, $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
if($output === 'stream'){
|
||||
//file???
|
||||
return $pdf->stream($name);
|
||||
}
|
||||
if($output === 'download'){
|
||||
//download
|
||||
return $pdf->download($name);
|
||||
}
|
||||
|
||||
if($output === 'save'){
|
||||
if($path){
|
||||
$pdf->save($path.$name);
|
||||
return $path.$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function merger($dir, $filename, $template){
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($this->prepath.$dir.$filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, $template);
|
||||
Storage::disk($this->disk)->put($dir.$filename, $file);
|
||||
}
|
||||
|
||||
public function setPrePath($path){
|
||||
$this->prepath = $path;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
47
app/Libraries/CreatePDFCoupon.php
Normal file
47
app/Libraries/CreatePDFCoupon.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Libraries\CouponPDF;
|
||||
use App\Models\Coupon;
|
||||
use Storage;
|
||||
|
||||
class CreatePDFCoupon{
|
||||
|
||||
protected $view;
|
||||
protected $pdf;
|
||||
|
||||
|
||||
public function __construct($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
|
||||
public function create($data, $name='test.pdf', $output='stream', $path = false){
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8') ;//chrome
|
||||
//dd($data);
|
||||
|
||||
$pdf = app('dompdf.wrapper');
|
||||
$pdf->getDomPDF()->set_option("enable_php", true);
|
||||
$pdf->loadView($this->view, $data);
|
||||
$customPaper = array(0, 0, 595.28, 283,47);
|
||||
$pdf->setPaper($customPaper, 'portrait');
|
||||
// $pdf->setPaper('A4', 'portrait');
|
||||
|
||||
if($output === 'stream'){
|
||||
return $pdf->stream($name);
|
||||
}
|
||||
if($output === 'download'){
|
||||
return $pdf->download($name);
|
||||
}
|
||||
|
||||
if($output === 'save'){
|
||||
if($path){
|
||||
$pdf->save($path.$name);
|
||||
return $path.$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
188
app/Libraries/MyPDFMerger.php
Normal file
188
app/Libraries/MyPDFMerger.php
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
namespace App\Libraries;
|
||||
|
||||
//use FPDI in myMerge v2
|
||||
//use FPDF;
|
||||
//use FPDI;
|
||||
|
||||
class MyPDFMerger
|
||||
{
|
||||
private $_files; //['form.pdf'] ["1,2,4, 5-19"]
|
||||
private $_fpdi;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
/* if(!class_exists("FPDF")) {
|
||||
require_once(__DIR__.'/fpdf/fpdf.php');
|
||||
}
|
||||
if(!class_exists("FPDI")) {
|
||||
require_once(__DIR__.'/fpdi/fpdi.php');
|
||||
}*/
|
||||
}
|
||||
|
||||
public function addPDF($filepath, $pages = 'all')
|
||||
{
|
||||
if (file_exists($filepath)) {
|
||||
if (strtolower($pages) != 'all') {
|
||||
$pages = $this->_rewritepages($pages);
|
||||
}
|
||||
|
||||
$this->_files[] = array($filepath, $pages);
|
||||
} else {
|
||||
throw new \exception("Could not locate PDF on '$filepath'");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function myMerge($outputmode = 'browser', $outputpath = 'newfile.pdf', $theme = false)
|
||||
{
|
||||
if (!isset($this->_files) || !is_array($this->_files)): throw new \exception("No PDFs to merge."); endif;
|
||||
|
||||
$fpdi = new \setasign\Fpdi\Fpdi();
|
||||
$first = 1;
|
||||
|
||||
//
|
||||
//merger operations
|
||||
foreach ($this->_files as $file) {
|
||||
$filename = $file[0];
|
||||
$filepages = $file[1];
|
||||
|
||||
|
||||
$count = $fpdi->setSourceFile($filename);
|
||||
|
||||
//add the pages
|
||||
if ($filepages == 'all') {
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$count = $fpdi->setSourceFile($filename);
|
||||
$template = $fpdi->importPage($i);
|
||||
$size = $fpdi->getTemplateSize($template);
|
||||
$orientation = ($size['height'] > $size['width']) ? 'P' : 'L';
|
||||
|
||||
$fpdi->AddPage($orientation, array($size['width'], $size['height']));
|
||||
if($theme){
|
||||
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/'.$theme.'-'.$first.'.pdf');
|
||||
if($first == 1){
|
||||
$first = 2;
|
||||
}
|
||||
$backId = $fpdi->importPage(1);
|
||||
$fpdi->useTemplate($backId);
|
||||
|
||||
}
|
||||
$fpdi->useTemplate($template);
|
||||
}
|
||||
} else {
|
||||
foreach ($filepages as $page) {
|
||||
$count = $fpdi->setSourceFile($filename);
|
||||
if (!$template = $fpdi->importPage($page)): throw new \exception("Could not load page '$page' in PDF '$filename'. Check that the page exists."); endif;
|
||||
$size = $fpdi->getTemplateSize($template);
|
||||
$orientation = ($size['h'] > $size['w']) ? 'P' : 'L';
|
||||
|
||||
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
|
||||
if($theme){
|
||||
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/'.$theme.'-'.$first.'.pdf');
|
||||
if($first == 1){
|
||||
$first = 2;
|
||||
}
|
||||
$backId = $fpdi->importPage(1);
|
||||
$fpdi->useTemplate($backId);
|
||||
}
|
||||
|
||||
$fpdi->useTemplate($template);
|
||||
}
|
||||
}
|
||||
//after first file (invoice) on bpaper
|
||||
$slug = false;
|
||||
}
|
||||
|
||||
//output operations
|
||||
$mode = $this->_switchmode($outputmode);
|
||||
|
||||
if ($mode == 'S') {
|
||||
return $fpdi->Output($outputpath, 'S');
|
||||
} else {
|
||||
if ($fpdi->Output($outputpath, $mode) == '') {
|
||||
return true;
|
||||
} else {
|
||||
throw new \exception("Error outputting PDF to '$outputmode'.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* FPDI uses single characters for specifying the output location. Change our more descriptive string into proper format.
|
||||
* @param $mode
|
||||
* @return Character
|
||||
*/
|
||||
private function _switchmode($mode)
|
||||
{
|
||||
switch (strtolower($mode)) {
|
||||
case 'download':
|
||||
return 'D';
|
||||
break;
|
||||
case 'browser':
|
||||
return 'I';
|
||||
break;
|
||||
case 'file':
|
||||
return 'F';
|
||||
break;
|
||||
case 'string':
|
||||
return 'S';
|
||||
break;
|
||||
default:
|
||||
return 'I';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes our provided pages in the form of 1,3,4,16-50 and creates an array of all pages
|
||||
* @param $pages
|
||||
* @return array
|
||||
* @throws exception
|
||||
*/
|
||||
private function _rewritepages($pages)
|
||||
{
|
||||
$pages = str_replace(' ', '', $pages);
|
||||
$part = explode(',', $pages);
|
||||
|
||||
//parse hyphens
|
||||
foreach ($part as $i) {
|
||||
$ind = explode('-', $i);
|
||||
|
||||
if (count($ind) == 2) {
|
||||
$x = $ind[0]; //start page
|
||||
$y = $ind[1]; //end page
|
||||
|
||||
if ($x > $y): throw new \exception("Starting page, '$x' is greater than ending page '$y'.");
|
||||
return false; endif;
|
||||
|
||||
//add middle pages
|
||||
while ($x <= $y): $newpages[] = (int)$x;
|
||||
$x++; endwhile;
|
||||
} else {
|
||||
$newpages[] = (int)$ind[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $newpages;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$pdf = new PDFMerger;
|
||||
|
||||
$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4')
|
||||
->addPDF('samplepdfs/two.pdf', '1-2')
|
||||
->addPDF('samplepdfs/three.pdf', 'all')
|
||||
->merge('file', 'samplepdfs/TEST2.pdf');
|
||||
|
||||
//REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
|
||||
//You do not need to give a file path for browser, string, or download - just the name.
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue