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