index.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  28. $hookmanager = new HookManager($db);
  29. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  30. $hookmanager->initHooks(array('donationindex'));
  31. $langs->load("donations");
  32. $donation_static = new Don($db);
  33. // Security check
  34. $result = restrictedArea($user, 'don');
  35. /*
  36. * Actions
  37. */
  38. // None
  39. /*
  40. * View
  41. */
  42. $donstatic = new Don($db);
  43. $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
  44. llxHeader('', $langs->trans("Donations"), $help_url);
  45. $nb = array();
  46. $somme = array();
  47. $total = 0;
  48. $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
  49. $sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
  50. $sql .= " GROUP BY d.fk_statut";
  51. $sql .= " ORDER BY d.fk_statut";
  52. $result = $db->query($sql);
  53. if ($result) {
  54. $i = 0;
  55. $num = $db->num_rows($result);
  56. while ($i < $num) {
  57. $objp = $db->fetch_object($result);
  58. $somme[$objp->fk_statut] = $objp->somme;
  59. $nb[$objp->fk_statut] = $objp->nb;
  60. $total += $objp->somme;
  61. $i++;
  62. }
  63. $db->free($result);
  64. } else {
  65. dol_print_error($db);
  66. }
  67. print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
  68. print '<div class="fichecenter"><div class="fichethirdleft">';
  69. if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // TODO Add a search into global search combo so we can remove this
  70. if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
  71. $listofsearchfields['search_donation'] = array('text'=>'Donation');
  72. }
  73. if (count($listofsearchfields)) {
  74. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  75. print '<input type="hidden" name="token" value="'.newToken().'">';
  76. print '<table class="noborder nohover centpercent">';
  77. $i = 0;
  78. foreach ($listofsearchfields as $key => $value) {
  79. if ($i == 0) {
  80. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  81. }
  82. print '<tr>';
  83. 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>';
  84. if ($i == 0) {
  85. print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
  86. }
  87. print '</tr>';
  88. $i++;
  89. }
  90. print '</table>';
  91. print '</form>';
  92. print '<br>';
  93. }
  94. }
  95. $dataseries = array();
  96. $colorseries = array();
  97. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  98. print '<table class="noborder nohover centpercent">';
  99. print '<tr class="liste_titre">';
  100. print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
  101. print "</tr>\n";
  102. $listofstatus = array(0, 1, -1, 2);
  103. foreach ($listofstatus as $status) {
  104. $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
  105. if ($status == Don::STATUS_DRAFT) {
  106. $colorseries[$status] = '-'.$badgeStatus0;
  107. }
  108. if ($status == Don::STATUS_VALIDATED) {
  109. $colorseries[$status] = $badgeStatus1;
  110. }
  111. if ($status == Don::STATUS_CANCELED) {
  112. $colorseries[$status] = $badgeStatus9;
  113. }
  114. if ($status == Don::STATUS_PAID) {
  115. $colorseries[$status] = $badgeStatus6;
  116. }
  117. }
  118. if ($conf->use_javascript_ajax) {
  119. print '<tr><td class="center" colspan="4">';
  120. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  121. $dolgraph = new DolGraph();
  122. $dolgraph->SetData($dataseries);
  123. $dolgraph->SetDataColor(array_values($colorseries));
  124. $dolgraph->setShowLegend(2);
  125. $dolgraph->setShowPercent(1);
  126. $dolgraph->SetType(array('pie'));
  127. $dolgraph->setHeight('200');
  128. $dolgraph->draw('idgraphstatus');
  129. print $dolgraph->show($total ? 0 : 1);
  130. print '</td></tr>';
  131. }
  132. print '<tr class="liste_titre">';
  133. print '<td>'.$langs->trans("Status").'</td>';
  134. print '<td class="right">'.$langs->trans("Number").'</td>';
  135. print '<td class="right">'.$langs->trans("Total").'</td>';
  136. print '<td class="right">'.$langs->trans("Average").'</td>';
  137. print '</tr>';
  138. $total = 0;
  139. $totalnb = 0;
  140. foreach ($listofstatus as $status) {
  141. print '<tr class="oddeven">';
  142. print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
  143. print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
  144. print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 'MT') : '&nbsp;').'</td>';
  145. print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
  146. $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
  147. $total += (!empty($somme[$status]) ? $somme[$status] : 0);
  148. print "</tr>";
  149. }
  150. print '<tr class="liste_total">';
  151. print '<td>'.$langs->trans("Total").'</td>';
  152. print '<td class="right nowraponall">'.$totalnb.'</td>';
  153. print '<td class="right nowraponall">'.price($total, 'MT').'</td>';
  154. print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
  155. print '</tr>';
  156. print "</table>";
  157. print '</div><div class="fichetwothirdright">';
  158. $max = 10;
  159. /*
  160. * Last modified donations
  161. */
  162. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
  163. $sql .= " FROM ".MAIN_DB_PREFIX."don as c";
  164. $sql .= " WHERE c.entity = ".$conf->entity;
  165. //$sql.= " AND c.fk_statut > 2";
  166. $sql .= " ORDER BY c.tms DESC";
  167. $sql .= $db->plimit($max, 0);
  168. $resql = $db->query($sql);
  169. if ($resql) {
  170. print '<table class="noborder centpercent">';
  171. print '<tr class="liste_titre">';
  172. print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).'</th></tr>';
  173. $num = $db->num_rows($resql);
  174. if ($num) {
  175. $i = 0;
  176. while ($i < $num) {
  177. $obj = $db->fetch_object($resql);
  178. print '<tr class="oddeven">';
  179. $donation_static->id = $obj->rowid;
  180. $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
  181. print '<td width="96" class="nobordernopadding nowrap">';
  182. print $donation_static->getNomUrl(1);
  183. print '</td>';
  184. print '<td class="nobordernopadding">';
  185. print $obj->societe;
  186. print ($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
  187. print dolGetFirstLastname($obj->firstname, $obj->lastname);
  188. print '</td>';
  189. print '<td class="right nobordernopadding nowraponall amount">';
  190. print price($obj->amount, 1);
  191. print '</td>';
  192. // Date
  193. print '<td class="center">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
  194. print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
  195. print '</tr>';
  196. $i++;
  197. }
  198. }
  199. print "</table><br>";
  200. } else {
  201. dol_print_error($db);
  202. }
  203. print '</div></div>';
  204. $parameters = array('user' => $user);
  205. $reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
  206. llxFooter();
  207. $db->close();