dolibarr 21.0.0-beta
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
51// Load translation files required by the page
52$langs->loadLangs(array('admin', 'multicurrency'));
53
54// Get Parameters
55$action = GETPOST('action', 'alpha');
56$massaction = GETPOST('massaction', 'alpha');
57$show_files = GETPOSTINT('show_files');
58$confirm = GETPOST('confirm', 'alpha');
59$toselect = GETPOST('toselect', 'array');
60$id_rate_selected = GETPOSTINT('id_rate');
61$sall = trim(GETPOST('search_all', 'alphanohtml'));
62$search_date_sync = dol_mktime(0, 0, 0, GETPOSTINT('search_date_syncmonth'), GETPOSTINT('search_date_syncday'), GETPOSTINT('search_date_syncyear'));
63$search_date_sync_end = dol_mktime(0, 0, 0, GETPOSTINT('search_date_sync_endmonth'), GETPOSTINT('search_date_sync_endday'), GETPOSTINT('search_date_sync_endyear'));
64$search_rate = GETPOST('search_rate', 'alpha');
65$search_rate_indirect = GETPOST('search_rate_indirect', 'alpha');
66$search_code = GETPOST('search_code', 'alpha');
67$multicurrency_code = GETPOST('multicurrency_code', 'alpha');
68$dateinput = dol_mktime(0, 0, 0, GETPOSTINT('dateinputmonth'), GETPOSTINT('dateinputday'), GETPOSTINT('dateinputyear'));
69$rateinput = (float) price2num(GETPOST('rateinput', 'alpha'));
70$rateindirectinput = (float) price2num(GETPOST('rateinidirectinput', 'alpha'));
71$optioncss = GETPOST('optioncss', 'alpha');
72$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
73$page = GETPOSTINT("page");
74if (empty($page) || $page == -1) {
75 $page = 0;
76} // If $page is not defined, or '' or -1
77$offset = $limit * $page;
78$pageprev = $page - 1;
79$pagenext = $page + 1;
80$sortfield = GETPOST('sortfield', 'aZ09comma');
81$sortorder = GETPOST('sortorder', 'aZ09comma');
82if (!$sortfield) {
83 $sortfield = "cr.date_sync";
84}
85if (!$sortorder) {
86 $sortorder = "DESC";
87}
88$type = '';
89$texte = '';
90$newcardbutton = '';
91
92// Initialize a technical objects
93$object = new CurrencyRate($db);
94$form = new Form($db);
95$extrafields = new ExtraFields($db);
96
97
98// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
99$hookmanager->initHooks(array('EditorRatelist', 'globallist'));
100
101if (empty($action)) {
102 $action = 'list';
103}
104
105// List of fields to search into when doing a "search in all"
106$fieldstosearchall = array(
107 'cr.date_sync' => "date_sync",
108 'cr.rate' => "rate",
109 'cr.rate_indirect' => "rate_indirect",
110 'm.code' => "code",
111);
112
113// Definition of fields for lists
114$arrayfields = array(
115 'cr.date_sync' => array('label' => 'Date', 'checked' => 1),
116 'cr.rate' => array('label' => 'Rate', 'checked' => 1),
117 'cr.rate_indirect' => array('label' => 'RateIndirect', 'checked' => 0, 'enabled' => (!getDolGlobalString('MULTICURRENCY_USE_RATE_INDIRECT') ? 0 : 1)),
118 'm.code' => array('label' => 'Code', 'checked' => 1),
119);
120
121
122$object->fields = dol_sort_array($object->fields, 'position');
123$arrayfields = dol_sort_array($arrayfields, 'position');
124'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
125
126// Access control
127// TODO Open this page to a given permission so a sale representative can modify change rates. Permission should be added into module multicurrency.
128// One permission to read rates (history) and one to add/edit rates.
129if (!$user->admin || !isModEnabled("multicurrency")) {
131}
132
133$error = 0;
134
135
136/*
137 * Actions
138 */
139
140if ($action == "create" && $user->hasRight('multicurrency', 'currency', 'read')) {
141 if (empty($multicurrency_code) || $multicurrency_code == '-1') {
142 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Currency")), null, "errors");
143 $error++;
144 }
145 if ($rateinput == 0) {
146 setEventMessages($langs->trans('NoEmptyRate'), null, "errors");
147 $error++;
148 } elseif (empty($rateinput)) {
149 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Rate")), null, "errors");
150 $error++;
151 }
152
153 if (!$error) {
154 $currencyRate_static = new CurrencyRate($db);
155 $currency_static = new MultiCurrency($db);
156 $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
157
158 $currencyRate_static->fk_multicurrency = $fk_currency;
159 $currencyRate_static->entity = $conf->entity;
160 $currencyRate_static->date_sync = $dateinput;
161 $currencyRate_static->rate = $rateinput;
162 $currencyRate_static->rate_indirect = $rateindirectinput;
163
164 $result = $currencyRate_static->create($user, intval($fk_currency));
165 if ($result > 0) {
166 setEventMessages($langs->trans('successRateCreate', $multicurrency_code), null);
167 } else {
168 dol_syslog("currencyRate:createRate", LOG_WARNING);
169 setEventMessages($currencyRate_static->error, $currencyRate_static->errors, 'errors');
170 }
171 }
172}
173
174if ($action == 'update' && $user->hasRight('multicurrency', 'currency', 'read')) {
175 $currencyRate = new CurrencyRate($db);
176 $result = $currencyRate->fetch($id_rate_selected);
177 if ($result > 0) {
178 $currency_static = new MultiCurrency($db);
179 $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
180 $currencyRate->date_sync = $dateinput;
181 $currencyRate->fk_multicurrency = $fk_currency;
182 $currencyRate->rate = $rateinput;
183 $res = $currencyRate->update($user);
184 if ($res) {
185 setEventMessages($langs->trans('successUpdateRate'), null);
186 } else {
187 setEventMessages($currencyRate->error, $currencyRate->errors, "errors");
188 }
189 } else {
190 setEventMessages($langs->trans('Error'), null, "warnings");
191 }
192}
193
194if ($action == "deleteRate" && $user->hasRight('multicurrency', 'currency', 'read')) {
195 $current_rate = new CurrencyRate($db);
196 $current_rate->fetch((int) $id_rate_selected);
197
198 if ($current_rate) {
199 $current_currency = new MultiCurrency($db);
200 $current_currency->fetch($current_rate->fk_multicurrency);
201 if ($current_currency) {
202 $delayedhtmlcontent = $form->formconfirm(
203 $_SERVER["PHP_SELF"].'?id_rate='.$id_rate_selected,
204 $langs->trans('DeleteLineRate'),
205 $langs->trans('ConfirmDeleteLineRate', $current_rate->rate, $current_currency->name, $current_rate->date_sync),
206 'confirm_delete',
207 '',
208 0,
209 1
210 );
211 } else {
212 dol_syslog("Multicurrency::fetch", LOG_WARNING);
213 }
214 } else {
215 setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings");
216 }
217}
218
219if ($action == "confirm_delete" && $user->hasRight('multicurrency', 'currency', 'read')) {
220 $current_rate = new CurrencyRate($db);
221 $current_rate->fetch((int) $id_rate_selected);
222 if ($current_rate) {
223 $result = $current_rate->delete($user);
224 if ($result) {
225 setEventMessages($langs->trans('successRateDelete'), null);
226 } else {
227 setEventMessages($current_rate->error, $current_rate->errors, 'errors');
228 }
229 } else {
230 setEventMessages($langs->trans('NoCurrencyRateSelected'), null, "warnings");
231 dol_syslog($langs->trans('NoCurrencyRateSelected'), LOG_WARNING);
232 }
233}
234
235
236if (GETPOST('cancel', 'alpha')) {
237 $action = 'list';
238 $massaction = '';
239}
240if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
241 $massaction = '';
242}
243
244$parameters = array();
245$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
246if ($reshook < 0) {
247 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
248}
249if (empty($reshook)) {
250 // Selection of new fields
251 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
252
253 // Purge search criteria
254 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
255 $sall = "";
256 $search_date_sync = "";
257 $search_date_sync_end = "";
258 $search_rate = "";
259 $search_code = "";
260 $search_array_options = array();
261 }
262
263 // Mass actions
264 $objectclass = "CurrencyRate";
265 $uploaddir = $conf->multicurrency->multidir_output; // define only because core/actions_massactions.inc.php want it
266 $permissiontoread = $user->admin;
267 $permissiontodelete = $user->admin;
268 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
269}
270
271
272/*
273 * View
274 */
275
276$form = new Form($db);
277
278$title = $langs->trans("CurrencyRate");
279$page_name = "MultiCurrencySetup";
280$help_url = '';
281
282llxHeader('', $title, $help_url, '');
283// Subheader
284$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
285print load_fiche_titre($langs->trans($page_name), $linkback);
286
287// Configuration header
289print dol_get_fiche_head($head, 'ratelist', $langs->trans("ModuleSetup"), -1, "multicurrency");
290
291// ACTION
292
293if (!in_array($action, array("updateRate", "deleteRate"))) {
294 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
295 print '<input type="hidden" name="token" value="'.newToken().'">';
296
297 print '<div class="div-table-responsive-no-min">';
298 print '<table class="noborder centpercent"><tr>';
299
300 print ' <td>'.$langs->trans('Date').'</td>';
301 print ' <td>';
302 print $form->selectDate($dateinput, 'dateinput', 0, 0, 1, '', 1, 1);
303 print '</td>';
304
305 print '<td> '.$langs->trans('Currency').'</td>';
306 print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 1, " code != '".$db->escape($conf->currency)."'", true).'</td>';
307
308 print ' <td>'.$langs->trans('Rate').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
309 print ' <td><input type="text" min="0" step="any" class="maxwidth75" id="rateinput" name="rateinput" value="'.dol_escape_htmltag((string) $rateinput).'"></td>';
310
311 if (getDolGlobalString('MULTICURRENCY_USE_RATE_INDIRECT')) {
312 print ' <td>'.$langs->trans('RateIndirect').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
313 print ' <td><input type="text" min="0" step="any" class="maxwidth75" id="rateindirectinput" name="rateindirectinput" value="'.dol_escape_htmltag((string) $rateindirectinput).'"></td>';
314 // LRR Calculate Rate Direct
315 print '<script type="text/javascript">';
316 print 'jQuery(document).ready(function () {
317 //alert("TC");
318 jQuery("#rateindirectinput").keyup(function () {
319 var valindirect = jQuery(this).val();
320 valdirect = 1 / parseFloat(valindirect);
321 jQuery("#rateinput").val(valdirect);
322 console.log("Rate Direct:"+valdirect)
323 });
324 });';
325 print '</script>';
326 }
327
328 print '<td>';
329 print '<input type="hidden" name="action" value="create">';
330 print '<input type="submit" class="button button-add small" name="btnCreateCurrencyRate" value="'.$langs->trans('CreateRate').'">';
331 print '</td>';
332
333 print '</tr></table>';
334 print '</div>';
335
336 print '</form>';
337
338 print '<br>';
339}
340
341
342
343
344$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.rate_indirect, cr.entity, m.code, m.name';
345// Add fields from hooks
346$parameters = array();
347$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
348$sql .= $hookmanager->resPrint;
349$sql .= ' FROM '.MAIN_DB_PREFIX.'multicurrency_rate as cr ';
350$sql .= " INNER JOIN ".MAIN_DB_PREFIX."multicurrency AS m ON cr.fk_multicurrency = m.rowid";
351if ($sall) {
352 $sql .= natural_search(array_keys($fieldstosearchall), $sall);
353}
354if ($search_date_sync && $search_date_sync_end) {
355 $sql .= " AND (cr.date_sync BETWEEN '".$db->idate($search_date_sync)."' AND '".$db->idate($search_date_sync_end)."')";
356} elseif ($search_date_sync && !$search_date_sync_end) {
357 $sql .= natural_search('cr.date_sync', $db->idate($search_date_sync));
358}
359if ($search_rate) {
360 $sql .= natural_search('cr.rate', $search_rate, 1);
361}
362if ($search_code) {
363 $sql .= natural_search('m.code', $search_code);
364}
365$sql .= " WHERE m.code <> '".$db->escape($conf->currency)."'";
366
367// Add where from hooks
368$parameters = array();
369$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
370$sql .= $hookmanager->resPrint;
371$sql .= " GROUP BY cr.rowid, cr.date_sync, cr.rate, cr.rate_indirect, m.code, cr.entity, m.code, m.name";
372
373// Add fields from hooks
374$parameters = array();
375$reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook
376$sql .= $hookmanager->resPrint;
377
378$sql .= $db->order($sortfield, $sortorder);
379
380
381$nbtotalofrecords = '';
382if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
383 $result = $db->query($sql);
384
385 if ($result) {
386 $nbtotalofrecords = $db->num_rows($result);
387 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
388 $page = 0;
389 $offset = 0;
390 }
391 } else {
392 setEventMessage($langs->trans('No_record_on_multicurrency_rate'), 'warnings');
393 }
394}
395
396$sql .= $db->plimit($limit + 1, $offset);
397
398$resql = $db->query($sql);
399if ($resql) {
400 $num = $db->num_rows($resql);
401 $arrayofselected = is_array($toselect) ? $toselect : array();
402
403 $param = '';
404 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
405 $param .= '&contextpage='.urlencode($contextpage);
406 }
407 if ($limit > 0 && $limit != $conf->liste_limit) {
408 $param .= '&limit='.((int) $limit);
409 }
410 if ($sall) {
411 $param .= "&sall=".urlencode($sall);
412 }
413
414 if ($search_date_sync) {
415 $param = "&search_date_sync=".$search_date_sync;
416 }
417 if ($search_date_sync_end) {
418 $param = "&search_date_sync_end=".$search_date_sync_end;
419 }
420 if ($search_rate) {
421 $param = "&search_rate=".urlencode($search_rate);
422 }
423 if ($search_code != '') {
424 $param .= "&search_code=".urlencode($search_code);
425 }
426
427 // Add $param from extra fields
428 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
429
430 if ($user->admin) {
431 $arrayofmassactions['predelete'] = $langs->trans("Delete");
432 }
433 if (in_array($massaction, array('presend', 'predelete'))) {
434 $arrayofmassactions = array();
435 }
436 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
437
438 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
439 if ($optioncss != '') {
440 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
441 }
442 print '<input type="hidden" name="token" value="'.newToken().'">';
443 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
444 print '<input type="hidden" name="action" value="list">';
445 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
446 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
447 print '<input type="hidden" name="page" value="'.$page.'">';
448 print '<input type="hidden" name="type" value="'.$type.'">';
449
450 print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_currency.png', 0, $newcardbutton, '', $limit);
451
452 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
453
454 if ($sall) {
455 foreach ($fieldstosearchall as $key => $val) {
456 $fieldstosearchall[$key] = $langs->trans($val);
457 }
458 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).implode(', ', $fieldstosearchall).'</div>';
459 }
460
461 // Filter on categories
462 $moreforfilter = '';
463
464
465 $parameters = array();
466 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
467 if (empty($reshook)) {
468 $moreforfilter .= $hookmanager->resPrint;
469 } else {
470 $moreforfilter = $hookmanager->resPrint;
471 }
472
473 if ($moreforfilter) {
474 print '<div class="liste_titre liste_titre_bydiv centpercent">';
475 print $moreforfilter;
476 print '</div>';
477 }
478
479 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
480 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
481 if ($massactionbutton) {
482 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
483 }
484
485 print '<div class="div-table-responsive">';
486 print '<table class="tagtable centpercent nomarginbottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
487
488 // Lines with input filters
489 print '<tr class="liste_titre_filter">';
490
491 // Action column
492 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
493 print '<td class="liste_titre center">';
494 $searchpicto = $form->showFilterButtons();
495 print $searchpicto;
496 print '</td>';
497 }
498 // date
499 if (!empty($arrayfields['cr.date_sync']['checked'])) {
500 print '<td class="liste_titre" align="left">';
501 print $form->selectDate(dol_print_date($search_date_sync, "%Y-%m-%d"), 'search_date_sync', 0, 0, 1);
502 print $form->selectDate(dol_print_date($search_date_sync_end, "%Y-%m-%d"), 'search_date_sync_end', 0, 0, 1);
503 print '</td>';
504 }
505 // code
506 if (!empty($arrayfields['m.code']['checked'])) {
507 print '<td class="liste_titre" align="left">';
508 print $form->selectMultiCurrency($multicurrency_code, 'search_code', 1, " code != '".$conf->currency."'", true);
509 print '</td>';
510 }
511 // rate
512 if (!empty($arrayfields['cr.rate']['checked'])) {
513 print '<td class="liste_titre" align="left">';
514 print '<input class="flat maxwidth75" type="text" name="search_rate" value="'.dol_escape_htmltag($search_rate).'">';
515 print '</td>';
516 }
517
518 // Fields from hook
519 $parameters = array('arrayfields' => $arrayfields);
520 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
521 print $hookmanager->resPrint;
522
523 // Action column
524 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
525 print '<td class="liste_titre center">';
526 $searchpicto = $form->showFilterButtons();
527 print $searchpicto;
528 print '</td>';
529 }
530 print '</tr>';
531
532 print '<tr class="liste_titre">';
533 // Action column
534 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
535 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
536 }
537 if (!empty($arrayfields['cr.date_sync']['checked'])) {
538 // @phan-suppress-next-line PhanTypeInvalidDimOffset
539 print_liste_field_titre($arrayfields['cr.date_sync']['label'], $_SERVER["PHP_SELF"], "cr.date_sync", "", $param, "", $sortfield, $sortorder);
540 }
541 if (!empty($arrayfields['m.code']['checked'])) {
542 print_liste_field_titre($arrayfields['m.code']['label'], $_SERVER["PHP_SELF"], "m.code", "", $param, "", $sortfield, $sortorder);
543 }
544 if (!empty($arrayfields['cr.rate']['checked'])) {
545 print_liste_field_titre($arrayfields['cr.rate']['label'], $_SERVER["PHP_SELF"], "cr.rate", "", $param, "", $sortfield, $sortorder);
546 }
547
548 // Hook fields
549 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
550 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
551 print $hookmanager->resPrint;
552 // Action column
553 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
554 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch center ');
555 }
556 print "</tr>\n";
557
558 $i = 0;
559 $totalarray = array();
560 $totalarray['nbfield'] = 0;
561 while ($i < min($num, $limit)) {
562 $obj = $db->fetch_object($resql);
563
564 print '<tr class="oddeven">';
565
566 // USER REQUEST UPDATE FOR THIS LINE
567 if ($action == "updateRate" && $obj->rowid == $id_rate_selected) {
568 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
569 print '<td class="center">';
570 print '</td>';
571 }
572 print '<td><input class="minwidth200" name="dateinput" value="'. date('Y-m-d', dol_stringtotime($obj->date_sync)) .'" type="date"></td>';
573 print '<td>' . $form->selectMultiCurrency($obj->code, 'multicurrency_code', 1, " code != '".$conf->currency."'", true) . '</td>';
574 print '<td><input type="text" min="0" step="any" class="maxwidth100" name="rateinput" value="' . dol_escape_htmltag($obj->rate) . '">';
575 print '<input type="hidden" name="page" value="'.dol_escape_htmltag((string) $page).'">';
576 print '<input type="hidden" name="id_rate" value="'.dol_escape_htmltag($obj->rowid).'">';
577 print '<button type="submit" class="button small reposition" name="action" value="update">'.$langs->trans("Modify").'</button>';
578 print '<button type="submit" class="button small reposition" name="action" value="cancel">'.$langs->trans("Cancel").'</button>';
579 print '</td>';
580 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
581 print '<td class="center">';
582 print '</td>';
583 }
584 } else {
585 // Action
586 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
587 print '<td class="nowrap center">';
588 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
589 $selected = 0;
590 if (in_array($obj->rowid, $arrayofselected)) {
591 $selected = 1;
592 }
593 print '<a class="editfielda marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
594 print '<a class="marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
595 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
596 }
597 print '</td>';
598 if (!$i) {
599 $totalarray['nbfield']++;
600 }
601 }
602
603 // date_sync
604 if (!empty($arrayfields['cr.date_sync']['checked'])) {
605 print '<td class="tdoverflowmax200">';
606 print $obj->date_sync;
607 print "</td>\n";
608 if (!$i) {
609 $totalarray['nbfield']++;
610 }
611 }
612
613 // code
614 if (!empty($arrayfields['m.code']['checked'])) {
615 print '<td class="tdoverflowmax200">';
616 print $obj->code;
617 print ' - <span class="opacitymedium">'.$obj->name.'</span>';
618 print "</td>\n";
619
620 if (! $i) {
621 $totalarray['nbfield']++;
622 }
623 }
624
625 // rate
626 if (!empty($arrayfields['cr.rate']['checked'])) {
627 print '<td class="tdoverflowmax200">';
628 print $obj->rate;
629 print "</td>\n";
630 if (! $i) {
631 $totalarray['nbfield']++;
632 }
633 }
634
635 // rate indirect
636 if (!empty($arrayfields['cr.rate_indirect']['checked'])) {
637 print '<td class="tdoverflowmax200">';
638 print $obj->rate_indirect;
639 print "</td>\n";
640 if (! $i) {
641 $totalarray['nbfield']++;
642 }
643 }
644
645
646 // Fields from hook
647 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj);
648 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
649 print $hookmanager->resPrint;
650
651 // Action
652 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
653 print '<td class="nowrap center">';
654 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
655 $selected = 0;
656 if (in_array($obj->rowid, $arrayofselected)) {
657 $selected = 1;
658 }
659 print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
660 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
661 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
662 }
663 print '</td>';
664 if (!$i) {
665 $totalarray['nbfield']++;
666 }
667 }
668
669 print "</tr>\n";
670 $i++;
671 }
672 }
673
674 $db->free($resql);
675
676 print "</table>";
677 print "</div>";
678
679 print '</form>';
680} else {
681 dol_print_error($db);
682}
683
684
685llxFooter();
686$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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:431
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.