2017-12-20 13:43:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Ordermanager\Modules\Application\Model;
|
|
|
|
|
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager;
|
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager_pdfhandler;
|
2019-05-15 11:31:18 +02:00
|
|
|
use Exception;
|
|
|
|
use InvoicepdfPDF;
|
|
|
|
use oxArticleInputException;
|
2017-12-20 13:43:20 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Application\Model\OrderArticle;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Basket;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Payment;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Voucher;
|
2018-01-11 11:45:22 +01:00
|
|
|
use OxidEsales\Eshop\Core\Exception\ArticleException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\ArticleInputException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\NoArticleException;
|
2017-12-20 13:43:20 +01:00
|
|
|
use OxidEsales\Eshop\Core\Model\ListModel;
|
2019-05-15 11:31:18 +02:00
|
|
|
use oxNoArticleException;
|
2017-12-20 13:43:20 +01:00
|
|
|
|
|
|
|
class d3_oxorder_ordermanager extends d3_oxorder_ordermanager_parent
|
|
|
|
{
|
2019-05-15 11:31:18 +02:00
|
|
|
/** @var Payment */
|
|
|
|
protected $_oPayment = null;
|
2017-12-20 13:43:20 +01:00
|
|
|
protected $_iSelectedLang;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $sName
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get($sName)
|
|
|
|
{
|
|
|
|
$mContent = parent::__get($sName);
|
|
|
|
|
|
|
|
if (false == $mContent && $this->{$sName}) {
|
|
|
|
return $this->{$sName};
|
|
|
|
}
|
|
|
|
|
|
|
|
return $mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Basket $oBasket
|
|
|
|
*/
|
|
|
|
public function d3setBasket4OrderManager(Basket $oBasket)
|
|
|
|
{
|
|
|
|
$this->_oBasket = $oBasket;
|
|
|
|
}
|
|
|
|
|
2019-05-15 11:31:18 +02:00
|
|
|
/**
|
|
|
|
* @return Basket
|
|
|
|
*/
|
|
|
|
public function d3getBasket4OrderManager()
|
|
|
|
{
|
|
|
|
return $this->_oBasket;
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:43:20 +01:00
|
|
|
/**
|
|
|
|
* @param Payment $oPayment
|
|
|
|
*/
|
|
|
|
public function d3setPayment4OrderManager(Payment $oPayment)
|
|
|
|
{
|
|
|
|
$this->_oPayment = $oPayment;
|
|
|
|
}
|
|
|
|
|
2019-05-15 11:31:18 +02:00
|
|
|
/**
|
|
|
|
* @return Payment
|
|
|
|
*/
|
|
|
|
public function d3getPayment4OrderManager()
|
|
|
|
{
|
|
|
|
return $this->_oPayment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Voucher
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function d3GetVoucher()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Voucher::class);
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:43:20 +01:00
|
|
|
/**
|
|
|
|
* @param d3ordermanager $oOrderManager
|
|
|
|
* @return Basket
|
2018-01-11 11:45:22 +01:00
|
|
|
* @throws ArticleException
|
|
|
|
* @throws ArticleInputException
|
|
|
|
* @throws NoArticleException
|
2019-05-15 11:31:18 +02:00
|
|
|
* @throws oxArticleInputException
|
|
|
|
* @throws oxNoArticleException
|
|
|
|
* @throws Exception
|
2017-12-20 13:43:20 +01:00
|
|
|
*/
|
|
|
|
public function d3getOrderBasket4OrderManager(d3ordermanager $oOrderManager)
|
|
|
|
{
|
|
|
|
$this->reloadDelivery(false);
|
|
|
|
// reload discount to true, because there is no voucher list in basket
|
|
|
|
$this->reloadDiscount(true);
|
|
|
|
/** @var $oBasket d3_oxbasket_ordermanager */
|
|
|
|
$oBasket = $this->_getOrderBasket(false);
|
|
|
|
|
|
|
|
/** @var $oOrderArticles ListModel */
|
|
|
|
if ($oOrderManager->getValue('blGetStornoArticles')) {
|
|
|
|
$oOrderArticles = $this->getOrderArticles(false);
|
|
|
|
} else {
|
|
|
|
$oOrderArticles = $this->getOrderArticles(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no order articles, return empty basket
|
|
|
|
if ($oOrderArticles->count() > 0) {
|
|
|
|
//adding order articles to basket
|
|
|
|
/** @var OrderArticle $oOrderArticle */
|
|
|
|
foreach ($oOrderArticles as $oOrderArticle) {
|
|
|
|
$oBasket->addOrderArticleToBasket4OrderManager($oOrderArticle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$oBasket->calculateBasket4OrderManager(true, $this);
|
|
|
|
|
|
|
|
$this->_aVoucherList = $oBasket->getVouchers();
|
|
|
|
foreach (array_keys($this->_aVoucherList) as $sKey) {
|
2019-05-15 11:31:18 +02:00
|
|
|
$oVoucher = $this->d3GetVoucher();
|
2017-12-20 13:43:20 +01:00
|
|
|
$oVoucher->load($sKey);
|
|
|
|
$this->_aVoucherList[$sKey] = $oVoucher;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $oBasket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-15 11:31:18 +02:00
|
|
|
* @return d3ordermanager_pdfhandler
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function d3GetPdfHandler()
|
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->set(
|
|
|
|
d3ordermanager_pdfhandler::class.'.args.ordermanager',
|
|
|
|
d3GetModCfgDIC()->get(d3ordermanager::class)
|
|
|
|
);
|
|
|
|
d3GetModCfgDIC()->set(
|
|
|
|
d3ordermanager_pdfhandler::class.'.args.order',
|
|
|
|
d3GetModCfgDIC()->get('d3ox.ordermanager.'.Order::class)
|
|
|
|
);
|
|
|
|
|
|
|
|
return d3GetModCfgDIC()->get(d3ordermanager_pdfhandler::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return InvoicepdfPDF
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function d3GetInvoicePdf()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.InvoicepdfPDF::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sFilename
|
|
|
|
* @param int $iSelLang
|
2017-12-20 13:43:20 +01:00
|
|
|
* @param string $sDocType
|
|
|
|
* @param string $sDestination
|
2019-05-15 11:31:18 +02:00
|
|
|
* @return null|string
|
|
|
|
* @throws Exception
|
2017-12-20 13:43:20 +01:00
|
|
|
*/
|
|
|
|
public function d3generatePdf($sFilename, $iSelLang = 0, $sDocType = 'invoice', $sDestination = 'S')
|
|
|
|
{
|
|
|
|
// setting pdf language
|
|
|
|
$this->_iSelectedLang = $iSelLang;
|
|
|
|
|
|
|
|
// setting invoice number
|
|
|
|
if (!$this->getFieldData('oxbillnr')) {
|
|
|
|
$this->_setFieldData('oxbillnr', $this->getNextBillNum());
|
|
|
|
$this->_setFieldData('oxbilldate', date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))));
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
|
2019-05-15 11:31:18 +02:00
|
|
|
$oPdfHandler = $this->d3GetPdfHandler();
|
2017-12-20 13:43:20 +01:00
|
|
|
if ($oPdfHandler->canGeneratePdf()) {
|
|
|
|
|
2019-05-15 11:31:18 +02:00
|
|
|
$oPdf = $this->d3GetInvoicePdf();
|
2017-12-20 13:43:20 +01:00
|
|
|
$oPdf->setPrintHeader(false);
|
2019-05-15 11:31:18 +02:00
|
|
|
$oPdf->Open();
|
2017-12-20 13:43:20 +01:00
|
|
|
|
|
|
|
// adding header
|
|
|
|
$this->pdfHeader($oPdf);
|
|
|
|
|
|
|
|
// adding info data
|
|
|
|
switch ($sDocType) {
|
|
|
|
case 'dnote':
|
|
|
|
$this->exportDeliveryNote($oPdf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->exportStandart($oPdf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// adding footer
|
|
|
|
$this->pdfFooter($oPdf);
|
|
|
|
|
|
|
|
// outputting file to browser
|
2019-05-15 11:31:18 +02:00
|
|
|
return $oPdf->Output($sFilename, $sDestination);
|
2017-12-20 13:43:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|