Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/erp/htdocs/custom/discountprice/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp/htdocs/custom/discountprice/lib/discountprice.lib.php
<?php
/* Copyright (C) 2017      Open-DSI             <support@open-dsi.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *	\file       htdocs/discountprice/lib/discountprice.lib.php
 * 	\ingroup	discountprice
 *	\brief      Functions for the module DiscountPrice
 */

/**
 * Prepare array with list of tabs
 *
 * @return  array				Array of tabs to show
 */
function discountprice_prepare_head()
{
    global $langs, $conf, $user;
    $h = 0;
    $head = array();

    $head[$h][0] = dol_buildpath("/discountprice/admin/setup.php", 1);
    $head[$h][1] = $langs->trans("Parameters");
    $head[$h][2] = 'settings';
    $h++;

    $head[$h][0] = dol_buildpath("/discountprice/admin/about.php", 1);
    $head[$h][1] = $langs->trans("About");
    $head[$h][2] = 'about';
    $h++;

    $head[$h][0] = dol_buildpath("/discountprice/admin/changelog.php", 1);
    $head[$h][1] = $langs->trans("OpenDsiChangeLog");
    $head[$h][2] = 'changelog';
    $h++;

    complete_head_from_modules($conf,$langs,null,$head,$h,'discountprice_admin');

    return $head;
}

/**
 * Print js code for replace discount to product selection
 *
 * @param   string  $html_name  Name of the html element for product selection
 * @return  void
 */
function print_js_ajax_discount_price($html_name)
{
    global $conf;

    $entity = $conf->entity;
    $url = dol_buildpath('/discountprice/ajax/ajaxdiscountpriceforproduct.php', 1);
    $mode_calculation = $conf->global->DISCOUNTPRICE_CALCULATION_MODE_WITH_EXISTING_DISCOUNT == 1?'true':'false'; // 1: replace, 2: cascade
    $precision = $conf->global->DISCOUNTPRICE_DISCOUNT_ROUND_PRECISION;

    $script = <<<SCRIPT
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            var select = $("select#$html_name");
            var autocompletion = $("input#$html_name");
            var input = select.length ? select : autocompletion;

            if (input.length == 0) {
                console.error('Error: Input for product selection not found.');
            } else {
                input.on("change", function(event) {
                    var id_product = $(this).val();
                    $.get("$url", { id: id_product, entity: $entity }, function(data) {
                        if (data!=null && data!="") {
                            data = JSON.parse(data);
                            if (data.discount) {
                                if ($mode_calculation) {
                                    $("#remise_percent").val(data.discount);
                                } else {
                                    var discount     = parseFloat($("#remise_percent").val());
                                    var discount_max = parseFloat(data.discount_max);
                                    var precision = Math.pow(10, $precision);
                                    
                                    if (discount > 0) discount = 100 - ((100 - discount) * (100 - data.discount) / 100); else discount = data.discount;
                                    discount = Math.trunc(discount * precision) / precision;
                                    discount_max = Math.trunc(discount_max * precision) / precision;

                                    discount = Math.min(discount, discount_max);
                                    $("#remise_percent").val(discount);
                                }
                            } else if (data.error) {
                                console.error("Error: " + data.error);
                            }
                        } else {
                            console.error("Error: Ajax url $url?id=" + id_product + " has returned an empty page. Should be an empty json array."); 
                        }
                    });
                });
            }
        });
    </script>
SCRIPT;

    print $script;
}

Hry