dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
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 
25 require '../../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
31 
32 $langs->loadLangs(array("compta","banks","bills","accountancy"));
33 
34 // Security check
35 $socid = GETPOST("socid","int");
36 if ($user->societe_id) $socid=$user->societe_id;
37 $result = restrictedArea($user, 'banque', '', '', '');
38 
39 $optioncss = GETPOST('optioncss','alpha');
40 
41 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
42 $search_ref = GETPOST('search_ref','int');
43 $search_user = GETPOST('search_user','alpha');
44 $search_label = GETPOST('search_label','alpha');
45 $search_amount_deb = GETPOST('search_amount_deb','alpha');
46 $search_amount_cred = GETPOST('search_amount_cred','alpha');
47 $search_account = GETPOST('search_account','int');
48 $search_date = dol_mktime(0, 0, 0, GETPOST('date_docmonth', 'int'), GETPOST('date_docday', 'int'), GETPOST('date_docyear', 'int'));
49 $search_accountancy_code = GETPOST("search_accountancy_code");
50 
51 $sortfield = GETPOST("sortfield",'alpha');
52 $sortorder = GETPOST("sortorder",'alpha');
53 $page = GETPOST("page",'int');
54 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
55 $offset = $conf->liste_limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (! $sortfield) $sortfield="v.datep";
59 if (! $sortorder) $sortorder="DESC";
60 
61 $filtre=GETPOST("filtre",'alpha');
62 
63 if (! GETPOST('typeid'))
64 {
65  $newfiltre=str_replace('filtre=','',$filtre);
66  $filterarray=explode('-',$newfiltre);
67  foreach($filterarray as $val)
68  {
69  $part=explode(':',$val);
70  if ($part[0] == 'v.fk_typepayment') $typeid=$part[1];
71  }
72 }
73 else
74 {
75  $typeid=GETPOST('typeid');
76 }
77 
78 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
79 {
80  $search_ref="";
81  $search_label="";
82  $search_amount_deb="";
83  $search_amount_cred="";
84  $search_account='';
85  $typeid="";
86  $search_date = '';
87  $search_accountancy_code = '';
88 }
89 
90 /*
91  * View
92  */
93 
94 llxHeader();
95 
96 $form = new Form($db);
97 $formaccounting = new FormAccounting($db);
98 $variousstatic = new PaymentVarious($db);
99 $accountstatic = new Account($db);
100 
101 $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,";
102 $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,";
103 $sql.= " pst.code as payment_code";
104 $sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
105 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity IN (" . getEntity('c_paiement').")";
106 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
107 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
108 $sql.= " WHERE v.entity IN (".getEntity('payment_various').")";
109 
110 // Search criteria
111 if ($search_ref) $sql.=" AND v.rowid=".$search_ref;
112 if ($search_label) $sql.=natural_search(array('v.label'), $search_label);
113 if ($search_amount_deb) $sql.=natural_search("v.amount", $search_amount_deb, 1);
114 if ($search_amount_cred) $sql.=natural_search("v.amount", $search_amount_cred, 1);
115 if ($search_account > 0) $sql.=" AND b.fk_account=".$search_account;
116 if ($search_date) $sql.=" AND v.datep=".$search_date;
117 if ($search_accountancy_code) $sql.=" AND v.accountancy_code=".$search_accountancy_code;
118 
119 if ($filtre) {
120  $filtre=str_replace(":","=",$filtre);
121  $sql .= " AND ".$filtre;
122 }
123 if ($typeid) {
124  $sql .= " AND v.fk_typepayment=".$typeid;
125 }
126 $sql.= $db->order($sortfield,$sortorder);
127 
128 $totalnboflines=0;
129 $result=$db->query($sql);
130 if ($result)
131 {
132  $totalnboflines = $db->num_rows($result);
133 }
134 $sql.= $db->plimit($limit+1,$offset);
135 
136 $result = $db->query($sql);
137 if ($result)
138 {
139  $num = $db->num_rows($result);
140  $i = 0;
141  $total = 0 ;
142  $var=true;
143 
144  $param='';
145  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
146  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
147  if ($typeid) $param.='&amp;typeid='.$typeid;
148  if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
149 
150  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
151 
152  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
153  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
154  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
155  print '<input type="hidden" name="action" value="list">';
156  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
157  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
158  print '<input type="hidden" name="page" value="'.$page.'">';
159 
160  print_barre_liste($langs->trans("VariousPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
161 
162  print '<div class="div-table-responsive">';
163  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
164 
165  print '<tr class="liste_titre">';
166  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"v.rowid","",$param,"",$sortfield,$sortorder);
167  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"v.label","",$param,'align="left"',$sortfield,$sortorder);
168  print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"v.datep","",$param,'align="center"',$sortfield,$sortorder);
169  print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
170  if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
171  if (! empty($conf->accounting->enabled)) print_liste_field_titre("AccountAccounting",$_SERVER["PHP_SELF"],"v.accountancy_code","",$param,'align="left"',$sortfield,$sortorder);
172  print_liste_field_titre("Debit",$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder);
173  print_liste_field_titre("Credit",$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder);
174  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
175  print "</tr>\n";
176 
177  print '<tr class="liste_titre">';
178 
179  // Ref
180  print '<td class="liste_titre" align="left">';
181  print '<input class="flat" type="text" size="3" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
182  print '</td>';
183 
184  // Label
185  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
186 
187  // Date
188  print '<td class="liste_titre center">';
189  print '<div class="nowrap">';
190  print $form->select_date($search_date, 'date_doc', 0, 0, 1);
191  print '</div>';
192  print '</td>';
193 
194  // Type
195  print '<td class="liste_titre" align="left">';
196  $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
197  print '</td>';
198 
199  // Account
200  if (! empty($conf->banque->enabled))
201  {
202  print '<td class="liste_titre">';
203  $form->select_comptes($search_account,'search_account',0,'',1);
204  print '</td>';
205  }
206 
207  // Accounting account
208  if (! empty($conf->accounting->enabled))
209  {
210  print '<td class="liste_titre">';
211  print '<div class="nowrap">';
212  print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, array (), 1, 1, 'maxwidth200');
213  print '</div>';
214  print '</td>';
215  }
216 
217  // Debit
218  print '<td class="liste_titre" align="right"><input name="search_amount_deb" class="flat" type="text" size="8" value="'.$search_amount_deb.'"></td>';
219 
220  // Credit
221  print '<td class="liste_titre" align="right"><input name="search_amount_cred" class="flat" type="text" size="8" value="'.$search_amount_cred.'"></td>';
222 
223  print '<td class="liste_titre" align="right">';
224  $searchpicto=$form->showFilterAndCheckAddButtons(0);
225  print $searchpicto;
226  print '</td>';
227 
228  print "</tr>\n";
229 
230  $totalarray=array();
231  while ($i < min($num,$limit))
232  {
233  $obj = $db->fetch_object($result);
234 
235  print '<tr class="oddeven">';
236 
237  $variousstatic->id=$obj->rowid;
238  $variousstatic->ref=$obj->rowid;
239 
240  // Ref
241  print "<td>".$variousstatic->getNomUrl(1)."</td>\n";
242 
243  // Label payment
244  print "<td>".dol_trunc($obj->label,40)."</td>\n";
245 
246  // Date payment
247  print '<td class="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
248 
249  // Type
250  print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
251 
252  // Account
253  if (! empty($conf->banque->enabled))
254  {
255  print '<td>';
256  if ($obj->bid > 0)
257  {
258  $accountstatic->id=$obj->bid;
259  $accountstatic->ref=$obj->bref;
260  $accountstatic->number=$obj->bnumber;
261 
262  if (! empty($conf->accounting->enabled)) {
263  $accountstatic->account_number=$obj->bank_account_number;
264 
265  $accountingjournal = new AccountingJournal($db);
266  $accountingjournal->fetch($obj->accountancy_journal);
267  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
268  }
269 
270  $accountstatic->label=$obj->blabel;
271  print $accountstatic->getNomUrl(1);
272  }
273  else print '&nbsp;';
274  print '</td>';
275  }
276 
277  // Accounting account
278  if (! empty($conf->accounting->enabled)) {
279  $accountingaccount = new AccountingAccount($db);
280  $accountingaccount->fetch('', $obj->accountancy_code, 1);
281 
282  print '<td>'.$accountingaccount->getNomUrl(0,1,1,'',1).'</td>';
283  }
284 
285  // Debit
286  print "<td align=\"right\">";
287  if ($obj->sens == 0)
288  {
289  print price($obj->amount);
290  $totalarray['totaldeb'] += $obj->amount;
291  }
292  print "</td>";
293 
294  // Credit
295  print "<td align=\"right\">";
296  if ($obj->sens == 1)
297  {
298  print price($obj->amount);
299  $totalarray['totalcred'] += $obj->amount;
300  }
301  print "</td>";
302 
303  print "<td></td>";
304 
305  $i++;
306  }
307 
308  $colspan=4;
309  if (! empty($conf->banque->enabled)) $colspan++;
310  if (! empty($conf->accounting->enabled)) $colspan++;
311 
312  print '<tr class="liste_total">';
313  print '<td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
314  print '<td class="liste_total" align="right">'.price($totalarray['totaldeb'])."</td>";
315  print '<td class="liste_total" align="right">'.price($totalarray['totalcred'])."</td>";
316  print '<td></td>';
317  print '</tr>';
318 
319  print "</table>";
320  print '</div>';
321  print '</form>';
322 
323  $db->free($result);
324 }
325 else
326 {
327  dol_print_error($db);
328 }
329 
330 
331 llxFooter();
332 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
Class to manage various payments.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
llxHeader()
Header empty.
Definition: index.php:37
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
print
Draft customers invoices.
Definition: index.php:91
Class to manage generation of HTML components for accounting management.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage accounting accounts.
Class to manage accounting accounts.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.