index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/dons/index.php
  21. * \ingroup don
  22. * \brief Home page of donation module
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php';
  26. $langs->load("donations");
  27. // Security check
  28. $result = restrictedArea($user, 'don');
  29. $donation_static=new Don($db);
  30. /*
  31. * Actions
  32. */
  33. // None
  34. /*
  35. * View
  36. */
  37. $donstatic=new Don($db);
  38. $help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
  39. llxHeader('',$langs->trans("Donations"),$help_url);
  40. $nb=array();
  41. $somme=array();
  42. $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
  43. $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
  44. $sql.= " GROUP BY d.fk_statut";
  45. $sql.= " ORDER BY d.fk_statut";
  46. $result = $db->query($sql);
  47. if ($result)
  48. {
  49. $i = 0;
  50. $num = $db->num_rows($result);
  51. while ($i < $num)
  52. {
  53. $objp = $db->fetch_object($result);
  54. $somme[$objp->fk_statut] = $objp->somme;
  55. $nb[$objp->fk_statut] = $objp->nb;
  56. $i++;
  57. }
  58. $db->free($result);
  59. } else {
  60. dol_print_error($db);
  61. }
  62. print_fiche_titre($langs->trans("DonationsArea"));
  63. print '<table width="100%" class="notopnoleftnoright">';
  64. // Left area
  65. print '<tr><td class="notopnoleft" width="30%" valign="top">';
  66. print '<table class="noborder" width="100%">';
  67. print '<tr class="liste_titre">';
  68. print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
  69. print "</tr>\n";
  70. $listofstatus=array(0,1,-1,2);
  71. foreach ($listofstatus as $status)
  72. {
  73. $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'data'=>(isset($nb[$status])?(int) $nb[$status]:0));
  74. }
  75. if ($conf->use_javascript_ajax)
  76. {
  77. print '<tr><td align="center" colspan="4">';
  78. $data=array('series'=>$dataseries);
  79. dol_print_graph('stats',300,180,$data,1,'pie',1);
  80. print '</td></tr>';
  81. }
  82. print '<tr class="liste_titre">';
  83. print '<td>'.$langs->trans("Status").'</td>';
  84. print '<td align="right">'.$langs->trans("Number").'</td>';
  85. print '<td align="right">'.$langs->trans("Total").'</td>';
  86. print '<td align="right">'.$langs->trans("Average").'</td>';
  87. print '</tr>';
  88. $total=0;
  89. $totalnb=0;
  90. $var=true;
  91. foreach ($listofstatus as $status)
  92. {
  93. $var=!$var;
  94. print "<tr ".$bc[$var].">";
  95. print '<td><a href="list.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>';
  96. print '<td align="right">'.(! empty($nb[$status])?$nb[$status]:'&nbsp;').'</td>';
  97. print '<td align="right">'.(! empty($nb[$status])?price($somme[$status],'MT'):'&nbsp;').'</td>';
  98. print '<td align="right">'.(! empty($nb[$status])?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>';
  99. $totalnb += (! empty($nb[$status])?$nb[$status]:0);
  100. $total += (! empty($somme[$status])?$somme[$status]:0);
  101. print "</tr>";
  102. }
  103. print '<tr class="liste_total">';
  104. print '<td>'.$langs->trans("Total").'</td>';
  105. print '<td align="right">'.$totalnb.'</td>';
  106. print '<td align="right">'.price($total,'MT').'</td>';
  107. print '<td align="right">'.($totalnb?price(price2num($total/$totalnb,'MT')):'&nbsp;').'</td>';
  108. print '</tr>';
  109. print "</table>";
  110. // Right area
  111. print '</td><td valign="top">';
  112. $max=10;
  113. /*
  114. * Last modified donations
  115. */
  116. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
  117. $sql.= " FROM ".MAIN_DB_PREFIX."don as c";
  118. $sql.= " WHERE c.entity = ".$conf->entity;
  119. //$sql.= " AND c.fk_statut > 2";
  120. $sql.= " ORDER BY c.tms DESC";
  121. $sql.= $db->plimit($max, 0);
  122. $resql=$db->query($sql);
  123. if ($resql)
  124. {
  125. print '<table class="noborder" width="100%">';
  126. print '<tr class="liste_titre">';
  127. print '<td colspan="5">'.$langs->trans("LastModifiedDonations",$max).'</td></tr>';
  128. $num = $db->num_rows($resql);
  129. if ($num)
  130. {
  131. $i = 0;
  132. $var = True;
  133. while ($i < $num)
  134. {
  135. $var=!$var;
  136. $obj = $db->fetch_object($resql);
  137. print "<tr ".$bc[$var].">";
  138. $donation_static->id=$obj->rowid;
  139. $donation_static->ref=$obj->ref?$obj->ref:$obj->rowid;
  140. print '<td width="96" class="nobordernopadding nowrap">';
  141. print $donation_static->getNomUrl(1);
  142. print '</td>';
  143. print '<td class="nobordernopadding">';
  144. print $obj->societe;
  145. print ($obj->societe && ($obj->lastname || $obj->firstname)?' / ':'');
  146. print dolGetFirstLastname($obj->lastname,$obj->firstname);
  147. print '</td>';
  148. print '<td align="right" class="nobordernopadding">';
  149. print price($obj->amount,1);
  150. print '</td>';
  151. // Date
  152. print '<td align="center">'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
  153. print '<td align="right">'.$donation_static->LibStatut($obj->fk_statut,5).'</td>';
  154. print '</tr>';
  155. $i++;
  156. }
  157. }
  158. print "</table><br>";
  159. }
  160. else dol_print_error($db);
  161. print '</td></tr></table>';
  162. llxFooter();
  163. $db->close();