From 265ff9354be1df060fd450064ad2ea8f7770d2ca Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 17 Nov 2009 09:24:53 +1100 Subject: [PATCH] working towards quote building --- controllers/costings_controller.php | 38 +++++ controllers/quote_products_controller.php | 192 +++++++++++----------- models/quote_product.php | 4 +- views/quote_products/add.ctp | 2 + views/quotes/view.ctp | 15 +- 5 files changed, 148 insertions(+), 103 deletions(-) create mode 100644 controllers/costings_controller.php diff --git a/controllers/costings_controller.php b/controllers/costings_controller.php new file mode 100644 index 00000000..7b5181dc --- /dev/null +++ b/controllers/costings_controller.php @@ -0,0 +1,38 @@ +Costings->recursive = 0; + $this->set('costings', $this->paginate()); + } + + + + /** + * Add a costing to a product. It's either being added to a product, quote_product etc. + * + * + * @param int $id + * @param string $target + */ + function add($id, $target) { + + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Quote ID', true)); + $this->redirect(array('action'=>'index')); + } + + + } + + +} + +?> diff --git a/controllers/quote_products_controller.php b/controllers/quote_products_controller.php index 4acd4d9d..fd05a725 100755 --- a/controllers/quote_products_controller.php +++ b/controllers/quote_products_controller.php @@ -1,134 +1,134 @@ QuoteProduct->recursive = 0; - $this->set('quoteProducts', $this->paginate()); - } + function index() { + $this->QuoteProduct->recursive = 0; + $this->set('quoteProducts', $this->paginate()); + } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid QuoteProduct.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('quoteProduct', $this->QuoteProduct->read(null, $id)); - } + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid QuoteProduct.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('quoteProduct', $this->QuoteProduct->read(null, $id)); + } - function add($quoteid = null) { - - if (!$quoteid && empty($this->data)) { - $this->Session->setFlash(__('Invalid Quote ID', true)); - $this->redirect(array('action'=>'index')); - } + function add($quoteid = null) { - if (!empty($this->data)) { - $this->QuoteProduct->create(); - - $product = $this->QuoteProduct->Product->findById($this->data['QuoteProduct']['product_id']); + if (!$quoteid && empty($this->data)) { + $this->Session->setFlash(__('Invalid Quote ID', true)); + $this->redirect(array('action'=>'index')); + } + + if (!empty($this->data)) { + $this->QuoteProduct->create(); + + $product = $this->QuoteProduct->Product->findById($this->data['QuoteProduct']['product_id']); /* 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']; + $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; - $numberOfItems = $this->QuoteProduct->find('count', - array('conditions' => array('QuoteProduct.quote_id' => $this->data['QuoteProduct']['quote_id']))); - $numberOfItems++; + if ($this->QuoteProduct->save($this->data)) { + $quoteid = $this->data['QuoteProduct']['quote_id']; - $this->data['QuoteProduct']['item_number'] = $numberOfItems; + $this->Session->setFlash(__('Product Added to Quote Successfully', true)); + $this->redirect(array('controller'=>'quotes', 'action'=>'view', $quoteid)); + } else { + $this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true)); + } + } - - 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 { - $this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true)); - } - } + $principles = $this->QuoteProduct->Product->Principle->find('list'); - - $principles = $this->QuoteProduct->Product->Principle->find('list'); - - $quote = $this->QuoteProduct->Quote->read(null, $quoteid); - $this->set(compact('principles','quote', 'products')); - - } + $quote = $this->QuoteProduct->Quote->read(null, $quoteid); + $this->set(compact('principles','quote', 'products')); + + } /* Display a list of Products for a given principle. Used for the add() method */ - function principle_products() { - if (empty($this->data['QuoteProduct']['principle_id'])) { - } - else { - $this->set('products', $this->QuoteProduct->Product->find('list', array('conditions'=>array('Product.principle_id'=>$this->data['QuoteProduct']['principle_id'])))); - } - } + function principle_products() { + if (empty($this->data['QuoteProduct']['principle_id'])) { + } + else { + $this->set('products', $this->QuoteProduct->Product->find('list', array('conditions'=>array('Product.principle_id'=>$this->data['QuoteProduct']['principle_id'])))); + } + } /* Display a list of Options (if any) for a given Product. Used for the add() method */ - function product_options() { - + function product_options() { + /*$this->set('categories', $this->QuoteProduct->Product->ProductOptionsCategory->find('list'), array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['QuoteProduct']['product_id']), 'order'=>'ProductOptionsCategory.location ASC') );*/ - - $this->set('options', $this->QuoteProduct->Product->ProductOptionsCategory->find('all', - array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['QuoteProduct']['product_id']), - 'order'=>'ProductOptionsCategory.location ASC'))); - - - } + + $this->set('options', $this->QuoteProduct->Product->ProductOptionsCategory->find('all', + array('conditions' => array('ProductOptionsCategory.product_id'=>$this->data['QuoteProduct']['product_id']), + 'order'=>'ProductOptionsCategory.location ASC'))); + + + } - function edit($id = null) { + function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid QuoteProduct', true)); - $this->redirect(array('action'=>'index')); - } + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid QuoteProduct', true)); + $this->redirect(array('action'=>'index')); + } - if (!empty($this->data)) { - if ($this->QuoteProduct->save($this->data)) { - $this->Session->setFlash(__('The QuoteProduct has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $this->data = $this->QuoteProduct->read(null, $id); - } - - $quotes = $this->QuoteProduct->Quote->find('list'); - $products = $this->QuoteProduct->Product->find('list'); - $this->set(compact('quotes','products')); - } + if (!empty($this->data)) { + if ($this->QuoteProduct->save($this->data)) { + $this->Session->setFlash(__('The QuoteProduct has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The QuoteProduct could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->QuoteProduct->read(null, $id); + } - function delete($id = null) { - - $thisQP = $this->QuoteProduct->read(null, $id); + $quotes = $this->QuoteProduct->Quote->find('list'); + $products = $this->QuoteProduct->Product->find('list'); + $this->set(compact('quotes','products')); + } + + function delete($id = null) { + + $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('controller'=>'quotes', 'action'=>'view/'.$thisQP['Quote']['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('controller'=>'quotes', 'action'=>'view/'.$thisQP['Quote']['id'])); - } - } - } ?> diff --git a/models/quote_product.php b/models/quote_product.php index 32aadcef..4993bad9 100755 --- a/models/quote_product.php +++ b/models/quote_product.php @@ -36,8 +36,10 @@ class QuoteProduct extends AppModel { var $hasOne = array( 'Costing' => array('className' => 'Costing', - 'foreignKey' => 'id') + 'foreignKey' => 'quote_product_id') ); + + var $order = "item_number ASC"; diff --git a/views/quote_products/add.ctp b/views/quote_products/add.ctp index f48b3bfe..58435c67 100755 --- a/views/quote_products/add.ctp +++ b/views/quote_products/add.ctp @@ -9,6 +9,8 @@ echo $form->input('quantity', array('class' => 'required validate-number', 'title'=>'Please enter the quantity. It must be a number')); + echo $form->input('option', array('label' => 'This item is optional')); + echo $form->input('principle_id', array('empty' => 'Select a Principle')); echo $ajax->observeField('QuoteProductPrincipleId', array( 'url' => 'principle_products', diff --git a/views/quotes/view.ctp b/views/quotes/view.ctp index 210e43bf..3533a1a8 100755 --- a/views/quotes/view.ctp +++ b/views/quotes/view.ctp @@ -24,7 +24,7 @@ else { ?> @@ -57,7 +57,6 @@ else { - @@ -75,8 +74,12 @@ else { ?> > - - + + @@ -103,4 +106,4 @@ else { - \ No newline at end of file +
'; + } + echo number_format($quoteProduct['QuoteProduct']['item_number'], 1, '.', '');?>