Transactional calulation for page breaking working OK it seems
This commit is contained in:
parent
b57145a34a
commit
f9d1d13431
|
|
@ -181,8 +181,8 @@ class QuotesController extends AppController {
|
|||
|
||||
$this->set('commercialDetails', $commercialDetails);
|
||||
|
||||
debug($quote);
|
||||
debug($commercialDetails);
|
||||
//debug($quote);
|
||||
//debug($commercialDetails);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
596
vendors/xtcpdf.php
vendored
596
vendors/xtcpdf.php
vendored
|
|
@ -9,7 +9,7 @@ class XTCPDF extends TCPDF {
|
|||
var $xfooterfont = PDF_FONT_NAME_MAIN ;
|
||||
var $xfooterfontsize = 8 ;
|
||||
|
||||
function header() {
|
||||
/* function header() {
|
||||
$this->SetHeaderMargin(4);
|
||||
$this->ln();
|
||||
$pageNo = $this->PageNoFormatted();
|
||||
|
|
@ -18,7 +18,7 @@ class XTCPDF extends TCPDF {
|
|||
// $this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)
|
||||
//$this->MultiCell(0, 0, "<b>PRICING AND SPECIFICATIONS</b>", 0, 'C', 0, 1, null, null, true, 0, true);
|
||||
$this->writeHTMLCell(0, 0, null, null, "<b>PRICING AND SPECIFICATIONS</b>", 0, 1, 0, true, 'C');
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Overwrites the default header
|
||||
|
|
@ -229,7 +229,7 @@ EOD;
|
|||
|
||||
foreach ($products as $product) {
|
||||
$fullDesc = "<b>".$product[$docType]['title'].'</b><br />'.$product[$docType]['description'];
|
||||
// echo $fullDesc;
|
||||
// echo $fullDesc;
|
||||
$itemno = number_format($product[$docType]['item_number'], 1, '.', '');
|
||||
$qty = $product[$docType]['quantity'];
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ EOD;
|
|||
|
||||
|
||||
|
||||
$tbl .= <<<ENDPRODUCT
|
||||
$tbl .= <<<ENDPRODUCT
|
||||
|
||||
<tr>
|
||||
<td width="$item_width" align="center">$itemno</td>
|
||||
|
|
@ -251,306 +251,229 @@ $tbl .= <<<ENDPRODUCT
|
|||
|
||||
ENDPRODUCT;
|
||||
}
|
||||
$tbl .= "</table>";
|
||||
$tbl .= "</table>";
|
||||
|
||||
$this->writeHTML($tbl, true, false, false, false, "");
|
||||
$this->writeHTML($tbl, true, false, false, false, "");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $principleName
|
||||
* @param <type> $currency
|
||||
* @param int $gst - 0 or 1 if GST is applicable.
|
||||
* @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 Map $commercialDetails - the details array/map - passed to commercialComments()
|
||||
*/
|
||||
function productPage($principleName, $currency,$gst, $products ,$docType, $commercialDetails) {
|
||||
/**
|
||||
* Start a TCPDF transaction and do the calculations for the product table.
|
||||
* @param <type> $principleName
|
||||
* @param <type> $currency
|
||||
* @param <type> $gst
|
||||
* @param <type> $products
|
||||
* @param <type> $docType
|
||||
* @param <type> $commercialDetails
|
||||
*/
|
||||
function calculateProductPage($principleName, $currency,$gst, $products ,$docType, $commercialDetails) {
|
||||
|
||||
$itemColwidth = 12;
|
||||
$qtyColwidth = 10;
|
||||
$descColwidth = 120;
|
||||
$unitpriceColwidth = 25;
|
||||
$totalPricColwidth = -10;
|
||||
|
||||
|
||||
$this->SetFontSize(10);
|
||||
//$availableHeight = 253;
|
||||
$availableHeight = 300;
|
||||
|
||||
//$lineHeight = 5; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs
|
||||
$lineHeight = 5;
|
||||
$heightLeft = $availableHeight; //height left on this particular page.
|
||||
|
||||
$pagesRequired = 1;
|
||||
|
||||
foreach ($products as $product) {
|
||||
|
||||
$this->startTransaction();
|
||||
|
||||
$fullDesc = "<b>".$product[$docType]['title'].'GG</b><br>'.$product[$docType]['description'];
|
||||
$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
|
||||
|
||||
$lasth = $this->getLastH();
|
||||
$this->rollbackTransaction($this);
|
||||
//echo "Last height needed for item: ".$product[$docType]['item_number']." was: ".$lasth."<br>";
|
||||
|
||||
|
||||
$itemColwidth = 12;
|
||||
$qtyColwidth = 10;
|
||||
$descColwidth = 120;
|
||||
$unitpriceColwidth = 25;
|
||||
$totalPricColwidth = -10;
|
||||
|
||||
$this->SetFillColor(240);
|
||||
echo $product[$docType]['id']." needs ".$lasth." has $heightLeft left<br>";
|
||||
|
||||
//$heightNeeded = $this->getNumLines("ITEM\NO.", $itemColwidth);
|
||||
//echo "HEADER ROW HEIGHT IS $heightNeeded";
|
||||
$itemno = $product[$docType]['item_number'];
|
||||
|
||||
/* Need to work out how many Pages the Product Table will need to be split over */
|
||||
if($heightLeft - $lasth <= 0) {
|
||||
echo "<br>OUT OF SPACE ON PAGE $pagesRequired making a new one<br>";
|
||||
$pagesRequired++;
|
||||
$heightLeft = $availableHeight; //Start checking the next page;
|
||||
echo "<br>remaining height on new one = ".$heightLeft."<br>";
|
||||
$heightLeft -= $lasth;
|
||||
$itemno = $product[$docType]['item_number'];
|
||||
echo "<br>Using $lasth for $itemno so now have $heightLeft left<br>";
|
||||
|
||||
//echo "Product Page height is: ".$this->getPageHeight();
|
||||
$pageProducts[$pagesRequired][] = $product[$docType]['id'];
|
||||
|
||||
}
|
||||
else {
|
||||
$heightLeft -= $lasth;
|
||||
$pageProducts[$pagesRequired][] = $product[$docType]['id'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
$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>";
|
||||
|
||||
$pagesRequired = 1;
|
||||
|
||||
$theseProductsHeight = 0;
|
||||
|
||||
$remainingHeight = $availableHeight;
|
||||
|
||||
$pageProducts = array(); //Array in the form $pageProducts[$pageNumber] = NUMBER_OF_ITEMS_ON_THIS_PAGE
|
||||
|
||||
echo "Page height is ".$this->getPageHeight();
|
||||
foreach ($products as $product) {
|
||||
|
||||
|
||||
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
|
||||
$linesNeeded = $this->getNumLines($fullDesc, $descColwidth);
|
||||
$mmNeeded = ($linesNeeded*$lineHeight);
|
||||
|
||||
echo $product[$docType]['item_number']." needs ".$mmNeeded." has $remainingHeight left<br>";
|
||||
|
||||
if($remainingHeight - $mmNeeded <= 0) {
|
||||
echo "<br>OUT OF SPACE ON PAGE $pagesRequired making a new one";
|
||||
$pagesRequired++;
|
||||
$remainingHeight = $availableHeight; //Start checking the next page;
|
||||
echo "<br>remaining height on new one = ".$remainingHeight;
|
||||
$remainingHeight -= $mmNeeded;
|
||||
$itemno = $product[$docType]['item_number'];
|
||||
echo "<br>Using $mmNeeded for $itemno so now have $remainingHeight left<br>";
|
||||
|
||||
$pageProducts[$pagesRequired][] = $product;
|
||||
|
||||
}
|
||||
else {
|
||||
$remainingHeight -= $mmNeeded;
|
||||
$pageProducts[$pagesRequired][] = $product;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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) {
|
||||
echo $product[$docType]['item_number']. " IS LAST";
|
||||
|
||||
$commMMneeded = 23*$lineHeight; //hardcoded. Which is bad. so Dont go and change text size on me now..
|
||||
echo "MM needed for commercial comments ".$commMMneeded;
|
||||
echo "MM remaining right now : ".$remainingHeight;
|
||||
if($remainingHeight - $commMMneeded <= 0) {
|
||||
echo "<br>Need a new page for last item and commercial comments";
|
||||
array_pop($pageProducts[$pagesRequired]);
|
||||
$pagesRequired++;
|
||||
$remainingHeight = $availableHeight;
|
||||
$remainingHeight -= $commMMneeded;
|
||||
$pageProducts[$pagesRequired][] = $product;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$this->startTransaction();
|
||||
$subtotal = 0;
|
||||
$totalsHeight = $this->totals($currency, $subtotal, 1);
|
||||
$commDetailsHeight = $this->commercialComments($commercialDetails);
|
||||
|
||||
$this->rollbackTransaction($this);
|
||||
|
||||
echo "Currently have $heightLeft Comm details height is ".$commDetailsHeight." totals height is: ".$totalsHeight."<br>";
|
||||
|
||||
if($heightLeft - ($commDetailsHeight + $totalsHeight) <= 0) {
|
||||
echo "<br>Need a new page for last item and commercial comments";
|
||||
array_pop($pageProducts[$pagesRequired]);
|
||||
$pagesRequired++;
|
||||
$heightLeft = $availableHeight;
|
||||
$heightLeft -= $commDetailsHeight;
|
||||
$pageProducts[$pagesRequired][] = $product[$docType]['id'];
|
||||
}
|
||||
|
||||
|
||||
debug($pageProducts);
|
||||
return $pageProducts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $principleName
|
||||
* @param <type> $currency
|
||||
* @param int $gst - 0 or 1 if GST is applicable.
|
||||
* @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 Map $commercialDetails - the details array/map - passed to commercialComments()
|
||||
*/
|
||||
function productPage($principleName, $currency,$gst, $products ,$docType, $commercialDetails, $pageProducts) {
|
||||
|
||||
|
||||
$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 = 12;
|
||||
$qtyColwidth = 10;
|
||||
$descColwidth = 120;
|
||||
$unitpriceColwidth = 25;
|
||||
$totalPricColwidth = -10;
|
||||
|
||||
}
|
||||
|
||||
//print_r($pageProducts[1]);
|
||||
|
||||
//echo "We need to make $pagesRequired product pages<br>";
|
||||
$this->SetFillColor(240);
|
||||
|
||||
|
||||
$subTotal = 0;
|
||||
$subTotal = 0;
|
||||
|
||||
for($i=1; $i<=$pagesRequired; $i++) {
|
||||
$this->AddPage();
|
||||
foreach ($pageProducts as $page) {
|
||||
|
||||
$this->AddPage();
|
||||
|
||||
//Draw Header Rows
|
||||
$this->setFontSize(12);
|
||||
$pageNo = $this->PageNoFormatted();
|
||||
$this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1);
|
||||
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1);
|
||||
$this->setFontSize(10);
|
||||
$this->MultiCell($itemColwidth, 0, "ITEM NO.", 1, "C", 1, 0);
|
||||
|
||||
//Draw Header Rows
|
||||
$pageNo = $this->PageNoFormatted();
|
||||
$this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1);
|
||||
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 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['iso4217'], 1, "C", 1, 0);
|
||||
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1);
|
||||
|
||||
|
||||
|
||||
|
||||
//Start Printing Product cells, until we run out of room. Then continue on the next page
|
||||
|
||||
foreach($pageProducts[$i] as $product) {
|
||||
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
|
||||
|
||||
|
||||
|
||||
$currentX = $this->GetX();
|
||||
$currentY = $this->GetY();
|
||||
|
||||
$this->SetX($currentX + $itemColwidth + $qtyColwidth);
|
||||
$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($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->SetX($endOfDesc);
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
$heightNeeded = $this->getLastH();
|
||||
/**
|
||||
* Call the commercial Comments. Need to have already figured out what page to do this on..
|
||||
*
|
||||
* * Passing a data structure in the following format.
|
||||
*
|
||||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'validFor' => (String) eg. 30 Days
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
* 'customsDuty' => (String) eg. NIL || 5%
|
||||
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
|
||||
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @todo this seems like a cleaner way of doing it than I did in the detailsBox(). Revise at some point
|
||||
*/
|
||||
|
||||
|
||||
$this->commercialComments($commercialDetails);
|
||||
$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['iso4217'], 1, "C", 1, 0);
|
||||
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1);
|
||||
|
||||
|
||||
$this->AliasNbPages();
|
||||
$this->lastPage();
|
||||
echo "<h2>$pageNo</h2>";
|
||||
print_r($page);
|
||||
|
||||
//Start Printing Product cells, until we run out of room. Then continue on the next page
|
||||
|
||||
foreach($page as $productID) {
|
||||
$product = array_shift($products);
|
||||
|
||||
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
|
||||
|
||||
|
||||
|
||||
$currentX = $this->GetX();
|
||||
$currentY = $this->GetY();
|
||||
|
||||
$this->SetX($currentX + $itemColwidth + $qtyColwidth);
|
||||
$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($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->SetX($endOfDesc);
|
||||
|
||||
$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>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
debug($products);
|
||||
|
||||
|
||||
|
||||
|
||||
//End Page For
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to format currency in an attractive human-viewable way. Australian style. Returns the formatted string.
|
||||
* @param String $symbol
|
||||
* Call the commercial Comments. Need to have already figured out what page to do this on..
|
||||
*
|
||||
* @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, '.', ',');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Print out the commercial comments in a CMC Quotation.
|
||||
*
|
||||
*
|
||||
* Receives a data structure in the following format.
|
||||
* * Passing a data structure in the following format.
|
||||
*
|
||||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'dateIssued' => (String) eg. 2009-05-10
|
||||
* 'validFor' => (String) eg. 30 Days
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
|
|
@ -558,19 +481,73 @@ ENDPRODUCT;
|
|||
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
|
||||
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
|
||||
* );
|
||||
*
|
||||
*
|
||||
*/
|
||||
function commercialComments($details) {
|
||||
|
||||
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)
|
||||
|
||||
$this->MultiCell(0, 0, "<b><u>Commercial Comments:</u></b>", 0, 'L', 0, 1, null, null, 1, null, true);
|
||||
|
||||
|
||||
$validUntilDate = strtotime($details["dateIssued"]. ' + '.$details["validFor"].' days');
|
||||
|
||||
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
|
||||
$this->totals($currency, $subTotal, $gst);
|
||||
$this->commercialComments($commercialDetails);
|
||||
|
||||
$listHtmlContents = <<<ENDHTMLCONTENTS
|
||||
|
||||
$this->AliasNbPages();
|
||||
$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, '.', ',');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Print out the commercial comments in a CMC Quotation.
|
||||
*
|
||||
*
|
||||
* Receives a data structure in the following format.
|
||||
*
|
||||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'dateIssued' => (String) eg. 2009-05-10
|
||||
* 'validFor' => (String) eg. 30 Days
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
* 'customsDuty' => (String) eg. NIL || 5%
|
||||
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
|
||||
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
|
||||
* );
|
||||
*/
|
||||
function commercialComments($details) {
|
||||
|
||||
$totalHeight = 0;
|
||||
|
||||
$this->MultiCell(0, 0, "<b><u>Commercial Comments:</u></b>", 0, 'L', 0, 1, null, null, 1, null, true);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
$validUntilDate = strtotime($details["dateIssued"]. ' + '.$details["validFor"].' days');
|
||||
|
||||
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
|
||||
|
||||
$listHtmlContents = <<<ENDHTMLCONTENTS
|
||||
<ol>
|
||||
<li><b>DELIVERY</b> IS ESTIMATED AT {$details["deliveryTime"]} ({$details["deliveryPoint"]}) FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER.</li>
|
||||
<li><b>PAYMENT TERMS:</b> {$details["paymentTerms"]}.</li>
|
||||
|
|
@ -585,27 +562,96 @@ ANY VARIATIONS ON ITEMS 5. TO 7. WILL BE TO YOUR ACCOUNT. THIS QUOTATION IS BASE
|
|||
IS SUBJECT TO CHANGE IF QUANTITIES VARY.
|
||||
<br>
|
||||
ENDHTMLCONTENTS;
|
||||
//$commlines = $this->getNumLines($listHtmlContents);
|
||||
//echo "lines required for commercial comments: ".$commlines;
|
||||
$this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true);
|
||||
$this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L');
|
||||
$this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L');
|
||||
//$commlines = $this->getNumLines($listHtmlContents);
|
||||
//echo "lines required for commercial comments: ".$commlines;
|
||||
$this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
}
|
||||
$this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L');
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L');
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
|
||||
function termsAndConditions() {
|
||||
return $totalHeight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function termsAndConditions() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function totals($currency, $subTotal, $gst) {
|
||||
|
||||
$itemColwidth = 12;
|
||||
$qtyColwidth = 10;
|
||||
$descColwidth = 120;
|
||||
$unitpriceColwidth = 25;
|
||||
$totalPricColwidth = -10;
|
||||
$totalHeight = 0;
|
||||
|
||||
echo "desc col wdith : ".$descColwidth;
|
||||
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
if($gst == 1) {
|
||||
$gstAmount = 0.1*$subTotal;
|
||||
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
}
|
||||
else {
|
||||
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
|
||||
$totalHeight += $this->getLastH();
|
||||
}
|
||||
|
||||
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
if($gst == 1) {
|
||||
$totalPrice = $subTotal * 1.1;
|
||||
}
|
||||
else {
|
||||
$totalPrice = $subTotal;
|
||||
}
|
||||
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1);
|
||||
|
||||
$totalHeight += $this->getLastH();
|
||||
|
||||
return $totalHeight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -26,6 +26,8 @@ $tcpdf->SetHeaderMargin(2);
|
|||
$tcpdf->setPrintHeader(false);
|
||||
$tcpdf->setPrintFooter(false);
|
||||
|
||||
$principle_name = strtoupper($enquiry['Principle']['name']);
|
||||
$pageProducts = $tcpdf->calculateProductPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'LineItem', $commercialDetails);
|
||||
|
||||
|
||||
$page1done = false; //Have we already made the first page? If so, don't show the CMC header/footer
|
||||
|
|
@ -88,13 +90,17 @@ foreach ($quote['QuotePage'] as $page) {
|
|||
|
||||
//print_r($products);
|
||||
|
||||
$principle_name = strtoupper($enquiry['Principle']['name']);
|
||||
|
||||
debug($commercialDetails);
|
||||
|
||||
//debug($commercialDetails);
|
||||
|
||||
//$tcpdf->productPageHTML($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'LineItem', $commercialDetails);
|
||||
|
||||
$tcpdf->productPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'LineItem', $commercialDetails);
|
||||
|
||||
|
||||
|
||||
$tcpdf->productPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'LineItem', $commercialDetails,
|
||||
$pageProducts);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue