list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/expensereport/index.php
  23. * \ingroup expensereport
  24. * \brief list of expense reports
  25. */
  26. require "../main.inc.php";
  27. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  30. $langs->load("companies");
  31. $langs->load("users");
  32. $langs->load("trips");
  33. // Security check
  34. $socid = $_GET["socid"]?$_GET["socid"]:'';
  35. if ($user->societe_id) $socid=$user->societe_id;
  36. $result = restrictedArea($user, 'expensereport','','');
  37. $search_ref = GETPOST('search_ref');
  38. $search_user = GETPOST('search_user','int');
  39. $search_amount_ht = GETPOST('search_amount_ht','alpha');
  40. $search_amount_ttc = GETPOST('search_amount_ttc','alpha');
  41. $search_status = (GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha'));
  42. $month_start = GETPOST("month_start","int");
  43. $year_start = GETPOST("year_start","int");
  44. $month_end = GETPOST("month_end","int");
  45. $year_end = GETPOST("year_end","int");
  46. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test must be present to be compatible with all browsers
  47. {
  48. $search_ref="";
  49. $search_user="";
  50. $search_amount_ht="";
  51. $search_amount_ttc="";
  52. $search_status="";
  53. $month_start="";
  54. $year_start="";
  55. $month_end="";
  56. $year_end="";
  57. }
  58. if ($search_status == '') $search_status=-1;
  59. if ($search_user == '') $search_user=-1;
  60. /*
  61. * View
  62. */
  63. $html = new Form($db);
  64. $formother = new FormOther($db);
  65. $expensereporttmp=new ExpenseReport($db);
  66. llxHeader('', $langs->trans("ListOfTrips"));
  67. $max_year = 5;
  68. $min_year = 5;
  69. $sortorder = GETPOST("sortorder");
  70. $sortfield = GETPOST("sortfield");
  71. $page = GETPOST("page");
  72. if (!$sortorder) $sortorder="DESC";
  73. if (!$sortfield) $sortfield="d.date_debut";
  74. if ($page == -1) {
  75. $page = 0 ;
  76. }
  77. $offset = $conf->liste_limit * $page;
  78. $pageprev = $page - 1;
  79. $pagenext = $page + 1;
  80. $limit = $conf->liste_limit;
  81. $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,";
  82. $sql.= " d.date_debut, d.date_fin,";
  83. $sql.= " u.rowid as id_user, u.firstname, u.lastname";
  84. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
  85. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid";
  86. $sql.= " WHERE d.entity = ".$conf->entity;
  87. // Ref
  88. if(!empty($search_ref)){
  89. $sql.= " AND d.ref LIKE '%".$db->escape($search_ref)."%'";
  90. }
  91. // Date Start
  92. if ($month_start > 0)
  93. {
  94. if ($year_start > 0 && empty($day))
  95. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,false))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,false))."'";
  96. else if ($year_start > 0 && ! empty($day))
  97. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_start, $day, $year_start))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_start, $day, $year_start))."'";
  98. else
  99. $sql.= " AND date_format(d.date_debut, '%m') = '".$month_start."'";
  100. }
  101. else if ($year_start > 0)
  102. {
  103. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,false))."' AND '".$db->idate(dol_get_last_day($year_start,12,false))."'";
  104. }
  105. // Date Start
  106. if ($month_end > 0)
  107. {
  108. if ($year_end > 0 && empty($day))
  109. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,false))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,false))."'";
  110. else if ($year_end > 0 && ! empty($day))
  111. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_end, $day, $year_end))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_end, $day, $year_end))."'";
  112. else
  113. $sql.= " AND date_format(d.date_fin, '%m') = '".$month_end."'";
  114. }
  115. else if ($year_end > 0)
  116. {
  117. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'";
  118. }
  119. // Amount
  120. if ($search_amount_ht != '')
  121. {
  122. $sql.= natural_search('d.total_ht', $search_amount_ht, 1);
  123. }
  124. if ($search_amount_ttc != '')
  125. {
  126. $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1);
  127. }
  128. // User
  129. if ($search_user != '' && $search_user >= 0)
  130. {
  131. $sql.= " AND u.rowid = '".$db->escape($search_user)."'";
  132. }
  133. // Status
  134. if ($search_status != '' && $search_status >= 0)
  135. {
  136. if (strstr($search_status, ',')) $sql.=" AND d.fk_statut IN (".$db->escape($search_status).")";
  137. else $sql.=" AND d.fk_statut = ".$search_status;
  138. }
  139. // RESTRICT RIGHTS
  140. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous))
  141. {
  142. $childids = $user->getAllChildIds();
  143. $childids[]=$user->id;
  144. $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
  145. }
  146. $sql.= $db->order($sortfield,$sortorder);
  147. $sql.= $db->plimit($limit+1, $offset);
  148. //print $sql;
  149. $resql=$db->query($sql);
  150. if ($resql)
  151. {
  152. $num = $db->num_rows($resql);
  153. $i = 0;
  154. $param="";
  155. if ($search_ref) $param.="&search_ref=".$search_ref;
  156. if ($search_user) $param.="&search_user=".$search_user;
  157. if ($search_amount_ht) $param.="&search_amount_ht=".$search_amount_ht;
  158. if ($search_amount_ttc) $param.="&search_amount_ttc=".$search_amount_ttc;
  159. if ($search_status >= 0) $param.="&search_status=".$search_status;
  160. print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
  161. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  162. print '<table class="noborder" width="100%">';
  163. print "<tr class=\"liste_titre\">";
  164. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","",$param,'',$sortfield,$sortorder);
  165. print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"d.date_debut","",$param,'align="center"',$sortfield,$sortorder);
  166. print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"d.date_fin","",$param,'align="center"',$sortfield,$sortorder);
  167. print_liste_field_titre($langs->trans("Person"),$_SERVER["PHP_SELF"],"u.lastname","",$param,'',$sortfield,$sortorder);
  168. print_liste_field_titre($langs->trans("TotalHT"),$_SERVER["PHP_SELF"],"d.total_ht","",$param,'align="right"',$sortfield,$sortorder);
  169. print_liste_field_titre($langs->trans("TotalVAT"),$_SERVER["PHP_SELF"],"d.total_tva","",$param,'align="right"',$sortfield,$sortorder);
  170. print_liste_field_titre($langs->trans("TotalTTC"),$_SERVER["PHP_SELF"],"d.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
  171. print_liste_field_titre($langs->trans("Statut"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder);
  172. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  173. print "</tr>\n";
  174. // Filters
  175. print '<tr class="liste_titre">';
  176. print '<td class="liste_titre" align="left">';
  177. print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
  178. // Date start
  179. print '<td class="liste_titre" align="center">';
  180. print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
  181. $formother->select_year($year_start,'year_start',1, $min_year, $max_year);
  182. print '</td>';
  183. // Date end
  184. print '<td class="liste_titre" align="center">';
  185. print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  186. $formother->select_year($year_end,'year_end',1, $min_year, $max_year);
  187. print '</td>';
  188. // User
  189. if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous){
  190. print '<td class="liste_titre" align="left">';
  191. $html->select_users($search_user,"search_user",1,"",0,'');
  192. print '</td>';
  193. } else {
  194. print '<td class="liste_titre">&nbsp;</td>';
  195. }
  196. // Amount with no tax
  197. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="6" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
  198. print '<td class="liste_titre">&nbsp;</td>';
  199. // Amount with all taxes
  200. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="6" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
  201. // Status
  202. print '<td class="liste_titre" align="right">';
  203. select_expensereport_statut($search_status,'search_status');
  204. print '</td>';
  205. print '<td class="liste_titre" align="right">';
  206. print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  207. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  208. print '</td>';
  209. print "</tr>\n";
  210. $var=true;
  211. $total_total_ht = 0;
  212. $total_total_ttc = 0;
  213. $total_total_tva = 0;
  214. $expensereportstatic=new ExpenseReport($db);
  215. if($num > 0)
  216. {
  217. while ($i < min($num,$limit))
  218. {
  219. $objp = $db->fetch_object($resql);
  220. $expensereportstatic->id=$objp->rowid;
  221. $expensereportstatic->ref=$objp->ref;
  222. $var=!$var;
  223. print "<tr ".$bc[$var].">";
  224. print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
  225. print '<td align="center">'.($objp->date_debut > 0 ? dol_print_date($objp->date_debut, 'day') : '').'</td>';
  226. print '<td align="center">'.($objp->date_fin > 0 ? dol_print_date($objp->date_fin, 'day') : '').'</td>';
  227. print '<td align="left"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objp->id_user.'">'.img_object($langs->trans("ShowUser"),"user").' '.dolGetFirstLastname($objp->firstname, $objp->lastname).'</a></td>';
  228. print '<td align="right">'.price($objp->total_ht).'</td>';
  229. print '<td align="right">'.price($objp->total_tva).'</td>';
  230. print '<td align="right">'.price($objp->total_ttc).'</td>';
  231. $expensereporttmp->status=$objp->status;
  232. print '<td align="right">';
  233. //print $objp->status;
  234. print $expensereporttmp->getLibStatut(5);
  235. print '</td>';
  236. print '<td></td>';
  237. print "</tr>\n";
  238. $total_total_ht = $total_total_ht + $objp->total_ht;
  239. $total_total_tva = $total_total_tva + $objp->total_tva;
  240. $total_total_ttc = $total_total_ttc + $objp->total_ttc;
  241. $i++;
  242. }
  243. print '<tr class="liste_total">';
  244. print '<td colspan="4">'.$langs->trans("Total").'</td>';
  245. print '<td style="text-align:right;">'.price($total_total_ht).'</td>';
  246. print '<td style="text-align:right;">'.price($total_total_tva).'</td>';
  247. print '<td style="text-align:right;">'.price($total_total_ttc).'</td>';
  248. print '<td></td>';
  249. print '<td></td>';
  250. print '</tr>';
  251. }
  252. else
  253. {
  254. print '<tr '.$bc[false].'>'.'<td colspan="9">'.$langs->trans("NoRecordFound").'</td></tr>';
  255. }
  256. print "</table>";
  257. print "</form>";
  258. print '<div class="tabsAction">';
  259. print '<a href="'.dol_buildpath('/expensereport/card.php',1).'?action=create" class="butAction">'.$langs->trans("NewTrip").'</a>';
  260. print '</div>';
  261. $db->free($resql);
  262. }
  263. else
  264. {
  265. dol_print_error($db);
  266. }
  267. llxFooter();
  268. $db->close();