Merge pull request #20365 from gdsoftdev/fix_invoicelineorders

Fix : keep row order into invoices created from massactions
This commit is contained in:
Laurent Destailleur 2022-03-17 13:37:17 +01:00 committed by GitHub
commit 7aeaaab7f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -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++;

View File

@ -719,7 +719,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) {

View File

@ -1164,6 +1164,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);

View File

@ -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++;