list.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@zendsi.com>
  3. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  4. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/loan/list.php
  22. * \ingroup loan
  23. * \brief Page to list all loans
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("loan","compta","banks","bills"));
  29. // Security check
  30. $socid = GETPOST('socid', 'int');
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. $result = restrictedArea($user, 'loan', '', '', '');
  33. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  34. $sortfield = GETPOST("sortfield",'alpha');
  35. $sortorder = GETPOST("sortorder",'alpha');
  36. $page = GETPOST("page",'int');
  37. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  38. $offset = $limit * $page;
  39. $pageprev = $page - 1;
  40. $pagenext = $page + 1;
  41. if (! $sortfield) $sortfield="l.rowid";
  42. if (! $sortorder) $sortorder="DESC";
  43. $search_ref=GETPOST('search_ref','int');
  44. $search_label=GETPOST('search_label','alpha');
  45. $search_amount=GETPOST('search_amount','alpha');
  46. $filtre=GETPOST("filtre");
  47. $optioncss = GETPOST('optioncss','alpha');
  48. // Purge search criteria
  49. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
  50. {
  51. $search_ref="";
  52. $search_label="";
  53. $search_amount="";
  54. }
  55. /*
  56. * View
  57. */
  58. $loan_static = new Loan($db);
  59. llxHeader();
  60. $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
  61. $sql.= " SUM(pl.amount_capital) as alreadypayed";
  62. $sql.= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl";
  63. $sql.= " ON l.rowid = pl.fk_loan";
  64. $sql.= " WHERE l.entity = ".$conf->entity;
  65. if ($search_amount) $sql.= natural_search("l.capital", $search_amount, 1);
  66. if ($search_ref) $sql.= " AND l.rowid = ".$db->escape($search_ref);
  67. if ($search_label) $sql.= natural_search("l.label", $search_label);
  68. if ($filtre) {
  69. $filtre=str_replace(":","=",$filtre);
  70. $sql .= " AND ".$filtre;
  71. }
  72. $sql.= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
  73. $sql.= $db->order($sortfield,$sortorder);
  74. $nbtotalofrecords = '';
  75. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  76. {
  77. $result = $db->query($sql);
  78. $nbtotalofrecords = $db->num_rows($result);
  79. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  80. {
  81. $page = 0;
  82. $offset = 0;
  83. }
  84. }
  85. $sql.= $db->plimit($limit+1, $offset);
  86. //print $sql;
  87. $resql=$db->query($sql);
  88. if ($resql)
  89. {
  90. $num = $db->num_rows($resql);
  91. $i = 0;
  92. $param='';
  93. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  94. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  95. if ($search_ref) $param.="&amp;search_ref=".urlencode($search_ref);
  96. if ($search_label) $param.="&amp;search_label=".urlencode($search_user);
  97. if ($search_amount) $param.="&amp;search_amount=".urlencode($search_amount_ht);
  98. if ($optioncss != '') $param.='&amp;optioncss='.urlencode($optioncss);
  99. $newcardbutton='';
  100. if ($user->rights->loan->write)
  101. {
  102. $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/loan/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewLoan').'</span>';
  103. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  104. $newcardbutton.= '</a>';
  105. }
  106. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  107. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  108. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  109. print '<input type="hidden" name="action" value="list">';
  110. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  111. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  112. print '<input type="hidden" name="page" value="'.$page.'">';
  113. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  114. print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
  115. print '<div class="div-table-responsive">';
  116. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  117. // Filters lines
  118. print '<tr class="liste_titre_filter">';
  119. print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
  120. print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
  121. print '<td class="liste_titre" align="right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
  122. print '<td class="liste_titre">&nbsp;</td>';
  123. print '<td class="liste_titre">&nbsp;</td>';
  124. print '<td class="liste_titre"></td>';
  125. print '<td align="right" class="liste_titre">';
  126. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  127. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  128. print '</td>';
  129. print '</tr>';
  130. print '<tr class="liste_titre">';
  131. print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder);
  132. print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder);
  133. print_liste_field_titre("LoanCapital",$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
  134. print_liste_field_titre("DateStart",$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder);
  135. print_liste_field_titre("DateEnd",$_SERVER["PHP_SELF"],"l.dateend","",$param,'align="center"',$sortfield,$sortorder);
  136. print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder);
  137. print_liste_field_titre('');
  138. print "</tr>\n";
  139. while ($i < min($num,$limit))
  140. {
  141. $obj = $db->fetch_object($resql);
  142. $loan_static->id = $obj->rowid;
  143. $loan_static->ref = $obj->rowid;
  144. $loan_static->label = $obj->label;
  145. print '<tr class="oddeven">';
  146. // Ref
  147. print '<td>'.$loan_static->getNomUrl(1, 42).'</td>';
  148. // Label
  149. print '<td>'.dol_trunc($obj->label,42).'</td>';
  150. // Capital
  151. print '<td align="right" width="100">'.price($obj->capital).'</td>';
  152. // Date start
  153. print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
  154. // Date end
  155. print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
  156. print '<td align="right" class="nowrap">'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'</a></td>';
  157. print '<td></td>';
  158. print "</tr>\n";
  159. $i++;
  160. }
  161. print "</table>";
  162. print '</div>';
  163. print "</form>\n";
  164. $db->free($resql);
  165. }
  166. else
  167. {
  168. dol_print_error($db);
  169. }
  170. // End of page
  171. llxFooter();
  172. $db->close();