NEW possibility to defined rounding rules by currency
This commit is contained in:
parent
0c77f6c3c5
commit
26b00dc5ca
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2009-2018 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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();
|
if (! $user->admin) accessforbidden();
|
||||||
|
|
||||||
$action = GETPOST('action','alpha');
|
$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')
|
if ($action == 'update')
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
$MAXDEC=8;
|
$MAXDEC=8;
|
||||||
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC
|
if ($_POST[$mainmaxdecimalsunit] > $MAXDEC
|
||||||
|| $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC
|
|| $_POST[$mainmaxdecimalstot] > $MAXDEC
|
||||||
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC)
|
|| $_POST[$mainmaxdecimalsshown] > $MAXDEC)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC), null, 'errors');
|
setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0
|
if ($_POST[$mainmaxdecimalsunit].(! empty($currencycode)?'_'.$currencycode:'') < 0
|
||||||
|| $_POST["MAIN_MAX_DECIMALS_TOT"] < 0
|
|| $_POST[$mainmaxdecimalstot] < 0
|
||||||
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0)
|
|| $_POST[$mainmaxdecimalsshown] < 0)
|
||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors');
|
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");
|
$langs->load("errors");
|
||||||
$error++;
|
$error++;
|
||||||
@ -66,22 +72,21 @@ if ($action == 'update')
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
dolibarr_set_const($db, "MAIN_MAX_DECIMALS_UNIT", $_POST["MAIN_MAX_DECIMALS_UNIT"],'chaine',0,'',$conf->entity);
|
dolibarr_set_const($db, $mainmaxdecimalsunit, $_POST[$mainmaxdecimalsunit],'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, $mainmaxdecimalstot, $_POST[$mainmaxdecimalstot],'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, $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;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$form=new Form($db);
|
$form=new Form($db);
|
||||||
|
|
||||||
@ -89,6 +94,31 @@ llxHeader();
|
|||||||
|
|
||||||
print load_fiche_titre($langs->trans("LimitsSetup"),'','title_setup');
|
print load_fiche_titre($langs->trans("LimitsSetup"),'','title_setup');
|
||||||
|
|
||||||
|
if ($conf->multicurrency->enabled && $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 $langs->trans("LimitsDesc")."<br>\n";
|
print $langs->trans("LimitsDesc")."<br>\n";
|
||||||
print "<br>\n";
|
print "<br>\n";
|
||||||
@ -98,29 +128,29 @@ if ($action == 'edit')
|
|||||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="update">';
|
print '<input type="hidden" name="action" value="update">';
|
||||||
|
if ($conf->multicurrency->enabled && $conf->global->MULTICURRENCY_USE_LIMIT_BY_CURRENCY) {
|
||||||
|
print '<input type="hidden" name="currencycode" value="'.$currencycode.'">';
|
||||||
|
}
|
||||||
|
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
print '<tr class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
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 class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
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><td><input class="flat" name="MAIN_MAX_DECIMALS_SHOWN" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_SHOWN . '"></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 class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
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>';
|
print '</table>';
|
||||||
|
|
||||||
@ -136,32 +166,28 @@ else
|
|||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
print '<tr class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
||||||
print '</td><td align="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 class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
||||||
print '</td><td align="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><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</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 class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
|
||||||
print '</td><td align="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 '</table>';
|
||||||
|
|
||||||
print '<div class="tabsAction">';
|
print '<div class="tabsAction">';
|
||||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit'.(! empty($currencycode)?'¤cycode='.$currencycode:'').'">'.$langs->trans("Modify").'</a>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (empty($mysoc->country_code))
|
if (empty($mysoc->country_code))
|
||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
@ -170,7 +196,6 @@ if (empty($mysoc->country_code))
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// Show examples
|
// Show examples
|
||||||
print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n";
|
print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n";
|
||||||
|
|
||||||
@ -196,7 +221,6 @@ else
|
|||||||
print " - ".$langs->trans("VAT").": ".$vat.'%';
|
print " - ".$langs->trans("VAT").": ".$vat.'%';
|
||||||
print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
|
print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
|
||||||
|
|
||||||
|
|
||||||
// Add vat rates examples specific to country
|
// Add vat rates examples specific to country
|
||||||
$vat_rates=array();
|
$vat_rates=array();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -44,3 +44,28 @@ function multicurrencyAdminPrepareHead()
|
|||||||
|
|
||||||
return $head;
|
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