list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/don/list.php
  23. * \ingroup donations
  24. * \brief List of donations
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  29. if (isModEnabled('project')) {
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('companies', 'donations'));
  34. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'sclist';
  35. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  36. $sortfield = GETPOST('sortfield', 'aZ09comma');
  37. $sortorder = GETPOST('sortorder', 'aZ09comma');
  38. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  39. $type = GETPOST('type', 'aZ');
  40. if (empty($page) || $page == -1) {
  41. $page = 0;
  42. } // If $page is not defined, or '' or -1
  43. $offset = $limit * $page;
  44. $pageprev = $page - 1;
  45. $pagenext = $page + 1;
  46. if (!$sortorder) {
  47. $sortorder = "DESC";
  48. }
  49. if (!$sortfield) {
  50. $sortfield = "d.datedon";
  51. }
  52. $search_status = (GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-4";
  53. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  54. $search_ref = GETPOST('search_ref', 'alpha');
  55. $search_company = GETPOST('search_company', 'alpha');
  56. $search_thirdparty = GETPOST('search_thirdparty', 'alpha');
  57. $search_name = GETPOST('search_name', 'alpha');
  58. $search_amount = GETPOST('search_amount', 'alpha');
  59. $optioncss = GETPOST('optioncss', 'alpha');
  60. $moreforfilter = GETPOST('moreforfilter', 'alpha');
  61. if (!$user->rights->don->lire) {
  62. accessforbidden();
  63. }
  64. 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
  65. $search_all = "";
  66. $search_ref = "";
  67. $search_company = "";
  68. $search_thirdparty = "";
  69. $search_name = "";
  70. $search_amount = "";
  71. $search_status = '';
  72. }
  73. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  74. $hookmanager->initHooks(array('orderlist'));
  75. // List of fields to search into when doing a "search in all"
  76. $fieldstosearchall = array(
  77. 'd.rowid'=>'Id',
  78. 'd.ref'=>'Ref',
  79. 'd.lastname'=>'Lastname',
  80. 'd.firstname'=>'Firstname',
  81. );
  82. // Security check
  83. $result = restrictedArea($user, 'don');
  84. /*
  85. * View
  86. */
  87. $donationstatic = new Don($db);
  88. $form = new Form($db);
  89. if (isModEnabled('project')) {
  90. $projectstatic = new Project($db);
  91. }
  92. $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
  93. llxHeader('', $langs->trans("Donations"), $help_url);
  94. // Genere requete de liste des dons
  95. $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
  96. $sql .= " d.amount, d.fk_statut as status,";
  97. $sql .= " p.rowid as pid, p.ref, p.title, p.public";
  98. $sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
  99. $sql .= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
  100. if ($search_status != '' && $search_status != '-4') {
  101. $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
  102. }
  103. if (trim($search_ref) != '') {
  104. $sql .= natural_search('d.ref', $search_ref);
  105. }
  106. if (trim($search_all) != '') {
  107. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  108. }
  109. if (trim($search_company) != '') {
  110. $sql .= natural_search('d.societe', $search_company);
  111. }
  112. if (trim($search_name) != '') {
  113. $sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
  114. }
  115. if ($search_amount) {
  116. $sql .= natural_search('d.amount', $search_amount, 1);
  117. }
  118. $sql .= $db->order($sortfield, $sortorder);
  119. $nbtotalofrecords = '';
  120. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  121. $result = $db->query($sql);
  122. $nbtotalofrecords = $db->num_rows($result);
  123. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  124. $page = 0;
  125. $offset = 0;
  126. }
  127. }
  128. $sql .= $db->plimit($limit + 1, $offset);
  129. $resql = $db->query($sql);
  130. if ($resql) {
  131. $num = $db->num_rows($resql);
  132. $i = 0;
  133. $param = '';
  134. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  135. $param .= '&contextpage='.urlencode($contextpage);
  136. }
  137. if ($limit > 0 && $limit != $conf->liste_limit) {
  138. $param .= '&limit='.urlencode($limit);
  139. }
  140. if ($optioncss != '') {
  141. $param .= '&optioncss='.urlencode($optioncss);
  142. }
  143. if ($search_status && $search_status != -1) {
  144. $param .= '&search_status='.urlencode($search_status);
  145. }
  146. if ($search_ref) {
  147. $param .= '&search_ref='.urlencode($search_ref);
  148. }
  149. if ($search_company) {
  150. $param .= '&search_company='.urlencode($search_company);
  151. }
  152. if ($search_name) {
  153. $param .= '&search_name='.urlencode($search_name);
  154. }
  155. if ($search_amount) {
  156. $param .= '&search_amount='.urlencode($search_amount);
  157. }
  158. $newcardbutton = '';
  159. if ($user->rights->don->creer) {
  160. $newcardbutton .= dolGetButtonTitle($langs->trans('NewDonation'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/don/card.php?action=create');
  161. }
  162. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  163. if ($optioncss != '') {
  164. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  165. }
  166. print '<input type="hidden" name="token" value="'.newToken().'">';
  167. print '<input type="hidden" name="action" value="list">';
  168. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  169. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  170. print '<input type="hidden" name="page" value="'.$page.'">';
  171. print '<input type="hidden" name="type" value="'.$type.'">';
  172. print_barre_liste($langs->trans("Donations"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_donation', 0, $newcardbutton, '', $limit, 0, 0, 1);
  173. if ($search_all) {
  174. foreach ($fieldstosearchall as $key => $val) {
  175. $fieldstosearchall[$key] = $langs->trans($val);
  176. }
  177. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  178. }
  179. print '<div class="div-table-responsive">';
  180. print '<table class="tagtable liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
  181. // Filters lines
  182. print '<tr class="liste_titre_filter">';
  183. print '<td class="liste_titre">';
  184. print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
  185. print '</td>';
  186. if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
  187. print '<td class="liste_titre">';
  188. print '<input class="flat" size="10" type="text" name="search_thirdparty" value="'.$search_thirdparty.'">';
  189. print '</td>';
  190. } else {
  191. print '<td class="liste_titre">';
  192. print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
  193. print '</td>';
  194. }
  195. print '<td class="liste_titre">';
  196. print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
  197. print '</td>';
  198. print '<td class="liste_titre left">';
  199. print '&nbsp;';
  200. print '</td>';
  201. if (isModEnabled('project')) {
  202. print '<td class="liste_titre right">';
  203. print '&nbsp;';
  204. print '</td>';
  205. }
  206. print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
  207. print '<td class="liste_titre right">';
  208. $liststatus = array(
  209. Don::STATUS_DRAFT=>$langs->trans("DonationStatusPromiseNotValidated"),
  210. Don::STATUS_VALIDATED=>$langs->trans("DonationStatusPromiseValidated"),
  211. Don::STATUS_PAID=>$langs->trans("DonationStatusPaid"),
  212. Don::STATUS_CANCELED=>$langs->trans("Canceled")
  213. );
  214. print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100 onrightofpage');
  215. print '</td>';
  216. print '<td class="liste_titre maxwidthsearch">';
  217. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  218. print $searchpicto;
  219. print '</td>';
  220. print "</tr>\n";
  221. print '<tr class="liste_titre">';
  222. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", $param, "", $sortfield, $sortorder);
  223. if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
  224. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "d.fk_soc", "", $param, "", $sortfield, $sortorder);
  225. } else {
  226. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "d.societe", "", $param, "", $sortfield, $sortorder);
  227. }
  228. print_liste_field_titre("Name", $_SERVER["PHP_SELF"], "d.lastname", "", $param, "", $sortfield, $sortorder);
  229. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.datedon", "", $param, '', $sortfield, $sortorder, 'center ');
  230. if (isModEnabled('project')) {
  231. $langs->load("projects");
  232. print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "d.fk_projet", "", $param, "", $sortfield, $sortorder);
  233. }
  234. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "d.amount", "", $param, '', $sortfield, $sortorder, 'right ');
  235. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  236. print_liste_field_titre('');
  237. print "</tr>\n";
  238. while ($i < min($num, $limit)) {
  239. $objp = $db->fetch_object($resql);
  240. print '<tr class="oddeven">';
  241. $donationstatic->id = $objp->rowid;
  242. $donationstatic->ref = $objp->rowid;
  243. $donationstatic->lastname = $objp->lastname;
  244. $donationstatic->firstname = $objp->firstname;
  245. print "<td>".$donationstatic->getNomUrl(1)."</td>";
  246. if (!empty($conf->global->DONATION_USE_THIRDPARTIES)) {
  247. $company = new Societe($db);
  248. $result = $company->fetch($objp->socid);
  249. if (!empty($objp->socid) && $company->id > 0) {
  250. print "<td>".$company->getNomUrl(1)."</td>";
  251. } else {
  252. print "<td>".$objp->societe."</td>";
  253. }
  254. } else {
  255. print "<td>".$objp->societe."</td>";
  256. }
  257. print "<td>".$donationstatic->getFullName($langs)."</td>";
  258. print '<td class="center">'.dol_print_date($db->jdate($objp->datedon), 'day').'</td>';
  259. if (isModEnabled('project')) {
  260. print "<td>";
  261. if ($objp->pid) {
  262. $projectstatic->id = $objp->pid;
  263. $projectstatic->ref = $objp->ref;
  264. $projectstatic->id = $objp->pid;
  265. $projectstatic->public = $objp->public;
  266. $projectstatic->title = $objp->title;
  267. print $projectstatic->getNomUrl(1);
  268. } else {
  269. print '&nbsp;';
  270. }
  271. print "</td>\n";
  272. }
  273. print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
  274. print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
  275. print '<td></td>';
  276. print "</tr>";
  277. $i++;
  278. }
  279. print "</table>";
  280. print '</div>';
  281. print "</form>\n";
  282. $db->free($resql);
  283. } else {
  284. dol_print_error($db);
  285. }
  286. llxFooter();
  287. $db->close();