fix : keep lines order when creating invoices from receptions

This commit is contained in:
Jé GDSOFT 2022-03-15 14:59:26 +01:00
parent d71f117e81
commit 6080e1f988
3 changed files with 14 additions and 2 deletions

View File

@ -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) {

View File

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

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