* @copyright 2021 Keshva * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ if (!defined('_PS_VERSION_')) exit; require_once(_PS_MODULE_DIR_.'modrefchange/classes/DocumentReferences.php'); class PDF extends PDFCore { private static function loadDocumentReferences() { if (!class_exists('DocumentReferences')) { require_once(_PS_MODULE_DIR_.'modrefchange/classes/DocumentReferences.php'); } } public function render($display = true) { self::loadDocumentReferences(); $render = false; $this->pdf_renderer->setFontForLang(Context::getContext()->language->iso_code); foreach ($this->objects as $object) { if (version_compare(_PS_VERSION_, '1.6.1.4', '>')) $this->pdf_renderer->startPageGroup(); $template = $this->getTemplateObject($object); if (!$template) { continue; } if (empty($this->filename)) { $this->filename = $template->getFilename(); if ($template instanceof HTMLTemplateInvoice && $object instanceof OrderInvoice) { if ($result = DocumentReferences::getReference($object->id, 'invoice')) { $template->title = $result['reference']; $this->filename = $result['reference'].'.pdf'; $orderNote = $this->getOrderNote($object->id_order); $template->order_invoice->note .= ($orderNote['show_on_invoice'] ? $orderNote['note'] : ''); } } else if ($template instanceof HTMLTemplateDeliverySlip && $object instanceof OrderInvoice) { if ($result = DocumentReferences::getReference($object->id, 'delivery_slip')) { $template->title = $result['reference']; $this->filename = $result['reference'].'.pdf'; } } else if ($object instanceof OrderSlip) { if ($result = DocumentReferences::getReference($object->id, 'credit_slip')) { $template->title = $result['reference']; $this->filename = $result['reference'].'.pdf'; } } if (count($this->objects) > 1) { $this->filename = $template->getBulkFilename(); } } if ($result = DocumentReferences::getReference($object->id, 'credit_slip')) { $template->title = $result['reference']; $this->filename = $result['reference'].'.pdf'; } $template->assignHookData($object); $this->pdf_renderer->createHeader($template->getHeader()); $this->pdf_renderer->createFooter($template->getFooter()); if (version_compare(_PS_VERSION_, '1.6.1.4', '>')) $this->pdf_renderer->createPagination($template->getPagination()); $this->pdf_renderer->createContent($template->getContent()); $this->pdf_renderer->writePage(); $render = true; unset($template); } if ($render) { // clean the output buffer if (ob_get_level() && ob_get_length() > 0) { ob_clean(); } return $this->pdf_renderer->render($this->filename, $display); } } private function getOrderNote($idOrder) { $orderNote = array( 'note' => '', 'show_on_invoice' => false ); if ($row = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'order_note WHERE id_order = '.(int)$idOrder)) { $orderNote = array( 'note' => $row['note'], 'show_on_invoice' => ((int)$row['show_on_invoice'] == 1) ); } return $orderNote; } }