From 65c0167d077605451f37351d94ef76cd8113fc69 Mon Sep 17 00:00:00 2001 From: Benjamin Chantalat <74144396+PyroShape@users.noreply.github.com> Date: Sun, 10 Oct 2021 20:50:51 +0200 Subject: [PATCH] ADD : info of number of product still to dispatched in a supplier order --- htdocs/core/lib/fourn.lib.php | 4 ++ .../class/fournisseur.commande.class.php | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php index efc9f60147c..e81bdb5e9d0 100644 --- a/htdocs/core/lib/fourn.lib.php +++ b/htdocs/core/lib/fourn.lib.php @@ -157,8 +157,12 @@ function ordersupplier_prepare_head($object) if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { $langs->load("stocks"); + $nbLineToDispatch = count($object->getNotCompletlyDispatchedLines()); $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id; $head[$h][1] = $langs->trans("OrderDispatch"); + if ($nbLineToDispatch > 0) { + $head[$h][1] .= ''.$nbLineToDispatch.''; + } $head[$h][2] = 'dispatch'; $h++; } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 99ef4e54e87..5277f5b1d34 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2274,6 +2274,49 @@ class CommandeFournisseur extends CommonOrder return $ret; } + /** + * Return array of the lines that are waiting to be dispatched + * + * @return array Array of lines + */ + public function getNotCompletlyDispatchedLines() + { + $ret = array(); + + $sql = "SELECT supplierOrderDet.fk_product as product_id, supplierOrderDet.qty as qty_ordered, supplierOrderDet.fk_commande,"; + $sql .= " dispatch.rowid as dispatchedlineid, sum(dispatch.qty) as qty_dispatched"; + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as supplierOrderDet"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as dispatch ON supplierOrderDet.rowid = dispatch.fk_commandefourndet"; + $sql .= " WHERE supplierOrderDet.fk_commande = ".$this->id; + $sql .= " GROUP BY supplierOrderDet.fk_product"; + + $resql = $this->db->query($sql); + + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) { + $objp = $this->db->fetch_object($resql); + + if ($objp) { + // If product not completly dispatched + if (is_null($objp->qty_dispatched) OR ($objp->qty_dispatched < $objp->qty_ordered)){ + $ret[] = array( + 'product_id' => $objp->product_id, + 'qty_ordered' => $objp->qty_ordered, + 'qty_dispatched' => $objp->qty_dispatched, + ); + } + } + $i++; + } + } else { + dol_print_error($this->db, 'Failed to execute request to get not completly dispatched lines'); + } + + return $ret; + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /**