Files
kupshop/bundles/External/HannahBundle/Attachment/SAPInvoicePDFAttachment.php
2025-08-02 16:30:27 +02:00

41 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace External\HannahBundle\Attachment;
use External\HannahBundle\Util\InvoiceUtil;
use KupShop\OrderingBundle\Attachment\BaseAttachment;
use KupShop\OrderingBundle\Exception\InvoiceException;
class SAPInvoicePDFAttachment extends BaseAttachment
{
protected static $name = 'SAP Faktura';
protected static $type = 'sap_order_invoice';
protected $filename = 'Faktura_{KOD}.pdf';
/** @var InvoiceUtil */
private $invoiceUtil;
/** @required */
public function setInvoiceUtil(InvoiceUtil $invoiceUtil): void
{
$this->invoiceUtil = $invoiceUtil;
}
public function getFilename(): string
{
return $this->order->replacePlaceholders(translate_shop('invoice_filename', 'attachments'));
}
public function getContent()
{
if ($invoiceNumber = $this->order->getData('sapInvoiceNumber')) {
return $this->invoiceUtil->getInvoicePDFContent($invoiceNumber, $this->order->getLanguage());
}
throw new InvoiceException("Nelze vytisknout SAP fakturu - objednávka (ID {$this->order->id}) ještě nebyla fakturována (chybí idoc).");
}
}