* Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Vinicius Nogueira * Copyright (C) 2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/fourn/facture/impayees.php * \ingroup facture * \brief Page to list all unpaid invoices */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; if (! $user->rights->facture->lire) accessforbidden(); $langs->load("companies"); $langs->load("bills"); $socid=GETPOST('socid','int'); $option = GETPOST('option'); // Security check if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } /* * View */ $now=dol_now(); llxHeader('',$langs->trans("BillsSuppliersUnpaid")); $title=$langs->trans("BillsSuppliersUnpaid"); $facturestatic=new FactureFournisseur($db); $companystatic=new Societe($db); /*************************************************************************** * * * Mode Liste * * * ***************************************************************************/ $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $search_ref = GETPOST('search_ref','alpha'); $search_ref_supplier = GETPOST('search_ref_supplier','alpha'); $search_societe = GETPOST('search_societe','alpha'); $search_montant_ht = GETPOST('search_montant_ht','int'); $search_montant_ttc = GETPOST('search_montant_ttc','int'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortfield) $sortfield="f.date_lim_reglement"; if (! $sortorder) $sortorder="ASC"; if ($user->rights->fournisseur->facture->lire) { $sql = "SELECT s.rowid as socid, s.nom,"; $sql.= " f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc,"; $sql.= " f.datef as df, f.date_lim_reglement as datelimite, "; $sql.= " f.paye as paye, f.rowid as facid, f.fk_statut"; $sql.= " ,sum(pf.amount) as am"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ",".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn "; $sql.= " WHERE f.entity = ".$conf->entity; $sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.paye = 0 AND f.fk_statut = 1"; if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql .= " AND s.rowid = ".$socid; if (GETPOST('filtre')) { $filtrearr = explode(",", GETPOST('filtre')); foreach ($filtrearr as $fil) { $filt = explode(":", $fil); $sql .= " AND " . $filt[0] . " = " . $filt[1]; } } if ($search_ref) { $sql .= " AND f.rowid LIKE '%".$search_ref."%'"; } if ($search_ref_supplier) { $sql .= " AND f.ref_supplier LIKE '%".$search_ref_supplier."%'"; } if ($search_societe) { $sql .= " AND s.nom LIKE '%".$search_societe."%'"; } if ($search_montant_ht) { $sql .= " AND f.total_ht = '".$search_montant_ht."'"; } if ($search_montant_ttc) { $sql .= " AND f.total_ttc = '".$search_montant_ttc."'"; } if (dol_strlen(GETPOST('sf_re')) > 0) { $sql .= " AND f.ref_supplier LIKE '%".GETPOST('sf_re')."%'"; } $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, s.rowid, s.nom"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.=$db->order($sortfield,$sortorder); if (! in_array("f.ref_supplier",explode(',',$sortfield))) $sql.= ", f.ref_supplier DESC"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($socid) { $soc = new Societe($db); $soc->fetch($socid); } $param =''; if ($socid) $param.="&socid=".$socid; if ($search_ref) $param.='&search_ref='.urlencode($search_ref); if ($search_ref_supplier) $param.='&search_ref_supplier='.urlencode($search_ref_supplier); if ($search_societe) $param.='&search_societe='.urlencode($search_societe); if ($search_montant_ht) $param.='&search_montant_ht='.urlencode($search_montant_ht); if ($search_montant_ttc) $param.='&search_montant_ttc='.urlencode($search_montant_ttc); $param.=($option?"&option=".$option:""); if (! empty($late)) $param.='&late='.urlencode($late); $urlsource=str_replace('&','&',$param); $titre=($socid?$langs->trans("BillsSuppliersUnpaidForCompany",$soc->nom):$langs->trans("BillsSuppliersUnpaid")); if ($option == 'late') $titre.=' ('.$langs->trans("Late").')'; else $titre.=' ('.$langs->trans("All").')'; $link=''; if (empty($option)) $link=''.$langs->trans("ShowUnpaidLateOnly").''; elseif ($option == 'late') $link=''.$langs->trans("ShowUnpaidAll").''; print_fiche_titre($titre,$link); print_barre_liste('','',$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',0); // We don't want pagination on this page $i = 0; print '
'; print ''; print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("RefSupplier"),$_SERVER["PHP_SELF"],"f.ref_supplier","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"f.date_lim_reglement","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AlreadyPaid"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder); print "\n"; // Lines with filter fields print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; if ($num > 0) { $var=True; $total_ht=0; $total_ttc=0; $total_paid=0; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print ""; $classname = "impayee"; print '\n"; print '\n"; print '\n"; print '\n"; print ''; print ""; print ""; print ""; // Affiche statut de la facture print ''; print "\n"; $total_ht+=$objp->total_ht; $total_ttc+=$objp->total_ttc; $total_paid+=$objp->am; $i++; } print ''; print ""; print ""; print ""; print ""; print ''; print "\n"; } print "
'; print ''; print '  '; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; $facturestatic->id=$objp->facid; $facturestatic->ref=$objp->ref; print $facturestatic->getNomUrl(1); print "'.dol_trunc($objp->ref_supplier,12)."'.dol_print_date($db->jdate($objp->df),'day')."'.dol_print_date($db->jdate($objp->datelimite),'day'); if ($objp->datelimite && $db->jdate($objp->datelimite) < ($now - $conf->facture->fournisseur->warning_delay) && ! $objp->paye && $objp->fk_statut == 1) print img_warning($langs->trans("Late")); print "'; $companystatic->id=$objp->socid; $companystatic->nom=$objp->nom; print $companystatic->getNomUrl(1,'supplier',32); print '".price($objp->total_ht)."".price($objp->total_ttc)."".price($objp->am)."'; print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am); print '
".$langs->trans("Total").": ".price($total_ht)."".price($total_ttc)."".price($total_paid)." 
"; print '
'; $db->free($resql); } else { dol_print_error($db); } } // End of page $db->close(); llxFooter();