diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index e6ae2f2ab87..d4c258599c5 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -1145,7 +1145,7 @@ if (empty($reshook)) {
setEventMessages($mesg, null, 'errors');
} else {
// Insert line
- $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rank, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
+ $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
if ($result > 0) {
$db->commit();
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index cfa21ce1534..1f587530175 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -937,7 +937,7 @@ if (empty($reshook)) {
setEventMessages($mesg, null, 'errors');
} else {
// Insert line
- $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, $rank, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise);
+ $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise);
if ($result > 0) {
$ret = $object->fetch($object->id); // Reload to get new records
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index c4cb861b2b6..910c16d446a 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -2262,7 +2262,7 @@ if (empty($reshook)) {
}
// Insert line
- $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, $rank, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress'], '', $fk_unit, $pu_ht_devise);
+ $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, min($rank, count($object->lines) + 1), $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress'], '', $fk_unit, $pu_ht_devise);
if ($result > 0) {
// Define output language and generate document
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index c224f33edf0..dba5e5be695 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -311,15 +311,8 @@ if ($nolinesbefore) {
echo '';
}
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- $tab = array(-1 => $langs->trans('AtTheEnd'));
- if (!empty($object->lines)) {
- $langs->load('admin');
- foreach ($object->lines as $k => $v) {
- $tab[$v->rang] = $langs->trans('OnLine') . ' ' . ($k + 1);
- }
- }
- echo '
'.$langs->trans('Position').' : '.$form->selectarray('rank', $tab);
+ if(!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
+ echo '
'.$langs->trans('AddLineOnPosition').' : ';
}
if (is_object($hookmanager) && empty($senderissupplier)) {
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 70b2908eb45..ffda0465a78 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -586,7 +586,7 @@ if (empty($reshook)) {
$pu_ht_devise,
'',
0,
- $rank
+ min($rank, count($object->lines) + 1)
);
}
if ($idprod == -99 || $idprod == 0) {
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index aeb0681547f..cb3b1bcd5e9 100755
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -1510,7 +1510,7 @@ if (empty($reshook)) {
$tva_npr,
$price_base_type,
$type,
- $rank,
+ min($rank, count($object->lines) + 1),
0,
$array_options,
$productsupplier->fk_unit,
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index cf82fe1fa6a..a81aa0a836a 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -1159,5 +1159,4 @@ hasBeenValidated=%s has been validated
ClientTZ=Client Time Zone (user)
NotClosedYet=Not yet closed
ClearSignature=Signature reset
-AtTheEnd=At the end
-OnLine=On line
+AddLineOnPosition=Add line on position (at the end if empty)
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index ac6344d91da..12f31a03bf6 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -674,7 +674,7 @@ if (empty($reshook)) {
$pu_ttc,
$tva_npr,
$type,
- $rank,
+ min($rank, count($object->lines) + 1),
0,
GETPOST('fk_parent_line'),
$fournprice,