'_doGenerate', ); protected $_serverIp = '127.0.0.1'; protected $_serverPort = '8767'; public function InvoiceImportGrid($Doc, $DBObj) { parent::DB_Grid(&$Doc, &$DBObj); } protected function _doGenerate() { if ($this->DBObj->setId()) { $invoiceRecords = $this->DBObj->getInvoiceRecords(); $totalAmount = 0; foreach($invoiceRecords as $invoiceRecord) { $totalAmount += $invoiceRecord['unit_price'] * $invoiceRecord['quantity']; } $this->Doc->addContent(array( 'tpl' => 'Invoice/invoice.tpl', 'invoiceRecords' => $invoiceRecords, 'totalAmount' => $totalAmount, 'paymentTerms' => $_REQUEST['payment_terms'], 'invoiceTitle' => $_REQUEST['invoice_title'], 'dueDate' => strtoupper(date('F j, Y', mktime(0, 0, 0, $_REQUEST['due_date_month'], $_REQUEST['due_date_day'], $_REQUEST['due_date_year']))) )); $html = $this->Doc->fetch('Doc/pdf_page.tpl'); $pdfRender = new Html2Pdf_Render( array('renderlinks' => true), array('type' => 'memory', 'content' => $html), array('type' => 'file', 'name' => BASE_PATH . "/tmp/tmpinvoice.pdf", 'width' => 900, 'margins' => array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0))); if (count($pdfRender->errors) || !$pdfRender->render()) { sendDeveloperEmail('PDF Generating Error', $pdfRender->errors); } else { if (!is_object($this->tableFile)) { require_once('class/DB/DBTable.php'); $this->tableFile = new DBTable('zz_File'); } if (!is_object($this->tableInvoice)) { require_once('class/DB/DBTable.php'); $this->tableInvoice = new DBTable('Invoice'); } $fileName = "invoice-{$invoiceRecords[0]['sop_number']}.pdf"; $fileId = $this->tableFile->insert(array( 'name' => $fileName, 'title' => $fileName, 'size' => filesize(BASE_PATH . "/tmp/tmpinvoice.pdf"), 'type' => 'application/pdf' )); $fileName = "invoice-{$invoiceRecords[0]['sop_number']}({$fileId}).pdf"; $this->tableFile->update(array('name' => $fileName), 'id = ' . $fileId); rename(BASE_PATH . "/tmp/tmpinvoice.pdf", WWW_PATH . "/userfile/{$fileName}"); $invoiceData = array( 'number' => $invoiceRecords[0]['sop_number'], 'amount' => $totalAmount, 'attachment' => $fileName, 'date_due' => (int)$_REQUEST['due_date_year'] . '-' . $_REQUEST['due_date_month'] . '-' . $_REQUEST['due_date_day'] ); if ($invoiceRecords[0]['type'] == 'exchange') { $invoiceData['id_location'] = $invoiceRecords[0]['customer_id']; } else { $invoiceData['id_member'] = $invoiceRecords[0]['customer_id']; } $this->tableInvoice->insert($invoiceData); } $this->DBObj->clearInvoiceRecords(); die('CONTINUE'); } else { die('DONE'); } } } ?>