2005-07-03 23:58:20 +02:00
< ? php
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-05-03 20:45: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 >
2005-07-03 23:58:20 +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
2005-07-03 23:58:20 +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 />.
2005-07-03 23:58:20 +02:00
*/
/**
2009-07-08 12:10:35 +02:00
* \file htdocs / contrat / services . php
* \ingroup contrat
2009-07-22 15:35:09 +02:00
* \brief Page to list services in contracts
2009-07-08 12:10:35 +02:00
*/
2005-07-03 23:58:20 +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 " );
2010-04-28 23:29:12 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /product/class/product.class.php " );
2010-04-29 16:54:12 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /societe/class/societe.class.php " );
2005-07-03 23:58:20 +02:00
$langs -> load ( " products " );
2011-05-21 16:57:17 +02:00
$langs -> load ( " contracts " );
2005-07-03 23:58:20 +02:00
$langs -> load ( " companies " );
2011-11-23 18:10:10 +01:00
$mode = GETPOST ( " mode " );
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2012-10-13 14:47:46 +02:00
$page = GETPOST ( " page " , 'int' );
2005-08-13 01:31:45 +02:00
if ( $page == - 1 ) { $page = 0 ; }
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
2005-07-03 23:58:20 +02:00
2005-08-13 01:31:45 +02:00
if ( ! $sortfield ) $sortfield = " c.rowid " ;
if ( ! $sortorder ) $sortorder = " ASC " ;
2011-11-23 18:10:10 +01:00
$filter = GETPOST ( " filter " );
$search_nom = GETPOST ( " search_nom " );
$search_contract = GETPOST ( " search_contract " );
$search_service = GETPOST ( " search_service " );
2012-07-25 11:46:33 +02:00
$statut = GETPOST ( 'statut' ) ? GETPOST ( 'statut' ) : 1 ;
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2005-07-03 23:58:20 +02:00
2012-07-25 11:46:33 +02:00
$op1month = GETPOST ( 'op1month' );
$op1day = GETPOST ( 'op1day' );
$op1year = GETPOST ( 'op1year' );
$filter_op1 = GETPOST ( 'filter_op1' );
$op2month = GETPOST ( 'op2month' );
$op2day = GETPOST ( 'op2day' );
$op2year = GETPOST ( 'op2year' );
$filter_op2 = GETPOST ( 'filter_op2' );
2008-02-25 17:30:43 +01:00
// Security check
2012-02-27 22:26:22 +01:00
$contratid = GETPOST ( 'id' , 'int' );
2012-07-25 11:46:33 +02:00
if ( ! empty ( $user -> societe_id )) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'contrat' , $contratid );
2008-02-25 17:30:43 +01:00
2005-07-03 23:58:20 +02:00
2006-03-18 18:41:36 +01:00
$staticcontrat = new Contrat ( $db );
$staticcontratligne = new ContratLigne ( $db );
2008-12-15 19:48:42 +01:00
$companystatic = new Societe ( $db );
2005-07-03 23:58:20 +02:00
2006-03-18 18:41:36 +01:00
/*
2008-09-06 00:15:46 +02:00
* View
2006-03-18 18:41:36 +01:00
*/
2008-09-06 00:15:46 +02:00
2012-02-06 05:31:19 +01:00
$now = dol_now ();
2008-10-28 21:05:23 +01:00
2008-10-20 23:42:11 +02:00
$form = new Form ( $db );
2005-08-13 01:31:45 +02:00
llxHeader ();
2005-07-03 23:58:20 +02:00
2008-10-28 21:05:23 +01:00
$sql = " SELECT c.rowid as cid, c.ref, c.statut as cstatut, " ;
$sql .= " s.rowid as socid, s.nom, " ;
2009-10-10 18:26:06 +02:00
$sql .= " cd.rowid, cd.description, cd.statut, " ;
2011-05-03 20:45:37 +02:00
$sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " sc.fk_soc, sc.fk_user, " ;
2010-05-08 21:21:57 +02:00
$sql .= " cd.date_ouverture_prevue, " ;
$sql .= " cd.date_ouverture, " ;
$sql .= " cd.date_fin_validite, " ;
$sql .= " cd.date_cloture " ;
2006-06-12 01:21:59 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " contrat as c, " ;
$sql .= " " . MAIN_DB_PREFIX . " societe as s, " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " " . MAIN_DB_PREFIX . " societe_commerciaux as sc, " ;
2006-06-12 01:21:59 +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-02-11 10:18:09 +01:00
$sql .= " WHERE c.entity = " . $conf -> entity ;
$sql .= " AND c.rowid = cd.fk_contrat " ;
2007-06-12 00:51:47 +02:00
$sql .= " AND c.fk_soc = s.rowid " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2005-07-03 23:58:20 +02:00
if ( $mode == " 0 " ) $sql .= " AND cd.statut = 0 " ;
if ( $mode == " 4 " ) $sql .= " AND cd.statut = 4 " ;
if ( $mode == " 5 " ) $sql .= " AND cd.statut = 5 " ;
2011-08-08 16:25:44 +02:00
if ( $filter == " expired " ) $sql .= " AND cd.date_fin_validite < ' " . $db -> idate ( $now ) . " ' " ;
2012-07-25 11:46:33 +02:00
if ( $search_nom ) $sql .= " AND s.nom LIKE '% " . $db -> escape ( $search_nom ) . " %' " ;
2011-02-24 19:22:24 +01:00
if ( $search_contract ) $sql .= " AND c.rowid = ' " . $db -> escape ( $search_contract ) . " ' " ;
2012-07-25 11:46:33 +02:00
if ( $search_service ) $sql .= " AND (p.ref LIKE '% " . $db -> escape ( $search_service ) . " %' OR p.description LIKE '% " . $db -> escape ( $search_service ) . " %' OR cd.description LIKE '% " . $db -> escape ( $search_service ) . " %') " ;
2007-06-12 00:51:47 +02:00
if ( $socid > 0 ) $sql .= " AND s.rowid = " . $socid ;
2012-07-25 11:46:33 +02:00
$filter_date1 = dol_mktime ( 0 , 0 , 0 , $op1month , $op1day , $op1year );
$filter_date2 = dol_mktime ( 0 , 0 , 0 , $op2month , $op2day , $op2year );
if ( ! empty ( $filter_op1 ) && $filter_op1 != - 1 && $filter_date1 != '' ) $sql .= " AND date_ouverture_prevue " . $filter_op1 . " " . $db -> idate ( $filter_date1 );
if ( ! empty ( $filter_op2 ) && $filter_op2 != - 1 && $filter_date2 != '' ) $sql .= " AND date_fin_validite " . $filter_op2 . " " . $db -> idate ( $filter_date2 );
2008-12-15 19:48:42 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2012-03-18 19:23:01 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2005-07-03 23:58:20 +02:00
2008-02-25 17:48:16 +01:00
//print $sql;
2009-02-20 23:53:15 +01:00
dol_syslog ( " contrat/services.php sql= " . $sql );
2005-07-03 23:58:20 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2009-07-08 12:10:35 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
$param = '' ;
if ( $search_contract ) $param .= '&search_contract=' . urlencode ( $search_contract );
if ( $search_nom ) $param .= '&search_nom=' . urlencode ( $search_nom );
if ( $search_service ) $param .= '&search_service=' . urlencode ( $search_service );
if ( $mode ) $param .= '&mode=' . $mode ;
if ( $filter ) $param .= '&filter=' . $filter ;
2012-07-25 11:46:33 +02:00
if ( ! empty ( $filter_op1 ) && $filter_op1 != - 1 ) $param .= '&filter_op1=' . urlencode ( $filter_op1 );
if ( ! empty ( $filter_op2 ) && $filter_op2 != - 1 ) $param .= '&filter_op2=' . urlencode ( $filter_op2 );
if ( $filter_date1 != '' ) $param .= '&op1day=' . $op1day . '&op1month=' . $op1month . '&op1year=' . $op1year ;
if ( $filter_date2 != '' ) $param .= '&op2day=' . $op2day . '&op2month=' . $op2month . '&op2year=' . $op2year ;
2009-07-08 12:10:35 +02:00
2009-07-22 15:35:09 +02:00
$title = $langs -> trans ( " ListOfServices " );
if ( $mode == " 0 " ) $title = $langs -> trans ( " ListOfInactiveServices " ); // Must use == "0"
if ( $mode == " 4 " && $filter != " expired " ) $title = $langs -> trans ( " ListOfRunningServices " );
if ( $mode == " 4 " && $filter == " expired " ) $title = $langs -> trans ( " ListOfExpiredServices " );
if ( $mode == " 5 " ) $title = $langs -> trans ( " ListOfClosedServices " );
print_barre_liste ( $title , $page , " services.php " , $param , $sortfield , $sortorder , '' , $num );
2009-07-08 12:10:35 +02:00
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $langs -> trans ( " Contract " ), " services.php " , " c.rowid " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Service " ), " services.php " , " p.description " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Company " ), " services.php " , " s.nom " , $param , " " , " " , $sortfield , $sortorder );
// Date debut
if ( $mode == " 0 " ) print_liste_field_titre ( $langs -> trans ( " DateStartPlannedShort " ), " services.php " , " cd.date_ouverture_prevue " , $param , '' , ' align="center"' , $sortfield , $sortorder );
if ( $mode == " " || $mode > 0 ) print_liste_field_titre ( $langs -> trans ( " DateStartRealShort " ), " services.php " , " cd.date_ouverture " , $param , '' , ' align="center"' , $sortfield , $sortorder );
// Date fin
if ( $mode == " " || $mode < 5 ) print_liste_field_titre ( $langs -> trans ( " DateEndPlannedShort " ), " services.php " , " cd.date_fin_validite " , $param , '' , ' align="center"' , $sortfield , $sortorder );
else print_liste_field_titre ( $langs -> trans ( " DateEndRealShort " ), " services.php " , " cd.date_cloture " , $param , '' , ' align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Status " ), " services.php " , " cd.statut,c.statut " , $param , " " , " align= \" right \" " , $sortfield , $sortorder );
print " </tr> \n " ;
print '<form method="POST" action="services.php">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-08-23 22:47:29 +02:00
2009-07-08 12:10:35 +02:00
print '<tr class="liste_titre">' ;
print '<td class="liste_titre">' ;
print '<input type="hidden" name="filter" value="' . $filter . '">' ;
print '<input type="hidden" name="mode" value="' . $mode . '">' ;
2011-11-23 18:10:10 +01:00
print '<input type="text" class="flat" size="3" name="search_contract" value="' . dol_escape_htmltag ( $search_contract ) . '">' ;
2009-07-08 12:10:35 +02:00
print '</td>' ;
2011-05-18 15:55:50 +02:00
// Service label
2009-07-08 12:10:35 +02:00
print '<td class="liste_titre">' ;
2011-11-23 18:10:10 +01:00
print '<input type="text" class="flat" size="18" name="search_service" value="' . dol_escape_htmltag ( $search_service ) . '">' ;
2009-07-08 12:10:35 +02:00
print '</td>' ;
2011-05-18 15:55:50 +02:00
// Third party
2009-07-08 12:10:35 +02:00
print '<td class="liste_titre">' ;
2011-11-23 18:10:10 +01:00
print '<input type="text" class="flat" size="24" name="search_nom" value="' . dol_escape_htmltag ( $search_nom ) . '">' ;
2009-07-08 12:10:35 +02:00
print '</td>' ;
print '<td class="liste_titre" align="center">' ;
$arrayofoperators = array ( '<' => '<' , '>' => '>' );
2012-07-25 11:46:33 +02:00
print $form -> selectarray ( 'filter_op1' , $arrayofoperators , $filter_op1 , 1 );
2009-07-08 12:10:35 +02:00
print ' ' ;
2012-07-25 11:46:33 +02:00
$filter_date1 = dol_mktime ( 0 , 0 , 0 , $op1month , $op1day , $op1year );
2009-07-08 12:10:35 +02:00
print $form -> select_date ( $filter_date1 , 'op1' , 0 , 0 , 1 );
print '</td>' ;
print '<td class="liste_titre" align="center">' ;
$arrayofoperators = array ( '<' => '<' , '>' => '>' );
2012-07-25 11:46:33 +02:00
print $form -> selectarray ( 'filter_op2' , $arrayofoperators , $filter_op2 , 1 );
2009-07-08 12:10:35 +02:00
print ' ' ;
2012-07-25 11:46:33 +02:00
$filter_date2 = dol_mktime ( 0 , 0 , 0 , $op2month , $op2day , $op2year );
2009-07-08 12:10:35 +02:00
print $form -> select_date ( $filter_date2 , 'op2' , 0 , 0 , 1 );
print '</td>' ;
2014-01-13 10:10:17 +01:00
print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2009-07-08 12:10:35 +02:00
print " </td> " ;
print " </tr> \n " ;
print '</form>' ;
2009-10-10 18:26:06 +02:00
$contractstatic = new Contrat ( $db );
$productstatic = new Product ( $db );
2009-07-08 12:10:35 +02:00
$var = True ;
while ( $i < min ( $num , $limit ))
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
2011-05-03 20:45:37 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2009-07-08 12:10:35 +02:00
print '<td>' ;
$contractstatic -> id = $obj -> cid ;
$contractstatic -> ref = $obj -> ref ? $obj -> ref : $obj -> cid ;
2009-08-23 22:47:29 +02:00
print $contractstatic -> getNomUrl ( 1 , 16 );
2009-07-08 12:10:35 +02:00
print '</td>' ;
// Service
print '<td>' ;
2011-05-03 20:45:37 +02:00
if ( $obj -> pid )
2011-03-13 01:08:26 +01:00
{
$productstatic -> id = $obj -> pid ;
$productstatic -> type = $obj -> ptype ;
2011-05-03 20:45:37 +02:00
$productstatic -> ref = $obj -> pref ;
2011-03-13 01:08:26 +01:00
print $productstatic -> getNomUrl ( 1 , '' , 20 );
2011-05-03 20:45:37 +02:00
print $obj -> label ? ' - ' . dol_trunc ( $obj -> label , 16 ) : '' ;
2012-12-31 13:40:13 +01:00
if ( ! empty ( $obj -> description ) && ! empty ( $conf -> global -> PRODUCT_DESC_IN_LIST )) print '<br>' . dol_nl2br ( $obj -> description );
2011-03-13 01:08:26 +01:00
}
else
{
if ( $obj -> type == 0 ) print img_object ( $obj -> description , 'product' ) . dol_trunc ( $obj -> description , 20 );
if ( $obj -> type == 1 ) print img_object ( $obj -> description , 'service' ) . dol_trunc ( $obj -> description , 20 );
}
2009-07-08 12:10:35 +02:00
print '</td>' ;
// Third party
print '<td>' ;
$companystatic -> id = $obj -> socid ;
$companystatic -> nom = $obj -> nom ;
$companystatic -> client = 1 ;
2009-08-23 22:47:29 +02:00
print $companystatic -> getNomUrl ( 1 , 'customer' , 28 );
2008-12-15 19:48:42 +01:00
print '</td>' ;
2009-02-09 20:31:06 +01:00
2009-07-08 12:10:35 +02:00
// Start date
if ( $mode == " 0 " ) {
print '<td align="center">' ;
2010-05-08 21:21:57 +02:00
print ( $obj -> date_ouverture_prevue ? dol_print_date ( $db -> jdate ( $obj -> date_ouverture_prevue )) : ' ' );
if ( $db -> jdate ( $obj -> date_ouverture_prevue ) && ( $db -> jdate ( $obj -> date_ouverture_prevue ) < ( $now - $conf -> contrat -> services -> inactifs -> warning_delay )))
2009-07-08 12:10:35 +02:00
print img_picto ( $langs -> trans ( " Late " ), " warning " );
else print ' ' ;
print '</td>' ;
}
2010-05-08 21:21:57 +02:00
if ( $mode == " " || $mode > 0 ) print '<td align="center">' . ( $obj -> date_ouverture ? dol_print_date ( $db -> jdate ( $obj -> date_ouverture )) : ' ' ) . '</td>' ;
2009-07-08 12:10:35 +02:00
// Date fin
2010-05-08 21:21:57 +02:00
if ( $mode == " " || $mode < 5 ) print '<td align="center">' . ( $obj -> date_fin_validite ? dol_print_date ( $db -> jdate ( $obj -> date_fin_validite )) : ' ' );
else print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> date_cloture ));
2009-07-08 12:10:35 +02:00
// Icone warning
2010-05-08 21:21:57 +02:00
if ( $obj -> date_fin_validite && $db -> jdate ( $obj -> date_fin_validite ) < ( $now - $conf -> contrat -> services -> expires -> warning_delay ) && $obj -> statut < 5 ) print img_warning ( $langs -> trans ( " Late " ));
2009-07-08 12:10:35 +02:00
else print ' ' ;
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2009-07-22 15:35:09 +02:00
if ( $obj -> cstatut == 0 ) // If contract is draft, we say line is also draft
2009-07-08 12:10:35 +02:00
{
2010-05-08 21:21:57 +02:00
print $contractstatic -> LibStatut ( 0 , 5 ,( $obj -> date_fin_validite && $db -> jdate ( $obj -> date_fin_validite ) < $now ));
2009-07-08 12:10:35 +02:00
}
else
{
2010-05-08 21:21:57 +02:00
print $staticcontratligne -> LibStatut ( $obj -> statut , 5 ,( $obj -> date_fin_validite && $db -> jdate ( $obj -> date_fin_validite ) < $now ) ? 1 : 0 );
2009-07-08 12:10:35 +02:00
}
print '</td>' ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $resql );
print " </table> " ;
2005-07-03 23:58:20 +02:00
}
else
{
2009-07-08 12:10:35 +02:00
dol_print_error ( $db );
2005-07-03 23:58:20 +02:00
}
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();
2005-07-03 23:58:20 +02:00
?>