dolibarr  9.0.0
limits.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array('companies', 'products', 'admin'));
31 
32 if (! $user->admin) accessforbidden();
33 
34 $action = GETPOST('action','alpha');
35 
36 if ($action == 'update')
37 {
38  $error=0;
39  $MAXDEC=8;
40  if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC
41  || $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC
42  || $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC)
43  {
44  $error++;
45  setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC), null, 'errors');
46  }
47 
48  if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0
49  || $_POST["MAIN_MAX_DECIMALS_TOT"] < 0
50  || $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0)
51  {
52  $langs->load("errors");
53  $error++;
54  setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors');
55  }
56 
57  if ($_POST["MAIN_ROUNDING_RULE_TOT"])
58  {
59  if ($_POST["MAIN_ROUNDING_RULE_TOT"] * pow(10,$_POST["MAIN_MAX_DECIMALS_TOT"]) < 1)
60  {
61  $langs->load("errors");
62  $error++;
63  setEventMessages($langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"), null, 'errors');
64  }
65  }
66 
67  if (! $error)
68  {
69  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_UNIT", $_POST["MAIN_MAX_DECIMALS_UNIT"],'chaine',0,'',$conf->entity);
70  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_TOT", $_POST["MAIN_MAX_DECIMALS_TOT"],'chaine',0,'',$conf->entity);
71  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_SHOWN", $_POST["MAIN_MAX_DECIMALS_SHOWN"],'chaine',0,'',$conf->entity);
72 
73  dolibarr_set_const($db, "MAIN_ROUNDING_RULE_TOT", $_POST["MAIN_ROUNDING_RULE_TOT"],'chaine',0,'',$conf->entity);
74 
75  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
76  exit;
77  }
78 }
79 
80 
81 
82 /*
83  * View
84 */
85 
86 $form=new Form($db);
87 
88 llxHeader();
89 
90 print load_fiche_titre($langs->trans("LimitsSetup"),'','title_setup');
91 
92 
93 print $langs->trans("LimitsDesc")."<br>\n";
94 print "<br>\n";
95 
96 if ($action == 'edit')
97 {
98  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
99  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
100  print '<input type="hidden" name="action" value="update">';
101 
102  clearstatcache();
103 
104  print '<table class="noborder" width="100%">';
105  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
106 
107 
108  print '<tr class="oddeven"><td>';
109  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
110  print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_UNIT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_UNIT . '"></td></tr>';
111 
112 
113  print '<tr class="oddeven"><td>';
114  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
115  print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_TOT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_TOT . '"></td></tr>';
116 
117 
118  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>';
119 
120 
121  print '<tr class="oddeven"><td>';
122  print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
123  print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>';
124 
125  print '</table>';
126 
127  print '<br><div class="center">';
128  print '<input class="button" type="submit" value="'.$langs->trans("Save").'">';
129  print '</div>';
130 
131  print '</form>';
132  print '<br>';
133 }
134 else
135 {
136  print '<table class="noborder" width="100%">';
137  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
138 
139 
140  print '<tr class="oddeven"><td>';
141  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
142  print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_UNIT.'</td></tr>';
143 
144 
145  print '<tr class="oddeven"><td>';
146  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
147  print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_TOT.'</td></tr>';
148 
149 
150  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>';
151 
152 
153  print '<tr class="oddeven"><td>';
154  print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
155  print '</td><td align="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>';
156 
157  print '</table>';
158 
159  print '<div class="tabsAction">';
160  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
161  print '</div>';
162 }
163 
164 
165 if (empty($mysoc->country_code))
166 {
167  $langs->load("errors");
168  $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete"));
169  print '<br><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a>';
170 }
171 else
172 {
173 
174  // Show examples
175  print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n";
176 
177  // Always show vat rates with vat 0
178  $s=2/7;$qty=1;$vat=0;
179  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc);
180  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
181  print " x ".$langs->trans("Quantity").": ".$qty;
182  print " - ".$langs->trans("VAT").": ".$vat.'%';
183  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
184 
185  $s=10/3;$qty=1;$vat=0;
186  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc);
187  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
188  print " x ".$langs->trans("Quantity").": ".$qty;
189  print " - ".$langs->trans("VAT").": ".$vat.'%';
190  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
191 
192  $s=10/3;$qty=2;$vat=0;
193  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
194  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
195  print " x ".$langs->trans("Quantity").": ".$qty;
196  print " - ".$langs->trans("VAT").": ".$vat.'%';
197  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
198 
199 
200  // Add vat rates examples specific to country
201  $vat_rates=array();
202 
203  $sql="SELECT taux as vat_rate";
204  $sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
205  $sql.=" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$mysoc->country_code."' AND t.taux <> 0";
206  $sql.=" ORDER BY t.taux ASC";
207  $resql=$db->query($sql);
208  if ($resql)
209  {
210  $num = $db->num_rows($resql);
211  if ($num)
212  {
213  for ($i = 0; $i < $num; $i++)
214  {
215  $obj = $db->fetch_object($resql);
216  $vat_rates[$i] = $obj->vat_rate;
217  }
218  }
219  }
220  else dol_print_error($db);
221 
222  if (count($vat_rates))
223  {
224  foreach($vat_rates as $vat)
225  {
226  for ($qty=1; $qty<=2; $qty++)
227  {
228  $s=10/3;
229  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
230  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
231  print " x ".$langs->trans("Quantity").": ".$qty;
232  print " - ".$langs->trans("VAT").": ".$vat.'%';
233  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
234  }
235  }
236  }
237  else
238  {
239  // More examples if not specific vat rate found
240  // This example must be kept for test purpose with current value because value used (2/7, 10/3, and vat 0, 10)
241  // were calculated to show all possible cases of rounding. If we change this, examples becomes useless or show the same rounding rule.
242 
243  $s=10/3;$qty=1;$vat=10;
244  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
245  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
246  print " x ".$langs->trans("Quantity").": ".$qty;
247  print " - ".$langs->trans("VAT").": ".$vat.'%';
248  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
249 
250  $s=10/3;$qty=2;$vat=10;
251  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
252  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
253  print " x ".$langs->trans("Quantity").": ".$qty;
254  print " - ".$langs->trans("VAT").": ".$vat.'%';
255  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
256  }
257 
258  // Important: can debug rounding, to simulate the rounded total
259  /*
260  print '<br><b>'.$langs->trans("VATRoundedByLine").' ('.$langs->trans("DolibarrDefault").')</b><br>';
261 
262  foreach($vat_rates as $vat)
263  {
264  for ($qty=1; $qty<=2; $qty++)
265  {
266  $s1=10/3;
267  $s2=2/7;
268 
269  // Round by line
270  $tmparray1=calcul_price_total(1,$qty*price2num($s1,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
271  $tmparray2=calcul_price_total(1,$qty*price2num($s2,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
272  $total_ht = $tmparray1[0] + $tmparray2[0];
273  $total_tva = $tmparray1[1] + $tmparray2[1];
274  $total_ttc = $tmparray1[2] + $tmparray2[2];
275 
276  print $langs->trans("UnitPriceOfProduct").": ".(price2num($s1,'MU') + price2num($s2,'MU'));
277  print " x ".$langs->trans("Quantity").": ".$qty;
278  print " - ".$langs->trans("VAT").": ".$vat.'%';
279  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n";
280  }
281  }
282 
283  print '<br><b>'.$langs->trans("VATRoundedOnTotal").'</b><br>';
284 
285  foreach($vat_rates as $vat)
286  {
287  for ($qty=1; $qty<=2; $qty++)
288  {
289  $s1=10/3;
290  $s2=2/7;
291 
292  // Global round
293  $subtotal_ht = (($qty*price2num($s1,'MU')) + ($qty*price2num($s2,'MU')));
294  $tmparray3=calcul_price_total(1,$subtotal_ht,0,$vat,0,0,0,'HT',0, 0,$mysoc);
295  $total_ht = $tmparray3[0];
296  $total_tva = $tmparray3[1];
297  $total_ttc = $tmparray3[2];
298 
299  print $langs->trans("UnitPriceOfProduct").": ".price2num($s1+$s2,'MU');
300  print " x ".$langs->trans("Quantity").": ".$qty;
301  print " - ".$langs->trans("VAT").": ".$vat.'%';
302  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n";
303  }
304  }
305  */
306 }
307 
308 // End of page
309 llxFooter();
310 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Empty header.
Definition: wrapper.php:44
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0)
Calculate totals (net, vat, ...) of a line.
Definition: price.lib.php:85
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...