Changes to the PDF output

This commit is contained in:
Karl Cordes 2009-10-16 17:43:17 +11:00
parent f5eb8c4364
commit 54b9deb839
3 changed files with 106 additions and 73 deletions

View file

@ -86,8 +86,14 @@ class QuotesController extends AppController {
$this->Session->setFlash(__('Invalid Quote', true)); $this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index')); $this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
} }
$quote = $this->Quote->findAllById($id); $quote = $this->Quote->findById($id);
//$this->set('quote', $quote); //$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
$enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']);
$this->set('quote', $quote);
$this->set('enquiry', $enquiry);
// $this->set('customer', $customer);
//$this->layout = 'pdf'; //$this->layout = 'pdf';
//$this->render(); //$this->render();
} }

49
vendors/xtcpdf.php vendored
View file

@ -46,7 +46,7 @@ class XTCPDF extends TCPDF
$this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1); $this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1);
$this->Rect($this->GetX()+33, $this->GetY(), 200, 2, 'DF', array('width'=>0), array(0, 0, 0)); $this->Rect($this->GetX()+33, $this->GetY()+2, 157, 2, 'DF', array('width'=>0), array(0, 0, 0));
/* Start the contact details */ /* Start the contact details */
$this->SetTextColor(0); //Set the Text Color to Black $this->SetTextColor(0); //Set the Text Color to Black
$this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 32); $this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 32);
@ -58,8 +58,6 @@ class XTCPDF extends TCPDF
$this->MultiCell(50, 0, "Unit 19, 77 Bourke Rd\nAlexandria\nNSW 2015\nAUSTRALIA\n", 0, 'L', 0, 0, 150, null); $this->MultiCell(50, 0, "Unit 19, 77 Bourke Rd\nAlexandria\nNSW 2015\nAUSTRALIA\n", 0, 'L', 0, 0, 150, null);
$this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue $this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue
$this->SetFont('times', 'B'); $this->SetFont('times', 'B');
$this->MultiCell(30, 20, "Engineering &\nIndustrial\nInstrumentation", 0, 'L', 0, 1, 10,37); $this->MultiCell(30, 20, "Engineering &\nIndustrial\nInstrumentation", 0, 'L', 0, 1, 10,37);
@ -74,20 +72,16 @@ class XTCPDF extends TCPDF
* set the text in the view using * set the text in the view using
* $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.'; * $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.';
*/ */
function Footer() function Page1Footer()
{ {
$year = date('Y');
$footertext = sprintf($this->xfootertext, $year);
$this->SetY(-20); $this->SetY(-20);
$this->SetTextColor(0, 0, 0); $this->Image(K_PATH_IMAGES.'cmcfooter.png', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C');
$this->SetFont($this->xfooterfont,'',$this->xfooterfontsize);
$this->Cell(0,8, $footertext,'T',1,'C');
} }
/** /**
* For Quotes and (hopefully) Invoices. Identifies who the document is for, date, reference number, etc. * For Quotes and (hopefully) Invoices. Identifies who the document is for, date, reference number, etc.
*/ */
function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber) { function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber, $your_reference) {
$this->SetTextColor(0); //Black Text $this->SetTextColor(0); //Black Text
@ -101,14 +95,14 @@ class XTCPDF extends TCPDF
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
//$pageOf = $this->getAliasNbPages(); //$pageOf = $this->getAliasNbPages();
/* Debugging Vars */ /* Debugging Vars
$companyName = "LONG COMPANY NAME TRADING AS MR AWESOME PTY LTD LONG COMPANY NAME TRADING AS MR AWESOME PTY LTD "; $companyName = "LONG COMPANY NAME TRADING AS MR AWESOME PTY LTD LONG COMPANY NAME TRADING AS MR AWESOME PTY LTD ";
$emailTo = "theman@theman.com"; $emailTo = "theman@theman.com";
$attention = "Joe Bloggs"; $attention = "Joe Bloggs";
$fromName = "Mr Sales Man"; $fromName = "Mr Sales Man";
$fromEmail = "SalesMan@cmctechnologies.com.au"; $fromEmail = "SalesMan@cmctechnologies.com.au";
$enquiryNumber = "CMC1234NE22656-41"; $enquiryNumber = "CMC1234NE22656-41";
*/
$this->SetXY($boxXstart, 55); $this->SetXY($boxXstart, 55);
@ -117,6 +111,7 @@ class XTCPDF extends TCPDF
echo "Height needed: $heightNeeded"; echo "Height needed: $heightNeeded";
$lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs. $lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs.
// $lineHeight = 0; // $lineHeight = 0;
// $this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml); // $this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml);
@ -126,7 +121,7 @@ class XTCPDF extends TCPDF
$this->MultiCell($secondColWidth, $lineHeight*$heightNeeded, $companyName, 'LTR', 'L', 0, 0); $this->MultiCell($secondColWidth, $lineHeight*$heightNeeded, $companyName, 'LTR', 'L', 0, 0);
$this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); $this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0);
$this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, $fromName, 'TR', 'L', 0, 1); //Start a new line after this. $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "<a href=\"mailto:$fromEmail\">$fromName</a>", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this.
// echo "Last height: ".$this->getLastH(); // echo "Last height: ".$this->getLastH();
$this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); $this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0);
@ -140,14 +135,27 @@ class XTCPDF extends TCPDF
$this->MultiCell($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1); $this->MultiCell($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1);
$todaysDateString = date('l, j F Y');
$this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0);
$this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0);
$this->MultiCell($fourthColWidth, 0, $your_reference, 'BR', 'L', 0, 1);
$this->SetFontSize(6);
//Kinda lame that I cant seem to wrap this text nicer. But Whatever.
$this->MultiCell(0, 0, 'The information in this document is confidential and may be privileged. If you are not the indended recipient then access, disclosure, copying or other dissemination of the contents of t his message is unauthorised and may be unlawful. Please inform the sender immediately if you are not the intended addressee.',
'', 'L'
);
/* /*
*
* *
$this->Cell($firstColWidth, 0, "ATTENTION:", 'LTRB', 0, 'L', 0, null, 0, false); $this->Cell($firstColWidth, 0, "ATTENTION:", 'LTRB', 0, 'L', 0, null, 0, false);
$this->Cell($secondColWidth, 0, $attention, 'LTRB', 0, 'L', 0, "mailto:$emailTo", 0, false); $this->Cell($secondColWidth, 0, $attention, 'LTRB', 0, 'L', 0, "mailto:$emailTo", 0, false);
$this->Cell($thirdColWidth, 0, "PAGE: ", 'LTB', 0, 'L', 0, null, 0, false); $this->Cell($thirdColWidth, 0, "PAGE: ", 'LTB', 0, 'L', 0, null, 0, false);
$this->Cell($fourthColWidth, 0, "$pageNo of {nb}", 'TBR', 1, 'L', 0, null, 0, false); //Start a new line after thi $this->Cell($fourthColWidth, 0, "$pageNo of {nb}", 'TBR', 1, 'L', 0, null, 0, false); //Start a new line after thi
*/ */
$this->lastPage(); // $this->lastPage();
//$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height) //$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height)
// $this->MultiCell($firstColWidth, 0, "QUOTATION TO:", 'LTRB', 'L', 0, 0, $boxXstart, $boxYstart, false, false, true, false, 0); // $this->MultiCell($firstColWidth, 0, "QUOTATION TO:", 'LTRB', 'L', 0, 0, $boxXstart, $boxYstart, false, false, true, false, 0);
@ -156,5 +164,18 @@ class XTCPDF extends TCPDF
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh) //$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh)
} }
function continuedHeader() {
$this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 15, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L');
$this->MultiCell(0,0, 'CMC Technologies Quote Continued');
}
} }
?> ?>

