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