2004-10-20 00:24:10 +02:00
< ? php
2005-01-31 13:21:44 +01:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
2003-02-13 17:02:41 +01:00
*
* 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 $
*
*/
2005-01-31 13:21:44 +01:00
/**
\file htdocs / includes / boxes / box_factures_imp . php
\ingroup factures
\brief Module de g<EFBFBD> n<EFBFBD> ration de l ' affichage de la box factures impayees
*/
2005-02-27 18:57:21 +01:00
include_once ( DOL_DOCUMENT_ROOT . " /includes/boxes/modules_boxes.php " );
2005-02-27 17:45:59 +01:00
class box_factures_imp extends ModeleBoxes {
2005-02-27 18:57:21 +01:00
var $boxcode = " oldestunpayedcustomerbills " ;
2005-02-28 18:08:25 +01:00
var $boximg = " object_bill " ;
2005-02-27 18:57:21 +01:00
var $boxlabel ;
var $depends = array ( " facture " );
2005-02-27 17:45:59 +01:00
var $info_box_head = array ();
var $info_box_contents = array ();
2005-02-27 18:57:21 +01:00
/**
* \brief Constructeur de la classe
*/
function box_factures_imp ()
{
global $langs ;
$langs -> load ( " boxes " );
$this -> boxlabel = $langs -> trans ( " BoxOldestUnpayedCustomerBills " );
}
/**
* \brief Charge les donn<EFBFBD> es en m<EFBFBD> moire pour affichage ult<EFBFBD> rieur
* \param $max Nombre maximum d ' enregistrements <EFBFBD> charger
*/
2005-02-27 17:45:59 +01:00
function loadBox ( $max = 5 )
2003-10-17 19:52:22 +02:00
{
2005-02-27 17:45:59 +01:00
global $user , $langs , $db ;
2005-02-27 18:57:21 +01:00
$langs -> load ( " boxes " );
2005-02-27 17:45:59 +01:00
2005-06-18 16:17:58 +02:00
$warning_delay = 31 * 24 * 60 * 60 ; // Delai affichage warning retard (si retard paiement facture > delai)
2005-02-28 18:08:25 +01:00
$this -> info_box_head = array ( 'text' => $langs -> trans ( " BoxTitleOldestUnpayedCustomerBills " , $max ));
2005-02-27 17:45:59 +01:00
if ( $user -> rights -> facture -> lire )
{
2005-06-18 16:17:58 +02:00
$sql = " SELECT s.nom,s.idp,f.facnumber, " . $db -> pdate ( " f.date_lim_reglement " ) . " as datelimite, f.amount, " . $db -> pdate ( " f.datef " ) . " as df,f.paye,f.rowid as facid " ;
2005-02-27 17:45:59 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f WHERE f.fk_soc = s.idp AND f.paye=0 AND fk_statut = 1 " ;
if ( $user -> societe_id )
{
$sql .= " AND s.idp = $user->societe_id " ;
}
2005-03-02 20:39:18 +01:00
//$sql .= " ORDER BY f.datef DESC, f.facnumber DESC ";
$sql .= " ORDER BY f.datef ASC, f.facnumber ASC " ;
2005-02-27 17:45:59 +01:00
$sql .= $db -> plimit ( $max , 0 );
$result = $db -> query ( $sql );
if ( $result )
{
2005-06-18 16:17:58 +02:00
$num = $db -> num_rows ( $result );
2005-02-27 17:45:59 +01:00
$i = 0 ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2005-06-18 16:17:58 +02:00
$late = " " ;
2005-08-03 19:43:47 +02:00
if ( $objp -> datelimite < ( time () - $warning_delay )) $late = img_warning ( $langs -> trans ( " Late " ));
2005-06-18 16:17:58 +02:00
2005-02-27 17:45:59 +01:00
$this -> info_box_contents [ $i ][ 0 ] = array ( 'align' => 'left' ,
2005-02-28 18:08:25 +01:00
'logo' => $this -> boximg ,
2005-06-18 16:35:58 +02:00
'text' => $objp -> facnumber ,
'text2' => $late ,
2005-02-27 17:45:59 +01:00
'url' => DOL_URL_ROOT . " /compta/facture.php?facid= " . $objp -> facid );
2005-06-18 16:17:58 +02:00
2005-02-27 17:45:59 +01:00
$this -> info_box_contents [ $i ][ 1 ] = array ( 'align' => 'left' ,
'text' => $objp -> nom ,
2005-08-11 20:54:59 +02:00
'maxlength' => 44 ,
2005-02-27 17:45:59 +01:00
'url' => DOL_URL_ROOT . " /comm/fiche.php?socid= " . $objp -> idp );
$i ++ ;
}
}
}
2005-06-27 23:25:17 +02:00
else {
$this -> info_box_contents [ 0 ][ 0 ] = array ( 'align' => 'left' ,
'text' => $langs -> trans ( " ReadPermissionNotAllowed " ));
}
2003-10-17 19:52:22 +02:00
}
2005-02-27 17:45:59 +01:00
function showBox ()
2003-08-06 11:13:24 +02:00
{
2005-02-27 17:45:59 +01:00
parent :: showBox ( $this -> info_box_head , $this -> info_box_contents );
2003-07-10 14:41:38 +02:00
}
2005-02-27 17:45:59 +01:00
2003-07-10 14:41:38 +02:00
}
2005-02-27 17:45:59 +01:00
2003-02-13 17:02:41 +01:00
?>