From 35c95344075f0c63ab60d268abfd2f75a2502513 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 16 Aug 2011 10:36:48 +1000 Subject: [PATCH] Invoice PDF generation working --- controllers/documents_controller.php | 6 ++ vendors/pdfdoc.php | 7 +- views/documents/pdf_invoice.ctp | 73 ++++++++++++++++++++ views/documents/pdf_order_ack.ctp | 0 views/documents/{pdf.ctp => pdf_quote.ctp} | 1 - views/elements/document_invoice_view.ctp | 6 +- views/elements/line_items_table.ctp | 5 +- views/elements/pdf_document_data_payment.ctp | 0 views/elements/pdf_shipping_billing_box.ctp | 57 +++++++++++++++ 9 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 views/documents/pdf_invoice.ctp create mode 100644 views/documents/pdf_order_ack.ctp rename views/documents/{pdf.ctp => pdf_quote.ctp} (99%) create mode 100644 views/elements/pdf_document_data_payment.ctp create mode 100644 views/elements/pdf_shipping_billing_box.ctp diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 4bec3a4f..c53ba0cf 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -436,6 +436,7 @@ class DocumentsController extends AppController { $this->set('principlesList', $this->Document->LineItem->Product->Principle->find('list')); $this->set('products', $document['LineItem']); + $this->set('states', $this->Document->Invoice->Enquiry->State->find('list')); //Set filename for the document. @@ -443,10 +444,13 @@ class DocumentsController extends AppController { switch($docType) { case "quote": $filename = $enquiry['Enquiry']['title']; + $template_name = 'pdf_quote'; break; case "invoice": $filename = $document['Invoice']['title']; + $this->set('job', $this->Document->Invoice->Job->find('first', array('conditions'=>array('Job.id'=>$document['Invoice']['job_id'])))); + $template_name = 'pdf_invoice'; break; case "purchaseOrder": @@ -487,6 +491,8 @@ class DocumentsController extends AppController { ); $this->set('colWidths',$colWidths); + + $this->render($template_name); } diff --git a/vendors/pdfdoc.php b/vendors/pdfdoc.php index 7ee5b5a4..f29b9b83 100644 --- a/vendors/pdfdoc.php +++ b/vendors/pdfdoc.php @@ -92,7 +92,7 @@ ENDHTML; } - + /** * For Quotes and (hopefully) Invoices. Identifies who the document is for, date, reference number, etc. */ @@ -101,7 +101,7 @@ ENDHTML; $pageNo = $this->PageNoFormatted(); $totalCount = $this->getAliasNbPages(); - + $col1width = '20%'; $col2width = '30%'; $col3width = $col1width; @@ -160,13 +160,14 @@ ENDTABLE; } + function header() { //$this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 15, 13.6, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L'); $this->SetFontSize(10); $pageNo = $this->PageNoFormatted(); $totalCount = $this->getAliasNbPages(); - + //$currentX = $this->GetX(); diff --git a/views/documents/pdf_invoice.ctp b/views/documents/pdf_invoice.ctp new file mode 100644 index 00000000..f0bdecd0 --- /dev/null +++ b/views/documents/pdf_invoice.ctp @@ -0,0 +1,73 @@ +SetPrintHeader(false); +$pdfdoc->SetPrintFooter(false); + + +$pdfdoc->AddPage(); +$pdfdoc->Page1Header(); + +$pageTitle = "

TAX INVOICE

"; +$pdfdoc->writeHTML($pageTitle, true, false, false, false, 'C'); + +$pdfdoc->SetTextColor(0); +$shippingBillingBox = $this->element('pdf_shipping_billing_box'); + +$pdfdoc->writeHTML($shippingBillingBox, false); + +$LineItemTable = $this->element('line_items_table'); +$pdfdoc->SetPrintHeader(true); + +$pdfdoc->pageContent($LineItemTable); +$pdfdoc->lastPage(); + +if($docType == 'quote') { + + $commercialComments = '
'.$document['Quote']['commercial_comments'].'
'; + $pdfdoc->pageContent($commercialComments); +} + + +$output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/'; + +$debuglevel = Configure::read('debug'); + +if($debuglevel == 0) { + $output_dir = '/var/www/cakephp/app/webroot/pdf/'; +} + + +$pdfdoc->Output($output_dir.$filename, 'F'); + +echo "
Wrote: ".$output_dir.$filename; + +App::import('Vendor', 'xfpdi'); + + +//$newpdf = new concat_pdf(); + +$newpdf = new XFPDI(); + +$newpdf->SetMargins(2, 2); +$newpdf->setPrintHeader(false); +$newpdf->setPrintFooter(false); + +$newpdf->setFiles(array($output_dir.$filename, $output_dir.'CMC_terms_and_conditions2006_A4.pdf')); +$newpdf->concat(); +$newpdf->Output($output_dir.$filename, "F"); +//$pdfdoc->Output($output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/'.'example_060.pdf', 'F'); + +//echo $html->link($filename, '/pdf/'.$filename); + +?> + + + + + + \ No newline at end of file diff --git a/views/documents/pdf_order_ack.ctp b/views/documents/pdf_order_ack.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/documents/pdf.ctp b/views/documents/pdf_quote.ctp similarity index 99% rename from views/documents/pdf.ctp rename to views/documents/pdf_quote.ctp index 58ba8950..73a4db2f 100755 --- a/views/documents/pdf.ctp +++ b/views/documents/pdf_quote.ctp @@ -9,7 +9,6 @@ $pdfdoc->SetPrintFooter(false); $firstPageDone = false; - $companyName = $enquiry['Customer']['name']; $emailTo = $enquiry['Contact']['email']; $attention = $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name']; diff --git a/views/elements/document_invoice_view.ctp b/views/elements/document_invoice_view.ctp index f0f76a64..280ee8c5 100644 --- a/views/elements/document_invoice_view.ctp +++ b/views/elements/document_invoice_view.ctp @@ -8,9 +8,9 @@ echo $form->input('Document.id');
- - - link('Generate PDF of this Quote', '/documents/pdf/'.$document['Document']['id']);?> + + + link('Generate PDF of this Invoice', '/documents/pdf/'.$document['Document']['id']);?>
diff --git a/views/elements/line_items_table.ctp b/views/elements/line_items_table.ctp index c342cf7a..d94b8afb 100644 --- a/views/elements/line_items_table.ctp +++ b/views/elements/line_items_table.ctp @@ -55,6 +55,9 @@ + + + @@ -102,5 +105,5 @@ } ?> - + diff --git a/views/elements/pdf_document_data_payment.ctp b/views/elements/pdf_document_data_payment.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/elements/pdf_shipping_billing_box.ctp b/views/elements/pdf_shipping_billing_box.ctp new file mode 100644 index 00000000..964e9f84 --- /dev/null +++ b/views/elements/pdf_shipping_billing_box.ctp @@ -0,0 +1,57 @@ + + + + + + + + + + + + +
BILL TO:SHIP TO: + CMC INVOICE#: CMCIN4745
+ Date:

+ MAKE PAYMENT TO:
+ Account Name: CMC Technologies Pty Ltd
+ Bank Number BSB#: 062-458
+ Account Number: 10067982
+ SWIFT Code: CTBAAU2S +
+
+
+
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
CUSTOMER ORDER NOCMC JOB #FOBSHIP VIATERMSCUSTOMER ABN
????element('abn', array('abn'=>$job['Customer']['abn']));?>
\ No newline at end of file