dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
9  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
31 require '../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('bills', 'compta', 'companies'));
40 
41 // Security check
42 $facid = GETPOST('facid','int');
43 $socid = GETPOST('socid','int');
44 $userid = GETPOST('userid','int');
45 $day = GETPOST('day','int');
46 $month = GETPOST('month','int');
47 $year = GETPOST('year','int');
48 
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'facture',$facid,'');
51 
52 $paymentstatic=new Paiement($db);
53 $accountstatic=new Account($db);
54 $companystatic=new Societe($db);
55 
56 $search_ref=GETPOST("search_ref","alpha");
57 $search_account=GETPOST("search_account","int");
58 $search_paymenttype=GETPOST("search_paymenttype");
59 $search_amount=GETPOST("search_amount",'alpha'); // alpha because we must be able to search on "< x"
60 $search_company=GETPOST("search_company",'alpha');
61 $search_payment_num=GETPOST('search_payment_num','alpha');
62 
63 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
64 $sortfield = GETPOST("sortfield",'alpha');
65 $sortorder = GETPOST("sortorder",'alpha');
66 $page = GETPOST("page",'int');
67 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
68 $offset = $limit * $page;
69 $pageprev = $page - 1;
70 $pagenext = $page + 1;
71 if (! $sortorder) $sortorder="DESC";
72 if (! $sortfield) $sortfield="p.rowid";
73 
74 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
75 $hookmanager->initHooks(array('paymentlist'));
76 $extrafields = new ExtraFields($db);
77 
78 $arrayfields=array();
79 
80 
81 /*
82  * Actions
83  */
84 
85 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
86 {
87  $search_ref="";
88  $search_account="";
89  $search_amount="";
90  $search_paymenttype="";
91  $search_payment_num="";
92  $search_company="";
93  $day='';
94  $year='';
95  $month='';
96 }
97 
98 
99 
100 /*
101  * View
102  */
103 
104 llxHeader('', $langs->trans('ListPayment'));
105 
106 $form=new Form($db);
107 $formother=new FormOther($db);
108 
109 if (GETPOST("orphelins"))
110 {
111  // Paiements lies a aucune facture (pour aide au diagnostic)
112  $sql = "SELECT p.rowid, p.ref, p.datep as dp, p.amount,";
113  $sql.= " p.statut, p.num_paiement,";
114  $sql.= " c.code as paiement_code";
115  // Add fields for extrafields
116  foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
117  // Add fields from hooks
118  $parameters=array();
119  $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
120  $sql.=$hookmanager->resPrint;
121  $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
122  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
123  $sql.= " WHERE p.entity IN (" . getEntity('facture').")";
124  $sql.= " AND pf.fk_facture IS NULL";
125  // Add where from hooks
126  $parameters=array();
127  $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
128  $sql.=$hookmanager->resPrint;
129 }
130 else
131 {
132  $sql = "SELECT DISTINCT p.rowid, p.ref, p.datep as dp, p.amount,"; // DISTINCT is to avoid duplicate when there is a link to sales representatives
133  $sql.= " p.statut, p.num_paiement,";
134  $sql.= " c.code as paiement_code,";
135  $sql.= " ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.fk_accountancy_journal as accountancy_journal,";
136  $sql.= " s.rowid as socid, s.nom as name, s.email";
137  // Add fields for extrafields
138  foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
139  // Add fields from hooks
140  $parameters=array();
141  $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
142  $sql.=$hookmanager->resPrint;
143  $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p";
144  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
145  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
146  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
147  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
148  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
149  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
150  if (!$user->rights->societe->client->voir && !$socid)
151  {
152  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
153  }
154  $sql.= " WHERE p.entity IN (" . getEntity('facture') . ")";
155  if (! $user->rights->societe->client->voir && ! $socid)
156  {
157  $sql.= " AND sc.fk_user = " .$user->id;
158  }
159  if ($socid > 0) $sql.= " AND f.fk_soc = ".$socid;
160  if ($userid)
161  {
162  if ($userid == -1) $sql.= " AND f.fk_user_author IS NULL";
163  else $sql.= " AND f.fk_user_author = ".$userid;
164  }
165  // Search criteria
166  if ($month > 0)
167  {
168  if ($year > 0 && empty($day))
169  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
170  else if ($year > 0 && ! empty($day))
171  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
172  else
173  $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
174  }
175  else if ($year > 0)
176  {
177  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
178  }
179  if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
180  if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
181  if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'";
182  if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num);
183  if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1);
184  if ($search_company) $sql .= natural_search('s.nom', $search_company);
185  // Add where from hooks
186  $parameters=array();
187  $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
188  $sql.=$hookmanager->resPrint;
189 }
190 $sql.= $db->order($sortfield,$sortorder);
191 
192 $nbtotalofrecords = '';
193 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
194 {
195  $result = $db->query($sql);
196  $nbtotalofrecords = $db->num_rows($result);
197  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
198  {
199  $page = 0;
200  $offset = 0;
201  }
202 }
203 
204 $sql.= $db->plimit($limit+1, $offset);
205 //print "$sql";
206 
207 $resql = $db->query($sql);
208 if ($resql)
209 {
210  $num = $db->num_rows($resql);
211  $i = 0;
212 
213  $param='';
214  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
215  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
216  $param.=(GETPOST("orphelins")?"&orphelins=1":"");
217  $param.=($search_ref?"&search_ref=".urlencode($search_ref):"");
218  $param.=($search_company?"&search_company=".urlencode($search_company):"");
219  $param.=($search_amount?"&search_amount=".urlencode($search_amount):"");
220  $param.=($search_payment_num?"&search_payment_num=".urlencode($search_payment_num):"");
221  if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
222 
223  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
224  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
225  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
226  print '<input type="hidden" name="action" value="list">';
227  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
228  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
229  print '<input type="hidden" name="page" value="'.$page.'">';
230  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
231 
232  print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords,'title_accountancy.png', 0, '', '', $limit);
233 
234  print '<div class="div-table-responsive">';
235  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
236 
237  // Lines for filters fields
238  print '<tr class="liste_titre_filter">';
239  print '<td class="liste_titre" align="left">';
240  print '<input class="flat" type="text" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
241  print '</td>';
242  print '<td class="liste_titre" align="center">';
243  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
244  print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.dol_escape_htmltag($month).'">';
245  $formother->select_year($year?$year:-1,'year',1, 20, 5);
246  print '</td>';
247  print '<td class="liste_titre" align="left">';
248  print '<input class="flat" type="text" size="6" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
249  print '</td>';
250  print '<td class="liste_titre">';
251  $form->select_types_paiements($search_paymenttype,'search_paymenttype','',2,1,1);
252  print '</td>';
253  print '<td class="liste_titre" align="left">';
254  print '<input class="flat" type="text" size="4" name="search_payment_num" value="'.dol_escape_htmltag($search_payment_num).'">';
255  print '</td>';
256  if (! empty($conf->banque->enabled))
257  {
258  print '<td class="liste_titre">';
259  $form->select_comptes($search_account,'search_account',0,'',1);
260  print '</td>';
261  }
262  print '<td class="liste_titre" align="right">';
263  print '<input class="flat" type="text" size="4" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
264  print '</td>';
265  print '<td class="liste_titre" align="right">';
266  $searchpicto=$form->showFilterAndCheckAddButtons(0);
267  print $searchpicto;
268  print '</td>';
269  if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
270  {
271  print '<td class="liste_titre" align="right">';
272  print '</td>';
273  }
274  print "</tr>\n";
275 
276  print '<tr class="liste_titre">';
277  print_liste_field_titre("RefPayment",$_SERVER["PHP_SELF"],"p.rowid","",$param,"",$sortfield,$sortorder);
278  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
279  print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
280  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"c.libelle","",$param,"",$sortfield,$sortorder);
281  print_liste_field_titre("Numero",$_SERVER["PHP_SELF"],"p.num_paiement","",$param,"",$sortfield,$sortorder);
282  if (! empty($conf->banque->enabled))
283  {
284  print_liste_field_titre("Account",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
285  }
286  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"p.amount","",$param,'align="right"',$sortfield,$sortorder);
287  //print_liste_field_titre("Invoices"),"","","",$param,'align="left"',$sortfield,$sortorder);
288 
289  $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
290  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
291  print $hookmanager->resPrint;
292 
293  if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"p.statut","",$param,'align="right"',$sortfield,$sortorder);
294  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
295  print "</tr>\n";
296 
297  while ($i < min($num,$limit))
298  {
299  $objp = $db->fetch_object($resql);
300 
301  $paymentstatic->id=$objp->rowid;
302  $paymentstatic->ref=$objp->ref;
303 
304  print '<tr class="oddeven">';
305 
306  print '<td>';
307  print $paymentstatic->getNomUrl(1);
308  print '</td>';
309 
310  // Date
311  $dateformatforpayment = 'day';
312  if (! empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) $dateformatforpayment='dayhour';
313  print '<td align="center">'.dol_print_date($db->jdate($objp->dp), $dateformatforpayment).'</td>';
314 
315  // Thirdparty
316  print '<td>';
317  if ($objp->socid > 0)
318  {
319  $companystatic->id=$objp->socid;
320  $companystatic->name=$objp->name;
321  $companystatic->email=$objp->email;
322 
323  print $companystatic->getNomUrl(1,'',24);
324  }
325  else print '&nbsp;';
326  print '</td>';
327 
328  // Type
329  print '<td>'.$langs->trans("PaymentTypeShort".$objp->paiement_code).'</td>';
330 
331  // Payment number
332  print '<td>'.$objp->num_paiement.'</td>';
333 
334  // Account
335  if (! empty($conf->banque->enabled))
336  {
337  print '<td>';
338  if ($objp->bid > 0)
339  {
340  $accountstatic->id=$objp->bid;
341  $accountstatic->ref=$objp->bref;
342  $accountstatic->label=$objp->blabel;
343  $accountstatic->number=$objp->number;
344  $accountstatic->account_number=$objp->account_number;
345 
346  $accountingjournal = new AccountingJournal($db);
347  $accountingjournal->fetch($objp->accountancy_journal);
348  $accountstatic->accountancy_journal = $accountingjournal->code;
349 
350  print $accountstatic->getNomUrl(1);
351  }
352  else print '&nbsp;';
353  print '</td>';
354  }
355  // Amount
356  print '<td align="right">'.price($objp->amount).'</td>';
357 
358  if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
359  {
360  print '<td align="right">';
361  if ($objp->statut == 0) print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">';
362  print $paymentstatic->LibStatut($objp->statut,5);
363  if ($objp->statut == 0) print '</a>';
364  print '</td>';
365  }
366 
367  print '<td>&nbsp;</td>';
368  print '</tr>';
369 
370  $i++;
371  }
372  print "</table>\n";
373  print "</div>";
374  print "</form>\n";
375 }
376 else
377 {
378  dol_print_error($db);
379 }
380 
381 // End of page
382 llxFooter();
383 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage bank accounts.
Class to manage standard extra fields.
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.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Classe permettant la generation de composants html autre Only common components are here...
Class to manage payments of customer invoices.
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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.