userinvoicebasiccommission_list.php 33 KB

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