2004-10-19 22:19:58 +02:00
< ? php
2006-12-23 15:57:19 +01:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-02-14 17:49:04 +01: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 >
2013-09-10 16:43:06 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2013-11-12 15:22:11 +01:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2002-05-10 14:28:10 +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
2002-05-10 14:28:10 +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-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2002-05-10 14:28:10 +02:00
*/
2004-12-25 19:44:15 +01:00
2005-04-29 00:25:48 +02:00
/**
2011-08-21 15:07:10 +02:00
* \file htdocs / comm / list . php
2011-08-08 18:14:48 +02:00
* \ingroup commercial societe
2010-01-05 21:03:37 +01:00
* \brief List of customers
2008-11-11 22:04:43 +01:00
*/
2004-12-25 19:44:15 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2004-02-21 02:46:26 +01:00
2011-02-14 18:40:15 +01:00
$langs -> load ( " companies " );
$langs -> load ( " customers " );
$langs -> load ( " suppliers " );
$langs -> load ( " commercial " );
2008-02-24 14:18:40 +01:00
// Security check
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2011-02-14 18:27:08 +01:00
$result = restrictedArea ( $user , 'societe' , $socid , '' );
2003-03-23 16:53:03 +01:00
2012-07-28 12:35:11 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2003-03-23 16:53:03 +01:00
if ( $page == - 1 ) { $page = 0 ; }
2008-03-31 05:57:05 +02:00
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " s.nom " ;
2002-05-10 14:28:10 +02:00
2011-05-02 01:14:54 +02:00
$search_nom = GETPOST ( " search_nom " );
2012-10-22 11:05:55 +02:00
$search_zipcode = GETPOST ( " search_zipcode " );
2013-02-22 16:19:16 +01:00
$search_town = GETPOST ( " search_town " );
2011-05-02 01:14:54 +02:00
$search_code = GETPOST ( " search_code " );
$search_compta = GETPOST ( " search_compta " );
2013-11-12 15:22:11 +01:00
$search_status = GETPOST ( " search_status " , 'int' );
if ( $search_status == '' ) $search_status = 1 ; // always display activ customer first
2005-08-11 20:54:59 +02:00
2010-03-16 20:50:07 +01:00
// Load sale and categ filters
2012-07-28 00:53:51 +02:00
$search_sale = GETPOST ( " search_sale " );
2012-07-28 22:07:27 +02:00
$search_categ = GETPOST ( " search_categ " , 'int' );
$catid = GETPOST ( " catid " , 'int' );
2013-12-14 15:21:15 +01:00
// If the internal user must only see his customers, force searching by him
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $search_sale = $user -> id ;
2010-03-16 20:50:07 +01:00
2012-10-20 10:04:49 +02:00
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'customerlist' ));
2008-03-06 18:56:12 +01:00
/*
2011-05-13 20:45:18 +02:00
* Actions
2008-03-06 18:56:12 +01:00
*/
2008-11-11 22:04:43 +01:00
2012-10-20 10:04:49 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters ); // Note that $action and $object may have been modified by some hooks
2011-02-14 18:27:08 +01:00
// Do we click on purge search criteria ?
if ( GETPOST ( " button_removefilter_x " ))
{
$search_categ = '' ;
2012-07-28 00:53:51 +02:00
$catid = '' ;
2011-02-14 18:27:08 +01:00
$search_sale = '' ;
$socname = " " ;
$search_nom = " " ;
2012-10-22 11:05:55 +02:00
$search_zipcode = " " ;
2013-02-22 16:19:16 +01:00
$search_town = " " ;
2011-02-14 18:27:08 +01:00
$search_idprof1 = '' ;
$search_idprof2 = '' ;
$search_idprof3 = '' ;
$search_idprof4 = '' ;
2013-11-12 15:22:11 +01:00
$seach_status = 1 ;
2011-02-14 18:27:08 +01:00
}
2008-03-06 18:56:12 +01:00
2011-05-13 20:45:18 +02:00
/*
* view
*/
2012-05-05 17:28:52 +02:00
$formother = new FormOther ( $db );
2013-11-12 15:22:11 +01:00
$form = new Form ( $db );
2011-05-13 20:45:18 +02:00
$thirdpartystatic = new Societe ( $db );
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas' ;
llxHeader ( '' , $langs -> trans ( " ThirdParty " ), $help_url );
2013-02-24 17:08:52 +01:00
$sql = " SELECT s.rowid, s.nom as name, s.client, s.zip, s.town, st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta, s.status as status, " ;
2011-02-14 17:49:04 +01:00
$sql .= " s.datec, s.datea, s.canvas " ;
2013-12-14 15:21:15 +01:00
if (( ! $user -> rights -> societe -> client -> voir && ! $socid ) || $search_sale ) $sql .= " , sc.fk_soc, sc.fk_user " ; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
2012-07-28 00:53:51 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! empty ( $search_categ ) || ! empty ( $catid )) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . " categorie_societe as cs ON s.rowid = cs.fk_societe " ; // We need this table joined to the select in order to filter by categ
2013-12-14 15:21:15 +01:00
if (( ! $user -> rights -> societe -> client -> voir && ! $socid ) || $search_sale ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ; // We need this table joined to the select in order to filter by sale
2012-07-28 00:53:51 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " c_stcomm as st " ;
2009-04-27 22:37:50 +02:00
$sql .= " WHERE s.fk_stcomm = st.id " ;
2010-01-05 21:03:37 +01:00
$sql .= " AND s.client IN (1, 3) " ;
2012-01-11 14:14:14 +01:00
$sql .= ' AND s.entity IN (' . getEntity ( 'societe' , 1 ) . ')' ;
2013-12-14 15:21:15 +01:00
if (( ! $user -> rights -> societe -> client -> voir && ! $socid ) || $search_sale ) $sql .= " AND s.rowid = sc.fk_soc " ;
2009-04-27 22:37:50 +02:00
if ( $socid ) $sql .= " AND s.rowid = " . $socid ;
2010-03-16 20:50:07 +01:00
if ( $search_sale ) $sql .= " AND s.rowid = sc.fk_soc " ; // Join for the needed table to filter by sale
2012-07-28 22:07:27 +02:00
if ( $catid > 0 ) $sql .= " AND cs.fk_categorie = " . $catid ;
if ( $catid == - 2 ) $sql .= " AND cs.fk_categorie IS NULL " ;
if ( $search_categ > 0 ) $sql .= " AND cs.fk_categorie = " . $search_categ ;
if ( $search_categ == - 2 ) $sql .= " AND cs.fk_categorie IS NULL " ;
2013-09-10 16:43:06 +02:00
if ( $search_nom ) {
2013-09-13 10:52:04 +02:00
$sql .= natural_search ( 's.nom' , $search_nom );
2013-09-10 16:43:06 +02:00
}
2013-02-24 17:08:52 +01:00
if ( $search_zipcode ) $sql .= " AND s.zip LIKE ' " . $db -> escape ( $search_zipcode ) . " %' " ;
2013-09-10 16:43:06 +02:00
if ( $search_town ) {
2013-09-13 10:52:04 +02:00
$sql .= natural_search ( 's.town' , $search_town );
2013-09-10 16:43:06 +02:00
}
2012-10-22 12:13:24 +02:00
if ( $search_code ) $sql .= " AND s.code_client LIKE '% " . $db -> escape ( $search_code ) . " %' " ;
2012-07-28 00:53:51 +02:00
if ( $search_compta ) $sql .= " AND s.code_compta LIKE '% " . $db -> escape ( $search_compta ) . " %' " ;
2013-11-12 15:22:11 +01:00
if ( $search_status != '' ) $sql .= " AND s.status = " . $db -> escape ( $search_status );
2010-03-16 20:50:07 +01:00
// Insert sale filter
if ( $search_sale )
{
$sql .= " AND sc.fk_user = " . $search_sale ;
}
2003-07-10 20:57:25 +02:00
2008-03-06 18:56:12 +01:00
// Count total nb of records
$nbtotalofrecords = 0 ;
2008-03-06 19:12:07 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
2008-03-06 18:56:12 +01:00
{
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
}
2002-05-10 14:28:10 +02:00
2010-03-13 00:40:39 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2006-05-20 11:19:20 +02:00
2013-12-14 15:21:15 +01:00
dol_syslog ( 'comm/list.php: sql=' . $sql , LOG_DEBUG );
2003-03-23 16:53:03 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
2008-11-11 22:04:43 +01:00
$num = $db -> num_rows ( $result );
2013-02-22 16:19:16 +01:00
$param = " &search_nom= " . $search_nom . " &search_code= " . $search_code . " &search_zipcode= " . $search_zipcode . " &search_town= " . $search_town ;
2010-03-16 20:50:07 +01:00
if ( $search_categ != '' ) $param .= '&search_categ=' . $search_categ ;
if ( $search_sale != '' ) $param .= '&search_sale=' . $search_sale ;
2013-11-12 15:22:11 +01:00
if ( $search_status != '' ) $param .= '&search_status=' . $search_status ;
2008-11-11 22:04:43 +01:00
print_barre_liste ( $langs -> trans ( " ListOfCustomers " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords );
$i = 0 ;
2012-10-20 10:53:44 +02:00
print '<form method="GET" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2010-03-16 20:50:07 +01:00
// Filter on categories
$moreforfilter = '' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> categorie -> enabled ))
2010-03-16 20:50:07 +01:00
{
$moreforfilter .= $langs -> trans ( 'Categories' ) . ': ' ;
2012-07-28 00:53:51 +02:00
$moreforfilter .= $formother -> select_categories ( 2 , $search_categ , 'search_categ' , 1 );
2010-03-16 20:50:07 +01:00
$moreforfilter .= ' ' ;
}
// If the user can view prospects other than his'
if ( $user -> rights -> societe -> client -> voir || $socid )
{
$moreforfilter .= $langs -> trans ( 'SalesRepresentatives' ) . ': ' ;
2012-05-05 17:28:52 +02:00
$moreforfilter .= $formother -> select_salesrepresentatives ( $search_sale , 'search_sale' , $user );
2010-03-16 20:50:07 +01:00
}
if ( $moreforfilter )
{
2012-10-20 10:04:49 +02:00
print '<div class="liste_titre">' ;
2010-03-16 20:50:07 +01:00
print $moreforfilter ;
2012-10-20 10:04:49 +02:00
print '</div>' ;
2010-03-16 20:50:07 +01:00
}
2012-10-20 10:04:49 +02:00
print '<table class="liste" width="100%">' . " \n " ;
2008-11-11 22:04:43 +01:00
print '<tr class="liste_titre">' ;
2011-04-21 23:21:06 +02:00
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , $param , " " , $sortfield , $sortorder );
2013-02-24 17:08:52 +01:00
print_liste_field_titre ( $langs -> trans ( " Zip " ), $_SERVER [ " PHP_SELF " ], " s.zip " , " " , $param , " " , $sortfield , $sortorder );
2013-02-22 16:19:16 +01:00
print_liste_field_titre ( $langs -> trans ( " Town " ), $_SERVER [ " PHP_SELF " ], " s.town " , " " , $param , " " , $sortfield , $sortorder );
2011-05-02 01:14:54 +02:00
print_liste_field_titre ( $langs -> trans ( " CustomerCode " ), $_SERVER [ " PHP_SELF " ], " s.code_client " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " AccountancyCode " ), $_SERVER [ " PHP_SELF " ], " s.code_compta " , " " , $param , 'align="left"' , $sortfield , $sortorder );
2011-04-21 23:21:06 +02:00
print_liste_field_titre ( $langs -> trans ( " DateCreation " ), $_SERVER [ " PHP_SELF " ], " datec " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2014-01-31 18:48:57 +01:00
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " s.status " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print '<td class="liste_titre"> </td>' ;
2012-10-20 10:04:49 +02:00
$parameters = array ();
$formconfirm = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print " </tr> \n " ;
2008-11-11 22:04:43 +01:00
print '<tr class="liste_titre">' ;
2011-05-02 01:14:54 +02:00
2008-11-11 22:04:43 +01:00
print '<td class="liste_titre">' ;
2011-05-02 01:14:54 +02:00
print '<input type="text" class="flat" name="search_nom" value="' . $search_nom . '" size="10">' ;
2011-03-26 19:29:29 +01:00
print '</td>' ;
2011-05-02 01:14:54 +02:00
2012-10-22 11:05:55 +02:00
print '<td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_zipcode" value="' . $search_zipcode . '" size="10">' ;
print '</td>' ;
2011-05-02 01:14:54 +02:00
print '<td class="liste_titre">' ;
2013-02-22 16:19:16 +01:00
print '<input type="text" class="flat" name="search_town" value="' . $search_town . '" size="10">' ;
2011-05-02 01:14:54 +02:00
print '</td>' ;
2011-03-26 19:29:29 +01:00
print '<td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_code" value="' . $search_code . '" size="10">' ;
print '</td>' ;
2011-05-02 01:14:54 +02:00
print '<td align="left" class="liste_titre">' ;
print '<input type="text" class="flat" name="search_compta" value="' . $search_compta . '" size="10">' ;
print '</td>' ;
2013-11-12 15:22:11 +01:00
print '<td class="liste_titre" align="center">' ;
print ' ' ;
print '</td>' ;
print '<td class="liste_titre" align="center">' ;
print $form -> selectarray ( 'search_status' , array ( '0' => $langs -> trans ( 'ActivityCeased' ), '1' => $langs -> trans ( 'InActivity' )), $search_status );
print '</td>' ;
2011-05-13 22:00:43 +02:00
2014-01-13 09:43:21 +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 " )) . '">' ;
2011-02-14 18:27:08 +01:00
print ' ' ;
2014-01-13 09:43:21 +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 " )) . '">' ;
2011-02-14 18:27:08 +01:00
print '</td>' ;
2011-05-13 22:00:43 +02:00
2012-10-20 10:04:49 +02:00
$parameters = array ();
$formconfirm = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters ); // Note that $action and $object may have been modified by hook
2011-02-14 18:27:08 +01:00
print " </tr> \n " ;
2008-11-11 22:04:43 +01:00
$var = True ;
while ( $i < min ( $num , $conf -> liste_limit ))
2005-02-14 11:28:18 +01:00
{
2008-11-11 22:04:43 +01:00
$obj = $db -> fetch_object ( $result );
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2011-02-14 17:49:04 +01:00
print '<td>' ;
$thirdpartystatic -> id = $obj -> rowid ;
2011-02-21 09:58:45 +01:00
$thirdpartystatic -> name = $obj -> name ;
2011-02-14 17:49:04 +01:00
$thirdpartystatic -> client = $obj -> client ;
2013-11-12 15:22:11 +01:00
$thirdpartystatic -> code_client = $obj -> code_client ;
2011-02-14 17:49:04 +01:00
$thirdpartystatic -> canvas = $obj -> canvas ;
2011-05-13 22:00:43 +02:00
$thirdpartystatic -> status = $obj -> status ;
2011-02-14 17:49:04 +01:00
print $thirdpartystatic -> getNomUrl ( 1 );
print '</td>' ;
2012-10-22 11:05:55 +02:00
print '<td>' . $obj -> zip . '</td>' ;
2013-02-22 16:19:16 +01:00
print '<td>' . $obj -> town . '</td>' ;
2011-03-26 19:29:29 +01:00
print '<td>' . $obj -> code_client . '</td>' ;
2011-05-02 01:14:54 +02:00
print '<td>' . $obj -> code_compta . '</td>' ;
print '<td align="right">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . '</td>' ;
2013-11-12 15:22:11 +01:00
print '<td align="center">' . $thirdpartystatic -> getLibStatut ( 3 );
2011-05-13 22:00:43 +02:00
print '</td>' ;
2013-11-12 15:22:11 +01:00
print '<td></td>' ;
2012-10-20 10:04:49 +02:00
$parameters = array ( 'obj' => $obj );
$formconfirm = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
2011-05-13 22:00:43 +02:00
print " </tr> \n " ;
2008-11-11 22:04:43 +01:00
$i ++ ;
2005-02-14 11:28:18 +01:00
}
2008-11-11 22:04:43 +01:00
//print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
print " </table> \n " ;
print " </form> \n " ;
$db -> free ( $result );
2012-10-20 10:04:49 +02:00
$parameters = array ( 'sql' => $sql );
$formconfirm = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters ); // Note that $action and $object may have been modified by hook
2003-03-23 16:53:03 +01:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2003-03-23 16:53:03 +01:00
}
2002-05-10 14:28:10 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-10-20 10:04:49 +02:00
$db -> close ();
2002-05-10 14:28:10 +02:00
?>