userinvoice_list.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <?php
  2. //phpinfo();
  3. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2023 Szollősi László <szollosi.laszlo@smbinfo.hu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file userinvoice_list.php
  21. * \ingroup financialreport
  22. * \brief List page for userinvoice
  23. */
  24. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
  25. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
  28. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
  29. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
  30. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
  31. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  32. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
  33. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  34. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  35. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  36. //if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
  37. //if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  38. //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
  39. //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
  40. //if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
  41. //if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
  42. //if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  43. //if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
  44. //if (! defined('NOSESSION')) define('NOSESSION', '1'); // On CLI mode, no need to use web sessions
  45. // Load Dolibarr environment
  46. $res = 0;
  47. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  48. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  49. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  50. }
  51. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  52. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  53. $tmp2 = realpath(__FILE__);
  54. $i = strlen($tmp) - 1;
  55. $j = strlen($tmp2) - 1;
  56. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  57. $i--;
  58. $j--;
  59. }
  60. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  61. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  62. }
  63. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  64. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  65. }
  66. // Try main.inc.php using relative path
  67. if (!$res && file_exists("../main.inc.php")) {
  68. $res = @include "../main.inc.php";
  69. }
  70. if (!$res && file_exists("../../main.inc.php")) {
  71. $res = @include "../../main.inc.php";
  72. }
  73. if (!$res && file_exists("../../../main.inc.php")) {
  74. $res = @include "../../../main.inc.php";
  75. }
  76. if (!$res) {
  77. die("Include of main fails");
  78. }
  79. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  80. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  81. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  82. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php';
  83. // load financialreport libraries
  84. require_once __DIR__ . '/class/userinvoice.class.php';
  85. // for other modules
  86. //dol_include_once('/othermodule/class/otherobject.class.php');
  87. // Load translation files required by the page
  88. $langs->loadLangs(array("financialreport@financialreport", "other"));
  89. $id = GETPOST('id', 'int');
  90. $ref = GETPOST('ref', 'alpha');
  91. $user_id = GETPOST('user_id', 'int');
  92. $payment_type = GETPOST('payment_type', 'int');
  93. $idmenu = GETPOST('idmenu', 'int');
  94. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  95. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  96. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  97. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  98. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  99. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  100. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search
  101. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  102. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  103. $mode = GETPOST('mode', 'aZ');
  104. // Load variable for pagination
  105. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  106. $sortfield = GETPOST('sortfield', 'aZ09comma');
  107. $sortorder = GETPOST('sortorder', 'aZ09comma');
  108. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  109. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  110. // If $page is not defined, or '' or -1 or if we click on clear filters
  111. $page = 0;
  112. }
  113. $offset = $limit * $page;
  114. $pageprev = $page - 1;
  115. $pagenext = $page + 1;
  116. // Initialize technical objects
  117. $object = new UserInvoice($db);
  118. $extrafields = new ExtraFields($db);
  119. $diroutputmassaction = $conf->financialreport->dir_output . '/temp/massgeneration/' . $user->id;
  120. $hookmanager->initHooks(array('userinvoicelist')); // Note that conf->hooks_modules contains array
  121. // Fetch optionals attributes and labels
  122. $extrafields->fetch_name_optionals_label($object->table_element);
  123. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  124. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  125. // Default sort order (if not yet defined by previous GETPOST)
  126. if (!$sortfield) {
  127. reset($object->fields); // Reset is required to avoid key() to return null.
  128. $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
  129. }
  130. if (!$sortorder) {
  131. $sortorder = "ASC";
  132. }
  133. // Initialize array of search criterias
  134. $search_all = GETPOST('search_all', 'alphanohtml');
  135. $search = array();
  136. foreach ($object->fields as $key => $val) {
  137. if (GETPOST('search_' . $key, 'alpha') !== '') {
  138. $search[$key] = GETPOST('search_' . $key, 'alpha');
  139. }
  140. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  141. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  142. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  143. }
  144. }
  145. // List of fields to search into when doing a "search in all"
  146. $fieldstosearchall = array();
  147. foreach ($object->fields as $key => $val) {
  148. if (!empty($val['searchall'])) {
  149. $fieldstosearchall['t.' . $key] = $val['label'];
  150. }
  151. }
  152. // Definition of array of fields for columns
  153. $arrayfields = array();
  154. foreach ($object->fields as $key => $val) {
  155. // If $val['visible']==0, then we never show the field
  156. if (!empty($val['visible'])) {
  157. $visible = (int) dol_eval($val['visible'], 1);
  158. $arrayfields['t.' . $key] = array(
  159. 'label' => $val['label'],
  160. 'checked' => (($visible < 0) ? 0 : 1),
  161. 'enabled' => (abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  162. 'position' => $val['position'],
  163. 'help' => isset($val['help']) ? $val['help'] : ''
  164. );
  165. }
  166. }
  167. // Extra fields
  168. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  169. $object->fields = dol_sort_array($object->fields, 'position');
  170. //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
  171. $arrayfields = dol_sort_array($arrayfields, 'position');
  172. // There is several ways to check permission.
  173. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  174. $enablepermissioncheck = 0;
  175. if ($enablepermissioncheck) {
  176. $permissiontoread = $user->rights->financialreport->userinvoice->read;
  177. $permissiontoadd = $user->rights->financialreport->userinvoice->write;
  178. $permissiontodelete = $user->rights->financialreport->userinvoice->delete;
  179. } else {
  180. $permissiontoread = 1;
  181. $permissiontoadd = 1;
  182. $permissiontodelete = 1;
  183. }
  184. // Security check (enable the most restrictive one)
  185. if ($user->socid > 0)
  186. accessforbidden();
  187. //if ($user->socid > 0) accessforbidden();
  188. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  189. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  190. //restrictedArea($user, $object->element, 0, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  191. if (empty($conf->financialreport->enabled))
  192. accessforbidden('Module not enabled');
  193. if (!$permissiontoread)
  194. accessforbidden();
  195. /*
  196. * Actions
  197. */
  198. if (GETPOST('cancel', 'alpha')) {
  199. $action = 'list';
  200. $massaction = '';
  201. }
  202. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  203. $massaction = '';
  204. }
  205. $parameters = array();
  206. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  207. if ($reshook < 0) {
  208. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  209. }
  210. if (empty($reshook)) {
  211. // Selection of new fields
  212. include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
  213. // Purge search criteria
  214. 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
  215. foreach ($object->fields as $key => $val) {
  216. $search[$key] = '';
  217. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  218. $search[$key . '_dtstart'] = '';
  219. $search[$key . '_dtend'] = '';
  220. }
  221. }
  222. $toselect = array();
  223. $search_array_options = array();
  224. }
  225. if (
  226. GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  227. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')
  228. ) {
  229. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  230. }
  231. // Mass actions
  232. $objectclass = 'UserInvoice';
  233. $objectlabel = 'UserInvoice';
  234. $uploaddir = $conf->financialreport->dir_output;
  235. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  236. }
  237. /*
  238. * View
  239. */
  240. $form = new Form($db);
  241. $helper = new HelperUserInvoice($db);
  242. $now = dol_now();
  243. //$help_url = "EN:Module_UserInvoice|FR:Module_UserInvoice_FR|ES:Módulo_UserInvoice";
  244. $help_url = '';
  245. $title = $helper->getTitle($payment_type);
  246. $morejs = array();
  247. $morecss = array();
  248. // Build and execute select
  249. // --------------------------------------------------------------------
  250. $sql = 'SELECT ';
  251. $sql .= $object->getFieldList('t');
  252. // Add fields from extrafields
  253. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  254. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  255. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key : '');
  256. }
  257. }
  258. // Add fields from hooks
  259. $parameters = array();
  260. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  261. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  262. $sql = preg_replace('/,\s*$/', '', $sql);
  263. //$sql .= ", COUNT(rc.rowid) as anotherfield";
  264. $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
  265. //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
  266. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  267. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
  268. }
  269. // Add table from hooks
  270. $parameters = array();
  271. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  272. $sql .= $hookmanager->resPrint;
  273. if ($object->ismultientitymanaged == 1) {
  274. $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ") AND user_id = {$user_id} AND payment_type = {$payment_type}";
  275. } else {
  276. $sql .= " WHERE user_id = {$user_id} AND payment_type = {$payment_type}";
  277. }
  278. foreach ($search as $key => $val) {
  279. if (array_key_exists($key, $object->fields)) {
  280. if ($key == 'status' && $search[$key] == -1) {
  281. continue;
  282. }
  283. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  284. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  285. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  286. $search[$key] = '';
  287. }
  288. $mode_search = 2;
  289. }
  290. if ($search[$key] != '') {
  291. $sql .= natural_search("t." . $db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  292. }
  293. } else {
  294. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  295. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  296. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  297. if (preg_match('/_dtstart$/', $key)) {
  298. $sql .= " AND t." . $db->escape($columnName) . " >= '" . $db->idate($search[$key]) . "'";
  299. }
  300. if (preg_match('/_dtend$/', $key)) {
  301. $sql .= " AND t." . $db->escape($columnName) . " <= '" . $db->idate($search[$key]) . "'";
  302. }
  303. }
  304. }
  305. }
  306. }
  307. if ($search_all) {
  308. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  309. }
  310. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  311. // Add where from extra fields
  312. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
  313. // Add where from hooks
  314. $parameters = array();
  315. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  316. $sql .= $hookmanager->resPrint;
  317. // Count total nb of records
  318. $nbtotalofrecords = '';
  319. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  320. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  321. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  322. $resql = $db->query($sqlforcount);
  323. if ($resql) {
  324. $objforcount = $db->fetch_object($resql);
  325. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  326. } else {
  327. dol_print_error($db);
  328. }
  329. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  330. $page = 0;
  331. $offset = 0;
  332. }
  333. $db->free($resql);
  334. }
  335. // Complete request and execute it with limit
  336. $sql .= $db->order($sortfield, $sortorder);
  337. if ($limit) {
  338. $sql .= $db->plimit($limit + 1, $offset);
  339. }
  340. $resql = $db->query($sql);
  341. if (!$resql) {
  342. dol_print_error($db);
  343. exit;
  344. }
  345. $num = $db->num_rows($resql);
  346. // Direct jump if only one record found
  347. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  348. $obj = $db->fetch_object($resql);
  349. $id = $obj->rowid;
  350. header("Location: " . dol_buildpath('/financialreport/userinvoice_card.php', 1) . '?id=' . $id);
  351. exit;
  352. }
  353. // Output page
  354. // --------------------------------------------------------------------
  355. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  356. $backpage = $helper->backPageSelector($payment_type);
  357. $linkback = '<a href="' . dol_buildpath("/financialreport/{$backpage}.php", 1) . '?idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=">' . '<b><span class="fa fa-arrow-left"></span> ' . $langs->trans("BackToList") . '</b></a>';
  358. print $linkback;
  359. $arrayofselected = is_array($toselect) ? $toselect : array();
  360. $param = '';
  361. if (!empty($mode)) {
  362. $param .= '&mode=' . urlencode($mode);
  363. }
  364. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  365. $param .= '&contextpage=' . urlencode($contextpage);
  366. }
  367. if ($limit > 0 && $limit != $conf->liste_limit) {
  368. $param .= '&limit=' . urlencode($limit);
  369. }
  370. foreach ($search as $key => $val) {
  371. if (is_array($search[$key])) {
  372. foreach ($search[$key] as $skey) {
  373. if ($skey != '') {
  374. $param .= '&search_' . $key . '[]=' . urlencode($skey);
  375. }
  376. }
  377. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  378. $param .= '&search_' . $key . 'month=' . ((int) GETPOST('search_' . $key . 'month', 'int'));
  379. $param .= '&search_' . $key . 'day=' . ((int) GETPOST('search_' . $key . 'day', 'int'));
  380. $param .= '&search_' . $key . 'year=' . ((int) GETPOST('search_' . $key . 'year', 'int'));
  381. } elseif ($search[$key] != '') {
  382. $param .= '&search_' . $key . '=' . urlencode($search[$key]);
  383. }
  384. }
  385. if ($optioncss != '') {
  386. $param .= '&optioncss=' . urlencode($optioncss);
  387. }
  388. // Add $param from extra fields
  389. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
  390. // Add $param from hooks
  391. $parameters = array();
  392. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  393. $param .= $hookmanager->resPrint;
  394. // List of mass actions available
  395. $arrayofmassactions = array(
  396. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  397. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  398. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  399. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  400. );
  401. if (!empty($permissiontodelete)) {
  402. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
  403. }
  404. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  405. $arrayofmassactions = array();
  406. }
  407. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  408. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  409. if ($optioncss != '') {
  410. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  411. }
  412. print '<input type="hidden" name="token" value="' . newToken() . '">';
  413. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  414. print '<input type="hidden" name="action" value="list">';
  415. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  416. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  417. print '<input type="hidden" name="page" value="' . $page . '">';
  418. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  419. print '<input type="hidden" name="mode" value="' . $mode . '">';
  420. print '<input type="hidden" name="user_id" value="' . $user_id . '">';
  421. print '<input type="hidden" name="payment_type" value="' . $payment_type . '">';
  422. $newcardbutton = '';
  423. $newcardbutton .= dolGetButtonTitleSeparator();
  424. //$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/financialreport/userinvoice_card.php', 1).'?action=create&user_id=' . $user_id . '&payment_type=' . $payment_type . '&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  425. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  426. include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/tpl/userdata_view.tpl.php';
  427. // Add code for pre mass action (confirmation or email presend form)
  428. $topicmail = "SendUserInvoiceRef";
  429. $modelmail = "userinvoice";
  430. $objecttmp = new UserInvoice($db);
  431. $trackid = 'xxxx' . $object->id;
  432. include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
  433. if ($search_all) {
  434. $setupstring = '';
  435. foreach ($fieldstosearchall as $key => $val) {
  436. $fieldstosearchall[$key] = $langs->trans($val);
  437. $setupstring .= $key . "=" . $val . ";";
  438. }
  439. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = ' . $setupstring . ' -->' . "\n";
  440. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>' . "\n";
  441. }
  442. $moreforfilter = '';
  443. $parameters = array();
  444. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  445. if (empty($reshook)) {
  446. $moreforfilter .= $hookmanager->resPrint;
  447. } else {
  448. $moreforfilter = $hookmanager->resPrint;
  449. }
  450. if (!empty($moreforfilter)) {
  451. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  452. print $moreforfilter;
  453. print '</div>';
  454. }
  455. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  456. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  457. //$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  458. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  459. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  460. // Fields title search
  461. // --------------------------------------------------------------------
  462. print '<tr class="liste_titre">';
  463. // Action column
  464. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  465. print '<td class="liste_titre maxwidthsearch">';
  466. $searchpicto = $form->showFilterButtons('left');
  467. print $searchpicto;
  468. print '</td>';
  469. }
  470. foreach ($object->fields as $key => $val) {
  471. $searchkey = empty($search[$key]) ? '' : $search[$key];
  472. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  473. if ($key == 'status') {
  474. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  475. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  476. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  477. } elseif (in_array($val['type'], array('timestamp'))) {
  478. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  479. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  480. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  481. }
  482. if (!empty($arrayfields['t.' . $key]['checked'])) {
  483. print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
  484. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  485. print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  486. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  487. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield . ' maxwidth250', 1);
  488. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  489. print '<div class="nowrap">';
  490. print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  491. print '</div>';
  492. print '<div class="nowrap">';
  493. print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  494. print '</div>';
  495. } elseif ($key == 'lang') {
  496. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
  497. $formadmin = new FormAdmin($db);
  498. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  499. } else {
  500. print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
  501. }
  502. print '</td>';
  503. }
  504. }
  505. // Extra fields
  506. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
  507. // Fields from hook
  508. $parameters = array('arrayfields' => $arrayfields);
  509. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  510. print $hookmanager->resPrint;
  511. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  512. print '<td class="liste_titre"></td>';
  513. }*/
  514. // Action column
  515. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  516. print '<td class="liste_titre maxwidthsearch">';
  517. $searchpicto = $form->showFilterButtons();
  518. print $searchpicto;
  519. print '</td>';
  520. }
  521. print '</tr>' . "\n";
  522. $totalarray = array();
  523. $totalarray['nbfield'] = 0;
  524. // Fields title label
  525. // --------------------------------------------------------------------
  526. print '<tr class="liste_titre">';
  527. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  528. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  529. }
  530. foreach ($object->fields as $key => $val) {
  531. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  532. if ($key == 'status') {
  533. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  534. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  535. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  536. } elseif (in_array($val['type'], array('timestamp'))) {
  537. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  538. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  539. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  540. }
  541. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  542. $param .= "&user_id={$user_id}&payment_type={$payment_type}";
  543. if (!empty($arrayfields['t.' . $key]['checked'])) {
  544. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  545. $totalarray['nbfield']++;
  546. }
  547. }
  548. // Extra fields
  549. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
  550. // Hook fields
  551. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
  552. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  553. print $hookmanager->resPrint;
  554. // Action column
  555. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  556. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  557. }
  558. $totalarray['nbfield']++;
  559. print '</tr>' . "\n";
  560. // Detect if we need a fetch on each output line
  561. $needToFetchEachLine = 0;
  562. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  563. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  564. if (preg_match('/\$object/', $val)) {
  565. $needToFetchEachLine++; // There is at least one compute field that use $object
  566. }
  567. }
  568. }
  569. // Loop on record
  570. // --------------------------------------------------------------------
  571. $i = 0;
  572. $savnbfield = $totalarray['nbfield'];
  573. $totalarray = array();
  574. $totalarray['nbfield'] = 0;
  575. $imaxinloop = ($limit ? min($num, $limit) : $num);
  576. while ($i < $imaxinloop) {
  577. $obj = $db->fetch_object($resql);
  578. if (empty($obj)) {
  579. break; // Should not happen
  580. }
  581. // Store properties in $object
  582. $object->setVarsFromFetchObj($obj);
  583. if ($mode == 'kanban') {
  584. if ($i == 0) {
  585. print '<tr><td colspan="' . $savnbfield . '">';
  586. print '<div class="box-flex-container">';
  587. }
  588. // Output Kanban
  589. print $object->getKanbanView('');
  590. if ($i == ($imaxinloop - 1)) {
  591. print '</div>';
  592. print '</td></tr>';
  593. }
  594. } else {
  595. // Show here line of result
  596. $j = 0;
  597. print '<tr data-rowid="' . $object->id . '" class="oddeven">';
  598. // Action column
  599. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  600. print '<td class="nowrap center">';
  601. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  602. $selected = 0;
  603. if (in_array($object->id, $arrayofselected)) {
  604. $selected = 1;
  605. }
  606. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  607. }
  608. print '</td>';
  609. }
  610. foreach ($object->fields as $key => $val) {
  611. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  612. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  613. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  614. } elseif ($key == 'status') {
  615. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  616. }
  617. if (in_array($val['type'], array('timestamp'))) {
  618. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  619. } elseif ($key == 'ref') {
  620. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  621. }
  622. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  623. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  624. }
  625. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  626. if (!empty($arrayfields['t.' . $key]['checked'])) {
  627. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '');
  628. if (preg_match('/tdoverflow/', $cssforfield)) {
  629. print ' title="' . dol_escape_htmltag($object->$key) . '"';
  630. }
  631. print '>';
  632. if ($key == 'status') {
  633. print $object->getLibStatut(5);
  634. } elseif ($key == 'rowid') {
  635. print $object->showOutputField($val, $key, $object->id, '');
  636. } elseif ($key == 'ref') {
  637. print '<a href="/custom/financialreport/userinvoice_card.php?id=' . $object->id . '&user_id=' . $user_id . '&payment_type=' . $payment_type . '&idmenu=' . $idmenu . '&save_lastsearch_values=1">' . $object->ref . '</a>';
  638. } elseif ($key == 'user_id') {
  639. $sqlUser = "SELECT firstname, lastname, login FROM llx_user WHERE rowid = {$object->$key}";
  640. $resultUser = $db->query($sqlUser);
  641. while($rowUser = $db->fetch_object($resultUser)){
  642. $username = $rowUser->firstname . ' ' . $rowUser->lastname . ' (' . $rowUser->login . ')';
  643. }
  644. print $username;
  645. } elseif ($key == 'receipt_pdf') {
  646. $filename = basename($object->$key);
  647. if ($filename != '') {
  648. print '<a href="/document.php?modulepart=settlements&file=pdf/' . $payment_type . '/' . $filename . '&entity=1" target="_blank" >' . $langs->trans('Print') . '</a>';
  649. }
  650. } else {
  651. print $object->showOutputField($val, $key, $object->$key, '');
  652. }
  653. print '</td>';
  654. if (!$i) {
  655. $totalarray['nbfield']++;
  656. }
  657. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  658. if (!$i) {
  659. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  660. }
  661. if (!isset($totalarray['val'])) {
  662. $totalarray['val'] = array();
  663. }
  664. if (!isset($totalarray['val']['t.' . $key])) {
  665. $totalarray['val']['t.' . $key] = 0;
  666. }
  667. $totalarray['val']['t.' . $key] += $object->$key;
  668. }
  669. }
  670. }
  671. // Extra fields
  672. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
  673. // Fields from hook
  674. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  675. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  676. print $hookmanager->resPrint;
  677. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  678. print '<td class="right">'.$obj->anotherfield.'</td>';
  679. }*/
  680. // Action column
  681. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  682. print '<td class="nowrap center">';
  683. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  684. $selected = 0;
  685. if (in_array($object->id, $arrayofselected)) {
  686. $selected = 1;
  687. }
  688. //print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  689. }
  690. print '</td>';
  691. }
  692. if (!$i) {
  693. $totalarray['nbfield']++;
  694. }
  695. print '</tr>' . "\n";
  696. }
  697. $i++;
  698. }
  699. // Show total line
  700. include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
  701. // If no record found
  702. if ($num == 0) {
  703. $colspan = 1;
  704. foreach ($arrayfields as $key => $val) {
  705. if (!empty($val['checked'])) {
  706. $colspan++;
  707. }
  708. }
  709. print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
  710. }
  711. $db->free($resql);
  712. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  713. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  714. print $hookmanager->resPrint;
  715. print '</table>' . "\n";
  716. print '</div>' . "\n";
  717. print '</form>' . "\n";
  718. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  719. $hidegeneratedfilelistifempty = 1;
  720. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  721. $hidegeneratedfilelistifempty = 0;
  722. }
  723. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  724. $formfile = new FormFile($db);
  725. // Show list of available documents
  726. $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
  727. $urlsource .= str_replace('&amp;', '&', $param);
  728. $filedir = $diroutputmassaction;
  729. $genallowed = $permissiontoread;
  730. $delallowed = $permissiontoadd;
  731. print $formfile->showdocuments('massfilesarea_financialreport', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  732. }
  733. // End of page
  734. llxFooter();
  735. $db->close();