index.php 6.5 KB

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