dolibarr  7.0.0-beta
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@capnetworks.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->load("companies");
37 $langs->load("bills");
38 
39 
40 $socid=GETPOST('socid','int');
41 $option = GETPOST('option');
42 
43 // Security check
44 if ($user->societe_id > 0)
45 {
46  $action = '';
47  $socid = $user->societe_id;
48 }
49 
50 $sortfield = GETPOST("sortfield",'alpha');
51 $sortorder = GETPOST("sortorder",'alpha');
52 
53 $search_ref = GETPOST('search_ref','alpha');
54 $search_ref_supplier = GETPOST('search_ref_supplier','alpha');
55 $search_company = GETPOST('search_company','alpha');
56 $search_amount_no_tax = GETPOST('search_amount_no_tax','alpha');
57 $search_amount_all_tax = GETPOST('search_amount_all_tax','alpha');
58 
59 $page = GETPOST("page",'int');
60 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
61 $offset = $conf->liste_limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
64 if (! $sortfield) $sortfield="f.date_lim_reglement";
65 if (! $sortorder) $sortorder="ASC";
66 
67 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
68 {
69  $search_ref="";
70  $search_ref_supplier="";
71  $search_company="";
72  $search_amount_no_tax="";
73  $search_amount_all_tax="";
74 }
75 
76 /*
77  * View
78  */
79 
80 $now=dol_now();
81 
82 llxHeader('',$langs->trans("BillsSuppliersUnpaid"));
83 
84 $title=$langs->trans("BillsSuppliersUnpaid");
85 
86 $facturestatic=new FactureFournisseur($db);
87 $companystatic=new Societe($db);
88 
89 if ($user->rights->fournisseur->facture->lire)
90 {
91  $sql = "SELECT s.rowid as socid, s.nom as name,";
92  $sql.= " f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc,";
93  $sql.= " f.datef as df, f.date_lim_reglement as datelimite, ";
94  $sql.= " f.paye as paye, f.rowid as facid, f.fk_statut";
95  $sql.= " ,sum(pf.amount) as am";
96  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
97  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
98  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99  $sql.= ",".MAIN_DB_PREFIX."facture_fourn as f";
100  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn ";
101  $sql.= " WHERE f.entity = ".$conf->entity;
102  $sql.= " AND f.fk_soc = s.rowid";
103  $sql.= " AND f.paye = 0 AND f.fk_statut = 1";
104  if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
105  if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
106  if ($socid) $sql .= " AND s.rowid = ".$socid;
107 
108  if (GETPOST('filtre'))
109  {
110  $filtrearr = explode(",", GETPOST('filtre'));
111  foreach ($filtrearr as $fil)
112  {
113  $filt = explode(":", $fil);
114  $sql .= " AND " . $filt[0] . " = " . $filt[1];
115  }
116  }
117 
118  if ($search_ref)
119  {
120  $sql .= " AND f.ref LIKE '%".$search_ref."%'";
121  }
122  if ($search_ref_supplier)
123  {
124  $sql .= " AND f.ref_supplier LIKE '%".$search_ref_supplier."%'";
125  }
126 
127  if ($search_company)
128  {
129  $sql .= " AND s.nom LIKE '%".$search_company."%'";
130  }
131 
132  if ($search_amount_no_tax)
133  {
134  $sql .= " AND f.total_ht = '".$search_amount_no_tax."'";
135  }
136 
137  if ($search_amount_all_tax)
138  {
139  $sql .= " AND f.total_ttc = '".$search_amount_all_tax."'";
140  }
141 
142  if (dol_strlen(GETPOST('sf_re')) > 0)
143  {
144  $sql .= " AND f.ref_supplier LIKE '%".$db->escape(GETPOST('sf_re'))."%'";
145  }
146 
147  $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";
148  if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
149  $sql.=$db->order($sortfield,$sortorder);
150  if (! in_array("f.ref_supplier",explode(',',$sortfield))) $sql.= ", f.ref_supplier DESC";
151 
152  $resql = $db->query($sql);
153  if ($resql)
154  {
155  $num = $db->num_rows($resql);
156 
157  if ($socid)
158  {
159  $soc = new Societe($db);
160  $soc->fetch($socid);
161  }
162 
163  $param ='';
164  if ($socid) $param.="&socid=".$socid;
165 
166  if ($search_ref) $param.='&amp;search_ref='.urlencode($search_ref);
167  if ($search_ref_supplier) $param.='&amp;search_ref_supplier='.urlencode($search_ref_supplier);
168  if ($search_company) $param.='&amp;search_company='.urlencode($search_company);
169  if ($search_amount_no_tax) $param.='&amp;search_amount_no_tax='.urlencode($search_amount_no_tax);
170  if ($search_amount_all_tax) $param.='&amp;search_amount_all_tax='.urlencode($search_amount_all_tax);
171 
172  $param.=($option?"&option=".$option:"");
173  if (! empty($late)) $param.='&late='.urlencode($late);
174  $urlsource=str_replace('&amp;','&',$param);
175 
176  $titre=($socid?$langs->trans("BillsSuppliersUnpaidForCompany",$soc->name):$langs->trans("BillsSuppliersUnpaid"));
177 
178  if ($option == 'late') $titre.=' ('.$langs->trans("Late").')';
179  else $titre.=' ('.$langs->trans("All").')';
180 
181  $link='';
182  if (empty($option)) $link='<a href="'.$_SERVER["PHP_SELF"].'?option=late'.($socid?'&socid='.$socid:'').'">'.$langs->trans("ShowUnpaidLateOnly").'</a>';
183  elseif ($option == 'late') $link='<a href="'.$_SERVER["PHP_SELF"].'?'.($socid?'&socid='.$socid:'').'">'.$langs->trans("ShowUnpaidAll").'</a>';
184  print load_fiche_titre($titre,$link);
185 
186  print_barre_liste('','',$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',0); // We don't want pagination on this page
187  $i = 0;
188  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
189 
190  print '<table class="liste" width="100%">';
191  print '<tr class="liste_titre">';
192  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"f.rowid","",$param,"",$sortfield,$sortorder);
193  print_liste_field_titre("RefSupplier",$_SERVER["PHP_SELF"],"f.ref_supplier","",$param,"",$sortfield,$sortorder);
194  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"f.datef","",$param,'align="center"',$sortfield,$sortorder);
195  print_liste_field_titre("DateDue",$_SERVER["PHP_SELF"],"f.date_lim_reglement","",$param,'align="center"',$sortfield,$sortorder);
196  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
197  print_liste_field_titre("AmountHT",$_SERVER["PHP_SELF"],"f.total_ht","",$param,'align="right"',$sortfield,$sortorder);
198  print_liste_field_titre("AmountTTC",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
199  print_liste_field_titre("AlreadyPaid",$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder);
200  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder);
201  print "</tr>\n";
202 
203  // Lines with filter fields
204  print '<tr class="liste_titre">';
205  print '<td class="liste_titre">';
206  print '<input class="flat" size="8" type="text" name="search_ref" value="'.$search_ref.'"></td>';
207  print '<td class="liste_titre">';
208  print '<input class="flat" size="8" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'"></td>';
209  print '<td class="liste_titre">&nbsp;</td>';
210  print '<td class="liste_titre">&nbsp;</td>';
211  print '<td class="liste_titre" align="left">';
212  print '<input class="flat" type="text" size="6" name="search_company" value="'.$search_company.'">';
213  print '</td><td class="liste_titre" align="right">';
214  print '<input class="flat" type="text" size="8" name="search_amount_no_tax" value="'.$search_amount_no_tax.'">';
215  print '</td><td class="liste_titre" align="right">';
216  print '<input class="flat" type="text" size="8" name="search_amount_all_tax" value="'.$search_amount_all_tax.'">';
217  print '</td>';
218  print '<td class="liste_titre" align="right">';
219  $searchpicto=$form->showFilterAndCheckAddButtons(0);
220  print $searchpicto;
221  print '</td>';
222  print "</tr>\n";
223 
224  if ($num > 0)
225  {
226  $var=True;
227  $total_ht=0;
228  $total_ttc=0;
229  $total_paid=0;
230 
231  while ($i < $num)
232  {
233  $objp = $db->fetch_object($resql);
234 
235  $facturestatic->statut = $objp->fk_statut;
236  $facturestatic->date_echeance = $db->jdate($objp->datelimite);
237 
238 
239 
240  print '<tr class="oddeven">';
241  $classname = "impayee";
242 
243  print '<td class="nowrap">';
244  $facturestatic->id=$objp->facid;
245  $facturestatic->ref=$objp->ref;
246  print $facturestatic->getNomUrl(1);
247  print "</td>\n";
248 
249  print '<td class="nowrap">'.dol_trunc($objp->ref_supplier,12).'</td>';
250 
251  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";
252  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->datelimite),'day');
253  if ($facturestatic->hasDelay()) {
254  print img_warning($langs->trans("Late"));
255  }
256  print "</td>\n";
257 
258  print '<td>';
259  $companystatic->id=$objp->socid;
260  $companystatic->name=$objp->name;
261  print $companystatic->getNomUrl(1,'supplier',32);
262  print '</td>';
263 
264  print "<td align=\"right\">".price($objp->total_ht)."</td>";
265  print "<td align=\"right\">".price($objp->total_ttc)."</td>";
266  print "<td align=\"right\">".price($objp->am)."</td>";
267 
268  // Show invoice status
269  print '<td align="right" class="nowrap">';
270  print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am);
271  print '</td>';
272 
273  print "</tr>\n";
274  $total_ht+=$objp->total_ht;
275  $total_ttc+=$objp->total_ttc;
276  $total_paid+=$objp->am;
277 
278  $i++;
279  }
280 
281  print '<tr class="liste_total">';
282  print "<td colspan=\"5\" align=\"left\">".$langs->trans("Total").": </td>";
283  print "<td align=\"right\"><b>".price($total_ht)."</b></td>";
284  print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
285  print "<td align=\"right\"><b>".price($total_paid)."</b></td>";
286  print '<td align="center">&nbsp;</td>';
287  print "</tr>\n";
288  }
289 
290  print "</table>";
291 
292  print '</form>';
293 
294  $db->free($resql);
295  }
296  else
297  {
298  dol_print_error($db);
299  }
300 
301 }
302 
303 // End of page
304 llxFooter();
305 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
dol_now($mode='gmt')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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.
type
Definition: viewcat.php:283
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.