2006-12-10 14:23:48 +01:00
< ? php
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-07-28 00:53:51 +02:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2011-06-09 12:22:14 +02:00
* Copyright ( C ) 2011 Philippe Grand < philippe . grand @ atoo - net . com >
2013-09-10 16:43:06 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2006-12-10 14:23:48 +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
2006-12-10 14:23:48 +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 />.
2006-12-10 14:23:48 +01:00
*/
/**
2014-09-18 20:33:37 +02:00
* \file htdocs / fourn / list . php
2008-11-16 19:55:00 +01:00
* \ingroup fournisseur
2010-07-10 18:42:12 +02:00
* \brief Home page of supplier area
2008-11-16 19:55:00 +01:00
*/
2006-12-10 14:23:48 +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' ;
2015-03-13 20:27:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2006-12-10 14:23:48 +01:00
2007-11-15 21:04:35 +01:00
$langs -> load ( " suppliers " );
$langs -> load ( " orders " );
$langs -> load ( " companies " );
2014-11-02 15:16:49 +01:00
$socname = GETPOST ( " socname " );
$search_name = GETPOST ( " search_name " );
$search_zipcode = GETPOST ( " search_zipcode " );
$search_town = GETPOST ( " search_town " );
$search_supplier_code = GETPOST ( " search_supplier_code " );
$search_supplier_accounting = GETPOST ( " search_supplier_accounting " );
$search_datec = GETPOST ( " search_datec " );
$search_categ = GETPOST ( 'search_categ' , 'int' );
$catid = GETPOST ( " catid " , 'int' );
2006-12-10 14:23:48 +01:00
2008-02-25 17:30:43 +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-11-03 17:38:04 +01:00
$result = restrictedArea ( $user , 'societe' , $socid , '' );
2006-12-10 14:23:48 +01:00
2012-10-13 14:47:46 +02:00
$page = GETPOST ( 'page' , 'int' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
2006-12-10 14:23:48 +01:00
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
2008-03-31 05:57:05 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2006-12-10 14:23:48 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " nom " ;
2012-10-20 10:53:44 +02:00
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'supplierlist' ));
2015-03-13 20:27:54 +01:00
$extrafields = new ExtraFields ( $db );
2012-10-20 10:53:44 +02:00
2014-11-23 09:36:07 +01:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter " )) // Both test are required to be compatible with all browsers
2014-11-02 15:16:49 +01:00
{
$socname = " " ;
$search_name = " " ;
$search_zipcode = " " ;
$search_town = " " ;
$search_supplier_code = " " ;
$search_supplier_accounting = " " ;
$search_datec = " " ;
$search_categ = " " ;
$catid = " " ;
}
2015-03-13 20:27:54 +01:00
$extrafields -> fetch_name_optionals_label ( 'thirdparty' );
2012-10-20 10:53:44 +02:00
/*
* Actions
*/
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters ); // Note that $action and $object may have been modified by some hooks
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2010-03-16 20:50:07 +01:00
2008-02-25 17:30:43 +01:00
/*
2010-03-16 20:50:07 +01:00
* View
*/
$htmlother = new FormOther ( $db );
2011-05-13 22:00:43 +02:00
$thirdpartystatic = new Societe ( $db );
2008-02-25 17:30:43 +01:00
2011-05-13 20:44:41 +02:00
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas' ;
llxHeader ( '' , $langs -> trans ( " ThirdParty " ), $help_url );
2008-02-25 17:30:43 +01:00
2014-10-04 17:20:17 +02:00
$sql = " SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.datec, st.libelle as stcomm, s.prefix_comm, s.status as status, " ;
2011-05-13 22:00:43 +02:00
$sql .= " code_fournisseur, code_compta_fournisseur " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , sc.fk_soc, sc.fk_user " ;
2015-03-13 20:27:54 +01:00
// Add fields for extrafields
2015-03-18 14:08:37 +01:00
foreach ( $extrafields -> attribute_list as $key => $val ) $sql .= " ,ef. " . $key . ' as options_' . $key ;
2015-03-13 20:27:54 +01:00
// Add fields from hooks
$parameters = array ();
2015-03-18 12:03:47 +01:00
$result = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters ); // Note that $action and $object may have been modified by hook
2015-03-13 20:27:54 +01:00
$sql .= $hookmanager -> resPrint ;
2012-07-28 00:53:51 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2015-03-13 20:27:54 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_extrafields as ef ON ef.fk_object = s.rowid " ;
2015-04-18 18:11:01 +02:00
if ( ! empty ( $search_categ ) || ! empty ( $catid )) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . " categorie_fournisseur as cf ON s.rowid = cf.fk_soc " ; // We need this table joined to the select in order to filter by categ
2012-07-28 00:53:51 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " c_stcomm as st " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2011-11-03 17:38:04 +01:00
$sql .= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1 " ;
2012-02-01 11:32:55 +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 ) $sql .= " AND s.rowid = sc.fk_soc " ;
2007-06-12 00:51:47 +02:00
if ( $socid ) $sql .= " AND s.rowid = " . $socid ;
2013-09-10 16:43:06 +02:00
if ( $socname ) {
2013-09-13 10:52:04 +02:00
$sql .= natural_search ( 's.nom' , $socname );
2010-03-16 20:50:07 +01:00
$sortfield = " s.nom " ;
$sortorder = " ASC " ;
2006-12-10 14:23:48 +01:00
}
2014-11-02 15:16:49 +01:00
if ( $search_name ) {
$sql .= natural_search ( 's.nom' , $search_name );
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
}
2014-11-02 15:16:49 +01:00
if ( $search_supplier_code ) $sql .= " AND s.code_fournisseur LIKE '% " . $db -> escape ( $search_supplier_code ) . " %' " ;
if ( $search_supplier_accounting ) $sql .= " AND s.code_compta_fournisseur LIKE '% " . $db -> escape ( $search_supplier_accounting ) . " %' " ;
2011-06-09 12:22:14 +02:00
if ( $search_datec ) $sql .= " AND s.datec LIKE '% " . $db -> escape ( $search_datec ) . " %' " ;
2012-07-28 00:53:51 +02:00
if ( $catid > 0 ) $sql .= " AND cf.fk_categorie = " . $catid ;
if ( $catid == - 2 ) $sql .= " AND cf.fk_categorie IS NULL " ;
if ( $search_categ > 0 ) $sql .= " AND cf.fk_categorie = " . $search_categ ;
if ( $search_categ == - 2 ) $sql .= " AND cf.fk_categorie IS NULL " ;
2015-03-13 20:27:54 +01:00
// Add where from hooks
$parameters = array ();
2015-03-18 12:03:47 +01:00
$result = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
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 );
}
2010-03-16 20:50:07 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2008-03-31 05:57:05 +02:00
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2015-03-13 20:27:54 +01:00
//print $sql;
2006-12-10 14:23:48 +01:00
2014-09-18 20:33:37 +02:00
dol_syslog ( 'fourn/list.php:' , LOG_DEBUG );
2006-12-10 14:23:48 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2010-03-16 20:50:07 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2014-11-02 15:16:49 +01:00
$param = " &search_name= " . $search_name . " &search_supplier_code= " . $search_supplier_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 ;
2012-07-28 00:53:51 +02:00
print_barre_liste ( $langs -> trans ( " ListOfSuppliers " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords );
2010-03-16 20:50:07 +01:00
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 .= $htmlother -> select_categories ( 1 , $search_categ , 'search_categ' , 1 );
2010-03-16 20:50:07 +01:00
$moreforfilter .= ' ' ;
}
if ( $moreforfilter )
{
2012-10-20 10:53:44 +02:00
print '<div class="liste_titre">' ;
2010-03-16 20:50:07 +01:00
print $moreforfilter ;
2012-10-20 10:53:44 +02:00
print '</div>' ;
2010-03-16 20:50:07 +01:00
}
2012-10-20 10:53:44 +02:00
print '<table class="liste" width="100%">' ;
2010-03-16 20:50:07 +01:00
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , $param , 'valign="middle"' , $sortfield , $sortorder );
2013-02-24 17:08:52 +01:00
print_liste_field_titre ( $langs -> trans ( " Zip " ), $_SERVER [ " PHP_SELF " ], " s.zip " , " " , $param , 'valign="middle"' , $sortfield , $sortorder );
2013-02-22 17:43:33 +01:00
print_liste_field_titre ( $langs -> trans ( " Town " ), $_SERVER [ " PHP_SELF " ], " s.town " , " " , $param , 'valign="middle"' , $sortfield , $sortorder );
2010-03-16 20:50:07 +01:00
print_liste_field_titre ( $langs -> trans ( " SupplierCode " ), $_SERVER [ " PHP_SELF " ], " s.code_fournisseur " , " " , $param , 'align="left"' , $sortfield , $sortorder );
2011-05-02 01:14:54 +02:00
print_liste_field_titre ( $langs -> trans ( " AccountancyCode " ), $_SERVER [ " PHP_SELF " ], " s.code_compta_fournisseur " , " " , $param , 'align="left"' , $sortfield , $sortorder );
2011-06-09 12:22:14 +02:00
print_liste_field_titre ( $langs -> trans ( " DateCreation " ), $_SERVER [ " PHP_SELF " ], " s.datec " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2012-10-20 10:53:44 +02:00
2015-03-18 14:08:37 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2012-10-20 10:53:44 +02:00
2015-03-18 14:08:37 +01:00
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " s.status " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2010-03-16 20:50:07 +01:00
print " </tr> \n " ;
print '<tr class="liste_titre">' ;
2014-11-02 15:16:49 +01:00
print '<td class="liste_titre"><input type="text" size="10" class="flat" name="search_name" value="' . $search_name . '"></td>' ;
2011-05-02 01:14:54 +02:00
2014-11-02 15:16:49 +01:00
print '<td class="liste_titre"><input type="text" size="10" class="flat" name="search_zipcode" value="' . $search_zipcode . '"></td>' ;
2012-10-22 11:05:55 +02:00
2014-11-02 15:16:49 +01:00
print '<td class="liste_titre"><input type="text" size="10" class="flat" name="search_town" value="' . $search_town . '"></td>' ;
2010-03-16 20:50:07 +01:00
print '<td align="left" class="liste_titre">' ;
2014-11-02 15:16:49 +01:00
print '<input class="flat" type="text" size="10" name="search_supplier_code" value="' . $search_supplier_code . '">' ;
2010-03-16 20:50:07 +01:00
print '</td>' ;
print '<td align="left" class="liste_titre">' ;
2014-11-02 15:16:49 +01:00
print '<input class="flat" type="text" size="10" name="search_supplier_accounting" value="' . $search_supplier_accounting . '">' ;
2010-03-16 20:50:07 +01:00
print '</td>' ;
2011-06-09 12:22:14 +02:00
print '<td align="right" class="liste_titre">' ;
print '<input class="flat" type="text" size="10" name="search_datec" value="' . $search_datec . '">' ;
print '</td>' ;
2011-05-13 22:00:43 +02:00
2015-03-18 14:08:37 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSearch' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2014-11-02 15:16:49 +01:00
print '<td 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 " )) . '">' ;
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 " ;
2015-03-13 20:27:54 +01:00
2010-03-16 20:50:07 +01:00
print '</tr>' ;
$var = True ;
while ( $i < min ( $num , $conf -> liste_limit ))
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
2011-05-17 16:45:20 +02:00
$thirdpartystatic -> id = $obj -> socid ;
2014-10-04 17:20:17 +02:00
$thirdpartystatic -> name = $obj -> name ;
2011-05-13 22:00:43 +02:00
$thirdpartystatic -> status = $obj -> status ;
2011-05-02 01:14:54 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2011-05-13 22:00:43 +02:00
print '<td>' ;
print $thirdpartystatic -> getNomUrl ( 1 , 'supplier' );
print " </td> \n " ;
2012-10-22 11:05:55 +02:00
print '<td>' . $obj -> zip . '</td>' . " \n " ;
2013-02-22 17:43:33 +01:00
print '<td>' . $obj -> town . '</td>' . " \n " ;
2010-03-16 20:50:07 +01:00
print '<td align="left">' . $obj -> code_fournisseur . ' </td>' ;
print '<td align="left">' . $obj -> code_compta_fournisseur . ' </td>' ;
2015-03-18 14:08:37 +01:00
print '<td align="right">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . '</td>' ;
2012-10-20 10:53:44 +02:00
$parameters = array ( 'obj' => $obj );
2015-03-18 14:08:37 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
print '<td align="right">' . $thirdpartystatic -> getLibStatut ( 3 ) . '</td>' ;
2012-10-20 10:53:44 +02:00
2010-03-16 20:50:07 +01:00
print " </tr> \n " ;
$i ++ ;
}
print " </table> \n " ;
print " </form> \n " ;
$db -> free ( $resql );
2012-10-20 10:53:44 +02:00
$parameters = array ( 'sql' => $sql );
2015-03-18 14:08:37 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2006-12-10 14:23:48 +01:00
}
2010-03-16 20:50:07 +01:00
else
2006-12-10 14:23:48 +01:00
{
2010-03-16 20:50:07 +01:00
dol_print_error ( $db );
2006-12-10 14:23:48 +01:00
}
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();