index.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 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@capnetworks.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/deplacement/index.php
  22. * \brief Page list of expenses
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  27. $langs->load("companies");
  28. $langs->load("users");
  29. $langs->load("trips");
  30. // Security check
  31. $socid = GETPOST('socid','int');
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result = restrictedArea($user, 'deplacement','','');
  34. $sortfield = GETPOST("sortfield",'alpha');
  35. $sortorder = GETPOST("sortorder",'alpha');
  36. $page = GETPOST("page",'int');
  37. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  38. $offset = $conf->liste_limit * $page;
  39. $pageprev = $page - 1;
  40. $pagenext = $page + 1;
  41. if (! $sortorder) $sortorder="DESC";
  42. if (! $sortfield) $sortfield="d.dated";
  43. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  44. /*
  45. * View
  46. */
  47. $tripandexpense_static=new Deplacement($db);
  48. $childids = $user->getAllChildIds();
  49. $childids[]=$user->id;
  50. //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
  51. $help_url='';
  52. llxHeader('',$langs->trans("ListOfFees"),$help_url);
  53. $totalnb=0;
  54. $sql = "SELECT count(d.rowid) as nb, sum(d.km) as km, d.type";
  55. $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d";
  56. $sql.= " WHERE d.entity = ".$conf->entity;
  57. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
  58. $sql.= " GROUP BY d.type";
  59. $sql.= " ORDER BY d.type";
  60. $result = $db->query($sql);
  61. if ($result)
  62. {
  63. $num = $db->num_rows($result);
  64. $i = 0;
  65. while ($i < $num)
  66. {
  67. $objp = $db->fetch_object($result);
  68. $somme[$objp->type] = $objp->km;
  69. $nb[$objp->type] = $objp->nb;
  70. $totalnb += $objp->nb;
  71. $i++;
  72. }
  73. $db->free($result);
  74. } else {
  75. dol_print_error($db);
  76. }
  77. print load_fiche_titre($langs->trans("ExpensesArea"));
  78. print '<div class="fichecenter"><div class="fichethirdleft">';
  79. // Statistics
  80. print '<table class="noborder nohover" width="100%">';
  81. print '<tr class="liste_titre">';
  82. print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
  83. print "</tr>\n";
  84. $listoftype=$tripandexpense_static->listOfTypes();
  85. foreach ($listoftype as $code => $label)
  86. {
  87. $dataseries[]=array('label'=>$label,'data'=>(isset($nb[$code])?(int) $nb[$code]:0));
  88. }
  89. if ($conf->use_javascript_ajax)
  90. {
  91. print '<tr '.$bc[false].'><td align="center" colspan="4">';
  92. $data=array('series'=>$dataseries);
  93. dol_print_graph('stats',300,180,$data,1,'pie',1);
  94. print '</td></tr>';
  95. }
  96. print '<tr class="liste_total">';
  97. print '<td>'.$langs->trans("Total").'</td>';
  98. print '<td align="right">'.$totalnb.'</td>';
  99. print '</tr>';
  100. print '</table>';
  101. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  102. $max=10;
  103. $langs->load("boxes");
  104. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, d.rowid, d.dated as date, d.tms as dm, d.km, d.fk_statut";
  105. $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
  106. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  107. $sql.= " WHERE u.rowid = d.fk_user";
  108. $sql.= " AND d.entity = ".$conf->entity;
  109. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
  110. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  111. if ($socid) $sql.= " AND d.fk_soc = ".$socid;
  112. $sql.= $db->order("d.tms","DESC");
  113. $sql.= $db->plimit($max, 0);
  114. $result = $db->query($sql);
  115. if ($result)
  116. {
  117. $var=false;
  118. $num = $db->num_rows($result);
  119. $i = 0;
  120. print '<table class="noborder" width="100%">';
  121. print '<tr class="liste_titre">';
  122. print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</td>';
  123. print '<td align="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
  124. print '<td align="right">'.$langs->trans("DateModificationShort").'</td>';
  125. print '<td width="16">&nbsp;</td>';
  126. print '</tr>';
  127. if ($num)
  128. {
  129. $total_ttc = $totalam = $total = 0;
  130. $deplacementstatic=new Deplacement($db);
  131. $userstatic=new User($db);
  132. while ($i < $num && $i < $max)
  133. {
  134. $obj = $db->fetch_object($result);
  135. $deplacementstatic->ref=$obj->rowid;
  136. $deplacementstatic->id=$obj->rowid;
  137. $userstatic->id=$obj->uid;
  138. $userstatic->lastname=$obj->lastname;
  139. $userstatic->firstname=$obj->firstname;
  140. print '<tr class="oddeven">';
  141. print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
  142. print '<td>'.$userstatic->getNomUrl(1).'</td>';
  143. print '<td align="right">'.$obj->km.'</td>';
  144. print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
  145. print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut,3).'</td>';
  146. print '</tr>';
  147. $i++;
  148. }
  149. }
  150. else
  151. {
  152. print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  153. }
  154. print '</table><br>';
  155. }
  156. else dol_print_error($db);
  157. print '</div></div></div>';
  158. llxFooter();
  159. $db->close();