1 | <?php |
||
2 | /* Copyright (C) 2007-2012 Laurent Destailleur <[email protected]> |
||
3 | * Copyright (C) 2009-2012 Regis Houssin <[email protected]> |
||
4 | * Copyright (C) 2010 Juanjo Menent <[email protected]> |
||
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 | |||
20 | /** |
||
21 | * \file htdocs/admin/limits.php |
||
22 | * \brief Page to setup limits |
||
23 | */ |
||
24 | |||
25 | |||
26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
||
27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
||
28 | require DOL_BASE_PATH . '/main.inc.php'; |
||
29 | |||
30 | require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
||
31 | require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
||
32 | |||
33 | // Load translation files required by the page |
||
34 | $langs->loadLangs(array('companies', 'products', 'admin')); |
||
35 | |||
36 | if (! $user->admin) accessforbidden(); |
||
37 | |||
38 | $action = GETPOST('action','alpha'); |
||
39 | |||
40 | if ($action == 'update') |
||
41 | { |
||
42 | $error=0; |
||
43 | $MAXDEC=8; |
||
44 | if ($_POST["MAIN_MAX_DECIMALS_UNIT"] > $MAXDEC |
||
45 | || $_POST["MAIN_MAX_DECIMALS_TOT"] > $MAXDEC |
||
46 | || $_POST["MAIN_MAX_DECIMALS_SHOWN"] > $MAXDEC) |
||
47 | { |
||
48 | $error++; |
||
49 | setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden",$MAXDEC), null, 'errors'); |
||
50 | } |
||
51 | |||
52 | if ($_POST["MAIN_MAX_DECIMALS_UNIT"] < 0 |
||
53 | || $_POST["MAIN_MAX_DECIMALS_TOT"] < 0 |
||
54 | || $_POST["MAIN_MAX_DECIMALS_SHOWN"] < 0) |
||
55 | { |
||
56 | $langs->load("errors"); |
||
57 | $error++; |
||
58 | setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors'); |
||
59 | } |
||
60 | |||
61 | if ($_POST["MAIN_ROUNDING_RULE_TOT"]) |
||
62 | { |
||
63 | if ($_POST["MAIN_ROUNDING_RULE_TOT"] * pow(10,$_POST["MAIN_MAX_DECIMALS_TOT"]) < 1) |
||
64 | { |
||
65 | $langs->load("errors"); |
||
66 | $error++; |
||
67 | setEventMessages($langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"), null, 'errors'); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | if (! $error) |
||
72 | { |
||
73 | dolibarr_set_const($db, "MAIN_MAX_DECIMALS_UNIT", $_POST["MAIN_MAX_DECIMALS_UNIT"],'chaine',0,'',$conf->entity); |
||
74 | dolibarr_set_const($db, "MAIN_MAX_DECIMALS_TOT", $_POST["MAIN_MAX_DECIMALS_TOT"],'chaine',0,'',$conf->entity); |
||
75 | dolibarr_set_const($db, "MAIN_MAX_DECIMALS_SHOWN", $_POST["MAIN_MAX_DECIMALS_SHOWN"],'chaine',0,'',$conf->entity); |
||
76 | |||
77 | dolibarr_set_const($db, "MAIN_ROUNDING_RULE_TOT", $_POST["MAIN_ROUNDING_RULE_TOT"],'chaine',0,'',$conf->entity); |
||
78 | |||
79 | header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); |
||
80 | exit; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | |||
85 | |||
86 | /* |
||
87 | * View |
||
88 | */ |
||
89 | |||
90 | $form=new Form($db); |
||
91 | |||
92 | llxHeader(); |
||
93 | |||
94 | print load_fiche_titre($langs->trans("LimitsSetup"),'','title_setup'); |
||
95 | |||
96 | |||
97 | print $langs->trans("LimitsDesc")."<br>\n"; |
||
98 | print "<br>\n"; |
||
99 | |||
100 | if ($action == 'edit') |
||
101 | { |
||
102 | print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; |
||
103 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
||
104 | print '<input type="hidden" name="action" value="update">'; |
||
105 | |||
106 | clearstatcache(); |
||
107 | |||
108 | print '<table class="noborder" width="100%">'; |
||
109 | print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; |
||
110 | |||
111 | |||
112 | print '<tr class="oddeven"><td>'; |
||
113 | print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
114 | print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_UNIT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_UNIT . '"></td></tr>'; |
||
115 | |||
116 | |||
117 | print '<tr class="oddeven"><td>'; |
||
118 | print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
119 | print '</td><td><input class="flat" name="MAIN_MAX_DECIMALS_TOT" size="3" value="' . $conf->global->MAIN_MAX_DECIMALS_TOT . '"></td></tr>'; |
||
120 | |||
121 | |||
122 | 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>'; |
||
123 | |||
124 | |||
125 | print '<tr class="oddeven"><td>'; |
||
126 | print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
127 | print '</td><td><input class="flat" name="MAIN_ROUNDING_RULE_TOT" size="3" value="' . $conf->global->MAIN_ROUNDING_RULE_TOT . '"></td></tr>'; |
||
128 | |||
129 | print '</table>'; |
||
130 | |||
131 | print '<br><div class="center">'; |
||
132 | print '<input class="button" type="submit" value="'.$langs->trans("Save").'">'; |
||
133 | print '</div>'; |
||
134 | |||
135 | print '</form>'; |
||
136 | print '<br>'; |
||
137 | } |
||
138 | else |
||
139 | { |
||
140 | print '<table class="noborder" width="100%">'; |
||
141 | print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; |
||
142 | |||
143 | |||
144 | print '<tr class="oddeven"><td>'; |
||
145 | print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
146 | print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_UNIT.'</td></tr>'; |
||
147 | |||
148 | |||
149 | print '<tr class="oddeven"><td>'; |
||
150 | print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
151 | print '</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_TOT.'</td></tr>'; |
||
152 | |||
153 | |||
154 | print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td><td align="right">'.$conf->global->MAIN_MAX_DECIMALS_SHOWN.'</td></tr>'; |
||
155 | |||
156 | |||
157 | print '<tr class="oddeven"><td>'; |
||
158 | print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"),$langs->trans("ParameterActiveForNextInputOnly")); |
||
159 | print '</td><td align="right">'.$conf->global->MAIN_ROUNDING_RULE_TOT.'</td></tr>'; |
||
160 | |||
161 | print '</table>'; |
||
162 | |||
163 | print '<div class="tabsAction">'; |
||
164 | print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>'; |
||
165 | print '</div>'; |
||
166 | } |
||
167 | |||
168 | |||
169 | if (empty($mysoc->country_code)) |
||
170 | { |
||
171 | $langs->load("errors"); |
||
172 | $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete")); |
||
173 | //print '<br><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a>'; |
||
174 | print '<br><a href="' . BASE_URI . '?controller=admin&method=company&mainmenu=home">' . $warnpicto . ' ' . $langs->trans("WarningMandatorySetupNotComplete") . '</a>'; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
175 | } |
||
176 | else |
||
177 | { |
||
178 | |||
179 | // Show examples |
||
180 | print '<b>'.$langs->trans("ExamplesWithCurrentSetup").":</b><br>\n"; |
||
181 | |||
182 | // Always show vat rates with vat 0 |
||
183 | $s=2/7;$qty=1;$vat=0; |
||
184 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc); |
||
185 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
186 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
187 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
188 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
189 | |||
190 | $s=10/3;$qty=1;$vat=0; |
||
191 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0,0,$mysoc); |
||
192 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
193 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
194 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
195 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
196 | |||
197 | $s=10/3;$qty=2;$vat=0; |
||
198 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
199 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
200 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
201 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
202 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
203 | |||
204 | |||
205 | // Add vat rates examples specific to country |
||
206 | $vat_rates=array(); |
||
207 | |||
208 | $sql="SELECT taux as vat_rate"; |
||
209 | $sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; |
||
210 | $sql.=" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$mysoc->country_code."' AND t.taux <> 0"; |
||
211 | $sql.=" ORDER BY t.taux ASC"; |
||
212 | $resql=$db->query($sql); |
||
213 | if ($resql) |
||
214 | { |
||
215 | $num = $db->num_rows($resql); |
||
216 | if ($num) |
||
217 | { |
||
218 | for ($i = 0; $i < $num; $i++) |
||
219 | { |
||
220 | $obj = $db->fetch_object($resql); |
||
221 | $vat_rates[$i] = $obj->vat_rate; |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | else dol_print_error($db); |
||
226 | |||
227 | if (count($vat_rates)) |
||
228 | { |
||
229 | foreach($vat_rates as $vat) |
||
230 | { |
||
231 | for ($qty=1; $qty<=2; $qty++) |
||
232 | { |
||
233 | $s=10/3; |
||
234 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
235 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
236 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
237 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
238 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | else |
||
243 | { |
||
244 | // More examples if not specific vat rate found |
||
245 | // This example must be kept for test purpose with current value because value used (2/7, 10/3, and vat 0, 10) |
||
246 | // were calculated to show all possible cases of rounding. If we change this, examples becomes useless or show the same rounding rule. |
||
247 | |||
248 | $s=10/3;$qty=1;$vat=10; |
||
249 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
250 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
251 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
252 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
253 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
254 | |||
255 | $s=10/3;$qty=2;$vat=10; |
||
256 | $tmparray=calcul_price_total(1,$qty*price2num($s,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
257 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s,'MU'); |
||
258 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
259 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
260 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n"; |
||
261 | } |
||
262 | |||
263 | // Important: can debug rounding, to simulate the rounded total |
||
264 | /* |
||
265 | print '<br><b>'.$langs->trans("VATRoundedByLine").' ('.$langs->trans("DolibarrDefault").')</b><br>'; |
||
266 | |||
267 | foreach($vat_rates as $vat) |
||
268 | { |
||
269 | for ($qty=1; $qty<=2; $qty++) |
||
270 | { |
||
271 | $s1=10/3; |
||
272 | $s2=2/7; |
||
273 | |||
274 | // Round by line |
||
275 | $tmparray1=calcul_price_total(1,$qty*price2num($s1,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
276 | $tmparray2=calcul_price_total(1,$qty*price2num($s2,'MU'),0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
277 | $total_ht = $tmparray1[0] + $tmparray2[0]; |
||
278 | $total_tva = $tmparray1[1] + $tmparray2[1]; |
||
279 | $total_ttc = $tmparray1[2] + $tmparray2[2]; |
||
280 | |||
281 | print $langs->trans("UnitPriceOfProduct").": ".(price2num($s1,'MU') + price2num($s2,'MU')); |
||
282 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
283 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
284 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n"; |
||
285 | } |
||
286 | } |
||
287 | |||
288 | print '<br><b>'.$langs->trans("VATRoundedOnTotal").'</b><br>'; |
||
289 | |||
290 | foreach($vat_rates as $vat) |
||
291 | { |
||
292 | for ($qty=1; $qty<=2; $qty++) |
||
293 | { |
||
294 | $s1=10/3; |
||
295 | $s2=2/7; |
||
296 | |||
297 | // Global round |
||
298 | $subtotal_ht = (($qty*price2num($s1,'MU')) + ($qty*price2num($s2,'MU'))); |
||
299 | $tmparray3=calcul_price_total(1,$subtotal_ht,0,$vat,0,0,0,'HT',0, 0,$mysoc); |
||
300 | $total_ht = $tmparray3[0]; |
||
301 | $total_tva = $tmparray3[1]; |
||
302 | $total_ttc = $tmparray3[2]; |
||
303 | |||
304 | print $langs->trans("UnitPriceOfProduct").": ".price2num($s1+$s2,'MU'); |
||
305 | print " x ".$langs->trans("Quantity").": ".$qty; |
||
306 | print " - ".$langs->trans("VAT").": ".$vat.'%'; |
||
307 | print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."<br>\n"; |
||
308 | } |
||
309 | } |
||
310 | */ |
||
311 | } |
||
312 | |||
313 | // End of page |
||
314 | llxFooter(); |
||
315 | $db->close(); |
||
316 |