// #PSTEST-457
This commit is contained in:
@@ -138,6 +138,9 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!product_infos.unit_price_te)
|
||||
product_infos.unit_price_te = 0;
|
||||
|
||||
// add a new line in the products table
|
||||
$('#products_in_supply_order > tbody:last').append(
|
||||
'<tr style="height:50px;">'+
|
||||
@@ -145,7 +148,7 @@
|
||||
'<td>'+product_infos.ean13+'<input type="hidden" name="input_ean13_'+product_infos.id+'" value="'+product_infos.ean13+'" /></td>'+
|
||||
'<td>'+product_infos.upc+'<input type="hidden" name="input_upc_'+product_infos.id+'" value="'+product_infos.upc+'" /></td>'+
|
||||
'<td>'+product_infos.name+'<input type="hidden" name="input_name_displayed_'+product_infos.id+'" value="'+product_infos.name+'" /></td>'+
|
||||
'<td class="center">{$currency->prefix} <input type="text" name="input_unit_price_te_'+product_infos.id+'" value="0" size="8" /> {$currency->suffix}</td>'+
|
||||
'<td class="center">{$currency->prefix} <input type="text" name="input_unit_price_te_'+product_infos.id+'" value="'+product_infos.unit_price_te+'" size="8" /> {$currency->suffix}</td>'+
|
||||
'<td class="center"><input type="text" name="input_quantity_expected_'+product_infos.id+'" value="0" size="5" /></td>'+
|
||||
'<td class="center"><input type="text" name="input_discount_rate_'+product_infos.id+'" value="0" size="5" />%</td>'+
|
||||
'<td class="center"><input type="text" name="input_tax_rate_'+product_infos.id+'" value="0" size="5" />%</td>'+
|
||||
@@ -184,8 +187,9 @@
|
||||
product_ids.splice(position, 1);
|
||||
|
||||
var input_id = $('input[name~="input_id_'+product_id+'"]');
|
||||
if (input_id.length > 0)
|
||||
product_ids_to_delete.push(product_id);
|
||||
if (input_id != 'undefined')
|
||||
if (input_id.length > 0)
|
||||
product_ids_to_delete.push(product_id);
|
||||
|
||||
// update the product_ids hidden field
|
||||
$('#product_ids').val(product_ids.join('|'));
|
||||
@@ -216,7 +220,7 @@
|
||||
// set autocomplete on search field
|
||||
$('#cur_product_name').autocomplete("ajax-tab.php", {
|
||||
delay: 100,
|
||||
minChars: 3,
|
||||
minChars: 4,
|
||||
autoFill: true,
|
||||
max:20,
|
||||
matchContains: true,
|
||||
@@ -225,14 +229,15 @@
|
||||
cacheLength:0,
|
||||
dataType: 'json',
|
||||
extraParams: {
|
||||
supplier_id: '{$supplier_id}',
|
||||
id_supplier: '{$supplier_id}',
|
||||
id_currency: '{$currency->id}',
|
||||
ajax : '1',
|
||||
controller : 'AdminSupplyOrders',
|
||||
token : '{$token}',
|
||||
action : 'searchProduct',
|
||||
},
|
||||
parse: function(data) {
|
||||
return $.map(data, function(row) {
|
||||
var res = $.map(data, function(row) {
|
||||
// filter the data to chaeck if the product is already added to the order
|
||||
if (jQuery.inArray(row.id, product_ids) == -1)
|
||||
return {
|
||||
@@ -241,12 +246,15 @@
|
||||
value: row.id
|
||||
}
|
||||
});
|
||||
return res;
|
||||
},
|
||||
formatItem: function(item) {
|
||||
return item.reference + ' - ' + item.name;
|
||||
}
|
||||
}).result(function(event, item){
|
||||
product_infos = item;
|
||||
if (typeof(ajax_running_timeout) !== 'undefined')
|
||||
clearTimeout(ajax_running_timeout);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -137,20 +137,27 @@ class ProductSupplierCore extends ObjectModel
|
||||
* @param int $id_product
|
||||
* @param int $id_product_attribute
|
||||
* @param int $id_supplier
|
||||
* @param bool $with_currency Optional
|
||||
* @return array
|
||||
*/
|
||||
public static function getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier)
|
||||
public static function getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier, $with_currency = false)
|
||||
{
|
||||
// build query
|
||||
$query = new DbQuery();
|
||||
$query->select('ps.product_supplier_price_te');
|
||||
if ($with_currency)
|
||||
$query->select('ps.id_currency');
|
||||
$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);
|
||||
if (!$with_currency)
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $res[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -481,7 +481,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
// formats prices and floats
|
||||
if ($this->def['fields'][$key]['validate'] == 'isFloat' ||
|
||||
$this->def['fields'][$key]['validate'] == 'isPrice')
|
||||
$value = number_format($value, 2);
|
||||
$value = Tools::ps_round($value, 6);
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,22 +219,22 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
protected function calculatePrices()
|
||||
{
|
||||
// calculates entry price
|
||||
$this->price_te = (float)Tools::ps_round((float)$this->unit_price_te * (int)$this->quantity_expected, 6);
|
||||
$this->price_te = Tools::ps_round((float)$this->unit_price_te * (int)$this->quantity_expected, 6);
|
||||
|
||||
// calculates entry discount value
|
||||
if ($this->discount_rate != null && (is_float($this->discount_rate) || is_numeric($this->discount_rate)) && $this->discount_rate > 0)
|
||||
$this->discount_value_te = (float)Tools::ps_round((float)$this->price_te * ($this->discount_rate / 100), 6);
|
||||
$this->discount_value_te = Tools::ps_round((float)$this->price_te * ($this->discount_rate / 100), 6);
|
||||
|
||||
// calculates entry price with discount
|
||||
$this->price_with_discount_te = (float)Tools::ps_round($this->price_te - $this->discount_value_te, 6);
|
||||
$this->price_with_discount_te = Tools::ps_round($this->price_te - $this->discount_value_te, 6);
|
||||
|
||||
// calculates tax value
|
||||
$this->tax_value = (float)Tools::ps_round($this->price_with_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->price_ti = (float)Tools::ps_round($this->price_with_discount_te + $this->tax_value, 6);
|
||||
$this->tax_value = Tools::ps_round($this->price_with_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->price_ti = Tools::ps_round($this->price_with_discount_te + $this->tax_value, 6);
|
||||
|
||||
// defines default values for order discount fields
|
||||
$this->tax_value_with_order_discount = (float)Tools::ps_round($this->tax_value, 6);
|
||||
$this->price_with_order_discount_te = (float)Tools::ps_round($this->price_with_discount_te, 6);
|
||||
$this->tax_value_with_order_discount = Tools::ps_round($this->tax_value, 6);
|
||||
$this->price_with_order_discount_te = Tools::ps_round($this->price_with_discount_te, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,14 +248,14 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
if ($discount_rate != null && is_numeric($discount_rate) && (float)$discount_rate > 0)
|
||||
{
|
||||
// calculates new price, with global order discount, tax ecluded
|
||||
$discount_value = $this->price_with_discount_te - ($this->price_with_discount_te * ((float)$discount_rate / 100));
|
||||
$discount_value = $this->price_with_discount_te - (($this->price_with_discount_te * (float)$discount_rate) / 100);
|
||||
|
||||
$this->price_with_order_discount_te = (float)Tools::ps_round($discount_value, 6);
|
||||
$this->price_with_order_discount_te = Tools::ps_round($discount_value, 6);
|
||||
|
||||
// calculates new tax value, with global order discount
|
||||
$this->tax_value_with_order_discount = (float)Tools::ps_round($this->price_with_order_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->tax_value_with_order_discount = Tools::ps_round($this->price_with_order_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
|
||||
$this->update();
|
||||
parent::update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
// formats prices and floats
|
||||
if ($this->def['fields'][$key]['validate'] == 'isFloat' ||
|
||||
$this->def['fields'][$key]['validate'] == 'isPrice')
|
||||
$value = number_format($value, 2);
|
||||
$value = Tools::ps_round($value, 6);
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,7 +972,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
$id_currency = (int)Tools::getValue('id_currency', 0);
|
||||
if ($id_currency <= 0 || ( !($result = Currency::getCurrency($id_currency)) || empty($result) ))
|
||||
$this->errors[] = Tools::displayError($this->l('The selected currency is not valid.'));
|
||||
|
||||
// get delivery date
|
||||
$delivery_expected = new DateTime(pSQL(Tools::getValue('date_delivery_expected')));
|
||||
// converts date to timestamp
|
||||
@@ -1002,6 +1001,10 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
// manage each associated product
|
||||
$this->manageOrderProducts();
|
||||
|
||||
// if the threshold is defined and we are saving the order
|
||||
if (Tools::isSubmit('submitAddsupply_order') && $quantity_threshold != null)
|
||||
$this->loadProducts($quantity_threshold);
|
||||
}
|
||||
|
||||
// Manage state change
|
||||
@@ -1093,10 +1096,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
if ((!count($this->errors) && $this->is_editing_order) || !$this->is_editing_order)
|
||||
parent::postProcess();
|
||||
|
||||
// if the threshold is defined and we are saving the order
|
||||
if (Tools::isSubmit('submitAddsupply_order') && $quantity_threshold != null)
|
||||
$this->loadProducts($quantity_threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1519,6 +1518,9 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
// get supplier id
|
||||
$id_supplier = (int)Tools::getValue('id_supplier', false);
|
||||
|
||||
// gets the currency
|
||||
$id_currency = (int)Tools::getValue('id_currency', false);
|
||||
|
||||
// get lang from context
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
@@ -1552,10 +1554,18 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
$items = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
$ids = explode('_', $item['id']);
|
||||
$prices = ProductSupplier::getProductSupplierPrice($ids[0], $ids[1], $id_supplier, true);
|
||||
$item['unit_price_te'] = Tools::convertPriceFull($prices['product_supplier_price_te'],
|
||||
new Currency((int)$prices['id_currency']),
|
||||
new Currency($id_currency));
|
||||
}
|
||||
if ($items)
|
||||
die(Tools::jsonEncode($items));
|
||||
|
||||
die();
|
||||
die(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1920,7 +1930,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
$items = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
// loads order currency
|
||||
$order_currency = new Currency($supply_order->id_ref_currency);
|
||||
$order_currency = new Currency($supply_order->id_currency);
|
||||
if (!Validate::isLoadedObject($order_currency))
|
||||
return;
|
||||
|
||||
@@ -1947,7 +1957,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
$product_currency = new Currency($item['id_currency']);
|
||||
if (Validate::isLoadedObject($product_currency))
|
||||
$supply_order_detail->unit_price_te = Tools::convertPriceFull($item['unit_price_te'], $order_currency, $product_currency);
|
||||
$supply_order_detail->unit_price_te = Tools::convertPriceFull($item['unit_price_te'], $product_currency, $order_currency);
|
||||
else
|
||||
$supply_order_detail->unit_price_te = 0;
|
||||
$supply_order_detail->save();
|
||||
|
||||
Reference in New Issue
Block a user