add: new file; modified
This commit is contained in:
parent
bfe16ec517
commit
d1a09fc220
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace D3\PdfDocuments\Modules\Application\Model\dev;
|
||||
namespace D3\PdfDocuments\Modules\Application\Model;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Order as OrderModel;
|
||||
use OxidEsales\EshopCommunity\Application\Model\Order;
|
||||
use OxidEsales\EshopCommunity\Application\Model\User;
|
||||
use OxidEsales\EshopCommunity\Application\Model\Payment;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use Spipu\Html2Pdf\Exception\Html2PdfException;
|
||||
use Spipu\Html2Pdf\Html2Pdf;
|
||||
|
||||
class deliverynotePdf extends pdfDocuments implements \pdfDocuments_interface
|
||||
{
|
||||
/**
|
||||
* @param string $sFilename
|
||||
* @param int $iSelLang
|
||||
* @param string $target
|
||||
* @throws Html2PdfException
|
||||
*/
|
||||
|
||||
public $blIsNewOrder = 0;
|
||||
public $sFilename;
|
||||
public $oOrder;
|
||||
|
||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||
{
|
||||
self::$_blIsAdmin = 0;
|
||||
|
||||
$oSmarty = Registry::getUtilsView()->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';
|
||||
}
|
||||
}
|
@ -1,111 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace D3\PdfDocuments\Modules\Application\Model\dev;
|
||||
namespace D3\PdfDocuments\Modules\Application\Model;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Order as OrderModel;
|
||||
use OxidEsales\EshopCommunity\Application\Model\Order;
|
||||
use OxidEsales\EshopCommunity\Application\Model\User;
|
||||
use OxidEsales\EshopCommunity\Application\Model\Payment;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use Spipu\Html2Pdf\Exception\Html2PdfException;
|
||||
use Spipu\Html2Pdf\Html2Pdf;
|
||||
|
||||
class invoicePdf extends pdfDocuments implements \pdfDocuments_interface
|
||||
{
|
||||
/**
|
||||
* @param string $sFilename
|
||||
* @param int $iSelLang
|
||||
* @param string $target
|
||||
* @throws Html2PdfException
|
||||
*/
|
||||
|
||||
public $blIsNewOrder = 0;
|
||||
public $sFilename;
|
||||
public $oOrder;
|
||||
|
||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||
{
|
||||
self::$_blIsAdmin = 0;
|
||||
|
||||
$oSmarty = Registry::getUtilsView()->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';
|
||||
}
|
||||
}
|
@ -1,17 +1,9 @@
|
||||
<?php
|
||||
namespace D3\PdfDocuments\Modules\Application\Model\dev;
|
||||
namespace D3\PdfDocuments\Modules\Application\Model;
|
||||
|
||||
use \OxidEsales\Eshop\Application\Model\Order;
|
||||
|
||||
interface albatros{
|
||||
public function setFilename($sContent, $target, $sFilename);
|
||||
public function setInvoiceNumber();
|
||||
public function setInvoiceDate();
|
||||
public function saveOrderOnChanges();
|
||||
public function getDeliveryNoteTemplate();
|
||||
}
|
||||
|
||||
abstract class pdfDocuments implements albatros, \pdfDocuments_interface
|
||||
abstract class pdfDocuments implements albatros
|
||||
{
|
||||
|
||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||
@ -40,10 +32,10 @@ abstract class pdfDocuments implements albatros, \pdfDocuments_interface
|
||||
switch (Registry::getRequest()->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';
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace D3\PdfDocuments\Modules\Application\controllers;
|
||||
|
||||
class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocuments_parent
|
||||
{
|
||||
public function canExport()
|
||||
{
|
||||
// We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
|
||||
$masterDb = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster();
|
||||
$sOrderId = $this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user