NEW : addline with position choice when MAIN_VIEW_LINE_NUMBER is enabled

This commit is contained in:
Gauthier PC portable 024 2021-11-16 14:09:18 +01:00
parent e188855dca
commit 1e0d7d92a9
14 changed files with 65 additions and 9 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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)
{

View File

@ -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.

View File

@ -296,6 +296,18 @@ if ($nolinesbefore) {
echo '<input type="hidden" name="pbq" id="pbq" value="">';
echo '</span>';
}
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') . '&nbsp;' . ($k + 1);
}
}
echo '<br>'.$langs->trans('Position').' : '.$form->selectarray('rank', $tab);
}
if (is_object($hookmanager) && empty($senderissupplier))
{
$parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));

View File

@ -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.

View File

@ -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.

View File

@ -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)

View File

@ -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,

View File

@ -1074,3 +1074,5 @@ AmountMustBePositive=Amount must be positive
ByStatus=By status
InformationMessage=Information
Used=Used
AtTheEnd=At the end
OnLine=On line

View File

@ -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,

View File

@ -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.