Improved add LineItem to Product

This commit is contained in:
Karl Cordes 2010-02-19 16:38:43 +11:00
parent 698fe977f5
commit 70a1c14a48
18 changed files with 876 additions and 312 deletions

View file

@ -54,9 +54,7 @@ class CustomersController extends AppController {
$this->Session->setFlash(__('The Customer has been saved', true));
$this->redirect(array('action'=>'view', 'id'=>$newcustomerid));
}
else {
$this->Session->setFlash(__('The Customer could not be saved. Please try again.', true));
}
}
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('states', $this->Customer->Address->State->find('list'));
@ -99,13 +97,41 @@ class CustomersController extends AppController {
/* Autocomplete the customer name - Used in: add.ctp */
function completeCustomer() {
$this->set('customers', $this->Customer->find('all', array(
$query = strtolower($_GET["term"]);
if($query == null) {
return;
}
App::import('Core', 'Sanitize');
$query = Sanitize::clean($query);
$customers = $this->Customer->find('all', array(
'conditions' => array(
'Customer.name LIKE' => '%'.$this->data['Customer']['name'].'%'
'Customer.name LIKE' => '%'.$query.'%'
),'fields' => array('Customer.name')
)));
$this->layout = 'ajax';
));
foreach ($customers as $customer) {
$custid = $customer['Customer']['id'];
$cust_list[] = array('id'=> $custid, 'label' => $customer['Customer']['name']);
}
$customers_json = json_encode($cust_list);
$this->set('customers_json', $customers_json);
$this->layout = 'ajax';
}

View file

@ -451,15 +451,6 @@ class EnquiriesController extends AppController {
}
function jsonStatus($id = null) {
if($id == null) {
return null;
}
else {
}
}

View file

@ -91,5 +91,38 @@ class ProductsController extends AppController {
}
}
/**
*
* Outputs a select box with the Products that belong to a particular principal. Perhaps will change to an autocomplete in the future.
*/
function getPrincipleProducts() {
if(empty($this->data)) {
return;
}
else {
$this->set('products', $this->Product->find('list', array('conditions' =>
array('Product.principle_id'=> $this->data['LineItem']['principle_id']))));
}
}
function getProductOptions() {
if(empty($this->data)) {
return;
}
else {
}
}
}
?>

View file

@ -35,6 +35,8 @@ class QuotesController extends AppController {
$this->set('currencies', $currencies);
$this->set('principles', $this->Quote->Enquiry->Principle->find('list'));
}

View file

@ -15,12 +15,12 @@ class Customer extends AppModel {
'abn' => array(
'rule' => 'checkABN',
'required' => true,
'required' => false,
'message' => 'ABN must contain 11 digits',
'allowEmpty' => true,
)
);
/* Custom Validation for ABN */

112
vendors/xtcpdf.php vendored
View file

