handle unset order in order based document types

This commit is contained in:
Daniel Seifert 2023-09-19 23:32:55 +02:00
parent 93fd76de19
commit 1e91990a28
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
13 changed files with 61 additions and 55 deletions

View File

@ -10,6 +10,7 @@
namespace D3\PdfDocuments\Application\Model\AbstractClasses; namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use Assert\InvalidArgumentException;
use D3\ModCfg\Application\Model\d3filesystem; use D3\ModCfg\Application\Model\d3filesystem;
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface;
@ -94,6 +95,9 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
} catch (pdfGeneratorExceptionAbstract $e) { } catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e); Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e); Registry::getLogger()->error($e);
} catch (InvalidArgumentException $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e);
} }
} }
@ -117,6 +121,9 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
} catch (pdfGeneratorExceptionAbstract $e) { } catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e); Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e); Registry::getLogger()->error($e);
} catch (InvalidArgumentException $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e);
} }
} }
@ -137,6 +144,9 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
} catch (pdfGeneratorExceptionAbstract $e) { } catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e); Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e); Registry::getLogger()->error($e);
} catch (InvalidArgumentException $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e);
} }
return null; return null;
@ -159,6 +169,7 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
* @param int $iSelLang * @param int $iSelLang
* *
* @return mixed * @return mixed
* @throws InvalidArgumentException
*/ */
public function getHTMLContent($iSelLang = 0) public function getHTMLContent($iSelLang = 0)
{ {
@ -242,7 +253,7 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
{ {
$extension = $this->filenameExtension; $extension = $this->filenameExtension;
$extensionLength = (strlen($extension) + 1) * -1; $extensionLength = (strlen($extension) + 1) * -1;
if ((bool) strlen($extension) && substr($filename, $extensionLength) != '.'.$extension) { if (strlen($extension) && substr($filename, $extensionLength) != '.'.$extension) {
$filename .= '.'.$extension; $filename .= '.'.$extension;
} }

View File

@ -10,9 +10,10 @@
namespace D3\PdfDocuments\Application\Model\AbstractClasses; namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException; use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface as orderInterface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface as orderInterface;
use \OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment; use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
@ -22,6 +23,14 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/** @var Order */ /** @var Order */
public $oOrder; public $oOrder;
/**
* don't use order as constructor argument because of same method interface for all document types
*/
public function __construct()
{
parent::__construct();
}
/** /**
* @param Order $order * @param Order $order
*/ */
@ -31,15 +40,22 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
} }
/** /**
* @throws InvalidArgumentException
* @return Order * @return Order
*/ */
public function getOrder() public function getOrder()
{ {
Assert::lazy()
->that($this->oOrder)->isInstanceOf(Order::class, 'no order for pdf generator set')
->that($this->oOrder->isLoaded())->true('given order is not loaded')
->verifyNow();
return $this->oOrder; return $this->oOrder;
} }
/** /**
* @param int $iSelLang * @param int $iSelLang
* @throws InvalidArgumentException
*/ */
public function setSmartyVars($iSelLang) public function setSmartyVars($iSelLang)
{ {
@ -58,6 +74,7 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/** /**
* @return string * @return string
* @throws InvalidArgumentException
*/ */
public function getFilename() public function getFilename()
{ {
@ -86,21 +103,6 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
); );
} }
/**
* @param $sFilename
* @param int $iSelLang
* @param string $target
* @return mixed|string|null
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{
if (false == $this->getOrder()) {
throw oxNew(noBaseObjectSetException::class);
}
return parent::genPdf($sFilename, $iSelLang, $target);
}
/** /**
* @return int * @return int
*/ */
@ -115,6 +117,7 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/** /**
* @return false|string * @return false|string
* @throws InvalidArgumentException
*/ */
public function getPayableUntilDate() public function getPayableUntilDate()
{ {

View File

@ -10,10 +10,9 @@
namespace D3\PdfDocuments\Application\Model\Documents; namespace D3\PdfDocuments\Application\Model\Documents;
use Assert\InvalidArgumentException;
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder; use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface;
use Spipu\Html2Pdf\Exception\Html2PdfException;
class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceInterface class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceInterface
{ {
@ -43,6 +42,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
return 'invoice'; return 'invoice';
} }
/**
* @return void
* @throws InvalidArgumentException
*/
public function runPreAction() public function runPreAction()
{ {
parent::runPreAction(); parent::runPreAction();
@ -52,6 +55,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
$this->saveOrderOnChanges(); $this->saveOrderOnChanges();
} }
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceNumber() public function setInvoiceNumber()
{ {
if (!$this->getOrder()->getFieldData('oxbillnr')) { if (!$this->getOrder()->getFieldData('oxbillnr')) {
@ -61,6 +68,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
} }
} }
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceDate() public function setInvoiceDate()
{ {
if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') { if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') {
@ -72,6 +83,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
} }
} }
/**
* @return void
* @throws InvalidArgumentException
*/
public function saveOrderOnChanges() public function saveOrderOnChanges()
{ {
if ($this->blIsNewOrder) { if ($this->blIsNewOrder) {
@ -85,6 +100,7 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
/** /**
* @return string * @return string
* @throws InvalidArgumentException
*/ */
public function getFilename() public function getFilename()
{ {

View File

@ -1,21 +0,0 @@
<?php
/**
* See LICENSE file for license details.
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\PdfDocuments\Application\Model\Exceptions;
use Exception;
class noBaseObjectSetException extends pdfGeneratorExceptionAbstract
{
public function __construct( $sMessage = "no base object (e.g. order) for pdf generator set", $iCode = 0, Exception $previous = null )
{
parent::__construct( $sMessage, $iCode, $previous );
}
}

View File

@ -10,8 +10,6 @@
namespace D3\PdfDocuments\Application\Model\Interfaces; namespace D3\PdfDocuments\Application\Model\Interfaces;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
interface pdfdocumentsGenericInterface interface pdfdocumentsGenericInterface
{ {
/** /**
@ -58,7 +56,6 @@ interface pdfdocumentsGenericInterface
* @param string $target * @param string $target
* *
* @return mixed * @return mixed
* @throws noBaseObjectSetException
*/ */
public function genPdf($sFilename, $iSelLang = 0, $target = 'I'); public function genPdf($sFilename, $iSelLang = 0, $target = 'I');

View File

@ -10,6 +10,7 @@
namespace D3\PdfDocuments\Application\Model\Interfaces; namespace D3\PdfDocuments\Application\Model\Interfaces;
use Assert\InvalidArgumentException;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
interface pdfdocumentsOrderInterface extends pdfdocumentsGenericInterface interface pdfdocumentsOrderInterface extends pdfdocumentsGenericInterface
@ -20,6 +21,7 @@ interface pdfdocumentsOrderInterface extends pdfdocumentsGenericInterface
public function setOrder(Order $order); public function setOrder(Order $order);
/** /**
* @throws InvalidArgumentException
* @return Order * @return Order
*/ */
public function getOrder(); public function getOrder();

View File

@ -1,7 +1,7 @@
[{assign var="defaultPagePadding" value=","|explode:"45,15,25,25"}] [{* top, right, bottom, left *}] [{assign var="defaultPagePadding" value=","|explode:"45,15,25,25"}] [{* top, right, bottom, left *}]
[{assign var="pagePadding" value=$pagePadding|default:$defaultPagePadding}] [{assign var="pagePadding" value=$pagePadding|default:$defaultPagePadding}]
<style type="text/css"> <style>
.marks { .marks {
position: absolute; position: absolute;
left: [{math equation="left - padding" left=5 padding=$pagePadding.3}]mm ; left: [{math equation="left - padding" left=5 padding=$pagePadding.3}]mm ;

View File

@ -4,7 +4,7 @@
[{* rulers *}] [{* rulers *}]
[{* include file="d3pdfrulers.tpl" pagePadding=$pagePadding *}] [{* include file="d3pdfrulers.tpl" pagePadding=$pagePadding *}]
<style type="text/css"> <style>
.rulerItemHorizontal { .rulerItemHorizontal {
position: absolute; position: absolute;
top: -[{$pagePadding.0}]mm; top: -[{$pagePadding.0}]mm;

View File

@ -4,7 +4,7 @@
[{assign var="defaultPagePadding" value=","|explode:"45,15,25,25"}] [{* top, right, bottom, left *}] [{assign var="defaultPagePadding" value=","|explode:"45,15,25,25"}] [{* top, right, bottom, left *}]
[{assign var="pagePadding" value=$pagePadding|default:$defaultPagePadding}] [{assign var="pagePadding" value=$pagePadding|default:$defaultPagePadding}]
<style type="text/css"> <style>
[{foreach from=$pdfBlock_style item="_block"}] [{foreach from=$pdfBlock_style item="_block"}]
[{$_block}] [{$_block}]
[{/foreach}] [{/foreach}]

View File

@ -11,11 +11,9 @@
namespace D3\PdfDocuments\Modules\Application\Controller; namespace D3\PdfDocuments\Modules\Application\Controller;
use D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator; use D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException; use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException;
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview; use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments;
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview; use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\DatabaseProvider; use OxidEsales\Eshop\Core\DatabaseProvider;
@ -45,12 +43,11 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu
$viewNameGenerator = Registry::get(TableViewNameGenerator::class); $viewNameGenerator = Registry::get(TableViewNameGenerator::class);
$sTable = $viewNameGenerator->getViewName("oxorderarticles"); $sTable = $viewNameGenerator->getViewName("oxorderarticles");
$sQ = "select count(oxid) from {$sTable} where oxorderid = " . $masterDb->quote($sOrderId) . " and oxstorno = 0"; $sQ = "select count(oxid) from $sTable where oxorderid = " . $masterDb->quote($sOrderId) . " and oxstorno = 0";
return (bool) $masterDb->getOne($sQ); return (bool) $masterDb->getOne($sQ);
} }
/** /**
* @throws noBaseObjectSetException
* @throws noPdfHandlerFoundException * @throws noPdfHandlerFoundException
* @throws pdfGeneratorExceptionAbstract * @throws pdfGeneratorExceptionAbstract
*/ */
@ -58,7 +55,7 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu
{ {
$soxId = $this->getEditObjectId(); $soxId = $this->getEditObjectId();
if ($soxId != "-1" && isset($soxId)) { if ($soxId != "-1" && isset($soxId)) {
/** @var d3_Order_PdfDocuments $oOrder */ /** @var Order $oOrder */
$oOrder = oxNew(Order::class); $oOrder = oxNew(Order::class);
if ($oOrder->load($soxId)) { if ($oOrder->load($soxId)) {
$generator = oxNew( orderOverviewPdfGenerator::class ); $generator = oxNew( orderOverviewPdfGenerator::class );

View File

@ -4,7 +4,7 @@
PDF-Dokumentgenerator für OXID eShop PDF-Dokumentgenerator für OXID eShop
Erstellen Sie unterschiedlichste statische oder dynamische PDF-Dokument auf Kopfdruck. Der Dokumentinhalt wird aus Smartytemplates erstellt. Erstellen Sie unterschiedliche statische oder dynamische PDF-Dokumente auf Kopfdruck. Der Dokumentinhalt wird aus Smartytemplates erstellt.
An den Bestellungen Ihres OXID-Shops steht Ihnen die Erstellung von Rechnung und Lieferschein zur Verfügung. An den Bestellungen Ihres OXID-Shops steht Ihnen die Erstellung von Rechnung und Lieferschein zur Verfügung.

View File

@ -34,7 +34,8 @@
"php": "^7.0 || ^8.0", "php": "^7.0 || ^8.0",
"oxid-esales/oxideshop-ce": "6.3 - 6.14", "oxid-esales/oxideshop-ce": "6.3 - 6.14",
"spipu/html2pdf": "^5.2", "spipu/html2pdf": "^5.2",
"d3/modcfg": "^5.3.6.000 || ^6" "d3/modcfg": "^5.3.6.000 || ^6",
"beberlei/assert": "^3.3.2"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -31,7 +31,7 @@ $aModule = [
'version' => '1.0.3.1', 'version' => '1.0.3.1',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)', 'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com', 'email' => 'support@shopmodule.com',
'url' => 'http://www.oxidmodule.com/', 'url' => 'https://www.oxidmodule.com/',
'extend' => [ 'extend' => [
OrderOverview::class => d3_overview_controller_pdfdocuments::class OrderOverview::class => d3_overview_controller_pdfdocuments::class
], ],