Merge pull request #20365 from gdsoftdev/fix_invoicelineorders
Fix : keep row order into invoices created from massactions
This commit is contained in:
commit
7aeaaab7f0
@ -635,6 +635,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
|||||||
|
|
||||||
$TFact = array();
|
$TFact = array();
|
||||||
$TFactThird = array();
|
$TFactThird = array();
|
||||||
|
$TFactThirdNbLines = array();
|
||||||
|
|
||||||
$nb_bills_created = 0;
|
$nb_bills_created = 0;
|
||||||
$lastid= 0;
|
$lastid= 0;
|
||||||
@ -685,6 +686,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
|||||||
$lastid = $objecttmp->id;
|
$lastid = $objecttmp->id;
|
||||||
|
|
||||||
$TFactThird[$cmd->socid] = $objecttmp;
|
$TFactThird[$cmd->socid] = $objecttmp;
|
||||||
|
$TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang
|
||||||
} else {
|
} else {
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->error);
|
$errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->error);
|
||||||
@ -774,6 +776,11 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
|||||||
|
|
||||||
$objecttmp->context['createfromclone'];
|
$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(
|
$result = $objecttmp->addline(
|
||||||
$desc,
|
$desc,
|
||||||
$lines[$i]->subprice,
|
$lines[$i]->subprice,
|
||||||
@ -791,7 +798,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
|||||||
'HT',
|
'HT',
|
||||||
0,
|
0,
|
||||||
$product_type,
|
$product_type,
|
||||||
$lines[$i]->rang,
|
$rang,
|
||||||
$lines[$i]->special_code,
|
$lines[$i]->special_code,
|
||||||
$objecttmp->origin,
|
$objecttmp->origin,
|
||||||
$lines[$i]->rowid,
|
$lines[$i]->rowid,
|
||||||
@ -806,6 +813,8 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
|||||||
);
|
);
|
||||||
if ($result > 0) {
|
if ($result > 0) {
|
||||||
$lineid = $result;
|
$lineid = $result;
|
||||||
|
if (!empty($createbills_onebythird)) //increment rang to keep order
|
||||||
|
$TFactThirdNbLines[$rcp->socid]++;
|
||||||
} else {
|
} else {
|
||||||
$lineid = 0;
|
$lineid = 0;
|
||||||
$error++;
|
$error++;
|
||||||
|
|||||||
@ -719,7 +719,7 @@ if ($id > 0 || !empty($ref)) {
|
|||||||
$sql .= $hookmanager->resPrint;
|
$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 .= " 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);
|
$resql = $db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
|
|||||||
@ -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 = '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 .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet';
|
||||||
$sql_commfourndet .= ' WHERE rowid = '.((int) $line->fk_commandefourndet);
|
$sql_commfourndet .= ' WHERE rowid = '.((int) $line->fk_commandefourndet);
|
||||||
|
$sql_commfourndet .= ' ORDER BY rang';
|
||||||
$resql_commfourndet = $this->db->query($sql_commfourndet);
|
$resql_commfourndet = $this->db->query($sql_commfourndet);
|
||||||
if (!empty($resql_commfourndet)) {
|
if (!empty($resql_commfourndet)) {
|
||||||
$obj = $this->db->fetch_object($resql_commfourndet);
|
$obj = $this->db->fetch_object($resql_commfourndet);
|
||||||
|
|||||||
@ -175,6 +175,7 @@ if (empty($reshook)) {
|
|||||||
|
|
||||||
$TFact = array();
|
$TFact = array();
|
||||||
$TFactThird = array();
|
$TFactThird = array();
|
||||||
|
$TFactThirdNbLines = array();
|
||||||
|
|
||||||
$nb_bills_created = 0;
|
$nb_bills_created = 0;
|
||||||
$lastid= 0;
|
$lastid= 0;
|
||||||
@ -182,6 +183,8 @@ if (empty($reshook)) {
|
|||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
|
//sort ids to keep order if one bill per third
|
||||||
|
sort($receptions);
|
||||||
foreach ($receptions as $id_reception) {
|
foreach ($receptions as $id_reception) {
|
||||||
$rcp = new Reception($db);
|
$rcp = new Reception($db);
|
||||||
// We only invoice reception that are validated
|
// We only invoice reception that are validated
|
||||||
@ -254,6 +257,7 @@ if (empty($reshook)) {
|
|||||||
$lastid = $objecttmp->id;
|
$lastid = $objecttmp->id;
|
||||||
|
|
||||||
$TFactThird[$rcp->socid] = $objecttmp;
|
$TFactThird[$rcp->socid] = $objecttmp;
|
||||||
|
$TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang
|
||||||
} else {
|
} else {
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
|
$errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
|
||||||
@ -343,6 +347,11 @@ if (empty($reshook)) {
|
|||||||
|
|
||||||
$objecttmp->context['createfromclone'];
|
$objecttmp->context['createfromclone'];
|
||||||
|
|
||||||
|
$rang = $i;
|
||||||
|
//there may already be rows from previous receptions
|
||||||
|
if (!empty($createbills_onebythird))
|
||||||
|
$rang = $TFactThirdNbLines[$rcp->socid];
|
||||||
|
|
||||||
$result = $objecttmp->addline(
|
$result = $objecttmp->addline(
|
||||||
$desc,
|
$desc,
|
||||||
$lines[$i]->subprice,
|
$lines[$i]->subprice,
|
||||||
@ -358,7 +367,7 @@ if (empty($reshook)) {
|
|||||||
$lines[$i]->info_bits,
|
$lines[$i]->info_bits,
|
||||||
'HT',
|
'HT',
|
||||||
$product_type,
|
$product_type,
|
||||||
$i,
|
$rang,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
null,
|
null,
|
||||||
@ -371,6 +380,8 @@ if (empty($reshook)) {
|
|||||||
|
|
||||||
if ($result > 0) {
|
if ($result > 0) {
|
||||||
$lineid = $result;
|
$lineid = $result;
|
||||||
|
if (!empty($createbills_onebythird)) //increment rang to keep order
|
||||||
|
$TFactThirdNbLines[$rcp->socid]++;
|
||||||
} else {
|
} else {
|
||||||
$lineid = 0;
|
$lineid = 0;
|
||||||
$error++;
|
$error++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user