list.php 11 KB

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