Tidying up PDF generation. Formatting in Quote viewing

This commit is contained in:
Karl Cordes 2010-01-16 16:41:46 -07:00
parent 1d6aba8d90
commit 03e015ea2e
5 changed files with 237 additions and 41 deletions

View file

@ -2,7 +2,7 @@
class QuotesController extends AppController {
var $name = 'Quotes';
var $helpers = array('Html', 'Form','Ajax', 'Time');
var $helpers = array('Html', 'Form','Ajax', 'Time', 'Number');
var $components = array('RequestHandler');
@ -16,8 +16,14 @@ class QuotesController extends AppController {
$this->Session->setFlash(__('Invalid Quote.', true));
$this->redirect(array('action'=>'index'));
}
$quote = $this->Quote->read(null, $id);
$this->set('quote', $quote);
if (empty($this->data)) {
$quote = $this->Quote->read(null, $id);
$this->data = $quote;
$this->set('quote', $quote);
}
$quoteProducts = $this->Quote->QuoteProduct->find('all', array('recursive' => 0, 'conditions' => array('QuoteProduct.quote_id' => $id),
'order' => array('QuoteProduct.item_number ASC'))
@ -25,6 +31,9 @@ class QuotesController extends AppController {
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
$this->set('quoteProducts', $quoteProducts);
$currencies = $this->Quote->Currency->find('list');
$this->set('currencies', $currencies);
}
@ -78,7 +87,16 @@ class QuotesController extends AppController {
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
$issuedate = $this->data['Quote']['date_issued'];
$issuedate = $issuedate['year'].'-'.$issuedate['month'].'-'.$issuedate['day'];
$validUntilDate = strtotime($issuedate."+ ".$this->data['Quote']['days_valid']." days");
$this->data['Quote']['valid_until'] = date('Y-m-d', $validUntilDate);
if ($this->Quote->save($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true));
$thisquote = $this->Quote->id;
$this->redirect(array('action' =>'view/'.$id), null, false);
@ -97,7 +115,7 @@ class QuotesController extends AppController {
function pdf($id = null) {
Configure::write('debug',0);
Configure::write('debug',1);
if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
@ -111,16 +129,74 @@ class QuotesController extends AppController {
'order' => array('QuoteProduct.item_number ASC'))
);
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
/**
* 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
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
* 'daysValid' => (Int) eg. 30
* '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
* );
*
*
*/
if($enquiry['Enquiry']['gst'] == 1) {
$gstPhrase = "10% EXTRA";
}
else {
$gstPhrase = "Not Applicable for Export";
}
$commercialDetails = array (
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
'validFor' => $quote['Quote']['days_valid'],
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
'gst' => strtoupper($gstPhrase),
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
);
$this->set('commercialDetails', $commercialDetails);
debug($quote);
debug($commercialDetails);
$this->set('quote', $quote);
$this->set('enquiry', $enquiry);
$this->set('products', $quoteProducts);
}
}
?>

105
vendors/xtcpdf.php vendored
View file

@ -90,7 +90,7 @@ class XTCPDF extends TCPDF {
$fourthColWidth = -10;
$pageNo = $this->PageNoFormatted();
@ -98,11 +98,11 @@ class XTCPDF extends TCPDF {
$this->SetXY($boxXstart, 55);
$heightNeeded = $this->getNumLines($companyName, $secondColWidth);
$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.
$this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0);
@ -110,7 +110,7 @@ class XTCPDF extends TCPDF {
$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.
$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);
@ -143,7 +143,14 @@ class XTCPDF extends TCPDF {
$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');
$currentX = $this->GetX();
$this->SetX($currentX + 40);
$this->MultiCell(100, 13.6, $cmcRef." CONTINUES", '','C', 0, 0);
$this->MultiCell(0,13.6, "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)
@ -157,8 +164,9 @@ class XTCPDF extends TCPDF {
* @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) {
function productPage($principleName, $currency,$gst, $products ,$docType, $commercialDetails) {
$this->SetFontSize(10);
@ -185,7 +193,7 @@ class XTCPDF extends TCPDF {
$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;
@ -194,7 +202,7 @@ class XTCPDF extends TCPDF {
$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) {
@ -224,6 +232,7 @@ class XTCPDF extends TCPDF {
*/
if(end($products) == $product) {
}
@ -247,7 +256,7 @@ class XTCPDF extends TCPDF {
$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();
@ -360,6 +369,28 @@ class XTCPDF extends TCPDF {
//End Page For
}
/**
* 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
* );
*
*
*/
$this->commercialComments($commercialDetails);
$this->AliasNbPages();
@ -384,6 +415,58 @@ class XTCPDF extends TCPDF {
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
* '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) {
//$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('now + '.$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>
<li><b>QUOTATION IS VALID</b> FOR: <u>{$details["validFor"]} DAYS</u> (UNTIL {$niceValidUntilDate}).</li>
<li>ALL PRICES ARE <u>{$details["deliveryPoint"]}</u>.</li>
<li>EXCHANGE RATE: {$details["exchangeRate"]}.</li>
<li>CUSTOMS DUTY INCLUDED AT: {$details["customsDuty"]}%.</li>
<li>GST: {$details["gst"]}.</li>
<li>WHEN PAYMENTS ARE MADE INTO OUR BANK ACCOUNT, BANK CHARGES ARE YOUR RESPONSIBILITY.<li>
</ol>
ANY VARIATIONS ON ITEMS 5. TO 7. WILL BE TO YOUR ACCOUNT. THIS QUOTATION IS BASED ON QUANTITIES STATED AND
IS SUBJECT TO CHANGE IF QUANTITIES VARY.
<br>
ENDHTMLCONTENTS;
$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');
@ -393,7 +476,9 @@ class XTCPDF extends TCPDF {
function termsAndConditions() {
}

View file

@ -91,7 +91,9 @@ foreach ($quote['QuotePage'] as $page) {
$principle_name = strtoupper($enquiry['Principle']['name']);
$tcpdf->productPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'QuoteProduct');
debug($commercialDetails);
$tcpdf->productPage($principle_name, $quote['Currency'], $enquiry['Enquiry']['gst'], $products, 'QuoteProduct', $commercialDetails);

View file

@ -5,7 +5,7 @@
array('controller'=>'enquiries', 'action'=>'view', $quote['Enquiry']['id']));
$customer_link = $html->link( $customer['Customer']['name'], array('controller'=>'customers', 'action' => 'view', $customer['Customer']['id']));
if($quote['Quote']['revision'] == 0) {
__('Quote: '.$enquirynumber_link. ' for '. $customer_link);
@ -14,7 +14,7 @@
__('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision'].' for '. $customer_link);
}
?></h2>
</div>
@ -68,7 +68,7 @@ foreach ($quote['QuotePage'] as $quotePage):
<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>
@ -97,12 +97,12 @@ foreach ($quote['QuotePage'] as $quotePage):
<td class="leftAlign"><?php echo $quoteProduct['QuoteProduct']['description'];?></td>
<td><?php echo $quote['Currency']['symbol'].$quoteProduct['QuoteProduct']['unit_price'];?></td>
<td><?php
$thisNetPrice = $quoteProduct['QuoteProduct']['unit_price']*$quoteProduct['QuoteProduct']['quantity'];
$subTotal += $thisNetPrice;
echo $quote['Currency']['symbol'].$thisNetPrice; ?></td>
$thisNetPrice = $quoteProduct['QuoteProduct']['unit_price']*$quoteProduct['QuoteProduct']['quantity'];
$subTotal += $thisNetPrice;
echo $quote['Currency']['symbol'].$thisNetPrice; ?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'quote_products', 'action'=>'view', $quoteProduct['QuoteProduct']['id'])); ?>
@ -131,18 +131,18 @@ foreach ($quote['QuotePage'] as $quotePage):
<td class="rightAlign">GST (10%)</td>
<td></td>
<td><?php
if($quote['Enquiry']['gst'] == 1 ) {
$gst = 0.1 * $subTotal;
echo $quote['Currency']['symbol'].$gst;
if($quote['Enquiry']['gst'] == 1 ) {
$gst = 0.1 * $subTotal;
echo $quote['Currency']['symbol'].$gst;
}
else {
$gst = 0;
echo "N/A";
}
else {
$gst = 0;
echo "N/A";
}
?></td>
}
?></td>
<td></td>
</tr>
@ -154,9 +154,9 @@ foreach ($quote['QuotePage'] as $quotePage):
<td class="rightAlign">TOTAL PAYABLE</td>
<td></td>
<td><?php
$total = $subTotal + $gst;
echo $quote['Currency']['symbol'].$total;
?>
$total = $subTotal + $gst;
echo $quote['Currency']['symbol'].$total;
?>
</td>
<td></td>
</tr>
@ -176,9 +176,34 @@ foreach ($quote['QuotePage'] as $quotePage):
</ul>
</div>
<div class="commercialComments">
<h3><?php __('Commercial Details');?></h3>
<?php echo $form->create('Quote');?>
<fieldset>
<?php
echo $form->input('id', array('type' => 'hidden', 'value' => $quote['Quote']['id']));
echo $form->input('enquiry_id', array('type' => 'hidden'));
echo $form->input('delivery_time');
echo $this->element('payment_terms_box');
echo $form->input('date_issued');
echo $form->input('days_valid', array('default'=>'30'));
echo $form->input('currency_id', array('label' => 'Sale Currency', 'options' => $currencies));
echo $form->input('delivery_point', array('default' => 'EX-CMC TECHNOLOGIES, ALEXANDRIA NSW'));
echo $form->input('exchange_rate', array('default' => 'FIXED'));
echo $form->input('customs_duty', array('default' => 'NIL'));
echo $form->end('Update Commercial Terms');
?>
</fieldset>
</div>
</div>
<?php // debug($quote);
?>

View file

@ -718,6 +718,7 @@ form.MER-inplace-select {
padding-right: 0;
margin: 0;
width: 100px;
font-size: 70%;
}
select.MER-inplace-select {
width: 100px;
@ -1127,3 +1128,10 @@ div.categorylist h3 a:hover {
div#costingwrapper {
display: none;
}
div.commercialComments {
clear: both;
display: block;
padding-top: 3%;
}