diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index 896448d7b9a..98ea79b078f 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -80,6 +80,7 @@ $confirm = GETPOST('confirm', 'alpha');
$lineid = GETPOST('lineid', 'int');
$contactid = GETPOST('contactid', 'int');
$projectid = GETPOST('projectid', 'int');
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
// PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -1143,7 +1144,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, - 1, 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, $rank, 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/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 2f055f54a42..a532a874d65 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -734,6 +734,10 @@ class Propal extends CommonObject
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $ranktouse; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la propale meme
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index db29da62565..9e682805d20 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -81,6 +81,7 @@ $contactid = GETPOST('contactid', 'int');
$projectid = GETPOST('projectid', 'int');
$origin = GETPOST('origin', 'alpha');
$originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
// PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -935,7 +936,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, - 1, 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, $rank, 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/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 9b315698527..67cb1a1790f 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1648,6 +1648,10 @@ class Commande extends CommonOrder
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $ranktouse; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la commande meme
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index ab1ab9f5dd7..abed475fbb5 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -92,6 +92,7 @@ $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
$origin = GETPOST('origin', 'alpha');
$originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
$fac_rec = GETPOST('fac_rec', 'int');
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
// PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -2260,7 +2261,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, - 1, $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, $rank, $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/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 649b7b0c093..4ce494c34a7 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -3355,6 +3355,10 @@ class Facture extends CommonInvoice
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $ranktouse; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la facture meme
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index aeac5d038f3..f1a15e0d537 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -309,6 +309,18 @@ if ($nolinesbefore) {
echo '';
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 (is_object($hookmanager) && empty($senderissupplier)) {
$parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
$reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 9e16c803b28..790f67623d8 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -1683,7 +1683,7 @@ class CommandeFournisseur extends CommonOrder
* @param int $origin_id Id of origin object
* @return int <=0 if KO, >0 if OK
*/
- public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $fk_prod_fourn_price = 0, $ref_supplier = '', $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $type = 0, $info_bits = 0, $notrigger = false, $date_start = null, $date_end = null, $array_options = 0, $fk_unit = null, $pu_ht_devise = 0, $origin = '', $origin_id = 0)
+ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $fk_prod_fourn_price = 0, $ref_supplier = '', $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $type = 0, $info_bits = 0, $notrigger = false, $date_start = null, $date_end = null, $array_options = 0, $fk_unit = null, $pu_ht_devise = 0, $origin = '', $origin_id = 0, $rang = -1)
{
global $langs, $mysoc, $conf;
@@ -1703,6 +1703,9 @@ class CommandeFournisseur extends CommonOrder
if (empty($txtva)) {
$txtva = 0;
}
+ if (empty($rang)) {
+ $rang = 0;
+ }
if (empty($txlocaltax1)) {
$txlocaltax1 = 0;
}
@@ -1854,8 +1857,11 @@ class CommandeFournisseur extends CommonOrder
$localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0];
$localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2];
- $rangmax = $this->line_max();
- $rang = $rangmax + 1;
+ if ($rang < 0)
+ {
+ $rangmax = $this->line_max();
+ $rang = $rangmax + 1;
+ }
// Insert line
$this->line = new CommandeFournisseurLigne($this->db);
@@ -1917,6 +1923,10 @@ class CommandeFournisseur extends CommonOrder
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($rang > 0 && $rang <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $rang; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la commande meme
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 6419d233d43..2aa778b3b66 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -2007,6 +2007,10 @@ class FactureFournisseur extends CommonInvoice
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($rang > 0 && $rang <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $rang; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la facture meme
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 8f6ed82160e..c341a529123 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -77,6 +77,7 @@ $cancel = GETPOST('cancel', 'alpha');
$lineid = GETPOST('lineid', 'int');
$origin = GETPOST('origin', 'alpha');
$originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
//PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -583,7 +584,8 @@ if (empty($reshook)) {
$productsupplier->fk_unit,
$pu_ht_devise,
'',
- 0
+ 0,
+ $rank
);
}
if ($idprod == -99 || $idprod == 0) {
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 7ad7d434f46..57356bbc1e9 100755
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -76,6 +76,7 @@ $projectid = GETPOST('projectid', 'int');
$origin = GETPOST('origin', 'alpha');
$originid = GETPOST('originid', 'int');
$fac_rec = GETPOST('fac_rec', 'int');
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
// PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -1508,7 +1509,7 @@ if (empty($reshook)) {
$tva_npr,
$price_base_type,
$type,
- -1,
+ $rank,
0,
$array_options,
$productsupplier->fk_unit,
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index a0b9fda9f64..cf82fe1fa6a 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -1158,4 +1158,6 @@ Properties=Properties
hasBeenValidated=%s has been validated
ClientTZ=Client Time Zone (user)
NotClosedYet=Not yet closed
-ClearSignature=Signature reset
\ No newline at end of file
+ClearSignature=Signature reset
+AtTheEnd=At the end
+OnLine=On line
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index a5837c2557f..eaed94f6529 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -67,6 +67,7 @@ $confirm = GETPOST('confirm', 'alpha');
$projectid = GETPOST('projectid', 'int');
$lineid = GETPOST('lineid', 'int');
$contactid = GETPOST('contactid', 'int');
+$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
// PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -672,7 +673,7 @@ if (empty($reshook)) {
$pu_ttc,
$tva_npr,
$type,
- -1,
+ $rank,
0,
GETPOST('fk_parent_line'),
$fournprice,
diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php
index 9c84e2c2e89..f90555f9f1e 100644
--- a/htdocs/supplier_proposal/class/supplier_proposal.class.php
+++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php
@@ -621,6 +621,10 @@ class SupplierProposal extends CommonObject
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
+ } elseif($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
+ for ($ii = $ranktouse; $ii <= count($this->lines); $ii++) {
+ $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
+ }
}
// Mise a jour informations denormalisees au niveau de la propale meme