multicurrency_rate.php 25 KB

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