2004-10-19 22:35:36 +02:00
|
|
|
<?php
|
2019-03-10 09:00:59 +01:00
|
|
|
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
|
|
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2019-06-18 14:07:52 +02:00
|
|
|
* Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
|
2025-01-18 23:15:39 +01:00
|
|
|
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
|
2024-11-04 23:53:20 +01:00
|
|
|
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
2002-12-19 19:55:38 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-12-19 19:55:38 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-12-19 19:55:38 +01:00
|
|
|
*/
|
2004-09-04 17:56:12 +02:00
|
|
|
|
2005-05-11 02:07:17 +02:00
|
|
|
/**
|
2015-03-25 22:37:14 +01:00
|
|
|
* \file htdocs/don/index.php
|
2015-03-22 08:20:19 +01:00
|
|
|
* \ingroup donations
|
|
|
|
|
* \brief Home page of donation module
|
2011-01-04 01:15:48 +01:00
|
|
|
*/
|
2004-09-04 17:56:12 +02:00
|
|
|
|
2022-09-07 20:08:59 +02:00
|
|
|
// Load Dolibarr environment
|
2015-03-20 06:36:48 +01:00
|
|
|
require '../main.inc.php';
|
2015-03-25 22:37:14 +01:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
|
2002-12-19 19:55:38 +01:00
|
|
|
|
2024-11-04 23:53:20 +01:00
|
|
|
/**
|
|
|
|
|
* @var Conf $conf
|
|
|
|
|
* @var DoliDB $db
|
|
|
|
|
* @var HookManager $hookmanager
|
|
|
|
|
* @var Translate $langs
|
|
|
|
|
* @var User $user
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$langs->load("donations");
|
|
|
|
|
|
2019-06-18 14:07:52 +02:00
|
|
|
|
2024-06-30 21:02:50 +02:00
|
|
|
// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
|
2019-06-18 14:07:52 +02:00
|
|
|
$hookmanager->initHooks(array('donationindex'));
|
|
|
|
|
|
2022-12-02 11:30:37 +01:00
|
|
|
$donation_static = new Don($db);
|
|
|
|
|
|
2012-07-11 10:14:56 +02:00
|
|
|
// Security check
|
|
|
|
|
$result = restrictedArea($user, 'don');
|
2012-02-01 14:20:22 +01:00
|
|
|
|
2011-06-12 17:47:10 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2012-02-01 14:20:22 +01:00
|
|
|
// None
|
2011-06-12 17:47:10 +02:00
|
|
|
|
2005-05-11 02:07:17 +02:00
|
|
|
|
2006-05-01 01:59:46 +02:00
|
|
|
/*
|
2009-08-12 14:59:14 +02:00
|
|
|
* View
|
2006-05-01 01:59:46 +02:00
|
|
|
*/
|
2009-08-12 14:59:14 +02:00
|
|
|
|
2019-11-12 00:15:34 +01:00
|
|
|
$donstatic = new Don($db);
|
2006-05-01 01:59:46 +02:00
|
|
|
|
2021-03-29 21:42:38 +02:00
|
|
|
$help_url = 'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones|DE:Modul_Spenden';
|
|
|
|
|
|
2023-12-17 23:08:08 +01:00
|
|
|
llxHeader('', $langs->trans("Donations"), $help_url, '', 0, 0, '', '', '', 'mod-donation page-index');
|
2011-06-29 19:55:32 +02:00
|
|
|
|
2019-11-12 00:15:34 +01:00
|
|
|
$nb = array();
|
|
|
|
|
$somme = array();
|
2017-11-23 20:00:54 +01:00
|
|
|
$total = 0;
|
2012-07-11 10:14:56 +02:00
|
|
|
|
2005-05-11 02:07:17 +02:00
|
|
|
$sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
|
2019-11-12 00:15:34 +01:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
|
|
|
|
|
$sql .= " GROUP BY d.fk_statut";
|
|
|
|
|
$sql .= " ORDER BY d.fk_statut";
|
2002-12-19 19:55:38 +01:00
|
|
|
|
|
|
|
|
$result = $db->query($sql);
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($result) {
|
2012-07-11 10:14:56 +02:00
|
|
|
$i = 0;
|
2020-10-31 14:32:18 +01:00
|
|
|
$num = $db->num_rows($result);
|
2021-02-25 22:18:34 +01:00
|
|
|
while ($i < $num) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$objp = $db->fetch_object($result);
|
|
|
|
|
|
|
|
|
|
$somme[$objp->fk_statut] = $objp->somme;
|
|
|
|
|
$nb[$objp->fk_statut] = $objp->nb;
|
|
|
|
|
$total += $objp->somme;
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
$db->free($result);
|
2004-11-16 21:11:30 +01:00
|
|
|
} else {
|
2020-10-31 14:32:18 +01:00
|
|
|
dol_print_error($db);
|
2002-12-19 19:55:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-24 23:56:57 +02:00
|
|
|
print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
|
2005-08-11 22:28:11 +02:00
|
|
|
|
|
|
|
|
|
2016-08-26 13:23:00 +02:00
|
|
|
print '<div class="fichecenter"><div class="fichethirdleft">';
|
2005-08-11 22:28:11 +02:00
|
|
|
|
2025-01-18 23:15:39 +01:00
|
|
|
$listofsearchfields = array();
|
|
|
|
|
|
2023-11-27 11:41:05 +01:00
|
|
|
if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // TODO Add a search into global search combo so we can remove this
|
2023-10-15 18:12:03 +02:00
|
|
|
if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
|
2024-03-09 16:32:02 +01:00
|
|
|
$listofsearchfields['search_donation'] = array('text' => 'Donation');
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 22:18:34 +01:00
|
|
|
if (count($listofsearchfields)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
|
|
|
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
|
|
|
print '<table class="noborder nohover centpercent">';
|
|
|
|
|
$i = 0;
|
2021-02-25 22:18:34 +01:00
|
|
|
foreach ($listofsearchfields as $key => $value) {
|
|
|
|
|
if ($i == 0) {
|
|
|
|
|
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
|
|
|
|
|
}
|
2023-03-05 14:05:37 +01:00
|
|
|
print '<tr>';
|
2020-10-31 14:32:18 +01:00
|
|
|
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>';
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($i == 0) {
|
2021-08-24 17:04:17 +02:00
|
|
|
print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
|
2021-02-25 22:18:34 +01:00
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
print '</tr>';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
print '</table>';
|
|
|
|
|
print '</form>';
|
|
|
|
|
print '<br>';
|
|
|
|
|
}
|
2016-08-26 13:23:00 +02:00
|
|
|
}
|
2005-08-11 22:28:11 +02:00
|
|
|
|
2020-03-23 19:46:43 +01:00
|
|
|
$dataseries = array();
|
|
|
|
|
$colorseries = array();
|
|
|
|
|
|
2021-04-06 22:18:32 +02:00
|
|
|
include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
|
2002-12-19 19:55:38 +01:00
|
|
|
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="noborder nohover centpercent">';
|
2011-06-12 17:47:10 +02:00
|
|
|
print '<tr class="liste_titre">';
|
2017-03-07 22:45:22 +01:00
|
|
|
print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
|
2011-06-12 17:47:10 +02:00
|
|
|
print "</tr>\n";
|
|
|
|
|
|
2019-11-12 00:15:34 +01:00
|
|
|
$listofstatus = array(0, 1, -1, 2);
|
2021-02-25 22:18:34 +01:00
|
|
|
foreach ($listofstatus as $status) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($status == Don::STATUS_DRAFT) {
|
|
|
|
|
$colorseries[$status] = '-'.$badgeStatus0;
|
|
|
|
|
}
|
|
|
|
|
if ($status == Don::STATUS_VALIDATED) {
|
|
|
|
|
$colorseries[$status] = $badgeStatus1;
|
|
|
|
|
}
|
|
|
|
|
if ($status == Don::STATUS_CANCELED) {
|
|
|
|
|
$colorseries[$status] = $badgeStatus9;
|
|
|
|
|
}
|
|
|
|
|
if ($status == Don::STATUS_PAID) {
|
|
|
|
|
$colorseries[$status] = $badgeStatus6;
|
|
|
|
|
}
|
2011-06-12 17:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($conf->use_javascript_ajax) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<tr><td class="center" colspan="4">';
|
|
|
|
|
|
|
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
|
|
|
|
|
$dolgraph = new DolGraph();
|
|
|
|
|
$dolgraph->SetData($dataseries);
|
|
|
|
|
$dolgraph->SetDataColor(array_values($colorseries));
|
|
|
|
|
$dolgraph->setShowLegend(2);
|
|
|
|
|
$dolgraph->setShowPercent(1);
|
|
|
|
|
$dolgraph->SetType(array('pie'));
|
|
|
|
|
$dolgraph->setHeight('200');
|
|
|
|
|
$dolgraph->draw('idgraphstatus');
|
|
|
|
|
print $dolgraph->show($total ? 0 : 1);
|
|
|
|
|
|
|
|
|
|
print '</td></tr>';
|
2011-06-12 17:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
2004-07-31 15:34:32 +02:00
|
|
|
print '<tr class="liste_titre">';
|
2004-11-16 21:11:30 +01:00
|
|
|
print '<td>'.$langs->trans("Status").'</td>';
|
2019-03-10 09:00:59 +01:00
|
|
|
print '<td class="right">'.$langs->trans("Number").'</td>';
|
|
|
|
|
print '<td class="right">'.$langs->trans("Total").'</td>';
|
|
|
|
|
print '<td class="right">'.$langs->trans("Average").'</td>';
|
2011-06-12 17:47:10 +02:00
|
|
|
print '</tr>';
|
2002-12-19 19:55:38 +01:00
|
|
|
|
2019-11-12 00:15:34 +01:00
|
|
|
$total = 0;
|
|
|
|
|
$totalnb = 0;
|
2021-02-25 22:18:34 +01:00
|
|
|
foreach ($listofstatus as $status) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<tr class="oddeven">';
|
|
|
|
|
print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
|
|
|
|
|
print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : ' ').'</td>';
|
2024-03-26 13:41:54 +01:00
|
|
|
print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 1, '', 1, -1, 'MT') : ' ').'</td>';
|
2023-12-04 12:12:12 +01:00
|
|
|
print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : ' ').'</td>';
|
2020-10-31 14:32:18 +01:00
|
|
|
$totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
|
|
|
|
|
$total += (!empty($somme[$status]) ? $somme[$status] : 0);
|
|
|
|
|
print "</tr>";
|
2002-12-19 19:55:38 +01:00
|
|
|
}
|
2004-11-16 21:11:30 +01:00
|
|
|
|
2005-06-11 13:57:29 +02:00
|
|
|
print '<tr class="liste_total">';
|
2004-11-16 21:11:30 +01:00
|
|
|
print '<td>'.$langs->trans("Total").'</td>';
|
2021-08-23 23:53:58 +02:00
|
|
|
print '<td class="right nowraponall">'.$totalnb.'</td>';
|
2024-03-26 13:41:54 +01:00
|
|
|
print '<td class="right nowraponall">'.price($total, 1, "", 1, -1, 'MT').'</td>';
|
2023-12-04 12:12:12 +01:00
|
|
|
print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : ' ').'</td>';
|
2004-11-16 21:11:30 +01:00
|
|
|
print '</tr>';
|
2002-12-19 19:55:38 +01:00
|
|
|
print "</table>";
|
|
|
|
|
|
|
|
|
|
|
2021-10-24 00:37:37 +02:00
|
|
|
print '</div><div class="fichetwothirdright">';
|
2011-06-12 17:47:10 +02:00
|
|
|
|
|
|
|
|
|
2024-11-04 21:28:59 +01:00
|
|
|
$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
|
|
|
|
|
|
2011-06-12 17:47:10 +02:00
|
|
|
|
|
|
|
|
/*
|
2012-10-10 15:06:02 +02:00
|
|
|
* Last modified donations
|
2011-06-12 17:47:10 +02:00
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:54:36 +01:00
|
|
|
$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount, c.fk_soc as socid";
|
2019-11-12 00:15:34 +01:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."don as c";
|
2024-11-04 21:28:59 +01:00
|
|
|
$sql .= " WHERE c.entity IN (".getEntity("don").")";
|
2011-06-12 17:47:10 +02:00
|
|
|
//$sql.= " AND c.fk_statut > 2";
|
2019-11-12 00:15:34 +01:00
|
|
|
$sql .= " ORDER BY c.tms DESC";
|
|
|
|
|
$sql .= $db->plimit($max, 0);
|
2011-06-12 17:47:10 +02:00
|
|
|
|
2019-11-12 00:15:34 +01:00
|
|
|
$resql = $db->query($sql);
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($resql) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<table class="noborder centpercent">';
|
|
|
|
|
print '<tr class="liste_titre">';
|
2024-11-04 21:28:59 +01:00
|
|
|
print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).' ';
|
2025-02-13 12:23:56 +01:00
|
|
|
print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.datedon&sortorder=DESC">';
|
2024-11-04 21:28:59 +01:00
|
|
|
print '<span class="badge">...</span>';
|
|
|
|
|
print '</a>';
|
|
|
|
|
print '</th></tr>';
|
2020-10-31 14:32:18 +01:00
|
|
|
|
|
|
|
|
$num = $db->num_rows($resql);
|
2021-02-25 22:18:34 +01:00
|
|
|
if ($num) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$i = 0;
|
2021-02-25 22:18:34 +01:00
|
|
|
while ($i < $num) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
|
|
|
|
|
print '<tr class="oddeven">';
|
|
|
|
|
|
|
|
|
|
$donation_static->id = $obj->rowid;
|
|
|
|
|
$donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
|
|
|
|
|
|
|
|
|
|
print '<td width="96" class="nobordernopadding nowrap">';
|
|
|
|
|
print $donation_static->getNomUrl(1);
|
|
|
|
|
print '</td>';
|
|
|
|
|
|
|
|
|
|
print '<td class="nobordernopadding">';
|
2025-02-05 13:54:36 +01:00
|
|
|
if (!empty($obj->socid)) {
|
|
|
|
|
$companystatic = new Societe($db);
|
|
|
|
|
$ret = $companystatic->fetch($obj->socid);
|
|
|
|
|
if ($ret > 0) {
|
|
|
|
|
print $companystatic->getNomUrl(1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
print $obj->societe;
|
|
|
|
|
print($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
|
|
|
|
|
print dolGetFirstLastname($obj->firstname, $obj->lastname);
|
|
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
print '</td>';
|
|
|
|
|
|
2021-08-23 23:53:58 +02:00
|
|
|
print '<td class="right nobordernopadding nowraponall amount">';
|
2020-10-31 14:32:18 +01:00
|
|
|
print price($obj->amount, 1);
|
|
|
|
|
print '</td>';
|
|
|
|
|
|
|
|
|
|
// Date
|
2024-12-30 03:14:20 +01:00
|
|
|
print '<td class="center" title="'.$langs->trans("DonationDate").': '.dol_print_date($db->jdate($obj->datem), 'day').'">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
|
2020-10-31 14:32:18 +01:00
|
|
|
|
|
|
|
|
print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
|
|
|
|
|
|
|
|
|
|
print '</tr>';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
print "</table><br>";
|
2021-02-25 22:18:34 +01:00
|
|
|
} else {
|
|
|
|
|
dol_print_error($db);
|
|
|
|
|
}
|
2011-06-12 17:47:10 +02:00
|
|
|
|
|
|
|
|
|
2021-10-24 00:37:37 +02:00
|
|
|
print '</div></div>';
|
2005-08-11 22:28:11 +02:00
|
|
|
|
2019-06-18 14:07:52 +02:00
|
|
|
$parameters = array('user' => $user);
|
|
|
|
|
$reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
|
2002-12-19 19:55:38 +01:00
|
|
|
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2012-10-10 15:06:02 +02:00
|
|
|
|
|
|
|
|
$db->close();
|