dolibarr 25.0.0-alpha
limits.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2022 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2018 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28// Load Dolibarr environment
29require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
40
41// Load translation files required by the page
42$langs->loadLangs(array('companies', 'products', 'admin'));
43
44$action = GETPOST('action', 'aZ09');
45$cancel = GETPOST('cancel', 'alpha');
46$currencycode = GETPOST('currencycode', 'alpha');
47if (empty($action)) {
48 $action = 'edit';
49}
50if ((isModEnabled('multicompany') || isModEnabled('multicurrency')) && getDolGlobalString('MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
51 // When MULTICURRENCY_USE_LIMIT_BY_CURRENCY is on, we use always a defined currency code instead of '' even for default.
52 $currencycode = (!empty($currencycode) ? $currencycode : getDolCurrency());
53}
54
55$mainmaxdecimalsunit = 'MAIN_MAX_DECIMALS_UNIT'.(!empty($currencycode) ? '_'.$currencycode : '');
56$mainmaxdecimalstot = 'MAIN_MAX_DECIMALS_TOT'.(!empty($currencycode) ? '_'.$currencycode : '');
57$mainmaxdecimalsshown = 'MAIN_MAX_DECIMALS_SHOWN'.(!empty($currencycode) ? '_'.$currencycode : '');
58$mainroundingruletot = 'MAIN_ROUNDING_RULE_TOT'.(!empty($currencycode) ? '_'.$currencycode : '');
59$mainmaxdecimalscurrencyrate = 'MAIN_MAX_DECIMALS_CURRENCY_RATE' . (!empty($currencycode) ? '_' . $currencycode : '');
60
61$valmainmaxdecimalsunit = GETPOSTINT($mainmaxdecimalsunit);
62$valmainmaxdecimalstot = GETPOSTINT($mainmaxdecimalstot);
63$valmainmaxdecimalsshown = GETPOST($mainmaxdecimalsshown, 'alpha'); // Can be 'x.y' but also 'x...'
64$valmainroundingruletot = price2num(GETPOST($mainroundingruletot, 'alphanohtml'), '', 2);
65$valmainmaxdecimalscurrencyrate = GETPOSTINT($mainmaxdecimalscurrencyrate);
66$valmainweightdefaultround = GETPOSTISSET('MAIN_WEIGHT_DEFAULT_ROUND') ? GETPOST('MAIN_WEIGHT_DEFAULT_ROUND', 'int') : getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1);
67$valmainvolumedefaultround = GETPOSTISSET('MAIN_VOLUME_DEFAULT_ROUND') ? GETPOST('MAIN_VOLUME_DEFAULT_ROUND', 'int') : getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1);
68
69if (!$user->admin) {
71}
72
73
74/*
75 * Actions
76 */
77
78if ($action == 'update' && !$cancel) {
79 $error = 0;
80 $MAXDEC = 8;
81 if ($valmainmaxdecimalsunit > $MAXDEC
82 || $valmainmaxdecimalstot > $MAXDEC
83 || $valmainmaxdecimalsshown > $MAXDEC) {
84 $error++;
85 setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden", $MAXDEC), null, 'errors');
86 $action = 'edit';
87 }
88
89 if ($valmainmaxdecimalsunit < 0
90 || $valmainmaxdecimalstot < 0
91 || $valmainmaxdecimalsshown < 0) {
92 $langs->load("errors");
93 $error++;
94 setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors');
95 $action = 'edit';
96 }
97
98 foreach (array('MAIN_WEIGHT_DEFAULT_ROUND' => $valmainweightdefaultround, 'MAIN_VOLUME_DEFAULT_ROUND' => $valmainvolumedefaultround) as $roundingparameter => $roundingvalue) {
99 if (filter_var($roundingvalue, FILTER_VALIDATE_INT, array('options' => array('min_range' => -1, 'max_range' => $MAXDEC))) === false) {
100 $langs->load('errors');
101 $error++;
102 setEventMessages($langs->trans('ErrorBadValueForParameter', $roundingvalue, $langs->transnoentitiesnoconv($roundingparameter)), null, 'errors');
103 $action = 'edit';
104 }
105 }
106
107 if ($valmainroundingruletot) {
108 if ((float) $valmainroundingruletot * pow(10, $valmainmaxdecimalstot) < 1) {
109 $langs->load("errors");
110 $error++;
111 setEventMessages($langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"), null, 'errors');
112 $action = 'edit';
113 }
114 }
115
116 if ((float) $valmainmaxdecimalsshown == 0) {
117 $langs->load("errors");
118 $error++;
119 setEventMessages($langs->trans("ErrorValueCantBeNull", dol_trunc(dol_string_nohtmltag($langs->transnoentitiesnoconv("MAIN_MAX_DECIMALS_SHOWN")), 40)), null, 'errors');
120 $action = 'edit';
121 }
122 if (! $error && ((float) $valmainmaxdecimalsshown < $valmainmaxdecimalsunit || (float) $valmainmaxdecimalsshown < $valmainmaxdecimalstot)) {
123 $langs->load("errors");
124 $error++;
125 setEventMessages($langs->trans("ErrorMaxDecimalsShownTooLowComparedToUnitOrTotal", $valmainmaxdecimalsshown, $valmainmaxdecimalsunit, $valmainmaxdecimalstot), null, 'errors');
126 $action = 'edit';
127 }
128
129 if ($valmainmaxdecimalscurrencyrate < 0) {
130 $valmainmaxdecimalscurrencyrate = 0;
131 }
132 if ($valmainmaxdecimalscurrencyrate > $MAXDEC) {
133 $valmainmaxdecimalscurrencyrate = $MAXDEC;
134 }
135
136 if (!$error) {
137 dolibarr_set_const($db, $mainmaxdecimalsunit, $valmainmaxdecimalsunit, 'chaine', 0, '', $conf->entity);
138 dolibarr_set_const($db, $mainmaxdecimalstot, $valmainmaxdecimalstot, 'chaine', 0, '', $conf->entity);
139 dolibarr_set_const($db, $mainmaxdecimalsshown, $valmainmaxdecimalsshown, 'chaine', 0, '', $conf->entity);
140
141 dolibarr_set_const($db, $mainroundingruletot, $valmainroundingruletot, 'chaine', 0, '', $conf->entity);
142 dolibarr_set_const($db, $mainmaxdecimalscurrencyrate, $valmainmaxdecimalscurrencyrate, 'chaine', 0, '', $conf->entity);
143 dolibarr_set_const($db, 'MAIN_WEIGHT_DEFAULT_ROUND', $valmainweightdefaultround, 'chaine', 0, '', $conf->entity);
144 dolibarr_set_const($db, 'MAIN_VOLUME_DEFAULT_ROUND', $valmainvolumedefaultround, 'chaine', 0, '', $conf->entity);
145
146 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
147
148 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup".(!empty($currencycode) ? '&currencycode='.$currencycode : ''));
149 exit;
150 }
151}
152
153
154/*
155 * View
156 */
157
158$form = new Form($db);
159
160$title = $langs->trans("LimitsSetup");
161$help_url = '';
162
163llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-limits');
164
165print load_fiche_titre($title, '', 'title_setup');
166
167$aCurrencies = array(getDolCurrency()); // Default currency always first position
168
169if ((isModEnabled('multicompany') || isModEnabled('multicurrency')) && getDolGlobalString('MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
170 require_once DOL_DOCUMENT_ROOT . '/core/lib/multicurrency.lib.php';
171
172 $sql = "SELECT rowid, code FROM " . MAIN_DB_PREFIX . "multicurrency";
173 $sql .= " WHERE entity = " . ((int) $conf->entity);
174 $sql .= " AND code <> '" . $db->escape(getDolCurrency()) . "'"; // Default currency always first position
175 $resql = $db->query($sql);
176 if ($resql) {
177 while ($obj = $db->fetch_object($resql)) {
178 $aCurrencies[] = $obj->code;
179 }
180 }
181
182 if (!empty($aCurrencies) && count($aCurrencies) > 1) {
183 $head = multicurrencyLimitPrepareHead($aCurrencies);
184
185 print dol_get_fiche_head($head, $currencycode, '', -1, '');
186 }
187}
188
189print '<span class="opacitymedium">'.$langs->trans("LimitsDesc")."</span><br>\n";
190print "<br>\n";
191
192if ($action == 'edit') {
193 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" spellcheck="false">';
194 print '<input type="hidden" name="token" value="' . newToken() . '">';
195 print '<input type="hidden" name="action" value="update">';
196 if ((isModEnabled('multicompany') || isModEnabled('multicurrency')) && getDolGlobalString('MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
197 print '<input type="hidden" name="currencycode" value="' . $currencycode . '">';
198 }
199
200 clearstatcache();
201
202 print '<table class="noborder centpercent">';
203 print '<tr class="liste_titre"><td>'.$langs->trans("Parameters").'</td><td></td></tr>';
204
205 print '<tr class="oddeven"><td>';
206 print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly"));
207 print '</td><td><input class="flat right" name="'.$mainmaxdecimalsunit.'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalsunit) ? GETPOST($mainmaxdecimalsunit) : getDolGlobalInt('MAIN_MAX_DECIMALS_UNIT', 0)).'"></td></tr>';
208
209 print '<tr class="oddeven"><td>';
210 print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
211 print '</td><td><input class="flat right" name="'.$mainmaxdecimalstot.'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalstot) ? GETPOST($mainmaxdecimalstot) : getDolGlobalInt('MAIN_MAX_DECIMALS_TOT', 0)).'"></td></tr>';
212
213 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td>';
214 print '<td><input class="flat right" name="'.$mainmaxdecimalsshown.'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalsshown) ? GETPOST($mainmaxdecimalsshown) : getDolGlobalString('MAIN_MAX_DECIMALS_SHOWN')).'"></td></tr>';
215
216 print '<tr class="oddeven"><td>';
217 print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
218 print '</td><td><input class="flat right" name="'.$mainroundingruletot.'" size="3" value="'.(GETPOSTISSET($mainroundingruletot) ? GETPOST($mainroundingruletot) : getDolGlobalString('MAIN_ROUNDING_RULE_TOT')).'"></td></tr>';
219
220 print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->trans('MAIN_MAX_DECIMALS_CURRENCY_RATE'), $langs->trans('MAIN_MAX_DECIMALS_CURRENCY_RATE_Help')) . '</td>';
221 print '<td><input class="flat right" name="' . $mainmaxdecimalscurrencyrate . '" size="3" value="' . (GETPOSTISSET($mainmaxdecimalscurrencyrate) ? GETPOST($mainmaxdecimalscurrencyrate) : getDolGlobalInt($mainmaxdecimalscurrencyrate, 8)) . '"></td></tr>';
222
223 print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->trans('MAIN_WEIGHT_DEFAULT_ROUND'), $langs->trans('WeightVolumeRoundingHelp')) . '</td>';
224 print '<td><input class="flat right" name="MAIN_WEIGHT_DEFAULT_ROUND" size="3" value="' . (GETPOSTISSET('MAIN_WEIGHT_DEFAULT_ROUND') ? GETPOSTINT('MAIN_WEIGHT_DEFAULT_ROUND') : getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1)) . '"></td></tr>';
225
226 print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->trans('MAIN_VOLUME_DEFAULT_ROUND'), $langs->trans('WeightVolumeRoundingHelp')) . '</td>';
227 print '<td><input class="flat right" name="MAIN_VOLUME_DEFAULT_ROUND" size="3" value="' . (GETPOSTISSET('MAIN_VOLUME_DEFAULT_ROUND') ? GETPOSTINT('MAIN_VOLUME_DEFAULT_ROUND') : getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1)) . '"></td></tr>';
228
229 print '</table>';
230
231 print '<div class="center">';
232 print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
233 /*
234 print ' &nbsp; ';
235 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
236 */
237 print '</div>';
238 print '<br>';
239
240 print '</form>';
241 print '<br>';
242} else {
243 print '<div class="div-table-responsive-no-min">';
244 print '<table class="noborder centpercent">';
245 print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td class="right"></td></tr>';
246
247 print '<tr class="oddeven"><td>';
248 print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly"));
249 print '</td><td align="right">'.(isset($conf->global->$mainmaxdecimalsunit) ? $conf->global->$mainmaxdecimalsunit : getDolGlobalString("MAIN_MAX_DECIMALS_UNIT")).'</td></tr>';
250
251 print '<tr class="oddeven"><td>';
252 print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
253 print '</td><td align="right">'.(isset($conf->global->$mainmaxdecimalstot) ? $conf->global->$mainmaxdecimalstot : getDolGlobalString("MAIN_MAX_DECIMALS_TOT")).'</td></tr>';
254
255 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").'</td>';
256 print '<td align="right">'.(isset($conf->global->$mainmaxdecimalsshown) ? $conf->global->$mainmaxdecimalsshown : getDolGlobalString("MAIN_MAX_DECIMALS_SHOWN")).'</td></tr>';
257
258 print '<tr class="oddeven"><td>';
259 print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"), $langs->trans("ParameterActiveForNextInputOnly"));
260 print '</td><td align="right">'.(isset($conf->global->$mainroundingruletot) ? $conf->global->$mainroundingruletot : getDolGlobalString('MAIN_ROUNDING_RULE_TOT')).'</td></tr>';
261
262 print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->trans('MAIN_WEIGHT_DEFAULT_ROUND'), $langs->trans('WeightVolumeRoundingHelp')) . '</td>';
263 print '<td class="right">' . getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1) . '</td></tr>';
264
265 print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->trans('MAIN_VOLUME_DEFAULT_ROUND'), $langs->trans('WeightVolumeRoundingHelp')) . '</td>';
266 print '<td class="right">' . getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1) . '</td></tr>';
267
268 print '</table>';
269 print '</div>';
270
271 print '<div class="tabsAction">';
272 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().(!empty($currencycode) ? '&currencycode='.$currencycode : '').'">'.$langs->trans("Modify").'</a>';
273 print '</div>';
274}
275
276if ((isModEnabled('multicompany') || isModEnabled('multicurrency')) && getDolGlobalString('MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
277 if (!empty($aCurrencies) && count($aCurrencies) > 1) {
278 print dol_get_fiche_end();
279 }
280}
281
282if (empty($mysoc->country_code)) {
283 $langs->load("errors");
284 $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
285 print '<br><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a>';
286} else {
287 // Show examples
288 print load_fiche_titre($langs->trans("ExamplesWithCurrentSetup"), '', '');
289
290 print '<div class="small">';
291
292 print '<span class="opacitymedium">'.$langs->trans("NumberFormatForATotalPrice", '1234.56789').':</span> '.price(price2num(1234.56789, 'MT'), 0, $langs, 1, -1, -1, $currencycode)."<br>\n";
293
294 // Always show vat rates with vat 0
295 $s = 2 / 3;
296 $qty = 1;
297 $vat = 0;
298 $tmparray = calcul_price_total(1, $qty * (float) price2num($s, 'MU'), 0, $vat, 0, 0, 0, 'HT', 0, 0, $mysoc);
299 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
300 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
301 print ' - <span class="opacitymedium">'.$langs->trans("VAT").":</span> ".$vat.'%';
302 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
303
304 $s = 10 / 3;
305 $qty = 1;
306 $vat = 0;
307 $tmparray = calcul_price_total(1, $qty * (float) price2num($s, 'MU'), 0, $vat, 0, 0, 0, 'HT', 0, 0, $mysoc);
308 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
309 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
310 print ' - <span class="opacitymedium">'.$langs->trans("VAT").":</span> ".$vat.'%';
311 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
312
313 $s = 10 / 3;
314 $qty = 2;
315 $vat = 0;
316 $tmparray = calcul_price_total(1, $qty * (float) price2num($s, 'MU'), 0, $vat, 0, 0, 0, 'HT', 0, 0, $mysoc);
317 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
318 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
319 print ' - <span class="opacitymedium">'.$langs->trans("VAT").":</span> ".$vat.'%';
320 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
321
322 // Add vat rates examples specific to country
323 $vat_rates = array();
324
325 $sql = "SELECT taux as vat_rate, t.code as vat_code, t.localtax1 as localtax_rate1, t.localtax2 as localtax_rate2";
326 $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
327 $sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($mysoc->country_code)."' AND (t.taux <> 0 OR t.localtax1 <> '0' OR t.localtax2 <> '0')";
328 $sql .= " AND t.entity IN (".getEntity('c_tva').")";
329 $sql .= " ORDER BY t.taux ASC";
330 $resql = $db->query($sql);
331 if ($resql) {
332 $num = $db->num_rows($resql);
333 if ($num) {
334 for ($i = 0; $i < $num; $i++) {
335 $obj = $db->fetch_object($resql);
336 $vat_rates[] = array('vat_rate' => $obj->vat_rate, 'code' => $obj->vat_code, 'localtax_rate1' => $obj->localtax_rate1, 'locltax_rate2' => $obj->localtax_rate2);
337 }
338 }
339 } else {
340 dol_print_error($db);
341 }
342
343 if (count($vat_rates)) {
344 foreach ($vat_rates as $vatarray) {
345 $vat = $vatarray['vat_rate'];
346 for ($qty = 1; $qty <= 2; $qty++) {
347 $vattxt = $vat.($vatarray['code'] ? ' ('.$vatarray['code'].')' : '');
348
349 $localtax_array = getLocalTaxesFromRate($vattxt, 0, $mysoc, $mysoc);
350
351 $s = 10 / 3;
352 $tmparray = calcul_price_total($qty, (float) price2num($s, 'MU'), 0, $vat, -1, -1, 0, 'HT', 0, 0, $mysoc, $localtax_array);
353 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
354 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
355 print ' - <span class="opacitymedium">'.$langs->trans("VAT").':</span> '.$vat.'%';
356 print($vatarray['code'] ? ' ('.$vatarray['code'].')' : '');
357 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ";
358 print $tmparray[0].' / '.$tmparray[1].($tmparray[9] ? '+'.$tmparray[9] : '').($tmparray[10] ? '+'.$tmparray[10] : '').' / '.$tmparray[2];
359 print "<br>\n";
360 }
361
362 if (getDolGlobalString('MAIN_ADD_MORE_EXAMPLE_IN_ACCURANCY_SETUP')) {
363 $qty = 1.234;
364 $vattxt = $vat.($vatarray['code'] ? ' ('.$vatarray['code'].')' : '');
365
366 $localtax_array = getLocalTaxesFromRate($vattxt, 0, $mysoc, $mysoc);
367
368 $s = 10 / 3;
369 $tmparray = calcul_price_total($qty, (float) price2num($s, 'MU'), 0, $vat, -1, -1, 0, 'HT', 0, 0, $mysoc, $localtax_array);
370 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
371 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
372 print ' - <span class="opacitymedium">'.$langs->trans("VAT").':</span> '.$vat.'%';
373 print($vatarray['code'] ? ' ('.$vatarray['code'].')' : '');
374 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ";
375 print $tmparray[0].' / '.$tmparray[1].($tmparray[9] ? '+'.$tmparray[9] : '').($tmparray[10] ? '+'.$tmparray[10] : '').' / '.$tmparray[2];
376 print "<br>\n";
377 }
378 }
379 } else {
380 // More examples if not specific vat rate found
381 // This example must be kept for test purpose with current value because value used (2/7, 10/3, and vat 0, 10)
382 // were calculated to show all possible cases of rounding. If we change this, examples becomes useless or show the same rounding rule.
383
384 $localtax_array = array();
385
386 $s = 10 / 3;
387 $qty = 1;
388 $vat = 10;
389 $tmparray = calcul_price_total($qty, (float) price2num($s, 'MU'), 0, $vat, -1, -1, 0, 'HT', 0, 0, $mysoc, $localtax_array);
390 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
391 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
392 print ' - <span class="opacitymedium">'.$langs->trans("VAT").":</span> ".$vat.'%';
393 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
394
395 $s = 10 / 3;
396 $qty = 2;
397 $vat = 10;
398 $tmparray = calcul_price_total($qty, (float) price2num($s, 'MU'), 0, $vat, -1, -1, 0, 'HT', 0, 0, $mysoc, $localtax_array);
399 print '<span class="opacitymedium">'.$langs->trans("UnitPriceOfProduct").":</span> ".price2num($s, 'MU');
400 print ' x <span class="opacitymedium">'.$langs->trans("Quantity").":</span> ".$qty;
401 print ' - <span class="opacitymedium">'.$langs->trans("VAT").":</span> ".$vat.'%';
402 print ' &nbsp; -> &nbsp; <span class="opacitymedium">'.$langs->trans("TotalPriceAfterRounding").":</span> ".$tmparray[0].' / '.$tmparray[1].' / '.$tmparray[2]."<br>\n";
403 }
404
405 print '</div>';
406}
407
408// End of page
409llxFooter();
410$db->close();
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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
global $mysoc
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
multicurrencyLimitPrepareHead($aCurrencies)
Prepare array with list of currency tabs.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:90
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.