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