// StockManager: updated getProductRealQuantities() because of supplier orders

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9970 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-11-08 16:00:37 +00:00
parent 57d6ba89f0
commit 7f117d226f
+14 -5
View File
@@ -420,7 +420,7 @@ class StockManagerCore implements StockManagerInterface
*/
public function getProductRealQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false)
{
// Gets clients_orders_qty
// Gets client_orders_qty
$query = new DbQuery();
$query->select('SUM(od.product_quantity)');
$query->from('order_detail od');
@@ -428,14 +428,23 @@ class StockManagerCore implements StockManagerInterface
$query->where('od.product_id = '.(int)$id_product.' AND od.product_attribute_id = '.(int)$id_product_attribute);
$query->where('o.delivery_number = 0');
$query->where('o.valid = 1');
$clients_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
$client_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
// Gets supplier_orders_qty
$query = new DbQuery();
$query->select('SUM(sod.quantity_expected)');
$query->from('supplier_order so');
$query->leftjoin('supplier_order_detail sod ON (sod.id_supplier_order = so.id_supplier_order)');
$query->leftjoin('supplier_order_state sos ON (sos.id_supplier_order_state = so.id_supplier_order_state)');
$query->where('sos.pending_receipt = 1');
$query->where('sod.id_product = '.(int)$id_product.' AND sod.id_product_attribute = '.(int)$id_product_attribute);
$supplier_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
// Gets {physical OR usable}_qty
$qty = $this->getProductPhysicalQuantities($id_product, $id_product_attribute, $ids_warehouse, $usable);
// Returns real_qty = qty - clients_orders_qty
// @TODO include suplliers orders in the calcul when they will be implemented
return ($qty - $clients_orders_qty);
// real qty = actual qty in stock - current client orders + current supplier orders
return ($qty - $client_orders_qty + $supplier_orders_qty);
}
/**