Merge pull request #9924 from hregis/develop_project
NEW possibility to defined rounding rules by currency
This commit is contained in:
commit
ea9d611024
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2009-2018 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -32,31 +32,37 @@ $langs->loadLangs(array('companies', 'products', 'admin'));
|
||||
if (! $user->admin) accessforbidden();
|
||||
|
||||
$action = GETPOST('action', 'alpha');
|
||||
$currencycode = GETPOST('currencycode', 'alpha');
|
||||
|
||||
$mainmaxdecimalsunit = 'MAIN_MAX_DECIMALS_UNIT'.(! empty($currencycode)?'_'.$currencycode:'');
|
||||
$mainmaxdecimalstot = 'MAIN_MAX_DECIMALS_TOT'.(! empty($currencycode)?'_'.$currencycode:'');
|
||||
$mainmaxdecimalsshown = 'MAIN_MAX_DECIMALS_SHOWN'.(! empty($currencycode)?'_'.$currencycode:'');
|
||||
$mainroundingruletot = 'MAIN_ROUNDING_RULE_TOT'.(! empty($currencycode)?'_'.$currencycode:'');
|
||||
|
||||
if ($action == 'update')
|
||||
{
|
||||
$error=0;
|
||||
$MAXDEC=8;
|
||||
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC
|
||||
|| $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC
|
||||
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC)
|
||||
$error=0;
|
||||
$MAXDEC=8;
|
||||
if ($_POST[$mainmaxdecimalsunit] > $MAXDEC
|
||||
|| $_POST[$mainmaxdecimalstot] > $MAXDEC
|
||||
|| $_POST[$mainmaxdecimalsshown] > $MAXDEC)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden", $MAXDEC), null, 'errors');
|
||||
}
|
||||
|
||||
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0
|
||||
|| $_POST["MAIN_MAX_DECIMALS_TOT"] < 0
|
||||
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0)
|
||||
if ($_POST[$mainmaxdecimalsunit].(! empty($currencycode)?'_'.$currencycode:'') < 0
|
||||
|| $_POST[$mainmaxdecimalstot] < 0
|
||||
|| $_POST[$mainmaxdecimalsshown] < 0)
|
||||
{
|
||||
$langs->load("errors");
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors');
|
||||
}
|
||||
|
||||
if ($_POST["MAIN_ROUNDING_RULE_TOT"])
|
||||
if ($_POST[$mainroundingruletot])
|
||||
{
|
||||
if ($_POST["MAIN_ROUNDING_RULE_TOT"] * pow(10, $_POST["MAIN_MAX_DECIMALS_TOT"]) < 1)
|
||||
if ($_POST[$mainroundingruletot] * pow(10, $_POST[$mainmaxdecimalstot]) < 1)
|
||||
{
|
||||
$langs->load("errors");
|
||||
$error++;
|
||||
@ -66,22 +72,21 @@ if ($action == 'update')
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
dolibarr_set_const($db, "MAIN_MAX_DECIMALS_UNIT", $_POST["MAIN_MAX_DECIMALS_UNIT"], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAX_DECIMALS_TOT", $_POST["MAIN_MAX_DECIMALS_TOT"], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAX_DECIMALS_SHOWN", $_POST["MAIN_MAX_DECIMALS_SHOWN"], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, $mainmaxdecimalsunit, $_POST[$mainmaxdecimalsunit], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, $mainmaxdecimalstot, $_POST[$mainmaxdecimalstot], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, $mainmaxdecimalsshown, $_POST[$mainmaxdecimalsshown], 'chaine', 0, '', $conf->entity);
|
||||
|
||||
dolibarr_set_const($db, "MAIN_ROUNDING_RULE_TOT", $_POST["MAIN_ROUNDING_RULE_TOT"], 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, $mainroundingruletot, $_POST[$mainroundingruletot], 'chaine', 0, '', $conf->entity);
|
||||
|
||||
header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
|
||||
header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup".(! empty($currencycode)?'¤cycode='.$currencycode:''));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
@ -89,6 +94,31 @@ llxHeader();
|
||||
|
||||
print load_fiche_titre($langs->trans("LimitsSetup"), '', 'title_setup');
|
||||
|
||||
if (! empty($conf->multicurrency->enabled) && ! empty($conf->global->MULTICURRENCY_USE_LIMIT_BY_CURRENCY))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/multicurrency.lib.php';
|
||||
|
||||
$currencycode = (! empty($currencycode)?$currencycode:$conf->currency);
|
||||
$aCurrencies = array($conf->currency); // Default currency always first position
|
||||
|
||||
$sql = 'SELECT rowid, code FROM '.MAIN_DB_PREFIX.'multicurrency';
|
||||
$sql.= ' WHERE entity = '.$conf->entity;
|
||||
$sql.= ' AND code != "'.$conf->currency.'"'; // Default currency always first position
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj = $db->fetch_object($resql))
|
||||
{
|
||||
$aCurrencies[] = $obj->code;
|
||||
}
|
||||
|
||||
if (! empty($aCurrencies) && count($aCurrencies) > 1)
|
||||
{
|
||||
$head = multicurrencyLimitPrepareHead($aCurrencies);
|
||||
dol_fiche_head($head, $currencycode, '', -1, "multicurrency");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print '<span class="opacitymedium">'.$langs->trans("LimitsDesc")."</span><br>\n";
|
||||
print "<br>\n";
|
||||
@ -98,29 +128,29 @@ if ($action == 'edit')
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
if (! empty($conf->multicurrency->enabled) && ! empty($conf->global->MULTICURRENCY_USE_LIMIT_BY_CURRENCY)) {
|
||||
print '<input type="hidden" name="currencycode" value="'.$currencycode.'">';
|
||||
}
|
||||
|
||||
clearstatcache();
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
||||
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_UNIT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_UNIT . '"></td></tr>';
|
||||
print '</td><td><input class="flat" name="'.$mainmaxdecimalsunit.'" size="3" value="'.(! empty($conf->global->$mainmaxdecimalsunit)?$conf->global->$mainmaxdecimalsunit:$conf->global->MAIN_MAX_DECIMALS_UNIT).'"></td></tr>';
|
||||
|
||||
|
||||
print '<tr><td>';
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_TOT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_TOT . '"></td></tr>';
|
||||
print '</td><td><input class="flat" name="'.$mainmaxdecimalstot.'" size="3" value="'.(! empty($conf->global->$mainmaxdecimalstot)?$conf->global->$mainmaxdecimalstot:$conf->global->MAIN_MAX_DECIMALS_TOT).'"></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td>';
|
||||
print '<td><input class="flat" name="'.$mainmaxdecimalsshown.'" size="3" value="'.(! empty($conf->global->$mainmaxdecimalsshown)?$conf->global->$mainmaxdecimalsshown:$conf->global->MAIN_MAX_DECIMALS_SHOWN).'"></td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td><input class="flat" name="MAIN_MAX_DECIMALS_SHOWN" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_SHOWN . '"></td></tr>';
|
||||
|
||||
|
||||
print '<tr><td>';
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>';
|
||||
print '</td><td><input class="flat" name="'.$mainroundingruletot.'" size="3" value="'.(! empty($conf->global->$mainroundingruletot)?$conf->global->$mainroundingruletot:$conf->global->MAIN_ROUNDING_RULE_TOT).'"></td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
@ -138,32 +168,28 @@ else
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
||||
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td class="right">'.$conf->global->MAIN_MAX_DECIMALS_UNIT.'</td></tr>';
|
||||
print '</td><td align="right">'.(! empty($conf->global->$mainmaxdecimalsunit)?$conf->global->$mainmaxdecimalsunit:$conf->global->MAIN_MAX_DECIMALS_UNIT).'</td></tr>';
|
||||
|
||||
|
||||
print '<tr><td>';
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td class="right">'.$conf->global->MAIN_MAX_DECIMALS_TOT.'</td></tr>';
|
||||
print '</td><td align="right">'.(! empty($conf->global->$mainmaxdecimalstot)?$conf->global->$mainmaxdecimalstot:$conf->global->MAIN_MAX_DECIMALS_TOT).'</td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td>';
|
||||
print '<td align="right">'.(! empty($conf->global->$mainmaxdecimalsshown)?$conf->global->$mainmaxdecimalsshown:$conf->global->MAIN_MAX_DECIMALS_SHOWN).'</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td class="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>';
|
||||
|
||||
|
||||
print '<tr><td>';
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
|
||||
print '</td><td class="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>';
|
||||
print '</td><td align="right">'.(! empty($conf->global->$mainroundingruletot)?$conf->global->$mainroundingruletot:$conf->global->MAIN_ROUNDING_RULE_TOT).'</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<div class="tabsAction tabsActionNoBottom">';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
|
||||
print '<div class="tabsAction">';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit'.(! empty($currencycode)?'¤cycode='.$currencycode:'').'">'.$langs->trans("Modify").'</a>';
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
|
||||
if (empty($mysoc->country_code))
|
||||
{
|
||||
$langs->load("errors");
|
||||
@ -197,7 +223,6 @@ else
|
||||
print " - ".$langs->trans("VAT").": ".$vat.'%';
|
||||
print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
|
||||
|
||||
|
||||
// Add vat rates examples specific to country
|
||||
$vat_rates=array();
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* <one line to give the program's name and a brief idea of what it does.>
|
||||
* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
|
||||
/* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
|
||||
* Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* 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
|
||||
@ -44,3 +44,28 @@ function multicurrencyAdminPrepareHead()
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare array with list of currency tabs
|
||||
*
|
||||
* @param array $aCurrencies Currencies array
|
||||
* @return array Array of tabs
|
||||
*/
|
||||
function multicurrencyLimitPrepareHead($aCurrencies)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$i=0;
|
||||
$head = array();
|
||||
|
||||
foreach($aCurrencies as $currency)
|
||||
{
|
||||
$head[$i][0] = $_SERVER['PHP_SELF'].'?currencycode='.$currency;
|
||||
$head[$i][1] = $langs->trans("Currency".$currency).' ('.$langs->getCurrencySymbol($currency).')';
|
||||
$head[$i][2] = $currency;
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user