27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
32$langs->loadLangs(array(
'companies',
'products',
'admin'));
34$action =
GETPOST(
'action',
'aZ09');
35$cancel =
GETPOST(
'cancel',
'aZ09');
36$currencycode =
GETPOST(
'currencycode',
'alpha');
38if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
40 $currencycode = (!empty($currencycode) ? $currencycode : $conf->currency);
43$mainmaxdecimalsunit =
'MAIN_MAX_DECIMALS_UNIT'.(!empty($currencycode) ?
'_'.$currencycode :
'');
44$mainmaxdecimalstot =
'MAIN_MAX_DECIMALS_TOT'.(!empty($currencycode) ?
'_'.$currencycode :
'');
45$mainmaxdecimalsshown =
'MAIN_MAX_DECIMALS_SHOWN'.(!empty($currencycode) ?
'_'.$currencycode :
'');
46$mainroundingruletot =
'MAIN_ROUNDING_RULE_TOT'.(!empty($currencycode) ?
'_'.$currencycode :
'');
48$valmainmaxdecimalsunit =
GETPOST($mainmaxdecimalsunit,
'int');
49$valmainmaxdecimalstot =
GETPOST($mainmaxdecimalstot,
'int');
50$valmainmaxdecimalsshown =
GETPOST($mainmaxdecimalsshown,
'alpha');
51$valmainroundingruletot =
price2num(
GETPOST($mainroundingruletot,
'alphanohtml'),
'', 2);
62if ($action ==
'update' && !$cancel) {
65 if ($valmainmaxdecimalsunit > $MAXDEC
66 || $valmainmaxdecimalstot > $MAXDEC
67 || $valmainmaxdecimalsshown > $MAXDEC) {
69 setEventMessages($langs->trans(
"ErrorDecimalLargerThanAreForbidden", $MAXDEC),
null,
'errors');
73 if ($valmainmaxdecimalsunit < 0
74 || $valmainmaxdecimalstot < 0
75 || $valmainmaxdecimalsshown < 0) {
76 $langs->load(
"errors");
78 setEventMessages($langs->trans(
"ErrorNegativeValueNotAllowed"),
null,
'errors');
82 if ($valmainroundingruletot) {
83 if ($valmainroundingruletot * pow(10, $valmainmaxdecimalstot) < 1) {
84 $langs->load(
"errors");
86 setEventMessages($langs->trans(
"ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"),
null,
'errors');
91 if ((
float) $valmainmaxdecimalsshown == 0) {
92 $langs->load(
"errors");
97 if (! $error && ((
float) $valmainmaxdecimalsshown < $valmainmaxdecimalsunit || (
float) $valmainmaxdecimalsshown < $valmainmaxdecimalstot)) {
98 $langs->load(
"errors");
105 dolibarr_set_const($db, $mainmaxdecimalsunit, $valmainmaxdecimalsunit,
'chaine', 0,
'', $conf->entity);
106 dolibarr_set_const($db, $mainmaxdecimalstot, $valmainmaxdecimalstot,
'chaine', 0,
'', $conf->entity);
107 dolibarr_set_const($db, $mainmaxdecimalsshown, $valmainmaxdecimalsshown,
'chaine', 0,
'', $conf->entity);
109 dolibarr_set_const($db, $mainroundingruletot, $valmainroundingruletot,
'chaine', 0,
'', $conf->entity);
111 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?mainmenu=home&leftmenu=setup".(!empty($currencycode) ?
'¤cycode='.$currencycode :
''));
121$form =
new Form($db);
123$title = $langs->trans(
"LimitsSetup");
130$aCurrencies = array($conf->currency);
132if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
133 require_once DOL_DOCUMENT_ROOT .
'/core/lib/multicurrency.lib.php';
135 $sql =
"SELECT rowid, code FROM " . MAIN_DB_PREFIX .
"multicurrency";
136 $sql .=
" WHERE entity = " . ((int) $conf->entity);
137 $sql .=
" AND code <> '" . $db->escape($conf->currency) .
"'";
138 $resql = $db->query($sql);
140 while ($obj = $db->fetch_object($resql)) {
141 $aCurrencies[] = $obj->code;
145 if (!empty($aCurrencies) && count($aCurrencies) > 1) {
152print
'<span class="opacitymedium">'.$langs->trans(
"LimitsDesc").
"</span><br>\n";
155if ($action ==
'edit') {
156 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
157 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
158 print
'<input type="hidden" name="action" value="update">';
159 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
160 print
'<input type="hidden" name="currencycode" value="' . $currencycode .
'">';
165 print
'<table class="noborder centpercent">';
166 print
'<tr class="liste_titre"><td>'.$langs->trans(
"Parameters").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
168 print
'<tr class="oddeven"><td>';
169 print $form->textwithpicto($langs->trans(
"MAIN_MAX_DECIMALS_UNIT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
170 print
'</td><td><input class="flat right" name="'.$mainmaxdecimalsunit.
'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalsunit) ?
GETPOST($mainmaxdecimalsunit) :
getDolGlobalInt(
'MAIN_MAX_DECIMALS_UNIT', 0)).
'"></td></tr>';
172 print
'<tr class="oddeven"><td>';
173 print $form->textwithpicto($langs->trans(
"MAIN_MAX_DECIMALS_TOT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
174 print
'</td><td><input class="flat right" name="'.$mainmaxdecimalstot.
'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalstot) ?
GETPOST($mainmaxdecimalstot) :
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)).
'"></td></tr>';
176 print
'<tr class="oddeven"><td>'.$langs->trans(
"MAIN_MAX_DECIMALS_SHOWN").
'</td>';
177 print
'<td><input class="flat right" name="'.$mainmaxdecimalsshown.
'" size="3" value="'.(GETPOSTISSET($mainmaxdecimalsshown) ?
GETPOST($mainmaxdecimalsshown) :
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN')).
'"></td></tr>';
179 print
'<tr class="oddeven"><td>';
180 print $form->textwithpicto($langs->trans(
"MAIN_ROUNDING_RULE_TOT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
181 print
'</td><td><input class="flat right" name="'.$mainroundingruletot.
'" size="3" value="'.(GETPOSTISSET($mainroundingruletot) ?
GETPOST($mainroundingruletot) :
getDolGlobalString(
'MAIN_ROUNDING_RULE_TOT')).
'"></td></tr>';
185 print
'<div class="center">';
186 print
'<input class="button button-save" type="submit" name="save" value="'.$langs->trans(
"Save").
'">';
188 print
'<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
195 print
'<div class="div-table-responsive-no-min">';
196 print
'<table class="noborder centpercent">';
197 print
'<tr class="liste_titre"><td>'.$langs->trans(
"Parameter").
'</td><td class="right">'.$langs->trans(
"Value").
'</td></tr>';
199 print
'<tr class="oddeven"><td>';
200 print $form->textwithpicto($langs->trans(
"MAIN_MAX_DECIMALS_UNIT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
201 print
'</td><td align="right">'.(isset($conf->global->$mainmaxdecimalsunit) ? $conf->global->$mainmaxdecimalsunit : $conf->global->MAIN_MAX_DECIMALS_UNIT).
'</td></tr>';
203 print
'<tr class="oddeven"><td>';
204 print $form->textwithpicto($langs->trans(
"MAIN_MAX_DECIMALS_TOT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
205 print
'</td><td align="right">'.(isset($conf->global->$mainmaxdecimalstot) ? $conf->global->$mainmaxdecimalstot : $conf->global->MAIN_MAX_DECIMALS_TOT).
'</td></tr>';
207 print
'<tr class="oddeven"><td>'.$langs->trans(
"MAIN_MAX_DECIMALS_SHOWN").
'</td>';
208 print
'<td align="right">'.(isset($conf->global->$mainmaxdecimalsshown) ? $conf->global->$mainmaxdecimalsshown : $conf->global->MAIN_MAX_DECIMALS_SHOWN).
'</td></tr>';
210 print
'<tr class="oddeven"><td>';
211 print $form->textwithpicto($langs->trans(
"MAIN_ROUNDING_RULE_TOT"), $langs->trans(
"ParameterActiveForNextInputOnly"));
212 print
'</td><td align="right">'.(isset($conf->global->$mainroundingruletot) ? $conf->global->$mainroundingruletot : (
getDolGlobalString(
'MAIN_ROUNDING_RULE_TOT') ? $conf->global->MAIN_ROUNDING_RULE_TOT :
'')).
'</td></tr>';
217 print
'<div class="tabsAction">';
218 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().(!empty($currencycode) ?
'¤cycode='.$currencycode :
'').
'">'.$langs->trans(
"Modify").
'</a>';
222if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
223 if (!empty($aCurrencies) && count($aCurrencies) > 1) {
228if (empty($mysoc->country_code)) {
229 $langs->load(
"errors");
230 $warnpicto =
img_warning($langs->trans(
"WarningMandatorySetupNotComplete"));
231 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
236 print
'<span class="opacitymedium">'.$langs->trans(
"Format").
':</span> '.
price(
price2num(1234.56789,
'MT'), 0, $langs, 1, -1, -1, $currencycode).
"<br>\n";
242 $tmparray =
calcul_price_total(1, $qty *
price2num($s,
'MU'), 0, $vat, 0, 0, 0,
'HT', 0, 0, $mysoc);
243 print
'<span class="opacitymedium">'.$langs->trans(
"UnitPriceOfProduct").
":</span> ".
price2num($s,
'MU');
244 print
' x <span class="opacitymedium">'.$langs->trans(
"Quantity").
":</span> ".$qty;
245 print
' - <span class="opacitymedium">'.$langs->trans(
"VAT").
":</span> ".$vat.
'%';
246 print
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ".$tmparray[0].
' / '.$tmparray[1].
' / '.$tmparray[2].
"<br>\n";
251 $tmparray =
calcul_price_total(1, $qty *
price2num($s,
'MU'), 0, $vat, 0, 0, 0,
'HT', 0, 0, $mysoc);
252 print
'<span class="opacitymedium">'.$langs->trans(
"UnitPriceOfProduct").
":</span> ".
price2num($s,
'MU');
253 print
' x <span class="opacitymedium">'.$langs->trans(
"Quantity").
":</span> ".$qty;
254 print
' - <span class="opacitymedium">'.$langs->trans(
"VAT").
":</span> ".$vat.
'%';
255 print
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ".$tmparray[0].
' / '.$tmparray[1].
' / '.$tmparray[2].
"<br>\n";
260 $tmparray =
calcul_price_total(1, $qty *
price2num($s,
'MU'), 0, $vat, 0, 0, 0,
'HT', 0, 0, $mysoc);
261 print
'<span class="opacitymedium">'.$langs->trans(
"UnitPriceOfProduct").
":</span> ".
price2num($s,
'MU');
262 print
' x <span class="opacitymedium">'.$langs->trans(
"Quantity").
":</span> ".$qty;
263 print
' - <span class="opacitymedium">'.$langs->trans(
"VAT").
":</span> ".$vat.
'%';
264 print
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ".$tmparray[0].
' / '.$tmparray[1].
' / '.$tmparray[2].
"<br>\n";
267 $vat_rates = array();
269 $sql =
"SELECT taux as vat_rate, t.code as vat_code, t.localtax1 as localtax_rate1, t.localtax2 as localtax_rate2";
270 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
271 $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')";
272 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
273 $sql .=
" ORDER BY t.taux ASC";
274 $resql = $db->query($sql);
276 $num = $db->num_rows($resql);
278 for ($i = 0; $i < $num; $i++) {
279 $obj = $db->fetch_object($resql);
280 $vat_rates[] = array(
'vat_rate'=>$obj->vat_rate,
'code'=>$obj->vat_code,
'localtax_rate1'=>$obj->localtax_rate1,
'locltax_rate2'=>$obj->localtax_rate2);
287 if (count($vat_rates)) {
288 foreach ($vat_rates as $vatarray) {
289 $vat = $vatarray[
'vat_rate'];
290 for ($qty = 1; $qty <= 2; $qty++) {
291 $vattxt = $vat.($vatarray[
'code'] ?
' ('.$vatarray[
'code'].
')' :
'');
296 $tmparray =
calcul_price_total($qty,
price2num($s,
'MU'), 0, $vat, -1, -1, 0,
'HT', 0, 0, $mysoc, $localtax_array);
297 print
'<span class="opacitymedium">'.$langs->trans(
"UnitPriceOfProduct").
":</span> ".
price2num($s,
'MU');
298 print
' x <span class="opacitymedium">'.$langs->trans(
"Quantity").
":</span> ".$qty;
299 print
' - <span class="opacitymedium">'.$langs->trans(
"VAT").
':</span> '.$vat.
'%';
300 print($vatarray[
'code'] ?
' ('.$vatarray[
'code'].
')' :
'');
301 print
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ";
302 print $tmparray[0].
' / '.$tmparray[1].($tmparray[9] ?
'+'.$tmparray[9] :
'').($tmparray[10] ?
'+'.$tmparray[10] :
'').
' / '.$tmparray[2];
311 $localtax_array = array();
316 $tmparray =
calcul_price_total($qty,
price2num($s,
'MU'), 0, $vat, -1, -1, 0,
'HT', 0, 0, $mysoc, $localtax_array);
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
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ".$tmparray[0].
' / '.$tmparray[1].
' / '.$tmparray[2].
"<br>\n";
325 $tmparray =
calcul_price_total($qty,
price2num($s,
'MU'), 0, $vat, -1, -1, 0,
'HT', 0, 0, $mysoc, $localtax_array);
326 print
'<span class="opacitymedium">'.$langs->trans(
"UnitPriceOfProduct").
":</span> ".
price2num($s,
'MU');
327 print
' x <span class="opacitymedium">'.$langs->trans(
"Quantity").
":</span> ".$qty;
328 print
' - <span class="opacitymedium">'.$langs->trans(
"VAT").
":</span> ".$vat.
'%';
329 print
' -> <span class="opacitymedium">'.$langs->trans(
"TotalPriceAfterRounding").
":</span> ".$tmparray[0].
' / '.$tmparray[1].
' / '.$tmparray[2].
"<br>\n";
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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
multicurrencyLimitPrepareHead($aCurrencies)
Prepare array with list of currency tabs.
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, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.