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