PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/dons/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 213 lines | 127 code | 49 blank | 37 comment | 9 complexity | ac6a4781c002cec74867e5e275bbb64b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. llxHeader('',$langs->trans("Donations"));
  39. $nb=array();
  40. $somme=array();
  41. $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
  42. $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
  43. $sql.= " GROUP BY d.fk_statut";
  44. $sql.= " ORDER BY d.fk_statut";
  45. $result = $db->query($sql);
  46. if ($result)
  47. {
  48. $i = 0;
  49. $num = $db->num_rows($result);
  50. while ($i < $num)
  51. {
  52. $objp = $db->fetch_object($result);
  53. $somme[$objp->fk_statut] = $objp->somme;
  54. $nb[$objp->fk_statut] = $objp->nb;
  55. $i++;
  56. }
  57. $db->free($result);
  58. } else {
  59. dol_print_error($db);
  60. }
  61. print_fiche_titre($langs->trans("DonationsArea"));
  62. print '<table width="100%" class="notopnoleftnoright">';
  63. // Left area
  64. print '<tr><td class="notopnoleft" width="30%" valign="top">';
  65. print '<table class="noborder" width="100%">';
  66. print '<tr class="liste_titre">';
  67. print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
  68. print "</tr>\n";
  69. $listofstatus=array(0,1,-1,2);
  70. foreach ($listofstatus as $status)
  71. {
  72. $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'data'=>(isset($nb[$status])?(int) $nb[$status]:0));
  73. }
  74. if ($conf->use_javascript_ajax)
  75. {
  76. print '<tr><td align="center" colspan="4">';
  77. $data=array('series'=>$dataseries);
  78. dol_print_graph('stats',300,180,$data,1,'pie',1);
  79. print '</td></tr>';
  80. }
  81. print '<tr class="liste_titre">';
  82. print '<td>'.$langs->trans("Status").'</td>';
  83. print '<td align="right">'.$langs->trans("Number").'</td>';
  84. print '<td align="right">'.$langs->trans("Total").'</td>';
  85. print '<td align="right">'.$langs->trans("Average").'</td>';
  86. print '</tr>';
  87. $total=0;
  88. $totalnb=0;
  89. $var=true;
  90. foreach ($listofstatus as $status)
  91. {
  92. $var=!$var;
  93. print "<tr ".$bc[$var].">";
  94. print '<td><a href="liste.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>';
  95. print '<td align="right">'.(! empty($nb[$status])?$nb[$status]:'&nbsp;').'</td>';
  96. print '<td align="right">'.(! empty($nb[$status])?price($somme[$status],'MT'):'&nbsp;').'</td>';
  97. print '<td align="right">'.(! empty($nb[$status])?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>';
  98. $totalnb += (! empty($nb[$status])?$nb[$status]:0);
  99. $total += (! empty($somme[$status])?$somme[$status]:0);
  100. print "</tr>";
  101. }
  102. print '<tr class="liste_total">';
  103. print '<td>'.$langs->trans("Total").'</td>';
  104. print '<td align="right">'.$totalnb.'</td>';
  105. print '<td align="right">'.price($total,'MT').'</td>';
  106. print '<td align="right">'.($totalnb?price(price2num($total/$totalnb,'MT')):'&nbsp;').'</td>';
  107. print '</tr>';
  108. print "</table>";
  109. // Right area
  110. print '</td><td valign="top">';
  111. $max=10;
  112. /*
  113. * Last modified donations
  114. */
  115. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.nom,";
  116. $sql.= " tms as datem, 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="nowrap">';
  141. print $donation_static->getNomUrl(1);
  142. print '</td>';
  143. print '<td class="nobordernopadding">';
  144. print $obj->societe;
  145. print ($obj->societe && $obj->nom?' / ':'');
  146. print $obj->nom;
  147. print '</td>';
  148. print '<td width="16" 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();
  164. ?>