PDF output working almost perfectly. Need to add commercial comments and discounts
This commit is contained in:
parent
5c75f512d7
commit
cb1d165155
|
|
@ -2,7 +2,7 @@
|
||||||
class QuotesController extends AppController {
|
class QuotesController extends AppController {
|
||||||
|
|
||||||
var $name = 'Quotes';
|
var $name = 'Quotes';
|
||||||
var $helpers = array('Html', 'Form','Ajax');
|
var $helpers = array('Html', 'Form','Ajax', 'Time');
|
||||||
|
|
||||||
var $components = array('RequestHandler');
|
var $components = array('RequestHandler');
|
||||||
|
|
||||||
|
|
@ -117,9 +117,8 @@ class QuotesController extends AppController {
|
||||||
|
|
||||||
$this->set('products', $quoteProducts);
|
$this->set('products', $quoteProducts);
|
||||||
|
|
||||||
// $this->set('customer', $customer);
|
|
||||||
//$this->layout = 'pdf';
|
|
||||||
//$this->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
195
vendors/xtcpdf.php
vendored
195
vendors/xtcpdf.php
vendored
|
|
@ -98,7 +98,7 @@ class XTCPDF extends TCPDF {
|
||||||
$this->SetXY($boxXstart, 55);
|
$this->SetXY($boxXstart, 55);
|
||||||
|
|
||||||
$heightNeeded = $this->getNumLines($companyName, $secondColWidth);
|
$heightNeeded = $this->getNumLines($companyName, $secondColWidth);
|
||||||
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.
|
||||||
|
|
||||||
|
|
@ -156,22 +156,23 @@ class XTCPDF extends TCPDF {
|
||||||
*
|
*
|
||||||
* @param <type> $principleName
|
* @param <type> $principleName
|
||||||
* @param <type> $currency
|
* @param <type> $currency
|
||||||
|
* @param int $gst - 0 or 1 if GST is applicable.
|
||||||
* @param <type> $products
|
* @param <type> $products
|
||||||
* @param String $docType - the model name of the Products we want to put in the table. ie. QuoteProduct, or InvoiceProduct, etc
|
* @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) {
|
function productPage($principleName, $currency,$gst, $products ,$docType) {
|
||||||
|
|
||||||
|
|
||||||
$this->SetFontSize(10);
|
$this->SetFontSize(10);
|
||||||
|
|
||||||
$lineHeight = 5.8; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs
|
$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;
|
$itemColwidth = 12;
|
||||||
$qtyColwidth = 15;
|
$qtyColwidth = 10;
|
||||||
$descColwidth = 130;
|
$descColwidth = 120;
|
||||||
$unitpriceColwidth = 15;
|
$unitpriceColwidth = 25;
|
||||||
$totalPricColwidth = -10;
|
$totalPricColwidth = -10;
|
||||||
|
|
||||||
$this->SetFillColor(240);
|
$this->SetFillColor(240);
|
||||||
|
|
@ -181,12 +182,12 @@ class XTCPDF extends TCPDF {
|
||||||
|
|
||||||
/* Need to work out how many Pages the Product Table will need to be split over */
|
/* Need to work out how many Pages the Product Table will need to be split over */
|
||||||
|
|
||||||
echo "Product Page height is: ".$this->getPageHeight();
|
//echo "Product Page height is: ".$this->getPageHeight();
|
||||||
|
|
||||||
|
|
||||||
$availableHeight = 253; //Figured out experimentally. Approx 253mm of space left for the actual table data after the header rows.
|
$availableHeight = 253; //Figured out experimentally. Approx 253mm of space left for the actual table data after the header rows.
|
||||||
|
|
||||||
echo "Remaining space on the page is: $availableHeight <br>";
|
// echo "Remaining space on the page is: $availableHeight <br>";
|
||||||
|
|
||||||
$pagesRequired = 1;
|
$pagesRequired = 1;
|
||||||
|
|
||||||
|
|
@ -219,11 +220,25 @@ class XTCPDF extends TCPDF {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Reached the last product in this Product Table.
|
||||||
|
* Need to see if we still have enough room to print the totals, if not will need to put the last item on a new page.
|
||||||
|
*/
|
||||||
|
if(end($products) == $product) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_r($pageProducts[1]);
|
|
||||||
|
|
||||||
echo "We need to make $pagesRequired product pages<br>";
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//print_r($pageProducts[1]);
|
||||||
|
|
||||||
|
//echo "We need to make $pagesRequired product pages<br>";
|
||||||
|
|
||||||
|
|
||||||
|
$subTotal = 0;
|
||||||
|
|
||||||
for($i=1; $i<=$pagesRequired; $i++) {
|
for($i=1; $i<=$pagesRequired; $i++) {
|
||||||
$this->AddPage();
|
$this->AddPage();
|
||||||
|
|
@ -232,7 +247,9 @@ class XTCPDF extends TCPDF {
|
||||||
|
|
||||||
//Draw Header Rows
|
//Draw Header Rows
|
||||||
$pageNo = $this->PageNoFormatted();
|
$pageNo = $this->PageNoFormatted();
|
||||||
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS (PAGE $pageNo OF {nb})", 0, "C", 0, 1);
|
$this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1);
|
||||||
|
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1);
|
||||||
|
$this->Ln();
|
||||||
|
|
||||||
$this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0);
|
$this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0);
|
||||||
|
|
||||||
|
|
@ -254,11 +271,8 @@ class XTCPDF extends TCPDF {
|
||||||
$heightNeeded = $this->getLastH();
|
$heightNeeded = $this->getLastH();
|
||||||
$this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0);
|
$this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0);
|
||||||
$this->MultiCell($descColwidth, $heightNeeded, $principleName, 1, "C", 1, 0);
|
$this->MultiCell($descColwidth, $heightNeeded, $principleName, 1, "C", 1, 0);
|
||||||
$this->MultiCell($unitpriceColwidth, $heightNeeded, $currency, 1, "C", 1, 0);
|
$this->MultiCell($unitpriceColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 0);
|
||||||
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency, 1, "C", 1, 1);
|
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1);
|
||||||
|
|
||||||
|
|
||||||
echo "POOOO";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -268,80 +282,117 @@ class XTCPDF extends TCPDF {
|
||||||
foreach($pageProducts[$i] as $product) {
|
foreach($pageProducts[$i] as $product) {
|
||||||
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
|
$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;
|
$currentX = $this->GetX();
|
||||||
|
$currentY = $this->GetY();
|
||||||
|
|
||||||
$this->MultiCell($itemColwidth, $mmNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
|
$this->SetX($currentX + $itemColwidth + $qtyColwidth);
|
||||||
$this->MultiCell($qtyColwidth, $mmNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
|
$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
|
||||||
|
$endOfDesc = $this->GetX();
|
||||||
|
$heightNeeded = $this->getLastH();
|
||||||
|
$this->SetX($currentX);
|
||||||
|
|
||||||
$this->MultiCell($descColwidth, $mmNeeded, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
|
$this->MultiCell($itemColwidth, $heightNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
|
||||||
|
$this->MultiCell($qtyColwidth, $heightNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
|
||||||
|
|
||||||
$this->MultiCell($unitpriceColwidth, $mmNeeded, "$1000", 1, "C", 0, 0);
|
$this->SetX($endOfDesc);
|
||||||
$this->MultiCell($totalPricColwidth, $mmNeeded, "$2000", 1, "C", 0, 1);
|
|
||||||
|
$this->MultiCell($unitpriceColwidth, $heightNeeded, $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']), 1, "C", 0, 0);
|
||||||
|
$thisTotalPrice = $product[$docType]['quantity']*$product[$docType]['unit_price'];
|
||||||
|
$this->MultiCell($totalPricColwidth, $heightNeeded, $this->formatCurrency($currency['symbol'],$thisTotalPrice), 1, "C", 0, 1);
|
||||||
|
|
||||||
|
$subTotal += $thisTotalPrice;
|
||||||
|
$lastY = $this->GetY();
|
||||||
|
$lastX = $this->GetX();
|
||||||
|
//echo $product[$docType]['item_number']." Last X is $lastX, Last Y is $lastY <br>";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(end($pageProducts[$pagesRequired]) == $product) {
|
||||||
|
|
||||||
|
|
||||||
|
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding);
|
||||||
|
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0);
|
||||||
|
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1);
|
||||||
|
|
||||||
|
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0);
|
||||||
|
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
|
||||||
|
if($gst == 1) {
|
||||||
|
$gstAmount = 0.1*$subTotal;
|
||||||
|
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
$this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0);
|
||||||
|
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||||
|
|
||||||
|
if($gst == 1) {
|
||||||
|
$totalPrice = $subTotal * 1.1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$totalPrice = $subTotal;
|
||||||
|
}
|
||||||
|
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//End Page For
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->AliasNbPages();
|
$this->AliasNbPages();
|
||||||
$this->lastPage();
|
$this->lastPage();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to format currency in an attractive human-viewable way. Australian style. Returns the formatted string.
|
||||||
|
* @param String $symbol
|
||||||
|
*
|
||||||
|
* @param $number
|
||||||
|
*/
|
||||||
|
function formatCurrency($symbol, $number) {
|
||||||
|
list($int, $dec) = explode('.', $number); //Creates an Undefined Offset notice. Fix eventually.
|
||||||
|
|
||||||
|
if($dec > 0) {
|
||||||
|
return $symbol.number_format($number, 2, '.', ',');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $symbol.number_format($number, 0, '.', ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// echo "Y is currently ".$this->GetY();
|
|
||||||
|
|
||||||
// $availableHeight = $this->getPageHeight() - $this->GetY() - 10;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
* */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// function productPageHTML() {
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ foreach ($quote['QuotePage'] as $page) {
|
||||||
if($page1done == false) {
|
if($page1done == false) {
|
||||||
$tcpdf->Page1Header();
|
$tcpdf->Page1Header();
|
||||||
|
|
||||||
if( (!$enqury['Enquiry']['customer_reference']) || ($enquiry['Enquiry']['customer_refernece'] == '') ) {
|
if( (!$enquiry['Enquiry']['customer_reference']) || ($enquiry['Enquiry']['customer_refernece'] == '') ) {
|
||||||
|
|
||||||
$enquiry_date = date('d/m/Y',$time->toUnix($enquiry['Enquiry']['created']));
|
$enquiry_date = date('d/m/Y',$time->toUnix($enquiry['Enquiry']['created']));
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ foreach ($quote['QuotePage'] as $page) {
|
||||||
|
|
||||||
$principle_name = strtoupper($enquiry['Principle']['name']);
|
$principle_name = strtoupper($enquiry['Principle']['name']);
|
||||||
|
|
||||||
$tcpdf->productPage($principle_name, $quote['Currency']['iso4217'], $products, 'QuoteProduct');
|
$tcpdf->productPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'QuoteProduct');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,10 +172,13 @@ foreach ($quote['QuotePage'] as $quotePage):
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<ul>
|
<ul>
|
||||||
<li><?php echo $html->link(__('Add Product to this Quote', true), array('controller'=> 'quote_products', 'action'=>'add', $quote['Quote']['id']));?> </li>
|
<li><?php echo $html->link(__('Add Product to this Quote', true), array('controller'=> 'quote_products', 'action'=>'add', $quote['Quote']['id']));?> </li>
|
||||||
|
<li><?php echo $html->link(__('Generate PDF from this Quote', true), array('controller'=>'quotes', 'action'=>'pdf', $quote['Quote']['id'])); ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php debug($quote); ?>
|
<?php // debug($quote);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
|
||||||
BIN
webroot/img/pdf.png
Executable file
BIN
webroot/img/pdf.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
Loading…
Reference in a new issue