View file

@ -3,6 +3,11 @@
//App::import('Vendor', 'tcpdf/tcpdf'); //App::import('Vendor', 'tcpdf/tcpdf');
// //
// //
print_r($quote);
print_r($enquiry);
$tcpdf = new XTCPDF(); $tcpdf = new XTCPDF();
//$tcpdf = new TCPDF(); //$tcpdf = new TCPDF();
@ -15,7 +20,7 @@ $textfont = 'times'; // looks better, finer, and more condensed than 'dejavusans
$tcpdf->SetAuthor("CMC Technologies"); $tcpdf->SetAuthor("CMC Technologies");
$tcpdf->SetTitle("CMC Technologies Quote"); $tcpdf->SetTitle("CMC Technologies Quote: ".$quote['Enquiry']['title']);
$tcpdf->SetAutoPageBreak( false ); $tcpdf->SetAutoPageBreak( false );
$tcpdf->setHeaderFont(array($textfont,'',40)); $tcpdf->setHeaderFont(array($textfont,'',40));
$tcpdf->xheadercolor = array(150,0,0); $tcpdf->xheadercolor = array(150,0,0);
@ -36,63 +41,37 @@ $tcpdf->SetFont($textfont,'B',20);
$tcpdf->Cell(0,14, "Hello World", 0,1,'L'); $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
*/ */
$tcpdf->AddPage(); $page1done = false; //Have we already made the first page? If so, don't show the CMC header/footer
$tcpdf->Page1Header();
$tcpdf->DetailsBox(); foreach ($quote['QuotePage'] as $page) {
$content = <<<ENDCONTENT
<p> $tcpdf->AddPage();
Dear Bill,</p>
<p style="text-align: center;">
<br />
<strong>RE: Awesome Products</strong></p>
<p>
Thank you for your enquiry regarding our Awesome Products. Please see the following quotation for:</p>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> if($page1done == false) {
<tbody> $tcpdf->Page1Header();
<tr>
<td>Item</td> if( (!$enqury['Enquiry']['customer_reference']) || ($enquiry['Enquiry']['customer_refernece'] == '') ) {
<td>Product</td>
</tr> $enquiry_date = date('d/m/Y',$time->toUnix($enquiry['Enquiry']['created']));
<tr>
<td>1.0</td>
<td>A Product (TM)</td> $enquiry['Enquiry']['customer_reference'] = "Enquiry on $enquiry_date";
</tr> }
<tr>
<td>2.0</td>
<td>Another Product</td> $tcpdf->DetailsBox($enquiry['Customer']['name'], $enquiry['Contact']['email'], $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'],
</tr> $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'], $enquiry['User']['email'], $quote['Enquiry']['title'],
</tbody> $enquiry['Enquiry']['customer_reference']);
</table>
<p>
&nbsp;</p>
<p>
Regards,</p> }
<p> else {
<br /> $tcpdf->continuedHeader();
Sales Engineer</p> }
<p>
&nbsp;</p>
<p>
Attachments:</p>
<p>
<em>attachment1.pdf </em><br />
<em>attachment2.pdf</em></p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
ENDCONTENT;
$currentX = $tcpdf->GetX(); $currentX = $tcpdf->GetX();
$currentY = $tcpdf->GetY(); $currentY = $tcpdf->GetY();
@ -101,17 +80,44 @@ $tcpdf->SetTextColor(0);
$tcpdf->SetFont('times', '', 12); $tcpdf->SetFont('times', '', 12);
$tcpdf->writeHTMLCell(0, 0, $currentX, $currentY+5, $content, 'LTRB', 1, 0, true, 'L', true); $tcpdf->writeHTMLCell(0, 0, $currentX, $currentY+5, $page['content'], 'LTRB', 1, 0, true, 'L', true);
$tcpdf->AddPage();
$tcpdf->AddPage(); /* Only show the footer if it's the first page */
if($page1done == false) {
$tcpdf->Page1Footer();
$page1done = true;
}
}
//DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber)
$tcpdf->AliasNbPages(); $tcpdf->AliasNbPages();
$tcpdf->lastPage(); $tcpdf->lastPage();
$tcpdf->Output('/home/karl/public_html/cake/quotenik-working/webroot/pdf/filename2.pdf', 'F');
$output_dir = '/var/www/cake/app/webroot/pdf/';
if($quote['Quote']['revision'] > 0) {
$filename = $enqury['Enquiry']['title'].'Rev'.$quote['Quote']['revision'].'.pdf';
}
else {
$filename = $enquiry['Enquiry']['title'].'.pdf';
}
$tcpdf->Output($output_dir.$filename, 'F');
//$tcpdf->Output('cmcquote.pdf', 'D'); //$tcpdf->Output('cmcquote.pdf', 'D');