2005-01-18 11:02:26 +01:00
< ? php
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 <EFBFBD> ric Seigne < eric . seigne @ ryxeo . com >
* Copyright ( C ) 2004 - 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* 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 2 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 , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
* $Id $
* $Source $
*
*/
/**
\file htdocs / compta / facture . php
\ingroup facture
\brief Page de cr<EFBFBD> ation d ' une facture
\version $Revision $
*/
require ( " ./pre.inc.php " );
$user -> getrights ( 'facture' );
$user -> getrights ( 'banque' );
if ( ! $user -> rights -> facture -> lire )
accessforbidden ();
$langs -> load ( " main " ); // BUG De chargement de traduction ne pas modifier cette ligne
$langs -> load ( " bills " );
require_once DOL_DOCUMENT_ROOT . " /facture.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /paiement.class.php " ;
if ( $_GET [ " socidp " ]) { $socidp = $_GET [ " socidp " ]; }
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$action = '' ;
$socidp = $user -> societe_id ;
}
llxHeader ( '' , 'Factures impay<61> es' );
/***************************************************************************
* *
* Mode Liste *
* *
***************************************************************************/
$page = $_GET [ " page " ];
$sortorder = $_GET [ " sortorder " ];
$sortfield = $_GET [ " sortfield " ];
$month = $_GET [ " month " ];
$year = $_GET [ " year " ];
if ( $page == - 1 )
{
$page = 0 ;
}
if ( $user -> rights -> facture -> lire )
{
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
if ( $sortorder == " " )
$sortorder = " DESC " ;
if ( $sortfield == " " )
$sortfield = " f.datef " ;
$sql = " SELECT s.nom,s.idp,f.facnumber,f.increment,f.total,f.total_ttc, " . $db -> pdate ( " f.datef " ) . " as df, f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf ON f.rowid=pf.fk_facture " ;
$sql .= " WHERE f.fk_soc = s.idp " ;
2005-01-19 21:38:05 +01:00
$sql .= " AND f.paye = 0 AND f.fk_statut = 1 " ;
2005-01-18 11:02:26 +01:00
if ( $socidp )
$sql .= " AND s.idp = $socidp " ;
if ( $month > 0 )
$sql .= " AND date_format(f.datef, '%m') = $month " ;
if ( $_GET [ " filtre " ])
{
$filtrearr = split ( " , " , $_GET [ " filtre " ]);
foreach ( $filtrearr as $fil )
{
$filt = split ( " : " , $fil );
$sql .= " AND " . $filt [ 0 ] . " = " . $filt [ 1 ];
}
}
if ( $_GET [ " search_ref " ])
{
$sql .= " AND f.facnumber like '% " . $_GET [ " search_ref " ] . " %' " ;
}
if ( $_GET [ " search_societe " ])
{
$sql .= " AND s.nom like '% " . $_GET [ " search_societe " ] . " %' " ;
}
if ( $_GET [ " search_montant_ht " ])
{
$sql .= " AND f.total = ' " . $_GET [ " search_montant_ht " ] . " ' " ;
}
if ( $_GET [ " search_montant_ttc " ])
{
$sql .= " AND f.total_ttc = ' " . $_GET [ " search_montant_ttc " ] . " ' " ;
}
if ( $year > 0 )
$sql .= " AND date_format(f.datef, '%Y') = $year " ;
if ( strlen ( $_POST [ " sf_ref " ]) > 0 )
{
$sql .= " AND f.facnumber like '% " . $_POST [ " sf_ref " ] . " %' " ;
}
$sql .= " GROUP BY f.facnumber " ;
$sql .= " ORDER BY " ;
$listfield = split ( ',' , $sortfield );
foreach ( $listfield as $key => $value ) {
$sql .= " $listfield[$key] $sortorder , " ;
}
$sql .= " f.rowid DESC " ;
2005-01-18 11:11:04 +01:00
//$sql .= $db->plimit($limit+1,$offset);
2005-01-18 11:02:26 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $socidp )
{
$soc = new Societe ( $db );
$soc -> fetch ( $socidp );
}
print_barre_liste ( " Factures client " . ( $socidp ? " $soc->nom " : " " ), $page , " impayees.php " , " &socidp= $socidp " , $sortfield , $sortorder , '' , $num );
$i = 0 ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " f.facnumber " , " " , " &socidp= $socidp " , " " , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Date " ), $_SERVER [ " PHP_SELF " ], " f.datef " , " " , " &socidp= $socidp " , 'align="center"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , " &socidp= $socidp " , " " , $sortfield );
print_liste_field_titre ( $langs -> trans ( " AmountHT " ), $_SERVER [ " PHP_SELF " ], " f.total " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " AmountTTC " ), $_SERVER [ " PHP_SELF " ], " f.total_ttc " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Received " ), $_SERVER [ " PHP_SELF " ], " am " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " fk_statut,paye " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print " </tr> \n " ;
// Lignes des champs de filtre
print '<form method="get" action="impayees.php">' ;
print '<tr class="liste_titre">' ;
print '<td valign="right">' ;
print '<input class="fat" size="10" type="text" name="search_ref" value="' . $_GET [ " search_ref " ] . '">' ;
print '</td><td> </td>' ;
print '<td align="left">' ;
print '<input class="fat" type="text" name="search_societe" value="' . $_GET [ " search_societe " ] . '">' ;
print '</td><td align="right">' ;
print '<input class="fat" type="text" size="10" name="search_montant_ht" value="' . $_GET [ " search_montant_ht " ] . '">' ;
print '</td><td align="right">' ;
print '<input class="fat" type="text" size="10" name="search_montant_ttc" value="' . $_GET [ " search_montant_ttc " ] . '">' ;
print '</td><td colspan="2" align="center">' ;
print '<input type="submit" class="button" name="button_search" value="' . $langs -> trans ( " Search " ) . '">' ;
print '</td>' ;
print " </tr> \n " ;
print '</form>' ;
2005-01-18 11:11:04 +01:00
2005-01-18 11:02:26 +01:00
if ( $num > 0 )
{
$var = True ;
$total = 0 ;
$totalrecu = 0 ;
2005-01-18 11:11:04 +01:00
while ( $i < $num )
2005-01-18 11:02:26 +01:00
{
$objp = $db -> fetch_object ( $result );
if ( $objp -> am == 0 )
{
2005-01-18 11:11:04 +01:00
$var =! $var ;
2005-01-18 11:02:26 +01:00
2005-01-18 11:11:04 +01:00
print " <tr $bc[$var] > " ;
$class = " impayee " ;
print '<td><a href="' . DOL_URL_ROOT . '/compta/facture.php?facid=' . $objp -> facid . '">' . img_file () . " </a> \n " ;
print '<a href="' . DOL_URL_ROOT . '/compta/facture.php?facid=' . $objp -> facid . '">' . $objp -> facnumber . '</a>' . $objp -> increment . " </td> \n " ;
if ( $objp -> df > 0 )
2005-01-18 11:02:26 +01:00
{
2005-01-18 11:11:04 +01:00
print " <td align= \" center \" > " ;
$y = strftime ( " %Y " , $objp -> df );
$m = strftime ( " %m " , $objp -> df );
print strftime ( " %d " , $objp -> df ) . " \n " ;
print ' <a href="impayees.php?year=' . $y . '&month=' . $m . '">' ;
print substr ( strftime ( " %B " , $objp -> df ), 0 , 3 ) . " </a> \n " ;
print ' <a href="impayees.php?year=' . $y . '">' ;
print strftime ( " %Y " , $objp -> df ) . " </a></TD> \n " ;
2005-01-18 11:02:26 +01:00
}
else
{
2005-01-18 11:11:04 +01:00
print " <td align= \" center \" ><b>!!!</b></td> \n " ;
2005-01-18 11:02:26 +01:00
}
2005-01-18 11:11:04 +01:00
print '<td><a href="fiche.php?socid=' . $objp -> idp . '">' . $objp -> nom . '</a></td>' ;
2005-01-18 11:02:26 +01:00
2005-01-18 11:11:04 +01:00
print " <td align= \" right \" > " . price ( $objp -> total ) . " </td> " ;
print " <td align= \" right \" > " . price ( $objp -> total_ttc ) . " </td> " ;
print " <td align= \" right \" > " . price ( $objp -> am ) . " </td> " ;
// Affiche statut de la facture
if ( $objp -> fk_statut == 3 )
2005-01-18 11:02:26 +01:00
{
print '<td align="center">abandonn<6E> e</td>' ;
}
else
{
print '<td align="center"><a class="' . $class . '" href="impayees.php?filtre=paye:0,fk_statut:1">' . ( $objp -> am ? " commenc<EFBFBD> " : " impay<EFBFBD> e " ) . '</a></td>' ;
}
2005-01-18 11:11:04 +01:00
print " </tr> \n " ;
$total += $objp -> total ;
$total_ttc += $objp -> total_ttc ;
$totalrecu += $objp -> am ;
2005-01-18 11:02:26 +01:00
}
$i ++ ;
}
2005-01-18 11:11:04 +01:00
print " <tr " . $bc [ ! $var ] . " > " ;
print " <td colspan=3 align= \" left \" > " . $langs -> trans ( " Total " ) . " : </td> " ;
print " <td align= \" right \" ><b> " . price ( $total ) . " </b></td> " ;
print " <td align= \" right \" ><b> " . price ( $total_ttc ) . " </b></td> " ;
print " <td align= \" right \" ><b> " . price ( $totalrecu ) . " </b></td> " ;
print '<td align="center"> </td>' ;
print " </tr> \n " ;
2005-01-18 11:02:26 +01:00
}
print " </table> " ;
$db -> free ();
}
else
{
dolibarr_print_error ( $db );
}
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>