index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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@inodbox.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 <https://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. // Load translation files required by the page
  28. $langs->loadLangs(array('companies', 'users', 'trips'));
  29. // Security check
  30. $socid = GETPOST('socid', 'int');
  31. if ($user->socid) {
  32. $socid = $user->socid;
  33. }
  34. $result = restrictedArea($user, 'deplacement', '', '');
  35. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  36. $sortfield = GETPOST('sortfield', 'aZ09comma');
  37. $sortorder = GETPOST('sortorder', 'aZ09comma');
  38. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  39. if (empty($page) || $page == -1) {
  40. $page = 0;
  41. } // If $page is not defined, or '' or -1
  42. $offset = $limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (!$sortorder) {
  46. $sortorder = "DESC";
  47. }
  48. if (!$sortfield) {
  49. $sortfield = "d.dated";
  50. }
  51. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  52. /*
  53. * View
  54. */
  55. $tripandexpense_static = new Deplacement($db);
  56. $childids = $user->getAllChildIds();
  57. $childids[] = $user->id;
  58. //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
  59. $help_url = '';
  60. llxHeader('', $langs->trans("ListOfFees"), $help_url);
  61. $totalnb = 0;
  62. $sql = "SELECT count(d.rowid) as nb, sum(d.km) as km, d.type";
  63. $sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d";
  64. $sql .= " WHERE d.entity = ".$conf->entity;
  65. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
  66. $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  67. }
  68. $sql .= " GROUP BY d.type";
  69. $sql .= " ORDER BY d.type";
  70. $result = $db->query($sql);
  71. if ($result) {
  72. $num = $db->num_rows($result);
  73. $i = 0;
  74. while ($i < $num) {
  75. $objp = $db->fetch_object($result);
  76. $somme[$objp->type] = $objp->km;
  77. $nb[$objp->type] = $objp->nb;
  78. $totalnb += $objp->nb;
  79. $i++;
  80. }
  81. $db->free($result);
  82. } else {
  83. dol_print_error($db);
  84. }
  85. print load_fiche_titre($langs->trans("ExpensesArea"));
  86. print '<div class="fichecenter"><div class="fichethirdleft">';
  87. // Statistics
  88. print '<table class="noborder nohover centpercent">';
  89. print '<tr class="liste_titre">';
  90. print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
  91. print "</tr>\n";
  92. $listoftype = $tripandexpense_static->listOfTypes();
  93. foreach ($listoftype as $code => $label) {
  94. $dataseries[] = array($label, (isset($nb[$code]) ? (int) $nb[$code] : 0));
  95. }
  96. if ($conf->use_javascript_ajax) {
  97. print '<tr><td align="center" colspan="4">';
  98. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  99. $dolgraph = new DolGraph();
  100. $dolgraph->SetData($dataseries);
  101. $dolgraph->setShowLegend(2);
  102. $dolgraph->setShowPercent(1);
  103. $dolgraph->SetType(array('pie'));
  104. $dolgraph->setHeight('200');
  105. $dolgraph->draw('idgraphstatus');
  106. print $dolgraph->show($totalnb ? 0 : 1);
  107. print '</td></tr>';
  108. }
  109. print '<tr class="liste_total">';
  110. print '<td>'.$langs->trans("Total").'</td>';
  111. print '<td class="right">'.$totalnb.'</td>';
  112. print '</tr>';
  113. print '</table>';
  114. print '</div><div class="fichetwothirdright">';
  115. $max = 10;
  116. $langs->load("boxes");
  117. $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";
  118. $sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
  119. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  120. $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  121. }
  122. $sql .= " WHERE u.rowid = d.fk_user";
  123. $sql .= " AND d.entity = ".$conf->entity;
  124. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
  125. $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  126. }
  127. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  128. $sql .= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  129. }
  130. if ($socid) {
  131. $sql .= " AND d.fk_soc = ".((int) $socid);
  132. }
  133. $sql .= $db->order("d.tms", "DESC");
  134. $sql .= $db->plimit($max, 0);
  135. $result = $db->query($sql);
  136. if ($result) {
  137. $var = false;
  138. $num = $db->num_rows($result);
  139. $i = 0;
  140. print '<table class="noborder centpercent">';
  141. print '<tr class="liste_titre">';
  142. print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</td>';
  143. print '<td class="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
  144. print '<td class="right">'.$langs->trans("DateModificationShort").'</td>';
  145. print '<td width="16">&nbsp;</td>';
  146. print '</tr>';
  147. if ($num) {
  148. $total_ttc = $totalam = $total = 0;
  149. $deplacementstatic = new Deplacement($db);
  150. $userstatic = new User($db);
  151. while ($i < $num && $i < $max) {
  152. $obj = $db->fetch_object($result);
  153. $deplacementstatic->ref = $obj->rowid;
  154. $deplacementstatic->id = $obj->rowid;
  155. $userstatic->id = $obj->uid;
  156. $userstatic->lastname = $obj->lastname;
  157. $userstatic->firstname = $obj->firstname;
  158. print '<tr class="oddeven">';
  159. print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
  160. print '<td>'.$userstatic->getNomUrl(1).'</td>';
  161. print '<td class="right">'.$obj->km.'</td>';
  162. print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
  163. print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut, 3).'</td>';
  164. print '</tr>';
  165. $i++;
  166. }
  167. } else {
  168. print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  169. }
  170. print '</table><br>';
  171. } else {
  172. dol_print_error($db);
  173. }
  174. print '</div></div>';
  175. // End of page
  176. llxFooter();
  177. $db->close();