Jquery line item add working. Need to make jquery now do the math on the product table
This commit is contained in:
parent
ec67ed76e2
commit
207b45a720
|
|
@ -2,7 +2,9 @@
|
|||
class LineItemsController extends AppController {
|
||||
|
||||
var $name = 'LineItems';
|
||||
var $helpers = array('Html', 'Form');
|
||||
var $helpers = array('Html', 'Form', 'Javascript');
|
||||
|
||||
var $components = array('RequestHandler');
|
||||
|
||||
function index() {
|
||||
$this->LineItem->recursive = 0;
|
||||
|
|
@ -34,13 +36,13 @@ class LineItemsController extends AppController {
|
|||
$this->data['LineItem']['description'] = $product['Product']['description'];
|
||||
$this->data['LineItem']['title'] = $product['Product']['title'];
|
||||
|
||||
|
||||
$numberOfItems = $this->LineItem->find('count',
|
||||
array('conditions' => array('LineItem.quote_id' => $this->data['LineItem']['quote_id'])));
|
||||
|
||||
$numberOfItems++;
|
||||
// $numberOfItems = $this->LineItem->find('count',
|
||||
// array('conditions' => array('LineItem.quote_id' => $this->data['LineItem']['quote_id'])));
|
||||
|
||||
$this->data['LineItem']['item_number'] = $numberOfItems;
|
||||
//$numberOfItems++;
|
||||
|
||||
// $this->data['LineItem']['item_number'] = $numberOfItems;
|
||||
|
||||
|
||||
|
||||
|
|
@ -60,6 +62,46 @@ class LineItemsController extends AppController {
|
|||
$quote = $this->LineItem->Quote->read(null, $quoteid);
|
||||
$this->set(compact('principles','quote', 'products'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Process the Line Item and add it to a quote */
|
||||
function ajaxSave() {
|
||||
|
||||
|
||||
if($this->RequestHandler->isAjax()) {
|
||||
|
||||
if (!empty($this->data)) {
|
||||
$this->LineItem->create();
|
||||
$product = $this->LineItem->Product->findById($this->data['LineItem']['product_id']);
|
||||
|
||||
/* Copy all the data from the Product to the new LineItem */
|
||||
$this->data['LineItem']['description'] = $product['Product']['description'];
|
||||
$this->data['LineItem']['title'] = $product['Product']['title'];
|
||||
|
||||
|
||||
if($this->LineItem->save($this->data)) {
|
||||
echo 'success';
|
||||
}
|
||||
else {
|
||||
echo 'failure';
|
||||
}
|
||||
Configure::write('debug', 0);
|
||||
$this->autoRender = false;
|
||||
exit();
|
||||
|
||||
|
||||
/* Need to find a way to append Product Option data to the description / model number title */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -98,14 +98,15 @@ class ProductsController extends AppController {
|
|||
*/
|
||||
function getPrincipleProducts() {
|
||||
|
||||
if(empty($this->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($this->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
$this->set('products', $this->Product->find('list', array('conditions' =>
|
||||
array('Product.principle_id'=> $this->data['LineItem']['principle_id']))));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,8 +117,10 @@ class ProductsController extends AppController {
|
|||
}
|
||||
|
||||
else {
|
||||
$this->set('productOptions', $this->Product->findById($this->data['LineItem']['product_id']));
|
||||
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC')));
|
||||
|
||||
$this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC')));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ class QuotesController extends AppController {
|
|||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'dateIssued' => (String) eg. 2009-05-20
|
||||
* 'daysValid' => (Int) eg. 30
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
|
|
@ -165,6 +166,7 @@ class QuotesController extends AppController {
|
|||
$commercialDetails = array (
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class Customer extends AppModel {
|
|||
|
||||
var $name = 'Customer';
|
||||
|
||||
var $displayField = 'email';
|
||||
|
||||
var $validate = array(
|
||||
'name' => array(
|
||||
|
|
|
|||
12
vendors/xtcpdf.php
vendored
12
vendors/xtcpdf.php
vendored
|
|
@ -78,10 +78,10 @@ class XTCPDF extends TCPDF {
|
|||
//$this->ln();
|
||||
//$this->ln();
|
||||
$this->SetFontSize(12);
|
||||
$this->MultiCell(120, 2, "<span style=\"color: #8A4B08; font-weight: bold\">EXPLOSION PREVENTION AND PROTECTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
|
||||
$this->MultiCell(120, 2, "<span style=\"color: #B40404; font-weight: bold\">EXPLOSION PREVENTION AND PROTECTION</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->ln();
|
||||
$this->MultiCell(0, 2, "<span style=\"color: #088A4B; font-weight: bold\">VISION IN THE PROCESS</span>", 0, 'C', null, 1, 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);
|
||||
|
|
@ -92,7 +92,7 @@ class XTCPDF extends TCPDF {
|
|||
/**
|
||||
* For Quotes and (hopefully) Invoices. Identifies who the document is for, date, reference number, etc.
|
||||
*/
|
||||
function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber, $your_reference) {
|
||||
function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber, $your_reference, $issuedate) {
|
||||
|
||||
$this->SetTextColor(0); //Black Text
|
||||
|
||||
|
|
@ -136,8 +136,9 @@ class XTCPDF extends TCPDF {
|
|||
$this->MultiCell($thirdColWidth, 0, "PAGE: ", 'LB', 'L', 0, 0);
|
||||
$this->MultiCell($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1);
|
||||
|
||||
$todayPHPdate = strtotime($issuedate);
|
||||
|
||||
$todaysDateString = date('l, j F Y');
|
||||
$todaysDateString = date('l, j F Y', $todayPHPdate);
|
||||
$this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0);
|
||||
$this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0);
|
||||
|
||||
|
|
@ -445,6 +446,7 @@ class XTCPDF extends TCPDF {
|
|||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'dateIssued' => (String) eg. 2009-05-10
|
||||
* 'validFor' => (String) eg. 30 Days
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
|
|
@ -460,7 +462,7 @@ class XTCPDF extends TCPDF {
|
|||
$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');
|
||||
$validUntilDate = strtotime($details["dateIssued"]. ' + '.$details["validFor"].' days');
|
||||
|
||||
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
echo $javascript->link('jquery-ui');
|
||||
echo $javascript->link('jquery.form');
|
||||
|
||||
|
||||
echo $scripts_for_layout;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
<?
|
||||
echo $form->input('LineItem.product_id', array('options' => $products, 'div' => false, 'empty'=>'Select the Product'));
|
||||
|
||||
//echo $javascript->object($products);
|
||||
?>
|
||||
|
|
@ -1,3 +1,48 @@
|
|||
|
||||
<?
|
||||
print_r($productOptions);
|
||||
foreach ($options as $opt) {
|
||||
|
||||
$default_option = '';
|
||||
foreach($opt['ProductOption'] as $prodopt) {
|
||||
|
||||
|
||||
/* Make it the default selected if it's the default option
|
||||
* Logic that enforces only 1 default option to be added to the product_options controller
|
||||
*/
|
||||
|
||||
|
||||
if($prodopt['model_number'] != null) {
|
||||
$drop_options[$prodopt['id']] = $prodopt['model_number'].": ".$prodopt['title'];
|
||||
}
|
||||
else {
|
||||
$drop_options[$prodopt['id']] = $prodopt['title'];
|
||||
}
|
||||
|
||||
if($prodopt['default'] == 1) {
|
||||
$default_option = $prodopt['id'];
|
||||
|
||||
$drop_options[$prodopt['id']] .= " (Default)";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If it's an exclusive category, display a drop down box. Otherwise, check boxes
|
||||
*/
|
||||
if($opt['ProductOptionsCategory']['exclusive'] == 1) {
|
||||
echo $form->input('ProductOption.'.$opt['ProductOptionsCategory']['name'],
|
||||
array('label' => $opt['ProductOptionsCategory']['name'],
|
||||
'options' => $drop_options, 'default' => $default_option));
|
||||
}
|
||||
|
||||
else {
|
||||
echo $form->input($opt['ProductOptionsCategory']['name'],
|
||||
array('options' => $drop_options, 'default' => $default_option,
|
||||
'multiple' => 'checkbox'));
|
||||
}
|
||||
|
||||
unset($drop_options);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
@ -53,7 +53,7 @@ foreach ($quote['QuotePage'] as $page) {
|
|||
|
||||
$tcpdf->DetailsBox($enquiry['Customer']['name'], $enquiry['Contact']['email'], $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'],
|
||||
$enquiry['User']['first_name'].' '.$enquiry['User']['last_name'], $enquiry['User']['email'], $cmcRef,
|
||||
$enquiry['Enquiry']['customer_reference']);
|
||||
$enquiry['Enquiry']['customer_reference'], $quote['Quote']['date_issued']);
|
||||
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
__('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision'].' for '. $customer_link);
|
||||
}
|
||||
?></h2>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
|
@ -61,7 +59,7 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
<div class="quoteproducts">
|
||||
<h3><?php __('Products in this Quote');?></h3>
|
||||
<?php if (!empty($quoteProducts)):?>
|
||||
<table cellpadding = "0" cellspacing = "0" class="quoteproducts">
|
||||
<table cellpadding = "0" cellspacing = "0" id= "quoteTable" class="quoteproducts" ">
|
||||
<tr>
|
||||
<th><?php __('Item Number'); ?></th>
|
||||
<th><?php __('Quantity'); ?></th>
|
||||
|
|
@ -167,7 +165,7 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
|
||||
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
</table>
|
||||
|
|
@ -192,7 +190,25 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
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('date_issued');
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
//format the mySQL date in the nice readable format.
|
||||
$phpdate_issued = strtotime($quote['Quote']['date_issued']);
|
||||
|
||||
$date_issued_readable = date('l j F Y', $phpdate_issued );
|
||||
|
||||
?>
|
||||
<div class="input select">
|
||||
<label for="QuoteDateIssuedDisplay">Date Issued</label>
|
||||
<input id="QuoteDateIssuedDisplay" type="text" value="<?php echo $date_issued_readable; ?>">
|
||||
</div>
|
||||
|
||||
<input id="QuoteDateIssued" type="hidden" name="data[Quote][date_issued]" value="<?php echo $quote['Quote']['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'));
|
||||
|
|
@ -215,24 +231,28 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
|
||||
<div id="addLineItem-form" title="Add a Product to this quote">
|
||||
<?php echo $form->create('LineItem');?>
|
||||
|
||||
<?php
|
||||
|
||||
echo $form->input('principle_id', array('options'=>$principles, 'empty' =>'Select the Principle for this Product'));
|
||||
?>
|
||||
|
||||
<div id="productBox" class="input select"></div>
|
||||
<?php
|
||||
|
||||
echo $form->input('quote_id', array('type'=>'hidden', 'value'=>$quote['Quote']['id']));
|
||||
echo $form->input('item_number');
|
||||
echo $form->input('option', array('label'=>'Optional Item'));
|
||||
|
||||
echo $form->input('quantity');
|
||||
echo $form->input('principle_id', array('options'=>$principles, 'empty' =>'Select the Principle for this Product'));
|
||||
|
||||
|
||||
<div id="addLineItem-form2">
|
||||
?>
|
||||
|
||||
<div id="productBox"></div>
|
||||
|
||||
<div id="productOptionsBox"></div>
|
||||
|
||||
<div id="productTitle"></div>
|
||||
|
||||
<div id="addLineItem-form2">
|
||||
<?
|
||||
echo $form->input('item_number');
|
||||
echo $form->input('option');
|
||||
|
||||
|
||||
|
||||
|
||||
echo $form->input('quantity');
|
||||
/*
|
||||
echo $form->input('title');
|
||||
echo $form->input('description');
|
||||
|
||||
|
|
@ -241,15 +261,18 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
echo $form->input('product_id');
|
||||
echo $form->input('costing_id');
|
||||
echo $form->input('unit_price');
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php echo $form->end('Submit');?>
|
||||
*/
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php //echo $form->end('Submit');
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<?php debug ($quoteProducts); ?>
|
||||
<?php // debug ($quoteProducts); ?>
|
||||
|
||||
<?php foreach ($quoteProducts as $quoteProduct) {
|
||||
|
||||
|
|
@ -261,4 +284,4 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
|
||||
?>
|
||||
|
||||
}
|
||||
<div id="mydebug"></div>
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Brings up a jQuery modal form dialog for adding a line item to a quote/job/invoice
|
||||
*
|
||||
*
|
||||
* Also does the date picker on the commercial details. Might change the commercial details so they're all javacript sexy too.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
$(function() {
|
||||
|
||||
|
||||
|
||||
|
||||
$("#addLineItem-form").dialog({
|
||||
autoOpen: false,
|
||||
height: 800,
|
||||
|
|
@ -19,14 +22,19 @@ $(function() {
|
|||
modal: true,
|
||||
buttons: {
|
||||
'Add Product': function() {
|
||||
alert('validation stuff here');
|
||||
|
||||
$.post("/line_items/ajaxSave", $("#LineItemAddForm").serialize(), function(data) {
|
||||
$('#mydebug').html(data);
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
Cancel: function() {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
},
|
||||
close: function() {
|
||||
//What happens on close goes here.
|
||||
//What happens on close goes here.
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -35,42 +43,71 @@ $(function() {
|
|||
.button()
|
||||
.click(function() {
|
||||
$('#addLineItem-form2').hide();
|
||||
|
||||
$('#addLineItem-form').dialog('open');
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#LineItemPrincipleId").change(getPrincipleProducts);
|
||||
|
||||
$('#QuoteDateIssuedDisplay').datepicker({
|
||||
showButtonPanel: true,
|
||||
dateFormat: 'DD d MM yy',
|
||||
altFormat: 'yy-mm-dd',
|
||||
altField: '#QuoteDateIssued'
|
||||
|
||||
$("#LineItemProductId").change(getProductOptions); //broken because this ID doesnt exist yet.
|
||||
//Ways to fix this. Quick and nasty to have a blank div or span that we destroy.. or something.
|
||||
// Better, maybe have the element already existing, and just update and show it with JSON data.
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get a list (in JSON) of Products that belong to a particular principle
|
||||
* Updates the productBox div with a Select Box of the products.
|
||||
*
|
||||
* puts the output in a div called productBox
|
||||
*/
|
||||
function getPrincipleProducts() {
|
||||
$.post("/products/getPrincipleProducts", $("#LineItemAddForm").serialize(), function(data) {
|
||||
$("#productBox").html(data);
|
||||
$.post("/products/getPrincipleProducts", $("#LineItemPrincipleId").serialize(), function(data) {
|
||||
|
||||
|
||||
|
||||
$('#productBox').html(data);
|
||||
$("#LineItemProductId").change(getProductOptions);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Ajax Request to get the Product Options (if any) for the Product selected
|
||||
*/
|
||||
|
||||
function getProductOptions() {
|
||||
alert('FARK');
|
||||
$.post("/products/getProductOptions", $("#LineItemAddForm").serialize(), function(optionData) {
|
||||
alert(optionData);
|
||||
|
||||
$.post("/products/getProductOptions", $("#LineItemProductId").serialize(), function(optionData) {
|
||||
$("#productOptionsBox").html(optionData);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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.');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue