Adding Products, Options going ok. Last version with duplicated costing fields.
This commit is contained in:
parent
8a981ea577
commit
4dbbeed27f
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
<td><?php echo $html->link(__($address['Country']['name'], true), array('controller'=>'countries', 'action' => 'view', $address['Country']['id']));?></td>
|
||||
<td><?php
|
||||
|
||||
/* I was told of the evil of switch statements, but it makes sense here. */
|
||||
/* Could probably use an Enum in the table instead.
|
||||
* This will stay for now though */
|
||||
switch($address['Address']['type']) {
|
||||
case 0:
|
||||
echo "Billing";
|
||||
|
|
|
|||
40
views/elements/product_costing.ctp
Normal file
40
views/elements/product_costing.ctp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
//if(!empty($modelName)) {
|
||||
|
||||
echo $form->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 '<div class="input text">';
|
||||
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 "</div>";
|
||||
echo '<div class="input text">';
|
||||
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 "</div>";
|
||||
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"=>'<p id="financeamount"> </p>'));
|
||||
echo '<div class="input text">';
|
||||
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 "</div>";
|
||||
echo $form->input("$modelName.sellprice_each", array("label" => "Sell Price Each", "id"=>"sellprice_each"));
|
||||
echo '<div class="input text">';
|
||||
echo $form->label("$modelName.gross_profit_dollars", "Gross Profit $");
|
||||
echo $form->text("$modelName.gross_profit_dollars", array("readonly"=>"readonly", "id"=>"gross_profit_dollars"));
|
||||
echo "</div>";
|
||||
echo '<div class="input text">';
|
||||
echo $form->label("$modelName.gross_profit_percent", "Gross Profit %");
|
||||
echo $form->text("$modelName.gross_profit_prercent", array("readonly"=>"readonly", "id"=>"gross_profit_percent"));
|
||||
echo "</div>";
|
||||
echo $ajax->observeForm("productaddform", array("frequency" => 0.5, "complete"=>"buildup()"));
|
||||
|
||||
//}
|
||||
|
||||
?>
|
||||
29
views/elements/product_list.ctp
Normal file
29
views/elements/product_list.ctp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<table cellpadding = "0" cellspacing = "0">
|
||||
<tr>
|
||||
<th><?php __('Principle'); ?></th>
|
||||
<th><?php __('Title'); ?></th>
|
||||
<th><?php __('Description'); ?></th>
|
||||
<th><?php __('Part Number'); ?></th>
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($products as $product):
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
?>
|
||||
<tr<?php echo $class;?>>
|
||||
<td><?php echo $product['Principle']['name'];?></td>
|
||||
<td><?php echo $product['Product']['title'];?></td>
|
||||
<td><?php echo $product['Product']['description'];?></td>
|
||||
<td><?php echo $product['Product']['part_number'];?></td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('controller'=> 'products', 'action'=>'view', $product['Product']['id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('controller'=> 'products', 'action'=>'edit', $product['Product']['id'])); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
|
|
@ -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 '<div id="costingdetails">';
|
||||
echo '</div>';
|
||||
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');
|
||||
|
||||
|
||||
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end(array('label' => 'Add Product', 'class'=>'wymupdate'));?>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?
|
||||
echo '<h3><a name="costing">Costing Buildup</a></h3>';
|
||||
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'));
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<legend><?php __('Add Product to this Quote');?></legend>
|
||||
<?php
|
||||
|
||||
echo $form->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 '<div id="productoptions"></div>';
|
||||
echo $ajax->div('productoptions');
|
||||
echo $ajax->divEnd('productoptions');
|
||||
//echo '<div id="productoptions"></div>';
|
||||
//echo $form->select('QuoteProduct.product_id', null, null, array('id'=>'products'));
|
||||
*/
|
||||
//*/
|
||||
|
||||
/*
|
||||
echo $form->input('item_number');
|
||||
|
|
|
|||
12
views/quote_products/principle_products.ctp
Normal file
12
views/quote_products/principle_products.ctp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
echo '<option value="">Select a Product</option>';
|
||||
|
||||
if(!empty($products)) {
|
||||
|
||||
foreach($products as $k => $v) {
|
||||
echo "<option value=\"$k\">$v</option>";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
57
views/quote_products/product_options.ctp
Normal file
57
views/quote_products/product_options.ctp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?
|
||||
$i = 0;
|
||||
foreach ($options as $opt) {
|
||||
|
||||
|
||||
$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($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);
|
||||
?>
|
||||
Loading…
Reference in a new issue