dolibarr  9.0.0
impayees.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2012 Vinicius Nogueira <viniciusvgn@gmail.com>
7  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
33 
34 if (! $user->rights->fournisseur->facture->lire) accessforbidden();
35 
36 $langs->loadLangs(array("companies", "bills"));
37 
38 $socid=GETPOST('socid','int');
39 $option = GETPOST('option');
40 
41 // Security check
42 if ($user->societe_id > 0)
43 {
44  $action = '';
45  $socid = $user->societe_id;
46 }
47 
48 $sortfield = GETPOST("sortfield",'alpha');
49 $sortorder = GETPOST("sortorder",'alpha');
50 
51 $search_ref = GETPOST('search_ref','alpha');
52 $search_ref_supplier = GETPOST('search_ref_supplier','alpha');
53 $search_company = GETPOST('search_company','alpha');
54 $search_amount_no_tax = GETPOST('search_amount_no_tax','alpha');
55 $search_amount_all_tax = GETPOST('search_amount_all_tax','alpha');
56 
57 $page = GETPOST("page",'int');
58 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
59 $offset = $conf->liste_limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 if (! $sortfield) $sortfield="f.date_lim_reglement";
63 if (! $sortorder) $sortorder="ASC";
64 
65 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
66 {
67  $search_ref="";
68  $search_ref_supplier="";
69  $search_company="";
70  $search_amount_no_tax="";
71  $search_amount_all_tax="";
72 }
73 
74 /*
75  * View
76  */
77 
78 $now=dol_now();
79 
80 llxHeader('',$langs->trans("BillsSuppliersUnpaid"));
81 
82 $title=$langs->trans("BillsSuppliersUnpaid");
83 
84 $facturestatic=new FactureFournisseur($db);
85 $companystatic=new Societe($db);
86 
87 if ($user->rights->fournisseur->facture->lire)
88 {
89  $sql = "SELECT s.rowid as socid, s.nom as name,";
90  $sql.= " f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc,";
91  $sql.= " f.datef as df, f.date_lim_reglement as datelimite, ";
92  $sql.= " f.paye as paye, f.rowid as facid, f.fk_statut";
93  $sql.= " ,sum(pf.amount) as am";
94  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
95  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
96  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97  $sql.= ",".MAIN_DB_PREFIX."facture_fourn as f";
98  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn ";
99  $sql.= " WHERE f.entity = ".$conf->entity;
100  $sql.= " AND f.fk_soc = s.rowid";
101  $sql.= " AND f.paye = 0 AND f.fk_statut = 1";
102  if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
103  if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
104  if ($socid) $sql .= " AND s.rowid = ".$socid;
105 
106  if (GETPOST('filtre'))
107  {
108  $filtrearr = explode(",", GETPOST('filtre'));
109  foreach ($filtrearr as $fil)
110  {
111  $filt = explode(":", $fil);
112  $sql .= " AND " . $filt[0] . " = " . $filt[1];
113  }
114  }
115 
116  if ($search_ref)
117  {
118  $sql .= " AND f.ref LIKE '%".$search_ref."%'";
119  }
120  if ($search_ref_supplier)
121  {
122  $sql .= " AND f.ref_supplier LIKE '%".$search_ref_supplier."%'";
123  }
124 
125  if ($search_company)
126  {
127  $sql .= " AND s.nom LIKE '%".$search_company."%'";
128  }
129 
130  if ($search_amount_no_tax)
131  {
132  $sql .= " AND f.total_ht = '".$search_amount_no_tax."'";
133  }
134 
135  if ($search_amount_all_tax)
136  {
137  $sql .= " AND f.total_ttc = '".$search_amount_all_tax."'";
138  }
139 
140  if (dol_strlen(GETPOST('sf_re')) > 0)
141  {
142  $sql .= " AND f.ref_supplier LIKE '%".$db->escape(GETPOST('sf_re'))."%'";
143  }
144 
145  $sql.= " GROUP BY s.rowid, s.nom, f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.datef, f.date_lim_reglement, f.paye, f.fk_statut";
146  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
147  $sql.=$db->order($sortfield,$sortorder);
148  if (! in_array("f.ref_supplier",explode(',',$sortfield))) $sql.= ", f.ref_supplier DESC";
149 
150  $resql = $db->query($sql);
151  if ($resql)
152  {
153  $num = $db->num_rows($resql);
154 
155  if ($socid)
156  {
157  $soc = new Societe($db);
158  $soc->fetch($socid);
159  }
160 
161  $param ='';
162  if ($socid) $param.="&socid=".$socid;
163 
164  if ($search_ref) $param.='&amp;search_ref='.urlencode($search_ref);
165  if ($search_ref_supplier) $param.='&amp;search_ref_supplier='.urlencode($search_ref_supplier);
166  if ($search_company) $param.='&amp;search_company='.urlencode($search_company);
167  if ($search_amount_no_tax) $param.='&amp;search_amount_no_tax='.urlencode($search_amount_no_tax);
168  if ($search_amount_all_tax) $param.='&amp;search_amount_all_tax='.urlencode($search_amount_all_tax);
169 
170  $param.=($option?"&option=".$option:"");
171  if (! empty($late)) $param.='&late='.urlencode($late);
172  $urlsource=str_replace('&amp;','&',$param);
173 
174  $titre=($socid?$langs->trans("BillsSuppliersUnpaidForCompany",$soc->name):$langs->trans("BillsSuppliersUnpaid"));
175 
176  if ($option == 'late') $titre.=' ('.$langs->trans("Late").')';
177  else $titre.=' ('.$langs->trans("All").')';
178 
179  $link='';
180  if (empty($option)) $link='<a href="'.$_SERVER["PHP_SELF"].'?option=late'.($socid?'&socid='.$socid:'').'">'.$langs->trans("ShowUnpaidLateOnly").'</a>';
181  elseif ($option == 'late') $link='<a href="'.$_SERVER["PHP_SELF"].'?'.($socid?'&socid='.$socid:'').'">'.$langs->trans("ShowUnpaidAll").'</a>';
182  print load_fiche_titre($titre,$link);
183 
184  print_barre_liste('','',$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',0); // We don't want pagination on this page
185  $i = 0;
186  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
187 
188  print '<table class="liste" width="100%">';
189  print '<tr class="liste_titre">';
190  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"f.rowid","",$param,"",$sortfield,$sortorder);
191  print_liste_field_titre("RefSupplier",$_SERVER["PHP_SELF"],"f.ref_supplier","",$param,"",$sortfield,$sortorder);
192  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"f.datef","",$param,'align="center"',$sortfield,$sortorder);
193  print_liste_field_titre("DateDue",$_SERVER["PHP_SELF"],"f.date_lim_reglement","",$param,'align="center"',$sortfield,$sortorder);
194  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
195  print_liste_field_titre("AmountHT",$_SERVER["PHP_SELF"],"f.total_ht","",$param,'align="right"',$sortfield,$sortorder);
196  print_liste_field_titre("AmountTTC",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
197  print_liste_field_titre("AlreadyPaid",$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder);
198  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder);
199  print "</tr>\n";
200 
201  // Lines with filter fields
202  print '<tr class="liste_titre">';
203  print '<td class="liste_titre">';
204  print '<input class="flat" size="8" type="text" name="search_ref" value="'.$search_ref.'"></td>';
205  print '<td class="liste_titre">';
206  print '<input class="flat" size="8" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'"></td>';
207  print '<td class="liste_titre">&nbsp;</td>';
208  print '<td class="liste_titre">&nbsp;</td>';
209  print '<td class="liste_titre" align="left">';
210  print '<input class="flat" type="text" size="6" name="search_company" value="'.$search_company.'">';
211  print '</td><td class="liste_titre" align="right">';
212  print '<input class="flat" type="text" size="8" name="search_amount_no_tax" value="'.$search_amount_no_tax.'">';
213  print '</td><td class="liste_titre" align="right">';
214  print '<input class="flat" type="text" size="8" name="search_amount_all_tax" value="'.$search_amount_all_tax.'">';
215  print '</td>';
216  print '<td class="liste_titre" align="right">';
217  $searchpicto=$form->showFilterAndCheckAddButtons(0);
218  print $searchpicto;
219  print '</td>';
220  print "</tr>\n";
221 
222  if ($num > 0)
223  {
224  $total_ht=0;
225  $total_ttc=0;
226  $total_paid=0;
227 
228  while ($i < $num)
229  {
230  $objp = $db->fetch_object($resql);
231 
232  $facturestatic->statut = $objp->fk_statut;
233  $facturestatic->date_echeance = $db->jdate($objp->datelimite);
234 
235 
236 
237  print '<tr class="oddeven">';
238  $classname = "impayee";
239 
240  print '<td class="nowrap">';
241  $facturestatic->id=$objp->facid;
242  $facturestatic->ref=$objp->ref;
243  print $facturestatic->getNomUrl(1);
244  print "</td>\n";
245 
246  print '<td class="nowrap">'.dol_trunc($objp->ref_supplier,12).'</td>';
247 
248  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";
249  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->datelimite),'day');
250  if ($facturestatic->hasDelay()) {
251  print img_warning($langs->trans("Late"));
252  }
253  print "</td>\n";
254 
255  print '<td>';
256  $companystatic->id=$objp->socid;
257  $companystatic->name=$objp->name;
258  print $companystatic->getNomUrl(1,'supplier',32);
259  print '</td>';
260 
261  print "<td align=\"right\">".price($objp->total_ht)."</td>";
262  print "<td align=\"right\">".price($objp->total_ttc)."</td>";
263  print "<td align=\"right\">".price($objp->am)."</td>";
264 
265  // Show invoice status
266  print '<td align="right" class="nowrap">';
267  print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am);
268  print '</td>';
269 
270  print "</tr>\n";
271  $total_ht+=$objp->total_ht;
272  $total_ttc+=$objp->total_ttc;
273  $total_paid+=$objp->am;
274 
275  $i++;
276  }
277 
278  print '<tr class="liste_total">';
279  print "<td colspan=\"5\" align=\"left\">".$langs->trans("Total").": </td>";
280  print "<td align=\"right\"><b>".price($total_ht)."</b></td>";
281  print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
282  print "<td align=\"right\"><b>".price($total_paid)."</b></td>";
283  print '<td align="center">&nbsp;</td>';
284  print "</tr>\n";
285  }
286 
287  print "</table>";
288 
289  print '</form>';
290 
291  $db->free($resql);
292  }
293  else
294  {
295  dol_print_error($db);
296  }
297 }
298 
299 // End of page
300 llxFooter();
301 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers invoices.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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.
type
Definition: viewcat.php:284
Class to manage third parties objects (customers, suppliers, prospects...)
if(! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'] s nom
Definition: list.php:573
llxHeader()
Empty header.
Definition: wrapper.php:44
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
dol_now($mode='gmt')
Return date for now.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.