multicurrency_rate.php 25 KB

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