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

View File

@ -10,9 +10,10 @@
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 \OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
@ -22,6 +23,14 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/** @var Order */
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
*/
@ -31,15 +40,22 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
}
/**
* @throws InvalidArgumentException
* @return Order
*/
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;
}
/**
* @param int $iSelLang
* @throws InvalidArgumentException
*/
public function setSmartyVars($iSelLang)
{
@ -58,6 +74,7 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/**
* @return string
* @throws InvalidArgumentException
*/
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
*/
@ -115,6 +117,7 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
/**
* @return false|string
* @throws InvalidArgumentException
*/
public function getPayableUntilDate()
{

View File

@ -10,10 +10,9 @@
namespace D3\PdfDocuments\Application\Model\Documents;
use Assert\InvalidArgumentException;
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface;
use Spipu\Html2Pdf\Exception\Html2PdfException;
class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceInterface
{
@ -43,6 +42,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
return 'invoice';
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function runPreAction()
{
parent::runPreAction();
@ -52,6 +55,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
$this->saveOrderOnChanges();
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceNumber()
{
if (!$this->getOrder()->getFieldData('oxbillnr')) {
@ -61,6 +68,10 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
}
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceDate()
{
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()
{
if ($this->blIsNewOrder) {
@ -85,6 +100,7 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
/**
* @return string
* @throws InvalidArgumentException
*/
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;
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
interface pdfdocumentsGenericInterface
{
/**
@ -58,7 +56,6 @@ interface pdfdocumentsGenericInterface
* @param string $target
*
* @return mixed
* @throws noBaseObjectSetException
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I');

View File

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

View File

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

View File

@ -4,7 +4,7 @@
[{* rulers *}]
[{* include file="d3pdfrulers.tpl" pagePadding=$pagePadding *}]
<style type="text/css">
<style>
.rulerItemHorizontal {
position: absolute;
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="pagePadding" value=$pagePadding|default:$defaultPagePadding}]
<style type="text/css">
<style>
[{foreach from=$pdfBlock_style item="_block"}]
[{$_block}]
[{/foreach}]

View File

@ -11,11 +11,9 @@
namespace D3\PdfDocuments\Modules\Application\Controller;
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\pdfGeneratorExceptionAbstract;
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\Model\Order;
use OxidEsales\Eshop\Core\DatabaseProvider;
@ -45,12 +43,11 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu
$viewNameGenerator = Registry::get(TableViewNameGenerator::class);
$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);
}
/**
* @throws noBaseObjectSetException
* @throws noPdfHandlerFoundException
* @throws pdfGeneratorExceptionAbstract
*/
@ -58,7 +55,7 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu
{
$soxId = $this->getEditObjectId();
if ($soxId != "-1" && isset($soxId)) {
/** @var d3_Order_PdfDocuments $oOrder */
/** @var Order $oOrder */
$oOrder = oxNew(Order::class);
if ($oOrder->load($soxId)) {
$generator = oxNew( orderOverviewPdfGenerator::class );

View File

@ -4,7 +4,7 @@
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.

View File

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

View File

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