public function saveInvoiceFile(Document $invoice) { require "vendor/autoload.php"; // inhibit DOMPDF's auto-loader define('DOMPDF_ENABLE_AUTOLOAD', false); //include the DOMPDF config file (required) require 'vendor/dompdf/dompdf/dompdf_config.inc.php'; //if you get errors about missing classes please also add: require_once 'vendor/dompdf/dompdf/include/autoload.inc.php'; $docType = $invoice instanceof Document\Invoice ? Document\Invoice::TYPE_INVOICE : Document\Invoice::TYPE_CREDIT_INVOICE; try { $renderer = $this->locator->get('Zend\\View\\Renderer\\PhpRenderer'); $renderer->setVars(array('document' => $invoice, 'rows' => $invoice->getRows())); $rendered = $renderer->render('application/document/pdf/invoice'); if ($rendered) { $output_document_dir = "data/files/Document/"; $output_customer_dir = "data/files/Customer/"; $fileNameDocument = $invoice->getId() . '_' . $invoice->getPrefix() . $invoice->getDocumentNumber() . '.pdf'; $fileNameCustomer = $invoice->getCustomer()->getId() . '_' . $invoice->getPrefix() . $invoice->getDocumentNumber() . '.pdf'; $dompdf = new \DOMPDF(); $dompdf->load_html($rendered); $dompdf->render(); $output = $dompdf->output(); file_put_contents($output_document_dir . $fileNameDocument, $output); file_put_contents($output_customer_dir . $fileNameCustomer, $output); $size = filesize($output_document_dir . $fileNameDocument); $type = filetype($output_document_dir . $fileNameDocument); $this->addDocumentFile($invoice, $output_document_dir, $fileNameDocument, $type, $size, $docType); $this->customerService->addCustomerFile($invoice->getCustomer(), $invoice, $output_customer_dir, $fileNameCustomer, $type, $size, $docType); } } catch (\Exception $e) { print_r($e->getMessage()); die; } }
public function setFormValues(Document $document = null) { if ($document) { $this->get('deadlineDays')->setValue($document->getDeadlineDays()); $this->get('delayPercent')->setValue($document->getDelayPercent()); if ($document instanceof Document\PurchaseInvoice) { $this->get('supplierDocNumber')->setValue($document->getSupplierDocumentNumber()); } $this->get('amount')->setValue($document->getAmount()); $this->get('taxAmount')->setValue($document->getTaxAmount()); $this->get('amountTax')->setValue($document->getAmountTax()); $this->get('comment')->setValue($document->getComment()); $this->get('paymentType')->setValue($document->getPaymentType()); if ($document->getDocumentDate()) { $this->get('docDate')->setValue($document->getDocumentDate()->format('d.m.Y')); } if ($document->getCustomer()) { $this->get('customer')->setValue($document->getCustomer()->getId()); } if ($document->getSupplier()) { $this->get('supplier')->setValue($document->getSupplier()->getId()); } if ($document->getVat()) { $this->get('vat')->setValue($document->getVat()->getId()); } } }