dolibarr 21.0.0-alpha
multicurrency_rate.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5 * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2013-2019 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
9 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
10 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11 * Copyright (C) 2013 Adolfo segura <adolfo.segura@gmail.com>
12 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
13 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2023 Lenin Rivas <lenin.rivas777@gmail.com>
15 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
38// Load Dolibarr environment
39require '../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/multicurrency.lib.php';
42
43
44// Load translation files required by the page
45$langs->loadLangs(array('admin', 'multicurrency'));
46
47// Get Parameters
48$action = GETPOST('action', 'alpha');
49$massaction = GETPOST('massaction', 'alpha');
50$show_files = GETPOSTINT('show_files');
51$confirm = GETPOST('confirm', 'alpha');
52$toselect = GETPOST('toselect', 'array');
53$id_rate_selected = GETPOSTINT('id_rate');
54$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
55$search_date_sync = dol_mktime(0, 0, 0, GETPOSTINT('search_date_syncmonth'), GETPOSTINT('search_date_syncday'), GETPOSTINT('search_date_syncyear'));
56$search_date_sync_end = dol_mktime(0, 0, 0, GETPOSTINT('search_date_sync_endmonth'), GETPOSTINT('search_date_sync_endday'), GETPOSTINT('search_date_sync_endyear'));
57$search_rate = GETPOST('search_rate', 'alpha');
58$search_rate_indirect = GETPOST('search_rate_indirect', 'alpha');
59$search_code = GETPOST('search_code', 'alpha');
60$multicurrency_code = GETPOST('multicurrency_code', 'alpha');
61$dateinput = dol_mktime(0, 0, 0, GETPOSTINT('dateinputmonth'), GETPOSTINT('dateinputday'), GETPOSTINT('dateinputyear'));
62$rateinput = (float) price2num(GETPOST('rateinput', 'alpha'));
63$rateindirectinput = (float) price2num(GETPOST('rateinidirectinput', 'alpha'));
64$optioncss = GETPOST('optioncss', 'alpha');
65$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
66$page = GETPOSTINT("page");
67if (empty($page) || $page == -1) {
68 $page = 0;
69} // If $page is not defined, or '' or -1
70$offset = $limit * $page;
71$pageprev = $page - 1;
72$pagenext = $page + 1;
73$sortfield = GETPOST('sortfield', 'aZ09comma');
74$sortorder = GETPOST('sortorder', 'aZ09comma');
75if (!$sortfield) {
76 $sortfield = "cr.date_sync";
77}
78if (!$sortorder) {
79 $sortorder = "DESC";
80}
81$type = '';
82$texte = '';
83$newcardbutton = '';
84
85// Initialize a technical objects
86$object = new CurrencyRate($db);
87$form = new Form($db);
88$extrafields = new ExtraFields($db);
89
90
91// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
92$hookmanager->initHooks(array('EditorRatelist', 'globallist'));
93
94if (empty($action)) {
95 $action = 'list';
96}
97
98// List of fields to search into when doing a "search in all"
99$fieldstosearchall = array(
100 'cr.date_sync' => "date_sync",
101 'cr.rate' => "rate",
102 'cr.rate_indirect' => "rate_indirect",
103 'm.code' => "code",
104);
105
106// Definition of fields for lists
107$arrayfields = array(
108 'cr.date_sync' => array('label' => 'Date', 'checked' => 1),
109 'cr.rate' => array('label' => 'Rate', 'checked' => 1),
110 'cr.rate_indirect' => array('label' => 'RateIndirect', 'checked' => 0, 'enabled' => (!getDolGlobalString('MULTICURRENCY_USE_RATE_INDIRECT') ? 0 : 1)),
111 'm.code' => array('label' => 'Code', 'checked' => 1),
112);
113
114
115$object->fields = dol_sort_array($object->fields, 'position');
116$arrayfields = dol_sort_array($arrayfields, 'position');
117'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
118
119// Access control
120// TODO Open this page to a given permission so a sale representative can modify change rates. Permission should be added into module multicurrency.
121// One permission to read rates (history) and one to add/edit rates.
122if (!$user->admin || !isModEnabled("multicurrency")) {
124}
125
126$error = 0;
127
128
129/*
130 * Actions
131 */
132
133if ($action == "create" && $user->hasRight('multicurrency', 'currency', 'read')) {
134 if (empty($multicurrency_code) || $multicurrency_code == '-1') {
135 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Currency")), null, "errors");
136 $error++;
137 }
138 if ($rateinput == 0) {
139 setEventMessages($langs->trans('NoEmptyRate'), null, "errors");
140 $error++;
141 } elseif (empty($rateinput)) {
142 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Rate")), null, "errors");
143 $error++;
144 }
145
146 if (!$error) {
147 $currencyRate_static = new CurrencyRate($db);
148 $currency_static = new MultiCurrency($db);
149 $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
150
151 $currencyRate_static->fk_multicurrency = $fk_currency;
152 $currencyRate_static->entity = $conf->entity;
153 $currencyRate_static->date_sync = $dateinput;
154 $currencyRate_static->rate = $rateinput;
155 $currencyRate_static->rate_indirect = $rateindirectinput;
156
157 $result = $currencyRate_static->create($user, intval($fk_currency));
158 if ($result > 0) {
159 setEventMessages($langs->trans('successRateCreate', $multicurrency_code), null);
160 } else {
161 dol_syslog("currencyRate:createRate", LOG_WARNING);
162 setEventMessages($currencyRate_static->error, $currencyRate_static->errors, 'errors');
163 }
164 }
165}
166
167if ($action == 'update' && $user->hasRight('multicurrency', 'currency', 'read')) {
168 $currencyRate = new CurrencyRate($db);
169 $result = $currencyRate->fetch($id_rate_selected);
170 if ($result > 0) {
171 $currency_static = new MultiCurrency($db);
172 $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
173 $currencyRate->date_sync = $dateinput;
174 $currencyRate->fk_multicurrency = $fk_currency;
175 $currencyRate->rate = $rateinput;
176 $res = $currencyRate->update($user);
177 if ($res) {
178 setEventMessages($langs->trans('successUpdateRate'), null);
179 } else {
180 setEventMessages($currencyRate->error, $currencyRate->errors, "errors");
181 }
182 } else {
183 setEventMessages($langs->trans('Error'), null, "warnings");
184 }
185}
186
187if ($action == "deleteRate" && $user->hasRight('multicurrency', 'currency', 'read')) {
188 $current_rate = new CurrencyRate($db);
189 $current_rate->fetch((int) $id_rate_selected);
190
191 if ($current_rate) {
192 $current_currency = new MultiCurrency($db);
193 $current_currency->fetch($current_rate->fk_multicurrency);
194 if ($current_currency) {
195 $delayedhtmlcontent = $form->formconfirm(
196 $_SERVER["PHP_SELF"].'?id_rate='.$id_rate_selected,
197 $langs->trans('DeleteLineRate'),
198 $langs->trans('ConfirmDeleteLineRate', $current_rate->rate, $current_currency->name, $current_rate->date_sync),
199 'confirm_delete',
200 '',
201 0,
202 1
203 );
204 } else {
205 dol_syslog("Multicurrency::fetch", LOG_WARNING);
206 }
207 } else {
208 setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings");
209 }
210}
211
212if ($action == "confirm_delete" && $user->hasRight('multicurrency', 'currency', 'read')) {
213 $current_rate = new CurrencyRate($db);
214 $current_rate->fetch((int) $id_rate_selected);
215 if ($current_rate) {
216 $result = $current_rate->delete($user);
217 if ($result) {
218 setEventMessages($langs->trans('successRateDelete'), null);
219 } else {
220 setEventMessages($current_rate->error, $current_rate->errors, 'errors');
221 }
222 } else {
223 setEventMessages($langs->trans('NoCurrencyRateSelected'), null, "warnings");
224 dol_syslog($langs->trans('NoCurrencyRateSelected'), LOG_WARNING);
225 }
226}
227
228
229if (GETPOST('cancel', 'alpha')) {
230 $action = 'list';
231 $massaction = '';
232}
233if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
234 $massaction = '';
235}
236
237$parameters = array();
238$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
239if ($reshook < 0) {
240 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
241}
242if (empty($reshook)) {
243 // Selection of new fields
244 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
245
246 // Purge search criteria
247 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
248 $sall = "";
249 $search_date_sync = "";
250 $search_date_sync_end = "";
251 $search_rate = "";
252 $search_code = "";
253 $search_array_options = array();
254 }
255
256 // Mass actions
257 $objectclass = "CurrencyRate";
258 $uploaddir = $conf->multicurrency->multidir_output; // define only because core/actions_massactions.inc.php want it
259 $permissiontoread = $user->admin;
260 $permissiontodelete = $user->admin;
261 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
262}
263
264
265/*
266 * View
267 */
268
269$form = new Form($db);
270
271$title = $langs->trans("CurrencyRate");
272$page_name = "MultiCurrencySetup";
273$help_url = '';
274
275llxHeader('', $title, $help_url, '');
276// Subheader
277$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
278print load_fiche_titre($langs->trans($page_name), $linkback);
279
280// Configuration header
282print dol_get_fiche_head($head, 'ratelist', $langs->trans("ModuleSetup"), -1, "multicurrency");
283
284// ACTION
285
286if (!in_array($action, array("updateRate", "deleteRate"))) {
287 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
288 print '<input type="hidden" name="token" value="'.newToken().'">';
289
290 print '<div class="div-table-responsive-no-min">';
291 print '<table class="noborder centpercent"><tr>';
292
293 print ' <td>'.$langs->trans('Date').'</td>';
294 print ' <td>';
295 print $form->selectDate($dateinput, 'dateinput', 0, 0, 1, '', 1, 1);
296 print '</td>';
297
298 print '<td> '.$langs->trans('Currency').'</td>';
299 print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 1, " code != '".$db->escape($conf->currency)."'", true).'</td>';
300
301 print ' <td>'.$langs->trans('Rate').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
302 print ' <td><input type="text" min="0" step="any" class="maxwidth75" id="rateinput" name="rateinput" value="'.dol_escape_htmltag((string) $rateinput).'"></td>';
303
304 if (getDolGlobalString('MULTICURRENCY_USE_RATE_INDIRECT')) {
305 print ' <td>'.$langs->trans('RateIndirect').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
306 print ' <td><input type="text" min="0" step="any" class="maxwidth75" id="rateindirectinput" name="rateindirectinput" value="'.dol_escape_htmltag((string) $rateindirectinput).'"></td>';
307 // LRR Calculate Rate Direct
308 print '<script type="text/javascript">';
309 print 'jQuery(document).ready(function () {
310 //alert("TC");
311 jQuery("#rateindirectinput").keyup(function () {
312 var valindirect = jQuery(this).val();
313 valdirect = 1 / parseFloat(valindirect);
314 jQuery("#rateinput").val(valdirect);
315 console.log("Rate Direct:"+valdirect)
316 });
317 });';
318 print '</script>';
319 }
320
321 print '<td>';
322 print '<input type="hidden" name="action" value="create">';
323 print '<input type="submit" class="button button-add small" name="btnCreateCurrencyRate" value="'.$langs->trans('CreateRate').'">';
324 print '</td>';
325
326 print '</tr></table>';
327 print '</div>';
328
329 print '</form>';
330
331 print '<br>';
332}
333
334
335
336
337$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.rate_indirect, cr.entity, m.code, m.name';
338// Add fields from hooks
339$parameters = array();
340$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
341$sql .= $hookmanager->resPrint;
342$sql .= ' FROM '.MAIN_DB_PREFIX.'multicurrency_rate as cr ';
343$sql .= " INNER JOIN ".MAIN_DB_PREFIX."multicurrency AS m ON cr.fk_multicurrency = m.rowid";
344if ($sall) {
345 $sql .= natural_search(array_keys($fieldstosearchall), $sall);
346}
347if ($search_date_sync && $search_date_sync_end) {
348 $sql .= " AND (cr.date_sync BETWEEN '".$db->idate($search_date_sync)."' AND '".$db->idate($search_date_sync_end)."')";
349} elseif ($search_date_sync && !$search_date_sync_end) {
350 $sql .= natural_search('cr.date_sync', $db->idate($search_date_sync));
351}
352if ($search_rate) {
353 $sql .= natural_search('cr.rate', $search_rate, 1);
354}
355if ($search_code) {
356 $sql .= natural_search('m.code', $search_code);
357}
358$sql .= " WHERE m.code <> '".$db->escape($conf->currency)."'";
359
360// Add where from hooks
361$parameters = array();
362$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
363$sql .= $hookmanager->resPrint;
364$sql .= " GROUP BY cr.rowid, cr.date_sync, cr.rate, cr.rate_indirect, m.code, cr.entity, m.code, m.name";
365
366// Add fields from hooks
367$parameters = array();
368$reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook
369$sql .= $hookmanager->resPrint;
370
371$sql .= $db->order($sortfield, $sortorder);
372
373
374$nbtotalofrecords = '';
375if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
376 $result = $db->query($sql);
377
378 if ($result) {
379 $nbtotalofrecords = $db->num_rows($result);
380 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
381 $page = 0;
382 $offset = 0;
383 }
384 } else {
385 setEventMessage($langs->trans('No_record_on_multicurrency_rate'), 'warnings');
386 }
387}
388
389$sql .= $db->plimit($limit + 1, $offset);
390
391$resql = $db->query($sql);
392if ($resql) {
393 $num = $db->num_rows($resql);
394 $arrayofselected = is_array($toselect) ? $toselect : array();
395
396 $param = '';
397 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
398 $param .= '&contextpage='.urlencode($contextpage);
399 }
400 if ($limit > 0 && $limit != $conf->liste_limit) {
401 $param .= '&limit='.((int) $limit);
402 }
403 if ($sall) {
404 $param .= "&sall=".urlencode($sall);
405 }
406
407 if ($search_date_sync) {
408 $param = "&search_date_sync=".$search_date_sync;
409 }
410 if ($search_date_sync_end) {
411 $param = "&search_date_sync_end=".$search_date_sync_end;
412 }
413 if ($search_rate) {
414 $param = "&search_rate=".urlencode($search_rate);
415 }
416 if ($search_code != '') {
417 $param .= "&search_code=".urlencode($search_code);
418 }
419
420 // Add $param from extra fields
421 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
422
423 if ($user->admin) {
424 $arrayofmassactions['predelete'] = $langs->trans("Delete");
425 }
426 if (in_array($massaction, array('presend', 'predelete'))) {
427 $arrayofmassactions = array();
428 }
429 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
430
431 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
432 if ($optioncss != '') {
433 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
434 }
435 print '<input type="hidden" name="token" value="'.newToken().'">';
436 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
437 print '<input type="hidden" name="action" value="list">';
438 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
439 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
440 print '<input type="hidden" name="page" value="'.$page.'">';
441 print '<input type="hidden" name="type" value="'.$type.'">';
442
443 print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_currency.png', 0, $newcardbutton, '', $limit);
444
445 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
446
447 if ($sall) {
448 foreach ($fieldstosearchall as $key => $val) {
449 $fieldstosearchall[$key] = $langs->trans($val);
450 }
451 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).implode(', ', $fieldstosearchall).'</div>';
452 }
453
454 // Filter on categories
455 $moreforfilter = '';
456
457
458 $parameters = array();
459 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
460 if (empty($reshook)) {
461 $moreforfilter .= $hookmanager->resPrint;
462 } else {
463 $moreforfilter = $hookmanager->resPrint;
464 }
465
466 if ($moreforfilter) {
467 print '<div class="liste_titre liste_titre_bydiv centpercent">';
468 print $moreforfilter;
469 print '</div>';
470 }
471
472 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
473 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
474 if ($massactionbutton) {
475 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
476 }
477
478 print '<div class="div-table-responsive">';
479 print '<table class="tagtable centpercent nomarginbottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
480
481 // Lines with input filters
482 print '<tr class="liste_titre_filter">';
483
484 // Action column
485 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
486 print '<td class="liste_titre center">';
487 $searchpicto = $form->showFilterButtons();
488 print $searchpicto;
489 print '</td>';
490 }
491 // date
492 if (!empty($arrayfields['cr.date_sync']['checked'])) {
493 print '<td class="liste_titre" align="left">';
494 print $form->selectDate(dol_print_date($search_date_sync, "%Y-%m-%d"), 'search_date_sync', 0, 0, 1);
495 print $form->selectDate(dol_print_date($search_date_sync_end, "%Y-%m-%d"), 'search_date_sync_end', 0, 0, 1);
496 print '</td>';
497 }
498 // code
499 if (!empty($arrayfields['m.code']['checked'])) {
500 print '<td class="liste_titre" align="left">';
501 print $form->selectMultiCurrency($multicurrency_code, 'search_code', 1, " code != '".$conf->currency."'", true);
502 print '</td>';
503 }
504 // rate
505 if (!empty($arrayfields['cr.rate']['checked'])) {
506 print '<td class="liste_titre" align="left">';
507 print '<input class="flat maxwidth75" type="text" name="search_rate" value="'.dol_escape_htmltag($search_rate).'">';
508 print '</td>';
509 }
510
511 // Fields from hook
512 $parameters = array('arrayfields' => $arrayfields);
513 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
514 print $hookmanager->resPrint;
515
516 // Action column
517 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
518 print '<td class="liste_titre center">';
519 $searchpicto = $form->showFilterButtons();
520 print $searchpicto;
521 print '</td>';
522 }
523 print '</tr>';
524
525 print '<tr class="liste_titre">';
526 // Action column
527 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
528 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
529 }
530 if (!empty($arrayfields['cr.date_sync']['checked'])) {
531 // @phan-suppress-next-line PhanTypeInvalidDimOffset
532 print_liste_field_titre($arrayfields['cr.date_sync']['label'], $_SERVER["PHP_SELF"], "cr.date_sync", "", $param, "", $sortfield, $sortorder);
533 }
534 if (!empty($arrayfields['m.code']['checked'])) {
535 print_liste_field_titre($arrayfields['m.code']['label'], $_SERVER["PHP_SELF"], "m.code", "", $param, "", $sortfield, $sortorder);
536 }
537 if (!empty($arrayfields['cr.rate']['checked'])) {
538 print_liste_field_titre($arrayfields['cr.rate']['label'], $_SERVER["PHP_SELF"], "cr.rate", "", $param, "", $sortfield, $sortorder);
539 }
540
541 // Hook fields
542 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
543 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
544 print $hookmanager->resPrint;
545 // Action column
546 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
547 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch center ');
548 }
549 print "</tr>\n";
550
551 $i = 0;
552 $totalarray = array();
553 $totalarray['nbfield'] = 0;
554 while ($i < min($num, $limit)) {
555 $obj = $db->fetch_object($resql);
556
557 print '<tr class="oddeven">';
558
559 // USER REQUEST UPDATE FOR THIS LINE
560 if ($action == "updateRate" && $obj->rowid == $id_rate_selected) {
561 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
562 print '<td class="center">';
563 print '</td>';
564 }
565 print '<td><input class="minwidth200" name="dateinput" value="'. date('Y-m-d', dol_stringtotime($obj->date_sync)) .'" type="date"></td>';
566 print '<td>' . $form->selectMultiCurrency($obj->code, 'multicurrency_code', 1, " code != '".$conf->currency."'", true) . '</td>';
567 print '<td><input type="text" min="0" step="any" class="maxwidth100" name="rateinput" value="' . dol_escape_htmltag($obj->rate) . '">';
568 print '<input type="hidden" name="page" value="'.dol_escape_htmltag((string) $page).'">';
569 print '<input type="hidden" name="id_rate" value="'.dol_escape_htmltag($obj->rowid).'">';
570 print '<button type="submit" class="button small reposition" name="action" value="update">'.$langs->trans("Modify").'</button>';
571 print '<button type="submit" class="button small reposition" name="action" value="cancel">'.$langs->trans("Cancel").'</button>';
572 print '</td>';
573 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
574 print '<td class="center">';
575 print '</td>';
576 }
577 } else {
578 // Action
579 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
580 print '<td class="nowrap center">';
581 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
582 $selected = 0;
583 if (in_array($obj->rowid, $arrayofselected)) {
584 $selected = 1;
585 }
586 print '<a class="editfielda marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
587 print '<a class="marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
588 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
589 }
590 print '</td>';
591 if (!$i) {
592 $totalarray['nbfield']++;
593 }
594 }
595
596 // date_sync
597 if (!empty($arrayfields['cr.date_sync']['checked'])) {
598 print '<td class="tdoverflowmax200">';
599 print $obj->date_sync;
600 print "</td>\n";
601 if (!$i) {
602 $totalarray['nbfield']++;
603 }
604 }
605
606 // code
607 if (!empty($arrayfields['m.code']['checked'])) {
608 print '<td class="tdoverflowmax200">';
609 print $obj->code;
610 print ' - <span class="opacitymedium">'.$obj->name.'</span>';
611 print "</td>\n";
612
613 if (! $i) {
614 $totalarray['nbfield']++;
615 }
616 }
617
618 // rate
619 if (!empty($arrayfields['cr.rate']['checked'])) {
620 print '<td class="tdoverflowmax200">';
621 print $obj->rate;
622 print "</td>\n";
623 if (! $i) {
624 $totalarray['nbfield']++;
625 }
626 }
627
628 // rate indirect
629 if (!empty($arrayfields['cr.rate_indirect']['checked'])) {
630 print '<td class="tdoverflowmax200">';
631 print $obj->rate_indirect;
632 print "</td>\n";
633 if (! $i) {
634 $totalarray['nbfield']++;
635 }
636 }
637
638
639 // Fields from hook
640 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj);
641 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
642 print $hookmanager->resPrint;
643
644 // Action
645 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
646 print '<td class="nowrap center">';
647 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
648 $selected = 0;
649 if (in_array($obj->rowid, $arrayofselected)) {
650 $selected = 1;
651 }
652 print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
653 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
654 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
655 }
656 print '</td>';
657 if (!$i) {
658 $totalarray['nbfield']++;
659 }
660 }
661
662 print "</tr>\n";
663 $i++;
664 }
665 }
666
667 $db->free($resql);
668
669 print "</table>";
670 print "</div>";
671
672 print '</form>';
673} else {
674 dol_print_error($db);
675}
676
677
678llxFooter();
679$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
Class CurrencyRate.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class Currency.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:426
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multicurrencyAdminPrepareHead()
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.