dolibarr/htdocs/don/list.php

313 lines
11 KiB
PHP
Raw Normal View History

<?php
2019-03-10 09:00:59 +01:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
2002-12-19 19:59:23 +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
* the Free Software Foundation; either version 3 of the License, or
2002-12-19 19:59:23 +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:59:23 +01:00
*/
2005-08-11 22:28:11 +02:00
/**
2019-03-10 09:00:59 +01:00
* \file htdocs/don/list.php
* \ingroup donations
* \brief List of donations
2010-04-05 03:25:44 +02:00
*/
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';
2021-02-25 22:18:34 +01:00
if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
2002-12-19 19:59:23 +01:00
2018-09-13 15:06:06 +02:00
// Load translation files required by the page
$langs->loadLangs(array("companies", "donations"));
2020-04-20 15:57:15 +02:00
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-25 22:18:34 +01:00
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
2010-11-20 14:08:44 +01:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-25 22:18:34 +01:00
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.datedon";
}
$search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_ref = GETPOST('search_ref', 'alpha');
$search_company = GETPOST('search_company', 'alpha');
$search_name = GETPOST('search_name', 'alpha');
$search_amount = GETPOST('search_amount', 'alpha');
$optioncss = GETPOST('optioncss', 'alpha');
2021-02-25 22:18:34 +01:00
if (!$user->rights->don->lire) {
accessforbidden();
}
2002-12-19 19:59:23 +01:00
2021-02-25 22:18:34 +01:00
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
$search_all = "";
$search_ref = "";
$search_company = "";
$search_name = "";
$search_amount = "";
$search_status = '';
2014-11-01 15:06:46 +01:00
}
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('orderlist'));
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
'd.rowid'=>'Id',
'd.ref'=>'Ref',
'd.lastname'=>'Lastname',
'd.firstname'=>'Firstname',
);
2020-04-24 23:56:57 +02:00
/*
2009-08-12 14:59:14 +02:00
* View
*/
2009-08-12 14:59:14 +02:00
2020-04-24 23:56:57 +02:00
$donationstatic = new Don($db);
$form = new Form($db);
2021-02-25 22:18:34 +01:00
if (!empty($conf->projet->enabled)) {
$projectstatic = new Project($db);
}
2010-10-02 14:05:15 +02:00
$help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
llxHeader('', $langs->trans("Donations"), $help_url);
// Genere requete de liste des dons
2019-03-17 17:57:06 +01:00
$sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
$sql .= " d.amount, d.fk_statut as status,";
$sql .= " p.rowid as pid, p.ref, p.title, p.public";
$sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
$sql .= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
2021-02-25 22:18:34 +01:00
if ($search_status != '' && $search_status != '-4') {
2021-03-22 11:30:18 +01:00
$sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
2003-01-18 15:57:12 +01:00
}
2021-02-25 22:18:34 +01:00
if (trim($search_ref) != '') {
$sql .= natural_search('d.ref', $search_ref);
}
2021-02-25 22:18:34 +01:00
if (trim($search_all) != '') {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
2021-02-25 22:18:34 +01:00
if (trim($search_company) != '') {
$sql .= natural_search('d.societe', $search_company);
}
2021-02-25 22:18:34 +01:00
if (trim($search_name) != '') {
$sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
}
2021-02-25 22:18:34 +01:00
if ($search_amount) {
$sql .= natural_search('d.amount', $search_amount, 1);
}
2014-11-01 15:06:46 +01:00
$sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
2021-02-25 22:18:34 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2016-10-23 16:53:45 +02:00
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
2021-02-25 22:18:34 +01:00
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
2016-10-23 16:53:45 +02:00
}
$sql .= $db->plimit($limit + 1, $offset);
2002-12-19 19:59:23 +01:00
2012-07-11 10:14:56 +02:00
$resql = $db->query($sql);
2021-02-25 22:18:34 +01:00
if ($resql) {
2012-07-11 10:14:56 +02:00
$num = $db->num_rows($resql);
2010-04-05 03:25:44 +02:00
$i = 0;
2019-11-02 11:36:48 +01:00
$param = '';
2021-02-25 22:18:34 +01:00
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
if ($search_status && $search_status != -1) {
$param .= '&search_status='.urlencode($search_status);
}
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_company) {
$param .= '&search_company='.urlencode($search_company);
}
if ($search_name) {
$param .= '&search_name='.urlencode($search_name);
}
if ($search_amount) {
$param .= '&search_amount='.urlencode($search_amount);
}
2011-06-12 17:47:10 +02:00
$newcardbutton = '';
2021-02-25 22:18:34 +01:00
if ($user->rights->don->creer) {
$newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
2018-04-15 17:37:49 +02:00
}
2018-04-07 16:17:40 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
2021-02-25 22:18:34 +01:00
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
2020-04-24 23:56:57 +02:00
print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
2018-04-07 16:17:40 +02:00
2021-02-25 22:18:34 +01:00
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
}
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
// Filters lines
print '<tr class="liste_titre_filter">';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
print '</td>';
if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
print '</td>';
} else {
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
print '</td>';
}
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
print '</td>';
print '<td class="liste_titre left">';
print '&nbsp;';
print '</td>';
2021-02-25 22:18:34 +01:00
if (!empty($conf->projet->enabled)) {
print '<td class="liste_titre right">';
print '&nbsp;';
print '</td>';
}
print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
print '<td class="liste_titre right">';
$liststatus = array(
Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
Don::STATUS_CANCELED=>$langs->trans("Canceled")
);
print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
print '</td>';
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto;
print '</td>';
print "</tr>\n";
2019-03-25 10:09:02 +01:00
print '<tr class="liste_titre">';
2019-03-18 00:59:12 +01:00
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
} else {
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
}
2019-03-18 12:38:58 +01:00
print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
2019-03-10 09:13:13 +01:00
print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
2021-02-25 22:18:34 +01:00
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
2017-04-01 12:46:47 +02:00
}
2019-03-10 09:13:13 +01:00
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
2017-04-01 12:46:47 +02:00
print_liste_field_titre('');
print "</tr>\n";
2021-02-25 22:18:34 +01:00
while ($i < min($num, $limit)) {
2016-10-23 16:53:45 +02:00
$objp = $db->fetch_object($resql);
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">';
$donationstatic->id = $objp->rowid;
$donationstatic->ref = $objp->rowid;
$donationstatic->lastname = $objp->lastname;
$donationstatic->firstname = $objp->firstname;
2019-03-17 17:57:06 +01:00
print "<td>".$donationstatic->getNomUrl(1)."</td>";
if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
$company = new Societe($db);
$result = $company->fetch($objp->socid);
if (!empty($objp->socid) && $company->id > 0) {
print "<td>".$company->getNomUrl(1)."</td>";
} else {
print "<td>".$objp->societe."</td>";
}
} else {
print "<td>".$objp->societe."</td>";
}
2019-03-18 12:38:58 +01:00
print "<td>".$donationstatic->getFullName($langs)."</td>";
2019-03-10 09:00:59 +01:00
print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
2021-02-25 22:18:34 +01:00
if (!empty($conf->projet->enabled)) {
2010-10-02 14:05:15 +02:00
print "<td>";
2021-02-25 22:18:34 +01:00
if ($objp->pid) {
$projectstatic->id = $objp->pid;
$projectstatic->ref = $objp->ref;
$projectstatic->id = $objp->pid;
$projectstatic->public = $objp->public;
$projectstatic->title = $objp->title;
2010-10-02 14:05:15 +02:00
print $projectstatic->getNomUrl(1);
2021-02-25 22:18:34 +01:00
} else {
print '&nbsp;';
}
2010-10-02 14:05:15 +02:00
print "</td>\n";
2010-04-05 03:25:44 +02:00
}
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
2019-11-02 11:36:48 +01:00
print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
print '<td></td>';
2010-04-05 03:25:44 +02:00
print "</tr>";
$i++;
}
print "</table>";
print '</div>';
print "</form>\n";
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2002-12-19 19:59:23 +01:00
}
llxFooter();
$db->close();