diff --git a/vendors/xtcpdf.php b/vendors/xtcpdf.php index 66cc7c1e..53ec8c55 100755 --- a/vendors/xtcpdf.php +++ b/vendors/xtcpdf.php @@ -164,7 +164,7 @@ class XTCPDF extends TCPDF { $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 + $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 @@ -180,44 +180,133 @@ class XTCPDF extends TCPDF { //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(); + + 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. + echo "Remaining space on the page is: $availableHeight
"; - //Draw Header Rows - $pageNo = $this->PageNoFormatted(); - $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS (PAGE $pageNo OF {nb})", 0, "C", 0, 1); + $pagesRequired = 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); - - + $theseProductsHeight = 0; + $remainingHeight = $availableHeight; + $pageProducts = array(); //Array in the form $pageProducts[$pageNumber] = NUMBER_OF_ITEMS_ON_THIS_PAGE + //Can see already the final summary total thing is going to be a bit of a bitch to do. foreach ($products as $product) { + + + $fullDesc = "".$product[$docType]['title'].'
'.$product[$docType]['description']; + $linesNeeded = $this->getNumLines($fullDesc, $descColwidth); + $mmNeeded = $linesNeeded*$lineHeight; + + if($remainingHeight - $mmNeeded <= 0) { + $pagesRequired++; + $remainingHeight = $availableHeight; //Start checking the next page; + + $remainingHeight -= $mmNeeded; + + $pageProducts[$pagesRequired][] = $product; + + } + else { + $remainingHeight -= $mmNeeded; + $pageProducts[$pagesRequired][] = $product; + + } + + } + + print_r($pageProducts[1]); + + echo "We need to make $pagesRequired product pages
"; + + for($i=1; $i<=$pagesRequired; $i++) { + $this->AddPage(); + + + + //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); + + + echo "POOOO"; + + + + + //Start Printing Product cells, until we run out of room. Then continue on the next page + + foreach($pageProducts[$i] as $product) { + $fullDesc = "".$product[$docType]['title'].'
'.$product[$docType]['description']; + + $linesNeeded = $this->getNumLines($fullDesc, $descColwidth); + // echo "
"; + //echo $product[$docType]['title']." needs $linesNeeded so approx ".$linesNeeded*$lineHeight." mm
"; + + + $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); + + } + + + $this->AliasNbPages(); + $this->lastPage(); + + + + + + } + + + // 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 = "".$product[$docType]['title'].'
'.$product[$docType]['description']; @@ -231,9 +320,6 @@ class XTCPDF extends TCPDF { $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); @@ -243,12 +329,17 @@ class XTCPDF extends TCPDF { } + * */ + } +// function productPageHTML() { +// } + diff --git a/views/quotes/pdf.ctp b/views/quotes/pdf.ctp index a18e6ee6..e58eba23 100755 --- a/views/quotes/pdf.ctp +++ b/views/quotes/pdf.ctp @@ -85,9 +85,9 @@ foreach ($quote['QuotePage'] as $page) { } -$tcpdf->AddPage(); -print_r($products); + +//print_r($products); $principle_name = strtoupper($enquiry['Principle']['name']); @@ -95,8 +95,7 @@ $tcpdf->productPage($principle_name, $quote['Currency']['iso4217'], $products, ' -$tcpdf->AliasNbPages(); -$tcpdf->lastPage(); + $output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/';