diff --git a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/d3_Order_PdfDocuments.php b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/d3_Order_PdfDocuments.php index 711b98c..643937e 100644 --- a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/d3_Order_PdfDocuments.php +++ b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/d3_Order_PdfDocuments.php @@ -17,7 +17,7 @@ namespace D3\PdfDocuments\Modules\Application\Model; -use D3\PdfDocuments\Modules\Application\Model\dev\deliverynotePdf; +use D3\PdfDocuments\Modules\Application\Model\deliverynotePdf; use OxidEsales\EshopCommunity\Application\Model\User; use OxidEsales\EshopCommunity\Application\Model\Payment; use OxidEsales\Eshop\Core\Registry; @@ -34,16 +34,33 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent */ public function genPdf($sFilename, $iSelLang = 0, $target = 'I') { - switch (Registry::getRequest()->getRequestParameter('pdftype')) { - case ('dnote'): - case ('dnote_without_logo'): - $Pdf = oxNew(deliverynotePdf::class); - break; - default: - $Pdf = oxNew(invoicePdf::class); - } + $Pdf= $this->getPdfClass(); + die(); $Pdf->setOrder($this); $Pdf->genPdf($sFilename, $iSelLang = 0, $target = 'I'); } + public function getPdfClass(){ + switch (Registry::getRequest()->getRequestParameter('pdftype')) { + case ('dnote'): + case ('dnote_without_logo'): + return oxNew(deliverynotePdf::class); + case ('standart'): + case('standart_without_logo'): + return oxNew(invoicePdf::class); + default: + dumpVar(get_class($this)); + return $this->getCustomPdfClass(); + } + } + + /** + * @return albatros + * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException + * @throws \oxSystemComponentException + */ + public function getCustomPdfClass() + { + return oxNew(invoicePdf::class); + } } diff --git a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/deliverynotePdf.php b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/deliverynotePdf.php index 2e7d047..bbe15f4 100644 --- a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/deliverynotePdf.php +++ b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/deliverynotePdf.php @@ -1,111 +1,9 @@ getSmarty(); - $oSmarty->assign('oConfig', Registry::getSession()->getConfig()); - $oSmarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig()); - $oSmarty->assign('order', $this); - $oSmarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop()); - $oSmarty->assign('lang', Registry::getLang()); - - $oUser= oxNew(User::Class); - $oUser->load($this->getOrder()->getFieldData('oxuserid')); - $oSmarty->assign('user', $oUser); - - $oPayment= oxNew(Payment::class); - $oPayment->load($this->getOrder()->getFieldData('oxpaymenttype')); - $oSmarty->assign('payment', $oPayment); - - $this->setInvoiceNumber(); - $this->setInvoiceDate(); - $this->saveOrderOnChanges(); - - switch (Registry::getRequest()->getRequestParameter('pdftype')) { - case ('dnote'): - case ('dnote_without_logo'): - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); - break; - default: - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); - } - } - - /** - * @param OrderModel $order - */ - public function setOrder(OrderModel $order){ - $this->oOrder= $order; - } - - /** - * @return OrderModel - */ - public function getOrder(){ - return $this->oOrder; - } - - public function setFilename($sContent, $target, $sFilename){ - $ordernr= $this->getOrder()->getFieldData('oxordernr'); - $billnr= $this->getOrder()->getFieldData('oxbillnr');; - - $sFilename = str_replace( $ordernr, $billnr, $sFilename); - - $oPdf= oxNew(Html2Pdf::class, 'P', 'A4', 'de'); - $oPdf->writeHTML($sContent); - $oPdf->output($sFilename, $target); - } - - public function setInvoiceNumber(){ - $this->blIsNewOrder = 0; - - if (!$this->getOrder()->getFieldData('oxbillnr')) { - $this->getOrder()->assign(['oxbillnr' => $this->getOrder()->getNextBillNum()]); - - $this->blIsNewOrder = 1; - } - } - - public function setInvoiceDate(){ - if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') { - $this->getOrder()->assign([date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')))]); - - $this->blIsNewOrder = 1; - } - } - - public function saveOrderOnChanges(){ - if ($this->blIsNewOrder) { - $this->getOrder()->save(); - } - } - - public function getDeliveryNoteTemplate(){ - return 'd3deliverynote.tpl'; +class deliverynotePdf extends pdfDocuments{ + public function getTemplate(){ + return 'deliverynote.tpl'; } } \ No newline at end of file diff --git a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/invoicePdf.php b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/invoicePdf.php index 2b022e1..546d8c8 100644 --- a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/invoicePdf.php +++ b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/invoicePdf.php @@ -1,111 +1,9 @@ getSmarty(); - $oSmarty->assign('oConfig', Registry::getSession()->getConfig()); - $oSmarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig()); - $oSmarty->assign('order', $this); - $oSmarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop()); - $oSmarty->assign('lang', Registry::getLang()); - - $oUser= oxNew(User::Class); - $oUser->load($this->getOrder()->getFieldData('oxuserid')); - $oSmarty->assign('user', $oUser); - - $oPayment= oxNew(Payment::class); - $oPayment->load($this->getOrder()->getFieldData('oxpaymenttype')); - $oSmarty->assign('payment', $oPayment); - - $this->setInvoiceNumber(); - $this->setInvoiceDate(); - $this->saveOrderOnChanges(); - - switch (Registry::getRequest()->getRequestParameter('pdftype')) { - case ('dnote'): - case ('dnote_without_logo'): - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); - break; - default: - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); - } - } - - /** - * @param OrderModel $order - */ - public function setOrder(OrderModel $order){ - $this->oOrder= $order; - } - - /** - * @return OrderModel - */ - public function getOrder(){ - return $this->oOrder; - } - - public function setFilename($sContent, $target, $sFilename){ - $ordernr= $this->getOrder()->getFieldData('oxordernr'); - $billnr= $this->getOrder()->getFieldData('oxbillnr');; - - $sFilename = str_replace( $ordernr, $billnr, $sFilename); - - $oPdf= oxNew(Html2Pdf::class, 'P', 'A4', 'de'); - $oPdf->writeHTML($sContent); - $oPdf->output($sFilename, $target); - } - - public function setInvoiceNumber(){ - $this->blIsNewOrder = 0; - - if (!$this->getOrder()->getFieldData('oxbillnr')) { - $this->getOrder()->assign(['oxbillnr' => $this->getOrder()->getNextBillNum()]); - - $this->blIsNewOrder = 1; - } - } - - public function setInvoiceDate(){ - if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') { - $this->getOrder()->assign([date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')))]); - - $this->blIsNewOrder = 1; - } - } - - public function saveOrderOnChanges(){ - if ($this->blIsNewOrder) { - $this->getOrder()->save(); - } - } - - public function getDeliveryNoteTemplate(){ - return 'd3deliverynote.tpl'; +class invoicePdf extends pdfDocuments{ + public function getTemplate(){ + return 'invoice.tpl'; } } \ No newline at end of file diff --git a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/pdfDocuments.php b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/pdfDocuments.php index 127a017..e053c21 100644 --- a/source/modules/d3/pdfdocuments/src/Modules/Application/Model/pdfDocuments.php +++ b/source/modules/d3/pdfdocuments/src/Modules/Application/Model/pdfDocuments.php @@ -1,17 +1,9 @@ getRequestParameter('pdftype')) { case ('dnote'): case ('dnote_without_logo'): - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); + $sContent = $oSmarty->fetch($this->getTemplate()); break; default: - $sContent = $oSmarty->fetch($this->getDeliveryNoteTemplate()); + $sContent = $oSmarty->fetch($this->getTemplate()); } } @@ -101,18 +93,4 @@ abstract class pdfDocuments implements albatros, \pdfDocuments_interface $this->getOrder()->save(); } } - - abstract public function getDeliveryNoteTemplate(); -} - -class invoicePdf extends pdfDocuments{ - public function getDeliveryNoteTemplate(){ - return 'deliverynote.tpl'; - } -} - -class deliverynotePdf extends pdfDocuments{ - public function getDeliveryNoteTemplate(){ - return 'invoice.tpl'; - } } \ No newline at end of file diff --git a/source/modules/d3/pdfdocuments/src/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php b/source/modules/d3/pdfdocuments/src/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php new file mode 100644 index 0000000..b0d13df --- /dev/null +++ b/source/modules/d3/pdfdocuments/src/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php @@ -0,0 +1,50 @@ +getEditObjectId(); + + $viewNameGenerator = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\TableViewNameGenerator::class); + $sTable = $viewNameGenerator->getViewName("oxorderarticles"); + + $sQ = "select count(oxid) from {$sTable} where oxorderid = " . $masterDb->quote($sOrderId) . " and oxstorno = 0"; + $blCan = (bool) $masterDb->getOne($sQ); + + return $blCan; + } + + public function createPDF() + { + echo __LINE__; + $soxId = $this->getEditObjectId(); + if ($soxId != "-1" && isset($soxId)) { + echo __LINE__; + // load object + $oOrder = oxNew(\OxidEsales\Eshop\Application\Model\Order::class); + if ($oOrder->load($soxId)) { + echo __LINE__; + $oUtils = \OxidEsales\Eshop\Core\Registry::getUtils(); + $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue()); + $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf"; + $sFilename = $this->makeValidFileName($sFilename); + //ob_start(); + echo __LINE__; + $oOrder->genPDF($sFilename, \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("pdflanguage")); + die(); + $sPDF = ob_get_contents(); + ob_end_clean(); + $oUtils->setHeader("Pragma: public"); + $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + $oUtils->setHeader("Expires: 0"); + $oUtils->setHeader("Content-type: application/pdf"); + $oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename); + \OxidEsales\Eshop\Core\Registry::getUtils()->showMessageAndExit($sPDF); + } + } + } +} \ No newline at end of file