index.php 10 KB

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