userinvoice_all_list.php 32 KB

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