From 4dbbeed27fa1f46c99ae705737f3cee7e44d85e8 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 11 Sep 2009 12:50:16 +1000 Subject: [PATCH] Adding Products, Options going ok. Last version with duplicated costing fields. --- controllers/product_options_controller.php | 1 + controllers/quote_products_controller.php | 25 +++++---- models/product_option.php | 12 +++++ models/quote_product.php | 8 +++ views/elements/address_table.ctp | 3 +- views/elements/product_costing.ctp | 40 +++++++++++++++ views/elements/product_list.ctp | 29 +++++++++++ views/products/add.ctp | 13 +++-- views/products/add_costing.ctp | 1 + views/quote_products/add.ctp | 12 +++-- views/quote_products/principle_products.ctp | 12 +++++ views/quote_products/product_options.ctp | 57 +++++++++++++++++++++ 12 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 views/elements/product_costing.ctp create mode 100644 views/elements/product_list.ctp create mode 100644 views/quote_products/principle_products.ctp create mode 100644 views/quote_products/product_options.ctp diff --git a/controllers/product_options_controller.php b/controllers/product_options_controller.php index f80eee4c..b86392bc 100644 --- a/controllers/product_options_controller.php +++ b/controllers/product_options_controller.php @@ -4,6 +4,7 @@ class ProductOptionsController extends AppController { var $name = 'ProductOptions'; var $helpers = array('Html', 'Form'); + function index() { $this->ProductOption->recursive = 0; $this->set('productOptions', $this->paginate()); diff --git a/controllers/quote_products_controller.php b/controllers/quote_products_controller.php index e9435df1..ad4762b2 100644 --- a/controllers/quote_products_controller.php +++ b/controllers/quote_products_controller.php @@ -27,8 +27,10 @@ class QuoteProductsController extends AppController { if (!empty($this->data)) { $this->QuoteProduct->create(); if ($this->QuoteProduct->save($this->data)) { - $this->Session->setFlash(__('The QuoteProduct has been saved', true)); - $this->redirect(array('action'=>'index')); + $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)); } @@ -37,8 +39,8 @@ class QuoteProductsController extends AppController { $principles = $this->QuoteProduct->Product->Principle->find('list'); $currencies = $this->QuoteProduct->Currency->find('list'); - $quotes = $this->QuoteProduct->Quote->find('list'); - $this->set(compact('principles', 'currencies', 'quotes', 'products')); + $quote = $this->QuoteProduct->Quote->read(null, $quoteid); + $this->set(compact('principles', 'currencies', 'quote', 'products')); } @@ -54,23 +56,20 @@ class QuoteProductsController extends AppController { /* Display a list of Options (if any) for a given Product. Used for the add() method */ function product_options() { - if (empty($this->data['QuoteProduct']['product_id'])) { - } - else { - // $this->set('options', $this->QuoteProduct->Product->ProductOptions->find('list', array('conditions'=>array('ProductOption.product_id'=>$this->data['QuoteProduct']['product_id'])))); - + + /*$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'))); - } + + } - - - function edit($id = null) { diff --git a/models/product_option.php b/models/product_option.php index eae19722..e05d1c6f 100644 --- a/models/product_option.php +++ b/models/product_option.php @@ -6,4 +6,16 @@ class ProductOption extends AppModel { var $belongsTo = array('ProductOptionsCategory'); + + /* Logic to enforce only 1 default option. + * If the option being saved claims to be the default, set any other options in that category + * that are already default == 1 , to be false. + * + */ + function beforeSave() { + + + + } + } diff --git a/models/quote_product.php b/models/quote_product.php index b989209a..01e77686 100755 --- a/models/quote_product.php +++ b/models/quote_product.php @@ -3,6 +3,14 @@ class QuoteProduct extends AppModel { var $name = 'QuoteProduct'; + /** + * @var QuoteProduct; + * + */ + + var $QuoteProduct; + + //The Associations below have been created with all possible keys, those that are not needed can be removed diff --git a/views/elements/address_table.ctp b/views/elements/address_table.ctp index 6cd42459..de3f3a8f 100644 --- a/views/elements/address_table.ctp +++ b/views/elements/address_table.ctp @@ -25,7 +25,8 @@ link(__($address['Country']['name'], true), array('controller'=>'countries', 'action' => 'view', $address['Country']['id']));?> input("$modelName.exchange_rate", array('id'=>'exchange_rate')); + echo $form->input("$modelName.cost_price_each", array('id'=>'costprice')); + echo $form->input("$modelName.our_discount", array("label"=>"Our Discount %", "id" => "ourdiscount")); + echo $form->input("$modelName.packing_each", array("id"=>"packing")); + echo '
'; + echo $form->label("$modelName.fob_country_of_export", "F.O.B Country of Export"); + echo $form->text("$modelName.fob_country_of_export", array("readonly"=>"readonly", "id"=>"fob_country_of_export")); + echo "
"; + echo '
'; + echo $form->label("$modelName.convert_to_aud", "Convert to A$"); + echo $form->text("$modelName.convert_to_aud", array("readonly"=>"readonly", "id"=>"convert_to_aud")); + echo "
"; + echo $form->input("$modelName.duty", array("label" => "Duty %", "id"=>"duty")); + echo $form->input("$modelName.shipping_weight_each", array("id"=>"shippingweight_each")); + echo $form->input("$modelName.shipping_cost_each", array("id"=>"shippingcost_each")); + echo $form->input("$modelName.customs", array("id"=>"customs")); + echo $form->input("$modelName.misc_cost", array("label" => "Misc. Costs", "id"=>"misc_cost")); + echo $form->input("$modelName.finance", array("label" => "Finance %", "id"=>"finance", "after"=>'

')); + echo '
'; + echo $form->label("$modelName.total_landed_cost", "Total Landed Cost"); + echo $form->text("$modelName.total_landed_cost", array("readonly"=>"readonly", "id"=>"total_landed_cost")); + echo "
"; + echo $form->input("$modelName.sellprice_each", array("label" => "Sell Price Each", "id"=>"sellprice_each")); + echo '
'; + echo $form->label("$modelName.gross_profit_dollars", "Gross Profit $"); + echo $form->text("$modelName.gross_profit_dollars", array("readonly"=>"readonly", "id"=>"gross_profit_dollars")); + echo "
"; + echo '
'; + echo $form->label("$modelName.gross_profit_percent", "Gross Profit %"); + echo $form->text("$modelName.gross_profit_prercent", array("readonly"=>"readonly", "id"=>"gross_profit_percent")); + echo "
"; + echo $ajax->observeForm("productaddform", array("frequency" => 0.5, "complete"=>"buildup()")); + +//} + +?> \ No newline at end of file diff --git a/views/elements/product_list.ctp b/views/elements/product_list.ctp new file mode 100644 index 00000000..66896f17 --- /dev/null +++ b/views/elements/product_list.ctp @@ -0,0 +1,29 @@ + + + + + + + + + + > + + + + + + + +
+ link(__('View', true), array('controller'=> 'products', 'action'=>'view', $product['Product']['id'])); ?> + link(__('Edit', true), array('controller'=> 'products', 'action'=>'edit', $product['Product']['id'])); ?> +
+ diff --git a/views/products/add.ctp b/views/products/add.ctp index 099aae23..d73f885a 100755 --- a/views/products/add.ctp +++ b/views/products/add.ctp @@ -10,11 +10,18 @@ echo $form->input('description', array('class'=>'wymeditor')); echo $form->input('part_number'); echo $form->input('product_category_id'); - echo $ajax->link('Show Costing Info', array('controller'=> 'products', 'action' => 'add_costing'), array( 'update' => 'costingdetails')); - echo '
'; - echo '
'; echo $form->input('notes'); + echo $html->link('Show/Hide Costing Details', '#', array('onClick' => "Effect.toggle('costingdetails', 'appear'); return false;")); + echo $html->image('calculator.png'); + echo $ajax->div('costingdetails'); + + echo $this->element('product_costing', array('modelName' => 'Product')); + + echo $ajax->divEnd('costingdetails'); + + + ?> end(array('label' => 'Add Product', 'class'=>'wymupdate'));?> diff --git a/views/products/add_costing.ctp b/views/products/add_costing.ctp index a1bc49ff..b8738740 100644 --- a/views/products/add_costing.ctp +++ b/views/products/add_costing.ctp @@ -1,4 +1,5 @@ Costing Buildup'; echo $form->input('Product.exchange_rate', array('id'=>'exchange_rate')); echo $form->input('Product.cost_price_each', array('id'=>'costprice')); echo $form->input('Product.our_discount', array('label'=>'Our Discount %', 'id' => 'ourdiscount')); diff --git a/views/quote_products/add.ctp b/views/quote_products/add.ctp index ee6d4132..cecdab60 100644 --- a/views/quote_products/add.ctp +++ b/views/quote_products/add.ctp @@ -4,7 +4,8 @@ input('principle_id'); + echo $form->input('quote_id', array('type' => 'hidden', 'value' => $quote['Quote']['id'])); + echo $form->input('principle_id', array('empty' => 'Select a Priniple')); echo $ajax->observeField('QuoteProductPrincipleId', array( 'url' => 'principle_products', 'frequency' => 0.2, @@ -14,7 +15,7 @@ echo $form->input('product_id', array('type' => 'select', 'id'=>'products')); - /*echo $ajax->observeField('products', array( + echo $ajax->observeField('products', array( 'url' => 'product_options', 'frequency' => 0.2, @@ -22,10 +23,11 @@ )); - - echo '
'; + echo $ajax->div('productoptions'); + echo $ajax->divEnd('productoptions'); + //echo '
'; //echo $form->select('QuoteProduct.product_id', null, null, array('id'=>'products')); - */ + //*/ /* echo $form->input('item_number'); diff --git a/views/quote_products/principle_products.ctp b/views/quote_products/principle_products.ctp new file mode 100644 index 00000000..51e8ce24 --- /dev/null +++ b/views/quote_products/principle_products.ctp @@ -0,0 +1,12 @@ +Select a Product'; + +if(!empty($products)) { + + foreach($products as $k => $v) { + echo ""; + } +} + +?> diff --git a/views/quote_products/product_options.ctp b/views/quote_products/product_options.ctp new file mode 100644 index 00000000..badfa12e --- /dev/null +++ b/views/quote_products/product_options.ctp @@ -0,0 +1,57 @@ +input($opt['ProductOptionsCategory']['name'], + array('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); +?>