index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.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/index.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. $langs->load("loan");
  28. $langs->load("compta");
  29. $langs->load("banks");
  30. $langs->load("bills");
  31. // Security check
  32. $socid = GETPOST('socid', 'int');
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user, 'loan', '', '', '');
  35. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  36. $sortfield = GETPOST("sortfield",'alpha');
  37. $sortorder = GETPOST("sortorder",'alpha');
  38. $page = GETPOST("page",'int');
  39. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  40. $offset = $limit * $page;
  41. $pageprev = $page - 1;
  42. $pagenext = $page + 1;
  43. if (! $sortfield) $sortfield="l.rowid";
  44. if (! $sortorder) $sortorder="DESC";
  45. $search_ref=GETPOST('search_ref','int');
  46. $search_label=GETPOST('search_label','alpha');
  47. $search_amount=GETPOST('search_amount','alpha');
  48. $filtre=GETPOST("filtre");
  49. $optioncss = GETPOST('optioncss','alpha');
  50. // Purge search criteria
  51. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  52. {
  53. $search_ref="";
  54. $search_label="";
  55. $search_amount="";
  56. }
  57. /*
  58. * View
  59. */
  60. $loan_static = new Loan($db);
  61. llxHeader();
  62. $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,";
  63. $sql.= " SUM(pl.amount_capital) as alreadypayed";
  64. $sql.= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl";
  65. $sql.= " ON l.rowid = pl.fk_loan";
  66. $sql.= " WHERE l.entity = ".$conf->entity;
  67. if ($search_amount) $sql.=" AND l.capital='".$db->escape(price2num(trim($search_amount)))."'";
  68. if ($search_ref) $sql.=" AND l.rowid = ".$db->escape($search_ref);
  69. if ($search_label) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'";
  70. if ($filtre) {
  71. $filtre=str_replace(":","=",$filtre);
  72. $sql .= " AND ".$filtre;
  73. }
  74. $sql.= " GROUP BY l.rowid, l.label, l.capital, l.datestart, l.dateend";
  75. $sql.= $db->order($sortfield,$sortorder);
  76. $nbtotalofrecords = '';
  77. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  78. {
  79. $result = $db->query($sql);
  80. $nbtotalofrecords = $db->num_rows($result);
  81. }
  82. $sql.= $db->plimit($limit+1, $offset);
  83. //print $sql;
  84. $resql=$db->query($sql);
  85. if ($resql)
  86. {
  87. $num = $db->num_rows($resql);
  88. $i = 0;
  89. $var=true;
  90. $param='';
  91. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  92. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  93. if ($search_ref) $param.="&amp;search_ref=".$search_ref;
  94. if ($search_label) $param.="&amp;search_label=".$search_user;
  95. if ($search_amount) $param.="&amp;search_amount=".$search_amount_ht;
  96. if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
  97. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  98. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  99. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  100. print '<input type="hidden" name="action" value="list">';
  101. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  102. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  103. print '<input type="hidden" name="page" value="'.$page.'">';
  104. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  105. print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
  106. print '<div class="div-table-responsive">';
  107. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  108. // Filters lines
  109. print '<tr class="liste_titre_filter">';
  110. print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
  111. print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
  112. print '<td class="liste_titre" align="right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
  113. print '<td class="liste_titre">&nbsp;</td>';
  114. print '<td class="liste_titre"></td>';
  115. print '<td align="right" class="liste_titre">';
  116. 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")).'">';
  117. 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")).'">';
  118. print '</td>';
  119. print '</tr>';
  120. print '<tr class="liste_titre">';
  121. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder);
  122. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder);
  123. print_liste_field_titre($langs->trans("LoanCapital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
  124. print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder);
  125. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder);
  126. print_liste_field_titre('');
  127. print "</tr>\n";
  128. while ($i < min($num,$limit))
  129. {
  130. $obj = $db->fetch_object($resql);
  131. $loan_static->id = $obj->rowid;
  132. $loan_static->ref = $obj->rowid;
  133. $loan_static->label = $obj->label;
  134. $var = !$var;
  135. print '<tr class="oddeven">';
  136. // Ref
  137. print '<td>'.$loan_static->getNomUrl(1, 42).'</td>';
  138. // Label
  139. print '<td>'.dol_trunc($obj->label,42).'</td>';
  140. // Capital
  141. print '<td align="right" width="100">'.price($obj->capital).'</td>';
  142. // Date start
  143. print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
  144. print '<td align="right" class="nowrap">'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'</a></td>';
  145. print '<td></td>';
  146. print "</tr>\n";
  147. $i++;
  148. }
  149. print "</table>";
  150. print '</div>';
  151. print "</form>\n";
  152. $db->free($resql);
  153. }
  154. else
  155. {
  156. dol_print_error($db);
  157. }
  158. llxFooter();
  159. $db->close();