From 895957e89da1de1e296e3310acb93108d6939642 Mon Sep 17 00:00:00 2001 From: mgabriel Date: Thu, 2 Feb 2023 08:41:08 +0100 Subject: [PATCH 1/5] Modify margin rates in offers like VAT rates. --- htdocs/admin/propal.php | 13 ++++++++++ htdocs/comm/propal/card.php | 31 ++++++++++++++++++++++++ htdocs/core/tpl/objectline_title.tpl.php | 16 +++++++++--- htdocs/langs/en_US/margins.lang | 1 + htdocs/langs/fr_FR/margins.lang | 1 + 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 10044e33b5b..289c514c703 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -615,6 +615,19 @@ print " \n"; print ""; +print ''; +print ''.$langs->trans("ModifyMarginRates").''; +print ''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('PROPALE_MODIFY_MARGIN_RATES'); +} else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("PROPALE_MODIFY_MARGIN_RATES", $arrval, $conf->global->PROPALE_MODIFY_MARGIN_RATES); +} +print "\n"; +print ''; +print "\n"; + print "
"; print ''; print ""; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 3f74c4a860f..c1912451cc8 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -914,6 +914,37 @@ if (empty($reshook)) { foreach ($object->lines as $line) { $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); } + } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines', 'none') !== '' && $usercancreate) { + // Define margin + $margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0); + foreach ($object->lines as &$line) { + $subprice = price2num($line->pa_ht * (1 + $margin_rate/100), 'MU'); + $prod = new Product($db); + $prod->fetch($line->fk_product); + if ($prod->price_min > $subprice) { + $price_subprice = price($subprice, 0, $outlangs, 1, -1, -1, 'auto'); + $price_price_min = price($prod->price_min, 0, $outlangs, 1, -1, -1, 'auto'); + setEventMessages($prod->ref.' - '.$prod->label.' ('.$price_subprice.' < '.$price_price_min.' '.strtolower($langs->trans("MinPrice")).')'."\n", null, 'warnings'); + } + // Manage $line->subprice and $line->multicurrency_subprice + $multicurrency_subprice = $subprice * $line->multicurrency_subprice / $line->subprice; + // Update DB + $result = $object->updateline($line->id, $subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_rate, $line->localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $multicurrency_subprice); + // Update $object with new margin info + $line->price = $subprice; + $line->marge_tx = $margin_rate; + $line->marque_tx = $margin_rate * $line->pa_ht / $subprice; + $line->total_ht = $line->qty * $subprice; + $line->total_tva = $line->tva_tx * $line->qty * $subprice; + $line->total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice; + // Manage $line->subprice and $line->multicurrency_subprice + $line->multicurrency_total_ht = $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + $line->multicurrency_total_tva = $line->tva_tx * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + // Used previous $line->subprice and $line->multicurrency_subprice above, now they can be set to their new values + $line->subprice = $subprice; + $line->multicurrency_subprice = $multicurrency_subprice; + } } elseif ($action == 'addline' && $usercancreate) { // Add line // Set if we used free entry or predefined product $predef = ''; diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php index 4640d710705..991910865e4 100644 --- a/htdocs/core/tpl/objectline_title.tpl.php +++ b/htdocs/core/tpl/objectline_title.tpl.php @@ -140,9 +140,19 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) { } } - if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { - print ''.$langs->trans('MarginRate').''; - } + if (!(empty($conf->global->DISPLAY_MARGIN_RATES) && empty($conf->global->PROPALE_MODIFY_MARGIN_RATES)) && $user->rights->margins->liretous) { + print ''.$langs->trans('MarginRate'); + if (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $user->hasRight("propal", "creer")) { + print 'id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').''; + if (GETPOST('mode', 'aZ09') == 'marginforalllines') { + print '
'; + print ''; + print ''; + print '
'; + } + } + print ''; + } if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { print ''.$langs->trans('MarkRate').''; } diff --git a/htdocs/langs/en_US/margins.lang b/htdocs/langs/en_US/margins.lang index a91b139ec7b..9101966eff2 100644 --- a/htdocs/langs/en_US/margins.lang +++ b/htdocs/langs/en_US/margins.lang @@ -6,6 +6,7 @@ TotalMargin=Total Margin MarginOnProducts=Margin / Products MarginOnServices=Margin / Services MarginRate=Margin rate +ModifyMarginRates=Modify margin rates MarkRate=Mark rate DisplayMarginRates=Display margin rates DisplayMarkRates=Display mark rates diff --git a/htdocs/langs/fr_FR/margins.lang b/htdocs/langs/fr_FR/margins.lang index a8a68c6599f..742b8ce76c0 100644 --- a/htdocs/langs/fr_FR/margins.lang +++ b/htdocs/langs/fr_FR/margins.lang @@ -8,6 +8,7 @@ MarginOnServices=Marge / Services MarginRate=Taux de marge MarkRate=Taux de marque DisplayMarginRates=Afficher les taux de marge +ModifyMarginRates=Modifier les taux de marge DisplayMarkRates=Afficher les taux de marque InputPrice=Saisir un prix margin=Gestion des marges From 35ce7352e8ed9ec613ddaa8b4005ba0330c94405 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 2 Feb 2023 08:09:57 +0000 Subject: [PATCH 2/5] Fixing style errors. --- htdocs/comm/propal/card.php | 62 ++++++++++++------------ htdocs/core/tpl/objectline_title.tpl.php | 26 +++++----- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index c1912451cc8..88f3c1e44aa 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -914,37 +914,37 @@ if (empty($reshook)) { foreach ($object->lines as $line) { $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); } - } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines', 'none') !== '' && $usercancreate) { - // Define margin - $margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0); - foreach ($object->lines as &$line) { - $subprice = price2num($line->pa_ht * (1 + $margin_rate/100), 'MU'); - $prod = new Product($db); - $prod->fetch($line->fk_product); - if ($prod->price_min > $subprice) { - $price_subprice = price($subprice, 0, $outlangs, 1, -1, -1, 'auto'); - $price_price_min = price($prod->price_min, 0, $outlangs, 1, -1, -1, 'auto'); - setEventMessages($prod->ref.' - '.$prod->label.' ('.$price_subprice.' < '.$price_price_min.' '.strtolower($langs->trans("MinPrice")).')'."\n", null, 'warnings'); - } - // Manage $line->subprice and $line->multicurrency_subprice - $multicurrency_subprice = $subprice * $line->multicurrency_subprice / $line->subprice; - // Update DB - $result = $object->updateline($line->id, $subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_rate, $line->localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $multicurrency_subprice); - // Update $object with new margin info - $line->price = $subprice; - $line->marge_tx = $margin_rate; - $line->marque_tx = $margin_rate * $line->pa_ht / $subprice; - $line->total_ht = $line->qty * $subprice; - $line->total_tva = $line->tva_tx * $line->qty * $subprice; - $line->total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice; - // Manage $line->subprice and $line->multicurrency_subprice - $line->multicurrency_total_ht = $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; - $line->multicurrency_total_tva = $line->tva_tx * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; - $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; - // Used previous $line->subprice and $line->multicurrency_subprice above, now they can be set to their new values - $line->subprice = $subprice; - $line->multicurrency_subprice = $multicurrency_subprice; - } + } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines', 'none') !== '' && $usercancreate) { + // Define margin + $margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0); + foreach ($object->lines as &$line) { + $subprice = price2num($line->pa_ht * (1 + $margin_rate/100), 'MU'); + $prod = new Product($db); + $prod->fetch($line->fk_product); + if ($prod->price_min > $subprice) { + $price_subprice = price($subprice, 0, $outlangs, 1, -1, -1, 'auto'); + $price_price_min = price($prod->price_min, 0, $outlangs, 1, -1, -1, 'auto'); + setEventMessages($prod->ref.' - '.$prod->label.' ('.$price_subprice.' < '.$price_price_min.' '.strtolower($langs->trans("MinPrice")).')'."\n", null, 'warnings'); + } + // Manage $line->subprice and $line->multicurrency_subprice + $multicurrency_subprice = $subprice * $line->multicurrency_subprice / $line->subprice; + // Update DB + $result = $object->updateline($line->id, $subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_rate, $line->localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $multicurrency_subprice); + // Update $object with new margin info + $line->price = $subprice; + $line->marge_tx = $margin_rate; + $line->marque_tx = $margin_rate * $line->pa_ht / $subprice; + $line->total_ht = $line->qty * $subprice; + $line->total_tva = $line->tva_tx * $line->qty * $subprice; + $line->total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice; + // Manage $line->subprice and $line->multicurrency_subprice + $line->multicurrency_total_ht = $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + $line->multicurrency_total_tva = $line->tva_tx * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice; + // Used previous $line->subprice and $line->multicurrency_subprice above, now they can be set to their new values + $line->subprice = $subprice; + $line->multicurrency_subprice = $multicurrency_subprice; + } } elseif ($action == 'addline' && $usercancreate) { // Add line // Set if we used free entry or predefined product $predef = ''; diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php index 991910865e4..e2882bcd43f 100644 --- a/htdocs/core/tpl/objectline_title.tpl.php +++ b/htdocs/core/tpl/objectline_title.tpl.php @@ -140,19 +140,19 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) { } } - if (!(empty($conf->global->DISPLAY_MARGIN_RATES) && empty($conf->global->PROPALE_MODIFY_MARGIN_RATES)) && $user->rights->margins->liretous) { - print ''.$langs->trans('MarginRate'); - if (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $user->hasRight("propal", "creer")) { - print 'id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').''; - if (GETPOST('mode', 'aZ09') == 'marginforalllines') { - print '
'; - print ''; - print ''; - print '
'; - } - } - print ''; - } + if (!(empty($conf->global->DISPLAY_MARGIN_RATES) && empty($conf->global->PROPALE_MODIFY_MARGIN_RATES)) && $user->rights->margins->liretous) { + print ''.$langs->trans('MarginRate'); + if (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $user->hasRight("propal", "creer")) { + print 'id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').''; + if (GETPOST('mode', 'aZ09') == 'marginforalllines') { + print '
'; + print ''; + print ''; + print '
'; + } + } + print ''; + } if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { print ''.$langs->trans('MarkRate').''; } From cd4064c0349138a86afd63f2432e3f0e8bb611c8 Mon Sep 17 00:00:00 2001 From: mgabriel Date: Thu, 2 Feb 2023 10:07:52 +0100 Subject: [PATCH 3/5] Dolibarr was using td here but is now using th so th was substituted for td. --- htdocs/core/tpl/objectline_title.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php index e2882bcd43f..e00a34551a5 100644 --- a/htdocs/core/tpl/objectline_title.tpl.php +++ b/htdocs/core/tpl/objectline_title.tpl.php @@ -141,7 +141,7 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) { } if (!(empty($conf->global->DISPLAY_MARGIN_RATES) && empty($conf->global->PROPALE_MODIFY_MARGIN_RATES)) && $user->rights->margins->liretous) { - print ''.$langs->trans('MarginRate'); + print ''.$langs->trans('MarginRate'); if (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $user->hasRight("propal", "creer")) { print 'id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').''; if (GETPOST('mode', 'aZ09') == 'marginforalllines') { @@ -151,7 +151,7 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) { print ''; } } - print ''; + print ''; } if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { print ''.$langs->trans('MarkRate').''; From 99e5c894843a6084489228a26e9eb94c29a0979b Mon Sep 17 00:00:00 2001 From: mgabriel Date: Thu, 2 Feb 2023 10:20:02 +0100 Subject: [PATCH 4/5] In CodingPhpTest::testPHP, found a GETPOST that uses 'none' as a parameter which is not allowe. --- htdocs/comm/propal/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 88f3c1e44aa..d3310085f1f 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -914,7 +914,7 @@ if (empty($reshook)) { foreach ($object->lines as $line) { $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); } - } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines', 'none') !== '' && $usercancreate) { + } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines') !== '' && $usercancreate) { // Define margin $margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0); foreach ($object->lines as &$line) { From b8cd507287008ac7e9bdf4bda5969dff203b1930 Mon Sep 17 00:00:00 2001 From: mgabriel Date: Mon, 6 Feb 2023 10:06:23 +0100 Subject: [PATCH 5/5] As suggested by Dolibarr, removed PROPALE_MODIFY_MARGIN_RATES as not needed. --- htdocs/admin/propal.php | 13 ------------- htdocs/comm/propal/card.php | 2 +- htdocs/core/tpl/objectline_title.tpl.php | 4 ++-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 289c514c703..10044e33b5b 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -615,19 +615,6 @@ print " \n"; print ""; -print ''; -print ''.$langs->trans("ModifyMarginRates").''; -print ''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('PROPALE_MODIFY_MARGIN_RATES'); -} else { - $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("PROPALE_MODIFY_MARGIN_RATES", $arrval, $conf->global->PROPALE_MODIFY_MARGIN_RATES); -} -print "\n"; -print ''; -print "\n"; - print ""; print ''; print ""; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index d3310085f1f..f1e191b323d 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -914,7 +914,7 @@ if (empty($reshook)) { foreach ($object->lines as $line) { $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); } - } elseif (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines') !== '' && $usercancreate) { + } elseif ($action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines') !== '' && $usercancreate) { // Define margin $margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0); foreach ($object->lines as &$line) { diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php index e00a34551a5..24231d3fe68 100644 --- a/htdocs/core/tpl/objectline_title.tpl.php +++ b/htdocs/core/tpl/objectline_title.tpl.php @@ -140,9 +140,9 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) { } } - if (!(empty($conf->global->DISPLAY_MARGIN_RATES) && empty($conf->global->PROPALE_MODIFY_MARGIN_RATES)) && $user->rights->margins->liretous) { + if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { print ''.$langs->trans('MarginRate'); - if (!empty($conf->global->PROPALE_MODIFY_MARGIN_RATES) && $user->hasRight("propal", "creer")) { + if ($user->hasRight("propal", "creer")) { print 'id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').''; if (GETPOST('mode', 'aZ09') == 'marginforalllines') { print '
';