From 6080e1f988d7860571d4af9f5d1199506a4118fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9=20GDSOFT?= Date: Tue, 15 Mar 2022 14:59:26 +0100 Subject: [PATCH 1/2] fix : keep lines order when creating invoices from receptions --- htdocs/fourn/commande/dispatch.php | 2 +- htdocs/reception/class/reception.class.php | 1 + htdocs/reception/list.php | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 9a8ab1fa7ef..fda6d1aba4a 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -709,7 +709,7 @@ if ($id > 0 || !empty($ref)) { $sql .= $hookmanager->resPrint; $sql .= " GROUP BY p.ref, p.label, p.tobatch, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product - $sql .= " ORDER BY p.ref, p.label"; + $sql .= " ORDER BY l.rang, p.ref, p.label"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 5fb8e3b8af0..62a9c8a8dde 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -1055,6 +1055,7 @@ class Reception extends CommonObject $sql_commfourndet = 'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent'; $sql_commfourndet .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet'; $sql_commfourndet .= ' WHERE rowid = '.((int) $line->fk_commandefourndet); + $sql_commfourndet .= ' ORDER BY rang'; $resql_commfourndet = $this->db->query($sql_commfourndet); if (!empty($resql_commfourndet)) { $obj = $this->db->fetch_object($resql_commfourndet); diff --git a/htdocs/reception/list.php b/htdocs/reception/list.php index 9f98202099a..cf12c6f8191 100644 --- a/htdocs/reception/list.php +++ b/htdocs/reception/list.php @@ -175,6 +175,7 @@ if (empty($reshook)) { $TFact = array(); $TFactThird = array(); + $TFactThirdNbLines = array(); $nb_bills_created = 0; $lastid= 0; @@ -182,6 +183,8 @@ if (empty($reshook)) { $db->begin(); + //sort ids to keep order if one bill per third + sort($receptions); foreach ($receptions as $id_reception) { $rcp = new Reception($db); // We only invoice reception that are validated @@ -254,6 +257,7 @@ if (empty($reshook)) { $lastid = $objecttmp->id; $TFactThird[$rcp->socid] = $objecttmp; + $TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang } else { $langs->load("errors"); $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error); @@ -343,6 +347,11 @@ if (empty($reshook)) { $objecttmp->context['createfromclone']; + $rang = $i; + //there may already be rows from previous receptions + if (!empty($createbills_onebythird)) + $rang = $TFactThirdNbLines[$rcp->socid]; + $result = $objecttmp->addline( $desc, $lines[$i]->subprice, @@ -358,7 +367,7 @@ if (empty($reshook)) { $lines[$i]->info_bits, 'HT', $product_type, - $i, + $rang, false, 0, null, @@ -371,6 +380,8 @@ if (empty($reshook)) { if ($result > 0) { $lineid = $result; + if (!empty($createbills_onebythird)) //increment rang to keep order + $TFactThirdNbLines[$rcp->socid]++; } else { $lineid = 0; $error++; From ffa6cb06106562aa1325296790f9df9a706ccd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9=20GDSOFT?= Date: Tue, 15 Mar 2022 15:47:36 +0100 Subject: [PATCH 2/2] fix : keep lines order when creating invoices from orders --- htdocs/core/actions_massactions.inc.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 64578ad68bb..b70e17b2ebb 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -635,6 +635,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. $TFact = array(); $TFactThird = array(); + $TFactThirdNbLines = array(); $nb_bills_created = 0; $lastid= 0; @@ -685,6 +686,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. $lastid = $objecttmp->id; $TFactThird[$cmd->socid] = $objecttmp; + $TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang } else { $langs->load("errors"); $errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->error); @@ -774,6 +776,11 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. $objecttmp->context['createfromclone']; + $rang = $lines[$i]->rang; + //there may already be rows from previous orders + if (!empty($createbills_onebythird)) + $rang = $TFactThirdNbLines[$cmd->socid]; + $result = $objecttmp->addline( $desc, $lines[$i]->subprice, @@ -791,7 +798,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. 'HT', 0, $product_type, - $lines[$i]->rang, + $rang, $lines[$i]->special_code, $objecttmp->origin, $lines[$i]->rowid, @@ -806,6 +813,8 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. ); if ($result > 0) { $lineid = $result; + if (!empty($createbills_onebythird)) //increment rang to keep order + $TFactThirdNbLines[$rcp->socid]++; } else { $lineid = 0; $error++;