// stock : update and bugs fix on supplier order add product interface and supplier order view interface + toolbar bug fix

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9991 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-11-09 15:11:36 +00:00
parent db61901f68
commit 047efe3e72
5 changed files with 273 additions and 222 deletions
@@ -35,6 +35,10 @@
<td>{l s='Employee:'}</td>
<td>{$supplier_order_employee}</td>
</tr>
<tr>
<td>{l s='Creation date:'}</td>
<td>{$supplier_order_creation_date}</td>
</tr>
<tr>
<td>{l s='Last update:'}</td>
<td>{$supplier_order_last_update}</td>
@@ -47,6 +51,14 @@
<td>{l s='Warehouse:'}</td>
<td>{$supplier_order_warehouse}</td>
</tr>
<tr>
<td>{l s='Currency:'}</td>
<td>{$supplier_order_currency->name}</td>
</tr>
<tr>
<td>{l s='Global discount rate:'}</td>
<td>{$supplier_order_discount_rate} %</td>
</tr>
</table>
</fieldset>
</div>
@@ -64,7 +76,7 @@
<table style="width: 400px;" classe="table">
<tr>
<th>{l s='Designation'}</th>
<th width='60px'>{l s='Value'}</th>
<th width="100px">{l s='Value'}</th>
</tr>
<tr>
<td bgcolor="#000000"></td>
@@ -72,15 +84,15 @@
</tr>
<tr>
<td>{l s='Total TE'}</td>
<td>{$supplier_order_total_te}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_te}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
<tr>
<td>{l s='Discount'}</td>
<td>{$supplier_order_discount_value_te}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_discount_value_te}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
<tr>
<td>{l s='Total with discount TE'}</td>
<td>{$supplier_order_total_with_discount_te}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_with_discount_te}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
<tr>
<td bgcolor="#000000"></td>
@@ -88,11 +100,11 @@
</tr>
<tr>
<td>{l s='Total Tax'}</td>
<td>{$supplier_order_total_tax}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_tax}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
<tr>
<td>{l s='Total TI'}</td>
<td>{$supplier_order_total_ti}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_ti}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
<tr>
<td bgcolor="#000000"></td>
@@ -100,7 +112,7 @@
</tr>
<tr>
<td>{l s='TOTAL TO PAY'}</td>
<td>{$supplier_order_total_ti}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_ti}&nbsp;{$supplier_order_currency->suffix}</td>
</tr>
</table>
</fieldset>
+39 -34
View File
@@ -40,49 +40,54 @@
//get reference on save link
btn_save = $('span[class~="process-icon-save"]').parent();
//get reference on save and stay link
btn_save_and_stay = $('span[class~="process-icon-save-and-stay"]').parent();
//get reference on form submit button
btn_submit = $('#{$table}_form_submit_btn');
//get reference on current save link label
lbl_save = $('#desc-{$table}-save div');
//override save link label with submit button value
lbl_save.html(btn_submit.attr("value"));
if (btn_save_and_stay)
if (btn_save.length > 0)
{
//get reference on save and stay link
btn_save_and_stay = $('span[class~="process-icon-save-and-stay"]').parent();
//get reference on form submit button
btn_submit = $('#{$table}_form_submit_btn');
//get reference on current save link label
lbl_save_and_stay = $('#desc-{$table}-save-and-stay div');
lbl_save = $('#desc-{$table}-save div');
//override save and stay link label with submit button value
lbl_save_and_stay.html(btn_submit.attr("value") + ' and stay');
}
//override save link label with submit button value
if (btn_submit.attr("value").length > 0)
lbl_save.html(btn_submit.attr("value"));
//hide standard submit button
btn_submit.hide();
//submit the form
{block name=formSubmit}
btn_save.click(function() {
//add hidden input to emulate submit button click when posting the form -> field name posted
btn_submit.before('<input type="hidden" name="'+btn_submit.attr("name")+'" value="1" />');
$('#{$table}_form').submit();
});
if (btn_save_and_stay)
if (btn_save_and_stay.length > 0)
{
btn_save_and_stay.click(function() {
//get reference on current save link label
lbl_save_and_stay = $('#desc-{$table}-save-and-stay div');
//override save and stay link label with submit button value
if (btn_submit.attr("value").length > 0)
lbl_save_and_stay.html(btn_submit.attr("value") + ' and stay');
}
//hide standard submit button
btn_submit.hide();
//submit the form
{block name=formSubmit}
btn_save.click(function() {
//add hidden input to emulate submit button click when posting the form -> field name posted
btn_submit.before('<input type="hidden" name="'+btn_submit.attr("name")+'AndStay" value="1" />');
btn_submit.before('<input type="hidden" name="'+btn_submit.attr("name")+'" value="1" />');
$('#{$table}_form').submit();
});
}
{/block}
if (btn_save_and_stay)
{
btn_save_and_stay.click(function() {
//add hidden input to emulate submit button click when posting the form -> field name posted
btn_submit.before('<input type="hidden" name="'+btn_submit.attr("name")+'AndStay" value="1" />');
$('#{$table}_form').submit();
});
}
{/block}
}
});
</script>
{/block}
+1 -3
View File
@@ -219,6 +219,7 @@ class SupplierOrderCore extends ObjectModel
$this->total_ti = 0;
$is_discount = false;
if (is_numeric($this->discount_rate) && (float)$this->discount_rate > 0)
$is_discount = true;
@@ -229,10 +230,7 @@ class SupplierOrderCore extends ObjectModel
{
// apply global discount rate on each product if possible
if ($is_discount)
{
$entry->applyGlobalDiscount((float)$this->discount_rate);
$entry->save();
}
// add new prices to the total
$this->total_te += $entry->price_with_discount_te;
+43 -8
View File
@@ -227,8 +227,8 @@ class SupplierOrderDetailCore extends ObjectModel
$this->price_te = (float)$this->unit_price_te * (int)$this->quantity_expected;
// calcul entry discount value
if ($this->discount_rate != null && is_numeric($this->discount_rate) && $this->discount_rate > 0)
$htis->discount_value_te = (float)$this->price_te * ((float)$this->discount_rate / 100);
if ($this->discount_rate != null && is_float($this->discount_rate) && $this->discount_rate > 0)
$this->discount_value_te = (float)$this->price_te * ($this->discount_rate / 100);
// calcul entry price with discount
$this->price_with_discount_te = $this->price_te - $this->discount_value_te;
@@ -239,7 +239,7 @@ class SupplierOrderDetailCore extends ObjectModel
// define default values for order discount fields
$this->tax_value_with_order_discount = $this->tax_value;
$this->price_with_order_dscount_te = $this->price_with_discount_te;
$this->price_with_order_discount_te = $this->price_with_discount_te;
}
/**
@@ -252,10 +252,12 @@ class SupplierOrderDetailCore extends ObjectModel
if ($discount_rate != null && is_numeric($discount_rate) && (float)$discount_rate > 0)
{
// calculate new price, with global order discount, tax ecluded
$this->price_with_order_dscount_te = $this->price_with_discount_te - ($this->price_with_discount_te * ((float)$discount_rate / 100));
$this->price_with_order_discount_te = $this->price_with_discount_te - ($this->price_with_discount_te * ((float)$discount_rate / 100));
// calculate new tax value, with global order discount
$this->tax_value_with_order_discount = $this->price_with_order_dscount_te * ((float)$this->tax_rate / 100);
$this->tax_value_with_order_discount = $this->price_with_order_discount_te * ((float)$this->tax_rate / 100);
parent::update();
}
}
@@ -264,15 +266,48 @@ class SupplierOrderDetailCore extends ObjectModel
*/
public function validateController($htmlentities = true)
{
$errors = parent::validateController($htmlentities);
$errors = array();
/* Checking for required fields */
$fields_required = $this->fieldsRequired;
if (isset(self::$fieldsRequiredDatabase[get_class($this)]))
$fields_required = array_merge(
$this->fieldsRequired,
self::$fieldsRequiredDatabase[get_class($this)]
);
foreach ($fields_required as $field)
if (($value = $this->{$field}) == false && (string)$value != '0')
if (!$this->id || $field != 'passwd')
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities)
.'</b> '.Tools::displayError('is required.');
/* Checking for maximum fields sizes */
foreach ($this->fieldsSize as $field => $max_length)
if ($value = $this->{$field} && Tools::strlen($value) > $max_length)
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities)
.'</b> '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$max_length.')';
/* Checking for fields validity */
foreach ($this->fieldsValidate as $field => $function)
if ($value = $this->{$field})
if (!Validate::$function($value) && (!empty($value) || in_array($field, $this->fieldsRequired)))
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is invalid.');
else
if ($field == 'passwd')
if ($value = Tools::getValue($field))
$this->{$field} = Tools::encrypt($value);
else
$this->{$field} = $value;
if ($this->quantity_expected <= 0)
$errors[] = '<b>'.self::displayFieldName('quantity_expected', get_class($this)).'</b> '.Tools::displayError('is invalid.');
if ($this->tax_rate <= 0 || $this->tax_rate > 100)
if ($this->tax_rate < 0 || $this->tax_rate > 100)
$errors[] = '<b>'.self::displayFieldName('tax_rate', get_class($this)).'</b> '.Tools::displayError('is invalid.');
if ($this->discount_rate <= 0 || $this->discount_rate > 100)
if ($this->discount_rate < 0 || $this->discount_rate > 100)
$errors[] = '<b>'.self::displayFieldName('discount_rate', get_class($this)).'</b> '.Tools::displayError('is invalid.');
return $errors;
@@ -351,11 +351,11 @@ class AdminSupplierOrdersControllerCore extends AdminController
),
array(
'type' => 'text',
'label' => $this->l('Global discount rate:'),
'label' => $this->l('Global discount rate (%):'),
'name' => 'discount_rate',
'size' => 7,
'required' => true,
'p' => $this->l('This is the global discount rate for the order.'),
'p' => $this->l('This is the global discount rate in percents for the order.'),
),
),
'submit' => array(
@@ -1400,178 +1400,36 @@ class AdminSupplierOrdersControllerCore extends AdminController
// gets the id supplier to view
$id_supplier_order = (int)Tools::getValue('id_supplier_order');
// re-defines fieldsDisplay
$this->fieldsDisplay = array(
'p_reference' => array(
'title' => $this->l('Reference'),
'align' => 'center',
'width' => 100,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_ean13' => array(
'title' => $this->l('EAN13'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_name' => array(
'title' => $this->l('Name'),
'width' => 350,
'orderby' => false,
'filter' => false,
'search' => false,
),
'unit_price_te' => array(
'title' => $this->l('Unit price (te)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'quantity_expected' => array(
'title' => $this->l('Quantity'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'price_te' => array(
'title' => $this->l('Price (te)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'discount_rate' => array(
'title' => $this->l('Discount rate'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'discount_value_te' => array(
'title' => $this->l('Discount value (te)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'price_with_discount_te' => array(
'title' => $this->l('Price with product discount (te)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'tax_rate' => array(
'title' => $this->l('Tax rate'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'tax_value' => array(
'title' => $this->l('Tax value'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'price_ti' => array(
'title' => $this->l('Price (ti)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'tax_value_with_order_discount' => array(
'title' => $this->l('Tax value with global order discount'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'price_with_order_discount_te' => array(
'title' => $this->l('Price with global order discount (te)'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
'exchange_rate' => array(
'title' => $this->l('Exchange rate'),
'align' => 'center',
'width' => 75,
'orderby' => false,
'filter' => false,
'search' => false,
),
);
// just in case..
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
// gets all information on the products ordered
$this->_select = '
CONCAT(a.unit_price_te, \' \', c.sign) as unit_price_te,
CONCAT(a.price_te, \' \', c.sign) as price_te,
CONCAT(a.discount_value_te, \' \', c.sign) as discount_value_te,
CONCAT(a.price_with_discount_te, \' \', c.sign) as price_with_discount_te,
CONCAT(a.tax_value, \' \', c.sign) as tax_value,
CONCAT(a.price_ti, \' \', c.sign) as price_ti,
CONCAT(a.tax_value_with_order_discount, \' \', c.sign) as tax_value_with_order_discount,
CONCAT(a.price_with_order_discount_te, \' \', c.sign) as price_with_order_discount_te,
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.name, \' - \', al.name SEPARATOR \', \')), pl.name) as p_name,
p.reference as p_reference,
p.ean13 as p_ean13';
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.name, \' - \', al.name SEPARATOR \', \')), pl.name) as p_name,
p.reference as p_reference,
p.ean13 as p_ean13';
$this->_join = '
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = a.id_product)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'currency c ON (a.id_currency = c.id_currency)';
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = a.id_product)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')';
$this->_where = 'AND a.`id_supplier_order` = '.(int)$id_supplier_order;
$this->_group = 'GROUP BY a.id_product';
// gets the list ordered by price desc, without limit
$this->getList($lang_id, 'price_te', 'DESC', 0, false, false);
// renders list
$helper = new HelperList();
$helper->simple_header = true;
$helper->no_link = true;
$helper->show_toolbar = false;
$helper->toolbar_fix = false;
$helper->shopLinkType = '';
$helper->identifier = $this->identifier;
// generates content
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
// displays content
// gets global order information
$supplier_order = new SupplierOrder((int)$id_supplier_order);
if (Validate::isLoadedObject($supplier_order))
{
// gets the list ordered by price desc, without limit
$this->getList($lang_id, 'price_te', 'DESC', 0, false, false);
// gets the currency used in this order
$currency = Currency::getCurrency($supplier_order->id_currency);
$currency = new Currency($supplier_order->id_currency);
// gets the employee in charge of the order
$employee = new Employee($supplier_order->id_employee);
@@ -1579,24 +1437,167 @@ class AdminSupplierOrdersControllerCore extends AdminController
// gets the warehouse where products will be received
$warehouse = new Warehouse($supplier_order->id_warehouse);
// sets toolbar title with order reference
$this->toolbar_title = sprintf($this->l('View Supplier Order #%s'), $supplier_order->reference);
// re-defines fieldsDisplay
$this->fieldsDisplay = array(
'p_reference' => array(
'title' => $this->l('Reference'),
'align' => 'center',
'width' => 120,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_ean13' => array(
'title' => $this->l('EAN13'),
'align' => 'center',
'width' => 100,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_name' => array(
'title' => $this->l('Name'),
'orderby' => false,
'filter' => false,
'search' => false,
),
'unit_price_te' => array(
'title' => $this->l('Unit price (te)'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
'quantity_expected' => array(
'title' => $this->l('Quantity'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
),
'price_te' => array(
'title' => $this->l('Price (te)'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
'discount_rate' => array(
'title' => $this->l('Discount rate'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'suffix' => '%',
),
'discount_value_te' => array(
'title' => $this->l('Discount value (te)'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
'price_with_discount_te' => array(
'title' => $this->l('Price with product discount (te)'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
'tax_rate' => array(
'title' => $this->l('Tax rate'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'suffix' => '%',
),
'tax_value' => array(
'title' => $this->l('Tax value'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
'price_ti' => array(
'title' => $this->l('Price (ti)'),
'align' => 'right',
'width' => 80,
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
),
);
//some staff before render list
foreach ($this->_list as &$item)
{
$item['unit_price_te'] = Tools::ps_round($item['unit_price_te'], (int)$currency->decimals + 1);
$item['price_te'] = Tools::ps_round($item['price_te'], (int)$currency->decimals + 1);
$item['tax_value'] = Tools::ps_round($item['tax_value'], (int)$currency->decimals + 1);
$item['tax_value_with_order_discount'] = Tools::ps_round($item['tax_value_with_order_discount'], (int)$currency->decimals + 1);
$item['price_ti'] = Tools::ps_round($item['price_ti'], (int)$currency->decimals + 1);
$item['price_with_discount_te'] = Tools::ps_round($item['price_with_discount_te'], (int)$currency->decimals + 1);
$item['price_with_order_discount_te'] = Tools::ps_round($item['price_with_order_discount_te'], (int)$currency->decimals + 1);
$item['discount_value_te'] = Tools::ps_round($item['discount_value_te'], (int)$currency->decimals + 1);
$item['discount_rate'] = Tools::ps_round($item['discount_rate'], 2);
$item['tax_rate'] = Tools::ps_round($item['tax_rate'], 2);
}
// renders list
$helper = new HelperList();
$helper->simple_header = true;
$helper->no_link = true;
$helper->show_toolbar = false;
$helper->toolbar_fix = false;
$helper->shopLinkType = '';
$helper->identifier = $this->identifier;
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
// display these global order informations
$this->tpl_view_vars = array(
'supplier_order_detail_content' => $content,
'supplier_order_currency_sign' => $currency ? $currency['sign'] : '',
'supplier_order_employee' => (Validate::isLoadedObject($employee) ? $employee->firstname.' '.$employee->lastname : ''),
'supplier_order_warehouse' => (Validate::isLoadedObject($warehouse) ? $warehouse->name : ''),
'supplier_order_reference' => $supplier_order->reference,
'supplier_order_last_update' => $supplier_order->date_upd,
'supplier_order_expected' => $supplier_order->date_delivery_expected,
'supplier_order_total_te' => $supplier_order->total_te,
'supplier_order_discount_value_te' => $supplier_order->discount_value_te,
'supplier_order_total_with_discount_te' => $supplier_order->total_with_discount_te,
'supplier_order_total_tax' => $supplier_order->total_tax,
'supplier_order_total_ti' => $supplier_order->total_ti,
'supplier_order_creation_date' => Tools::displayDate($supplier_order->date_add, $lang_id, true),
'supplier_order_last_update' => Tools::displayDate($supplier_order->date_upd, $lang_id, true),
'supplier_order_expected' => Tools::displayDate($supplier_order->date_delivery_expected, $lang_id, true),
'supplier_order_discount_rate' => Tools::ps_round($supplier_order->discount_rate, 2),
'supplier_order_total_te' => Tools::ps_round($supplier_order->total_te, (int)$currency->decimals + 1),
'supplier_order_discount_value_te' => Tools::ps_round($supplier_order->discount_value_te, (int)$currency->decimals + 1),
'supplier_order_total_with_discount_te' => Tools::ps_round($supplier_order->total_with_discount_te, (int)$currency->decimals + 1),
'supplier_order_total_tax' => Tools::ps_round($supplier_order->total_tax, (int)$currency->decimals + 1),
'supplier_order_total_ti' => Tools::ps_round($supplier_order->total_ti, (int)$currency->decimals + 1),
'supplier_order_currency' => $currency,
);
// sets toolbar title with order reference
$this->toolbar_title = sprintf($this->l('View Supplier Order #%s'), $supplier_order->reference);
}
return parent::initView();
}