diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5a4ec3bf02f..d32418d7550 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++; diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 08b4b2c6bf0..60cdae1d0e7 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -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) { diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 6435acb2877..9d20d07005d 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -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); diff --git a/htdocs/reception/list.php b/htdocs/reception/list.php index b83afc3f37d..8575c84c026 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++;