index.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * 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. * or see http://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/expensereport/index.php
  24. * \ingroup expensereport
  25. * \brief Page list of expenses
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  30. $langs->load("companies");
  31. $langs->load("users");
  32. $langs->load("trips");
  33. // Security check
  34. $socid = GETPOST('socid','int');
  35. if ($user->societe_id) $socid=$user->societe_id;
  36. $result = restrictedArea($user, 'expensereport','','');
  37. $sortfield = GETPOST("sortfield",'alpha');
  38. $sortorder = GETPOST("sortorder",'alpha');
  39. $page = GETPOST("page",'int');
  40. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  41. $offset = $conf->liste_limit * $page;
  42. $pageprev = $page - 1;
  43. $pagenext = $page + 1;
  44. if (! $sortorder) $sortorder="DESC";
  45. if (! $sortfield) $sortfield="d.date_create";
  46. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  47. /*
  48. * View
  49. */
  50. $tripandexpense_static=new ExpenseReport($db);
  51. $childids = $user->getAllChildIds();
  52. $childids[]=$user->id;
  53. //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
  54. $help_url='';
  55. llxHeader('',$langs->trans("ListOfFees"),$help_url);
  56. $label=$somme=$nb=array();
  57. $totalnb=$totalsum=0;
  58. $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
  59. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
  60. $sql.= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
  61. // RESTRICT RIGHTS
  62. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
  63. && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
  64. {
  65. $childids = $user->getAllChildIds();
  66. $childids[]=$user->id;
  67. $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
  68. }
  69. $sql.= " GROUP BY tf.code, tf.label";
  70. $result = $db->query($sql);
  71. if ($result)
  72. {
  73. $num = $db->num_rows($result);
  74. $i = 0;
  75. while ($i < $num)
  76. {
  77. $objp = $db->fetch_object($result);
  78. $somme[$objp->code] = $objp->km;
  79. $nb[$objp->code] = $objp->nb;
  80. $label[$objp->code] = $objp->label;
  81. $totalnb += $objp->nb;
  82. $totalsum += $objp->km;
  83. $i++;
  84. }
  85. $db->free($result);
  86. } else {
  87. dol_print_error($db);
  88. }
  89. print load_fiche_titre($langs->trans("ExpensesArea"));
  90. print '<div class="fichecenter"><div class="fichethirdleft">';
  91. print '<table class="noborder nohover" width="100%">';
  92. print '<tr class="liste_titre">';
  93. print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
  94. print "</tr>\n";
  95. $listoftype=$tripandexpense_static->listOfTypes();
  96. foreach ($listoftype as $code => $label)
  97. {
  98. $dataseries[]=array('label'=>$label,'data'=>(isset($somme[$code])?(int) $somme[$code]:0));
  99. }
  100. if ($conf->use_javascript_ajax)
  101. {
  102. print '<tr '.$bc[0].'><td align="center" colspan="4">';
  103. $data=array('series'=>$dataseries);
  104. dol_print_graph('stats',320,180,$data,1,'pie',0,'',0);
  105. print '</td></tr>';
  106. }
  107. print '<tr class="liste_total">';
  108. print '<td>'.$langs->trans("Total").'</td>';
  109. print '<td align="right" colspan="3">'.price($totalsum,1,$langs,0,0,0,$conf->currency).'</td>';
  110. print '</tr>';
  111. print '</table>';
  112. // Right area
  113. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  114. $max=10;
  115. $langs->load("boxes");
  116. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut, u.photo, d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as fk_status";
  117. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
  118. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  119. $sql.= " WHERE u.rowid = d.fk_user_author";
  120. // RESTRICT RIGHTS
  121. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
  122. && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
  123. {
  124. $childids = $user->getAllChildIds();
  125. $childids[]=$user->id;
  126. $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
  127. }
  128. $sql.= ' AND d.entity IN ('.getEntity('expensereport').')';
  129. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  130. if ($socid) $sql.= " AND d.fk_user_author = ".$socid;
  131. $sql.= $db->order($sortfield,$sortorder);
  132. $sql.= $db->plimit($max, 0);
  133. $result = $db->query($sql);
  134. if ($result)
  135. {
  136. $var=false;
  137. $num = $db->num_rows($result);
  138. $i = 0;
  139. print '<table class="noborder" width="100%">';
  140. print '<tr class="liste_titre">';
  141. print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
  142. print '<th align="right">'.$langs->trans("AmountHT").'</th>';
  143. print '<th align="right">'.$langs->trans("AmountTTC").'</th>';
  144. print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
  145. print '<th>&nbsp;</th>';
  146. print '</tr>';
  147. if ($num)
  148. {
  149. $total_ttc = $totalam = $total = 0;
  150. $expensereportstatic=new ExpenseReport($db);
  151. $userstatic=new User($db);
  152. while ($i < $num && $i < $max)
  153. {
  154. $obj = $db->fetch_object($result);
  155. $expensereportstatic->id=$obj->rowid;
  156. $expensereportstatic->ref=$obj->ref;
  157. $userstatic->id=$obj->uid;
  158. $userstatic->lastname=$obj->lastname;
  159. $userstatic->firstname=$obj->firstname;
  160. $userstatic->login=$obj->login;
  161. $userstatic->statut=$obj->statut;
  162. $userstatic->photo=$obj->photo;
  163. print '<tr class="oddeven">';
  164. print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
  165. print '<td>'.$userstatic->getNomUrl(-1).'</td>';
  166. print '<td align="right">'.price($obj->total_ht).'</td>';
  167. print '<td align="right">'.price($obj->total_ttc).'</td>';
  168. print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
  169. print '<td align="right">';
  170. //print $obj->libelle;
  171. print $expensereportstatic->LibStatut($obj->fk_status,3);
  172. print '</td>';
  173. print '</tr>';
  174. $i++;
  175. }
  176. }
  177. else
  178. {
  179. print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  180. }
  181. print '</table><br>';
  182. }
  183. else dol_print_error($db);
  184. print '</div></div></div>';
  185. llxFooter();
  186. $db->close();