list.php 12 KB

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