dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("companies");
30 $langs->load("products");
31 $langs->load("admin");
32 
33 if (! $user->admin) accessforbidden();
34 
35 $action = GETPOST('action','alpha');
36 
37 if ($action == 'update')
38 {
39  $error=0;
40  $MAXDEC=8;
41  if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC
42  || $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC
43  || $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC)
44  {
45  $error++;
46  setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC), null, 'errors');
47  }
48 
49  if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0
50  || $_POST["MAIN_MAX_DECIMALS_TOT"] < 0
51  || $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0)
52  {
53  $langs->load("errors");
54  $error++;
55  setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors');
56  }
57 
58  if ($_POST["MAIN_ROUNDING_RULE_TOT"])
59  {
60  if ($_POST["MAIN_ROUNDING_RULE_TOT"] * pow(10,$_POST["MAIN_MAX_DECIMALS_TOT"]) < 1)
61  {
62  $langs->load("errors");
63  $error++;
64  setEventMessages($langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"), null, 'errors');
65  }
66  }
67 
68  if (! $error)
69  {
70  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_UNIT", $_POST["MAIN_MAX_DECIMALS_UNIT"],'chaine',0,'',$conf->entity);
71  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_TOT", $_POST["MAIN_MAX_DECIMALS_TOT"],'chaine',0,'',$conf->entity);
72  dolibarr_set_const($db, "MAIN_MAX_DECIMALS_SHOWN", $_POST["MAIN_MAX_DECIMALS_SHOWN"],'chaine',0,'',$conf->entity);
73 
74  dolibarr_set_const($db, "MAIN_ROUNDING_RULE_TOT", $_POST["MAIN_ROUNDING_RULE_TOT"],'chaine',0,'',$conf->entity);
75 
76  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
77  exit;
78  }
79 }
80 
81 
82 
83 /*
84  * View
85 */
86 
87 $form=new Form($db);
88 
89 llxHeader();
90 
91 print load_fiche_titre($langs->trans("LimitsSetup"),'','title_setup');
92 
93 
94 print $langs->trans("LimitsDesc")."<br>\n";
95 print "<br>\n";
96 
97 if ($action == 'edit')
98 {
99  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
100  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
101  print '<input type="hidden" name="action" value="update">';
102 
103  clearstatcache();
104 
105  print '<table class="noborder" width="100%">';
106  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
107 
108 
109  print '<tr class="oddeven"><td>';
110  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
111  print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_UNIT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_UNIT . '"></td></tr>';
112 
113 
114  print '<tr class="oddeven"><td>';
115  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
116  print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_TOT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_TOT . '"></td></tr>';
117 
118 
119  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>';
120 
121 
122  print '<tr class="oddeven"><td>';
123  print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
124  print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>';
125 
126  print '</table>';
127 
128  print '<br><div class="center">';
129  print '<input class="button" type="submit" value="'.$langs->trans("Save").'">';
130  print '</div>';
131 
132  print '</form>';
133  print '<br>';
134 }
135 else
136 {
137  print '<table class="noborder" width="100%">';
138  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
139 
140 
141  print '<tr class="oddeven"><td>';
142  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly"));
143  print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_UNIT.'</td></tr>';
144 
145 
146  print '<tr class="oddeven"><td>';
147  print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
148  print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_TOT.'</td></tr>';
149 
150 
151  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>';
152 
153 
154  print '<tr class="oddeven"><td>';
155  print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly"));
156  print '</td><td align="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>';
157 
158  print '</table>';
159 
160  print '<div class="tabsAction">';
161  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
162  print '</div>';
163 }
164 
165 
166 if (empty($mysoc->country_code))
167 {
168  $langs->load("errors");
169  $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete"));
170  print '<br><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a>';
171 }
172 else
173 {
174 
175  // Show examples
176  print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n";
177 
178  // Always show vat rates with vat 0
179  $s=2/7;$qty=1;$vat=0;
180  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc);
181  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
182  print " x ".$langs->trans("Quantity").": ".$qty;
183  print " - ".$langs->trans("VAT").": ".$vat.'%';
184  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
185 
186  $s=10/3;$qty=1;$vat=0;
187  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc);
188  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
189  print " x ".$langs->trans("Quantity").": ".$qty;
190  print " - ".$langs->trans("VAT").": ".$vat.'%';
191  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
192 
193  $s=10/3;$qty=2;$vat=0;
194  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
195  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
196  print " x ".$langs->trans("Quantity").": ".$qty;
197  print " - ".$langs->trans("VAT").": ".$vat.'%';
198  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
199 
200 
201  // Add vat rates examples specific to country
202  $vat_rates=array();
203 
204  $sql="SELECT taux as vat_rate";
205  $sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
206  $sql.=" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$mysoc->country_code."' AND t.taux <> 0";
207  $sql.=" ORDER BY t.taux ASC";
208  $resql=$db->query($sql);
209  if ($resql)
210  {
211  $num = $db->num_rows($resql);
212  if ($num)
213  {
214  for ($i = 0; $i < $num; $i++)
215  {
216  $obj = $db->fetch_object($resql);
217  $vat_rates[$i] = $obj->vat_rate;
218  }
219  }
220  }
221  else dol_print_error($db);
222 
223  if (count($vat_rates))
224  {
225  foreach($vat_rates as $vat)
226  {
227  for ($qty=1; $qty<=2; $qty++)
228  {
229  $s=10/3;
230  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
231  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
232  print " x ".$langs->trans("Quantity").": ".$qty;
233  print " - ".$langs->trans("VAT").": ".$vat.'%';
234  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
235  }
236  }
237  }
238  else
239  {
240  // More examples if not specific vat rate found
241  // This example must be kept for test purpose with current value because value used (2/7, 10/3, and vat 0, 10)
242  // were calculated to show all possible cases of rounding. If we change this, examples becomes useless or show the same rounding rule.
243 
244  $s=10/3;$qty=1;$vat=10;
245  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
246  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
247  print " x ".$langs->trans("Quantity").": ".$qty;
248  print " - ".$langs->trans("VAT").": ".$vat.'%';
249  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
250 
251  $s=10/3;$qty=2;$vat=10;
252  $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
253  print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU');
254  print " x ".$langs->trans("Quantity").": ".$qty;
255  print " - ".$langs->trans("VAT").": ".$vat.'%';
256  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
257 
258  }
259 
260  // Important: can debug rounding, to simulate the rounded total
261  /*
262  print '<br><b>'.$langs->trans("VATRoundedByLine").' ('.$langs->trans("DolibarrDefault").')</b><br>';
263 
264  foreach($vat_rates as $vat)
265  {
266  for ($qty=1; $qty<=2; $qty++)
267  {
268  $s1=10/3;
269  $s2=2/7;
270 
271  // Round by line
272  $tmparray1=calcul_price_total(1,$qty*price2num($s1,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
273  $tmparray2=calcul_price_total(1,$qty*price2num($s2,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc);
274  $total_ht = $tmparray1[0] + $tmparray2[0];
275  $total_tva = $tmparray1[1] + $tmparray2[1];
276  $total_ttc = $tmparray1[2] + $tmparray2[2];
277 
278  print $langs->trans("UnitPriceOfProduct").": ".(price2num($s1,'MU') + price2num($s2,'MU'));
279  print " x ".$langs->trans("Quantity").": ".$qty;
280  print " - ".$langs->trans("VAT").": ".$vat.'%';
281  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n";
282  }
283  }
284 
285  print '<br><b>'.$langs->trans("VATRoundedOnTotal").'</b><br>';
286 
287  foreach($vat_rates as $vat)
288  {
289  for ($qty=1; $qty<=2; $qty++)
290  {
291  $s1=10/3;
292  $s2=2/7;
293 
294  // Global round
295  $subtotal_ht = (($qty*price2num($s1,'MU')) + ($qty*price2num($s2,'MU')));
296  $tmparray3=calcul_price_total(1,$subtotal_ht,0,$vat,0,0,0,'HT',0, 0,$mysoc);
297  $total_ht = $tmparray3[0];
298  $total_tva = $tmparray3[1];
299  $total_ttc = $tmparray3[2];
300 
301  print $langs->trans("UnitPriceOfProduct").": ".price2num($s1+$s2,'MU');
302  print " x ".$langs->trans("Quantity").": ".$qty;
303  print " - ".$langs->trans("VAT").": ".$vat.'%';
304  print " &nbsp; -> &nbsp; ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n";
305  }
306  }
307  */
308 }
309 
310 
311 llxFooter();
312 
313 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:485
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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
print
Draft customers invoices.
Definition: index.php:91
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:1013
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...