2004-10-19 22:43:23 +02:00
< ? php
2004-05-27 12:11:38 +02:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-05-22 02:42:37 +02:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2003-08-03 21:15:39 +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
2003-08-03 21:15:39 +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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-08-03 21:15:39 +02:00
*/
2004-09-27 01:02:40 +02:00
2005-04-23 00:39:11 +02:00
/**
2009-02-09 20:31:06 +01:00
* \file htdocs / contrat / index . php
* \ingroup contrat
2011-08-08 16:25:44 +02:00
* \brief Home page of contract area
2009-02-09 20:31:06 +01:00
*/
2004-09-27 01:02:40 +02:00
2010-03-27 15:50:05 +01:00
require ( " ../main.inc.php " );
2010-04-28 10:35:57 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /contrat/class/contrat.class.php " );
2012-04-07 00:30:36 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /product/class/product.class.php " );
2003-08-03 21:15:39 +02:00
2004-09-27 01:02:40 +02:00
$langs -> load ( " products " );
2004-09-27 01:15:30 +02:00
$langs -> load ( " companies " );
2004-09-27 01:02:40 +02:00
2012-07-25 11:46:33 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2004-10-31 18:34:44 +01:00
2012-07-25 11:46:33 +02:00
$statut = GETPOST ( 'statut' ) ? GETPOST ( 'statut' ) : 1 ;
2004-07-25 20:24:32 +02:00
2008-02-25 17:30:43 +01:00
// Security check
2009-01-21 16:06:34 +01:00
$socid = 0 ;
2012-05-03 18:40:52 +02:00
$id = GETPOST ( 'id' , 'int' );
2012-07-25 11:46:33 +02:00
if ( ! empty ( $user -> societe_id )) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'contrat' , $id );
2003-08-03 21:15:39 +02:00
2008-04-13 21:53:39 +02:00
$staticcompany = new Societe ( $db );
2006-03-17 01:14:55 +01:00
$staticcontrat = new Contrat ( $db );
2006-03-18 18:41:36 +01:00
$staticcontratligne = new ContratLigne ( $db );
2011-08-08 16:25:44 +02:00
$productstatic = new Product ( $db );
/*
* Action
*/
// None
2006-03-17 01:14:55 +01:00
/*
2008-07-12 13:24:01 +02:00
* View
2006-03-17 01:14:55 +01:00
*/
2011-05-22 02:42:37 +02:00
$now = dol_now ();
2009-02-09 20:31:06 +01:00
2006-03-17 01:14:55 +01:00
llxHeader ();
2005-08-11 20:54:59 +02:00
print_fiche_titre ( $langs -> trans ( " ContractsArea " ));
2004-07-25 20:24:32 +02:00
2013-03-30 14:27:13 +01:00
//print '<table border="0" width="100%" class="notopnoleftnoright">';
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2005-04-23 00:39:11 +02:00
2009-04-15 13:42:39 +02:00
// Search contract
2012-07-25 11:46:33 +02:00
if ( ! empty ( $conf -> contrat -> enabled ))
2005-08-25 00:27:23 +02:00
{
2009-07-08 12:10:35 +02:00
$var = false ;
2005-06-11 13:33:21 +02:00
print '<form method="post" action="' . DOL_URL_ROOT . '/contrat/liste.php">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2012-09-09 13:13:24 +02:00
print '<table class="noborder nohover" width="100%">' ;
2005-06-11 13:33:21 +02:00
print '<tr class="liste_titre"><td colspan="3">' . $langs -> trans ( " SearchAContract " ) . '</td></tr>' ;
2005-08-25 00:27:23 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2013-07-19 14:23:42 +02:00
print '<td class="nowrap">' . $langs -> trans ( " Ref " ) . ':</td><td><input type="text" class="flat" name="search_contract" size="18"></td>' ;
2005-08-25 00:27:23 +02:00
print '<td rowspan="2"><input type="submit" value="' . $langs -> trans ( " Search " ) . '" class="button"></td></tr>' ;
2013-07-19 14:23:42 +02:00
print '<tr ' . $bc [ $var ] . '><td class="nowrap">' . $langs -> trans ( " Other " ) . ':</td><td><input type="text" class="flat" name="sall" size="18"></td>' ;
2005-08-25 00:27:23 +02:00
print '</tr>' ;
2005-07-03 15:07:59 +02:00
print " </table></form> \n " ;
2005-08-25 00:27:23 +02:00
print " <br> " ;
2005-06-11 13:33:21 +02:00
}
2009-07-08 12:10:35 +02:00
/*
2011-05-22 02:42:37 +02:00
* Statistics
2009-07-08 12:10:35 +02:00
*/
2011-05-22 02:42:37 +02:00
2009-07-08 12:10:35 +02:00
$nb = array ();
2011-05-22 02:42:37 +02:00
$total = 0 ;
$totalinprocess = 0 ;
$dataseries = array ();
$vals = array ();
2009-07-08 12:10:35 +02:00
// Search by status (except expired)
$sql = " SELECT count(cd.rowid), cd.statut " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd, " . MAIN_DB_PREFIX . " contrat as c " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid " ;
2012-02-06 05:31:19 +01:00
$sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= ' " . $db -> idate ( $now ) . " '))) " ;
2012-05-03 18:40:52 +02:00
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2009-07-08 12:10:35 +02:00
if ( $user -> societe_id ) $sql .= ' AND c.fk_soc = ' . $user -> societe_id ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
$sql .= " GROUP BY cd.statut " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$row = $db -> fetch_row ( $resql );
2011-05-22 02:42:37 +02:00
if ( $row )
{
$nb [ $row [ 1 ]] = $row [ 0 ];
if ( $row [ 1 ] != 5 )
{
$vals [ $row [ 1 ]] = $row [ 0 ];
$totalinprocess += $row [ 0 ];
}
$total += $row [ 0 ];
}
2009-07-08 12:10:35 +02:00
$i ++ ;
}
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
// Search by status (only expired)
$sql = " SELECT count(cd.rowid), cd.statut " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd, " . MAIN_DB_PREFIX . " contrat as c " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid " ;
2012-02-06 05:31:19 +01:00
$sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ') " ;
2012-05-03 18:40:52 +02:00
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2009-07-08 12:10:35 +02:00
if ( $user -> societe_id ) $sql .= ' AND c.fk_soc = ' . $user -> societe_id ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
$sql .= " GROUP BY cd.statut " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
2011-05-22 02:42:37 +02:00
// 0 inactive, 4 active, 5 closed
$i = 0 ;
while ( $i < $num )
{
$row = $db -> fetch_row ( $resql );
if ( $row )
{
$nb [ $row [ 1 ] . true ] = $row [ 0 ];
if ( $row [ 1 ] != 5 )
{
$vals [ $row [ 1 ]] = $row [ 0 ];
$totalinprocess += $row [ 0 ];
}
$total += $row [ 0 ];
}
$i ++ ;
}
$db -> free ( $resql );
2009-07-08 12:10:35 +02:00
}
else
{
dol_print_error ( $db );
}
2011-05-22 02:42:37 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Statistics " ) . ' - ' . $langs -> trans ( " Services " ) . '</td></tr>' . " \n " ;
$var = true ;
$listofstatus = array ( 0 , 4 , 4 , 5 ); $bool = false ;
foreach ( $listofstatus as $status )
{
2012-07-25 11:46:33 +02:00
$dataseries [] = array ( 'label' => $staticcontratligne -> LibStatut ( $status , 1 ,( $bool ? 1 : 0 )), 'data' => ( isset ( $nb [ $status . $bool ]) ? ( int ) $nb [ $status . $bool ] : 0 ));
if ( empty ( $conf -> use_javascript_ajax ))
2011-05-22 02:42:37 +02:00
{
$var =! $var ;
2011-06-13 15:13:15 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2011-05-22 02:42:37 +02:00
print '<td>' . $staticcontratligne -> LibStatut ( $status , 0 ,( $bool ? 1 : 0 )) . '</td>' ;
print '<td align="right"><a href="services.php?mode=' . $status . ( $bool ? '&filter=expired' : '' ) . '">' . ( $nb [ $status . $bool ] ? $nb [ $status . $bool ] : 0 ) . ' ' . $staticcontratligne -> LibStatut ( $status , 3 ,( $bool ? 1 : 0 )) . '</a></td>' ;
print " </tr> \n " ;
}
if ( $status == 4 && $bool == false ) $bool = true ;
else $bool = false ;
}
2012-07-25 11:46:33 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2011-05-22 02:42:37 +02:00
{
print '<tr><td align="center" colspan="2">' ;
$data = array ( 'series' => $dataseries );
2011-06-07 00:23:24 +02:00
dol_print_graph ( 'stats' , 300 , 180 , $data , 1 , 'pie' , 1 );
2011-05-22 02:42:37 +02:00
print '</td></tr>' ;
}
2009-07-08 12:10:35 +02:00
$var = true ;
$listofstatus = array ( 0 , 4 , 4 , 5 ); $bool = false ;
foreach ( $listofstatus as $status )
{
2012-07-25 11:46:33 +02:00
if ( empty ( $conf -> use_javascript_ajax ))
2011-06-06 19:04:10 +02:00
{
$var =! $var ;
2011-06-13 15:13:15 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2011-06-06 19:04:10 +02:00
print '<td>' . $staticcontratligne -> LibStatut ( $status , 0 ,( $bool ? 1 : 0 )) . '</td>' ;
print '<td align="right"><a href="services.php?mode=' . $status . ( $bool ? '&filter=expired' : '' ) . '">' . ( $nb [ $status . $bool ] ? $nb [ $status . $bool ] : 0 ) . ' ' . $staticcontratligne -> LibStatut ( $status , 3 ,( $bool ? 1 : 0 )) . '</a></td>' ;
if ( $status == 4 && $bool == false ) $bool = true ;
else $bool = false ;
print " </tr> \n " ;
}
2009-07-08 12:10:35 +02:00
}
2011-05-22 02:42:37 +02:00
//if ($totalinprocess != $total)
//print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("ServicesRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
print '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td><td align="right">' . $total . '</td></tr>' ;
2009-07-08 12:10:35 +02:00
print " </table><br> " ;
2008-04-07 19:16:45 +02:00
/**
* Draft contratcs
*/
2012-07-25 11:46:33 +02:00
if ( ! empty ( $conf -> contrat -> enabled ) && $user -> rights -> contrat -> lire )
2008-04-07 19:16:45 +02:00
{
$sql = " SELECT c.rowid as ref, c.rowid, " ;
$sql .= " s.nom, s.rowid as socid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " contrat as c, " . MAIN_DB_PREFIX . " societe as s " ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE s.rowid = c.fk_soc " ;
2012-05-03 18:40:52 +02:00
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND c.statut = 0 " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2013-01-02 18:43:59 +01:00
if ( $socid ) $sql .= " AND c.fk_soc = " . $socid ;
2008-04-07 19:16:45 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$var = false ;
$num = $db -> num_rows ( $resql );
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td colspan="3">' . $langs -> trans ( " DraftContracts " ) . ( $num ? ' (' . $num . ')' : '' ) . '</td></tr>' ;
if ( $num )
{
$companystatic = new Societe ( $db );
$i = 0 ;
2009-01-21 16:06:34 +01:00
//$tot_ttc = 0;
2008-04-07 19:16:45 +02:00
while ( $i < $num && $i < 20 )
{
$obj = $db -> fetch_object ( $resql );
2013-07-19 14:23:42 +02:00
print '<tr ' . $bc [ $var ] . '><td class="nowrap">' ;
2008-04-07 19:16:45 +02:00
$staticcontrat -> ref = $obj -> ref ;
$staticcontrat -> id = $obj -> rowid ;
print $staticcontrat -> getNomUrl ( 1 , '' );
print '</td>' ;
print '<td>' ;
$companystatic -> id = $obj -> socid ;
$companystatic -> nom = $obj -> nom ;
$companystatic -> client = 1 ;
print $companystatic -> getNomUrl ( 1 , '' , 16 );
print '</td>' ;
print '</tr>' ;
2009-01-21 16:06:34 +01:00
//$tot_ttc+=$obj->total_ttc;
2008-04-07 19:16:45 +02:00
$i ++ ;
$var =! $var ;
}
}
else
{
print '<tr colspan="3" ' . $bc [ $var ] . '><td>' . $langs -> trans ( " NoContracts " ) . '</td></tr>' ;
}
print " </table><br> " ;
$db -> free ( $resql );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-04-07 19:16:45 +02:00
}
}
2003-08-03 21:15:39 +02:00
2013-03-17 19:31:13 +01:00
2013-03-30 14:27:13 +01:00
//print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">' ;
2004-07-25 20:24:32 +02:00
2005-07-03 04:37:16 +02:00
2008-04-13 21:53:39 +02:00
// Last modified contracts
2005-07-03 04:37:16 +02:00
$max = 5 ;
2005-07-03 15:07:59 +02:00
$sql = 'SELECT ' ;
$sql .= ' sum(' . $db -> ifsql ( " cd.statut=0 " , 1 , 0 ) . ') as nb_initial,' ;
2012-04-07 00:30:36 +02:00
$sql .= ' sum(' . $db -> ifsql ( " cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= ' " . $db -> idate ( $now ) . " ') " , 1 , 0 ) . ') as nb_running,' ;
$sql .= ' sum(' . $db -> ifsql ( " cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ') " , 1 , 0 ) . ') as nb_expired,' ;
$sql .= ' sum(' . $db -> ifsql ( " cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < ' " . $db -> idate ( $now - $conf -> contrat -> services -> expires -> warning_delay ) . " ') " , 1 , 0 ) . ') as nb_late,' ;
2005-07-03 15:07:59 +02:00
$sql .= ' sum(' . $db -> ifsql ( " cd.statut=5 " , 1 , 0 ) . ') as nb_closed,' ;
2008-07-12 13:24:01 +02:00
$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid as socid " ;
2007-01-31 11:04:56 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " " . MAIN_DB_PREFIX . " societe_commerciaux as sc, " ;
2007-01-31 11:04:56 +01:00
$sql .= " " . MAIN_DB_PREFIX . " contrat as c " ;
2005-07-03 04:37:16 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " contratdet as cd ON c.rowid = cd.fk_contrat " ;
2009-04-27 22:37:50 +02:00
$sql .= " WHERE c.fk_soc = s.rowid " ;
2012-05-03 18:40:52 +02:00
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND c.statut > 0 " ;
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 ;
2010-11-16 22:45:33 +01:00
$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid " ;
2008-04-07 19:16:45 +02:00
$sql .= " ORDER BY c.tms DESC " ;
$sql .= " LIMIT " . $max ;
2005-07-03 04:37:16 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " contrat/index.php sql= " . $sql , LOG_DEBUG );
2005-07-03 04:37:16 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2009-01-21 16:06:34 +01:00
2009-07-08 12:10:35 +02:00
print '<table class="noborder" width="100%">' ;
2009-01-21 16:06:34 +01:00
2009-07-08 12:10:35 +02:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " LastContracts " , 5 ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " DateModification " ) . '</td>' ;
//print '<td align="left">'.$langs->trans("Status").'</td>';
2011-06-13 15:13:15 +02:00
print '<td align="center" width="80" colspan="4">' . $langs -> trans ( " Services " ) . '</td>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2009-01-21 16:06:34 +01:00
2009-07-08 12:10:35 +02:00
$var = True ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$var =! $var ;
2009-01-21 16:06:34 +01:00
2011-06-13 15:13:15 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2013-04-25 01:13:13 +02:00
print '<td width="110" class="nowrap">' ;
2008-04-13 21:53:39 +02:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> cid );
$staticcontrat -> id = $obj -> cid ;
print $staticcontrat -> getNomUrl ( 1 , 16 );
2009-07-08 12:10:35 +02:00
if ( $obj -> nb_late ) print img_warning ( $langs -> trans ( " Late " ));
print '</td>' ;
print '<td>' ;
2008-09-05 16:10:44 +02:00
$staticcompany -> id = $obj -> socid ;
2008-04-13 21:53:39 +02:00
$staticcompany -> nom = $obj -> nom ;
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
print '</td>' ;
2009-07-08 12:10:35 +02:00
print '<td align="center">' . dol_print_date ( $obj -> tms , 'dayhour' ) . '</td>' ;
//print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
print '<td align="right" width="32">' . ( $obj -> nb_initial > 0 ? $obj -> nb_initial . $staticcontratligne -> LibStatut ( 0 , 3 ) : '' ) . '</td>' ;
print '<td align="right" width="32">' . ( $obj -> nb_running > 0 ? $obj -> nb_running . $staticcontratligne -> LibStatut ( 4 , 3 , 0 ) : '' ) . '</td>' ;
print '<td align="right" width="32">' . ( $obj -> nb_expired > 0 ? $obj -> nb_expired . $staticcontratligne -> LibStatut ( 4 , 3 , 1 ) : '' ) . '</td>' ;
print '<td align="right" width="32">' . ( $obj -> nb_closed > 0 ? $obj -> nb_closed . $staticcontratligne -> LibStatut ( 5 , 3 ) : '' ) . '</td>' ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $result );
print " </table> " ;
2009-01-21 16:06:34 +01:00
2005-07-03 04:37:16 +02:00
}
else
{
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
2005-07-03 04:37:16 +02:00
}
print '<br>' ;
2011-08-08 16:25:44 +02:00
// Last modified services
$sql = " SELECT c.ref, c.fk_soc, " ;
$sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite, " ;
$sql .= " s.nom, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype " ;
2012-04-07 00:30:36 +02:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
2011-08-08 16:25:44 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2012-04-07 00:30:36 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
2012-05-03 18:40:52 +02:00
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2012-02-11 10:18:09 +01:00
$sql .= " AND cd.fk_contrat = c.rowid " ;
2011-08-08 16:25:44 +02:00
$sql .= " AND c.fk_soc = s.rowid " ;
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 ;
$sql .= " ORDER BY cd.tms DESC " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre"><td colspan="4">' . $langs -> trans ( " LastModifiedServices " , $max ) . '</td>' ;
print " </tr> \n " ;
$var = True ;
while ( $i < min ( $num , $max ))
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2013-04-25 01:13:13 +02:00
print '<td width="110" class="nowrap">' ;
2011-08-08 16:25:44 +02:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
print $staticcontrat -> getNomUrl ( 1 , 16 );
//if (1 == 1) print img_warning($langs->trans("Late"));
print '</td>' ;
print '<td>' ;
if ( $obj -> fk_product > 0 )
{
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
print $productstatic -> getNomUrl ( 1 , '' , 20 );
}
else
{
print '<a href="' . DOL_URL_ROOT . '/contrat/fiche.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
if ( $obj -> label ) print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
else print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
print '</td>' ;
print '<td>' ;
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> nom = $obj -> nom ;
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" align="right"><a href="' . DOL_URL_ROOT . '/contrat/fiche.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
2011-08-08 16:25:44 +02:00
$dateend = $db -> jdate ( $obj -> date_fin_validite );
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 , ( $dateend && $dateend < $now ) ? 1 : 0 );
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ();
print " </table> " ;
}
else
{
dol_print_error ( $db );
}
print '<br>' ;
2005-07-03 04:37:16 +02:00
2005-04-23 00:39:11 +02:00
// Not activated services
2011-08-08 16:25:44 +02:00
$sql = " SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, " ;
$sql .= " s.nom, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype " ;
2012-04-07 00:30:36 +02:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
2009-04-27 22:37:50 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2012-04-07 00:30:36 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
2011-08-08 16:25:44 +02:00
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
2012-05-03 18:40:52 +02:00
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2012-02-11 10:18:09 +01:00
$sql .= " AND c.statut = 1 " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND cd.statut = 0 " ;
$sql .= " AND cd.fk_contrat = c.rowid " ;
$sql .= " AND c.fk_soc = s.rowid " ;
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 ;
2005-04-29 00:38:00 +02:00
$sql .= " ORDER BY cd.tms DESC " ;
2003-08-03 21:15:39 +02:00
2010-08-09 17:52:44 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2003-08-03 21:15:39 +02:00
{
2010-08-09 17:52:44 +02:00
$num = $db -> num_rows ( $resql );
2009-07-08 12:10:35 +02:00
$i = 0 ;
2003-08-03 21:15:39 +02:00
2009-07-08 12:10:35 +02:00
print '<table class="noborder" width="100%">' ;
2003-08-03 21:15:39 +02:00
2011-08-08 16:25:44 +02:00
print '<tr class="liste_titre"><td colspan="4">' . $langs -> trans ( " NotActivatedServices " ) . ' <a href="' . DOL_URL_ROOT . '/contrat/services.php?mode=0">(' . $num . ')</a></td>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2005-04-23 00:39:11 +02:00
2009-07-08 12:10:35 +02:00
$var = True ;
while ( $i < $num )
{
2010-08-09 17:52:44 +02:00
$obj = $db -> fetch_object ( $resql );
2009-07-08 12:10:35 +02:00
$var =! $var ;
2011-06-13 15:13:15 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2005-04-23 00:39:11 +02:00
2013-04-25 01:13:13 +02:00
print '<td width="110" class="nowrap">' ;
2008-04-13 21:53:39 +02:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
print $staticcontrat -> getNomUrl ( 1 , 16 );
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2011-08-08 16:25:44 +02:00
if ( $obj -> fk_product > 0 )
{
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
print $productstatic -> getNomUrl ( 1 , '' , 20 );
}
else
{
print '<a href="' . DOL_URL_ROOT . '/contrat/fiche.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
if ( $obj -> label ) print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
else print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
print '</td>' ;
2009-07-08 12:10:35 +02:00
print '<td>' ;
2008-04-13 21:53:39 +02:00
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> nom = $obj -> nom ;
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
print '</td>' ;
2009-07-08 12:10:35 +02:00
print '<td width="16" align="right"><a href="ligne.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 );
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ();
2004-11-26 15:17:48 +01:00
2009-07-08 12:10:35 +02:00
print " </table> " ;
2005-04-23 00:39:11 +02:00
}
else
{
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
2005-04-23 00:39:11 +02:00
}
2004-11-26 15:17:48 +01:00
2005-04-23 00:39:11 +02:00
print '<br>' ;
2004-11-26 15:17:48 +01:00
2011-08-08 16:25:44 +02:00
// Expired services
$sql = " SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, " ;
$sql .= " s.nom, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype " ;
2012-04-07 00:30:36 +02:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
2009-04-27 22:37:50 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2012-04-07 00:30:36 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
2011-08-08 16:25:44 +02:00
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
2012-05-03 18:40:52 +02:00
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' ) . " ) " ;
2012-02-11 10:18:09 +01:00
$sql .= " AND c.statut = 1 " ;
2011-08-08 16:25:44 +02:00
$sql .= " AND cd.statut = 4 " ;
$sql .= " AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ' " ;
$sql .= " AND cd.fk_contrat = c.rowid " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND c.fk_soc = s.rowid " ;
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 ;
2005-07-03 15:07:59 +02:00
$sql .= " ORDER BY cd.tms DESC " ;
2005-04-23 00:39:11 +02:00
2008-04-13 21:53:39 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2005-04-23 00:39:11 +02:00
{
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2005-04-23 00:39:11 +02:00
2009-07-08 12:10:35 +02:00
print '<table class="noborder" width="100%">' ;
2005-04-23 00:39:11 +02:00
2011-08-08 16:25:44 +02:00
print '<tr class="liste_titre"><td colspan="4">' . $langs -> trans ( " ListOfExpiredServices " ) . ' <a href="' . DOL_URL_ROOT . '/contrat/services.php?mode=4&filter=expired">(' . $num . ')</a></td>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2005-04-23 00:39:11 +02:00
2009-07-08 12:10:35 +02:00
$var = True ;
2011-08-08 16:25:44 +02:00
while ( $i < $num )
2009-07-08 12:10:35 +02:00
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
2011-06-13 15:13:15 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2011-08-08 16:25:44 +02:00
2013-04-25 01:13:13 +02:00
print '<td width="110" class="nowrap">' ;
2008-04-13 21:53:39 +02:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
print $staticcontrat -> getNomUrl ( 1 , 16 );
2009-07-08 12:10:35 +02:00
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2011-08-08 16:25:44 +02:00
if ( $obj -> fk_product > 0 )
{
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
print $productstatic -> getNomUrl ( 1 , '' , 20 );
}
else
{
print '<a href="' . DOL_URL_ROOT . '/contrat/fiche.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
if ( $obj -> label ) print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
else print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
print '</td>' ;
2009-07-08 12:10:35 +02:00
print '<td>' ;
2008-04-13 21:53:39 +02:00
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> nom = $obj -> nom ;
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
print '</td>' ;
2011-08-08 16:25:44 +02:00
print '<td width="16" align="right"><a href="ligne.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 , 1 );
2009-07-08 12:10:35 +02:00
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ();
2003-08-03 21:15:39 +02:00
2009-07-08 12:10:35 +02:00
print " </table> " ;
2003-08-03 21:15:39 +02:00
}
else
{
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
2003-08-03 21:15:39 +02:00
}
2013-03-17 19:31:13 +01:00
//print '</td></tr></table>';
2013-03-30 19:40:52 +01:00
print '</div></div></div>' ;
2005-06-26 04:12:53 +02:00
2003-08-03 21:15:39 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-04-07 00:30:36 +02:00
$db -> close ();
2011-06-13 15:13:15 +02:00
?>