25require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
37 $dispatched = array();
41 $sql =
'SELECT fk_product, SUM(qty) as qtydispatched FROM '.MAIN_DB_PREFIX.
'receptiondet_batch';
42 $sql .=
" WHERE fk_element = ".((int) $order_id).
" AND element_type = 'supplier_order'";
43 $sql .=
' GROUP BY fk_product';
44 $sql .=
' ORDER by fk_product';
45 $resql = $db->query($sql);
46 if ($resql && $db->num_rows($resql)) {
47 while ($obj = $db->fetch_object($resql)) {
48 $dispatched[$obj->fk_product] = $obj->qtydispatched;
53 $sql =
'SELECT fk_product, SUM(qty) as qtyordered FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
54 $sql .=
' WHERE fk_commande = '.((int) $order_id);
55 $sql .=
' AND fk_product > 0';
57 $sql .=
' AND product_type = 0';
59 $sql .=
' GROUP BY fk_product';
60 $sql .=
' ORDER by fk_product';
61 $resql = $db->query($sql);
62 if ($resql && $db->num_rows($resql)) {
63 while ($obj = $db->fetch_object($resql)) {
64 $ordered[$obj->fk_product] = $obj->qtyordered;
69 foreach ($ordered as $key => $val) {
70 if ((empty($ordered[$key]) ? 0 : $ordered[$key]) > (empty($dispatched[$key]) ? 0 : $dispatched[$key])) {
75 return ($todispatch ?
true :
false);
88 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'commande_fournisseur';
89 $resql = $db->query($sql);
91 if ($resql && $db->num_rows($resql) > 0) {
92 while ($obj = $db->fetch_object($resql)) {
94 $resarray[] = $obj->rowid;
99 if (count($resarray)) {
100 $res =
'('.implode(
',', $resarray).
')';
118 $sql =
'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) as qty FROM';
119 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cfd ';
120 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commande_fournisseur as cf';
121 $sql .=
' ON cfd.fk_commande = cf.rowid WHERE';
123 $sql .=
' cf.fk_statut < 3';
124 } elseif (
getDolGlobalInt(
"STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER")) {
125 $sql .=
' cf.fk_statut < 6 AND cf.rowid NOT IN '.dispatchedOrders();
127 $sql .=
' cf.fk_statut < 5';
129 $sql .=
' AND cfd.fk_product = '.((int) $product_id);
130 $sql .=
' GROUP BY cfd.fk_product';
132 $resql = $db->query($sql);
134 $exists = $db->num_rows($resql);
135 if ($exists && $obj = $db->fetch_array($resql)) {
143 return 'Error '.$db->lasterror();
158 $f = $order->fetch($order_id);
161 foreach ($order->lines as $line) {
162 if (!in_array($line->fk_product, $products)) {
163 $products[] = $line->fk_product;
Class to manage predefined suppliers products.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
ordered($product_id)
ordered
dolDispatchToDo($order_id)
Check if there is still some dispatching of stock to do.
getProducts($order_id)
getProducts
dispatchedOrders()
dispatchedOrders