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 $name = 'Costings';
var $helpers = array('Html', 'Form');
function index() {
$this->Costing->recursive = 0;
$this->set('costings', $this->paginate());
}
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 index() {
$this->Costings->recursive = 0;
$this->set('costings', $this->paginate());
}
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'));
}
/**
* 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));
$this->redirect(array('action'=>'index'));
}
}
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

@ -1,104 +1,212 @@
<?php
class QuotePagesController extends AppController {
var $name = 'QuotePages';
var $helpers = array('Html', 'Form', 'Ajax', 'Number', 'Fck');
var $name = 'QuotePages';
var $helpers = array('Html', 'Form', 'Ajax', 'Number', 'Fck');
var $components = array('RequestHandler');
var $components = array('RequestHandler');
function index() {
$this->QuotePage->recursive = 0;
$this->set('quotePages', $this->paginate());
}
function index() {
$this->QuotePage->recursive = 0;
$this->set('quotePages', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid QuotePage.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('quotePage', $this->QuotePage->read(null, $id));
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid QuotePage.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('quotePage', $this->QuotePage->read(null, $id));
}
function add($id = null) {
function add($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
$this->redirect(array('controller' => 'quotes', 'action'=>'index'));
}
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
$this->redirect(array('controller' => 'quotes', 'action'=>'index'));
}
if (!empty($this->data)) {
$this->QuotePage->create();
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The Quote Page has been saved', true));
$this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$this->data['QuotePage']['quote_id']));
} else {
$this->Session->setFlash(__('The Quote Page could not be saved. Please, try again.', true));
}
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
$this->set('quoteid', $id);
$number_of_pages = $this->QuotePage->find('count', array('conditions' => array('QuotePage.quote_id'=>$id)));
$number_of_pages++;
$this->set('pagenumber', $number_of_pages);
}
if (!empty($this->data)) {
$this->QuotePage->create();
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The Quote Page has been saved', true));
$this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$this->data['QuotePage']['quote_id']));
} else {
$this->Session->setFlash(__('The Quote Page could not be saved. Please, try again.', true));
}
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
$this->set('quoteid', $id);
$number_of_pages = $this->QuotePage->find('count', array('conditions' => array('QuotePage.quote_id'=>$id)));
$number_of_pages++;
$this->set('pagenumber', $number_of_pages);
}
function edit($id = null) {
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid QuotePage', true));
$this->redirect(array('action'=>'index'));
}
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid QuotePage', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The QuotePage has been saved', true));
$id = $this->data['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));
}
}
if (empty($this->data)) {
$this->data = $this->QuotePage->read(null, $id);
$this->set('content', $this->data['QuotePage']['content']);
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
}
if (!empty($this->data)) {
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The QuotePage has been saved', true));
$id = $this->data['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));
}
}
if (empty($this->data)) {
$this->data = $this->QuotePage->read(null, $id);
$this->set('content', $this->data['QuotePage']['content']);
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for QuotePage', true));
$this->redirect(array('action'=>'index'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for QuotePage', true));
$this->redirect(array('action'=>'index'));
}
$quotepage = $this->QuotePage->findById($id);
$quoteid = $quotepage['QuotePage']['quote_id'];
$quotepage = $this->QuotePage->findById($id);
$quoteid = $quotepage['QuotePage']['quote_id'];
if ($this->QuotePage->del($id)) {
if ($this->QuotePage->del($id)) {
$this->Session->setFlash(__('Quote Page deleted', true));
$this->redirect(array('controller' => 'quotes' , 'action'=>'view', $quoteid));
}
}
$this->Session->setFlash(__('Quote Page deleted', true));
$this->redirect(array('controller' => 'quotes' , 'action'=>'view', $quoteid));
}
}
function show($id = null) {
$this->layout = 'ajax';
$this->set('quotePage', $this->QuotePage->read(null, $id));
function show($id = null) {
$this->layout = 'ajax';
$this->set('quotePage', $this->QuotePage->read(null, $id));
}
}
function frame($id = null) {
$this->layout = 'ajax';
$this->set('id', $id);
}
function frame($id = null) {
$this->layout = 'ajax';
$this->set('id', $id);
}
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):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
$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,65 +47,65 @@ else {
<?php endforeach; ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Cover Page', true), array('controller'=> 'quote_pages', 'action'=>'add/'.$quote['Quote']['id']));?> </li>
</ul>
</div>
<div class="actions">
<ul>
<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 class="related">
<h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Item Number'); ?></th>
<th><?php __('Quantity'); ?></th>
<th><?php __('Title'); ?></th>
<th><?php __('Description'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0" class="quoteproducts">
<tr>
<th><?php __('Item Number'); ?></th>
<th><?php __('Quantity'); ?></th>
<th><?php __('Title'); ?></th>
<th><?php __('Description'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($quoteProducts as $quoteProduct):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<?php
$i = 0;
foreach ($quoteProducts as $quoteProduct):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php
<td><?php
if($quoteProduct['QuoteProduct']['option'] == 1 ) {
echo 'Option <br>';
echo 'Option <br>';
}
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><?php echo $quoteProduct['QuoteProduct']['quantity'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['title'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['description'];?></td>
<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'])); ?>
</td>
<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'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Add Product to this Quote', true), array('controller'=> 'quote_products', 'action'=>'add', $quote['Quote']['id']));?> </li>
</ul>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Add Product to this Quote', true), array('controller'=> 'quote_products', 'action'=>'add', $quote['Quote']['id']));?> </li>
</ul>
</div>
</div>

File diff suppressed because it is too large Load diff

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);
}