diff --git a/controllers/quotes_controller.php b/controllers/quotes_controller.php index ef65fe9b..f49087b3 100755 --- a/controllers/quotes_controller.php +++ b/controllers/quotes_controller.php @@ -86,8 +86,14 @@ class QuotesController extends AppController { $this->Session->setFlash(__('Invalid Quote', true)); $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); } - $quote = $this->Quote->findAllById($id); - //$this->set('quote', $quote); + $quote = $this->Quote->findById($id); + //$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->render(); } diff --git a/vendors/xtcpdf.php b/vendors/xtcpdf.php index abf8332f..871d2e07 100644 --- a/vendors/xtcpdf.php +++ b/vendors/xtcpdf.php @@ -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->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 */ $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); @@ -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->SetTextColor(0 , 0, 152); //Set the Text Color to Blue $this->SetFont('times', 'B'); $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 * $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->SetTextColor(0, 0, 0); - $this->SetFont($this->xfooterfont,'',$this->xfooterfontsize); - $this->Cell(0,8, $footertext,'T',1,'C'); + $this->Image(K_PATH_IMAGES.'cmcfooter.png', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C'); } /** * 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 @@ -101,14 +95,14 @@ class XTCPDF extends TCPDF $pageNo = $this->PageNoFormatted(); //$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 "; $emailTo = "theman@theman.com"; $attention = "Joe Bloggs"; $fromName = "Mr Sales Man"; $fromEmail = "SalesMan@cmctechnologies.com.au"; $enquiryNumber = "CMC1234NE22656-41"; - + */ $this->SetXY($boxXstart, 55); @@ -117,6 +111,7 @@ class XTCPDF extends TCPDF 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 = 0; // $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($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, "$fromName", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this. // echo "Last height: ".$this->getLastH(); $this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); @@ -139,15 +134,28 @@ class XTCPDF extends TCPDF $this->MultiCell($thirdColWidth, 0, "PAGE: ", 'LB', 'L', 0, 0); $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($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($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->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) } + + + 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'); + } + + + + + + + } ?> \ No newline at end of file diff --git a/views/quotes/pdf.ctp b/views/quotes/pdf.ctp index 24c6a681..c37f1810 100644 --- a/views/quotes/pdf.ctp +++ b/views/quotes/pdf.ctp @@ -3,6 +3,11 @@ //App::import('Vendor', 'tcpdf/tcpdf'); // // + +print_r($quote); + +print_r($enquiry); + $tcpdf = new XTCPDF(); //$tcpdf = new TCPDF(); @@ -15,7 +20,7 @@ $textfont = 'times'; // looks better, finer, and more condensed than 'dejavusans $tcpdf->SetAuthor("CMC Technologies"); -$tcpdf->SetTitle("CMC Technologies Quote"); +$tcpdf->SetTitle("CMC Technologies Quote: ".$quote['Enquiry']['title']); $tcpdf->SetAutoPageBreak( false ); $tcpdf->setHeaderFont(array($textfont,'',40)); $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->AddPage(); -$tcpdf->Page1Header(); +$page1done = false; //Have we already made the first page? If so, don't show the CMC header/footer -$tcpdf->DetailsBox(); -$content = << - Dear Bill,

-

-
- RE: Awesome Products

-

- Thank you for your enquiry regarding our Awesome Products. Please see the following quotation for:

+ $tcpdf->AddPage(); - - - - - - - - - - - - - - - -
ItemProduct
1.0A Product (TM)
2.0Another Product
-

-  

-

- Regards,

-

-
- Sales Engineer

-

-  

-

- Attachments:

-

- attachment1.pdf
- attachment2.pdf

-

-  

-

-  

-

-  

-

-  

-

-  

+ if($page1done == false) { + $tcpdf->Page1Header(); + + if( (!$enqury['Enquiry']['customer_reference']) || ($enquiry['Enquiry']['customer_refernece'] == '') ) { + + $enquiry_date = date('d/m/Y',$time->toUnix($enquiry['Enquiry']['created'])); + + + $enquiry['Enquiry']['customer_reference'] = "Enquiry on $enquiry_date"; + } + + + $tcpdf->DetailsBox($enquiry['Customer']['name'], $enquiry['Contact']['email'], $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'], + $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'], $enquiry['User']['email'], $quote['Enquiry']['title'], + $enquiry['Enquiry']['customer_reference']); + + + + + } + else { + $tcpdf->continuedHeader(); + } -ENDCONTENT; $currentX = $tcpdf->GetX(); $currentY = $tcpdf->GetY(); @@ -101,17 +80,44 @@ $tcpdf->SetTextColor(0); $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->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');