2004-11-26 15:20:43 +01:00
< ? php
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2010-11-16 22:45:33 +01:00
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2013-09-10 16:43:06 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2014-07-12 10:56:13 +02:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
2015-02-23 20:26:34 +01:00
* Copyright ( C ) 2015 Claudio Aschieri < c . aschieri @ 19. coop >
2015-04-18 21:28:55 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2004-11-26 15:20:43 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-11-26 15:20:43 +01: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 />.
2004-11-26 15:20:43 +01:00
*/
2005-04-23 00:39:11 +02:00
/**
2014-09-18 20:33:37 +02:00
* \file htdocs / contrat / list . php
2008-10-27 20:19:51 +01:00
* \ingroup contrat
* \brief Page liste des contrats
*/
2004-11-26 15:20:43 +01: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 " );
2015-02-23 20:26:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2004-11-26 15:20:43 +01:00
2005-04-23 00:39:11 +02:00
$langs -> load ( " contracts " );
2004-11-26 15:20:43 +01:00
$langs -> load ( " products " );
$langs -> load ( " companies " );
2014-07-11 16:12:31 +02:00
$langs -> load ( " compta " );
2004-11-26 15:20:43 +01:00
2012-07-25 11:46:33 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2005-04-23 00:39:11 +02:00
if ( $page == - 1 ) { $page = 0 ; }
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
2004-11-26 15:20:43 +01:00
2014-11-03 06:05:51 +01:00
$search_name = GETPOST ( 'search_name' );
2012-07-25 11:46:33 +02:00
$search_contract = GETPOST ( 'search_contract' );
2014-09-24 10:21:26 +02:00
$search_ref_supplier = GETPOST ( 'search_ref_supplier' , 'alpha' );
2012-07-25 11:46:33 +02:00
$sall = GETPOST ( 'sall' );
2014-11-03 06:05:51 +01:00
$search_status = GETPOST ( 'search_status' );
2012-07-25 11:46:33 +02:00
$socid = GETPOST ( 'socid' );
2004-11-26 15:20:43 +01:00
2015-02-23 20:26:34 +01:00
$search_sale = GETPOST ( 'search_sale' , 'int' );
2005-04-23 00:39:11 +02:00
if ( ! $sortfield ) $sortfield = " c.rowid " ;
if ( ! $sortorder ) $sortorder = " DESC " ;
2008-02-25 17:30:43 +01:00
// Security check
2012-07-25 11:46:33 +02:00
$id = GETPOST ( 'id' , 'int' );
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2012-07-25 11:46:33 +02:00
$result = restrictedArea ( $user , 'contrat' , $id );
2004-11-26 15:20:43 +01:00
2006-03-18 18:41:36 +01:00
$staticcontrat = new Contrat ( $db );
$staticcontratligne = new ContratLigne ( $db );
2014-11-23 09:34:56 +01:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter " )) // Both test are required to be compatible with all browsers
2014-11-03 06:05:51 +01:00
{
$search_name = " " ;
$search_contract = " " ;
$search_ref_supplier = " " ;
2015-02-23 20:26:34 +01:00
$search_sale = " " ;
2014-11-03 06:05:51 +01:00
$sall = " " ;
$search_status = " " ;
}
if ( $search_status == '' ) $search_status = 1 ;
2004-11-26 15:20:43 +01:00
2006-03-18 18:41:36 +01:00
/*
2008-10-27 20:19:51 +01:00
* View
2006-03-18 18:41:36 +01:00
*/
2012-03-23 18:19:50 +01:00
$now = dol_now ();
2015-02-23 20:26:34 +01:00
$formother = new FormOther ( $db );
$socstatic = new Societe ( $db );
2009-02-09 20:31:06 +01:00
2006-03-18 18:41:36 +01:00
llxHeader ();
2004-11-26 15:20:43 +01:00
2005-07-03 15:07:59 +02:00
$sql = 'SELECT' ;
2014-11-22 15:12:36 +01:00
$sql .= " c.rowid as cid, c.ref, c.datec, c.date_contrat, c.statut, c.ref_supplier, " ;
$sql .= " s.nom as name, s.rowid as socid, " ;
2012-07-25 11:46:33 +02:00
$sql .= ' SUM(' . $db -> ifsql ( " cd.statut=0 " , 1 , 0 ) . ') as nb_initial,' ;
2014-03-15 23:12:00 +01: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,' ;
2014-11-22 15:12:36 +01:00
$sql .= ' SUM(' . $db -> ifsql ( " cd.statut=5 " , 1 , 0 ) . ') as nb_closed' ;
2009-04-27 22:37:50 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2015-02-23 20:26:34 +01:00
if ( $search_sale > 0 || ( ! $user -> rights -> societe -> client -> voir && ! $socid )) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2009-04-27 22:37:50 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " contrat as c " ;
2005-06-11 13:33:21 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " contratdet as cd ON c.rowid = cd.fk_contrat " ;
2007-06-12 00:51:47 +02:00
$sql .= " WHERE c.fk_soc = s.rowid " ;
2012-02-01 11:32:55 +01:00
$sql .= " AND c.entity = " . $conf -> entity ;
2009-04-27 22:37:50 +02:00
if ( $socid ) $sql .= " AND s.rowid = " . $socid ;
2015-02-23 20:26:34 +01:00
2014-11-03 06:05:51 +01:00
if ( $search_name ) {
$sql .= natural_search ( 's.nom' , $search_name );
2013-09-10 16:43:06 +02:00
}
if ( $search_contract ) {
$sql .= natural_search ( array ( 'c.rowid' , 'c.ref' ), $search_contract );
}
2014-09-24 10:21:26 +02:00
if ( ! empty ( $search_ref_supplier )) {
$sql .= natural_search ( array ( 'c.ref_supplier' ), $search_ref_supplier );
2014-07-11 11:26:54 +02:00
}
2015-02-23 20:26:34 +01:00
if ( $search_sale > 0 )
{
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $search_sale ;
}
2013-09-10 16:43:06 +02:00
if ( $sall ) {
$sql .= natural_search ( array ( 's.nom' , 'cd.label' , 'cd.description' ), $sall );
}
2014-11-22 15:12:36 +01:00
$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.date_contrat, c.statut, c.ref_supplier, s.nom, s.rowid " ;
2014-10-04 17:20:17 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2012-03-18 19:23:01 +01:00
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2004-11-26 15:20:43 +01:00
2005-04-24 04:45:23 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2004-11-26 15:20:43 +01:00
{
2005-07-03 15:07:59 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2015-04-18 21:28:55 +02:00
print_barre_liste ( $langs -> trans ( " ListOfContracts " ), $page , $_SERVER [ " PHP_SELF " ], '&search_contract=' . $search_contract . '&search_name=' . $search_name , $sortfield , $sortorder , '' , $num , $totalnboflines , 'title_commercial.png' );
2014-11-28 00:57:40 +01:00
print '<form method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '">' ;
2005-08-15 18:22:20 +02:00
print '<table class="liste" width="100%">' ;
2005-07-03 15:07:59 +02:00
2015-02-23 20:26:34 +01:00
// If the user can view prospects other than his'
$moreforfilter = '' ;
if ( $user -> rights -> societe -> client -> voir || $socid )
{
$langs -> load ( " commercial " );
$moreforfilter .= $langs -> trans ( 'ThirdPartiesOfSaleRepresentative' ) . ': ' ;
$moreforfilter .= $formother -> select_salesrepresentatives ( $search_sale , 'search_sale' , $user );
$moreforfilter .= ' ' ;
}
if ( $moreforfilter )
{
print '<tr class="liste_titre">' ;
print '<td class="liste_titre" colspan="9">' ;
print $moreforfilter ;
print '</td></tr>' ;
}
2005-07-03 15:07:59 +02:00
print '<tr class="liste_titre">' ;
2005-08-11 20:54:59 +02:00
$param = '&search_contract=' . $search_contract ;
2014-11-03 06:05:51 +01:00
$param .= '&search_name=' . $search_name ;
2014-09-24 10:21:26 +02:00
$param .= '&search_ref_supplier=' . $search_ref_supplier ;
2015-02-23 20:26:34 +01:00
$param .= '&search_sale=' . $search_sale ;
2011-05-03 20:45:37 +02:00
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " c.rowid " , " " , " $param " , '' , $sortfield , $sortorder );
2014-09-24 10:21:26 +02:00
print_liste_field_titre ( $langs -> trans ( " RefCustomer " ), $_SERVER [ " PHP_SELF " ], " c.ref_supplier " , " " , " $param " , '' , $sortfield , $sortorder );
2011-05-03 20:45:37 +02:00
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , " $param " , '' , $sortfield , $sortorder );
2015-02-23 20:26:34 +01:00
print_liste_field_titre ( $langs -> trans ( " SalesRepresentative " ), $_SERVER [ " PHP_SELF " ], " " , " " , " $param " , '' , $sortfield , $sortorder );
2008-04-07 19:16:45 +02:00
//print_liste_field_titre($langs->trans("DateCreation"), $_SERVER["PHP_SELF"], "c.datec","","$param",'align="center"',$sortfield,$sortorder);
print_liste_field_titre ( $langs -> trans ( " DateContract " ), $_SERVER [ " PHP_SELF " ], " c.date_contrat " , " " , " $param " , 'align="center"' , $sortfield , $sortorder );
//print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "c.statut","","$param",'align="center"',$sortfield,$sortorder);
2006-03-18 18:41:36 +01:00
print '<td class="liste_titre" width="16">' . $staticcontratligne -> LibStatut ( 0 , 3 ) . '</td>' ;
2009-07-08 12:10:35 +02:00
print '<td class="liste_titre" width="16">' . $staticcontratligne -> LibStatut ( 4 , 3 , 0 ) . '</td>' ;
print '<td class="liste_titre" width="16">' . $staticcontratligne -> LibStatut ( 4 , 3 , 1 ) . '</td>' ;
2006-03-18 18:41:36 +01:00
print '<td class="liste_titre" width="16">' . $staticcontratligne -> LibStatut ( 5 , 3 ) . '</td>' ;
2005-07-03 15:07:59 +02:00
print " </tr> \n " ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2005-08-11 20:54:59 +02:00
print '<tr class="liste_titre">' ;
2005-08-15 18:22:20 +02:00
print '<td class="liste_titre">' ;
2008-02-25 17:48:16 +01:00
print '<input type="text" class="flat" size="3" name="search_contract" value="' . $search_contract . '">' ;
2005-08-11 20:54:59 +02:00
print '</td>' ;
2008-08-29 23:16:34 +02:00
print '<td class="liste_titre">' ;
2014-09-24 10:21:26 +02:00
print '<input type="text" class="flat" size="7" name="search_ref_supplier value="' . $search_ref_supplier . '">' ;
2014-07-11 11:26:54 +02:00
print '</td>' ;
print '<td class="liste_titre">' ;
2014-11-03 06:05:51 +01:00
print '<input type="text" class="flat" size="24" name="search_name" value="' . $search_name . '">' ;
2005-08-11 20:54:59 +02:00
print '</td>' ;
print '<td class="liste_titre"> </td>' ;
2008-04-07 19:16:45 +02:00
//print '<td class="liste_titre"> </td>';
2015-02-23 20:26:34 +01:00
print '<td colspan="5" class="liste_titre" align="right"><input type="image" class="liste_titre" name="button_search" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2014-11-03 06:05:51 +01:00
print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto ( $langs -> trans ( " Search " ), 'searchclear.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '">' ;
print " </td></tr> \n " ;
2005-07-03 15:07:59 +02:00
2012-10-22 00:28:32 +02:00
$var = true ;
2005-07-03 15:07:59 +02:00
while ( $i < min ( $num , $limit ))
2004-11-26 15:20:43 +01:00
{
2005-07-03 15:07:59 +02:00
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
2011-05-03 20:45:37 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2014-09-18 21:18:25 +02:00
print '<td class="nowrap"><a href="card.php?id=' . $obj -> cid . '">' ;
2006-03-18 18:41:36 +01:00
print img_object ( $langs -> trans ( " ShowContract " ), " contract " ) . ' ' . ( isset ( $obj -> ref ) ? $obj -> ref : $obj -> cid ) . '</a>' ;
2005-07-03 15:07:59 +02:00
if ( $obj -> nb_late ) print img_warning ( $langs -> trans ( " Late " ));
print '</td>' ;
2014-09-24 10:21:26 +02:00
print '<td>' . $obj -> ref_supplier . '</td>' ;
2014-10-04 17:20:17 +02:00
print '<td><a href="../comm/card.php?socid=' . $obj -> socid . '">' . img_object ( $langs -> trans ( " ShowCompany " ), " company " ) . ' ' . $obj -> name . '</a></td>' ;
2009-02-20 23:53:15 +01:00
//print '<td align="center">'.dol_print_date($obj->datec).'</td>';
2015-02-23 20:26:34 +01:00
// Sales Rapresentatives
print '<td>' ;
if ( $obj -> socid )
{
$socstatic -> fetch ( $obj -> socid );
$listsalesrepresentatives = $socstatic -> getSalesRepresentatives ( $user );
$nbofsalesrepresentative = count ( $listsalesrepresentatives );
if ( $nbofsalesrepresentative > 3 ) // We print only number
{
print '<a href="' . DOL_URL_ROOT . '/societe/commerciaux.php?socid=' . $socstatic -> id . '">' ;
print $nbofsalesrepresentative ;
print '</a>' ;
}
else if ( $nbofsalesrepresentative > 0 )
{
$userstatic = new User ( $db );
$j = 0 ;
foreach ( $listsalesrepresentatives as $val )
{
$userstatic -> id = $val [ 'id' ];
$userstatic -> lastname = $val [ 'lastname' ];
$userstatic -> firstname = $val [ 'firstname' ];
print $userstatic -> getNomUrl ( 1 );
$j ++ ;
if ( $j < $nbofsalesrepresentative ) print '<br/>' ;
}
}
else print $langs -> trans ( " NoSalesRepresentativeAffected " );
}
else
{
print ' ' ;
}
print '</td>' ;
2012-10-22 00:28:32 +02:00
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> date_contrat )) . '</td>' ;
2008-04-07 19:16:45 +02:00
//print '<td align="center">'.$staticcontrat->LibStatut($obj->statut,3).'</td>';
2005-07-03 15:07:59 +02:00
print '<td align="center">' . ( $obj -> nb_initial > 0 ? $obj -> nb_initial : '' ) . '</td>' ;
2009-02-09 20:31:06 +01:00
print '<td align="center">' . ( $obj -> nb_running > 0 ? $obj -> nb_running : '' ) . '</td>' ;
print '<td align="center">' . ( $obj -> nb_expired > 0 ? $obj -> nb_expired : '' ) . '</td>' ;
print '<td align="center">' . ( $obj -> nb_closed > 0 ? $obj -> nb_closed : '' ) . '</td>' ;
2005-07-03 15:07:59 +02:00
print " </tr> \n " ;
$i ++ ;
2004-11-26 15:20:43 +01:00
}
2005-07-03 15:07:59 +02:00
$db -> free ( $resql );
2004-11-26 15:20:43 +01:00
2014-11-28 00:57:40 +01:00
print '</table>' ;
print '</form>' ;
2004-11-26 15:20:43 +01:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2004-11-26 15:20:43 +01:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-07-25 11:46:33 +02:00
$db -> close ();