2004-10-19 20:58:50 +02:00
< ? php
2009-04-27 22:37:50 +02:00
/* Copyright ( C ) 2001 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-05-03 22:58:12 +02:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-10-04 18:40:05 +02:00
* Copyright ( C ) 2012 Juanjo Menent < jmenent @ 2 byte . es >
2013-01-03 11:06:05 +01:00
* Copyright ( C ) 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
2013-09-10 16:43:06 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2015-01-31 10:58:03 +01:00
* Copyright ( C ) 2015 Frederic France < frederic . france @ free . fr >
2015-03-20 11:28:23 +01:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2015-04-18 21:28:55 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2003-11-09 18:52:17 +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
2003-11-09 18:52:17 +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 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-11-09 18:52:17 +01:00
*/
2005-08-11 20:54:59 +02:00
/**
2014-09-18 20:33:37 +02:00
* \file htdocs / commande / list . php
2009-06-14 22:59:27 +02:00
* \ingroup commande
* \brief Page to list orders
2008-10-23 23:54:30 +02:00
*/
2005-02-06 19:45:24 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2013-06-01 15:39:45 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2014-10-23 17:48:51 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2003-11-09 18:52:17 +01:00
2005-09-15 02:37:03 +02:00
$langs -> load ( 'orders' );
2010-10-06 10:13:22 +02:00
$langs -> load ( 'deliveries' );
2006-08-03 13:53:09 +02:00
$langs -> load ( 'companies' );
2004-08-02 04:00:18 +02:00
2010-11-10 22:07:04 +01:00
$orderyear = GETPOST ( " orderyear " , " int " );
$ordermonth = GETPOST ( " ordermonth " , " int " );
$deliveryyear = GETPOST ( " deliveryyear " , " int " );
$deliverymonth = GETPOST ( " deliverymonth " , " int " );
2015-07-02 22:07:13 +02:00
$search_product_category = GETPOST ( 'search_product_category' , 'int' );
2015-03-28 17:17:55 +01:00
$search_ref = GETPOST ( 'search_ref' , 'alpha' ) != '' ? GETPOST ( 'search_ref' , 'alpha' ) : GETPOST ( 'sref' , 'alpha' );
2014-11-06 07:13:03 +01:00
$search_ref_customer = GETPOST ( 'search_ref_customer' , 'alpha' );
$search_company = GETPOST ( 'search_company' , 'alpha' );
2010-11-10 22:07:04 +01:00
$sall = GETPOST ( 'sall' );
$socid = GETPOST ( 'socid' , 'int' );
2012-05-05 19:41:38 +02:00
$search_user = GETPOST ( 'search_user' , 'int' );
2012-06-23 20:39:20 +02:00
$search_sale = GETPOST ( 'search_sale' , 'int' );
2015-03-06 20:59:18 +01:00
$search_total_ht = GETPOST ( 'search_total_ht' , 'alpha' );
2005-04-12 11:59:04 +02:00
2008-02-25 17:30:43 +01:00
// Security check
2012-02-27 22:26:22 +01:00
$id = ( GETPOST ( 'orderid' ) ? GETPOST ( 'orderid' ) : GETPOST ( 'id' , 'int' ));
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2011-11-25 17:35:01 +01:00
$result = restrictedArea ( $user , 'commande' , $id , '' );
2003-11-09 18:52:17 +01:00
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortfield ) $sortfield = 'c.rowid' ;
if ( ! $sortorder ) $sortorder = 'DESC' ;
$limit = $conf -> liste_limit ;
2011-05-22 02:42:37 +02:00
$viewstatut = GETPOST ( 'viewstatut' );
2014-11-06 07:13:03 +01:00
// Purge search criteria
2014-11-23 01:21:51 +01:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter " )) // Both test are required to be compatible with all browsers
2012-06-23 20:39:20 +02:00
{
$search_categ = '' ;
$search_user = '' ;
$search_sale = '' ;
2015-07-02 22:07:13 +02:00
$search_product_category = '' ;
2012-06-23 20:39:20 +02:00
$search_ref = '' ;
2014-11-06 07:13:03 +01:00
$search_ref_customer = '' ;
$search_company = '' ;
2015-03-06 20:59:18 +01:00
$search_total_ht = '' ;
2012-07-13 10:15:47 +02:00
$orderyear = '' ;
$ordermonth = '' ;
$deliverymonth = '' ;
$deliveryyear = '' ;
2012-06-23 20:39:20 +02:00
}
2014-11-06 07:13:03 +01:00
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'orderlist' ));
2012-06-23 20:39:20 +02:00
2014-11-06 07:13:03 +01:00
/*
* Actions
*/
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hook
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2005-09-01 00:14:12 +02:00
2015-03-06 20:59:18 +01:00
2006-05-25 22:07:09 +02:00
/*
2008-08-08 19:58:50 +02:00
* View
2006-05-25 22:07:09 +02:00
*/
2008-10-23 23:54:30 +02:00
2010-11-20 14:08:44 +01:00
$now = dol_now ();
2009-01-07 16:21:16 +01:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2012-06-23 20:39:20 +02:00
$formother = new FormOther ( $db );
2008-01-20 14:53:02 +01:00
$formfile = new FormFile ( $db );
2009-08-05 20:11:27 +02:00
$companystatic = new Societe ( $db );
2008-10-23 23:54:30 +02:00
2012-08-07 13:12:20 +02:00
$help_url = " EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes " ;
llxHeader ( '' , $langs -> trans ( " Orders " ), $help_url );
2003-11-09 18:52:17 +01:00
2015-07-02 22:07:13 +02:00
$sql = 'SELECT' ;
if ( $sall || $search_product_category > 0 ) $sql = 'SELECT DISTINCT' ;
$sql .= ' s.nom as name, s.rowid as socid, s.client, s.code_client, c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client,' ;
2015-03-20 11:28:23 +01:00
$sql .= ' c.date_valid, c.date_commande, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as facturee' ;
2009-04-27 22:37:50 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
$sql .= ', ' . MAIN_DB_PREFIX . 'commande as c' ;
2015-07-02 22:07:13 +02:00
if ( $sall || $search_product_category > 0 ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commandedet as pd ON c.rowid=pd.fk_commande' ;
if ( $search_product_category > 0 ) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'categorie_product as cp ON cp.fk_product=pd.fk_product' ;
2012-06-23 20:39:20 +02:00
// We'll need this table joined to the select in order to filter by sale
if ( $search_sale > 0 || ( ! $user -> rights -> societe -> client -> voir && ! $socid )) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2012-05-05 19:41:38 +02:00
if ( $search_user > 0 )
{
$sql .= " , " . MAIN_DB_PREFIX . " element_contact as ec " ;
$sql .= " , " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
}
2007-06-12 00:51:47 +02:00
$sql .= ' WHERE c.fk_soc = s.rowid' ;
2015-04-19 03:05:37 +02:00
$sql .= ' AND c.entity IN (' . getEntity ( 'commande' , 1 ) . ')' ;
2015-07-02 22:07:13 +02:00
if ( $search_product_category > 0 ) $sql .= " AND cp.fk_categorie = " . $search_product_category ;
if ( $socid > 0 ) $sql .= ' AND s.rowid = ' . $socid ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2015-06-30 13:14:19 +02:00
if ( $search_ref ) $sql .= natural_search ( 'c.ref' , $search_ref );
if ( $sall ) $sql .= natural_search ( array ( 'c.ref' , 'c.note_private' ), $sall );
2009-10-27 12:24:48 +01:00
if ( $viewstatut <> '' )
2005-09-15 02:37:03 +02:00
{
2012-10-03 11:43:39 +02:00
if ( $viewstatut < 4 && $viewstatut > - 3 )
2007-03-30 13:41:41 +02:00
{
2013-03-16 17:02:13 +01:00
if ( $viewstatut == 1 && empty ( $conf -> expedition -> enabled )) $sql .= ' AND c.fk_statut IN (1,2)' ; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
else $sql .= ' AND c.fk_statut = ' . $viewstatut ; // brouillon, validee, en cours, annulee
2007-03-30 13:55:36 +02:00
if ( $viewstatut == 3 )
{
2009-06-14 22:59:27 +02:00
$sql .= ' AND c.facture = 0' ; // need to create invoice
2007-03-30 13:55:36 +02:00
}
2007-03-30 13:41:41 +02:00
}
2008-08-08 19:58:50 +02:00
if ( $viewstatut == 4 )
2007-03-30 13:41:41 +02:00
{
2009-06-14 22:59:27 +02:00
$sql .= ' AND c.facture = 1' ; // invoice created
2007-03-30 13:41:41 +02:00
}
2009-06-14 22:59:27 +02:00
if ( $viewstatut == - 2 ) // To process
2008-08-08 19:58:50 +02:00
{
2012-05-03 22:58:12 +02:00
//$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
$sql .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0)) " ; // If status is 2 and facture=1, it must be selected
2008-08-08 19:58:50 +02:00
}
2012-10-03 11:43:39 +02:00
if ( $viewstatut == - 3 ) // To bill
{
2014-09-25 17:00:44 +02:00
//$sql.= ' AND c.fk_statut in (1,2,3)';
//$sql.= ' AND c.facture = 0'; // invoice not created
$sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))' ; // validated, in process or closed but not billed
2012-10-03 11:43:39 +02:00
}
2005-09-15 02:37:03 +02:00
}
2011-11-25 17:35:01 +01:00
if ( $ordermonth > 0 )
2003-11-17 11:12:30 +01:00
{
2012-05-05 19:41:38 +02:00
if ( $orderyear > 0 && empty ( $day ))
2014-03-06 17:02:27 +01:00
$sql .= " AND c.date_commande BETWEEN ' " . $db -> idate ( dol_get_first_day ( $orderyear , $ordermonth , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $orderyear , $ordermonth , false )) . " ' " ;
2012-05-05 19:41:38 +02:00
else if ( $orderyear > 0 && ! empty ( $day ))
2014-03-06 17:02:27 +01:00
$sql .= " AND c.date_commande BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $ordermonth , $day , $orderyear )) . " ' AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $ordermonth , $day , $orderyear )) . " ' " ;
2012-05-05 19:41:38 +02:00
else
2014-03-06 17:02:27 +01:00
$sql .= " AND date_format(c.date_commande, '%m') = ' " . $ordermonth . " ' " ;
2007-03-30 13:41:41 +02:00
}
2012-05-05 19:41:38 +02:00
else if ( $orderyear > 0 )
2007-03-30 13:41:41 +02:00
{
2014-03-06 17:02:27 +01:00
$sql .= " AND c.date_commande BETWEEN ' " . $db -> idate ( dol_get_first_day ( $orderyear , 1 , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $orderyear , 12 , false )) . " ' " ;
2010-10-06 10:01:41 +02:00
}
2011-11-25 17:35:01 +01:00
if ( $deliverymonth > 0 )
2010-10-06 10:01:41 +02:00
{
2012-05-05 19:41:38 +02:00
if ( $deliveryyear > 0 && empty ( $day ))
$sql .= " AND c.date_livraison BETWEEN ' " . $db -> idate ( dol_get_first_day ( $deliveryyear , $deliverymonth , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $deliveryyear , $deliverymonth , false )) . " ' " ;
else if ( $deliveryyear > 0 && ! empty ( $day ))
$sql .= " AND c.date_livraison BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $deliverymonth , $day , $deliveryyear )) . " ' AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $deliverymonth , $day , $deliveryyear )) . " ' " ;
else
$sql .= " AND date_format(c.date_livraison, '%m') = ' " . $deliverymonth . " ' " ;
2010-10-06 10:01:41 +02:00
}
2012-05-05 19:41:38 +02:00
else if ( $deliveryyear > 0 )
2010-10-06 10:01:41 +02:00
{
2012-05-05 19:41:38 +02:00
$sql .= " AND c.date_livraison BETWEEN ' " . $db -> idate ( dol_get_first_day ( $deliveryyear , 1 , false )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $deliveryyear , 12 , false )) . " ' " ;
2003-11-17 11:12:30 +01:00
}
2015-06-30 13:14:19 +02:00
if ( ! empty ( $search_company )) $sql .= natural_search ( 's.nom' , $search_company );
if ( ! empty ( $search_ref_customer )) $sql .= natural_search ( 'c.ref_client' , $search_ref_customer );
2012-06-23 20:39:20 +02:00
if ( $search_sale > 0 ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $search_sale ;
2015-06-30 13:14:19 +02:00
if ( $search_user > 0 ) $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = " . $search_user ;
if ( $search_total_ht != '' ) $sql .= natural_search ( 'c.total_ht' , $search_total_ht , 1 );
$sql .= $db -> order ( $sortfield , $sortorder );
2014-05-12 11:00:58 +02:00
$nbtotalofrecords = 0 ;
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
}
2009-04-27 22:37:50 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2003-11-09 18:52:17 +01:00
2012-05-05 19:41:38 +02:00
//print $sql;
2005-04-12 11:59:04 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2003-11-09 18:52:17 +01:00
{
2006-09-13 20:56:30 +02:00
if ( $socid )
2005-09-15 02:37:03 +02:00
{
$soc = new Societe ( $db );
2006-09-13 20:56:30 +02:00
$soc -> fetch ( $socid );
2014-10-04 17:20:17 +02:00
$title = $langs -> trans ( 'ListOfOrders' ) . ' - ' . $soc -> name ;
2005-09-15 02:37:03 +02:00
}
else
2005-04-12 11:59:04 +02:00
{
2005-09-15 02:37:03 +02:00
$title = $langs -> trans ( 'ListOfOrders' );
2005-04-12 11:59:04 +02:00
}
2011-11-25 17:35:01 +01:00
if ( strval ( $viewstatut ) == '0' )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderDraftShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == 1 )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderValidatedShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == 2 )
2014-11-22 00:08:06 +01:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderSentShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == 3 )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderToBillShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == 4 )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderProcessedShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == - 1 )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderCanceledShort' );
2011-11-25 17:35:01 +01:00
if ( $viewstatut == - 2 )
2008-10-23 23:54:30 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderToProcessShort' );
2012-10-08 20:47:10 +02:00
if ( $viewstatut == - 3 )
2013-03-16 17:02:13 +01:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderValidated' ) . ', ' . ( empty ( $conf -> expedition -> enabled ) ? '' : $langs -> trans ( " StatusOrderSent " ) . ', ' ) . $langs -> trans ( 'StatusOrderToBill' );
2008-10-23 23:54:30 +02:00
2012-05-05 20:07:34 +02:00
$param = '&socid=' . $socid . '&viewstatut=' . $viewstatut ;
2014-11-06 07:13:03 +01:00
if ( $ordermonth ) $param .= '&ordermonth=' . $ordermonth ;
if ( $orderyear ) $param .= '&orderyear=' . $orderyear ;
if ( $deliverymonth ) $param .= '&deliverymonth=' . $deliverymonth ;
if ( $deliveryyear ) $param .= '&deliveryyear=' . $deliveryyear ;
if ( $search_ref ) $param .= '&search_ref=' . $search_ref ;
if ( $search_company ) $param .= '&search_company=' . $search_company ;
if ( $search_ref_customer ) $param .= '&search_ref_customer=' . $search_ref_customer ;
if ( $search_user > 0 ) $param .= '&search_user=' . $search_user ;
if ( $search_sale > 0 ) $param .= '&search_sale=' . $search_sale ;
2015-03-06 20:59:18 +01:00
if ( $search_total_ht != '' ) $param .= '&search_total_ht=' . $search_total_ht ;
2015-03-14 14:55:41 +01:00
2005-09-15 02:37:03 +02:00
$num = $db -> num_rows ( $resql );
2015-04-18 21:28:55 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords , 'title_commercial.png' );
2005-09-15 02:37:03 +02:00
$i = 0 ;
2012-05-05 19:41:38 +02:00
// Lignes des champs de filtre
print '<form method="GET" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2012-10-03 11:43:39 +02:00
print '<input type="hidden" name="viewstatut" value="' . $viewstatut . '">' ;
2012-05-05 19:41:38 +02:00
2005-09-15 02:37:03 +02:00
print '<table class="noborder" width="100%">' ;
2012-05-05 19:41:38 +02:00
2012-07-13 10:15:47 +02:00
$moreforfilter = '' ;
2012-06-23 20:39:20 +02:00
// If the user can view prospects other than his'
if ( $user -> rights -> societe -> client -> voir || $socid )
{
2012-10-13 17:00:38 +02:00
$langs -> load ( " commercial " );
2015-07-02 22:07:13 +02:00
$moreforfilter .= '<div class="divsearchfield">' ;
2012-10-13 17:00:38 +02:00
$moreforfilter .= $langs -> trans ( 'ThirdPartiesOfSaleRepresentative' ) . ': ' ;
2015-07-04 11:57:55 +02:00
$moreforfilter .= $formother -> select_salesrepresentatives ( $search_sale , 'search_sale' , $user , 0 , 1 , 'maxwidth300' );
2015-07-02 22:07:13 +02:00
$moreforfilter .= '</div>' ;
2012-06-23 20:39:20 +02:00
}
2012-05-05 19:41:38 +02:00
// If the user can view prospects other than his'
if ( $user -> rights -> societe -> client -> voir || $socid )
{
2015-07-02 22:07:13 +02:00
$moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= $langs -> trans ( 'LinkedToSpecificUsers' ) . ': ' ;
2015-07-04 11:57:55 +02:00
$moreforfilter .= $form -> select_dolusers ( $search_user , 'search_user' , 1 , '' , 0 , '' , '' , 0 , 0 , 0 , '' , 0 , '' , 'maxwidth300' );
2015-07-02 22:07:13 +02:00
$moreforfilter .= '</div>' ;
}
// If the user can view prospects other than his'
if ( $conf -> categorie -> enabled && $user -> rights -> produit -> lire )
{
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= $langs -> trans ( 'IncludingProductWithTag' ) . ': ' ;
$cate_arbo = $form -> select_all_categories ( Categorie :: TYPE_PRODUCT , null , 'parent' , null , null , 1 );
$moreforfilter .= $form -> selectarray ( 'search_product_category' , $cate_arbo , $search_product_category , 1 , 0 , 0 , '' , 0 , 0 , 0 , 0 , '' , 1 );
$moreforfilter .= '</div>' ;
2012-05-05 19:41:38 +02:00
}
2012-07-13 10:15:47 +02:00
if ( ! empty ( $moreforfilter ))
2012-05-05 19:41:38 +02:00
{
2015-07-04 18:20:17 +02:00
print '<div class="liste_titre">' ;
print $moreforfilter ;
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
print '</div>' ;
2012-05-05 19:41:38 +02:00
}
2005-09-15 02:37:03 +02:00
print '<tr class="liste_titre">' ;
2012-05-05 20:07:34 +02:00
print_liste_field_titre ( $langs -> trans ( 'Ref' ), $_SERVER [ " PHP_SELF " ], 'c.ref' , '' , $param , 'width="25%"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'RefCustomerOrder' ), $_SERVER [ " PHP_SELF " ], 'c.ref_client' , '' , $param , '' , $sortfield , $sortorder );
2013-10-07 21:58:12 +02:00
print_liste_field_titre ( $langs -> trans ( 'Company' ), $_SERVER [ " PHP_SELF " ], 's.nom' , '' , $param , '' , $sortfield , $sortorder );
2014-11-06 07:13:03 +01:00
print_liste_field_titre ( $langs -> trans ( 'OrderDate' ), $_SERVER [ " PHP_SELF " ], 'c.date_commande' , '' , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'DeliveryDate' ), $_SERVER [ " PHP_SELF " ], 'c.date_livraison' , '' , $param , 'align="center"' , $sortfield , $sortorder );
2013-01-03 11:06:05 +01:00
print_liste_field_titre ( $langs -> trans ( 'AmountHT' ), $_SERVER [ " PHP_SELF " ], 'c.total_ht' , '' , $param , 'align="right"' , $sortfield , $sortorder );
2015-07-04 18:20:17 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2012-05-05 20:07:34 +02:00
print_liste_field_titre ( $langs -> trans ( 'Status' ), $_SERVER [ " PHP_SELF " ], 'c.fk_statut' , '' , $param , 'align="right"' , $sortfield , $sortorder );
2015-06-30 13:14:19 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
2005-09-15 02:37:03 +02:00
print '</tr>' ;
2014-11-22 00:08:06 +01:00
2005-09-15 02:37:03 +02:00
print '<tr class="liste_titre">' ;
2008-08-29 23:16:34 +02:00
print '<td class="liste_titre">' ;
2014-11-06 07:13:03 +01:00
print '<input class="flat" size="6" type="text" name="search_ref" value="' . $search_ref . '">' ;
2013-10-07 21:58:12 +02:00
print '</td>' ;
print '<td class="liste_titre" align="left">' ;
2014-11-06 07:13:03 +01:00
print '<input class="flat" type="text" size="6" name="search_ref_customer" value="' . $search_ref_customer . '">' ;
2013-10-07 21:58:12 +02:00
print '</td>' ;
print '<td class="liste_titre" align="left">' ;
2014-11-06 07:13:03 +01:00
print '<input class="flat" type="text" name="search_company" value="' . $search_company . '">' ;
2013-10-07 21:58:12 +02:00
print '</td>' ;
2014-11-06 07:13:03 +01:00
print '<td class="liste_titre" align="center">' ;
2014-03-06 17:02:27 +01:00
if ( ! empty ( $conf -> global -> MAIN_LIST_FILTER_ON_DAY )) print '<input class="flat" type="text" size="1" maxlength="2" name="orderday" value="' . $orderday . '">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="ordermonth" value="' . $ordermonth . '">' ;
$formother -> select_year ( $orderyear ? $orderyear :- 1 , 'orderyear' , 1 , 20 , 5 );
2014-11-06 07:13:03 +01:00
print '</td><td class="liste_titre" align="center">' ;
2014-03-06 17:02:27 +01:00
if ( ! empty ( $conf -> global -> MAIN_LIST_FILTER_ON_DAY )) print '<input class="flat" type="text" size="1" maxlength="2" name="deliveryday" value="' . $deliveryday . '">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="deliverymonth" value="' . $deliverymonth . '">' ;
$formother -> select_year ( $deliveryyear ? $deliveryyear :- 1 , 'deliveryyear' , 1 , 20 , 5 );
2014-11-06 07:13:03 +01:00
print '</td>' ;
2015-03-06 20:59:18 +01:00
print '<td class="liste_titre" align="right">' ;
print '<input class="flat" type="text" size="6" name="search_total_ht" value="' . $search_total_ht . '">' ;
print '</td>' ;
2015-07-04 11:57:55 +02:00
print '<td align="right">' ;
$liststatus = array ( '0' => $langs -> trans ( " StatusOrderDraftShort " ), '1' => $langs -> trans ( " StatusOrderValidated " ), '2' => $langs -> trans ( " StatusOrderSentShort " ), '3' => $langs -> trans ( " StatusOrderToBill " ), '4' => $langs -> trans ( " StatusOrderProcessed " ), '-1' => $langs -> trans ( " StatusOrderCanceledShort " ));
2015-09-23 09:24:49 +02:00
print $form -> selectarray ( 'viewstatut' , $liststatus , $viewstatut , - 4 );
2015-07-04 11:57:55 +02:00
print '</td>' ;
2014-11-06 07:13:03 +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 " ;
2012-05-05 19:41:38 +02:00
2012-07-13 10:15:47 +02:00
$var = true ;
$total = 0 ;
$subtotal = 0 ;
2015-01-28 21:27:07 +01:00
$productstat_cache = array ();
2012-07-13 10:15:47 +02:00
2014-10-23 17:48:51 +02:00
$generic_commande = new Commande ( $db );
$generic_product = new Product ( $db );
2015-03-14 14:55:41 +01:00
while ( $i < min ( $num , $limit ))
2015-03-06 20:59:18 +01:00
{
2014-10-23 17:48:51 +02:00
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td class="nowrap">' ;
$generic_commande -> id = $objp -> rowid ;
$generic_commande -> ref = $objp -> ref ;
2015-01-24 15:36:47 +01:00
$generic_commande -> ref_client = $objp -> ref_client ;
$generic_commande -> total_ht = $objp -> total_ht ;
$generic_commande -> total_tva = $objp -> total_tva ;
$generic_commande -> total_ttc = $objp -> total_ttc ;
2014-10-23 17:48:51 +02:00
$generic_commande -> lines = array ();
$generic_commande -> getLinesArray ();
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding nowrap">' ;
print $generic_commande -> getNomUrl ( 1 ,( $viewstatut != 2 ? 0 : $objp -> fk_statut ));
print '</td>' ;
2014-10-24 09:23:39 +02:00
// Shippable Icon
2014-10-25 11:37:39 +02:00
if (( $objp -> fk_statut > 0 ) && ( $objp -> fk_statut < 3 ) && ! empty ( $conf -> global -> SHIPPABLE_ORDER_ICON_IN_LIST )) {
2014-10-24 08:55:30 +02:00
$notshippable = 0 ;
2014-10-23 17:48:51 +02:00
$text_info = '' ;
2014-10-24 09:23:39 +02:00
$nbprod = 0 ;
2014-10-23 17:48:51 +02:00
for ( $lig = 0 ; $lig < ( count ( $generic_commande -> lines )); $lig ++ ) {
if ( $generic_commande -> lines [ $lig ] -> product_type == 0 ) {
2014-10-24 09:23:39 +02:00
$nbprod ++ ; // order contains real products
2014-10-23 17:48:51 +02:00
$generic_product -> id = $generic_commande -> lines [ $lig ] -> fk_product ;
2015-01-28 21:27:07 +01:00
if ( empty ( $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ])) {
2015-03-14 14:55:41 +01:00
$generic_product -> load_stock ();
2015-01-28 21:27:07 +01:00
$productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stock_reel' ] = $generic_product -> stock_reel ;
} else {
$generic_product -> stock_reel = $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stock_reel' ];
}
2014-10-24 08:55:30 +02:00
// stock order and stock order_supplier
$stock_order = 0 ;
$stock_order_supplier = 0 ;
2015-03-01 16:04:34 +01:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SHIPMENT ))
{
if ( ! empty ( $conf -> commande -> enabled ))
{
2015-01-28 21:27:07 +01:00
if ( empty ( $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_customer' ])) {
2015-03-01 16:04:34 +01:00
$generic_product -> load_stats_commande ( 0 , '1,2' );
2015-01-28 21:27:07 +01:00
$productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_customer' ] = $generic_product -> stats_commande [ 'qty' ];
} else {
$generic_product -> stats_commande [ 'qty' ] = $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_customer' ];
}
2014-10-24 08:55:30 +02:00
$stock_order = $generic_product -> stats_commande [ 'qty' ];
}
2015-03-01 16:04:34 +01:00
if ( ! empty ( $conf -> fournisseur -> enabled ))
{
2015-01-28 21:27:07 +01:00
if ( empty ( $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_supplier' ])) {
2015-03-01 16:04:34 +01:00
$generic_product -> load_stats_commande_fournisseur ( 0 , '3' );
2015-01-28 21:27:07 +01:00
$productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_supplier' ] = $generic_product -> stats_commande_fournisseur [ 'qty' ];
} else {
$generic_product -> stats_commande_fournisseur [ 'qty' ] = $productstat_cache [ $generic_commande -> lines [ $lig ] -> fk_product ][ 'stats_order_supplier' ];
}
2014-10-24 08:55:30 +02:00
$stock_order_supplier = $generic_product -> stats_commande_fournisseur [ 'qty' ];
}
}
$text_info .= $generic_commande -> lines [ $lig ] -> qty . ' X ' . $generic_commande -> lines [ $lig ] -> ref . ' ' . dol_trunc ( $generic_commande -> lines [ $lig ] -> product_label , 25 );
$text_stock_reel = $generic_product -> stock_reel . '/' . $stock_order ;
2014-10-23 17:48:51 +02:00
if ( $generic_product -> stock_reel < $generic_commande -> lines [ $lig ] -> qty ) {
2014-10-24 08:55:30 +02:00
$notshippable ++ ;
$text_info .= '<span class="warning">' . $langs -> trans ( 'Available' ) . ' : ' . $text_stock_reel . '</span>' ;
} else {
$text_info .= '<span class="ok">' . $langs -> trans ( 'Available' ) . ' : ' . $text_stock_reel . '</span>' ;
}
if ( $stock_order_supplier > 0 ) {
$text_info .= ' ' . $langs -> trans ( 'SupplierOrder' ) . ' : ' . $stock_order_supplier . '<br>' ;
2014-10-23 17:48:51 +02:00
} else {
2014-10-24 08:55:30 +02:00
$text_info .= '<br>' ;
2014-10-23 17:48:51 +02:00
}
}
}
2014-10-24 08:55:30 +02:00
if ( $notshippable == 0 ) {
2014-10-23 17:48:51 +02:00
$text_icon = img_picto ( '' , 'object_sending' );
$text_info = $langs -> trans ( 'Shippable' ) . '<br>' . $text_info ;
} else {
$text_icon = img_picto ( '' , 'error' );
$text_info = $langs -> trans ( 'NonShippable' ) . '<br>' . $text_info ;
}
2014-10-24 09:23:39 +02:00
if ( $nbprod > 0 ) {
print '<td>' ;
print $form -> textwithtooltip ( '' , $text_info , 2 , 1 , $text_icon , '' , 2 );
print '</td>' ;
}
2014-10-23 17:48:51 +02:00
}
// warning late icon
2013-08-06 19:12:26 +02:00
print '<td style="min-width: 20px" class="nobordernopadding nowrap">' ;
2015-03-23 20:05:31 +01:00
if (( $objp -> fk_statut > 0 ) && ( $objp -> fk_statut < 3 ) && max ( $db -> jdate ( $objp -> date_commande ), $db -> jdate ( $objp -> date_delivery )) < ( $now - $conf -> commande -> client -> warning_delay ))
2013-12-14 15:49:08 +01:00
print img_picto ( $langs -> trans ( " Late " ), " warning " );
2013-08-06 19:12:26 +02:00
if ( ! empty ( $objp -> note_private ))
{
print ' <span class="note">' ;
print '<a href="' . DOL_URL_ROOT . '/commande/note.php?id=' . $objp -> rowid . '">' . img_picto ( $langs -> trans ( " ViewPrivateNote " ), 'object_generic' ) . '</a>' ;
print '</span>' ;
}
2007-07-13 20:00:04 +02:00
print '</td>' ;
2008-10-23 23:54:30 +02:00
2013-04-25 20:27:45 +02:00
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">' ;
2009-04-29 20:02:50 +02:00
$filename = dol_sanitizeFileName ( $objp -> ref );
$filedir = $conf -> commande -> dir_output . '/' . dol_sanitizeFileName ( $objp -> ref );
2007-07-13 20:00:04 +02:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?id=' . $objp -> rowid ;
2012-09-15 09:02:20 +02:00
print $formfile -> getDocumentsLink ( $generic_commande -> element , $filename , $filedir );
2013-04-25 20:27:45 +02:00
print '</td>' ;
print '</tr></table>' ;
2008-10-23 23:54:30 +02:00
2007-07-13 20:00:04 +02:00
print '</td>' ;
2008-10-23 23:54:30 +02:00
2013-10-07 21:58:12 +02:00
// Ref customer
print '<td>' . $objp -> ref_client . '</td>' ;
2009-08-05 20:11:27 +02:00
// Company
$companystatic -> id = $objp -> socid ;
2015-01-31 10:58:03 +01:00
$companystatic -> code_client = $objp -> code_client ;
2014-10-04 17:20:17 +02:00
$companystatic -> name = $objp -> name ;
2009-08-05 20:11:27 +02:00
$companystatic -> client = $objp -> client ;
print '<td>' ;
print $companystatic -> getNomUrl ( 1 , 'customer' );
2012-10-13 17:00:38 +02:00
2012-10-04 18:23:21 +02:00
// If module invoices enabled and user with invoice creation permissions
2013-04-25 20:27:45 +02:00
if ( ! empty ( $conf -> facture -> enabled ) && ! empty ( $conf -> global -> ORDER_BILLING_ALL_CUSTOMER ))
2012-10-08 20:47:10 +02:00
{
if ( $user -> rights -> facture -> creer )
2012-10-04 18:23:21 +02:00
{
if (( $objp -> fk_statut > 0 && $objp -> fk_statut < 3 ) || ( $objp -> fk_statut == 3 && $objp -> facturee == 0 ))
{
2013-04-25 20:27:45 +02:00
print ' <a href="' . DOL_URL_ROOT . '/commande/orderstoinvoice.php?socid=' . $companystatic -> id . '">' ;
2014-10-04 17:20:17 +02:00
print img_picto ( $langs -> trans ( " CreateInvoiceForThisCustomer " ) . ' : ' . $companystatic -> name , 'object_bill' , 'hideonsmartphone' ) . '</a>' ;
2012-10-04 18:23:21 +02:00
}
}
}
2009-08-05 20:11:27 +02:00
print '</td>' ;
2009-04-29 20:02:50 +02:00
2010-10-06 10:01:41 +02:00
// Order date
2014-11-06 07:13:03 +01:00
print '<td align="center">' ;
2014-03-06 17:02:27 +01:00
print dol_print_date ( $db -> jdate ( $objp -> date_commande ), 'day' );
2010-10-06 10:01:41 +02:00
print '</td>' ;
2010-11-13 18:37:22 +01:00
2010-10-06 10:01:41 +02:00
// Delivery date
2014-11-06 07:13:03 +01:00
print '<td align="center">' ;
2014-03-06 17:02:27 +01:00
print dol_print_date ( $db -> jdate ( $objp -> date_delivery ), 'day' );
2006-05-17 21:17:26 +02:00
print '</td>' ;
2010-11-13 18:37:22 +01:00
2013-01-03 11:06:05 +01:00
// Amount HT
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . price ( $objp -> total_ht ) . '</td>' ;
2013-01-03 11:06:05 +01:00
2010-10-06 10:01:41 +02:00
// Statut
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . $generic_commande -> LibStatut ( $objp -> fk_statut , $objp -> facturee , 5 ) . '</td>' ;
2010-11-13 18:37:22 +01:00
2015-06-30 13:14:19 +02:00
print '<td></td>' ;
2005-09-15 02:37:03 +02:00
print '</tr>' ;
2010-11-13 18:37:22 +01:00
2012-07-13 10:15:47 +02:00
$total += $objp -> total_ht ;
$subtotal += $objp -> total_ht ;
2005-09-15 02:37:03 +02:00
$i ++ ;
2003-11-09 18:52:17 +01:00
}
2013-01-03 20:42:26 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_TOTAL_FOR_LIMITED_LIST ))
{
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" colspan="5">' . $langs -> trans ( 'TotalHT' ) . '</td>' ;
2013-01-03 20:42:26 +01:00
// Total HT
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . price ( $total ) . '</td>' ;
2015-06-30 13:14:19 +02:00
print '<td></td>' ;
print '<td></td>' ;
2013-01-03 20:42:26 +01:00
print '</tr>' ;
}
2005-09-15 02:37:03 +02:00
print '</table>' ;
2012-05-05 19:41:38 +02:00
2014-02-25 16:13:23 +01:00
print '</form>' . " \n " ;
2012-05-05 19:41:38 +02:00
2014-02-25 16:13:23 +01:00
print '<br>' . img_help ( 1 , '' ) . ' ' . $langs -> trans ( " ToBillSeveralOrderSelectCustomer " , $langs -> transnoentitiesnoconv ( " CreateInvoiceForThisCustomer " )) . '<br>' ;
2014-09-28 03:41:32 +02:00
2005-09-15 02:37:03 +02:00
$db -> free ( $resql );
2005-02-06 19:45:24 +01:00
}
else
{
2015-02-10 13:17:37 +01:00
dol_print_error ( $db );
2005-02-06 19:45:24 +01:00
}
2003-11-09 18:52:17 +01:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-05-05 19:41:38 +02:00
$db -> close ();