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 >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2015-04-18 21:28:55 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2019-06-18 14:07:52 +02:00
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// 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
2018-07-26 11:57:25 +02:00
require " ../main.inc.php " ;
require_once DOL_DOCUMENT_ROOT . " /contrat/class/contrat.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /product/class/product.class.php " ;
2003-08-03 21:15:39 +02:00
2019-06-18 14:07:52 +02:00
$hookmanager = new HookManager ( $db );
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager -> initHooks ( array ( 'contractindex' ));
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'products' , 'companies' , 'contracts' ));
2004-09-27 01:02:40 +02:00
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2004-10-31 18:34:44 +01:00
2019-11-12 00:15:34 +01: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
2019-11-12 00:15:34 +01:00
$socid = 0 ;
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
2021-02-23 21:24:38 +01:00
if ( ! empty ( $user -> socid )) {
$socid = $user -> socid ;
}
2012-07-25 11:46:33 +02:00
$result = restrictedArea ( $user , 'contrat' , $id );
2003-08-03 21:15:39 +02:00
2019-11-12 00:15:34 +01:00
$staticcompany = new Societe ( $db );
$staticcontrat = new Contrat ( $db );
$staticcontratligne = new ContratLigne ( $db );
$productstatic = new Product ( $db );
2011-08-08 16:25:44 +02:00
/*
* 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 ();
2020-04-25 13:49:44 +02:00
print load_fiche_titre ( $langs -> trans ( " ContractsArea " ), '' , 'contract' );
2004-07-25 20:24:32 +02:00
2013-03-30 14:27:13 +01:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2005-04-23 00:39:11 +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
2019-11-12 00:15:34 +01:00
$nb = array ();
$total = 0 ;
$totalinprocess = 0 ;
$dataseries = array ();
$vals = array ();
2011-05-22 02:42:37 +02:00
2009-07-08 12:10:35 +02:00
// Search by status (except expired)
2020-03-24 20:18:18 +01:00
$sql = " SELECT count(cd.rowid) as nb, cd.statut as status " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd, " . MAIN_DB_PREFIX . " contrat as c " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid " ;
$sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= ' " . $db -> idate ( $now ) . " '))) " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
2021-02-23 21:24:38 +01:00
if ( $user -> socid ) {
2021-08-28 00:55:51 +02:00
$sql .= ' AND c.fk_soc = ' . (( int ) $user -> socid );
2021-02-23 21:24:38 +01:00
}
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " GROUP BY cd.statut " ;
2009-07-08 12:10:35 +02:00
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2020-03-24 20:18:18 +01:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 21:24:38 +01:00
if ( $obj ) {
2020-03-24 20:18:18 +01:00
$nb [ $obj -> status ] = $obj -> nb ;
2021-02-23 21:24:38 +01:00
if ( $obj -> status != 5 ) {
2020-10-31 14:32:18 +01:00
$vals [ $obj -> status ] = $obj -> nb ;
$totalinprocess += $obj -> nb ;
}
$total += $obj -> nb ;
2011-05-22 02:42:37 +02:00
}
2009-07-08 12:10:35 +02:00
$i ++ ;
}
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
}
// Search by status (only expired)
2020-03-24 20:18:18 +01:00
$sql = " SELECT count(cd.rowid) as nb, cd.statut as status " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd, " . MAIN_DB_PREFIX . " contrat as c " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid " ;
$sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ') " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
2021-02-23 21:24:38 +01:00
if ( $user -> socid ) {
2021-08-28 00:55:51 +02:00
$sql .= ' AND c.fk_soc = ' . (( int ) $user -> socid );
2021-02-23 21:24:38 +01:00
}
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " GROUP BY cd.statut " ;
2009-07-08 12:10:35 +02:00
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $resql );
2020-10-31 14:32:18 +01:00
// 0 inactive, 4 active, 5 closed
$i = 0 ;
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 21:24:38 +01:00
if ( $obj ) {
2020-10-31 14:32:18 +01:00
$nb [ $obj -> status . true ] = $obj -> nb ;
2021-02-23 21:24:38 +01:00
if ( $obj -> status != 5 ) {
2020-10-31 14:32:18 +01:00
$vals [ $obj -> status . true ] = $obj -> nb ;
$totalinprocess += $obj -> nb ;
}
$total += $obj -> nb ;
}
$i ++ ;
}
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
}
2011-05-22 02:42:37 +02:00
2020-03-24 20:18:18 +01:00
$colorseries = array ();
2021-04-06 22:18:32 +02:00
include DOL_DOCUMENT_ROOT . '/theme/' . $conf -> theme . '/theme_vars.inc.php' ;
2020-03-24 20:18:18 +01:00
2019-11-05 19:03:28 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder nohover centpercent">' ;
2017-03-07 22:45:22 +01:00
print '<tr class="liste_titre"><th colspan="2">' . $langs -> trans ( " Statistics " ) . ' - ' . $langs -> trans ( " Services " ) . '</th></tr>' . " \n " ;
2019-11-12 00:15:34 +01:00
$listofstatus = array ( 0 , 4 , 4 , 5 ); $bool = false ;
2021-02-23 21:24:38 +01:00
foreach ( $listofstatus as $status ) {
2020-10-31 14:32:18 +01:00
$dataseries [] = array ( $staticcontratligne -> LibStatut ( $status , 1 , ( $bool ? 1 : 0 )), ( isset ( $nb [ $status . $bool ]) ? ( int ) $nb [ $status . $bool ] : 0 ));
2021-02-23 21:24:38 +01:00
if ( $status == ContratLigne :: STATUS_INITIAL ) {
$colorseries [ $status . $bool ] = '-' . $badgeStatus0 ;
}
if ( $status == ContratLigne :: STATUS_OPEN && ! $bool ) {
$colorseries [ $status . $bool ] = $badgeStatus4 ;
}
if ( $status == ContratLigne :: STATUS_OPEN && $bool ) {
$colorseries [ $status . $bool ] = $badgeStatus1 ;
}
if ( $status == ContratLigne :: STATUS_CLOSED ) {
$colorseries [ $status . $bool ] = $badgeStatus6 ;
}
2020-10-31 14:32:18 +01:00
2021-02-23 21:24:38 +01:00
if ( empty ( $conf -> use_javascript_ajax )) {
2020-10-31 14:32:18 +01:00
print '<tr class="oddeven">' ;
print '<td>' . $staticcontratligne -> LibStatut ( $status , 0 , ( $bool ? 1 : 0 )) . '</td>' ;
print '<td class="right"><a href="services_list.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 " ;
}
2021-02-23 21:24:38 +01:00
if ( $status == 4 && ! $bool ) {
$bool = true ;
} else {
$bool = false ;
}
2011-05-22 02:42:37 +02:00
}
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-10-31 14:32:18 +01:00
print '<tr class="impair"><td class="center" colspan="2">' ;
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php' ;
$dolgraph = new DolGraph ();
$dolgraph -> SetData ( $dataseries );
$dolgraph -> SetDataColor ( array_values ( $colorseries ));
$dolgraph -> setShowLegend ( 2 );
$dolgraph -> setShowPercent ( 1 );
$dolgraph -> SetType ( array ( 'pie' ));
$dolgraph -> setHeight ( '200' );
$dolgraph -> draw ( 'idgraphstatus' );
print $dolgraph -> show ( $total ? 0 : 1 );
print '</td></tr>' ;
2011-05-22 02:42:37 +02:00
}
2019-11-12 00:15:34 +01:00
$listofstatus = array ( 0 , 4 , 4 , 5 ); $bool = false ;
2021-02-23 21:24:38 +01:00
foreach ( $listofstatus as $status ) {
if ( empty ( $conf -> use_javascript_ajax )) {
2020-10-31 14:32:18 +01:00
print '<tr class="oddeven">' ;
print '<td>' . $staticcontratligne -> LibStatut ( $status , 0 , ( $bool ? 1 : 0 )) . '</td>' ;
print '<td class="right"><a href="services_list.php?mode=' . $status . ( $bool ? '&filter=expired' : '' ) . '">' . ( $nb [ $status . $bool ] ? $nb [ $status . $bool ] : 0 ) . ' ' . $staticcontratligne -> LibStatut ( $status , 3 , ( $bool ? 1 : 0 )) . '</a></td>' ;
2021-02-23 21:24:38 +01:00
if ( $status == 4 && ! $bool ) {
$bool = true ;
} else {
$bool = false ;
}
2020-10-31 14:32:18 +01:00
print " </tr> \n " ;
}
2009-07-08 12:10:35 +02:00
}
2019-02-19 17:08:35 +01:00
print '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td><td class="right">' . $total . '</td></tr>' ;
2019-11-05 19:03:28 +01:00
print " </table></div><br> " ;
2009-07-08 12:10:35 +02:00
2017-12-09 20:58:06 +01:00
// Draft contracts
2021-02-23 21:24:38 +01:00
if ( ! empty ( $conf -> contrat -> enabled ) && $user -> rights -> contrat -> lire ) {
2019-11-12 00:15:34 +01:00
$sql = " SELECT c.rowid, c.ref, " ;
$sql .= " s.nom as name, s.rowid as socid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " contrat as c, " . MAIN_DB_PREFIX . " societe as s " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " WHERE s.rowid = c.fk_soc " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
$sql .= " AND c.statut = 0 " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
if ( $socid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND c.fk_soc = " . (( int ) $socid );
2021-02-23 21:24:38 +01:00
}
2008-04-07 19:16:45 +02:00
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
2008-04-07 19:16:45 +02:00
$num = $db -> num_rows ( $resql );
2019-11-07 12:43:33 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2008-04-07 19:16:45 +02:00
print '<tr class="liste_titre">' ;
2019-12-02 11:00:09 +01:00
print '<th colspan="3">' . $langs -> trans ( " DraftContracts " ) . ( $num ? '<span class="badge marginleftonlyshort">' . $num . '</span>' : '' ) . '</th></tr>' ;
2021-02-23 21:24:38 +01:00
if ( $num ) {
2019-11-12 00:15:34 +01:00
$companystatic = new Societe ( $db );
2008-04-07 19:16:45 +02:00
$i = 0 ;
2009-01-21 16:06:34 +01:00
//$tot_ttc = 0;
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2008-04-07 19:16:45 +02:00
$obj = $db -> fetch_object ( $resql );
2017-12-09 20:58:06 +01:00
2019-11-12 00:15:34 +01:00
$staticcontrat -> ref = $obj -> ref ;
$staticcontrat -> id = $obj -> rowid ;
2017-12-09 20:58:06 +01:00
2019-11-12 00:15:34 +01:00
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> name ;
$companystatic -> client = 1 ;
2017-12-09 20:58:06 +01:00
print '<tr class="oddeven"><td class="nowrap">' ;
2019-01-27 11:55:16 +01:00
print $staticcontrat -> getNomUrl ( 1 , '' );
2017-12-09 20:58:06 +01:00
print '</td>' ;
print '<td>' ;
2019-01-27 11:55:16 +01:00
print $companystatic -> getNomUrl ( 1 , '' , 16 );
2008-04-07 19:16:45 +02:00
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 ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-05-12 16:02:01 +02:00
print '<tr class="oddeven"><td colspan="3" class="opacitymedium">' . $langs -> trans ( " NoContracts " ) . '</td></tr>' ;
2008-04-07 19:16:45 +02:00
}
2019-11-05 19:03:28 +01:00
print " </table></div><br> " ;
2008-04-07 19:16:45 +02:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} 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
2021-10-24 00:37:37 +02:00
print '</div><div class="fichetwothirdright">' ;
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
2019-11-12 00:15:34 +01:00
$max = 5 ;
2005-07-03 15:07:59 +02:00
$sql = 'SELECT ' ;
2021-08-28 00:55:51 +02:00
$sql .= " sum( " . $db -> ifsql ( " cd.statut=0 " , 1 , 0 ) . ') as nb_initial,' ;
$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,' ;
$sql .= " sum( " . $db -> ifsql ( " cd.statut=5 " , 1 , 0 ) . ') as nb_closed,' ;
2019-11-12 00:15:34 +01:00
$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " " . MAIN_DB_PREFIX . " societe_commerciaux as sc, " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " " . MAIN_DB_PREFIX . " contrat as c " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " contratdet as cd ON c.rowid = cd.fk_contrat " ;
$sql .= " WHERE c.fk_soc = s.rowid " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
$sql .= " AND c.statut > 0 " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
if ( $socid ) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid " ;
$sql .= " ORDER BY c.tms DESC " ;
2021-04-24 20:18:11 +02:00
$sql .= $db -> plimit ( $max );
2005-07-03 04:37:16 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " contrat/index.php " , LOG_DEBUG );
2019-11-12 00:15:34 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
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
2019-11-07 11:20:47 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2009-01-21 16:06:34 +01:00
2019-01-27 11:55:16 +01:00
print '<tr class="liste_titre"><th colspan="2">' . $langs -> trans ( " LastContracts " , 5 ) . '</th>' ;
2019-03-03 09:37:43 +01:00
print '<th class="center">' . $langs -> trans ( " DateModification " ) . '</th>' ;
2019-02-19 17:08:35 +01:00
//print '<th class="left">'.$langs->trans("Status").'</th>';
2019-03-03 09:37:43 +01:00
print '<th class="center" width="80" colspan="4">' . $langs -> trans ( " Services " ) . '</th>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2009-01-21 16:06:34 +01:00
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2017-09-11 02:54:06 +02:00
$obj = $db -> fetch_object ( $result );
2022-05-15 22:29:19 +02:00
$datem = $db -> jdate ( $obj -> tms );
2009-01-21 16:06:34 +01:00
2019-11-12 00:15:34 +01:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> cid );
$staticcontrat -> id = $obj -> cid ;
2022-05-15 22:29:19 +02:00
$staticcompany -> id = $obj -> socid ;
$staticcompany -> name = $obj -> name ;
print '<tr class="oddeven">' ;
print '<td class="nowraponall">' ;
2019-01-27 11:55:16 +01:00
print $staticcontrat -> getNomUrl ( 1 , 16 );
2021-02-23 21:24:38 +01:00
if ( $obj -> nb_late ) {
print img_warning ( $langs -> trans ( " Late " ));
}
2009-07-08 12:10:35 +02:00
print '</td>' ;
2022-05-17 23:27:11 +02:00
2022-05-17 23:23:50 +02:00
print '<td class="tdoverflowmax150">' ;
2019-01-27 11:55:16 +01:00
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
2008-04-13 21:53:39 +02:00
print '</td>' ;
2022-05-15 22:29:19 +02:00
print '<td class="center nowraponall" title="' . dol_escape_htmltag ( $langs -> trans ( " DateModification " ) . ': ' . dol_print_date ( $datem , 'dayhour' , 'tzuserrel' )) . '">' ;
print dol_print_date ( $datem , 'dayhour' );
print '</td>' ;
2019-01-19 12:29:41 +01:00
//print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
2020-03-05 03:20:06 +01:00
print '<td class="right nowraponall" width="32">' . ( $obj -> nb_initial > 0 ? '<span class="paddingright">' . $obj -> nb_initial . '</span>' . $staticcontratligne -> LibStatut ( 0 , 3 , - 1 , 'class="paddingleft"' ) : '' ) . '</td>' ;
print '<td class="right nowraponall" width="32">' . ( $obj -> nb_running > 0 ? '<span class="paddingright">' . $obj -> nb_running . '</span>' . $staticcontratligne -> LibStatut ( 4 , 3 , 0 , 'class="marginleft"' ) : '' ) . '</td>' ;
print '<td class="right nowraponall" width="32">' . ( $obj -> nb_expired > 0 ? '<span class="paddingright">' . $obj -> nb_expired . '</span>' . $staticcontratligne -> LibStatut ( 4 , 3 , 1 , 'class="paddingleft"' ) : '' ) . '</td>' ;
print '<td class="right nowraponall" width="32">' . ( $obj -> nb_closed > 0 ? '<span class="paddingright">' . $obj -> nb_closed . '</span>' . $staticcontratligne -> LibStatut ( 5 , 3 , - 1 , 'class="paddingleft"' ) : '' ) . '</td>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $result );
2019-11-05 19:03:28 +01:00
print " </table></div> " ;
2020-05-21 15:05:19 +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, " ;
2019-11-12 00:15:34 +01:00
$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 as name, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
$sql .= " AND cd.fk_contrat = c.rowid " ;
$sql .= " AND c.fk_soc = s.rowid " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
if ( $socid ) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " ORDER BY cd.tms DESC " ;
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
2011-08-08 16:25:44 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2019-11-07 11:20:47 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2011-08-08 16:25:44 +02:00
2019-01-27 11:55:16 +01:00
print '<tr class="liste_titre"><th colspan="4">' . $langs -> trans ( " LastModifiedServices " , $max ) . '</th>' ;
2011-08-08 16:25:44 +02:00
print " </tr> \n " ;
2021-02-23 21:24:38 +01:00
while ( $i < min ( $num , $max )) {
2011-08-08 16:25:44 +02:00
$obj = $db -> fetch_object ( $resql );
2017-09-11 02:54:06 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2020-05-04 17:07:18 +02:00
print '<td class="nowraponall">' ;
2019-11-12 00:15:34 +01:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
2019-01-27 11:55:16 +01:00
print $staticcontrat -> getNomUrl ( 1 , 16 );
2011-08-08 16:25:44 +02:00
//if (1 == 1) print img_warning($langs->trans("Late"));
print '</td>' ;
print '<td>' ;
2021-02-23 21:24:38 +01:00
if ( $obj -> fk_product > 0 ) {
2020-10-31 14:32:18 +01:00
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
2019-11-12 00:15:34 +01:00
$productstatic -> entity = $obj -> pentity ;
2020-10-31 14:32:18 +01:00
print $productstatic -> getNomUrl ( 1 , '' , 20 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
print '<a href="' . DOL_URL_ROOT . '/contrat/card.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
2021-02-23 21:24:38 +01:00
if ( $obj -> label ) {
print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
} else {
print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
2011-08-08 16:25:44 +02:00
}
print '</td>' ;
2022-05-17 23:23:50 +02:00
print '<td class="tdoverflowmax125">' ;
2019-11-12 00:15:34 +01:00
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> name = $obj -> name ;
2019-01-27 11:55:16 +01:00
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
2011-08-08 16:25:44 +02:00
print '</td>' ;
2019-02-19 17:08:35 +01:00
print '<td class="nowrap right"><a href="' . DOL_URL_ROOT . '/contrat/card.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
2019-11-12 00:15:34 +01:00
$dateend = $db -> jdate ( $obj -> date_fin_validite );
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 , ( $dateend && $dateend < $now ) ? 1 : 0 );
2011-08-08 16:25:44 +02:00
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
2022-05-15 22:29:19 +02:00
$db -> free ( $resql );
2011-08-08 16:25:44 +02:00
2019-11-05 19:03:28 +01:00
print " </table></div> " ;
2020-05-21 15:05:19 +02:00
} else {
2011-08-08 16:25:44 +02:00
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, " ;
2019-11-12 00:15:34 +01:00
$sql .= " s.nom as name, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
$sql .= " AND c.statut = 1 " ;
$sql .= " AND cd.statut = 0 " ;
$sql .= " AND cd.fk_contrat = c.rowid " ;
$sql .= " AND c.fk_soc = s.rowid " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
if ( $socid ) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " ORDER BY cd.tms DESC " ;
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
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
2019-11-07 11:20:47 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2003-08-03 21:15:39 +02:00
2017-10-29 11:00:02 +01:00
print '<tr class="liste_titre"><th colspan="4">' . $langs -> trans ( " NotActivatedServices " ) . ' <a href="' . DOL_URL_ROOT . '/contrat/services_list.php?mode=0"><span class="badge">' . $num . '</span></a></th>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2005-04-23 00:39:11 +02:00
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2010-08-09 17:52:44 +02:00
$obj = $db -> fetch_object ( $resql );
2017-09-11 02:54:06 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2005-04-23 00:39:11 +02:00
2020-05-04 17:07:18 +02:00
print '<td class="nowraponall">' ;
2019-11-12 00:15:34 +01:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
2019-01-27 11:55:16 +01:00
print $staticcontrat -> getNomUrl ( 1 , 16 );
2008-04-13 21:53:39 +02:00
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2021-02-23 21:24:38 +01:00
if ( $obj -> fk_product > 0 ) {
2020-10-31 14:32:18 +01:00
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
2019-11-12 00:15:34 +01:00
$productstatic -> entity = $obj -> pentity ;
2020-10-31 14:32:18 +01:00
print $productstatic -> getNomUrl ( 1 , '' , 20 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
print '<a href="' . DOL_URL_ROOT . '/contrat/card.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
2021-02-23 21:24:38 +01:00
if ( $obj -> label ) {
print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
} else {
print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
2011-08-08 16:25:44 +02:00
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
2022-05-17 23:23:50 +02:00
print '<td class="tdoverflowmax125">' ;
2019-11-12 00:15:34 +01:00
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> name = $obj -> name ;
2019-01-27 11:55:16 +01:00
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
2008-04-13 21:53:39 +02:00
print '</td>' ;
2019-07-19 23:19:06 +02:00
print '<td width="16" class="right"><a href="line.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
2019-01-27 11:55:16 +01:00
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 );
2009-07-08 12:10:35 +02:00
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
2022-05-15 22:29:19 +02:00
$db -> free ( $resql );
2004-11-26 15:17:48 +01:00
2019-11-05 19:03:28 +01:00
print " </table></div> " ;
2020-05-21 15:05:19 +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, " ;
2019-11-12 00:15:34 +01:00
$sql .= " s.nom as name, " ;
$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " contrat as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:24:38 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-12 00:15:34 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " ) LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON cd.fk_product = p.rowid " ;
$sql .= " WHERE c.entity IN ( " . getEntity ( 'contract' , 0 ) . " ) " ;
$sql .= " AND c.statut = 1 " ;
$sql .= " AND cd.statut = 4 " ;
$sql .= " AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ' " ;
$sql .= " AND cd.fk_contrat = c.rowid " ;
$sql .= " AND c.fk_soc = s.rowid " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:24:38 +01:00
}
if ( $socid ) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2021-02-23 21:24:38 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " ORDER BY cd.tms DESC " ;
$resql = $db -> query ( $sql );
2021-02-23 21:24:38 +01:00
if ( $resql ) {
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2005-04-23 00:39:11 +02:00
2019-11-07 11:20:47 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2005-04-23 00:39:11 +02:00
2017-10-29 11:00:02 +01:00
print '<tr class="liste_titre"><th colspan="4">' . $langs -> trans ( " ListOfExpiredServices " ) . ' <a href="' . DOL_URL_ROOT . '/contrat/services_list.php?mode=4&filter=expired"><span class="badge">' . $num . '</span></a></th>' ;
2009-07-08 12:10:35 +02:00
print " </tr> \n " ;
2005-04-23 00:39:11 +02:00
2021-02-23 21:24:38 +01:00
while ( $i < $num ) {
2009-07-08 12:10:35 +02:00
$obj = $db -> fetch_object ( $resql );
2017-09-11 02:54:06 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2011-08-08 16:25:44 +02:00
2020-05-04 17:07:18 +02:00
print '<td class="nowraponall">' ;
2019-11-12 00:15:34 +01:00
$staticcontrat -> ref = ( $obj -> ref ? $obj -> ref : $obj -> fk_contrat );
$staticcontrat -> id = $obj -> fk_contrat ;
2019-01-27 11:55:16 +01:00
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">' ;
2021-02-23 21:24:38 +01:00
if ( $obj -> fk_product > 0 ) {
2020-10-31 14:32:18 +01:00
$productstatic -> id = $obj -> fk_product ;
$productstatic -> type = $obj -> ptype ;
$productstatic -> ref = $obj -> pref ;
2019-11-12 00:15:34 +01:00
$productstatic -> entity = $obj -> pentity ;
2020-10-31 14:32:18 +01:00
print $productstatic -> getNomUrl ( 1 , '' , 20 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
print '<a href="' . DOL_URL_ROOT . '/contrat/card.php?id=' . $obj -> fk_contrat . '">' . img_object ( $langs -> trans ( " ShowService " ), " service " );
2021-02-23 21:24:38 +01:00
if ( $obj -> label ) {
print ' ' . dol_trunc ( $obj -> label , 20 ) . '</a>' ;
} else {
print '</a> ' . dol_trunc ( $obj -> note , 20 );
}
2011-08-08 16:25:44 +02:00
}
print '</td>' ;
2022-05-17 23:23:50 +02:00
print '<td class="tdoverflowmax125">' ;
2019-11-12 00:15:34 +01:00
$staticcompany -> id = $obj -> fk_soc ;
$staticcompany -> name = $obj -> name ;
2019-01-27 11:55:16 +01:00
print $staticcompany -> getNomUrl ( 1 , '' , 20 );
2008-04-13 21:53:39 +02:00
print '</td>' ;
2019-07-19 23:19:06 +02:00
print '<td width="16" class="right"><a href="line.php?id=' . $obj -> fk_contrat . '&ligne=' . $obj -> cid . '">' ;
2019-01-27 11:55:16 +01:00
print $staticcontratligne -> LibStatut ( $obj -> statut , 3 , 1 );
2009-07-08 12:10:35 +02:00
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
2022-05-15 22:29:19 +02:00
$db -> free ( $resql );
2003-08-03 21:15:39 +02:00
2019-11-05 19:03:28 +01:00
print " </table></div> " ;
2020-05-21 15:05:19 +02:00
} else {
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
2003-08-03 21:15:39 +02:00
}
2021-10-24 00:37:37 +02:00
print '</div></div>' ;
2005-06-26 04:12:53 +02:00
2019-06-18 14:07:52 +02:00
$parameters = array ( 'user' => $user );
$reshook = $hookmanager -> executeHooks ( 'dashboardContracts' , $parameters , $object ); // Note that $action and $object may have been modified by hook
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 ();