pdfdokumente/Application/Model/Documents/invoicePdf.php

112 lignes
2.7 KiB
PHP
Brut Vue normale Historique

<?php
/**
2020-07-04 23:25:24 +02:00
* See LICENSE file for license details.
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2020-07-04 23:25:24 +02:00
* @author D3 Data Development - Max Buhe <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
2020-05-28 13:32:34 +02:00
namespace D3\PdfDocuments\Application\Model\Documents;
2020-05-30 01:17:27 +02:00
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
2020-05-30 00:48:43 +02:00
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
2020-05-30 01:17:27 +02:00
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface;
2020-06-09 14:56:14 +02:00
use Spipu\Html2Pdf\Exception\Html2PdfException;
2020-05-26 16:12:17 +02:00
2020-05-30 01:17:27 +02:00
class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceInterface
{
2020-05-26 16:32:22 +02:00
protected $blIsNewOrder = false;
2020-05-30 00:48:43 +02:00
/**
* @return string
*/
public function getRequestId()
{
2020-07-03 21:59:18 +02:00
return 'invoice';
2020-05-30 00:48:43 +02:00
}
/**
* @return string
*/
public function getTitleIdent()
{
2020-07-03 20:04:21 +02:00
return "D3_PDFDOCUMENTS_INVOICE";
2020-05-30 00:48:43 +02:00
}
/**
* @return string
*/
public function getTypeForFilename()
{
return 'invoice';
}
2020-05-30 00:48:43 +02:00
/**
2020-06-09 14:56:14 +02:00
* @param $sFilename
* @param int $iSelLang
2020-05-30 00:48:43 +02:00
* @param string $target
2020-06-09 14:56:14 +02:00
*
* @return mixed|string|void
* @throws Html2PdfException
2020-05-30 00:48:43 +02:00
* @throws noBaseObjectSetException
*/
public function genPdf( $sFilename, $iSelLang = 0, $target = 'I' )
{
$this->setInvoiceNumber();
$this->setInvoiceDate();
$this->saveOrderOnChanges();
2020-06-09 14:56:14 +02:00
return parent::genPdf( $sFilename, $iSelLang, $target );
}
2020-05-26 16:32:22 +02:00
public function setInvoiceNumber()
{
$this->blIsNewOrder = false;
if (!$this->getOrder()->getFieldData('oxbillnr')) {
$this->getOrder()->assign(['oxbillnr' => $this->getOrder()->getNextBillNum()]);
$this->blIsNewOrder = true;
}
}
public function setInvoiceDate()
{
if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') {
2020-06-04 11:04:17 +02:00
$this->getOrder()->assign([
"oxbilldate" => date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')))
]);
2020-05-26 16:32:22 +02:00
$this->blIsNewOrder = true;
}
}
public function saveOrderOnChanges()
{
if ($this->blIsNewOrder) {
$this->getOrder()->save();
}
}
2020-05-26 16:12:17 +02:00
public function getTemplate(){
return 'd3invoice_pdf.tpl';
2020-05-26 16:12:17 +02:00
}
/**
* @return string
*/
public function getFilename()
{
$filename = parent::getFilename();
2020-06-17 09:05:49 +02:00
$filename = str_replace(
$this->getOrder()->getFieldData('oxordernr'),
$this->getOrder()->getFieldData('oxbillnr'),
$filename
);
2020-06-17 09:05:49 +02:00
return $this->makeValidFileName($filename);
}
}