multicurrency_rate.php 22 KB

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