From 207b45a720c6d4a08cb431c928f15100d359fa09 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 23 Feb 2010 14:49:19 +1100 Subject: [PATCH] Jquery line item add working. Need to make jquery now do the math on the product table --- controllers/line_items_controller.php | 54 +++++++++++++++-- controllers/products_controller.php | 15 +++-- controllers/quotes_controller.php | 2 + models/customer.php | 1 + vendors/xtcpdf.php | 12 ++-- views/layouts/default.ctp | 1 + views/products/get_principle_products.ctp | 2 + views/products/get_product_options.ctp | 47 ++++++++++++++- views/quotes/pdf.ctp | 2 +- views/quotes/view.ctp | 73 +++++++++++++++-------- webroot/js/addLineItem.js | 65 +++++++++++++++----- 11 files changed, 216 insertions(+), 58 deletions(-) diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php index ce2b00ad..31dbd85e 100644 --- a/controllers/line_items_controller.php +++ b/controllers/line_items_controller.php @@ -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 */ + + + } + + + } + + + + } diff --git a/controllers/products_controller.php b/controllers/products_controller.php index 9344079f..03e2da2a 100755 --- a/controllers/products_controller.php +++ b/controllers/products_controller.php @@ -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'))); + + } diff --git a/controllers/quotes_controller.php b/controllers/quotes_controller.php index 2d6bac4a..6aa48527 100755 --- a/controllers/quotes_controller.php +++ b/controllers/quotes_controller.php @@ -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']), diff --git a/models/customer.php b/models/customer.php index 5278c32b..3a9cdc72 100755 --- a/models/customer.php +++ b/models/customer.php @@ -3,6 +3,7 @@ class Customer extends AppModel { var $name = 'Customer'; + var $displayField = 'email'; var $validate = array( 'name' => array( diff --git a/vendors/xtcpdf.php b/vendors/xtcpdf.php index 42024429..17cd85e1 100755 --- a/vendors/xtcpdf.php +++ b/vendors/xtcpdf.php @@ -78,10 +78,10 @@ class XTCPDF extends TCPDF { //$this->ln(); //$this->ln(); $this->SetFontSize(12); - $this->MultiCell(120, 2, "EXPLOSION PREVENTION AND PROTECTION", 0, 'L', null, 0, null, null, true, 0, true, false); + $this->MultiCell(120, 2, "EXPLOSION PREVENTION AND PROTECTION", 0, 'L', null, 0, null, null, true, 0, true, false); $this->MultiCell(0, 2, "PRESSURE RELIEF", 0, 'R', null, 1, null, null, true, 0, true, false); // $this->ln(); - $this->MultiCell(0, 2, "VISION IN THE PROCESS", 0, 'C', null, 1, null, null, true, 0, true, false); + $this->MultiCell(0, 2, "VISION IN THE PROCESS", 0, 'R', null, 1, null, null, true, 0, true, false); // $this->ln(); $this->MultiCell(80, 2, "FLOW MEASUREMENT", 0, 'L', null, 0, null, null, true, 0, true, false); $this->MultiCell(0, 2, "PROCESS INSTRUMENTATION", 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, "Commercial Comments:", 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)); diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 1c091544..23542b83 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -23,6 +23,7 @@ echo $javascript->link('jquery-ui'); echo $javascript->link('jquery.form'); + echo $scripts_for_layout; diff --git a/views/products/get_principle_products.ctp b/views/products/get_principle_products.ctp index 3dbd6409..0e61586d 100644 --- a/views/products/get_principle_products.ctp +++ b/views/products/get_principle_products.ctp @@ -1,3 +1,5 @@ input('LineItem.product_id', array('options' => $products, 'div' => false, 'empty'=>'Select the Product')); + +//echo $javascript->object($products); ?> \ No newline at end of file diff --git a/views/products/get_product_options.ctp b/views/products/get_product_options.ctp index 04441362..70b444a6 100644 --- a/views/products/get_product_options.ctp +++ b/views/products/get_product_options.ctp @@ -1,3 +1,48 @@ + 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); +} + + ?> \ No newline at end of file diff --git a/views/quotes/pdf.ctp b/views/quotes/pdf.ctp index bcfb598b..3d4ac802 100755 --- a/views/quotes/pdf.ctp +++ b/views/quotes/pdf.ctp @@ -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 { diff --git a/views/quotes/view.ctp b/views/quotes/view.ctp index d8e9047d..df436df0 100755 --- a/views/quotes/view.ctp +++ b/views/quotes/view.ctp @@ -16,8 +16,6 @@ __('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision'].' for '. $customer_link); } ?> - -

- +
@@ -167,7 +165,7 @@ foreach ($quote['QuotePage'] as $quotePage): - +
@@ -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'); + ?> + + + +
+ + +
+ + + + 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):
create('LineItem');?> - - input('principle_id', array('options'=>$principles, 'empty' =>'Select the Principle for this Product')); - ?> -
+ 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')); -
+ ?> + +
+ +
+ +
+ +
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'); - ?> -
- - end('Submit');?> + */ + ?> + +
+ + end('Submit'); + ?>
- + -} \ No newline at end of file +
\ No newline at end of file diff --git a/webroot/js/addLineItem.js b/webroot/js/addLineItem.js index 3e4caed6..7ef4d60d 100644 --- a/webroot/js/addLineItem.js +++ b/webroot/js/addLineItem.js @@ -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.'); +}