index.php 7.9 KB

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