Invoice PDF generation working

This commit is contained in:
Karl Cordes 2011-08-16 10:36:48 +10:00
parent e400230c41
commit 35c9534407
9 changed files with 147 additions and 8 deletions

View file

@ -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);
}

7
vendors/pdfdoc.php vendored
View file

@ -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();

View file

@ -0,0 +1,73 @@
<?php
App::import('Vendor','pdfdoc');
$pdfdoc = new PDFDOC();
$pdfdoc->SetPrintHeader(false);
$pdfdoc->SetPrintFooter(false);
$pdfdoc->AddPage();
$pdfdoc->Page1Header();
$pageTitle = "<h1>TAX INVOICE</h1>";
$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 = '<div nobr="true">'.$document['Quote']['commercial_comments'].'</div>';
$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 "<br> 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);
?>
<script type="text/javascript">
//window.location.replace("/documents/view/<?=$document['Document']['id']?>");
</script>
<? debug($job); ?>
<? //debug($enquiry); ?>

View file

View file

@ -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'];

View file

@ -8,9 +8,9 @@ echo $form->input('Document.id');
<div class="docButtons">
<button id="generateFirstPage">(re)Generate First Page</button>
<button id="addPage">Add Content Page</button>
<button id="editQuoteDetails">View/Edit Quote Details</button>
<?=$html->link('Generate PDF of this Quote', '/documents/pdf/'.$document['Document']['id']);?>
<button id="editInvoiceDetails">View/Edit Invoice Details</button>
<?=$html->link('Generate PDF of this Invoice', '/documents/pdf/'.$document['Document']['id']);?>
</div>
<div id="flashMessage" class="message">

View file

@ -55,6 +55,9 @@
</td>
</tr>
<?endforeach;?>
</tbody>
<tfoot nobr="true">
<tr nobr="true">
<td width="<?=$colWidths['item'];?>"></td>
<td width="<?=$colWidths['qty'];?>"></td>
@ -102,5 +105,5 @@
}
?></td>
</tr>
</tbody>
</tfoot>
</table>

View file

@ -0,0 +1,57 @@
<?
$col1width = '30%';
$col2width = '30%';
$col3width = '30%';
?>
<table cellpadding="2" cellspacing="0" >
<tr>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">BILL TO:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">SHIP TO:</td>
<td style="width: 3%;"></td>
<td style="font-size: 9pt; width: 37%;" colspan="4" rowspan="2">
<span style="text-decoration: underline; font-size: 11pt">CMC INVOICE#: CMCIN4745</span><br>
<span style="text-decoration: none">Date: <?=$document['Invoice']['issue_date'];?></span><br><br>
<span style="text-decoration: underline">MAKE PAYMENT TO:</span><br>
<span style="text-decoration: none">Account Name: CMC Technologies Pty Ltd<br>
Bank Number BSB#: 062-458<br>
Account Number: 10067982<br>
SWIFT Code: CTBAAU2S
</span>
</td>
</tr>
<tr>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black">
<?=$enquiry['BillingAddress']['address'];?><br>
<?=$enquiry['BillingAddress']['city'];?><br>
<?=$enquiry['BillingAddress']['postcode'];?>
<?=strtoupper($states[$enquiry['BillingAddress']['state_id']]);?><br>
</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black">
<?=$enquiry['ShippingAddress']['address'];?><br>
<?=$enquiry['ShippingAddress']['city'];?><br>
<?=$enquiry['ShippingAddress']['postcode'];?>
<?=strtoupper($states[$enquiry['ShippingAddress']['state_id']]);?><br>
</td>
</tr>
</table>
<br>
<table border="1" cellpadding="2" cellspacing="0">
<tr bgcolor="#f2f2f2" align="center">
<? $moreDetailsFont = '9pt'; ?>
<td style="font-size: <?=$moreDetailsFont?>">CUSTOMER ORDER NO</td>
<td style="font-size: <?=$moreDetailsFont?>">CMC JOB #</td>
<td style="font-size: <?=$moreDetailsFont?>">FOB</td>
<td style="font-size: <?=$moreDetailsFont?>">SHIP VIA</td>
<td style="font-size: <?=$moreDetailsFont?>">TERMS</td>
<td style="font-size: <?=$moreDetailsFont?>">CUSTOMER ABN</td>
</tr>
<tr align="center">
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Job']['customer_order_number'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Job']['title'];?></td>
<td style="font-size: <?=$moreDetailsFont?>">??</td>
<td style="font-size: <?=$moreDetailsFont?>">??</td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Customer']['payment_terms'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$this->element('abn', array('abn'=>$job['Customer']['abn']));?></td>
</tr>
</table>