@ -71,8 +71,22 @@ class XTCPDF extends TCPDF {
* $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.';
*/
function Page1Footer() {
$this->SetY(-20);
$this->Image(K_PATH_IMAGES.'cmcfooter.jpg', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C');
$this->SetY(-30);
//$this->Image(K_PATH_IMAGES.'cmcfooter.jpg', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C');
$this->MultiCell(0, 2, "<hr>", 0, 'C', null, 1, null, null, true, 0, true, false);
// $this->MultiCell(0, 2, "PROVIDING SOLUTIONS IN", 0, 'C', null, 1, null, null, true, 0, true, false);
//$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(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->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);
}
/**
@ -202,7 +216,7 @@ class XTCPDF extends TCPDF {
$remainingHeight = $availableHeight;
$pageProducts = array(); //Array in the form $pageProducts[$pageNumber] = NUMBER_OF_ITEMS_ON_THIS_PAGE
foreach ($products as $product) {
@ -371,28 +385,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
* );
*
*
*/
/**
* 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->commercialComments($commercialDetails);
$this->AliasNbPages();
@ -421,36 +435,36 @@ class XTCPDF extends TCPDF {
/**
*
* 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
* );
*/
/**
*
* 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);
$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('now + '.$details["validFor"].' days');
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
$listHtmlContents = <<<ENDHTMLCONTENTS
$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>
@ -466,9 +480,9 @@ 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');
$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');
@ -478,7 +492,7 @@ ENDHTMLCONTENTS;
function termsAndConditions() {
}

View file

@ -1,6 +1,4 @@
<?php echo $this->element('tipbox', array('tip' => "Tip: When adding or removing Contact/Address entry forms, removing the first contact/address form will remove all of the dynamically added forms.
<br><br>Also, don't submit blank Contacts or Addresses - it may cause validation to fail and you'll have to re-enter the data. Remove any Contacts/Address forms you don't need."));
?>
<?php echo $javascript->link('autocomplete-customer'); ?>
<div class="customers form">
@ -8,11 +6,10 @@
<fieldset>
<legend><?php __('Add Customer');?></legend>
<?php
echo '<div class="input text">';
echo $form->label('Customer.name', 'Company Name');
echo $ajax->autoComplete('name', '/customers/completeCustomer');
echo $form->input('name', array('id'=>'customerName'));
echo "<br><br><span class=\"warning\">If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "<br>Do Not Add Duplicates.</span>";
echo '</div>';
echo $form->input('abn', array('label'=>'ABN', 'title' => 'The 11-digit Australian Business Number for the new Customer. Spaces or no spaces - it does not matter'));
echo $this->element('payment_terms_box');
@ -24,20 +21,7 @@
echo $form->input('notes', array('label' => 'Notes about this Customer'));
echo $form->input('url', array('label'=>'Website URL'));
echo '<br><br>';
?>
<div id="contacts0">
<? echo $ajax->link('Add A Contact to this New Customer', array('controller' => 'contacts', 'action' => 'add_another',0), array('update'=>'contacts0'));
echo $html->image('contact-new.png');
?>
</div>
<div id="addresses0">
<?
echo $ajax->link('Add an Address to this New Customer', array('controller' => 'addresses', 'action' => 'add_another',0), array('update'=>'addresses0')); ?>
<? echo $html->image('address-book-new.png'); ?>
</div>
<?
echo $form->end('Submit');
?>

View file

@ -1,6 +1,6 @@
<ul>
<?php foreach($customers as $customer): ?>
<li><?php echo $customer['Customer']['name']; ?></li>
<?php endforeach; ?>
</ul>
<?
if(isset($customers_json)) {
echo $customers_json;
}
?>

View file

@ -1,15 +1,14 @@
<?php echo $javascript->link('autocomplete-customer'); ?>
<div class="customers form">
<?php echo $this->element('tipbox', array('tip' => "Start typing the Company name into the box, a list of results should appear. Select the Customer you're looking for and click 'View'")); ?>
<?php echo $form->create('Customer', array('action'=>'find'));
echo '<h2>Find Customer';
echo $html->image('system-search.png');
echo '</h2>';
echo '<div class="input text">';
echo $form->label('Customer.name', 'Company Name');
echo $ajax->autoComplete('name', '/customers/completeCustomer');
echo '</div>';
echo $form->input('Customer.name', array('Label'=>'Customer Name', 'id'=>'customerName'));
echo $form->end('Find');
?>

View file

@ -14,15 +14,15 @@
echo $html->css('quotenik');
echo $html->css('jquery-ui.custom.css');
//echo $javascript->link('prototype');
//echo $javascript->link('scriptaculous');
echo $javascript->link('ckeditor/ckeditor');
//echo $javascript->link('validation');
echo $javascript->link('jquery');
echo $javascript->link('jquery-ui');
echo $javascript->link('jquery.form');
echo $scripts_for_layout;

View file

@ -1,36 +0,0 @@
<?
echo '<h3><a name="costing">Costing Buildup</a></h3>';
echo $form->input('Product.exchange_rate', array('id'=>'exchange_rate'));
echo $form->input('Product.cost_price_each', array('id'=>'costprice'));
echo $form->input('Product.our_discount', array('label'=>'Our Discount %', 'id' => 'ourdiscount'));
echo $form->input('Product.packing_each', array('id'=>'packing'));
echo '<div class="input text">';
echo $form->label('Product.fob_country_of_export', 'F.O.B Country of Export');
echo $form->text('Product.fob_country_of_export', array('readonly'=>'readonly', 'id'=>'fob_country_of_export'));
echo '</div>';
echo '<div class="input text">';
echo $form->label('Product.convert_to_aud', 'Convert to A$');
echo $form->text('Product.convert_to_aud', array('readonly'=>'readonly', 'id'=>'convert_to_aud'));
echo '</div>';
echo $form->input('Product.duty', array('label' => 'Duty %', 'id'=>'duty'));
echo $form->input('Product.shipping_weight_each', array('id'=>'shippingweight_each'));
echo $form->input('Product.shipping_cost_each', array('id'=>'shippingcost_each'));
echo $form->input('Product.customs', array('id'=>'customs'));
echo $form->input('Product.misc_cost', array('label' => 'Misc. Costs', 'id'=>'misc_cost'));
echo $form->input('Product.finance', array('label' => 'Finance %', 'id'=>'finance', 'after'=>'<p id="financeamount"> </p>'));
echo '<div class="input text">';
echo $form->label('Product.total_landed_cost', 'Total Landed Cost');
echo $form->text('Product.total_landed_cost', array('readonly'=>'readonly', 'id'=>'total_landed_cost'));
echo '</div>';
echo $form->input('Product.sellprice_each', array('label' => 'Sell Price Each', 'id'=>'sellprice_each'));
echo '<div class="input text">';
echo $form->label('Product.gross_profit_dollars', 'Gross Profit $');
echo $form->text('Product.gross_profit_dollars', array('readonly'=>'readonly', 'id'=>'gross_profit_dollars'));
echo '</div>';
echo '<div class="input text">';
echo $form->label('Product.gross_profit_percent', 'Gross Profit %');
echo $form->text('Product.gross_profit_prercent', array('readonly'=>'readonly', 'id'=>'gross_profit_percent'));
echo '</div>';
echo $ajax->observeForm('productaddform', array('frequency' => 0.5, 'complete'=>'buildup()'));
?>

View file

@ -0,0 +1,3 @@
<?
echo $form->input('LineItem.product_id', array('options' => $products, 'div' => false));
?>

View file

@ -1,136 +0,0 @@
<div class="products view">
<h2><?php __('Product');?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Principle'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($product['Principle']['name'], array('controller'=> 'principles', 'action'=>'view', $product['Principle']['id'])); ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Title'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['title']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Description'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['description']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Part Number'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['model_number']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Cost Price Each'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['cost_price_each']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Our Discount'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['our_discount']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Packing Each'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['packing_each']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Shipping Weight Each'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['shipping_weight_each']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Shipping Cost Each'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['shipping_cost_each']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Duty'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['duty']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Sellprice Each'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['sellprice_each']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Notes'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $product['Product']['notes']; ?>
&nbsp;
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit Product', true), array('action'=>'edit', $product['Product']['id'])); ?> </li>
</ul>
</div>
<div class="related">
<h3><?php __('Product Options');?></h3>
<?php if (!empty($product['ProductOption'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Title'); ?></th>
<th><?php __('Description'); ?></th>
<th><?php __('Cost Price'); ?></th>
<th><?php __('Our Discount'); ?></th>
<th><?php __('Packing Each'); ?></th>
<th><?php __('Shipping Weight Each'); ?></th>
<th><?php __('Shipping Cost Each'); ?></th>
<th><?php __('Duty'); ?></th>
<th><?php __('Sell Price'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($product['ProductOption'] as $productOption):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $productOption['title'];?></td>
<td><?php echo $productOption['description'];?></td>
<td><?php echo $productOption['cost_price'];?></td>
<td><?php echo $productOption['our_discount'];?></td>
<td><?php echo $productOption['packing_each'];?></td>
<td><?php echo $productOption['shipping_weight_each'];?></td>
<td><?php echo $productOption['shipping_cost_each'];?></td>
<td><?php echo $productOption['duty'];?></td>
<td><?php echo $productOption['sell_price'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'product_options', 'action'=>'view', $productOption['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'product_options', 'action'=>'edit', $productOption['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'product_options', 'action'=>'delete', $productOption['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $productOption['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Product Option', true), array('controller'=> 'product_options', 'action'=>'add'));?> </li>
</ul>
</div>
</div>
<div class="related">
<h3><?php if($number_of_files == 1) {
__($number_of_files.' Attachment in this Product');
}
else {
__($number_of_files.' Attachments in this Product');
}
?>
<?php echo $html->image('document.png'); ?></h3>
<?php echo $this->element('product_attachment_table', $files); ?>
</div>
<?php debug($product); ?>

View file

@ -217,16 +217,32 @@ foreach ($quote['QuotePage'] as $quotePage):
<?php echo $form->create('LineItem');?>
<?php
echo $form->input('principle_id', array('options'=>$principles));
?>
<div id="productBox" class="input select"></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');
echo $form->input('quote_id');
echo $form->input('product_id');
echo $form->input('costing_id');
echo $form->input('unit_price');
?>
</div>
<?php echo $form->end('Submit');?>
</div>

View file

@ -746,40 +746,6 @@ input#searchbox {
width: 100px;
}
/* CSS from Easy Prototype Validation Script */
input.disabled {
background-color: #D8D8D8;
}
input.required, textarea.required {
border: 1px solid #00A8E6;
}
input.validation-failed, textarea.validation-failed {
border: 1px solid #FF3300;
color : #FF3300;
}
input.validation-passed, textarea.validation-passed {
border: 1px solid #00CC00;
color : #000;
}
.validation-advice {
margin: 5px 0;
padding: 5px;
background-color: #FF3300;
color : #FFF;
font-weight: bold;
}
.custom-advice {
margin: 5px 0;
padding: 5px;
background-color: #C8AA00;
color : #FFF;
font-weight: bold;
}
/* End CSS from that script */
select {
clear: both;

View file

@ -14,8 +14,8 @@ $(function() {
$("#addLineItem-form").dialog({
autoOpen: false,
height: 640,
width: 480,
height: 800,
width: 800,
modal: true,
buttons: {
'Add Product': function() {
@ -34,9 +34,28 @@ $(function() {
$('#addLineItem')
.button()
.click(function() {
$('#addLineItem-form2').hide();
$('#addLineItem-form').dialog('open');
});
});
$("#LineItemPrincipleId").change(getPrincipleProducts);
});
/**
* get a list (in JSON) of Products that belong to a particular principle
*
* puts the output in a div called productBox
*/
function getPrincipleProducts() {
$.post("/products/getPrincipleProducts", $("#LineItemAddForm").serialize(), function(data) {
$("#productBox").html(data);
});
}

View file

@ -0,0 +1,18 @@
/*
* autocomplete-customer.js
*
*
*
*/
$(function() {
$("#customerName").autocomplete({
source: "/customers/completeCustomer",
minLength: 1
});
});

665
webroot/js/jquery.form.js Normal file
View file

@ -0,0 +1,665 @@
/*
* jQuery Form Plugin
* version: 2.38 (13-FEB-2010)
* @requires jQuery v1.3.2 or later
*
* Examples and documentation at: http://malsup.com/jquery/form/
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
;(function($) {
/*
Usage Note:
-----------
Do not use both ajaxSubmit and ajaxForm on the same form. These
functions are intended to be exclusive. Use ajaxSubmit if you want
to bind your own submit handler to the form. For example,
$(document).ready(function() {
$('#myForm').bind('submit', function() {
$(this).ajaxSubmit({
target: '#output'
});
return false; // <-- important!
});
});
Use ajaxForm when you want the plugin to manage all the event binding
for you. For example,
$(document).ready(function() {
$('#myForm').ajaxForm({
target: '#output'
});
});
When using ajaxForm, the ajaxSubmit function will be invoked for you
at the appropriate time.
*/
/**
* ajaxSubmit() provides a mechanism for immediately submitting
* an HTML form using AJAX.
*/
$.fn.ajaxSubmit = function(options) {
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
if (!this.length) {
log('ajaxSubmit: skipping submit process - no element selected');
return this;
}
if (typeof options == 'function')
options = { success: options };
var url = $.trim(this.attr('action'));
if (url) {
// clean url (don't include hash vaue)
url = (url.match(/^([^#]+)/)||[])[1];
}
url = url || window.location.href || '';
options = $.extend({
url: url,
type: this.attr('method') || 'GET',
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
}, options || {});
// hook for manipulating the form data before it is extracted;
// convenient for use with rich editors like tinyMCE or FCKEditor
var veto = {};
this.trigger('form-pre-serialize', [this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
return this;
}
// provide opportunity to alter form data before it is serialized
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSerialize callback');
return this;
}
var a = this.formToArray(options.semantic);
if (options.data) {
options.extraData = options.data;
for (var n in options.data) {
if(options.data[n] instanceof Array) {
for (var k in options.data[n])
a.push( { name: n, value: options.data[n][k] } );
}
else
a.push( { name: n, value: options.data[n] } );
}
}
// give pre-submit callback an opportunity to abort the submit
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSubmit callback');
return this;
}
// fire vetoable 'validate' event
this.trigger('form-submit-validate', [a, this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
return this;
}
var q = $.param(a);
if (options.type.toUpperCase() == 'GET') {
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
options.data = null; // data is null for 'get'
}
else
options.data = q; // data is the query string for 'post'
var $form = this, callbacks = [];
if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
if (options.clearForm) callbacks.push(function() { $form.clearForm(); });
// perform a load on the target only if dataType is not provided
if (!options.dataType && options.target) {
var oldSuccess = options.success || function(){};
callbacks.push(function(data) {
$(options.target).html(data).each(oldSuccess, arguments);
});
}
else if (options.success)
callbacks.push(options.success);
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
for (var i=0, max=callbacks.length; i < max; i++)
callbacks[i].apply(options, [data, status, xhr || $form, $form]);
};
// are there files to upload?
var files = $('input:file', this).fieldValue();
var found = false;
for (var j=0; j < files.length; j++)
if (files[j])
found = true;
var multipart = false;
// var mp = 'multipart/form-data';
// multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
// options.iframe allows user to force iframe mode
// 06-NOV-09: now defaulting to iframe mode if file input is detected
if ((files.length && options.iframe !== false) || options.iframe || found || multipart) {
// hack to fix Safari hang (thanks to Tim Molendijk for this)
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
if (options.closeKeepAlive)
$.get(options.closeKeepAlive, fileUpload);
else
fileUpload();
}
else
$.ajax(options);
// fire 'notify' event
this.trigger('form-submit-notify', [this, options]);
return this;
// private function for handling file uploads (hat tip to YAHOO!)
function fileUpload() {
var form = $form[0];
if ($(':input[name=submit]', form).length) {
alert('Error: Form elements must not be named "submit".');
return;
}
var opts = $.extend({}, $.ajaxSettings, options);
var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
var id = 'jqFormIO' + (new Date().getTime());
var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ opts.iframeSrc +'" />');
var io = $io[0];
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
var xhr = { // mock object
aborted: 0,
responseText: null,
responseXML: null,
status: 0,
statusText: 'n/a',
getAllResponseHeaders: function() {},
getResponseHeader: function() {},
setRequestHeader: function() {},
abort: function() {
this.aborted = 1;
$io.attr('src', opts.iframeSrc); // abort op in progress
}
};
var g = opts.global;
// trigger ajax global events so that activity/block indicators work like normal
if (g && ! $.active++) $.event.trigger("ajaxStart");
if (g) $.event.trigger("ajaxSend", [xhr, opts]);
if (s.beforeSend && s.beforeSend(xhr, s) === false) {
s.global && $.active--;
return;
}
if (xhr.aborted)
return;
var cbInvoked = 0;
var timedOut = 0;
// add submitting element to data if we know it
var sub = form.clk;
if (sub) {
var n = sub.name;
if (n && !sub.disabled) {
opts.extraData = opts.extraData || {};
opts.extraData[n] = sub.value;
if (sub.type == "image") {
opts.extraData[name+'.x'] = form.clk_x;
opts.extraData[name+'.y'] = form.clk_y;
}
}
}
// take a breath so that pending repaints get some cpu time before the upload starts
function doSubmit() {
// make sure form attrs are set
var t = $form.attr('target'), a = $form.attr('action');
// update form attrs in IE friendly way
form.setAttribute('target',id);
if (form.getAttribute('method') != 'POST')
form.setAttribute('method', 'POST');
if (form.getAttribute('action') != opts.url)
form.setAttribute('action', opts.url);
// ie borks in some cases when setting encoding
if (! opts.skipEncodingOverride) {
$form.attr({
encoding: 'multipart/form-data',
enctype: 'multipart/form-data'
});
}
// support timout
if (opts.timeout)
setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
// add "extra" data to form if provided in options
var extraInputs = [];
try {
if (opts.extraData)
for (var n in opts.extraData)
extraInputs.push(
$('<input type="hidden" name="'+n+'" value="'+opts.extraData[n]+'" />')
.appendTo(form)[0]);
// add iframe to doc and submit the form
$io.appendTo('body');
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
form.submit();
}
finally {
// reset attrs and remove "extra" input elements
form.setAttribute('action',a);
t ? form.setAttribute('target', t) : $form.removeAttr('target');
$(extraInputs).remove();
}
};
if (opts.forceSync)
doSubmit();
else
setTimeout(doSubmit, 10); // this lets dom updates render
var domCheckCount = 50;
function cb() {
if (cbInvoked++) return;
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
var ok = true;
try {
if (timedOut) throw 'timeout';
// extract the server response from the iframe
var data, doc;
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
var isXml = opts.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
log('isXml='+isXml);
if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
if (--domCheckCount) {
// in some browsers (Opera) the iframe DOM is not always traversable when
// the onload callback fires, so we loop a bit to accommodate
cbInvoked = 0;
setTimeout(cb, 100);
return;
}
log('Could not access iframe DOM after 50 tries.');
return;
}
xhr.responseText = doc.body ? doc.body.innerHTML : null;
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
xhr.getResponseHeader = function(header){
var headers = {'content-type': opts.dataType};
return headers[header];
};
if (opts.dataType == 'json' || opts.dataType == 'script') {
// see if user embedded response in textarea
var ta = doc.getElementsByTagName('textarea')[0];
if (ta)
xhr.responseText = ta.value;
else {
// account for browsers injecting pre around json response
var pre = doc.getElementsByTagName('pre')[0];
if (pre)
xhr.responseText = pre.innerHTML;
}
}
else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
xhr.responseXML = toXml(xhr.responseText);
}
data = $.httpData(xhr, opts.dataType);
}
catch(e){
ok = false;
$.handleError(opts, xhr, 'error', e);
}
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
if (ok) {
opts.success(data, 'success');
if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
}
if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
if (g && ! --$.active) $.event.trigger("ajaxStop");
if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
// clean up
setTimeout(function() {
$io.remove();
xhr.responseXML = null;
}, 100);
};
function toXml(s, doc) {
if (window.ActiveXObject) {
doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML(s);
}
else
doc = (new DOMParser()).parseFromString(s, 'text/xml');
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
};
};
};
/**
* ajaxForm() provides a mechanism for fully automating form submission.
*
* The advantages of using this method instead of ajaxSubmit() are:
*
* 1: This method will include coordinates for <input type="image" /> elements (if the element
* is used to submit the form).
* 2. This method will include the submit element's name/value data (for the element that was
* used to submit the form).
* 3. This method binds the submit() method to the form for you.
*
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
* passes the options argument along after properly binding events for submit elements and
* the form itself.
*/
$.fn.ajaxForm = function(options) {
return this.ajaxFormUnbind().bind('submit.form-plugin', function() {
$(this).ajaxSubmit(options);
return false;
}).bind('click.form-plugin', function(e) {
var target = e.target;
var $el = $(target);
if (!($el.is(":submit,input:image"))) {
// is this a child element of the submit el? (ex: a span within a button)
var t = $el.closest(':submit');
if (t.length == 0)
return;
target = t[0];
}
var form = this;
form.clk = target;
if (target.type == 'image') {
if (e.offsetX != undefined) {
form.clk_x = e.offsetX;
form.clk_y = e.offsetY;
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
var offset = $el.offset();
form.clk_x = e.pageX - offset.left;
form.clk_y = e.pageY - offset.top;
} else {
form.clk_x = e.pageX - target.offsetLeft;
form.clk_y = e.pageY - target.offsetTop;
}
}
// clear form vars
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
});
};
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
return this.unbind('submit.form-plugin click.form-plugin');
};
/**
* formToArray() gathers form element data into an array of objects that can
* be passed to any of the following ajax functions: $.get, $.post, or load.
* Each object in the array has both a 'name' and 'value' property. An example of
* an array for a simple login form might be:
*
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
*
* It is this array that is passed to pre-submit callback functions provided to the
* ajaxSubmit() and ajaxForm() methods.
*/
$.fn.formToArray = function(semantic) {
var a = [];
if (this.length == 0) return a;
var form = this[0];
var els = semantic ? form.getElementsByTagName('*') : form.elements;
if (!els) return a;
for(var i=0, max=els.length; i < max; i++) {
var el = els[i];
var n = el.name;
if (!n) continue;
if (semantic && form.clk && el.type == "image") {
// handle image inputs on the fly when semantic == true
if(!el.disabled && form.clk == el) {
a.push({name: n, value: $(el).val()});
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
continue;
}
var v = $.fieldValue(el, true);
if (v && v.constructor == Array) {
for(var j=0, jmax=v.length; j < jmax; j++)
a.push({name: n, value: v[j]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: n, value: v});
}
if (!semantic && form.clk) {
// input type=='image' are not found in elements array! handle it here
var $input = $(form.clk), input = $input[0], n = input.name;
if (n && !input.disabled && input.type == 'image') {
a.push({name: n, value: $input.val()});
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
}
return a;
};
/**
* Serializes form data into a 'submittable' string. This method will return a string
* in the format: name1=value1&amp;name2=value2
*/
$.fn.formSerialize = function(semantic) {
//hand off to jQuery.param for proper encoding
return $.param(this.formToArray(semantic));
};
/**
* Serializes all field elements in the jQuery object into a query string.
* This method will return a string in the format: name1=value1&amp;name2=value2
*/
$.fn.fieldSerialize = function(successful) {
var a = [];
this.each(function() {
var n = this.name;
if (!n) return;
var v = $.fieldValue(this, successful);
if (v && v.constructor == Array) {
for (var i=0,max=v.length; i < max; i++)
a.push({name: n, value: v[i]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: this.name, value: v});
});
//hand off to jQuery.param for proper encoding
return $.param(a);
};
/**
* Returns the value(s) of the element in the matched set. For example, consider the following form:
*
* <form><fieldset>
* <input name="A" type="text" />
* <input name="A" type="text" />
* <input name="B" type="checkbox" value="B1" />
* <input name="B" type="checkbox" value="B2"/>
* <input name="C" type="radio" value="C1" />
* <input name="C" type="radio" value="C2" />
* </fieldset></form>
*
* var v = $(':text').fieldValue();
* // if no values are entered into the text inputs
* v == ['','']
* // if values entered into the text inputs are 'foo' and 'bar'
* v == ['foo','bar']
*
* var v = $(':checkbox').fieldValue();
* // if neither checkbox is checked
* v === undefined
* // if both checkboxes are checked
* v == ['B1', 'B2']
*
* var v = $(':radio').fieldValue();
* // if neither radio is checked
* v === undefined
* // if first radio is checked
* v == ['C1']
*
* The successful argument controls whether or not the field element must be 'successful'
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
* The default value of the successful argument is true. If this value is false the value(s)
* for each element is returned.
*
* Note: This method *always* returns an array. If no valid value can be determined the
* array will be empty, otherwise it will contain one or more values.
*/
$.fn.fieldValue = function(successful) {
for (var val=[], i=0, max=this.length; i < max; i++) {
var el = this[i];
var v = $.fieldValue(el, successful);
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
continue;
v.constructor == Array ? $.merge(val, v) : val.push(v);
}
return val;
};
/**
* Returns the value of the field element.
*/
$.fieldValue = function(el, successful) {
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
if (typeof successful == 'undefined') successful = true;
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
(t == 'checkbox' || t == 'radio') && !el.checked ||
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
tag == 'select' && el.selectedIndex == -1))
return null;
if (tag == 'select') {
var index = el.selectedIndex;
if (index < 0) return null;
var a = [], ops = el.options;
var one = (t == 'select-one');
var max = (one ? index+1 : ops.length);
for(var i=(one ? index : 0); i < max; i++) {
var op = ops[i];
if (op.selected) {
var v = op.value;
if (!v) // extra pain for IE...
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
if (one) return v;
a.push(v);
}
}
return a;
}
return el.value;
};
/**
* Clears the form data. Takes the following actions on the form's input fields:
* - input text fields will have their 'value' property set to the empty string
* - select elements will have their 'selectedIndex' property set to -1
* - checkbox and radio inputs will have their 'checked' property set to false
* - inputs of type submit, button, reset, and hidden will *not* be effected
* - button elements will *not* be effected
*/
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).clearFields();
});
};
/**
* Clears the selected form elements.
*/
$.fn.clearFields = $.fn.clearInputs = function() {
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (t == 'text' || t == 'password' || tag == 'textarea')
this.value = '';
else if (t == 'checkbox' || t == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
/**
* Resets the form data. Causes all form elements to be reset to their original value.
*/
$.fn.resetForm = function() {
return this.each(function() {
// guard against an input with the name of 'reset'
// note that IE reports the reset function as an 'object'
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
this.reset();
});
};
/**
* Enables or disables any matching elements.
*/
$.fn.enable = function(b) {
if (b == undefined) b = true;
return this.each(function() {
this.disabled = !b;
});
};
/**
* Checks/unchecks any matching checkboxes or radio buttons and
* selects/deselects and matching option elements.
*/
$.fn.selected = function(select) {
if (select == undefined) select = true;
return this.each(function() {
var t = this.type;
if (t == 'checkbox' || t == 'radio')
this.checked = select;
else if (this.tagName.toLowerCase() == 'option') {
var $sel = $(this).parent('select');
if (select && $sel[0] && $sel[0].type == 'select-one') {
// deselect all other options
$sel.find('option').selected(false);
}
this.selected = select;
}
});
};
// helper fn for console logging
// set $.fn.ajaxSubmit.debug to true to enable debug logging
function log() {
if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
};
})(jQuery);