Skip to content
Snippets Groups Projects
Commit 1961b32a authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Can round with 0.5 ranges

parent 8e6f4d8e
Branches
Tags
No related merge requests found
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/price.lib.php");
$langs->load("companies"); $langs->load("companies");
$langs->load("products"); $langs->load("products");
...@@ -36,19 +37,42 @@ if (!$user->admin) ...@@ -36,19 +37,42 @@ if (!$user->admin)
if (isset($_POST["action"]) && $_POST["action"] == 'update') if (isset($_POST["action"]) && $_POST["action"] == 'update')
{ {
$error=0;
$MAXDEC=8; $MAXDEC=8;
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC
|| $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC || $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC) || $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC)
{ {
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC).'</div>';
} }
else
if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0
|| $_POST["MAIN_MAX_DECIMALS_TOT"] < 0
|| $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0)
{
$langs->load("errors");
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorNegativeValueNotAllowed").'</div>';
}
if ($_POST["MAIN_ROUNDING_RULE_TOT"])
{
if ($_POST["MAIN_ROUNDING_RULE_TOT"] * pow(10,$_POST["MAIN_MAX_DECIMALS_TOT"]) < 1)
{
$langs->load("errors");
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT").'</div>';
}
}
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_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_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, "MAIN_MAX_DECIMALS_SHOWN", $_POST["MAIN_MAX_DECIMALS_SHOWN"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_DISABLE_PDF_COMPRESSION", $_POST["MAIN_DISABLE_PDF_COMPRESSION"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_ROUNDING_RULE_TOT", $_POST["MAIN_ROUNDING_RULE_TOT"],'chaine',0,'',$conf->entity);
Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
exit; exit;
...@@ -56,6 +80,11 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update') ...@@ -56,6 +80,11 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update')
} }
/*
* View
*/
$html=new Form($db); $html=new Form($db);
llxHeader(); llxHeader();
...@@ -93,12 +122,10 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit') ...@@ -93,12 +122,10 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><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 '.$bc[$var].'><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>';
/*
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_PDF_COMPRESSION").'</td><td>'; print '<tr '.$bc[$var].'><td>';
print $html->selectyesno('MAIN_DISABLE_PDF_COMPRESSION',$conf->global->MAIN_DISABLE_PDF_COMPRESSION); print $html->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td></tr>'; print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>';
*/
print '</table>'; print '</table>';
...@@ -129,10 +156,10 @@ else ...@@ -129,10 +156,10 @@ else
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>';
/*
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_PDF_COMPRESSION").'</td><td align="right">'.yn($conf->global->MAIN_DISABLE_PDF_COMPRESSION).'</td></tr>'; print '<tr '.$bc[$var].'><td>';
*/ print $html->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
print '</td><td align="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>';
print '</table>'; print '</table>';
...@@ -142,6 +169,44 @@ else ...@@ -142,6 +169,44 @@ else
} }
// Show examples
print '<b>'.$langs->trans("Examples").":</b><br>\n";
$s=2/7;$qty=1;$vat=0;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat;
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[2]."<br>\n";
$s=10/3;$qty=1;$vat=0;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat;
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[2]."<br>\n";
$s=10/3;$qty=2;$vat=0;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat;
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[2]."<br>\n";
$s=10/3;$qty=1;$vat=10;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat;
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[2]."<br>\n";
$s=10/3;$qty=2;$vat=10;
$tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,'HT',0);
print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
print " x ".$langs->trans("Quantity").": ".$qty;
print " - ".$langs->trans("VAT").": ".$vat;
print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[2]."<br>\n";
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');
......
...@@ -713,6 +713,9 @@ MAIN_MAX_DECIMALS_UNIT=Max decimals for unit prices ...@@ -713,6 +713,9 @@ MAIN_MAX_DECIMALS_UNIT=Max decimals for unit prices
MAIN_MAX_DECIMALS_TOT=Max decimals for total prices MAIN_MAX_DECIMALS_TOT=Max decimals for total prices
MAIN_MAX_DECIMALS_SHOWN=Max decimals for prices shown on screen (Add <b>...</b> after this number if you want to see <b>...</b> when number is truncated when shown on screen) MAIN_MAX_DECIMALS_SHOWN=Max decimals for prices shown on screen (Add <b>...</b> after this number if you want to see <b>...</b> when number is truncated when shown on screen)
MAIN_DISABLE_PDF_COMPRESSION=Use PDF compression for generated PDF files. MAIN_DISABLE_PDF_COMPRESSION=Use PDF compression for generated PDF files.
MAIN_ROUNDING_RULE_TOT = Size of rounding range (for rare countries where rounding is done on something else than base 10)
UnitPriceOfProduct=Net unit price of a product
TotalPriceAfterRounding=Total price inc. tax after rounding
ParameterActiveForNextInputOnly=Parameter effective for next input only ParameterActiveForNextInputOnly=Parameter effective for next input only
NoEventOrNoAuditSetup=No security event has been recorded yet. This can be normal if audit has not been enabled on "setup - security - audit" page. NoEventOrNoAuditSetup=No security event has been recorded yet. This can be normal if audit has not been enabled on "setup - security - audit" page.
NoEventFoundWithCriteria=No security event has been found for such search criterias. NoEventFoundWithCriteria=No security event has been found for such search criterias.
......
...@@ -428,6 +428,7 @@ NotAllowed=Not allowed ...@@ -428,6 +428,7 @@ NotAllowed=Not allowed
ReadPermissionNotAllowed=Read permission not allowed ReadPermissionNotAllowed=Read permission not allowed
AmountInCurrency=Amount in %s currency AmountInCurrency=Amount in %s currency
Example=Example Example=Example
Examples=Examples
NoExample=No example NoExample=No example
FindBug=Report a bug FindBug=Report a bug
NbOfThirdParties=Number of third parties NbOfThirdParties=Number of third parties
......
...@@ -713,6 +713,9 @@ MAIN_MAX_DECIMALS_UNIT = Nombre de décimales maximum pour les prix unitaires ...@@ -713,6 +713,9 @@ MAIN_MAX_DECIMALS_UNIT = Nombre de décimales maximum pour les prix unitaires
MAIN_MAX_DECIMALS_TOT = Nombre de décimales maximum pour les prix totaux MAIN_MAX_DECIMALS_TOT = Nombre de décimales maximum pour les prix totaux
MAIN_MAX_DECIMALS_SHOWN = Nombre de décimales maximum pour les montant affichés à l'écran (Mettre <b>...</b> après ce nombre max si vous voulez voir <b>...</b> quand le nombre est tronqué à l'affichage écran) MAIN_MAX_DECIMALS_SHOWN = Nombre de décimales maximum pour les montant affichés à l'écran (Mettre <b>...</b> après ce nombre max si vous voulez voir <b>...</b> quand le nombre est tronqué à l'affichage écran)
MAIN_DISABLE_PDF_COMPRESSION = Utiliser la compression PDF pour les fichiers PDF générés. MAIN_DISABLE_PDF_COMPRESSION = Utiliser la compression PDF pour les fichiers PDF générés.
MAIN_ROUNDING_RULE_TOT = Taille du pas des arrondis (pour les très rares pays qui arrondissent sur une autre base que la base 10)
UnitPriceOfProduct=Prix unitaire HT d'un produit
TotalPriceAfterRounding=Prix total TTC après arrondis
ParameterActiveForNextInputOnly = Parametre effectif pour les prochaines saisies uniquement ParameterActiveForNextInputOnly = Parametre effectif pour les prochaines saisies uniquement
NoEventOrNoAuditSetup = Aucun évenement d'audit de sécurité n'a été enregistré. Ceci peut etre normal si l'audit n'a pas été activé dans la configuration - sécurité - audit. NoEventOrNoAuditSetup = Aucun évenement d'audit de sécurité n'a été enregistré. Ceci peut etre normal si l'audit n'a pas été activé dans la configuration - sécurité - audit.
NoEventFoundWithCriteria = Aucun évenement d'audit de sécurité trouvé avec ces critères. NoEventFoundWithCriteria = Aucun évenement d'audit de sécurité trouvé avec ces critères.
......
...@@ -427,6 +427,7 @@ NotAllowed=Non autorisé ...@@ -427,6 +427,7 @@ NotAllowed=Non autorisé
ReadPermissionNotAllowed=Lecture non autorisée ReadPermissionNotAllowed=Lecture non autorisée
AmountInCurrency=Montants exprimés en %s AmountInCurrency=Montants exprimés en %s
Example=Exemple Example=Exemple
Examples=Exemples
NoExample=Pas d'exemple NoExample=Pas d'exemple
FindBug=Signaler un bug FindBug=Signaler un bug
NbOfThirdParties=Nombre de tiers NbOfThirdParties=Nombre de tiers
......
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
/** /**
* \brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de * \brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
* facture, propale, commande ou autre depuis: * facture, propale, commande ou autre depuis:
* quantity, unit price, remise_percent_ligne, txtva, remise_percent_global, price_base_type, info_bits * quantity, unit price, remise_percent_ligne, txtva, remise_percent_global, price_base_type, info_bits * \param qty Quantity
* \param qty Quantity
* \param pu Prix unitaire (HT ou TTC selon price_base_type) * \param pu Prix unitaire (HT ou TTC selon price_base_type)
* \param remise_percent_ligne Remise ligne * \param remise_percent_ligne Remise ligne
* \param txtva Taux tva * \param txtva Taux tva
...@@ -59,7 +58,13 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe ...@@ -59,7 +58,13 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
$result[0] = price2num($tot_avec_remise, 'MT'); $result[0] = price2num($tot_avec_remise, 'MT');
$result[2] = price2num($tot_avec_remise * ( 1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non $result[2] = price2num($tot_avec_remise * ( 1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result2bis= price2num($tot_avec_remise * ( 1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) $result2bis= price2num($tot_avec_remise * ( 1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = $result2bis - $result[0]; if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT))
{
$result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
$result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
$result2bis=round($result2bis/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
}
$result[1] = $result2bis - $result[0]; // Total VAT = TTC - HT
$result[3] = price2num($pu, 'MU'); $result[3] = price2num($pu, 'MU');
$result[5] = price2num($pu * ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non $result[5] = price2num($pu * ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
...@@ -68,8 +73,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe ...@@ -68,8 +73,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
} }
else else
{ {
// On cacule a l'envers en partant du prix TTC // On calcule à l'envers en partant du prix TTC
// Utilise pour les produits a prix TTC reglemente (livres, ...)
$tot_sans_remise = $pu * $qty; $tot_sans_remise = $pu * $qty;
$tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100)); $tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100));
$tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100)); $tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100));
...@@ -82,7 +86,13 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe ...@@ -82,7 +86,13 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
$result[2] = price2num($tot_avec_remise, 'MT'); $result[2] = price2num($tot_avec_remise, 'MT');
$result[0] = price2num($tot_avec_remise / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non $result[0] = price2num($tot_avec_remise / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result0bis= price2num($tot_avec_remise / ( 1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) $result0bis= price2num($tot_avec_remise / ( 1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = $result[2] - $result0bis; if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT))
{
$result0bis=round($result0bis/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
$result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
$result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
}
$result[1] = $result[2] - $result0bis; // Total VAT = TTC - HT
$result[5] = price2num($pu, 'MU'); $result[5] = price2num($pu, 'MU');
$result[3] = price2num($pu / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non $result[3] = price2num($pu / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment