From 26452cd1a0fb9e27ab0a6c236741505732a5d6b4 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Wed, 16 Dec 2009 15:50:48 -0500 Subject: [PATCH] First commit this side of the pacific --- controllers/products_controller.php | 138 +++++++++++------------ models/product_option.php | 6 +- models/product_options_category.php | 4 +- models/quote_product_option.php | 13 +++ views/products/index.ctp | 2 +- views/quote_products/product_options.ctp | 98 ++++++++-------- views/quotes/view.ctp | 8 +- webroot/css/quotenik.css | 9 ++ 8 files changed, 148 insertions(+), 130 deletions(-) create mode 100644 models/quote_product_option.php diff --git a/controllers/products_controller.php b/controllers/products_controller.php index 29b432c2..bb1f835b 100755 --- a/controllers/products_controller.php +++ b/controllers/products_controller.php @@ -1,82 +1,82 @@ Product->recursive = 0; - $this->set('products', $this->paginate()); - } + function index() { + $this->Product->recursive = 0; + $this->set('products', $this->paginate()); + } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Product.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('product', $this->Product->read(null, $id)); + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Product.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('product', $this->Product->read(null, $id)); - //$this->set('product', $this->Product->find('first', array('conditions' => array('Product.id'=>$id), 'recursive' => 1))); + //$this->set('product', $this->Product->find('first', array('conditions' => array('Product.id'=>$id), 'recursive' => 1))); - $this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC'))); - - $this->set('files', $this->Product->ProductAttachment->findAllByProductId($id)); - $this->set('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id)))); - } + $this->set('options', $this->Product->ProductOptionsCategory->find('all', array('conditions' => array('ProductOptionsCategory.product_id'=>$id), 'order'=>'ProductOptionsCategory.location ASC'))); - function add() { - if (!empty($this->data)) { - $this->Product->create(); - - if ($this->Product->save($this->data)) { - $this->Session->setFlash(__('The Product has been saved', true)); - $id = $this->Product->id; - $this->redirect(array('action'=>'view/'.$id)); - } else { - $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); - } - } - $principles = $this->Product->Principle->find('list'); - - $this->set(compact('principles', 'product_categories')); - } - - function add_costing() { - - } + $this->set('files', $this->Product->ProductAttachment->findAllByProductId($id)); + $this->set('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id)))); + } - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid Product', true)); - $this->redirect(array('action'=>'index')); - } - if (!empty($this->data)) { - if ($this->Product->save($this->data)) { - $this->Session->setFlash(__('The Product has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->Product->read(null, $id); - $this->set('description', $this->data['Product']['description']); - } - $principles = $this->Product->Principle->find('list'); - $this->set(compact('principles')); - } + function add() { + if (!empty($this->data)) { + $this->Product->create(); - function delete($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid id for Product', true)); - $this->redirect(array('action'=>'index')); - } - if ($this->Product->del($id)) { - $this->Session->setFlash(__('Product deleted', true)); - $this->redirect(array('action'=>'index')); - } - } + if ($this->Product->save($this->data)) { + $this->Session->setFlash(__('The Product has been saved', true)); + $id = $this->Product->id; + $this->redirect(array('action'=>'view/'.$id)); + } else { + $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); + } + } + $principles = $this->Product->Principle->find('list'); + + $this->set(compact('principles', 'product_categories')); + } + + function add_costing() { + + } + + function edit($id = null) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Product', true)); + $this->redirect(array('action'=>'index')); + } + if (!empty($this->data)) { + if ($this->Product->save($this->data)) { + $this->Session->setFlash(__('The Product has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Product could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->Product->read(null, $id); + $this->set('description', $this->data['Product']['description']); + } + $principles = $this->Product->Principle->find('list'); + $this->set(compact('principles')); + } + + function delete($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Product', true)); + $this->redirect(array('action'=>'index')); + } + if ($this->Product->del($id)) { + $this->Session->setFlash(__('Product deleted', true)); + $this->redirect(array('action'=>'index')); + } + } } ?> diff --git a/models/product_option.php b/models/product_option.php index e05d1c6f..c3d2b59d 100755 --- a/models/product_option.php +++ b/models/product_option.php @@ -12,10 +12,6 @@ class ProductOption extends AppModel { * that are already default == 1 , to be false. * */ - function beforeSave() { - - - - } + } diff --git a/models/product_options_category.php b/models/product_options_category.php index d7ed475e..986dc7f5 100755 --- a/models/product_options_category.php +++ b/models/product_options_category.php @@ -5,8 +5,8 @@ class ProductOptionsCategory extends AppModel { var $validate = array( 'product_id' => array('numeric'), 'name' => array('notempty'), - 'location' => array('numeric'), - 'exclusive' => array('notempty') + 'location' => array('numeric' => array('allowEmpty' => true)), + 'exclusive' => array('boolean') ); //The Associations below have been created with all possible keys, those that are not needed can be removed diff --git a/models/quote_product_option.php b/models/quote_product_option.php new file mode 100644 index 00000000..92d06088 --- /dev/null +++ b/models/quote_product_option.php @@ -0,0 +1,13 @@ + diff --git a/views/products/index.ctp b/views/products/index.ctp index 864fb6ee..3fe9c919 100755 --- a/views/products/index.ctp +++ b/views/products/index.ctp @@ -1,5 +1,5 @@
-

+

counter(array( diff --git a/views/quote_products/product_options.ctp b/views/quote_products/product_options.ctp index 8f69c6a5..86bbf2f9 100755 --- a/views/quote_products/product_options.ctp +++ b/views/quote_products/product_options.ctp @@ -1,57 +1,57 @@ 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); - } - - - - - - + + $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); +} + + + + + + //print_r($categories); -//print_r($options); +print_r($options); ?> diff --git a/views/quotes/view.ctp b/views/quotes/view.ctp index af859331..aee2fadf 100755 --- a/views/quotes/view.ctp +++ b/views/quotes/view.ctp @@ -94,7 +94,7 @@ foreach ($quote['QuotePage'] as $quotePage): - + - SUB-TOTAL (Excluding GST) + SUB-TOTAL (Excluding GST) @@ -128,7 +128,7 @@ foreach ($quote['QuotePage'] as $quotePage): - GST (10%) + GST (10%) - TOTAL PAYABLE + TOTAL PAYABLE