From 67680e8e2fbaeb87bc71fb9a17a5f2a1e04a9184 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Wed, 31 Mar 2010 16:50:22 +1100 Subject: [PATCH] added blank items. bugs need to be fixed --- controllers/line_items_controller.php | 45 ++++++++++++++++----------- views/quotes/ajaxpdf.ctp | 7 +++++ views/quotes/view.ctp | 10 ++++-- webroot/js/addLineItem.js | 13 ++++++-- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php index c4a30ed2..9e141644 100644 --- a/controllers/line_items_controller.php +++ b/controllers/line_items_controller.php @@ -29,12 +29,15 @@ class LineItemsController extends AppController { if (!empty($this->data)) { $this->LineItem->create(); - $product = $this->LineItem->Product->findById($this->data['LineItem']['product_id']); + if(isset($this->data['LineItem']['product_id'])) { + $product = $this->LineItem->Product->findById($this->data['LineItem']['product_id']); - /* Copy all the data from the Product to the new LineItem */ + /* 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']; + } - $this->data['LineItem']['description'] = $product['Product']['description']; - $this->data['LineItem']['title'] = $product['Product']['title']; // $numberOfItems = $this->LineItem->find('count', @@ -65,7 +68,7 @@ class LineItemsController extends AppController { } -/* Process the Line Item and add it to a quote */ + /* Process the Line Item and add it to a quote */ function ajaxSave() { @@ -73,11 +76,17 @@ class LineItemsController extends AppController { 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(isset($this->data['LineItem']['product_id'])) { + $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)) { @@ -91,7 +100,7 @@ class LineItemsController extends AppController { exit(); - /* Need to find a way to append Product Option data to the description / model number title */ + /* Need to find a way to append Product Option data to the description / model number title */ } @@ -105,7 +114,7 @@ class LineItemsController extends AppController { } - /* Display a list of Products for a given principle. Used for the add() method */ + /* Display a list of Products for a given principle. Used for the add() method */ function principle_products() { if (empty($this->data['LineItem']['principle_id'])) { } @@ -115,16 +124,16 @@ class LineItemsController extends AppController { } - /* Display a list of Options (if any) for a given Product. Used for the add() method */ + /* Display a list of Options (if any) for a given Product. Used for the add() method */ function product_options() { - /*$this->set('categories', $this->LineItem->Product->ProductOptionsCategory->find('list'), + /*$this->set('categories', $this->LineItem->Product->ProductOptionsCategory->find('list'), array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), 'order'=>'ProductOptionsCategory.location ASC') );*/ $this->set('options', $this->LineItem->Product->ProductOptionsCategory->find('all', - array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), - 'order'=>'ProductOptionsCategory.location ASC'))); + array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['LineItem']['product_id']), + 'order'=>'ProductOptionsCategory.location ASC'))); } @@ -182,8 +191,8 @@ class LineItemsController extends AppController { $quoteid = $this->data['LineItem']['quote_id']; $lineItems = $this->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $quoteid), - 'order' => array('LineItem.item_number ASC')) - ); + 'order' => array('LineItem.item_number ASC')) + ); $quote = $this->LineItem->Quote->read(null, $quoteid); $this->set('quote', $quote); @@ -192,7 +201,7 @@ class LineItemsController extends AppController { } } else { - //Was POSTed with no data. + //Was POSTed with no data. $this->set('lineItems', 'Something has broken. Requesting a LineItem table without POSTing a quote or job ID'); } } diff --git a/views/quotes/ajaxpdf.ctp b/views/quotes/ajaxpdf.ctp index 152c5e34..763218d9 100644 --- a/views/quotes/ajaxpdf.ctp +++ b/views/quotes/ajaxpdf.ctp @@ -108,6 +108,13 @@ $tcpdf->productPage($quote['Currency'], $enquiry['Enquiry']['gst'], $products, ' $output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/'; +$debuglevel = Configure::read('debug'); + +if($debuglevel == 0) { + $output_dir = '/var/www/cakephp/app/webroot/pdf/'; +} + + if($quote['Quote']['revision'] > 0) { $filename = $enquiry['Enquiry']['title'].'rev'.$quote['Quote']['revision'].'.pdf'; } diff --git a/views/quotes/view.ctp b/views/quotes/view.ctp index 8ba18846..0b7099af 100755 --- a/views/quotes/view.ctp +++ b/views/quotes/view.ctp @@ -136,13 +136,19 @@ foreach ($quote['QuotePage'] as $quotePage): ?> + + input('title', array('div'=>'blankItem')); + echo $form->input('description', array('div'=>'blankItem')); + ?> +
- input('unit_price', array('id'=>"unitPrice", 'div'=>'nocosting', 'class'=>'nocostinput')); ?> - input('discount_percent', array('id'=>'discountPercent', 'div'=>'nocosting', 'class'=>'nocostinput')); + input('unit_price', array('id'=>"unitPrice", 'div'=>'nocosting', 'class'=>'nocostinput')); + echo $form->input('discount_percent', array('id'=>'discountPercent', 'div'=>'nocosting', 'class'=>'nocostinput')); echo $form->input('discount_amount_each', array('id'=>'discountAmountEach', 'readonly'=>'readonly', 'div'=>'nocosting')); echo $form->input('net_price_each', array('id'=>'net_price_each', 'readonly'=>'readonly', 'div'=>'nocosting')); echo $form->input('total_discount_amount', array('id'=>'total_discountAmount', 'readonly'=>'readonly', 'div'=>'nocosting')); diff --git a/webroot/js/addLineItem.js b/webroot/js/addLineItem.js index 43f8f948..a6ee1b90 100644 --- a/webroot/js/addLineItem.js +++ b/webroot/js/addLineItem.js @@ -19,7 +19,7 @@ $(function() { $(".nocosting").hide(); - + $(".blankItem").hide(); $("#addLineItem-form").dialog({ @@ -33,7 +33,8 @@ $(function() { $.post("/line_items/ajaxSave", $("#LineItemAddForm").serialize(), function(data) { fetchTable(); - } + $('#mydebug').html(data); + } ); $("#LineItemAddForm").resetForm(); @@ -80,7 +81,13 @@ $(function() { }); - + $('#addBlankItem').button().click(function () { + $("#LineItemPrincipleId").hide(); + $(".blankItem").show(); + $(".nocosting").show(); + return false; + + }); });