Adding product page to PDF functionality

This commit is contained in:
Karl Cordes 2009-11-18 09:42:42 +11:00
parent 265ff9354b
commit b1cac9e89d
9 changed files with 965 additions and 792 deletions

View file

@ -1,38 +1,72 @@
<?php
class CostingsController extends AppController {
var $name = 'Costings';
var $helpers = array('Html', 'Form','Ajax');
var $components = array('RequestHandler');
var $helpers = array('Html', 'Form');
function index() {
$this->Costings->recursive = 0;
$this->Costing->recursive = 0;
$this->set('costings', $this->paginate());
}
/**
* Add a costing to a product. It's either being added to a product, quote_product etc.
*
*
* @param int $id
* @param string $target
*/
function add($id, $target) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Costing.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('costing', $this->Costing->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->Costing->create();
if ($this->Costing->save($this->data)) {
$this->Session->setFlash(__('The Costing has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Costing could not be saved. Please, try again.', true));
}
}
$products = $this->Costing->Product->find('list');
$quoteProducts = $this->Costing->QuoteProduct->find('list');
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
$this->set(compact('products', 'quoteProducts', 'purchaseCurrencies', 'saleCurrencies'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Costing', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Costing->save($this->data)) {
$this->Session->setFlash(__('The Costing has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Costing could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Costing->read(null, $id);
}
$products = $this->Costing->Product->find('list');
$quoteProducts = $this->Costing->QuoteProduct->find('list');
$purchaseCurrencies = $this->Costing->PurchaseCurrency->find('list');
$saleCurrencies = $this->Costing->SaleCurrency->find('list');
$this->set(compact('products','quoteProducts','purchaseCurrencies','saleCurrencies'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Costing', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Costing->del($id)) {
$this->Session->setFlash(__('Costing deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>

View file

@ -99,6 +99,114 @@ class QuotePagesController extends AppController {
}
function regeneratePage($id = null) {
if(!$id) {
$this->Session->setFlash(__('Invalid id for QuotePage', true));
$this->redirect(array('action'=>'index'));
}
else {
$quotePage = $this->QuotePage->read(null, $id);
//$enquiry = $this->QuotePage->Quote->Enquiry->find('all', array('conditions' => array('Enquiry.id' => $quotePage['Quote']['enquiry_id'])));
$enquiry = $this->QuotePage->Quote->Enquiry->read(null, $quotePage['Quote']['enquiry_id']);
// $quote = $this->QuotePage->Quote->find('all', array('conditions' => array('Quote.id' => $quotePage['Quote']['id'])));
$quoteProducts = $this->QuotePage->Quote->QuoteProduct->find('all', array('recursive' => 0, 'conditions' =>
array('QuoteProduct.quote_id' => $quotePage['Quote']['id']),
'order' => array('QuoteProduct.item_number ASC'))
);
$contactFirstName = $enquiry['Contact']['first_name'];
$salesEngineerName = $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];
$productRows = "";
foreach($quoteProducts as $quoteproduct) {
$itemNumber = $quoteproduct['QuoteProduct']['item_number'];
$title = $quoteproduct['QuoteProduct']['title'];
if($quoteproduct['QuoteProduct']['option'] == 1) {
$optionText = "Option ";
}
else {
$optionText = "";
}
$productRows .= <<<ENDROW
<tr>
<td>
$optionText
$itemNumber
</td>
<td>
$title
</td>
</tr>
ENDROW;
}
$this->data['QuotePage']['content'] = <<<ENDCONTENT
<p>Dear $contactFirstName, </p>
<p>&nbsp;</p>
<p> Thank for your recent enquiry. Please see the following quotation for: </p>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%; ">
<tbody>
<tr>
<th><b>Item</b></th>
<th><b>Product</b></th>
</tr>
$productRows
</tbody>
</table
<p> &nbsp;</p>
<p>Regards, </p>
<p>$salesEngineerName</p>
ENDCONTENT;
if (!empty($this->data)) {
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The QuotePage has been saved', true));
$id = $quotePage['Quote']['id'];
$this->redirect(array('controller' => 'quotes', 'action'=>'view/'.$id));
} else {
$this->Session->setFlash(__('The QuotePage could not be saved. Please, try again.', true));
}
}
debug($quotePage);
echo "<hr>";
debug ($quoteProducts);
}
}

View file

@ -14,9 +14,14 @@ class Costing extends AppModel {
'order' => ''
),
'QuoteProduct' => array('className'=>'QuoteProduct',
'foreignKey' => 'quote_product_id'
)
'QuoteProduct' => array('className'=>'QuoteProduct','foreignKey' => 'quote_product_id'
),
'PurchaseCurrency' => array('className' => 'Currency', 'foreignKey' => 'purchase_currency_id'),
'SaleCurrency' => array('className' => 'Currency', 'foreignKey' => 'sale_currency_id')
//'ProductOption' => array('className' => 'ProductOption', 'foreignKey' => 'product_option_id'),
//'QuoteProductOption'

View file

@ -1,35 +0,0 @@
<?php
class QuotedProduct extends AppModel {
var $name = 'QuotedProduct';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Principle' => array('className' => 'Principle',
'foreignKey' => 'principle_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Currency' => array('className' => 'Currency',
'foreignKey' => 'currency_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Quote' => array('className' => 'Quote',
'foreignKey' => 'quote_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Product' => array('className' => 'Product',
'foreignKey' => 'product_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>

8
vendors/xtcpdf.php vendored
View file

@ -178,6 +178,14 @@ class XTCPDF extends TCPDF
function productPage() {
}

View file

@ -72,7 +72,7 @@ foreach ($quote['QuotePage'] as $page) {
$tcpdf->SetFont('times', '', 12);
$tcpdf->writeHTMLCell(0, 0, $currentX, $currentY+5, $page['content'], 'LTRB', 1, 0, true, 'L', true);
$tcpdf->writeHTMLCell(0, 0, $currentX, $currentY+5, $page['content'], '', 1, 0, true, 'L', true);
/* Only show the footer if it's the first page */
@ -86,6 +86,9 @@ foreach ($quote['QuotePage'] as $page) {
}
//DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber)

View file

@ -1,39 +1,43 @@
<div class="quotes view">
<h2><?php
<h2><?php
$enquirynumber_link = $html->link($quote['Enquiry']['title'],
array('controller'=>'enquiries', 'action'=>'view', $quote['Enquiry']['id']));
$enquirynumber_link = $html->link($quote['Enquiry']['title'],
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);
}
else {
__('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision'].' for'. $customer_link);
}
?></h2>
if($quote['Quote']['revision'] == 0) {
__('Quote: '.$enquirynumber_link);
}
else {
__('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision']);
}
?></h2>
</div>
<?php
$i = 0;
foreach ($quote['QuotePage'] as $quotePage):
$i = 0;
foreach ($quote['QuotePage'] as $quotePage):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
?>
<div class="related">
<h3>Page <?php echo $i; ?> </h3>
<div class="quotepageview">
<?php echo $quotePage['content']; ?>
</div>
<h3>Page <?php echo $i; ?> </h3>
<div class="quotepageview">
<?php echo $quotePage['content']; ?>
</div>
<?php echo $html->link(__('Edit', true), array('controller'=>'quote_pages', 'action'=>'edit',$quotePage['id']));?>
<?php echo $html->link(__('Edit', true), array('controller'=>'quote_pages', 'action'=>'edit',$quotePage['id']));?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_pages', 'action'=>'delete', $quotePage['id']), null, sprintf(__('Are you ABSOLUTELY sure you want to delete Page # %s? This cannot be undone.', true), $i)); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_pages', 'action'=>'delete', $quotePage['id']), null, sprintf(__('Are you ABSOLUTELY sure you want to delete Page # %s? This cannot be undone.', true), $i)); ?>
</div>
@ -43,18 +47,19 @@ else {
<?php endforeach; ?>
<div class="actions">
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Cover Page', true), array('controller'=> 'quote_pages', 'action'=>'add/'.$quote['Quote']['id']));?> </li>
<li><?php echo $html->link(__('Add Cover Page', true), array('controller'=> 'quote_pages', 'action'=>'add/'.$quote['Quote']['id']));?> </li>
<li> <?php echo $html->link(__('Regenerate First Page', true), array('controller'=> 'quote_pages', 'action'=>'regeneratePage', $quotePage['id']), null, sprintf(__('Are you sure you want to regenerate the first page? You will lose any changes you have made to it.', true), $i)); ?></li>
</ul>
</div>
</div>
<div class="related">
<h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0">
<table cellpadding = "0" cellspacing = "0" class="quoteproducts">
<tr>
<th><?php __('Item Number'); ?></th>
<th><?php __('Quantity'); ?></th>
@ -64,7 +69,7 @@ else {
</tr>
<?php
<?php
$i = 0;
foreach ($quoteProducts as $quoteProduct):
$class = null;
@ -80,12 +85,11 @@ else {
}
echo number_format($quoteProduct['QuoteProduct']['item_number'], 1, '.', '');?></td>
<td><?php echo $quoteProduct['QuoteProduct']['quantity'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['title'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['description'];?></td>
<td class="actions">
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'quote_products', 'action'=>'view', $quoteProduct['QuoteProduct']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'quote_products', 'action'=>'edit', $quoteProduct['QuoteProduct']['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_products', 'action'=>'delete', $quoteProduct['QuoteProduct']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $quoteProduct['QuoteProduct']['id'])); ?>
@ -95,7 +99,7 @@ else {
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php endif; ?>
<div class="actions">
<ul>

View file

@ -27,7 +27,7 @@
* @modifiedby $LastChangedBy: gwoo $
* @lastmodified $Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
*/
/* Quotenik.css - Modifed version of cake.generic.css - Karl Cordes 20 December 2008 */
@ -161,11 +161,11 @@ ul.principle-emails {
width: 20%;
text-align: right;
color: #FFFFFF;
}
}
#username a {
color: #FFFFFF;
}
}
#nav {
width: 100%;
@ -211,7 +211,7 @@ ul.principle-emails {
}
#nav a:hover {
}
}
#nav li { /* all list items */
float: left;
@ -257,16 +257,16 @@ ul.principle-emails {
}
#mailheaders {
width: 80%;
}
}
a#mailheaders {
color: #003d4c;
}
}
#viewemail {
text-align: left;
font-size: 80%;
}
}
@ -276,23 +276,23 @@ a#mailheaders {
font-size: 90%;
background-color: #FFFFFF;
color: #000000;
}
}
#showemail {
padding-top:1em;
width: 100%;
}
}
#emailframe {
float: left;
width: 50%;
}
}
#emailattachments {
padding-right: 2em;
float: right;
}
}
dl#showemail {
line-height: 2em;
@ -326,8 +326,8 @@ div.quotepageview {
div.enquiriesindex {
padding: 0;
margin: 0;
padding: 0;
margin: 0;
}
@ -372,13 +372,13 @@ table tr.altrow td {
table tr.customer-suspect td {
background: #65BFDC;
}
}
table tr.customer-prospect td {
background: #F4F42F;
}
}
table tr.customer-customer td {
background: #63D463;
}
}
td.actions {
text-align: center;
@ -408,7 +408,7 @@ table.mer {
padding-left: 0;
padding-right: 0;
overflow: auto;
}
}
th.mer {
background: #f2f2f2;
@ -486,7 +486,7 @@ table.mer tr td.comments {
table.mer tr td.status {
padding: 0;
font-size: x-small;
}
}
table.mer tr td.contactemail {
padding: 0;
@ -509,14 +509,14 @@ table.mer tr td.viewedit {
table.quotetable {
width: auto;
}
}
table.quotetable tr.mostrecent td {
background: #ADD8E6;
}
}
table.quotetable tr.altrow td {
background: #f4f4f4;
}
}
table.emailtable {
font-size: small;
@ -533,6 +533,10 @@ table.productoptions tr.defaultoption {
font-weight: bold;
}
table.quoteproducts {
width: 50%;
}
/* Paging */
div.paging {
@ -577,7 +581,7 @@ dt {
dt.altrow {
background: #E6F0F0;
}
}
dd.mailheaders {
margin-top: -2em;
vertical-align: top;
@ -586,7 +590,7 @@ dd.mailheaders-altrow {
margin-top: -2em;
vertical-align: top;
background: #E6F0F0;
}
}
dd {
margin-left: 20em;
@ -595,7 +599,7 @@ dd {
}
dd.altrow {
background: #E6F0F0;
}
}
/* Forms */
@ -611,7 +615,7 @@ form#searchbox {
clear:auto;
width: auto;
margin-right: 0px;
}
}
fieldset {
border: 1px solid #ccc;
@ -673,7 +677,7 @@ form.MER-inplace-select {
}
select.MER-inplace-select {
width: 100px;
}
}
label {
@ -975,19 +979,19 @@ div.code-coverage-results span.result-good {
}
div.principle-emails {
float: right;
background: #ECF2F2;
border: 1px black dashed;
width: auto;
text-align: left;
font-size: 70%;
margin:0;
padding:0;
float: right;
background: #ECF2F2;
border: 1px black dashed;
width: auto;
text-align: left;
font-size: 70%;
margin:0;
padding:0;
}
div.enquiries-view {
float: left;
width: 80%;
float: left;
width: 80%;
}
div.auto_complete {
@ -1012,15 +1016,15 @@ span {
color: #2F782A;
font-weight: bold;
font-size: 110%;
}
}
span.note {
font-size: 85%;
}
}
span.warning {
font-size: 80%;
color: #FF0000;
}
}
span.highlight {
background-color: #74DD63;
@ -1041,7 +1045,7 @@ span.enquiry-view-comments {
span.tip {
color: #000000;
}
}
div#qTip {
padding: 3px;

View file

@ -1,10 +1,52 @@
/**
* Add costing to a product
*
*
*
*/
function buildup() {
//Fetch all the relevent inputs from the form
quantity = +($F('CostingQuantity'));
costprice = +($F('CostingUnitCostPrice'));
ourdiscount_percentage = +($F('OurDiscountPercent'));
packing_each = +($F('CostingPacking'));
exchange_rate = +($F('CostingExchangeRate'));
shipping_cost = +($F('CostingShippingCost'));
duty = +($F('CostingDutyPercent'));
sellprice_each = +($F('sellprice_each'));
customs = +($F('CostingCustoms'));
misc_cost = +($F('CostingMiscCosts'));
finance = +($F('CostingFinancePercent'));
if(ourdiscount_percentage != 0) {
discount = ourdiscount_percentage / 100;
}
else {
discount = 0;
}
discountamount = discount * costprice;
net_foreign_price = costprice - discountamount;
total_foreign_price = net_foreign_price + packing_each;
$('fob_country_of_export').value = total_foreign_price;
domestic_cost = total_foreign_price / exchange_rate;
$('convert_to_aud').value = domestic_cost.toFixed(2);
dutyamount = (duty / 100) * domestic_cost;
total_landed_cost = domestic_cost + dutyamount + customs + misc_cost + shipping_cost;
financeamount = (finance / 100) * domestic_cost;
financeamount = financeamount.toFixed(2);
$('financeamount').update('Finance amount: ' + financeamount);
total_landed_cost += (+financeamount);
total_landed_cost = total_landed_cost.toFixed(2);
$('total_landed_cost').value = total_landed_cost;
gross_profit_dollars = sellprice_each - total_landed_cost
$('gross_profit_dollars').value = gross_profit_dollars;
$('gross_profit_percent').value = ((gross_profit_dollars / sellprice_each)*100).toFixed(2);
}