26require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
38 $dispatched = array();
42 $sql =
'SELECT fk_product, SUM(qty) as qtydispatched FROM '.MAIN_DB_PREFIX.
'receptiondet_batch';
43 $sql .=
" WHERE fk_element = ".((int) $order_id).
" AND element_type = 'supplier_order'";
44 $sql .=
' GROUP BY fk_product';
45 $sql .=
' ORDER by fk_product';
46 $resql =
$db->query($sql);
47 if ($resql &&
$db->num_rows($resql)) {
48 while ($obj =
$db->fetch_object($resql)) {
49 $dispatched[$obj->fk_product] = $obj->qtydispatched;
54 $sql =
'SELECT fk_product, SUM(qty) as qtyordered FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
55 $sql .=
' WHERE fk_commande = '.((int) $order_id);
56 $sql .=
' AND fk_product > 0';
58 $sql .=
' AND product_type = 0';
60 $sql .=
' GROUP BY fk_product';
61 $sql .=
' ORDER by fk_product';
62 $resql =
$db->query($sql);
63 if ($resql &&
$db->num_rows($resql)) {
64 while ($obj =
$db->fetch_object($resql)) {
65 $ordered[$obj->fk_product] = $obj->qtyordered;
70 foreach ($ordered as $key => $val) {
71 if ((empty($ordered[$key]) ? 0 : $ordered[$key]) > (empty($dispatched[$key]) ? 0 : $dispatched[$key])) {
76 return ($todispatch ?
true :
false);
89 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'commande_fournisseur';
90 $resql =
$db->query($sql);
92 if ($resql &&
$db->num_rows($resql) > 0) {
93 while ($obj =
$db->fetch_object($resql)) {
95 $resarray[] = $obj->rowid;
100 if (count($resarray)) {
101 $res =
'('.implode(
',', $resarray).
')';
119 $sql =
'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) as qty FROM';
120 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cfd ';
121 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commande_fournisseur as cf';
122 $sql .=
' ON cfd.fk_commande = cf.rowid WHERE';
124 $sql .=
' cf.fk_statut < 3';
125 } elseif (
getDolGlobalInt(
"STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER")) {
126 $sql .=
' cf.fk_statut < 6 AND cf.rowid NOT IN '.dispatchedOrders();
128 $sql .=
' cf.fk_statut < 5';
130 $sql .=
' AND cfd.fk_product = '.((int) $product_id);
131 $sql .=
' GROUP BY cfd.fk_product';
133 $resql =
$db->query($sql);
135 $exists =
$db->num_rows($resql);
136 if ($exists && $obj =
$db->fetch_array($resql)) {
144 return 'Error '.$db->lasterror();
159 $f = $order->fetch($order_id);
162 foreach ($order->lines as $line) {
163 if (!in_array($line->fk_product, $products)) {
164 $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