259 lines
9.6 KiB
PHP
Executable file
259 lines
9.6 KiB
PHP
Executable file
<?php
|
|
App::import('Vendor','tcpdf/tcpdf');
|
|
|
|
class XTCPDF extends TCPDF {
|
|
|
|
var $xheadertext = 'PDF created using CakePHP and TCPDF';
|
|
var $xheadercolor = array(0,0,200);
|
|
var $xfootertext = 'Copyright © %d XXXXXXXXXXX. All rights reserved.';
|
|
var $xfooterfont = PDF_FONT_NAME_MAIN ;
|
|
var $xfooterfontsize = 8 ;
|
|
|
|
|
|
|
|
/**
|
|
* Overwrites the default header
|
|
* set the text in the view using
|
|
* $fpdf->xheadertext = 'YOUR ORGANIZATION';
|
|
* set the fill color in the view using
|
|
* $fpdf->xheadercolor = array(0,0,100); (r, g, b)
|
|
* set the font in the view using
|
|
* $fpdf->setHeaderFont(array('YourFont','',fontsize));
|
|
*/
|
|
function Page1Header() {
|
|
|
|
|
|
list($r, $b, $g) = $this->xheadercolor;
|
|
|
|
|
|
//$this->setY(10); // shouldn't be needed due to page margin, but helas, otherwise it's at the page top
|
|
|
|
$this->SetFillColor(255, 255, 255);
|
|
$this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue
|
|
|
|
// $this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden)
|
|
|
|
$this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 30, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L');
|
|
$this->Cell(30);
|
|
$this->SetFont('times', 'B');
|
|
$this->SetFontSize(30);
|
|
$this->Cell(0,0, $this->xheadertext, 0,1,'C', 1);
|
|
$this->SetFontSize(10);
|
|
$this->SetY(22);
|
|
$this->Cell(30);
|
|
$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()+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);
|
|
|
|
|
|
|
|
$this->MultiCell(50, 0, "+61 2 9669 4000<br>+61 2 9669 4111<br><a href=\"mailto:sales@cmctechnologies.com.au\">sales@cmctechnologies.com.au</a>
|
|
<br><a href=\"http://www.cmctechnologies.com.au\">www.cmctechnologies.com.au</a><br>", 0, 'L', 0, 0, 65, null, true, 0, true);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Overwrites the default footer
|
|
* set the text in the view using
|
|
* $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.';
|
|
*/
|
|
function Page1Footer() {
|
|
$this->SetY(-20);
|
|
$this->Image(K_PATH_IMAGES.'cmcfooter.jpg', 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, $your_reference) {
|
|
|
|
$this->SetTextColor(0); //Black Text
|
|
|
|
$boxYstart = 45;
|
|
$boxXstart = 10;
|
|
$firstColWidth = 40;
|
|
$secondColWidth = 70;
|
|
$thirdColWidth = 30;
|
|
$fourthColWidth = -10;
|
|
|
|
$pageNo = $this->PageNoFormatted();
|
|
//$pageOf = $this->getAliasNbPages();
|
|
|
|
|
|
|
|
|
|
$this->SetXY($boxXstart, 55);
|
|
|
|
$heightNeeded = $this->getNumLines($companyName, $secondColWidth);
|
|
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);
|
|
|
|
|
|
$this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", '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($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();
|
|
|
|
$this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0);
|
|
$this->MultiCell($secondColWidth, 0, "<a href=\"mailto:$emailTo\">$emailTo</a>", 'LR','L', 0, 0, null, null, true, 0, true);
|
|
$this->MultiCell($thirdColWidth, 0, "CMC REF#:", 'L', 'L', 0, 0);
|
|
$this->MultiCell($fourthColWidth, 0, $enquiryNumber, 'R', 'L', 0, 1); //Start a new line after thi
|
|
|
|
$this->MultiCell($firstColWidth, 0, "ATTENTION:", 'LRB', 'L', 0, 0);
|
|
$this->MultiCell($secondColWidth, 0, $attention, 'LRB', 'L', 0, 0);
|
|
$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'
|
|
);
|
|
|
|
}
|
|
|
|
|
|
function continuedHeader($cmcRef) {
|
|
$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();
|
|
$this->MultiCell(0,13.6, "$cmcRef PAGE $pageNo OF {nb}", '', 'R');
|
|
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)
|
|
//$this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi)
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @param <type> $principleName
|
|
* @param <type> $currency
|
|
* @param <type> $products
|
|
* @param String $docType - the model name of the Products we want to put in the table. ie. QuoteProduct, or InvoiceProduct, etc
|
|
*/
|
|
function productPage($principleName, $currency, $products ,$docType) {
|
|
|
|
|
|
$this->SetFontSize(10);
|
|
|
|
$lineHeight = 5; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs
|
|
|
|
|
|
|
|
$itemColwidth = 15;
|
|
$qtyColwidth = 15;
|
|
$descColwidth = 130;
|
|
$unitpriceColwidth = 15;
|
|
$totalPricColwidth = -10;
|
|
|
|
$this->SetFillColor(240);
|
|
|
|
//$heightNeeded = $this->getNumLines("ITEM\NO.", $itemColwidth);
|
|
//echo "HEADER ROW HEIGHT IS $heightNeeded";
|
|
|
|
/* Need to work out how many Pages the Product Table will need to be split over */
|
|
|
|
echo "Product Page height is: ".$this->getPageHeight();
|
|
|
|
|
|
|
|
|
|
//Draw Header Rows
|
|
$pageNo = $this->PageNoFormatted();
|
|
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS (PAGE $pageNo OF {nb})", 0, "C", 0, 1);
|
|
|
|
$this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0);
|
|
|
|
$heightNeeded = $this->getLastH();
|
|
/**
|
|
* @todo this seems like a cleaner way of doing it than I did in the detailsBox(). Revise at some point
|
|
*/
|
|
|
|
|
|
$this->MultiCell($qtyColwidth, $heightNeeded, "QTY", 1, "C", 1, 0);
|
|
$this->MultiCell($descColwidth, $heightNeeded, "DESCRIPTION", 1, "C", 1, 0);
|
|
$this->MultiCell($unitpriceColwidth, $heightNeeded, "UNIT\nPRICE", 1, "C", 1, 0);
|
|
$this->MultiCell($totalPricColwidth, $heightNeeded, "TOTAL\nPRICE", 1, "C", 1, 1);
|
|
|
|
//Header Line 2
|
|
|
|
$this->MultiCell($itemColwidth, 0, "", 1, "C", 1, 0);
|
|
|
|
$heightNeeded = $this->getLastH();
|
|
$this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0);
|
|
$this->MultiCell($descColwidth, $heightNeeded, $principleName, 1, "C", 1, 0);
|
|
$this->MultiCell($unitpriceColwidth, $heightNeeded, $currency, 1, "C", 1, 0);
|
|
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency, 1, "C", 1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($products as $product) {
|
|
//Need to use the getNumLines method to figure out how big to make the cells before the description cell
|
|
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
|
|
|
|
$linesNeeded = $this->getNumLines($fullDesc, $descColwidth);
|
|
echo "<br>";
|
|
echo $product[$docType]['title']." needs $linesNeeded so approx ".$linesNeeded*$lineHeight." mm <br>";
|
|
|
|
|
|
$mmNeeded = $linesNeeded*$lineHeight;
|
|
|
|
$this->MultiCell($itemColwidth, $mmNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
|
|
$this->MultiCell($qtyColwidth, $mmNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
|
|
|
|
|
|
|
|
|
|
$this->MultiCell($descColwidth, $mmNeeded, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
|
|
|
|
$this->MultiCell($unitpriceColwidth, $mmNeeded, "$1000", 1, "C", 0, 0);
|
|
$this->MultiCell($totalPricColwidth, $mmNeeded, "$2000", 1, "C", 0, 1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
?>
|