// Product Suppliers : Add wholesale price management for each supplier

This commit is contained in:
dSevere
2011-11-28 17:16:39 +00:00
parent 01c2498f69
commit e96deb1865
6 changed files with 107 additions and 42 deletions
@@ -202,21 +202,6 @@
</a>
</td>
</tr>
<!--tr>
<td class="col-left"><label>{l s='Supplier:' }</label></td>
<td style="padding-bottom:5px;">
<select name="id_supplier" id="id_supplier">
<option value="0">-- {l s='Choose (optional)'} --</option>
{if $product->id_supplier}
<option value="{$product->id_supplier}" selected="selected">{$product->supplier_name}</option>
{/if}
<option disabled="disabled">----------</option>
</select>&nbsp;&nbsp;&nbsp;
<a href="{$link->getAdminLink('AdminSuppliers')}&addsupplier" onclick="return confirm('{l s='Are you sure you want to delete entered product information?' js=1}">
<img src="../img/admin/add.gif" alt="{l s='Create'}" title="{l s='Create'}" /> <b>{l s='Create'}</b>
</a>
</td>
</tr-->
</table>
<table cellpadding="5" cellspacing="0" border="0" style="width: 100%;"><tr><td><div class="separation"></div></td></tr></table>
{* [begin] pack product *}
@@ -576,13 +561,13 @@ $(document).ready(function(){
</tr>
{* @todo : prices related has to be moved in price subtab *}
<tr>
<!--tr>
<td class="col-left"><label>{l s='Pre-tax wholesale price:'}</label></td>
<td style="padding-bottom:5px;">
{$currency->prefix}<input size="11" maxlength="14" name="wholesale_price" type="text" value="{$product->wholesale_price}" onchange="this.value = this.value.replace(/,/g, '.');" />{$currency->suffix}
<p class="preference_description">{l s='The wholesale price at which you bought this product'}</p>
</td>
</tr>
</tr-->
<tr>
<td class="col-left"><label>{l s='Pre-tax retail price:'}</label></td>
@@ -973,7 +958,7 @@ $(document).ready(function(){
<p class="preference_description">{l s='Tags separated by commas (e.g., dvd, dvd player, hifi)'}</p>
</td>
</tr>
<tr>
<td class="col-left"><label>{l s='Accessories:'}<br /><br /><i>{l s='(Do not forget to Save the product afterward)'}</i></label></td>
<td style="padding-bottom:5px;">
@@ -989,7 +974,7 @@ $(document).ready(function(){
var formProduct;
var accessories = new Array();
</script>
<div id="ajax_choose_product" style="padding:6px; padding-top:2px; width:600px;">
<p class="clear">{l s='Begin typing the first letters of the product name, then select the product from the drop-down list:'}</p>
<input type="text" value="" id="product_autocomplete_input" />
@@ -1035,7 +1020,7 @@ var accessories = new Array();
<br />
</div>
<script type="text/javascript">
toggleVirtualProduct(getE('is_virtual_good'));
unitPriceWithTax('unit');
@@ -45,26 +45,44 @@
{foreach from=$associated_suppliers item=supplier}
<h3 style="margin-bottom:0;"><a href="#">{$supplier->name}</a></h3>
<div style="display:block;">
<table cellpadding="5" cellspacing="5" style="width:80%; margin-left:0;">
<table cellpadding="10" cellspacing="0" class="table">
<thead>
<tr>
<th>{l s='product name'}</th>
<th width="150">{l s='supplier reference'}</th>
<th width="150">{l s='Supplier reference'}</th>
<th width="150">{l s='Unit price tax excluded'}</th>
<th width="150">{l s='Unit price currency'}</th>
</tr>
</thead>
<tbody>
{foreach from=$attributes item=attribute}
{foreach $attributes AS $index => $attribute}
{assign var=reference value=''}
{assign var=price_te value=''}
{assign var=id_currency value=''}
{foreach from=$associated_suppliers_collection item=asc}
{if $asc->id_product == $attribute['id_product'] && $asc->id_product_attribute == $attribute['id_product_attribute'] && $asc->id_supplier == $supplier->id_supplier}
{assign var=reference value=$asc->product_supplier_reference}
{assign var=price_te value=Tools::ps_round($asc->product_supplier_price_te, 2)}
{assign var=id_currency value=$asc->id_currency}
{/if}
{/foreach}
<tr>
<tr {if $index is odd}class="alt_row"{/if}>
<td>{$product_designation[$attribute['id_product_attribute']]}</td>
<td>
<input type="text" size="10" value="{$reference}" name="supplier_reference_{$attribute['id_product']}_{$attribute['id_product_attribute']}_{$supplier->id_supplier}" />
</td>
<td>
<input type="text" size="10" value="{$price_te}" name="product_price_{$attribute['id_product']}_{$attribute['id_product_attribute']}_{$supplier->id_supplier}" />
</td>
<td>
<select name="product_price_currency_{$attribute['id_product']}_{$attribute['id_product_attribute']}_{$supplier->id_supplier}">
{foreach $currencies AS $currency}
<option value="{$currency['id_currency']}"
{if $currency['id_currency'] == $id_currency}selected="selected"{/if}
>{$currency['name']}</option>
{/foreach}
</select>
</td>
</tr>
{/foreach}
</tbody>
@@ -17,13 +17,13 @@
{foreach from=$warehouses item=warehouse}
<h3 style="margin-bottom:0;"><a href="#">{$warehouse['name']}</a></h3>
<div style="display:block;">
<table cellpadding="5" cellspacing="5" style="width:80%; margin-left:0;">
<table cellpadding="10" cellspacing="0" class="table">
<tr>
<th width="100">{l s='In the warehouse?'}</th>
<th>{l s='product name'}</th>
<th width="150">{l s='location in the warehouse (optionnal)'}</th>
</tr>
{foreach from=$attributes item=attribute}
{foreach $attributes AS $index => $attribute}
{assign var=location value=''}
{assign var=selected value=''}
{foreach from=$associated_warehouses item=aw}
@@ -32,7 +32,7 @@
{assign var=selected value=true}
{/if}
{/foreach}
<tr>
<tr {if $index is odd}class="alt_row"{/if}>
<td><input type="checkbox"
name="check_warehouse_{$warehouse['id_warehouse']}_{$attribute['id_product']}_{$attribute['id_product_attribute']}"
{if $selected == true}checked="checked"{/if}
+36
View File
@@ -49,6 +49,16 @@ class ProductSupplierCore extends ObjectModel
* */
public $product_supplier_reference;
/**
* @var integer the currency ID for unit price tax excluded
* */
public $id_currency;
/**
* @var string The unit price tax excluded of the product
* */
public $product_supplier_price_te;
protected $fieldsRequired = array('id_product', 'id_product_attribute', 'id_supplier');
protected $fieldsSize = array('supplier_reference' => 32);
protected $fieldsValidate = array(
@@ -56,6 +66,8 @@ class ProductSupplierCore extends ObjectModel
'id_product' => 'isUnsignedId',
'id_product_attribute' => 'isUnsignedId',
'id_supplier' => 'isUnsignedId',
'product_supplier_price_te' => 'isPrice',
'id_currency' => 'isUnsignedId',
);
protected $table = 'product_supplier';
@@ -69,6 +81,8 @@ class ProductSupplierCore extends ObjectModel
$fields['id_product_attribute'] = (int)$this->id_product_attribute;
$fields['id_supplier'] = (int)$this->id_supplier;
$fields['product_supplier_reference'] = pSQL($this->product_supplier_reference);
$fields['id_currency'] = (int)$this->id_currency;
$fields['product_supplier_price_te'] = pSQL($this->product_supplier_price_te);
return $fields;
}
@@ -95,6 +109,28 @@ class ProductSupplierCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/**
* For a given product and supplier, get the product unit price
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_supplier
* @return array
*/
public static function getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier)
{
// build query
$query = new DbQuery();
$query->select('ps.product_supplier_price_te');
$query->from('product_supplier ps');
$query->where('ps.id_product = '.(int)$id_product.'
AND ps.id_product_attribute = '.(int)$id_product_attribute.'
AND ps.id_supplier = '.(int)$id_supplier
);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/**
* For a given product and supplier, get the ProductSupplier corresponding ID
*
+39 -15
View File
@@ -2021,13 +2021,6 @@ class AdminProductsControllerCore extends AdminController
}
}
// Manage defaut supplier for product
if ($new_default_supplier != 0 && $new_default_supplier != $product->id_supplier && Supplier::supplierExists($new_default_supplier))
{
$product->id_supplier = $new_default_supplier;
$product->update();
}
$this->confirmations[] = $this->l('Suppliers of the product have been updated');
// Get all id_product_attribute
@@ -2038,12 +2031,23 @@ class AdminProductsControllerCore extends AdminController
'attribute_designation' => ''
);
// Manage references
// Manage references and prices
foreach ($attributes as $attribute)
foreach ($associated_suppliers as $supplier)
if (Tools::isSubmit('supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier))
if (Tools::isSubmit('supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier)
||
(
Tools::isSubmit('product_price_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier)
&&
Tools::isSubmit('product_price_currency_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier)
)
)
{
$reference = Tools::getValue('supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, '');
$reference = pSQL(Tools::getValue('supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, ''));
$price = (float)str_replace(array(' ', ','), array('', '.'), Tools::getValue('product_price_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, 0));
$id_currency = (int)Tools::getValue('product_price_currency_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, 0);
if ($id_currency <= 0 || ( !($result = Currency::getCurrency($id_currency)) || empty($result) ))
$this->_errors[] = Tools::displayError($this->l('The selected currency is not valid.'));
if (!empty($reference))
{
@@ -2055,25 +2059,44 @@ class AdminProductsControllerCore extends AdminController
$product_supplier_entity = new ProductSupplier();
$product_supplier_entity->id_product = $product->id;
$product_supplier_entity->id_product_attribute = $attribute['id_product_attribute'];
$product_supplier_entity->id_supplier = $supplier->id_supplier;
$product_supplier_entity->product_supplier_reference = pSQL($reference);
$product_supplier_entity->id_supplier = (int)$supplier->id_supplier;
$product_supplier_entity->product_supplier_reference = $reference;
$product_supplier_entity->id_currency = $id_currency;
$product_supplier_entity->product_supplier_price_te = $price;
$product_supplier_entity->save();
}
else
{
//update existing record
$product_supplier_entity = new ProductSupplier($existing_id);
$reference = pSQL($reference);
if ($product_supplier_entity->product_supplier_reference != $reference)
if (
($product_supplier_entity->product_supplier_reference != $reference)
||
($product_supplier_entity->product_supplier_price_te != $price)
||
($product_supplier_entity->id_currency != $id_currency)
)
{
$product_supplier_entity->product_supplier_reference = pSQL($reference);
$product_supplier_entity->product_supplier_reference = $reference;
$product_supplier_entity->id_currency = $id_currency;
$product_supplier_entity->product_supplier_price_te = $price;
$product_supplier_entity->update();
}
}
if ($product->id_supplier == $supplier->id_supplier)
$product->wholesale_price = Tools::convertPrice($price, $id_currency);
}
}
// Manage defaut supplier for product
if ($new_default_supplier != 0 && $new_default_supplier != $product->id_supplier && Supplier::supplierExists($new_default_supplier))
{
$product->id_supplier = $new_default_supplier;
$product->update();
}
$this->confirmations[] = $this->l('Supplier Reference(s) of the product have been updated');
}
}
@@ -3225,6 +3248,7 @@ class AdminProductsControllerCore extends AdminController
'associated_suppliers' => $associated_suppliers,
'associated_suppliers_collection' => $product_supplier_collection,
'product_designation' => $product_designation,
'currencies' => Currency::getCurrencies(),
'product' => $this->object,
'link' => $this->context->link,
'token' => $this->token
+2
View File
@@ -2241,6 +2241,8 @@ CREATE TABLE `PREFIX_product_supplier` (
`id_product_attribute` int(11) UNSIGNED NOT NULL DEFAULT '0',
`id_supplier` int(11) UNSIGNED NOT NULL,
`product_supplier_reference` varchar(32) DEFAULT NULL,
`product_supplier_price_te` decimal(20,6) NOT NULL DEFAULT '0.000000',
`id_currency` int(11) unsigned NOT NULL,
PRIMARY KEY (`id_product_supplier`),
UNIQUE KEY `id_product` (`id_product`,`id_product_attribute`,`id_supplier`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;