Changing Product table to writeHTML breaking tables. Going to fix pageBreak problems

This commit is contained in:
Karl Cordes 2010-02-25 17:12:27 +11:00
parent e4c8a242bb
commit d36f9241d2
4 changed files with 75 additions and 184 deletions

View file

@ -172,5 +172,32 @@ class LineItemsController extends AppController {
}
function viewTable() {
if($this->RequestHandler->isAjax()) {
if (!empty($this->data)) {
if($this->data['LineItem']['quote_id'] != null) {
$quoteid = $this->data['LineItem']['quote_id'];
$lineItems = $this->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $quoteid),
'order' => array('LineItem.item_number ASC'))
);
$quote = $this->LineItem->Quote->read(null, $quoteid);
$this->set('quote', $quote);
$this->set('lineItems', $lineItems);
}
}
else {
//Was POSTed with no data.
$this->set('lineItems', 'Something has broken. Requesting a LineItem table without POSTing a quote or job ID');
}
}
}
}
?>

37
vendors/xtcpdf.php vendored
View file

@ -78,13 +78,13 @@ class XTCPDF extends TCPDF {
//$this->ln();
//$this->ln();
$this->SetFontSize(12);
$this->MultiCell(120, 2, "<span style=\"color: #B40404; font-weight: bold\">EXPLOSION PREVENTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(120, 2, "<span style=\"color: #DF0101; font-weight: bold\">EXPLOSION PREVENTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #DF0101; font-weight: bold\">PRESSURE RELIEF</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
$this->MultiCell(120, 2, "<span style=\"color: #B40404; font-weight: bold\">EXPLOSION PROTECTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(120, 2, "<span style=\"color: #088A4B; font-weight: bold\">EXPLOSION PROTECTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #088A4B; font-weight: bold\">VISION IN THE PROCESS</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
// $this->ln();
$this->MultiCell(80, 2, "<span style=\"color: #0000FF; font-weight: bold\">FLOW MEASUREMENT</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #4B088A; font-weight: bold\">PROCESS INSTRUMENTATION</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #0000FF; font-weight: bold\">PROCESS INSTRUMENTATION</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
}
@ -182,8 +182,8 @@ 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; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs
$lineHeight = 5;
$itemColwidth = 12;
@ -214,19 +214,24 @@ class XTCPDF extends TCPDF {
$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;
$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;
@ -242,6 +247,19 @@ class XTCPDF extends TCPDF {
* 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;
}
}
@ -477,7 +495,8 @@ 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');

View file

@ -58,164 +58,8 @@ foreach ($quote['QuotePage'] as $quotePage):
<div class="quoteproducts">
<h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0" id= "quoteTable" class="quoteproducts" ">
<thead>
<tr>
<th><?php __('Item Number'); ?></th>
<th><?php __('Quantity'); ?></th>
<th><?php __('Title'); ?></th>
<th><?php __('Description'); ?></th>
<th>Unit Price (<?php echo $quote['Currency']['iso4217']; ?>)</th>
<th><?php __('Total Price'); ?> (<?php echo $quote['Currency']['iso4217']; ?>)</th>
<th class="actions"><?php __('Actions');?></th>
</tr>
</thead>
<?
$dontTotal = 0; //if we encounter an optional item. Make Subtotal, GST and total payable to be $TBA
$subTotal = 0;
foreach ($quoteProducts as $quoteProduct) {
$thisNetPrice = $quoteProduct['LineItem']['unit_price']*$quoteProduct['LineItem']['quantity'];
$subTotal += $thisNetPrice;
if($quoteProduct['LineItem']['option'] == 1) {
$dontTotal = 1;
}
}
?>
<tfoot>
<tr class="divider">
<td></td>
<td></td>
<td></td>
<td class="rightAlign">SUB-TOTAL (Excluding GST)</td>
<td></td>
<td><?php
if($dontTotal == 0) {
echo $quote['Currency']['symbol'].$subTotal;
}
else {
echo "TBA";
}
?></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="rightAlign">GST (10%)</td>
<td></td>
<td><?php
if($dontTotal == 0) {
if($quote['Enquiry']['gst'] == 1 ) {
$gst = 0.1 * $subTotal;
echo $quote['Currency']['symbol'].$gst;
}
else {
$gst = 0;
echo "N/A";
}
}
else {
echo "TBA";
}
?></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="rightAlign">TOTAL PAYABLE</td>
<td></td>
<td><?php
if($dontTotal == 0) {
$total = $subTotal + $gst;
echo $quote['Currency']['symbol'].$total;
}
else {
echo "TBA";
}
?>
</td>
<td></td>
</tr>
</tfoot>
<?php
$i = 0;
$subTotal = 0;
foreach ($quoteProducts as $quoteProduct):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php
if($quoteProduct['LineItem']['option'] == 1 ) {
echo 'Option <br>';
}
echo number_format($quoteProduct['LineItem']['item_number'], 1, '.', '');?></td>
<td><?php echo $quoteProduct['LineItem']['quantity'];?></td>
<td><?php echo $quoteProduct['LineItem']['title'];?></td>
<td class="leftAlign"><?php echo $quoteProduct['LineItem']['description'];?></td>
<td><?php echo $quote['Currency']['symbol'].$quoteProduct['LineItem']['unit_price'];
?></td>
<td class="netPrice"><?php
$thisNetPrice = $quoteProduct['LineItem']['unit_price']*$quoteProduct['LineItem']['quantity'];
$subTotal += $thisNetPrice;
echo $quote['Currency']['symbol'].$thisNetPrice; ?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'line_items', 'action'=>'view', $quoteProduct['LineItem']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'line_items', 'action'=>'edit', $quoteProduct['LineItem']['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'line_items', 'action'=>'delete', $quoteProduct['LineItem']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $quoteProduct['LineItem']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div id="productTable"></div>
<div class="actions">
<ul>

View file

@ -12,6 +12,11 @@
$(function() {
fetchTable();
$("#addLineItem-form").dialog({
autoOpen: false,
height: 800,
@ -22,9 +27,12 @@ $(function() {
$.post("/line_items/ajaxSave", $("#LineItemAddForm").serialize(), function(data) {
location.reload();
});
fetchTable();
}
);
$("#LineItemAddForm").resetForm();
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
@ -55,7 +63,7 @@ $(function() {
altField: '#QuoteDateIssued'
});
});
@ -92,19 +100,12 @@ function getProductOptions() {
/*
* Fetch the most recent table of Line Items. This allows calculation to be done in PHP rather than JS.
*/
function fetchTable() {
$.post("/lineItems/viewTable", $("#LineItemQuoteId").serialize(), function (itemTable) {
$("#productTable").html(itemTable);
});
}
function showResponse(responseText, statusText, xhr, $form) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}