2020-05-19 16:06:32 +02:00
|
|
|
<?php
|
2020-05-30 00:52:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Max Buhe <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2020-05-19 16:06:32 +02:00
|
|
|
namespace D3\PdfDocuments\Modules\Application\controllers;
|
|
|
|
|
2020-05-30 00:52:41 +02:00
|
|
|
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
|
|
|
|
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
|
|
|
|
use D3\PdfDocuments\Application\Model\Registries\registry_orderoverview;
|
|
|
|
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments;
|
2020-05-20 11:51:48 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\TableViewNameGenerator;
|
2020-05-30 00:52:41 +02:00
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2020-05-20 11:51:48 +02:00
|
|
|
|
2020-05-19 16:06:32 +02:00
|
|
|
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).
|
2020-05-20 11:51:48 +02:00
|
|
|
$masterDb = DatabaseProvider::getMaster();
|
2020-05-19 16:06:32 +02:00
|
|
|
$sOrderId = $this->getEditObjectId();
|
|
|
|
|
2020-05-20 11:51:48 +02:00
|
|
|
$viewNameGenerator = Registry::get(TableViewNameGenerator::class);
|
2020-05-19 16:06:32 +02:00
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$soxId = $this->getEditObjectId();
|
|
|
|
if ($soxId != "-1" && isset($soxId)) {
|
2020-05-30 00:52:41 +02:00
|
|
|
/** @var d3_Order_PdfDocuments $oOrder */
|
2020-05-20 11:51:48 +02:00
|
|
|
$oOrder = oxNew(Order::class);
|
2020-05-19 16:06:32 +02:00
|
|
|
if ($oOrder->load($soxId)) {
|
2020-05-30 00:52:41 +02:00
|
|
|
try {
|
|
|
|
self::$_blIsAdmin = 0;
|
|
|
|
$oUtils = Registry::getUtils();
|
|
|
|
$sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
|
|
|
|
$sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
|
|
|
|
$sFilename = $this->makeValidFileName($sFilename);
|
|
|
|
ob_start();
|
|
|
|
$oOrder->genPdf($sFilename, Registry::getConfig()->getRequestParameter("pdflanguage"));
|
|
|
|
$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);
|
|
|
|
Registry::getUtils()->showMessageAndExit($sPDF);
|
|
|
|
} catch (pdfGeneratorExceptionAbstract $e) {
|
|
|
|
Registry::get(UtilsView::class)->addErrorToDisplay($e);
|
|
|
|
Registry::getLogger()->error($e);
|
|
|
|
}
|
2020-05-19 16:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 00:52:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return registry_orderoverview
|
|
|
|
*/
|
|
|
|
public function d3getGeneratorList()
|
|
|
|
{
|
|
|
|
return oxNew(registry_orderoverview::class);
|
|
|
|
}
|
2020-05-19 16:06:32 +02:00
|
|
|
}
|