index.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/don/index.php
  22. * \ingroup donations
  23. * \brief Home page of donation module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  27. $hookmanager = new HookManager($db);
  28. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  29. $hookmanager->initHooks(array('donationindex'));
  30. $langs->load("donations");
  31. // Security check
  32. $result = restrictedArea($user, 'don');
  33. $donation_static = new Don($db);
  34. /*
  35. * Actions
  36. */
  37. // None
  38. /*
  39. * View
  40. */
  41. $donstatic = new Don($db);
  42. $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
  43. llxHeader('', $langs->trans("Donations"), $help_url);
  44. $nb = array();
  45. $somme = array();
  46. $total = 0;
  47. $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
  48. $sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
  49. $sql .= " GROUP BY d.fk_statut";
  50. $sql .= " ORDER BY d.fk_statut";
  51. $result = $db->query($sql);
  52. if ($result) {
  53. $i = 0;
  54. $num = $db->num_rows($result);
  55. while ($i < $num) {
  56. $objp = $db->fetch_object($result);
  57. $somme[$objp->fk_statut] = $objp->somme;
  58. $nb[$objp->fk_statut] = $objp->nb;
  59. $total += $objp->somme;
  60. $i++;
  61. }
  62. $db->free($result);
  63. } else {
  64. dol_print_error($db);
  65. }
  66. print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
  67. print '<div class="fichecenter"><div class="fichethirdleft">';
  68. if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // TODO Add a search into global search combo so we can remove this
  69. if (!empty($conf->don->enabled) && $user->rights->don->lire) {
  70. $listofsearchfields['search_donation'] = array('text'=>'Donation');
  71. }
  72. if (count($listofsearchfields)) {
  73. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  74. print '<input type="hidden" name="token" value="'.newToken().'">';
  75. print '<table class="noborder nohover centpercent">';
  76. $i = 0;
  77. foreach ($listofsearchfields as $key => $value) {
  78. if ($i == 0) {
  79. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  80. }
  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) {
  84. print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
  85. }
  86. print '</tr>';
  87. $i++;
  88. }
  89. print '</table>';
  90. print '</form>';
  91. print '<br>';
  92. }
  93. }
  94. $dataseries = array();
  95. $colorseries = array();
  96. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  97. print '<table class="noborder nohover centpercent">';
  98. print '<tr class="liste_titre">';
  99. print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
  100. print "</tr>\n";
  101. $listofstatus = array(0, 1, -1, 2);
  102. foreach ($listofstatus as $status) {
  103. $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
  104. if ($status == Don::STATUS_DRAFT) {
  105. $colorseries[$status] = '-'.$badgeStatus0;
  106. }
  107. if ($status == Don::STATUS_VALIDATED) {
  108. $colorseries[$status] = $badgeStatus1;
  109. }
  110. if ($status == Don::STATUS_CANCELED) {
  111. $colorseries[$status] = $badgeStatus9;
  112. }
  113. if ($status == Don::STATUS_PAID) {
  114. $colorseries[$status] = $badgeStatus6;
  115. }
  116. }
  117. if ($conf->use_javascript_ajax) {
  118. print '<tr><td class="center" colspan="4">';
  119. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  120. $dolgraph = new DolGraph();
  121. $dolgraph->SetData($dataseries);
  122. $dolgraph->SetDataColor(array_values($colorseries));
  123. $dolgraph->setShowLegend(2);
  124. $dolgraph->setShowPercent(1);
  125. $dolgraph->SetType(array('pie'));
  126. $dolgraph->setHeight('200');
  127. $dolgraph->draw('idgraphstatus');
  128. print $dolgraph->show($total ? 0 : 1);
  129. print '</td></tr>';
  130. }
  131. print '<tr class="liste_titre">';
  132. print '<td>'.$langs->trans("Status").'</td>';
  133. print '<td class="right">'.$langs->trans("Number").'</td>';
  134. print '<td class="right">'.$langs->trans("Total").'</td>';
  135. print '<td class="right">'.$langs->trans("Average").'</td>';
  136. print '</tr>';
  137. $total = 0;
  138. $totalnb = 0;
  139. foreach ($listofstatus as $status) {
  140. print '<tr class="oddeven">';
  141. print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
  142. print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
  143. print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 'MT') : '&nbsp;').'</td>';
  144. print '<td class="right nowraponall">'.(!empty($nb[$status]) ?price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
  145. $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
  146. $total += (!empty($somme[$status]) ? $somme[$status] : 0);
  147. print "</tr>";
  148. }
  149. print '<tr class="liste_total">';
  150. print '<td>'.$langs->trans("Total").'</td>';
  151. print '<td class="right nowraponall">'.$totalnb.'</td>';
  152. print '<td class="right nowraponall">'.price($total, 'MT').'</td>';
  153. print '<td class="right nowraponall">'.($totalnb ?price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
  154. print '</tr>';
  155. print "</table>";
  156. print '</div><div class="fichetwothirdright">';
  157. $max = 10;
  158. /*
  159. * Last modified donations
  160. */
  161. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
  162. $sql .= " FROM ".MAIN_DB_PREFIX."don as c";
  163. $sql .= " WHERE c.entity = ".$conf->entity;
  164. //$sql.= " AND c.fk_statut > 2";
  165. $sql .= " ORDER BY c.tms DESC";
  166. $sql .= $db->plimit($max, 0);
  167. $resql = $db->query($sql);
  168. if ($resql) {
  169. print '<table class="noborder centpercent">';
  170. print '<tr class="liste_titre">';
  171. print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).'</th></tr>';
  172. $num = $db->num_rows($resql);
  173. if ($num) {
  174. $i = 0;
  175. while ($i < $num) {
  176. $obj = $db->fetch_object($resql);
  177. print '<tr class="oddeven">';
  178. $donation_static->id = $obj->rowid;
  179. $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
  180. print '<td width="96" class="nobordernopadding nowrap">';
  181. print $donation_static->getNomUrl(1);
  182. print '</td>';
  183. print '<td class="nobordernopadding">';
  184. print $obj->societe;
  185. print ($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
  186. print dolGetFirstLastname($obj->lastname, $obj->firstname);
  187. print '</td>';
  188. print '<td class="right nobordernopadding nowraponall amount">';
  189. print price($obj->amount, 1);
  190. print '</td>';
  191. // Date
  192. print '<td class="center">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
  193. print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
  194. print '</tr>';
  195. $i++;
  196. }
  197. }
  198. print "</table><br>";
  199. } else {
  200. dol_print_error($db);
  201. }
  202. print '</div></div>';
  203. $parameters = array('user' => $user);
  204. $reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
  205. llxFooter();
  206. $db->close();