list.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/deplacement/list.php
  24. * \brief Page to list trips and expenses
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('companies', 'users', 'trips'));
  34. // Security check
  35. $socid = GETPOST('socid', 'int');
  36. if ($user->socid) {
  37. $socid = $user->socid;
  38. }
  39. $result = restrictedArea($user, 'deplacement', '', '');
  40. $search_ref = GETPOST('search_ref', 'int');
  41. $search_name = GETPOST('search_name', 'alpha');
  42. $search_company = GETPOST('search_company', 'alpha');
  43. // $search_amount=GETPOST('search_amount','alpha');
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "DESC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "d.dated";
  59. }
  60. $year = GETPOST("year");
  61. $month = GETPOST("month");
  62. $day = GETPOST("day");
  63. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  64. $search_ref = "";
  65. $search_name = "";
  66. $search_company = "";
  67. // $search_amount="";
  68. $year = "";
  69. $month = "";
  70. $day = "";
  71. }
  72. /*
  73. * View
  74. */
  75. $formother = new FormOther($db);
  76. $tripandexpense_static = new Deplacement($db);
  77. $userstatic = new User($db);
  78. $childids = $user->getAllChildIds();
  79. $childids[] = $user->id;
  80. llxHeader();
  81. $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
  82. $sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
  83. $sql .= " d.fk_statut,";
  84. $sql .= " u.lastname, u.firstname"; // Qui
  85. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  86. $sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
  87. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
  88. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  89. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  90. }
  91. $sql .= " WHERE d.fk_user = u.rowid";
  92. $sql .= " AND d.entity = ".$conf->entity;
  93. if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
  94. $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  95. }
  96. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  97. $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR d.fk_soc IS NULL) ";
  98. }
  99. if ($socid) {
  100. $sql .= " AND s.rowid = ".((int) $socid);
  101. }
  102. if ($search_ref) {
  103. $sql .= " AND d.rowid = ".((int) $search_ref);
  104. }
  105. if ($search_name) {
  106. $sql .= natural_search('u.lastname', $search_name);
  107. }
  108. if ($search_company) {
  109. $sql .= natural_search('s.nom', $search_company);
  110. }
  111. $sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
  112. $sql .= $db->order($sortfield, $sortorder);
  113. $sql .= $db->plimit($limit + 1, $offset);
  114. //print $sql;
  115. $resql = $db->query($sql);
  116. if ($resql) {
  117. $num = $db->num_rows($resql);
  118. print_barre_liste($langs->trans("TripsAndExpenses"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
  119. $i = 0;
  120. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  121. print '<table class="noborder centpercent">';
  122. print "<tr class=\"liste_titre\">";
  123. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
  124. print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
  125. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
  126. print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
  127. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
  128. print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
  129. print_liste_field_titre('');
  130. print "</tr>\n";
  131. // Filters lines
  132. print '<tr class="liste_titre">';
  133. print '<td class="liste_titre">';
  134. print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
  135. print '</td>';
  136. print '<td class="liste_titre">';
  137. print '&nbsp;';
  138. print '</td>';
  139. print '<td class="liste_titre" align="center">';
  140. if (getDolGlobalString('MAIN_LIST_FILTER_ON_DAY')) {
  141. print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  142. }
  143. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  144. print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
  145. print '</td>';
  146. print '<td class="liste_titre">';
  147. print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
  148. print '</td>';
  149. print '<td class="liste_titre">';
  150. print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
  151. print '</td>';
  152. print '<td class="liste_titre right">';
  153. // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
  154. print '</td>';
  155. print '<td class="liste_titre maxwidthsearch">';
  156. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  157. print $searchpicto;
  158. print '</td>';
  159. print "</tr>\n";
  160. while ($i < min($num, $limit)) {
  161. $obj = $db->fetch_object($resql);
  162. $soc = new Societe($db);
  163. if ($obj->socid) {
  164. $soc->fetch($obj->socid);
  165. }
  166. print '<tr class="oddeven">';
  167. // Id
  168. print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
  169. // Type
  170. print '<td>'.$langs->trans($obj->type).'</td>';
  171. // Date
  172. print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
  173. // User
  174. print '<td>';
  175. $userstatic->id = $obj->fk_user;
  176. $userstatic->lastname = $obj->lastname;
  177. $userstatic->firstname = $obj->firstname;
  178. print $userstatic->getNomUrl(1);
  179. print '</td>';
  180. if ($obj->socid) {
  181. print '<td>'.$soc->getNomUrl(1).'</td>';
  182. } else {
  183. print '<td>&nbsp;</td>';
  184. }
  185. print '<td class="right">'.$obj->km.'</td>';
  186. $tripandexpense_static->statut = $obj->fk_statut;
  187. print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
  188. print "</tr>\n";
  189. $i++;
  190. }
  191. print "</table>";
  192. print "</form>\n";
  193. $db->free($resql);
  194. } else {
  195. dol_print_error($db);
  196. }
  197. // End of page
  198. llxFooter();
  199. $db->close();