list.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('companies', 'users', 'trips'));
  33. // Security check
  34. $socid = GETPOST('socid', 'int');
  35. if ($user->socid) {
  36. $socid = $user->socid;
  37. }
  38. $result = restrictedArea($user, 'deplacement', '', '');
  39. $search_ref = GETPOST('search_ref', 'int');
  40. $search_name = GETPOST('search_name', 'alpha');
  41. $search_company = GETPOST('search_company', 'alpha');
  42. // $search_amount=GETPOST('search_amount','alpha');
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortorder) {
  54. $sortorder = "DESC";
  55. }
  56. if (!$sortfield) {
  57. $sortfield = "d.dated";
  58. }
  59. $year = GETPOST("year");
  60. $month = GETPOST("month");
  61. $day = GETPOST("day");
  62. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  63. $search_ref = "";
  64. $search_name = "";
  65. $search_company = "";
  66. // $search_amount="";
  67. $year = "";
  68. $month = "";
  69. $day = "";
  70. }
  71. /*
  72. * View
  73. */
  74. $formother = new FormOther($db);
  75. $tripandexpense_static = new Deplacement($db);
  76. $userstatic = new User($db);
  77. $childids = $user->getAllChildIds();
  78. $childids[] = $user->id;
  79. llxHeader();
  80. $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
  81. $sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
  82. $sql .= " d.fk_statut,";
  83. $sql .= " u.lastname, u.firstname"; // Qui
  84. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  85. $sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
  86. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
  87. if (empty($user->rights->societe->client->voir) && !$socid) {
  88. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  89. }
  90. $sql .= " WHERE d.fk_user = u.rowid";
  91. $sql .= " AND d.entity = ".$conf->entity;
  92. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
  93. $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  94. }
  95. if (empty($user->rights->societe->client->voir) && !$socid) {
  96. $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR d.fk_soc IS NULL) ";
  97. }
  98. if ($socid) {
  99. $sql .= " AND s.rowid = ".((int) $socid);
  100. }
  101. if ($search_ref) {
  102. $sql .= " AND d.rowid = ".((int) $search_ref);
  103. }
  104. if ($search_name) {
  105. $sql .= natural_search('u.lastname', $search_name);
  106. }
  107. if ($search_company) {
  108. $sql .= natural_search('s.nom', $search_company);
  109. }
  110. $sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
  111. $sql .= $db->order($sortfield, $sortorder);
  112. $sql .= $db->plimit($limit + 1, $offset);
  113. //print $sql;
  114. $resql = $db->query($sql);
  115. if ($resql) {
  116. $num = $db->num_rows($resql);
  117. print_barre_liste($langs->trans("ListOfFees"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
  118. $i = 0;
  119. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  120. print '<table class="noborder centpercent">';
  121. print "<tr class=\"liste_titre\">";
  122. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
  123. print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
  124. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
  125. print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
  126. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
  127. print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
  128. print_liste_field_titre('');
  129. print "</tr>\n";
  130. // Filters lines
  131. print '<tr class="liste_titre">';
  132. print '<td class="liste_titre">';
  133. print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
  134. print '</td>';
  135. print '<td class="liste_titre">';
  136. print '&nbsp;';
  137. print '</td>';
  138. print '<td class="liste_titre" align="center">';
  139. if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  140. print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  141. }
  142. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  143. print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
  144. print '</td>';
  145. print '<td class="liste_titre">';
  146. print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
  147. print '</td>';
  148. print '<td class="liste_titre">';
  149. print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
  150. print '</td>';
  151. print '<td class="liste_titre right">';
  152. // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
  153. print '</td>';
  154. print '<td class="liste_titre maxwidthsearch">';
  155. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  156. print $searchpicto;
  157. print '</td>';
  158. print "</tr>\n";
  159. while ($i < min($num, $limit)) {
  160. $obj = $db->fetch_object($resql);
  161. $soc = new Societe($db);
  162. if ($obj->socid) {
  163. $soc->fetch($obj->socid);
  164. }
  165. print '<tr class="oddeven">';
  166. // Id
  167. print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
  168. // Type
  169. print '<td>'.$langs->trans($obj->type).'</td>';
  170. // Date
  171. print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
  172. // User
  173. print '<td>';
  174. $userstatic->id = $obj->fk_user;
  175. $userstatic->lastname = $obj->lastname;
  176. $userstatic->firstname = $obj->firstname;
  177. print $userstatic->getNomUrl(1);
  178. print '</td>';
  179. if ($obj->socid) {
  180. print '<td>'.$soc->getNomUrl(1).'</td>';
  181. } else {
  182. print '<td>&nbsp;</td>';
  183. }
  184. print '<td class="right">'.$obj->km.'</td>';
  185. $tripandexpense_static->statut = $obj->fk_statut;
  186. print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
  187. print "</tr>\n";
  188. $i++;
  189. }
  190. print "</table>";
  191. print "</form>\n";
  192. $db->free($resql);
  193. } else {
  194. dol_print_error($db);
  195. }
  196. // End of page
  197. llxFooter();
  198. $db->close();