/** * Render the invoice. * * @return mixed */ public function render() { // libs TinyButStrong include_once 'TinyButStrong/tinyButStrong.class.php'; include_once 'TinyButStrong/tinyDoc.class.php'; $doc = new tinyDoc(); // use zip extension if available if (class_exists('ZipArchive')) { $doc->setZipMethod('ziparchive'); } else { $doc->setZipMethod('shell'); try { $doc->setZipBinary('zip'); $doc->setUnzipBinary('unzip'); } catch (tinyDocException $e) { $doc->setZipMethod('pclzip'); } } $doc->setProcessDir($this->getTemporaryDirectory()); //This is where the template is selected $templateform = $this->getTemplateDir() . $this->getTemplateFile(); $doc->createFrom($templateform); $doc->loadXml('content.xml'); // fetch variables from model to get values $customer = $this->getModel()->getCustomer(); $projects = $this->getModel()->getProjects(); $entries = $this->getModel()->getEntries(); // assign all available variables (which are not arrays as they do not work in tinyButStrong) foreach ($this->getModel()->toArray() as $k => $v) { if (is_array($v)) { continue; } $GLOBALS[$k] = $v; } // ugly but neccessary for tinyButStrong // set globals variables, so they can be used in invoice templates $allCustomer = $this->prepareCustomerArray($customer); foreach ($allCustomer as $k => $v) { $GLOBALS[$k] = $v; } $GLOBALS['projects'] = $projects; $GLOBALS['project'] = implode(', ', array_map(function ($project) { return $project['name']; }, $projects)); $doc->mergeXmlBlock('row', $entries); $doc->saveXml(); $doc->close(); // send and remove the document $doc->sendResponse(); $doc->remove(); }
} $vat_rate = $kndArray['knd_vat']; if (!is_numeric($vat_rate)) { $vat_rate = $kga['conf']['defaultVat']; } $vat = $vat_rate * $gtotal / 100; $total = $gtotal - $vat; $doc = new tinyDoc(); // use zip extension if available if (class_exists('ZipArchive')) { $doc->setZipMethod('ziparchive'); } else { $doc->setZipMethod('shell'); try { $doc->setZipBinary('zip'); $doc->setUnzipBinary('unzip'); } catch (tinyDocException $e) { $doc->setZipMethod('pclzip'); } } $doc->setProcessDir('../../temporary'); //This is where the template is selected $templateform = "templates/" . $_REQUEST['ivform_file']; $doc->createFrom($templateform); $doc->loadXml('content.xml'); $doc->mergeXmlBlock('row', $invoiceArray); $doc->saveXml(); $doc->close(); // send and remove the document $doc->sendResponse(); $doc->remove();