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 1/7] 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
/**
From 73bd05606c554802d3371cfb7235e365e8f0fff2 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Sun, 10 Oct 2021 18:53:22 +0000
Subject: [PATCH 2/7] Fixing style errors.
---
htdocs/fourn/class/fournisseur.commande.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 5277f5b1d34..a9d3cbdcac5 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -2289,7 +2289,7 @@ class CommandeFournisseur extends CommonOrder
$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) {
@@ -2301,7 +2301,7 @@ class CommandeFournisseur extends CommonOrder
if ($objp) {
// If product not completly dispatched
- if (is_null($objp->qty_dispatched) OR ($objp->qty_dispatched < $objp->qty_ordered)){
+ 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,
From a7563ff62e1fbef41f99bbb679674f0ef2cce67c Mon Sep 17 00:00:00 2001
From: Benjamin Chantalat <74144396+PyroShape@users.noreply.github.com>
Date: Sun, 10 Oct 2021 21:15:14 +0200
Subject: [PATCH 3/7] Fix : Found non quoted or not casted var into sql request
---
htdocs/fourn/class/fournisseur.commande.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index a9d3cbdcac5..787d9ee321b 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -2287,7 +2287,7 @@ class CommandeFournisseur extends CommonOrder
$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 .= " WHERE supplierOrderDet.fk_commande = ".((int) $this->id);
$sql .= " GROUP BY supplierOrderDet.fk_product";
$resql = $this->db->query($sql);
From 5be40b926b6198e638dba1e796c2114417cd75c9 Mon Sep 17 00:00:00 2001
From: Benjamin Chantalat <74144396+PyroShape@users.noreply.github.com>
Date: Mon, 1 Nov 2021 19:56:24 +0100
Subject: [PATCH 4/7] Clean function not use anymore
---
.../class/fournisseur.commande.class.php | 44 -------------------
1 file changed, 44 deletions(-)
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 787d9ee321b..9cf3c74e967 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -2274,50 +2274,6 @@ 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 = ".((int) $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
/**
* Set a delivery in database for this supplier order
From 7b88f1da3fea112919f0c61bf9cb894323cbfbab Mon Sep 17 00:00:00 2001
From: Benjamin Chantalat <74144396+PyroShape@users.noreply.github.com>
Date: Mon, 1 Nov 2021 19:56:55 +0100
Subject: [PATCH 5/7] Change to have number of item dispached on number of
total item
---
htdocs/core/lib/fourn.lib.php | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php
index e81bdb5e9d0..7fc903db72b 100644
--- a/htdocs/core/lib/fourn.lib.php
+++ b/htdocs/core/lib/fourn.lib.php
@@ -157,12 +157,24 @@ 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.'';
+
+ //If dispach process running we add the number of item to dispatch into the head
+ if ($object->statut == '3' OR $object->statut == '4' OR $object->statut == '5') {
+ $lines = $object->fetch_lines();
+ $dispachedLines = $object->getDispachedLines(1);
+ $sumQtyAllreadyDispatched = 0;
+ for ($line = 0 ; $line < count($dispachedLines) ; $line++) {
+ $sumQtyAllreadyDispatched = $sumQtyAllreadyDispatched + $dispachedLines[$line]['qty'];
+ }
+ $sumQtyOrdered = 0;
+ for ($line = 0 ; $line < count($object->lines) ; $line++) {
+ $sumQtyOrdered = $sumQtyOrdered + $object->lines[$line]->qty;
+ }
+ $head[$h][1] .= ''.$sumQtyAllreadyDispatched.' / '.$sumQtyOrdered.'';
}
+
$head[$h][2] = 'dispatch';
$h++;
}
From 85372a70836d2d9cdb003cc490bd8fa17c73fc46 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Mon, 1 Nov 2021 18:57:35 +0000
Subject: [PATCH 6/7] Fixing style errors.
---
htdocs/core/lib/fourn.lib.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php
index 7fc903db72b..27ebc98635d 100644
--- a/htdocs/core/lib/fourn.lib.php
+++ b/htdocs/core/lib/fourn.lib.php
@@ -159,22 +159,22 @@ function ordersupplier_prepare_head($object)
$langs->load("stocks");
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
$head[$h][1] = $langs->trans("OrderDispatch");
-
+
//If dispach process running we add the number of item to dispatch into the head
if ($object->statut == '3' OR $object->statut == '4' OR $object->statut == '5') {
$lines = $object->fetch_lines();
$dispachedLines = $object->getDispachedLines(1);
$sumQtyAllreadyDispatched = 0;
- for ($line = 0 ; $line < count($dispachedLines) ; $line++) {
+ for ($line = 0 ; $line < count($dispachedLines); $line++) {
$sumQtyAllreadyDispatched = $sumQtyAllreadyDispatched + $dispachedLines[$line]['qty'];
}
$sumQtyOrdered = 0;
- for ($line = 0 ; $line < count($object->lines) ; $line++) {
+ for ($line = 0 ; $line < count($object->lines); $line++) {
$sumQtyOrdered = $sumQtyOrdered + $object->lines[$line]->qty;
- }
+ }
$head[$h][1] .= ''.$sumQtyAllreadyDispatched.' / '.$sumQtyOrdered.'';
}
-
+
$head[$h][2] = 'dispatch';
$h++;
}
From 85776f7529dbc3d969e827a82d6fcf1c1b168159 Mon Sep 17 00:00:00 2001
From: Benjamin Chantalat <74144396+PyroShape@users.noreply.github.com>
Date: Mon, 1 Nov 2021 20:08:00 +0100
Subject: [PATCH 7/7] Avoid function calls in a FOR loop test part
---
htdocs/core/lib/fourn.lib.php | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php
index 27ebc98635d..25bbd52e413 100644
--- a/htdocs/core/lib/fourn.lib.php
+++ b/htdocs/core/lib/fourn.lib.php
@@ -162,14 +162,17 @@ function ordersupplier_prepare_head($object)
//If dispach process running we add the number of item to dispatch into the head
if ($object->statut == '3' OR $object->statut == '4' OR $object->statut == '5') {
- $lines = $object->fetch_lines();
+ $object->fetch_lines();
+ $nbLinesOrdered = count($object->lines);
$dispachedLines = $object->getDispachedLines(1);
+ $nbDispachedLines = count($dispachedLines);
+
$sumQtyAllreadyDispatched = 0;
- for ($line = 0 ; $line < count($dispachedLines); $line++) {
+ for ($line = 0 ; $line < $nbDispachedLines; $line++) {
$sumQtyAllreadyDispatched = $sumQtyAllreadyDispatched + $dispachedLines[$line]['qty'];
}
$sumQtyOrdered = 0;
- for ($line = 0 ; $line < count($object->lines); $line++) {
+ for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
$sumQtyOrdered = $sumQtyOrdered + $object->lines[$line]->qty;
}
$head[$h][1] .= ''.$sumQtyAllreadyDispatched.' / '.$sumQtyOrdered.'';