From 7e1902089c93bd909e50788b061eb47aa5e8c03c Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 16 Nov 2009 14:31:10 +1100 Subject: [PATCH] Various changes --- controllers/quote_products_controller.php | 31 ++- controllers/quotes_controller.php | 8 + models/quote_product.php | 7 +- views/layouts/default.ctp | 3 +- views/product_options/add.ctp | 11 - views/products/add.ctp | 15 +- views/quote_products/add.ctp | 19 +- views/quote_products/product_options.ctp | 5 +- views/quotes/view.ctp | 20 +- webroot/css/quotenik.css | 37 +++ webroot/js/quotenik/add_costing.js | 10 + webroot/js/validation.js | 280 ++++++++++++++++++++++ 12 files changed, 404 insertions(+), 42 deletions(-) create mode 100644 webroot/js/quotenik/add_costing.js create mode 100755 webroot/js/validation.js diff --git a/controllers/quote_products_controller.php b/controllers/quote_products_controller.php index 68f455e8..4acd4d9d 100755 --- a/controllers/quote_products_controller.php +++ b/controllers/quote_products_controller.php @@ -28,17 +28,25 @@ class QuoteProductsController extends AppController { $this->QuoteProduct->create(); $product = $this->QuoteProduct->Product->findById($this->data['QuoteProduct']['product_id']); - $this->data['QuoteProduct']['description'] = $product['Product']['description']; - - $numberOfItems - $this->Quo + + /* Copy all the data from the Product to the new QuoteProduct */ + + $this->data['QuoteProduct']['description'] = $product['Product']['description']; + $this->data['QuoteProduct']['title'] = $product['Product']['title']; + + + $numberOfItems = $this->QuoteProduct->find('count', + array('conditions' => array('QuoteProduct.quote_id' => $this->data['QuoteProduct']['quote_id']))); + + $numberOfItems++; + + $this->data['QuoteProduct']['item_number'] = $numberOfItems; if ($this->QuoteProduct->save($this->data)) { $quoteid = $this->data['QuoteProduct']['quote_id']; - - $this->Session->setFlash(__('Product Added to Quote Successfully', true)); $this->redirect(array('controller'=>'quotes', 'action'=>'view', $quoteid)); } else { @@ -101,23 +109,26 @@ class QuoteProductsController extends AppController { if (empty($this->data)) { $this->data = $this->QuoteProduct->read(null, $id); } - $principles = $this->QuoteProduct->Principle->find('list'); - $currencies = $this->QuoteProduct->Currency->find('list'); + $quotes = $this->QuoteProduct->Quote->find('list'); $products = $this->QuoteProduct->Product->find('list'); - $this->set(compact('principles','currencies','quotes','products')); + $this->set(compact('quotes','products')); } function delete($id = null) { - if (!$id) { + + $thisQP = $this->QuoteProduct->read(null, $id); + + if (!$id) { $this->Session->setFlash(__('Invalid id for QuoteProduct', true)); $this->redirect(array('action'=>'index')); } if ($this->QuoteProduct->del($id)) { $this->Session->setFlash(__('QuoteProduct deleted', true)); - $this->redirect(array('action'=>'index')); + $this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$thisQP['Quote']['id'])); } } + } ?> diff --git a/controllers/quotes_controller.php b/controllers/quotes_controller.php index f49087b3..046a70f0 100755 --- a/controllers/quotes_controller.php +++ b/controllers/quotes_controller.php @@ -18,7 +18,15 @@ class QuotesController extends AppController { } $quote = $this->Quote->read(null, $id); $this->set('quote', $quote); + + $quoteProducts = $this->Quote->QuoteProduct->find('all', array('recursive' => 0, 'conditions' => array('QuoteProduct.quote_id' => $id), + 'order' => array('QuoteProduct.item_number ASC')) + ); + $this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id'])); + $this->set('quoteProducts', $quoteProducts); + + } function add() { diff --git a/models/quote_product.php b/models/quote_product.php index eabc9051..32aadcef 100755 --- a/models/quote_product.php +++ b/models/quote_product.php @@ -9,7 +9,9 @@ class QuoteProduct extends AppModel { */ var $QuoteProduct; - + + + //The Associations below have been created with all possible keys, those that are not needed can be removed @@ -37,5 +39,8 @@ class QuoteProduct extends AppModel { 'foreignKey' => 'id') ); + + var $order = "item_number ASC"; + } ?> \ No newline at end of file diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 20d1db29..c971d528 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -19,6 +19,7 @@ echo $javascript->link('prototype'); echo $javascript->link('scriptaculous'); echo $javascript->link('ckeditor/ckeditor'); + echo $javascript->link('validation'); ?> @@ -102,7 +103,7 @@ - +
input('description'); echo $form->input('model_number'); echo $form->input('default'); - echo $form->input('cost_price'); - echo $form->input('exchange_rate'); - echo $form->input('our_discount'); - echo $form->input('packing_each'); - echo $form->input('shipping_weight_each'); - echo $form->input('shipping_cost_each'); - echo $form->input('duty'); - echo $form->input('customs'); - echo $form->input('finance'); - echo $form->input('misc_cost'); - echo $form->input('sell_price'); echo $form->input('notes'); ?> diff --git a/views/products/add.ctp b/views/products/add.ctp index bb2aa162..875200ba 100755 --- a/views/products/add.ctp +++ b/views/products/add.ctp @@ -6,7 +6,7 @@ input('principle_id'); - echo $form->input('title'); + echo $form->input('title', array('class' => 'required', 'title'=>'Please Enter the Title for the Product')); echo $form->input('description', array('id' => 'description', 'class'=>'ckeditor')); //echo $javascript->codeBlock("CKEDITOR.replace('description');"); @@ -18,15 +18,22 @@ echo $html->image('calculator.png'); //echo $ajax->div('costingdetails'); - //echo $this->element('product_costing', array('modelName' => 'Product')); + //echo $this->e + //lement('product_costing', array('modelName' => 'Product')); //echo $ajax->divEnd('costingdetails'); - + + ?> -end(array('label' => 'Add Product', 'class'=>'wymupdate'));?> +end(array('label' => 'Add Product')); + echo $javascript->codeBlock("new Validation('productaddform', {immediate : true, useTitles : true});", array('allowCache'=>true, 'safe'=>false)); + +?> + +