diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 79d70727331..4f738f68a97 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -642,7 +642,9 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. $lastref = ''; $db->begin(); - + + $nbOrders = is_array($orders) ? count($orders) : 1; + foreach ($orders as $id_order) { $cmd = new Commande($db); if ($cmd->fetch($id_order) <= 0) { @@ -774,7 +776,7 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. } $objecttmp->context['createfromclone']; - + $rankedLine = ($nbOrders > 1) ? -1 : $lines[$i]->rang; $result = $objecttmp->addline( $desc, $lines[$i]->subprice, @@ -792,7 +794,9 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. 'HT', 0, $product_type, - $lines[$i]->rang, + //we have define the max rank for each line which makes it possible not to have a duplicate on the rank field in the case of several orders + //-1 will give us the right number + $rankedLine, // rank $lines[$i]->special_code, $objecttmp->origin, $lines[$i]->rowid,