2012-07-04 09:07:15 +02:00
< ? php
/* Copyright ( C ) 2012 Charles - François BENKE < charles . fr @ benke . fr >
2013-01-15 15:26:46 +01:00
* Copyright ( C ) 2005 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
*
2012-07-04 09:07:15 +02: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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-07-04 09:07:15 +02:00
* ( 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 < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / core / boxes / box_activity . php
* \ingroup societes
* \brief Module to show box of bills , orders & propal of the current year
*/
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php' ;
2012-07-04 09:07:15 +02:00
2012-07-25 11:35:34 +02:00
/**
* Class to manage the box of customer activity ( invoice , order , proposal )
*/
2012-07-04 09:07:15 +02:00
class box_activity extends ModeleBoxes
{
var $boxcode = " activity " ;
var $boximg = " object_bill " ;
var $boxlabel ;
var $depends = array ( " facture " );
var $db ;
var $param ;
2013-01-15 15:26:46 +01:00
var $enabled = 1 ;
2013-01-18 13:56:36 +01:00
2012-07-04 09:07:15 +02:00
var $info_box_head = array ();
var $info_box_contents = array ();
/**
2012-07-25 11:35:34 +02:00
* Constructor
2012-07-04 09:07:15 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ()
2012-07-04 09:07:15 +02:00
{
2013-01-15 15:26:46 +01:00
global $langs , $conf ;
2012-08-04 14:45:23 +02:00
2012-07-04 09:07:15 +02:00
$langs -> load ( " boxes " );
$langs -> load ( " bills " );
$langs -> load ( " projects " );
2012-08-04 14:45:23 +02:00
$langs -> load ( " orders " );
2012-07-04 09:07:15 +02:00
2012-08-04 14:45:23 +02:00
$this -> boxlabel = $langs -> transnoentitiesnoconv ( " BoxGlobalActivity " );
2013-01-18 13:56:36 +01:00
2013-01-18 14:22:18 +01:00
// Disabled by default because, still has some bug (pgsl support, filters, getCurrencySymbol us a cache into a form object not defined, ...) and slow down seriously Dolibarr
2013-01-15 15:26:46 +01:00
$this -> enabled = ( ! empty ( $conf -> global -> MAIN_FEATURES_LEVEL ) || ! empty ( $conf -> global -> MAIN_BOX_ACTIVITY_ENABLED ));
2012-07-04 09:07:15 +02:00
}
/**
2012-07-25 11:35:34 +02:00
* Charge les donnees en memoire pour affichage ulterieur
*
* @ param int $max Maximum number of records to load
* @ return void
2012-07-04 09:07:15 +02:00
*/
2012-07-25 11:35:34 +02:00
function loadBox ( $max = 5 )
2012-07-04 09:07:15 +02:00
{
global $conf , $user , $langs , $db ;
$totalMnt = 0 ;
$totalnb = 0 ;
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2013-01-02 14:35:16 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-07-04 09:07:15 +02:00
$facturestatic = new Facture ( $db );
$propalstatic = new Propal ( $db );
$commandestatic = new Commande ( $db );
$textHead = $langs -> trans ( " Activity " ) . " " . date ( " Y " );
$this -> info_box_head = array ( 'text' => $textHead , 'limit' => dol_strlen ( $textHead ));
// list the summary of the bills
2012-09-15 11:21:22 +02:00
if ( ! empty ( $conf -> facture -> enabled ) && $user -> rights -> facture -> lire )
2012-07-04 09:07:15 +02:00
{
$sql = " SELECT f.paye, f.fk_statut, sum(f.total_ttc) as Mnttot, count(*) as nb " ;
2013-01-02 14:35:16 +01:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " ) " ;
2012-07-04 09:07:15 +02:00
$sql .= " WHERE f.entity = " . $conf -> entity ;
2013-01-02 14:35:16 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
if ( $user -> societe_id ) $sql .= " AND s.rowid = " . $user -> societe_id ;
2012-07-04 09:07:15 +02:00
$sql .= " AND f.fk_soc = s.rowid " ;
2013-01-02 14:35:16 +01:00
$sql .= " AND f.datef between ' " . $db -> idate ( dol_get_first_day ( date ( " Y " ), 1 , 1 )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( date ( " Y " ), 12 , 1 )) . " ' " ;
2012-07-04 09:07:15 +02:00
$sql .= " GROUP BY f.paye, f.fk_statut " ;
$sql .= " ORDER BY f.fk_statut DESC " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
2012-07-08 23:22:22 +02:00
$now = dol_now ();
2012-07-04 09:07:15 +02:00
$i = 0 ;
while ( $i < $num )
{
$this -> info_box_contents [ $i ][ 0 ] = array ( 'td' => 'align="left" width="16"' ,
'logo' => 'bill' );
$objp = $db -> fetch_object ( $result );
$this -> info_box_contents [ $i ][ 1 ] = array ( 'td' => 'align="left"' ,
'text' => $langs -> trans ( " Bills " ) . " " . $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 0 ));
if ( $objp -> fk_statut == 0 )
{ // draft
$billurl = " viewstatut=0&paye=0 " ;
} elseif ( $objp -> fk_statut == 1 )
{ // unpaid
$billurl = " viewstatut=1&paye=0 " ;
} else
{ // paid for current year
$billurl = " viewstatut=2&paye=1 " ;
}
$this -> info_box_contents [ $i ][ 2 ] = array ( 'td' => 'align="right"' ,
'text' => $objp -> nb , 'url' => DOL_URL_ROOT . " /compta/facture/list.php? " . $billurl . " &mainmenu=accountancy&leftmenu=customers_bills "
);
$totalnb += $objp -> nb ;
$this -> info_box_contents [ $i ][ 3 ] = array ( 'td' => 'align="right"' ,
'text' => dol_trunc ( number_format ( $objp -> Mnttot , 0 , ',' , ' ' ), 40 ) . " " . getCurrencySymbol ( $conf -> currency )
);
$totalMnt += $objp -> Mnttot ;
$this -> info_box_contents [ $i ][ 4 ] = array ( 'td' => 'align="right" width="18"' ,
'text' => $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 3 )
);
$i ++ ;
}
if ( $num == 0 ) $this -> info_box_contents [ $i ][ 0 ] = array ( 'td' => 'align="center"' , 'text' => $langs -> trans ( " NoRecordedInvoices " ));
} else {
$this -> info_box_contents [ 0 ][ 0 ] = array ( 'td' => 'align="left"' , 'maxlength' => 500 , 'text' => ( $db -> error () . ' sql=' . $sql ));
}
}
// list the summary of the orders
2012-09-15 11:21:22 +02:00
if ( ! empty ( $conf -> commande -> enabled ) && $user -> rights -> commande -> lire )
2012-07-04 09:07:15 +02:00
{
$sql = " SELECT c.fk_statut,c.facture, sum(c.total_ttc) as Mnttot, count(*) as nb " ;
2013-01-02 14:35:16 +01:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " commande as c " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " ) " ;
2012-07-04 09:07:15 +02:00
$sql .= " WHERE c.entity = " . $conf -> entity ;
$sql .= " AND c.fk_soc = s.rowid " ;
2013-01-02 14:35:16 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
if ( $user -> societe_id ) $sql .= " AND s.rowid = " . $user -> societe_id ;
2013-01-18 13:56:36 +01:00
$sql .= " AND c.date_commande between ' " . $db -> idate ( dol_get_first_day ( date ( " Y " ), 1 , 1 )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( date ( " Y " ), 12 , 1 )) . " ' " ;
2012-07-04 09:07:15 +02:00
$sql .= " AND c.facture=0 " ;
2013-01-18 13:56:36 +01:00
$sql .= " GROUP BY c.fk_statut,c.facture " ;
2012-07-04 09:07:15 +02:00
$sql .= " ORDER BY c.fk_statut DESC " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result ) + $i ;
while ( $i < $num )
{
$this -> info_box_contents [ $i ][ 0 ] = array ( 'td' => 'align="left" width="16"' , 'logo' => 'object_order' );
$objp = $db -> fetch_object ( $result );
$this -> info_box_contents [ $i ][ 1 ] = array ( 'td' => 'align="left"' ,
'text' => $langs -> trans ( " Orders " ) . " " . $commandestatic -> LibStatut ( $objp -> fk_statut , $objp -> facture , 0 )
);
$this -> info_box_contents [ $i ][ 2 ] = array ( 'td' => 'align="right"' ,
'text' => $objp -> nb ,
'url' => DOL_URL_ROOT . " /commande/liste.php?mainmenu=commercial&leftmenu=orders&viewstatut= " . $objp -> fk_statut
);
$totalnb += $objp -> nb ;
$this -> info_box_contents [ $i ][ 3 ] = array ( 'td' => 'align="right"' ,
'text' => dol_trunc ( number_format ( $objp -> Mnttot , 0 , ',' , ' ' ), 40 ) . " " . getCurrencySymbol ( $conf -> currency )
);
$totalMnt += $objp -> Mnttot ;
$this -> info_box_contents [ $i ][ 4 ] = array ( 'td' => 'align="right" width="18"' , 'text' => $commandestatic -> LibStatut ( $objp -> fk_statut , $objp -> facture , 3 ));
$i ++ ;
}
}
}
// list the summary of the propals
2012-09-15 11:21:22 +02:00
if ( ! empty ( $conf -> propal -> enabled ) && $user -> rights -> propal -> lire )
2012-07-04 09:07:15 +02:00
{
$sql = " SELECT p.fk_statut, sum(p.total) as Mnttot, count(*) as nb " ;
2013-01-02 14:35:16 +01:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as p " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " ) " ;
2012-07-04 09:07:15 +02:00
$sql .= " WHERE p.entity = " . $conf -> entity ;
$sql .= " AND p.fk_soc = s.rowid " ;
2013-01-02 14:35:16 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
if ( $user -> societe_id ) $sql .= " AND s.rowid = " . $user -> societe_id ;
$sql .= " AND p.datep between ' " . $db -> idate ( dol_get_first_day ( date ( " Y " ), 1 , 1 )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( date ( " Y " ), 12 , 1 )) . " ' " ;
$sql .= " AND p.date_cloture IS NULL " ; // just unclosed
2012-07-04 09:07:15 +02:00
$sql .= " GROUP BY p.fk_statut " ;
$sql .= " ORDER BY p.fk_statut DESC " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result ) + $i ;
while ( $i < $num )
{
$this -> info_box_contents [ $i ][ 0 ] = array ( 'td' => 'align="left" width="16"' , 'logo' => 'object_propal' );
$objp = $db -> fetch_object ( $result );
$this -> info_box_contents [ $i ][ 1 ] = array ( 'td' => 'align="left"' ,
'text' => $langs -> trans ( " Proposals " ) . " " . $propalstatic -> LibStatut ( $objp -> fk_statut , 0 )
);
$this -> info_box_contents [ $i ][ 2 ] = array ( 'td' => 'align="right"' ,
'text' => $objp -> nb ,
'url' => DOL_URL_ROOT . " /comm/propal/list.php?mainmenu=commercial&leftmenu=propals&viewstatut= " . $objp -> fk_statut
);
$totalnb += $objp -> nb ;
$this -> info_box_contents [ $i ][ 3 ] = array ( 'td' => 'align="right"' ,
'text' => dol_trunc ( number_format ( $objp -> Mnttot , 0 , ',' , ' ' ), 40 ) . " " . getCurrencySymbol ( $conf -> currency )
);
$totalMnt += $objp -> Mnttot ;
$this -> info_box_contents [ $i ][ 4 ] = array ( 'td' => 'align="right" width="18"' , 'text' => $propalstatic -> LibStatut ( $objp -> fk_statut , 3 ));
$i ++ ;
}
}
}
// Add the sum in the bottom of the boxes
$this -> info_box_contents [ $i ][ 1 ] = array ( 'td' => 'align="left" ' , 'text' => $langs -> trans ( " Total " ) . " " . $textHead );
$this -> info_box_contents [ $i ][ 2 ] = array ( 'td' => 'align="right" ' , 'text' => number_format ( $totalnb , 0 , ',' , ' ' ));
$this -> info_box_contents [ $i ][ 3 ] = array ( 'td' => 'align="right" ' , 'text' => number_format ( $totalMnt , 0 , ',' , ' ' ) . " " . getCurrencySymbol ( $conf -> currency ));
$this -> info_box_contents [ $i ][ 4 ] = array ( 'td' => 'align="right" ' , 'text' => " " );
$this -> info_box_contents [ $i ][ 5 ] = array ( 'td' => 'align="right"' , 'text' => " " );
}
2012-07-25 11:35:34 +02:00
/**
* Method to show box
*
* @ param array $head Array with properties of box title
* @ param array $contents Array with properties of box lines
* @ return void
*/
2012-07-04 09:07:15 +02:00
function showBox ( $head = null , $contents = null )
{
parent :: showBox ( $this -> info_box_head , $this -> info_box_contents );
}
}
?>