// stock : debug + interfaces optimizations + stockManager update

This commit is contained in:
dSevere
2011-11-10 17:30:16 +00:00
parent cb86145611
commit a2c3001445
17 changed files with 540 additions and 379 deletions
@@ -189,7 +189,16 @@
$('#supplier_order_form').submit();
});
// set autocomplete
// bind enter key event on search field
$('#cur_product_name').bind('keypress', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
e.stopPropagation();//Stop event propagation
return false;
}
});
// set autocomplete on search field
$('#cur_product_name').autocomplete("ajax_supplier_order_products_list.php", {
delay: 100,
minChars: 4,
@@ -31,7 +31,5 @@ $(function() {
});
});
</script>
<fieldset>
<legend>{l s='Order'} #{$supplier_order_reference}</legend>
{$content}
</fieldset>
{$content}
@@ -84,15 +84,15 @@
</tr>
<tr>
<td>{l s='Total TE'}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_te}&nbsp;{$supplier_order_currency->suffix}</td>
<td align="right">{$supplier_order_total_te}</td>
</tr>
<tr>
<td>{l s='Discount'}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_discount_value_te}&nbsp;{$supplier_order_currency->suffix}</td>
<td align="right">{$supplier_order_discount_value_te}</td>
</tr>
<tr>
<td>{l s='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>
<td align="right">{$supplier_order_total_with_discount_te}</td>
</tr>
<tr>
<td bgcolor="#000000"></td>
@@ -100,11 +100,11 @@
</tr>
<tr>
<td>{l s='Total Tax'}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_tax}&nbsp;{$supplier_order_currency->suffix}</td>
<td align="right">{$supplier_order_total_tax}</td>
</tr>
<tr>
<td>{l s='Total TI'}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_ti}&nbsp;{$supplier_order_currency->suffix}</td>
<td align="right">{$supplier_order_total_ti}</td>
</tr>
<tr>
<td bgcolor="#000000"></td>
@@ -112,7 +112,7 @@
</tr>
<tr>
<td>{l s='TOTAL TO PAY'}</td>
<td align="right">{$supplier_order_currency->prefix}&nbsp;{$supplier_order_total_ti}&nbsp;{$supplier_order_currency->suffix}</td>
<td align="right">{$supplier_order_total_ti}</td>
</tr>
</table>
</fieldset>
+30 -19
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -29,13 +29,13 @@ class OrderHistoryCore extends ObjectModel
{
/** @var integer Order id */
public $id_order;
/** @var integer Order state id */
public $id_order_state;
/** @var integer Employee id for this history entry */
public $id_employee;
/** @var string Object creation date */
public $date_add;
@@ -43,13 +43,13 @@ class OrderHistoryCore extends ObjectModel
public $date_upd;
protected $tables = array ('order_history');
protected $fieldsRequired = array('id_order', 'id_order_state');
protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'id_order_state' => 'isUnsignedId', 'id_employee' => 'isUnsignedId');
protected $table = 'order_history';
protected $identifier = 'id_order_history';
protected $webserviceParameters = array(
'objectsNodeName' => 'order_histories',
'fields' => array(
@@ -61,12 +61,12 @@ class OrderHistoryCore extends ObjectModel
public function getFields()
{
$this->validateFields();
$fields['id_order'] = (int)$this->id_order;
$fields['id_order_state'] = (int)$this->id_order_state;
$fields['id_employee'] = (int)$this->id_employee;
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
@@ -76,7 +76,7 @@ class OrderHistoryCore extends ObjectModel
{
Hook::updateOrderStatus((int)($new_order_state), (int)$id_order);
$order = new Order((int)($id_order));
/* Best sellers */
$newOS = new OrderState((int)($new_order_state), $order->id_lang);
$oldOrderStatus = OrderHistory::getLastOrderState((int)$id_order);
@@ -91,20 +91,31 @@ class OrderHistoryCore extends ObjectModel
/* If becoming unlogable => removing sale */
elseif (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']);
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == Configuration::get('PS_OS_ERROR'))
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity']);
else if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0) // The product is removed from the physical stock. $id_warehouse is needed
Stock::updateQuantity($product['id_product'], $product['id_product_attribute'], -$product['cart_quantity'], $id_warehouse, $id_order);
{
$manager = StockManagerFactory::getManager();
$warehouse = new Warehouse($id_warehouse);
$manager->removeProduct($product['id_product'],
$product['id_product_attribute'],
$warehouse,
$product['cart_quantity'],
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
true,
(int)$id_order);
}
// @todo If the old order states was "shipped" and the new is "not shipped" the stock is not decremented
}
$this->id_order_state = (int)($new_order_state);
/* Change invoice number of order ? */
if (!Validate::isLoadedObject($newOS) OR !Validate::isLoadedObject($order))
die(Tools::displayError('Invalid new order state'));
/* The order is valid only if the invoice is available and the order is not cancelled */
$order->valid = $newOS->logable;
$order->update();
@@ -134,7 +145,7 @@ class OrderHistoryCore extends ObjectModel
if (!$context)
$context = Context::getContext();
$lastOrderState = $this->getLastOrderState($this->id_order);
if (!parent::add($autodate))
return false;
@@ -156,7 +167,7 @@ class OrderHistoryCore extends ObjectModel
$order = new Order((int)$this->id_order);
$data['{total_paid}'] = Tools::displayPrice((float)$order->total_paid, new Currency((int)$order->id_currency), false);
$data['{order_name}'] = sprintf("#%06d", (int)$order->id);
// An additional email is sent the first time a virtual item is validated
if ($virtualProducts = $order->getVirtualProducts() AND (!$lastOrderState OR !$lastOrderState->logable) AND $newOrderState = new OrderState($this->id_order_state, Configuration::get('PS_LANG_DEFAULT')) AND $newOrderState->logable)
{
@@ -196,13 +207,13 @@ class OrderHistoryCore extends ObjectModel
return true;
}
public function isValidated()
{
return Db::getInstance()->getValue('
SELECT COUNT(oh.`id_order_history`) AS nb
FROM `'._DB_PREFIX_.'order_state` os
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (os.`id_order_state` = oh.`id_order_state`)
FROM `'._DB_PREFIX_.'order_state` os
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (os.`id_order_state` = oh.`id_order_state`)
WHERE oh.`id_order` = '.(int)$this->id_order.'
AND os.`logable` = 1');
}
+2
View File
@@ -378,6 +378,8 @@ class ToolsCore
*/
public static function displayPrice($price, $currency = NULL, $no_utf8 = false, Context $context = null)
{
if (!is_numeric($price))
return $price;
if (!$context)
$context = Context::getContext();
if ($currency === NULL)
-30
View File
@@ -73,34 +73,4 @@ class StockCore extends ObjectModel
$fields['price_te'] = (float)round($this->price_te, 6);
return $fields;
}
/**
* For a given id_product and id_product_attribute update the quantity in stock
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_warehouse, $id_order = null)
{
$warehouse = new Warehouse($id_warehouse);
// Update quantity of the pack products
if (Pack::isPack($id_product))
{
$products_pack = Pack::getItems((int)$product['id_product'], (int)Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1);
self::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_warehouse, $id_order);
}
}
if ($delta_quantity > 0)
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_INC_REASON_DEFAULT');
else
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_DEC_REASON_DEFAULT');
StockManagerFactory::getManager()->removeProduct($id_product,
$id_product_attribute,
$warehouse,
$delta_quantity,
$id_stock_mvt_reason,
true,
(int)$id_order);
}
}
+171 -157
View File
@@ -202,188 +202,202 @@ class StockManagerCore implements StockManagerInterface
$context = Context::getContext();
// gets total quantities in stock for the current product
$physical_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false);
$usable_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true);
// check quantity if we want to decrement unusable quantity
if (!$is_usable)
$quantity_in_stock = $physical_quantity_in_stock - $usable_quantity_in_stock;
else
$quantity_in_stock = $usable_quantity_in_stock;
// checks if it's possible to remove the given quantity
if ($quantity_in_stock < $quantity)
return $return;
$stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id);
// check if the collection is loaded
if (count($stock_collection) <= 0)
return $return;
$stock_history_qty_available = array();
$mvt_params = array();
$stock_params = array();
$quantity_to_decrement_by_stock = array();
$global_quantity_to_decrement = $quantity;
// switch on MANAGEMENT_TYPE
switch ($warehouse->management_type)
// Special case of a pack
if (Pack::isPack($id_product))
{
// case CUMP mode
case 'WA':
// There is one and only one stock for a given product in a warehouse in this mode
$stock = $stock_collection[0];
$products_pack = Pack::getItems((int)$product['id_product'], (int)Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1); //@TODO is there a better way to retrieve the product attribute assciated to the pack ?
$this->removeProduct($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $quantity, $warehouse, $id_order);
}
}
else
{
// gets total quantities in stock for the current product
$physical_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false);
$usable_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true);
$mvt_params = array(
'id_stock' => $stock->id,
'physical_quantity' => $quantity,
'id_stock_mvt_reason' => $id_stock_mvt_reason,
'id_order' => $id_order,
'price_te' => $stock->price_te,
'last_wa' => $stock->price_te,
'current_wa' => $stock->price_te,
'id_employee' => $context->employee->id,
'sign' => -1
);
$stock_params = array(
'physical_quantity' => ($stock->physical_quantity - $quantity),
'usable_quantity' => ($is_usable ? ($stock->usable_quantity - $quantity) : $stock->usable_quantity)
);
// check quantity if we want to decrement unusable quantity
if (!$is_usable)
$quantity_in_stock = $physical_quantity_in_stock - $usable_quantity_in_stock;
else
$quantity_in_stock = $usable_quantity_in_stock;
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
// checks if it's possible to remove the given quantity
if ($quantity_in_stock < $quantity)
return $return;
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->save();
$stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id);
$return[$stock->id]['quantity'] = $quantity;
$return[$stock->id]['price_te'] = $stock->price_te;
// check if the collection is loaded
if (count($stock_collection) <= 0)
return $return;
break;
$stock_history_qty_available = array();
$mvt_params = array();
$stock_params = array();
$quantity_to_decrement_by_stock = array();
$global_quantity_to_decrement = $quantity;
case 'LIFO':
case 'FIFO':
// switch on MANAGEMENT_TYPE
switch ($warehouse->management_type)
{
// case CUMP mode
case 'WA':
// There is one and only one stock for a given product in a warehouse in this mode
$stock = $stock_collection[0];
// for each stock, parse its mvts history to calculate the quantities left for each positive mvt,
// according to the instant available quantities for this stock
foreach ($stock_collection as $stock)
{
$left_quantity_to_check = $stock->physical_quantity;
if ($left_quantity_to_check <= 0)
continue;
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
SELECT sm.`id_stock_mvt`, sm.`date_add`, sm.`physical_quantity`,
IF ((sm2.`physical_quantity` is null), sm.`physical_quantity`, (sm.`physical_quantity` - SUM(sm2.`physical_quantity`))) as qty
FROM `'._DB_PREFIX_.'stock_mvt` sm
LEFT JOIN `'._DB_PREFIX_.'stock_mvt` sm2 ON sm2.`referer` = sm.`id_stock_mvt`
WHERE sm.`sign` = 1
AND sm.`id_stock` = '.(int)$stock->id.'
GROUP BY sm.`id_stock_mvt`
ORDER BY sm.`date_add` DESC'
$mvt_params = array(
'id_stock' => $stock->id,
'physical_quantity' => $quantity,
'id_stock_mvt_reason' => $id_stock_mvt_reason,
'id_order' => $id_order,
'price_te' => $stock->price_te,
'last_wa' => $stock->price_te,
'current_wa' => $stock->price_te,
'id_employee' => $context->employee->id,
'sign' => -1
);
$stock_params = array(
'physical_quantity' => ($stock->physical_quantity - $quantity),
'usable_quantity' => ($is_usable ? ($stock->usable_quantity - $quantity) : $stock->usable_quantity)
);
while ($row = Db::getInstance()->nextRow($resource))
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->save();
$return[$stock->id]['quantity'] = $quantity;
$return[$stock->id]['price_te'] = $stock->price_te;
break;
case 'LIFO':
case 'FIFO':
// for each stock, parse its mvts history to calculate the quantities left for each positive mvt,
// according to the instant available quantities for this stock
foreach ($stock_collection as $stock)
{
// break - in FIFO mode, we have to retreive the oldest positive mvts for which there are left quantities
if ($warehouse->management_type == 'FIFO')
if ($row['qty'] == 0)
break;
$left_quantity_to_check = $stock->physical_quantity;
if ($left_quantity_to_check <= 0)
continue;
// converts date to timestamp
$date = new DateTime($row['date_add']);
$timestamp = $date->format('U');
// history of the mvt
$stock_history_qty_available[$timestamp] = array(
'id_stock' => $stock->id,
'id_stock_mvt' => (int)$row['id_stock_mvt'],
'qty' => (int)$row['qty']
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
SELECT sm.`id_stock_mvt`, sm.`date_add`, sm.`physical_quantity`,
IF ((sm2.`physical_quantity` is null), sm.`physical_quantity`, (sm.`physical_quantity` - SUM(sm2.`physical_quantity`))) as qty
FROM `'._DB_PREFIX_.'stock_mvt` sm
LEFT JOIN `'._DB_PREFIX_.'stock_mvt` sm2 ON sm2.`referer` = sm.`id_stock_mvt`
WHERE sm.`sign` = 1
AND sm.`id_stock` = '.(int)$stock->id.'
GROUP BY sm.`id_stock_mvt`
ORDER BY sm.`date_add` DESC'
);
// break - in LIFO mode, checks only the necessary history to handle the global quantity for the current stock
if ($warehouse->management_type == 'LIFO')
while ($row = Db::getInstance()->nextRow($resource))
{
$left_quantity_to_check -= (int)$row['physical_quantity'];
if ($left_quantity_to_check <= 0)
break;
}
}
}
// break - in FIFO mode, we have to retreive the oldest positive mvts for which there are left quantities
if ($warehouse->management_type == 'FIFO')
if ($row['qty'] == 0)
break;
if ($warehouse->management_type == 'LIFO')
// orders stock history by timestamp to get newest history first
krsort($stock_history_qty_available);
else
// orders stock history by timestamp to get oldest history first
ksort($stock_history_qty_available);
// converts date to timestamp
$date = new DateTime($row['date_add']);
$timestamp = $date->format('U');
// checks each stock to manage the real quantity to decrement for each of them
foreach ($stock_history_qty_available as $entry)
{
if ($entry['qty'] >= $global_quantity_to_decrement)
{
$quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $global_quantity_to_decrement;
$global_quantity_to_decrement = 0;
}
else
{
$quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $entry['qty'];
$global_quantity_to_decrement -= $entry['qty'];
}
if ($global_quantity_to_decrement <= 0)
break;
}
// for each stock, decrements it and logs the mvts
foreach ($stock_collection as $stock)
{
if (array_key_exists($stock->id, $quantity_to_decrement_by_stock) && is_array($quantity_to_decrement_by_stock[$stock->id]))
{
$total_quantity_for_current_stock = 0;
foreach ($quantity_to_decrement_by_stock[$stock->id] as $id_mvt_referrer => $qte)
{
$mvt_params = array(
// history of the mvt
$stock_history_qty_available[$timestamp] = array(
'id_stock' => $stock->id,
'physical_quantity' => $qte,
'id_stock_mvt_reason' => $id_stock_mvt_reason,
'id_order' => $id_order,
'price_te' => $stock->price_te,
'sign' => -1,
'referer' => $id_mvt_referrer,
'id_employee' => $context->employee->id
'id_stock_mvt' => (int)$row['id_stock_mvt'],
'qty' => (int)$row['qty']
);
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->save();
// break - in LIFO mode, checks only the necessary history to handle the global quantity for the current stock
if ($warehouse->management_type == 'LIFO')
{
$left_quantity_to_check -= (int)$row['physical_quantity'];
if ($left_quantity_to_check <= 0)
break;
}
}
}
$total_quantity_for_current_stock += $qte;
if ($warehouse->management_type == 'LIFO')
// orders stock history by timestamp to get newest history first
krsort($stock_history_qty_available);
else
// orders stock history by timestamp to get oldest history first
ksort($stock_history_qty_available);
// checks each stock to manage the real quantity to decrement for each of them
foreach ($stock_history_qty_available as $entry)
{
if ($entry['qty'] >= $global_quantity_to_decrement)
{
$quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $global_quantity_to_decrement;
$global_quantity_to_decrement = 0;
}
else
{
$quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $entry['qty'];
$global_quantity_to_decrement -= $entry['qty'];
}
$stock_params = array(
'physical_quantity' => ($stock->physical_quantity - $total_quantity_for_current_stock),
'usable_quantity' => ($is_usable ? ($stock->usable_quantity - $total_quantity_for_current_stock) : $stock->usable_quantity)
);
$return[$stock->id]['quantity'] = $total_quantity_for_current_stock;
$return[$stock->id]['price_te'] = $stock->price_te;
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
if ($global_quantity_to_decrement <= 0)
break;
}
}
break;
// for each stock, decrements it and logs the mvts
foreach ($stock_collection as $stock)
{
if (array_key_exists($stock->id, $quantity_to_decrement_by_stock) && is_array($quantity_to_decrement_by_stock[$stock->id]))
{
$total_quantity_for_current_stock = 0;
foreach ($quantity_to_decrement_by_stock[$stock->id] as $id_mvt_referrer => $qte)
{
$mvt_params = array(
'id_stock' => $stock->id,
'physical_quantity' => $qte,
'id_stock_mvt_reason' => $id_stock_mvt_reason,
'id_order' => $id_order,
'price_te' => $stock->price_te,
'sign' => -1,
'referer' => $id_mvt_referrer,
'id_employee' => $context->employee->id
);
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->save();
$total_quantity_for_current_stock += $qte;
}
$stock_params = array(
'physical_quantity' => ($stock->physical_quantity - $total_quantity_for_current_stock),
'usable_quantity' => ($is_usable ? ($stock->usable_quantity - $total_quantity_for_current_stock) : $stock->usable_quantity)
);
$return[$stock->id]['quantity'] = $total_quantity_for_current_stock;
$return[$stock->id]['price_te'] = $stock->price_te;
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
}
}
break;
}
}
return $return;
}
+12 -5
View File
@@ -33,28 +33,35 @@ class StockMvtCore extends ObjectModel
/**
* @since 1.5.0
* @var int
* @var int The stock id on wtich the movement is applied
*/
public $id_stock;
/**
* @since 1.5.0
* @var int
* @var int the quantity of product with is moved
*/
public $physical_quantity;
/**
* @var int id of the movement reason assoiated to the movement
*/
public $id_stock_mvt_reason;
/**
* @var int Used when the movement is due to a customer order
*/
public $id_order = null;
/**
* @since 1.5.0
* @var int
* @var int detrmine if the movement is a positive or negative operation
*/
public $sign;
/**
* @since 1.5.0
* @var int Will be used when supplier order are implemented
* @var int Used when the movement is due to a supplier order
*/
public $id_supplier_order = null;
@@ -72,7 +79,7 @@ class StockMvtCore extends ObjectModel
/**
* @since 1.5.0
* @var float
* @var float The unit price without tax of the product associated to the movement
*/
public $price_te;
+17 -1
View File
@@ -27,14 +27,26 @@
class StockMvtReasonCore extends ObjectModel
{
/** @var int identifier of the movement reason */
public $id;
/** @var string the name of the movement reason */
public $name;
/** @var int detrmine if the movement reason correspond to a positive or negative operation */
public $sign;
/** @var string the creation date of the movement reason */
public $date_add;
/** @var string the last update date of the movement reason */
public $date_upd;
/** @var boolean True if the movement reason has been deleted (staying in database as deleted) */
public $deleted = 0;
protected $table = 'stock_mvt_reason';
protected $identifier = 'id_stock_mvt_reason';
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 255);
protected $fieldsValidateLang = array('name' => 'isGenericName');
@@ -50,6 +62,7 @@ class StockMvtReasonCore extends ObjectModel
$fields['sign'] = (int)$this->sign;
$fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd);
$fields['deleted'] = (int)$this->deleted;
return $fields;
}
@@ -65,6 +78,7 @@ class StockMvtReasonCore extends ObjectModel
$query->select('smrl.name, smr.id_stock_mvt_reason, smr.sign');
$query->from('stock_mvt_reason smr');
$query->leftjoin('stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')');
$query->where('smr.deleted = 0');
if ($sign != null)
$query->where('smr.sign = '.(int)$sign);
@@ -86,6 +100,7 @@ class StockMvtReasonCore extends ObjectModel
$query->select('smrl.name, smr.id_stock_mvt_reason, smr.sign');
$query->from('stock_mvt_reason smr');
$query->leftjoin('stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')');
$query->where('smr.deleted = 0');
if ($sign != null)
$query->where('smr.sign = '.(int)$sign);
@@ -111,6 +126,7 @@ class StockMvtReasonCore extends ObjectModel
$query->select('smr.id_stock_mvt_reason');
$query->from('stock_mvt_reason smr');
$query->where('smr.id_stock_mvt_reason = '.(int)$id_stock_mvt_reason);
$query->where('smr.deleted = 0');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
}
+18
View File
@@ -32,13 +32,27 @@
*/
class WarehouseCore extends ObjectModel
{
/** @var int identifier of the warehouse */
public $id;
/** @var int The id of the address associated to the warehouse */
public $id_address;
/** @var string The reference of the warehouse */
public $reference;
/** @var string The name of the warehouse */
public $name;
/** @var int The id of the employee who is responsible of the warehouse */
public $id_employee;
/** @var int The id of the valuation currency of the warehouse */
public $id_currency;
/** @var boolean True if warehouse has been deleted (staying in database as deleted) */
public $deleted = 0;
/**
* Describes the way a Warehouse is managed
* @var enum WA|LIFO|FIFO
@@ -78,9 +92,11 @@ class WarehouseCore extends ObjectModel
$fields['id_address'] = (int)$this->id_address;
$fields['reference'] = $this->reference;
$fields['name'] = pSQL($this->name);
$fields['deleted'] = (int)$this->deleted;
$fields['id_employee'] = (int)$this->id_employee;
$fields['management_type'] = pSQL($this->management_type);
$fields['id_currency'] = (int)$this->id_currency;
return $fields;
}
@@ -192,6 +208,7 @@ class WarehouseCore extends ObjectModel
$query->select('id_warehouse');
$query->from('warehouse');
$query->where('id_warehouse = '.(int)$id_warehouse);
$query->where('deleted = 0');
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query));
}
@@ -259,6 +276,7 @@ class WarehouseCore extends ObjectModel
$query = new DbQuery();
$query->select('w.id_warehouse, name');
$query->from('warehouse w');
$query->where('deleted = 0');
if (!$ignore_shop)
$query->innerJoin('warehouse_shop ws ON ws.id_warehouse = w.id_warehouse AND ws.id_shop = '.(int)$id_shop);
@@ -59,6 +59,8 @@ class AdminStockInstantStateControllerCore extends AdminController
'width' => 150,
'orderby' => false,
'search' => false,
'type' => 'price',
'currency' => true,
),
'physical_quantity' => array(
'title' => $this->l('Physical quantity'),
@@ -107,7 +109,8 @@ class AdminStockInstantStateControllerCore extends AdminController
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name,
IFNULL(s.physical_quantity, 0) as physical_quantity,
IFNULL(s.usable_quantity, 0) as usable_quantity,
s.price_te
s.price_te,
w.id_currency as id_currency
FROM '._DB_PREFIX_.'product_attribute a
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_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
@@ -115,6 +118,7 @@ class AdminStockInstantStateControllerCore extends AdminController
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.')
INNER JOIN '._DB_PREFIX_.'stock s ON (a.id_product_attribute = s.id_product_attribute)
LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = s.id_warehouse)
WHERE a.id_product = '.$id_product.
($warehouse != -1 ? ' AND s.id_warehouse = '.(int)$warehouse : ' ').'
GROUP BY a.id_product_attribute';
@@ -124,13 +128,19 @@ class AdminStockInstantStateControllerCore extends AdminController
// queries
$datas = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
foreach ($datas as &$data) // retrieves real quantity for each product
foreach ($datas as &$data)
{
// retrieves real quantity for each product
$data['real_quantity'] = $manager->getProductRealQuantities($data['id_product'],
$data['id'],
($warehouse == -1 ? null : array($warehouse)), // all or selected warehouse(s)
true);
// display price correctly
$data['price_te'] = Tools::displayPrice($data['price_te'], (int)$data['id_currency']);
}
echo Tools::jsonEncode(array('data'=> $datas, 'fields_display' => $this->fieldsDisplay));
}
die;
@@ -148,9 +158,13 @@ class AdminStockInstantStateControllerCore extends AdminController
COUNT(pa.id_product_attribute) as variations,
s.physical_quantity as physical_quantity,
s.usable_quantity as usable_quantity,
s.price_te as price_te';
s.price_te as price_te,
w.id_currency as id_currency';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)';
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)
LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = s.id_warehouse)';
if ($this->getCurrentCoverageWarehouse() != -1)
$this->_where .= ' AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse();
@@ -116,10 +116,10 @@ class AdminStockManagementControllerCore extends AdminController
switch ($this->display)
{
case 'addstock' :
$this->fields_form = array(
$this->fields_form[]['form'] = array(
'legend' => array(
'title' => $this->l('Add product to stock'),
'image' => '../img/admin/arrow_up.png'
'image' => '../img/admin/add_stock.png'
),
'input' => array(
array(
@@ -252,10 +252,10 @@ class AdminStockManagementControllerCore extends AdminController
break;
case 'removestock' :
$this->fields_form = array(
$this->fields_form[]['form'] = array(
'legend' => array(
'title' => $this->l('Remove product from stock'),
'image' => '../img/admin/arrow_down.png'
'image' => '../img/admin/remove_stock.png'
),
'input' => array(
array(
@@ -367,10 +367,10 @@ class AdminStockManagementControllerCore extends AdminController
break;
case 'transferstock' :
$this->fields_form = array(
$this->fields_form[]['form'] = array(
'legend' => array(
'title' => $this->l('Transfert product from warehouse to another'),
'image' => '../img/admin/arrow-right.png'
'image' => '../img/admin/transfer_stock.png'
),
'input' => array(
array(
+42 -3
View File
@@ -81,14 +81,32 @@ class AdminStockMvtControllerCore extends AdminController
'cast' => 'intval',
'type' => 'select',
'list' => $reasons_inc,
'identifier' => 'id_stock_mvt_reason'
'identifier' => 'id_stock_mvt_reason',
'visibility' => Shop::CONTEXT_ALL
),
'PS_STOCK_MVT_DEC_REASON_DEFAULT' => array(
'title' => $this->l('Default reason when decrementing stock:'),
'cast' => 'intval',
'type' => 'select',
'list' => $reasons_dec,
'identifier' => 'id_stock_mvt_reason'
'identifier' => 'id_stock_mvt_reason',
'visibility' => Shop::CONTEXT_ALL
),
'PS_STOCK_CUSTOMER_ORDER_REASON' => array(
'title' => $this->l('Default reason when decrementing stock when a customer order is shipped:'),
'cast' => 'intval',
'type' => 'select',
'list' => $reasons_dec,
'identifier' => 'id_stock_mvt_reason',
'visibility' => Shop::CONTEXT_ALL
),
'PS_STOCK_MVT_SUPPLIER_ORDER' => array(
'title' => $this->l('Default reason when incrementing stock when a supplier order is received:'),
'cast' => 'intval',
'type' => 'select',
'list' => $reasons_inc,
'identifier' => 'id_stock_mvt_reason',
'visibility' => Shop::CONTEXT_ALL
),
),
'submit' => array(),
@@ -175,7 +193,8 @@ class AdminStockMvtControllerCore extends AdminController
*/
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->addRowActionSkipList('delete', array(1, 2, 3, 4, 6, 7, 8));
$this->addRowActionSkipList('edit', array(1, 2, 3, 4, 5, 6, 7, 8));
$this->addRowActionSkipList('delete', array(1, 2, 3, 4, 5, 6, 7, 8));
$this->toolbar_title = $this->l('Stock : Stock movements reasons');
$first_list = parent::initList();
@@ -195,6 +214,7 @@ class AdminStockMvtControllerCore extends AdminController
unset($this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter);
// override table, land, className and identifier for the current controller
$this->deleted = false;
$this->table = 'stock_mvt';
$this->className = 'StockMvt';
$this->identifier = 'id_stock_mvt';
@@ -305,8 +325,14 @@ class AdminStockMvtControllerCore extends AdminController
// reset all query vars
unset($this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter);
// reset default table and className for options list management
$this->table = 'stock_mvt_reason';
$this->className = 'StockMvtReason';
// return the two lists
return $second_list.$first_list;
}
/**
@@ -327,4 +353,17 @@ class AdminStockMvtControllerCore extends AdminController
return $warehouse;
}
/**
* AdminController::postProcess() override
* @see AdminController::postProcess()
*/
public function postProcess()
{
//when deleting a movement reason, enable deleted flag for parent postProcess and no remove the corresponding row from the database
if (Tools::isSubmit('delete'.$this->table))
$this->deleted = true;
return parent::postProcess();
}
}
@@ -129,6 +129,15 @@ class AdminSupplierOrdersControllerCore extends AdminController
else
$this->_errors[] = Tools::displayError($this->l('You do not have permission to edit here.'));
}
if (Tools::isSubmit('update_receipt') && Tools::isSubmit('id_supplier_order'))
{
// change the display type in order to add specific actions to
$this->display = 'update_receipt';
// display correct toolBar
$this->initToolbar();
}
}
/**
@@ -142,11 +151,6 @@ class AdminSupplierOrdersControllerCore extends AdminController
Tools::isSubmit('submitAddsupplier_order_state') ||
Tools::isSubmit('submitUpdatesupplier_order_state'))
{
if (Tools::isSubmit('updatesupplier_order_state'))
$this->toolbar_title = $this->l('Stock : Update Supplier order state');
else
$this->toolbar_title = $this->l('Stock : Add Supplier order state');
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Supplier Order State'),
@@ -263,6 +267,48 @@ class AdminSupplierOrdersControllerCore extends AdminController
)
);
if (Tools::isSubmit('addsupplier_order_state'))
$this->toolbar_title = $this->l('Stock : Add Supplier order state');
else
{
$this->toolbar_title = $this->l('Stock : Update Supplier order state');
$id_supplier_order_state = Tools::getValue('id_supplier_order_state', 0);
// only some fields are editable for initial states
if (in_array($id_supplier_order_state, array(1, 2, 3, 4, 5, 6)))
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Supplier Order State'),
'image' => '../img/admin/edit.gif'
),
'input' => array(
array(
'type' => 'text',
'lang' => true,
'attributeLang' => 'name',
'label' => $this->l('Name:'),
'name' => 'name',
'size' => 50,
'required' => true
),
array(
'type' => 'color',
'label' => $this->l('Back office color:'),
'name' => 'color',
'size' => 20,
'p' => $this->l('Back office background will be displayed in this color. HTML colors only (e.g.,').' "lightblue", "#CC6600")'
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
}
}
return parent::initForm();
}
@@ -281,10 +327,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->addJqueryUI('ui.datepicker');
//get warehouses list
$warehouses = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT `id_warehouse`, CONCAT(`reference`, " - ", `name`) as name
FROM `'._DB_PREFIX_.'warehouse`
ORDER BY `reference` ASC');
$warehouses = Warehouse::getWarehouseList(true);
//get currencies list
$currencies = Currency::getCurrencies();
@@ -421,7 +464,6 @@ class AdminSupplierOrdersControllerCore extends AdminController
*/
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->addRowActionSkipList('edit', array(1, 2, 3, 4, 5, 6));
$this->addRowActionSkipList('delete', array(1, 2, 3, 4, 5, 6));
$this->toolbar_title = $this->l('Stock : Suppliers Orders States');
@@ -482,7 +524,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
),
'state' => array(
'title' => $this->l('State'),
'width' => 150,
'width' => 250,
'filter_key' => 'stl!name',
'color' => 'color',
),
@@ -523,7 +565,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->_select = '
CONCAT(e.lastname, \' \', e.firstname) AS employee,
s.name AS supplier,
CONCAT(w.reference, \' \', w.name) AS warehouse,
w.name AS warehouse,
stl.name AS state,
st.delivery_note,
st.editable,
@@ -588,10 +630,10 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->getlanguages();
// defines the fields of the form to display
$this->fields_form = array(
$this->fields_form[]['form'] = array(
'legend' => array(
'title' => $this->l('Supplier Order State'),
'image' => '../img/admin/edit.gif'
'image' => '../img/admin/cms.gif'
),
'input' => array(
array(
@@ -711,11 +753,6 @@ class AdminSupplierOrdersControllerCore extends AdminController
*/
public function initUpdateReceiptContent()
{
// change the display type in order to add specific actions to
$this->display = 'update_receipt';
// overrides parent::initContent();
$this->initToolbar();
$id_supplier_order = (int)Tools::getValue('id_supplier_order', null);
// if there is no order to fetch
@@ -797,13 +834,19 @@ class AdminSupplierOrdersControllerCore extends AdminController
)
);
// defines which table we are using
// attributes override
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
$this->table = 'supplier_order_detail';
$this->identifier = 'id_supplier_order_detail';
$this->className = 'SupplierOrderDetail';
// theme pruposes
$this->colorOnBackground = false;
$this->list_simple_header = true;
$this->list_no_link = true;
$this->bulk_actions = array('Update' => array('text' => $this->l('Update selected'), 'confirm' => $this->l('Update selected items?')));
$this->addRowAction('details');
// sets toolbar title with order reference
$this->toolbar_title = sprintf($this->l('Reception of products for supplier order #%s'), $supplier_order->reference);
// gets lang info
$this->lang = false;
$lang_id = (int)$this->context->language->id;
@@ -828,27 +871,18 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->_where = 'AND a.`id_supplier_order` = '.(int)$id_supplier_order;
$this->_group = 'GROUP BY a.id_supplier_order_detail';
$this->addRowAction('details');
// gets the list ordered by price desc, without limit
$this->getList($lang_id, 'quantity_expected', 'DESC', 0, false, false);
// defines action for POST
$action = '&id_supplier_order='.$id_supplier_order.'&submitUpdateReceipt';
// renders list
$helper = new HelperList();
$this->setHelperDisplay($helper);
$helper->override_folder = 'supplier_orders_receipt_history/';
$helper->simple_header = true;
$helper->actions = $this->actions;
$helper->table = $this->table;
$helper->no_link = true;
$helper->show_toolbar = false;
$helper->toolbar_fix = false;
$helper->shopLinkType = '';
//$helper->shopLinkType = '';
$helper->currentIndex = self::$currentIndex.$action;
$helper->token = $this->token;
$helper->identifier = $this->identifier;
$helper->bulk_actions = array('Update' => array('text' => $this->l('Update selected'), 'confirm' => $this->l('Update selected items?')));
// display these global order informations
$this->displayInformation($this->l('This interface allows you to update the quantities of this on-going order.').'<br />');
@@ -860,7 +894,6 @@ class AdminSupplierOrdersControllerCore extends AdminController
// assigns var
$this->context->smarty->assign(array(
'content' => $content,
'supplier_order_reference' => $supplier_order->reference
));
}
@@ -1193,7 +1226,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$warehouse,
(int)$quantity,
Configuration::get('PS_STOCK_MVT_SUPPLIER_ORDER'),
$supplier_order_detail->price_te,
$supplier_order_detail->unit_price_te,
true,
$supplier_order->id);
if ($res) // if product has been added
@@ -1410,6 +1443,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->className = 'SupplierOrderDetail';
$this->colorOnBackground = false;
$this->lang = false;
$this->list_simple_header = true;
$this->list_no_link = true;
$lang_id = (int)$this->context->language->id;
// gets the id supplier to view
@@ -1453,7 +1488,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$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);
$this->toolbar_title = sprintf($this->l('Details on supplier order #%s'), $supplier_order->reference);
// re-defines fieldsDisplay
$this->fieldsDisplay = array(
@@ -1486,8 +1521,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
'quantity_expected' => array(
'title' => $this->l('Quantity'),
@@ -1504,8 +1539,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
'discount_rate' => array(
'title' => $this->l('Discount rate'),
@@ -1523,8 +1558,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
'price_with_discount_te' => array(
'title' => $this->l('Price with product discount (te)'),
@@ -1533,8 +1568,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
'tax_rate' => array(
'title' => $this->l('Tax rate'),
@@ -1552,8 +1587,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
'price_ti' => array(
'title' => $this->l('Price (ti)'),
@@ -1562,35 +1597,22 @@ class AdminSupplierOrdersControllerCore extends AdminController
'orderby' => false,
'filter' => false,
'search' => false,
'prefix' => $currency->prefix,
'suffix' => $currency->suffix,
'type' => 'price',
'currency' => true,
),
);
//some staff before render list
foreach ($this->_list as &$item)
{
$item['unit_price_te'] = Tools::ps_round($item['unit_price_te'], 2);
$item['price_te'] = Tools::ps_round($item['price_te'], 2);
$item['tax_value'] = Tools::ps_round($item['tax_value'], 2);
$item['tax_value_with_order_discount'] = Tools::ps_round($item['tax_value_with_order_discount'], 2);
$item['price_ti'] = Tools::ps_round($item['price_ti'], 2);
$item['price_with_discount_te'] = Tools::ps_round($item['price_with_discount_te'], 2);
$item['price_with_order_discount_te'] = Tools::ps_round($item['price_with_order_discount_te'], 2);
$item['discount_value_te'] = Tools::ps_round($item['discount_value_te'], 2);
$item['discount_rate'] = Tools::ps_round($item['discount_rate'], 4);
$item['tax_rate'] = Tools::ps_round($item['tax_rate'], 4);
}
// renders list
$helper = new HelperList();
$helper->simple_header = true;
$helper->no_link = true;
$this->setHelperDisplay($helper);
$helper->show_toolbar = false;
$helper->toolbar_fix = false;
$helper->shopLinkType = '';
$helper->identifier = $this->identifier;
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
@@ -1604,11 +1626,11 @@ class AdminSupplierOrdersControllerCore extends AdminController
'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, 2),
'supplier_order_discount_value_te' => Tools::ps_round($supplier_order->discount_value_te, 2),
'supplier_order_total_with_discount_te' => Tools::ps_round($supplier_order->total_with_discount_te, 2),
'supplier_order_total_tax' => Tools::ps_round($supplier_order->total_tax, 2),
'supplier_order_total_ti' => Tools::ps_round($supplier_order->total_ti, 2),
'supplier_order_total_te' => Tools::displayPrice($supplier_order->total_te, $currency),
'supplier_order_discount_value_te' => Tools::displayPrice($supplier_order->discount_value_te, $currency),
'supplier_order_total_with_discount_te' => Tools::displayPrice($supplier_order->total_with_discount_te, $currency),
'supplier_order_total_tax' => Tools::displayPrice($supplier_order->total_tax, $currency),
'supplier_order_total_ti' => Tools::displayPrice($supplier_order->total_ti, $currency),
'supplier_order_currency' => $currency,
);
}
@@ -1658,6 +1680,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
'desc' => $this->l('Save')
);
case 'update_receipt':
// Default cancel button - like old back link
if (!isset($this->no_back) || $this->no_back == false)
{
+78 -49
View File
@@ -35,7 +35,9 @@ class AdminWarehousesControllerCore extends AdminController
$this->table = 'warehouse';
$this->className = 'Warehouse';
$this->context = Context::getContext();
$this->deleted = true;
$this->lang = false;
$this->fieldsDisplay = array(
'reference' => array(
'title' => $this->l('Reference'),
@@ -89,6 +91,7 @@ class AdminWarehousesControllerCore extends AdminController
// adds actions on rows
$this->addRowAction('edit');
$this->addRowAction('view');
$this->addRowAction('delete');
// query: select
$this->_select = '
@@ -123,6 +126,10 @@ class AdminWarehousesControllerCore extends AdminController
*/
public function initForm()
{
// loads current warehouse
if (!($obj = $this->loadObject(true)))
return;
// gets the manager of the warehouse
$query = new DbQuery();
$query->select('id_employee, CONCAT(lastname," ",firstname) as name');
@@ -137,7 +144,7 @@ class AdminWarehousesControllerCore extends AdminController
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Warehouse management'),
'image' => '../img/admin/tab.gif'
'image' => '../img/admin/edit.gif'
),
'input' => array(
array(
@@ -234,44 +241,6 @@ class AdminWarehousesControllerCore extends AdminController
'name' => 'name'
),
),
array(
'type' => 'select',
'label' => $this->l('Management type:'),
'name' => 'management_type',
'required' => true,
'options' => array(
'query' => array(
array(
'id' => 'WA',
'name' => $this->l('Weight Average')
),
array(
'id' => 'FIFO',
'name' => $this->l('First In, First Out')
),
array(
'id' => 'LIFO',
'name' => $this->l('Last In, First Out')
),
),
'id' => 'id',
'name' => 'name'
),
'p' => $this->l('Inventory valuation method'),
'hint' => $this->l('Do not change this value before the end of the accounting period for this warehouse.'),
),
array(
'type' => 'select',
'label' => $this->l('Stock valuation currency:'),
'name' => 'id_currency',
'required' => true,
'options' => array(
'query' => Currency::getCurrencies(),
'id' => 'id_currency',
'name' => 'name'
),
'hint' => $this->l('Do not change this value before the end of the accounting period for this warehouse.'),
),
array(
'type' => 'select',
'label' => $this->l('Associated shops:'),
@@ -295,22 +264,72 @@ class AdminWarehousesControllerCore extends AdminController
'multiple' => true,
'options' => array(
'query' => Carrier::getCarriers($this->context->language->id, true),
'id' => 'id_carrier',
'id' => 'id_reference',
'name' => 'name'
),
'p' => $this->l('Associated carriers'),
'hint' => $this->l('You can specifiy the carriers available to ship orders from this warehouse'),
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
// loads current warehouse
if (!($obj = $this->loadObject(true)))
return;
// It is not possible to change currency valuation and management type
if (Tools::isSubmit('addwarehouse'))
{
$this->fields_form['input'][] = array(
'type' => 'select',
'label' => $this->l('Management type:'),
'name' => 'management_type',
'required' => true,
'options' => array(
'query' => array(
array(
'id' => 'WA',
'name' => $this->l('Weight Average')
),
array(
'id' => 'FIFO',
'name' => $this->l('First In, First Out')
),
array(
'id' => 'LIFO',
'name' => $this->l('Last In, First Out')
),
),
'id' => 'id',
'name' => 'name'
),
'p' => $this->l('Inventory valuation method')
);
$this->fields_form['input'][] = array(
'type' => 'select',
'label' => $this->l('Stock valuation currency:'),
'name' => 'id_currency',
'required' => true,
'options' => array(
'query' => Currency::getCurrencies(),
'id' => 'id_currency',
'name' => 'name'
)
);
} else {
$this->fields_form['input'][] = array(
'type' => 'hidden',
'name' => 'management_type'
);
$this->fields_form['input'][] = array(
'type' => 'hidden',
'name' => 'id_currency'
);
}
$this->fields_form['submit'] = array(
'title' => $this->l(' Save '),
'class' => 'button'
);
// loads current address for this warehouse - if possible
$address = null;
@@ -405,9 +424,19 @@ class AdminWarehousesControllerCore extends AdminController
$_POST['id_address'] = $address->id;
}
}
}
return parent::postProcess();
// hack for enable the possibility to update a warehouse without recreate new id
$this->deleted = false;
return parent::postProcess();
}
else if (Tools::isSubmit('delete'.$this->table))
if (!($obj = $this->loadObject(true)))
return;
else if ($obj->getQuantitiesOfProducts() > 0)
$this->_errors[] = $this->l('It is not possible to delete a Warehosue when there are products in it.');
else
return parent::postProcess();
}
/**
+2
View File
@@ -1985,6 +1985,7 @@ CREATE TABLE `PREFIX_stock_mvt_reason` (
`sign` tinyint(1) NOT NULL DEFAULT 1,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
`deleted` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id_stock_mvt_reason`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
@@ -2017,6 +2018,7 @@ CREATE TABLE `PREFIX_warehouse` (
`reference` VARCHAR(32) DEFAULT NULL,
`name` VARCHAR(45) NOT NULL,
`management_type` ENUM('WA', 'FIFO', 'LIFO') NOT NULL DEFAULT 'WA',
`deleted` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id_warehouse`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
+35 -26
View File
@@ -330,10 +330,11 @@ INSERT INTO `PREFIX_configuration` (`id_configuration`, `name`, `value`, `date_a
(154, 'PS_STOCK_MVT_DEC_REASON_DEFAULT', '2', NOW(), NOW()),
(155, 'PS_ADVANCED_STOCK_MANAGEMENT', '1', NOW(), NOW()),
(156, 'PS_ADMINREFRESH_NOTIFICATION', '1', NOW(), NOW()),
(157, 'PS_STOCK_MVT_TRANSFER_TO', '6', NOW(), NOW()),
(158, 'PS_STOCK_MVT_TRANSFER_FROM', '7', NOW(), NOW()),
(157, 'PS_STOCK_MVT_TRANSFER_TO', '7', NOW(), NOW()),
(158, 'PS_STOCK_MVT_TRANSFER_FROM', '6', NOW(), NOW()),
(159, 'PS_CARRIER_DEFAULT_ORDER', '0', NOW(), NOW()),
(160, 'PS_STOCK_MVT_SUPPLIER_ORDER', '8', NOW(), NOW());
(160, 'PS_STOCK_MVT_SUPPLIER_ORDER', '8', NOW(), NOW()),
(161, 'PS_STOCK_CUSTOMER_ORDER_REASON', '3', NOW(), NOW());
INSERT INTO `PREFIX_configuration_lang` (`id_configuration`, `id_lang`, `value`, `date_upd`) VALUES
(36, 1, 'IN', NOW()),(36, 2, 'FA', NOW()),(36, 3, 'CU', NOW()),(36, 4, 'FA', NOW()),(36, 5, 'FA', NOW()),
@@ -1426,7 +1427,15 @@ INSERT INTO `PREFIX_group_group_shop` (`id_group`, `id_group_shop`) (SELECT `id_
INSERT INTO `PREFIX_category_group` (`id_category`, `id_group`) VALUES (1, 1);
INSERT INTO `PREFIX_stock_mvt_reason` (`id_stock_mvt_reason`, `sign`, `date_add`, `date_upd`) VALUES
(1, 1, NOW(), NOW()), (2, -1, NOW(), NOW()), (3, -1, NOW(), NOW()), (4, -1, NOW(), NOW()), (5, 1, NOW(), NOW()), (6, 1, NOW(), NOW()), (7, -1, NOW(), NOW()), (8, 1, NOW(), NOW());
(1, 1, NOW(), NOW()),
(2, -1, NOW(), NOW()),
(3, -1, NOW(), NOW()),
(4, -1, NOW(), NOW()),
(5, 1, NOW(), NOW()),
(6, -1, NOW(), NOW()),
(7, 1, NOW(), NOW()),
(8, 1, NOW(), NOW());
INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `name`) VALUES
(1, 1, 'Increase'),
(1, 2, 'Augmenter'),
@@ -1438,33 +1447,33 @@ INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `n
(2, 3, 'Disminuir'),
(2, 4, 'Reduzieren'),
(2, 5, 'Decrease'),
(3, 1, 'Client Order'),
(3, 1, 'Customer Order'),
(3, 2, 'Commande client'),
(3, 3, 'Pedido'),
(3, 4, 'Bestellung'),
(3, 5, 'Ordine'),
(4, 1, 'Missing Stock Movement'),
(4, 2, 'Mouvement de stock manquant'),
(4, 3, 'Movimiento de stock que falta'),
(4, 4, 'Lagerbewegung nicht stattgefunden'),
(4, 5, 'Movimento di merce mancante'),
(5, 1, 'Restocking'),
(5, 2, 'assort'),
(5, 3, 'Reaprovisionar'),
(5, 4, 'Auffüllung'),
(5, 5, 'Riassortimento'),
(6, 1, 'Transfer (to)'),
(6, 2, 'Transferer (vers)'),
(6, 3, 'Transfer (to)'),
(6, 4, 'Transfer (to)'),
(6, 5, 'Transfer (to)'),
(7, 1, 'Transfer (from)'),
(7, 2, 'Transferer (depuis)'),
(7, 3, 'Transfer (from)'),
(7, 4, 'Transfer (from)'),
(7, 5, 'Transfer (from)'),
(4, 1, 'Regulation following an inventory of stock'),
(4, 2, 'Régularisation du stock suite à un inventaire'),
(4, 3, 'Regulation following an inventory of stock'),
(4, 4, 'Regulation following an inventory of stock'),
(4, 5, 'Regulation following an inventory of stock'),
(5, 1, 'Regulation following an inventory of stock'),
(5, 2, 'gularisation du stock suite à un inventaire'),
(5, 3, 'Regulation following an inventory of stock'),
(5, 4, 'Regulation following an inventory of stock'),
(5, 5, 'Regulation following an inventory of stock'),
(6, 1, 'Transfer to another warehouse'),
(6, 2, 'Transfert vers un autre entrepôt'),
(6, 3, 'Transfer to another warehouse'),
(6, 4, 'Transfer to another warehouse'),
(6, 5, 'Transfer to another warehouse'),
(7, 1, 'Transfer from another warehouse'),
(7, 2, 'Transfert depuis un autre entrepôt'),
(7, 3, 'Transfer from another warehouse'),
(7, 4, 'Transfer from another warehouse'),
(7, 5, 'Transfer from another warehouse'),
(8, 1, 'Supplier Order'),
(8, 2, 'Commande fournisseur)'),
(8, 2, 'Commande fournisseur'),
(8, 3, 'Supplier Order'),
(8, 4, 'Supplier Order'),
(8, 5, 'Supplier Order');