index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/compta/bank/various_payment/index.php
  19. * \ingroup bank
  20. * \brief List of various payments
  21. */
  22. require '../../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  25. $langs->load("compta");
  26. $langs->load("banks");
  27. $langs->load("bills");
  28. // Security check
  29. $socid = GETPOST("socid","int");
  30. if ($user->societe_id) $socid=$user->societe_id;
  31. $result = restrictedArea($user, 'banque', '', '', '');
  32. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  33. $search_ref = GETPOST('search_ref','int');
  34. $search_user = GETPOST('search_user','alpha');
  35. $search_label = GETPOST('search_label','alpha');
  36. $search_amount = GETPOST('search_amount','alpha');
  37. $search_account = GETPOST('search_account','int');
  38. $sortfield = GETPOST("sortfield",'alpha');
  39. $sortorder = GETPOST("sortorder",'alpha');
  40. $page = GETPOST("page",'int');
  41. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  42. $offset = $conf->liste_limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (! $sortfield) $sortfield="v.datep";
  46. if (! $sortorder) $sortorder="DESC";
  47. $optioncss = GETPOST('optioncss','alpha');
  48. $filtre=$_GET["filtre"];
  49. if (empty($_REQUEST['typeid']))
  50. {
  51. $newfiltre=str_replace('filtre=','',$filtre);
  52. $filterarray=explode('-',$newfiltre);
  53. foreach($filterarray as $val)
  54. {
  55. $part=explode(':',$val);
  56. if ($part[0] == 'v.fk_typepayment') $typeid=$part[1];
  57. }
  58. }
  59. else
  60. {
  61. $typeid=$_REQUEST['typeid'];
  62. }
  63. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  64. {
  65. $search_ref="";
  66. $search_label="";
  67. $search_amount="";
  68. $search_account='';
  69. $typeid="";
  70. }
  71. /*
  72. * View
  73. */
  74. llxHeader();
  75. $form = new Form($db);
  76. $variousstatic = new PaymentVarious($db);
  77. $accountstatic = new Account($db);
  78. $sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank,";
  79. $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,";
  80. $sql.= " pst.code as payment_code";
  81. $sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  82. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
  83. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  84. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  85. $sql.= " WHERE v.entity = ".$conf->entity;
  86. // Search criteria
  87. if ($search_ref) $sql.=" AND v.rowid=".$search_ref;
  88. if ($search_label) $sql.=natural_search(array('v.label'), $search_label);
  89. if ($search_amount) $sql.=natural_search("v.amount", $search_amount, 1);
  90. if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
  91. if ($filtre) {
  92. $filtre=str_replace(":","=",$filtre);
  93. $sql .= " AND ".$filtre;
  94. }
  95. if ($typeid) {
  96. $sql .= " AND v.fk_typepayment=".$typeid;
  97. }
  98. $sql.= $db->order($sortfield,$sortorder);
  99. //$sql.= " GROUP BY u.rowid, u.lastname, u.firstname, v.rowid, v.fk_user, v.amount, v.label, v.datev, v.fk_typepayment, v.num_payment, pst.code";
  100. $totalnboflines=0;
  101. $result=$db->query($sql);
  102. if ($result)
  103. {
  104. $totalnboflines = $db->num_rows($result);
  105. }
  106. $sql.= $db->plimit($limit+1,$offset);
  107. $result = $db->query($sql);
  108. if ($result)
  109. {
  110. $num = $db->num_rows($result);
  111. $i = 0;
  112. $total = 0 ;
  113. $var=true;
  114. $param='';
  115. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  116. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  117. if ($typeid) $param.='&amp;typeid='.$typeid;
  118. if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
  119. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  120. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  121. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  122. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  123. print '<input type="hidden" name="action" value="list">';
  124. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  125. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  126. print '<input type="hidden" name="page" value="'.$page.'">';
  127. print_barre_liste($langs->trans("VariousPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
  128. print '<div class="div-table-responsive">';
  129. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  130. print '<tr class="liste_titre">';
  131. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"v.rowid","",$param,"",$sortfield,$sortorder);
  132. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"v.label","",$param,'align="left"',$sortfield,$sortorder);
  133. print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"v.datep","",$param,'align="center"',$sortfield,$sortorder);
  134. print_liste_field_titre($langs->trans("PaymentMode"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
  135. if (! empty($conf->banque->enabled)) print_liste_field_titre($langs->trans("BankAccount"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  136. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder);
  137. print_liste_field_titre($langs->trans("Sens"),$_SERVER["PHP_SELF"],"v.sens","",$param,'align="right"',$sortfield,$sortorder);
  138. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  139. print "</tr>\n";
  140. print '<tr class="liste_titre">';
  141. // Ref
  142. print '<td class="liste_titre" align="left">';
  143. print '<input class="flat" type="text" size="3" name="search_ref" value="'.$search_ref.'">';
  144. print '</td>';
  145. // Label
  146. print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$search_label.'"></td>';
  147. // Date
  148. print '<td class="liste_titre">&nbsp;</td>';
  149. // Type
  150. print '<td class="liste_titre" align="left">';
  151. $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
  152. print '</td>';
  153. // Account
  154. if (! empty($conf->banque->enabled))
  155. {
  156. print '<td class="liste_titre">';
  157. $form->select_comptes($search_account,'search_account',0,'',1);
  158. print '</td>';
  159. }
  160. // Amount
  161. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
  162. // Sens
  163. print '<td class="liste_titre">&nbsp;</td>';
  164. print '<td class="liste_titre" align="right">';
  165. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  166. print $searchpicto;
  167. print '</td>';
  168. print "</tr>\n";
  169. while ($i < min($num,$limit))
  170. {
  171. $obj = $db->fetch_object($result);
  172. print '<tr class="oddeven">';
  173. $variousstatic->id=$obj->rowid;
  174. $variousstatic->ref=$obj->rowid;
  175. // Ref
  176. print "<td>".$variousstatic->getNomUrl(1)."</td>\n";
  177. // Label payment
  178. print "<td>".dol_trunc($obj->label,40)."</td>\n";
  179. // Date payment
  180. print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
  181. // Type
  182. print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
  183. // Account
  184. if (! empty($conf->banque->enabled))
  185. {
  186. print '<td>';
  187. if ($obj->fk_bank > 0)
  188. {
  189. //$accountstatic->fetch($obj->fk_bank);
  190. $accountstatic->id=$obj->bid;
  191. $accountstatic->ref=$obj->bref;
  192. $accountstatic->number=$obj->bnumber;
  193. $accountstatic->accountancy_number=$obj->account_number;
  194. $accountstatic->fk_accountancy_journal=$obj->fk_accountancy_journal;
  195. $accountstatic->label=$obj->blabel;
  196. print $accountstatic->getNomUrl(1);
  197. }
  198. else print '&nbsp;';
  199. print '</td>';
  200. }
  201. // Amount
  202. print "<td align=\"right\">".price($obj->amount)."</td>";
  203. // Sens
  204. if ($obj->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
  205. print "<td align=\"right\">".$sens."</td>";
  206. print "<td></td>";
  207. print "</tr>\n";
  208. $total = $total + $obj->amount;
  209. $i++;
  210. }
  211. $colspan=4;
  212. if (! empty($conf->banque->enabled)) $colspan++;
  213. print '<tr class="liste_total"><td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
  214. print '<td class="liste_total" align="right">'.price($total)."</td>";
  215. print "<td></td></tr>";
  216. print "</table>";
  217. print '</div>';
  218. print '</form>';
  219. $db->free($result);
  220. }
  221. else
  222. {
  223. dol_print_error($db);
  224. }
  225. llxFooter();
  226. $db->close();