From 1e0d7d92a956d36c4b6f67a8178bb5d60577a5e6 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Tue, 16 Nov 2021 14:09:18 +0100 Subject: [PATCH] NEW : addline with position choice when MAIN_VIEW_LINE_NUMBER is enabled --- htdocs/comm/propal/card.php | 3 ++- htdocs/comm/propal/class/propal.class.php | 5 +++++ htdocs/commande/card.php | 3 ++- htdocs/commande/class/commande.class.php | 5 +++++ htdocs/compta/facture/card.php | 3 ++- htdocs/compta/facture/class/facture.class.php | 5 +++++ htdocs/core/tpl/objectline_create.tpl.php | 12 ++++++++++++ .../fourn/class/fournisseur.commande.class.php | 16 +++++++++++++--- htdocs/fourn/class/fournisseur.facture.class.php | 5 +++++ htdocs/fourn/commande/card.php | 4 +++- htdocs/fourn/facture/card.php | 3 ++- htdocs/langs/en_US/main.lang | 2 ++ htdocs/supplier_proposal/card.php | 3 ++- .../class/supplier_proposal.class.php | 5 +++++ 14 files changed, 65 insertions(+), 9 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 483f7b543f5..559ceba1548 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -76,6 +76,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)); @@ -1127,7 +1128,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 7bdb531ec9b..8ba39410380 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -710,6 +710,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index b9900459006..a241222ae73 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -75,6 +75,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)); @@ -953,7 +954,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 3712a6eea1b..d9921ca1d14 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1658,6 +1658,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 86d3abedd2b..62dcfaa5ddc 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -87,6 +87,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)); @@ -2228,7 +2229,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, $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) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 8eb749b1d6b..81e3584b773 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3209,6 +3209,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 8da4d30af02..153f1b26775 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -296,6 +296,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')); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 08516fbc7d2..ff2e07b9600 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1597,9 +1597,10 @@ class CommandeFournisseur extends CommonOrder * @param string $pu_ht_devise Amount in currency * @param string $origin 'order', ... * @param int $origin_id Id of origin object + * @param int $rang Position of line * @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; @@ -1616,6 +1617,7 @@ class CommandeFournisseur extends CommonOrder if (!$qty) $qty = 1; if (!$info_bits) $info_bits = 0; if (empty($txtva)) $txtva = 0; + if (empty($rang)) $rang = 0; if (empty($txlocaltax1)) $txlocaltax1 = 0; if (empty($txlocaltax2)) $txlocaltax2 = 0; if (empty($remise_percent)) $remise_percent = 0; @@ -1776,8 +1778,11 @@ class CommandeFournisseur extends CommonOrder $localtax1_type = $localtaxes_type[0]; $localtax2_type = $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); @@ -1839,6 +1844,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 72d040583b2..34c9f8de335 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1857,6 +1857,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index f79f37d16e5..4dee5059223 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -66,6 +66,7 @@ $socid = GETPOST('socid', 'int'); $projectid = GETPOST('projectid', 'int'); $cancel = GETPOST('cancel', 'alpha'); $lineid = GETPOST('lineid', 'int'); +$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1; $lineid = GETPOST('lineid', 'int'); $origin = GETPOST('origin', 'alpha'); @@ -532,7 +533,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 985c9a4cc62..b60ee380cf4 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -70,6 +70,7 @@ $lineid = GETPOST('lineid', 'int'); $projectid = GETPOST('projectid', 'int'); $origin = GETPOST('origin', 'alpha'); $originid = GETPOST('originid', '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)); @@ -1379,7 +1380,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 67c78bf2915..3f21e47bc5f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1074,3 +1074,5 @@ AmountMustBePositive=Amount must be positive ByStatus=By status InformationMessage=Information Used=Used +AtTheEnd=At the end +OnLine=On line diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 708844b71c8..1fc8723951c 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -65,6 +65,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)); @@ -678,7 +679,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 d28a0ef3b72..91652248395 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -618,6 +618,11 @@ 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 $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.