index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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/don/index.php
  21. * \ingroup donations
  22. * \brief Home page of donation module
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/don/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. $total = 0;
  43. $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
  44. $sql.= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
  45. $sql.= " GROUP BY d.fk_statut";
  46. $sql.= " ORDER BY d.fk_statut";
  47. $result = $db->query($sql);
  48. if ($result)
  49. {
  50. $i = 0;
  51. $num = $db->num_rows($result);
  52. while ($i < $num)
  53. {
  54. $objp = $db->fetch_object($result);
  55. $somme[$objp->fk_statut] = $objp->somme;
  56. $nb[$objp->fk_statut] = $objp->nb;
  57. $total += $objp->somme;
  58. $i++;
  59. }
  60. $db->free($result);
  61. } else {
  62. dol_print_error($db);
  63. }
  64. print load_fiche_titre($langs->trans("DonationsArea"));
  65. print '<div class="fichecenter"><div class="fichethirdleft">';
  66. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  67. {
  68. if (! empty($conf->don->enabled) && $user->rights->don->lire)
  69. {
  70. $listofsearchfields['search_donation']=array('text'=>'Donation');
  71. }
  72. if (count($listofsearchfields))
  73. {
  74. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  75. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  76. print '<table class="noborder nohover centpercent">';
  77. $i=0;
  78. foreach($listofsearchfields as $key => $value)
  79. {
  80. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  81. print '<tr '.$bc[false].'>';
  82. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'"></td>';
  83. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  84. print '</tr>';
  85. $i++;
  86. }
  87. print '</table>';
  88. print '</form>';
  89. print '<br>';
  90. }
  91. }
  92. print '<table class="noborder nohover" width="100%">';
  93. print '<tr class="liste_titre">';
  94. print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
  95. print "</tr>\n";
  96. $listofstatus=array(0,1,-1,2);
  97. foreach ($listofstatus as $status)
  98. {
  99. $dataseries[]=array($donstatic->LibStatut($status,1), (isset($nb[$status])?(int) $nb[$status]:0));
  100. }
  101. if ($conf->use_javascript_ajax)
  102. {
  103. print '<tr><td align="center" colspan="4">';
  104. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  105. $dolgraph = new DolGraph();
  106. $dolgraph->SetData($dataseries);
  107. $dolgraph->setShowLegend(1);
  108. $dolgraph->setShowPercent(1);
  109. $dolgraph->SetType(array('pie'));
  110. $dolgraph->setWidth('100%');
  111. $dolgraph->draw('idgraphstatus');
  112. print $dolgraph->show($total?0:1);
  113. print '</td></tr>';
  114. }
  115. print '<tr class="liste_titre">';
  116. print '<td>'.$langs->trans("Status").'</td>';
  117. print '<td align="right">'.$langs->trans("Number").'</td>';
  118. print '<td align="right">'.$langs->trans("Total").'</td>';
  119. print '<td align="right">'.$langs->trans("Average").'</td>';
  120. print '</tr>';
  121. $total=0;
  122. $totalnb=0;
  123. foreach ($listofstatus as $status)
  124. {
  125. print '<tr class="oddeven">';
  126. print '<td><a href="list.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>';
  127. print '<td align="right">'.(! empty($nb[$status])?$nb[$status]:'&nbsp;').'</td>';
  128. print '<td align="right">'.(! empty($nb[$status])?price($somme[$status],'MT'):'&nbsp;').'</td>';
  129. print '<td align="right">'.(! empty($nb[$status])?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>';
  130. $totalnb += (! empty($nb[$status])?$nb[$status]:0);
  131. $total += (! empty($somme[$status])?$somme[$status]:0);
  132. print "</tr>";
  133. }
  134. print '<tr class="liste_total">';
  135. print '<td>'.$langs->trans("Total").'</td>';
  136. print '<td align="right">'.$totalnb.'</td>';
  137. print '<td align="right">'.price($total,'MT').'</td>';
  138. print '<td align="right">'.($totalnb?price(price2num($total/$totalnb,'MT')):'&nbsp;').'</td>';
  139. print '</tr>';
  140. print "</table>";
  141. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  142. $max=10;
  143. /*
  144. * Last modified donations
  145. */
  146. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
  147. $sql.= " FROM ".MAIN_DB_PREFIX."don as c";
  148. $sql.= " WHERE c.entity = ".$conf->entity;
  149. //$sql.= " AND c.fk_statut > 2";
  150. $sql.= " ORDER BY c.tms DESC";
  151. $sql.= $db->plimit($max, 0);
  152. $resql=$db->query($sql);
  153. if ($resql)
  154. {
  155. print '<table class="noborder" width="100%">';
  156. print '<tr class="liste_titre">';
  157. print '<th colspan="5">'.$langs->trans("LastModifiedDonations",$max).'</th></tr>';
  158. $num = $db->num_rows($resql);
  159. if ($num)
  160. {
  161. $i = 0;
  162. while ($i < $num)
  163. {
  164. $obj = $db->fetch_object($resql);
  165. print '<tr class="oddeven">';
  166. $donation_static->id=$obj->rowid;
  167. $donation_static->ref=$obj->ref?$obj->ref:$obj->rowid;
  168. print '<td width="96" class="nobordernopadding nowrap">';
  169. print $donation_static->getNomUrl(1);
  170. print '</td>';
  171. print '<td class="nobordernopadding">';
  172. print $obj->societe;
  173. print ($obj->societe && ($obj->lastname || $obj->firstname)?' / ':'');
  174. print dolGetFirstLastname($obj->lastname,$obj->firstname);
  175. print '</td>';
  176. print '<td align="right" class="nobordernopadding">';
  177. print price($obj->amount,1);
  178. print '</td>';
  179. // Date
  180. print '<td align="center">'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
  181. print '<td align="right">'.$donation_static->LibStatut($obj->fk_statut,5).'</td>';
  182. print '</tr>';
  183. $i++;
  184. }
  185. }
  186. print "</table><br>";
  187. }
  188. else dol_print_error($db);
  189. print '</div></div></div>';
  190. llxFooter();
  191. $db->close();