pdfdokumente/Application/Model/Documents/invoicePdf.php

117 regels
2.6 KiB
PHP

<?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;
use Assert\InvalidArgumentException;
2020-05-30 01:17:27 +02:00
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface;
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';
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function runPreAction()
{
parent::runPreAction();
$this->setInvoiceNumber();
$this->setInvoiceDate();
$this->saveOrderOnChanges();
}
/**
* @return void
* @throws InvalidArgumentException
*/
2020-05-26 16:32:22 +02:00
public function setInvoiceNumber()
{
if (!$this->getOrder()->getFieldData('oxbillnr')) {
$this->getOrder()->assign(['oxbillnr' => $this->getOrder()->getNextBillNum()]);
$this->blIsNewOrder = true;
}
}
/**
* @return void
* @throws InvalidArgumentException
*/
2020-05-26 16:32:22 +02:00
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;
}
}
/**
* @return void
* @throws InvalidArgumentException
*/
2020-05-26 16:32:22 +02:00
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
* @throws InvalidArgumentException
*/
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);
}
}