2004-10-20 22:06:49 +02:00
< ? php
2015-07-16 05:06:46 +02:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2014 Regis Houssin < regis . houssin @ inodbox . com >
2016-06-09 18:48:36 +02:00
* Copyright ( C ) 2014 - 2016 Charlie BENKE < charlie @ patas - monkey . com >
2015-07-16 05:06:46 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2019-02-24 11:18:55 +01:00
* Copyright ( C ) 2019 Pierre Ardoin < mapiolca @ me . com >
2021-02-23 00:14:11 +01:00
* Copyright ( C ) 2019 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2019-06-18 14:07:52 +02:00
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
2002-04-30 12:57:25 +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-04-30 12:57:25 +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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2002-04-30 12:57:25 +02:00
*/
2004-10-23 01:34:25 +02:00
2005-04-14 22:10:15 +02:00
/**
2019-02-24 11:18:55 +01:00
* \file htdocs / product / index . php
2008-09-11 01:28:23 +02:00
* \ingroup product
2014-04-08 14:05:10 +02:00
* \brief Homepage products and services
2008-09-11 01:28:23 +02:00
*/
2004-10-23 01:34:25 +02: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 . '/product/class/product.class.php' ;
2013-09-03 17:37:22 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2015-03-14 16:50:02 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2004-08-13 00:16:46 +02:00
2019-11-12 00:15:34 +01:00
$type = GETPOST ( " type " , 'int' );
2021-09-02 19:17:38 +02:00
if ( $type == '' && empty ( $user -> rights -> produit -> lire )) {
2021-02-26 14:25:17 +01:00
$type = '1' ; // Force global page on service page only
}
2021-09-02 18:48:46 +02:00
if ( $type == '' && empty ( $user -> rights -> service -> lire )) {
2021-02-26 14:25:17 +01:00
$type = '0' ; // Force global page on product page only
}
2010-02-27 18:30:17 +01:00
2021-04-01 11:01:07 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'products' , 'stocks' ));
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
$hookmanager -> initHooks ( array ( 'productindex' ));
$product_static = new Product ( $db );
2010-02-27 18:30:17 +01:00
// Security check
2021-02-26 14:25:17 +01:00
if ( $type == '0' ) {
$result = restrictedArea ( $user , 'produit' );
} elseif ( $type == '1' ) {
$result = restrictedArea ( $user , 'service' );
} else {
$result = restrictedArea ( $user , 'produit|service|expedition' );
}
2003-08-06 14:28:02 +02:00
2009-03-09 22:59:29 +01:00
2003-08-06 14:07:24 +02:00
/*
2009-03-09 22:59:29 +01:00
* View
2003-08-06 14:07:24 +02:00
*/
2002-04-30 12:57:25 +02:00
2007-12-05 13:08:53 +01:00
$transAreaType = $langs -> trans ( " ProductsAndServicesArea " );
2016-07-28 12:17:00 +02:00
2019-11-12 00:15:34 +01:00
$helpurl = '' ;
2021-02-26 14:25:17 +01:00
if ( ! isset ( $_GET [ " type " ])) {
2012-07-27 21:27:03 +02:00
$transAreaType = $langs -> trans ( " ProductsAndServicesArea " );
2019-11-12 00:15:34 +01:00
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos' ;
2009-08-12 15:07:49 +02:00
}
2021-02-26 14:25:17 +01:00
if (( isset ( $_GET [ " type " ]) && $_GET [ " type " ] == 0 ) || empty ( $conf -> service -> enabled )) {
2009-08-24 14:21:46 +02:00
$transAreaType = $langs -> trans ( " ProductsArea " );
2019-11-12 00:15:34 +01:00
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos' ;
2009-08-24 14:21:46 +02:00
}
2021-02-26 14:25:17 +01:00
if (( isset ( $_GET [ " type " ]) && $_GET [ " type " ] == 1 ) || empty ( $conf -> product -> enabled )) {
2009-08-12 15:07:49 +02:00
$transAreaType = $langs -> trans ( " ServicesArea " );
2019-11-12 00:15:34 +01:00
$helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios' ;
2009-08-12 15:07:49 +02:00
}
2007-12-05 13:08:53 +01:00
2016-07-28 12:17:00 +02:00
llxHeader ( " " , $langs -> trans ( " ProductsAndServices " ), $helpurl );
2002-04-30 12:57:25 +02:00
2019-11-12 00:15:34 +01:00
$linkback = " " ;
2020-04-12 21:36:57 +02:00
print load_fiche_titre ( $transAreaType , $linkback , 'product' );
2003-08-12 15:56:44 +02:00
2013-03-30 14:27:13 +01:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2013-03-16 14:53:15 +01:00
2003-08-06 14:07:24 +02:00
2021-04-13 15:58:13 +02:00
if ( ! empty ( $conf -> global -> MAIN_SEARCH_FORM_ON_HOME_AREAS )) { // This may be useless due to the global search combo
2020-10-31 14:32:18 +01:00
// Search contract
2021-02-26 14:25:17 +01:00
if (( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) && ( $user -> rights -> produit -> lire || $user -> rights -> service -> lire )) {
2020-10-31 14:32:18 +01:00
$listofsearchfields [ 'search_product' ] = array ( 'text' => 'ProductOrService' );
}
2021-02-26 14:25:17 +01:00
if ( count ( $listofsearchfields )) {
2020-10-31 14:32:18 +01:00
print '<form method="post" action="' . DOL_URL_ROOT . '/core/search.php">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder nohover centpercent">' ;
$i = 0 ;
2021-02-26 14:25:17 +01:00
foreach ( $listofsearchfields as $key => $value ) {
if ( $i == 0 ) {
print '<tr class="liste_titre"><td colspan="3">' . $langs -> trans ( " Search " ) . '</td></tr>' ;
}
2020-10-31 14:32:18 +01:00
print '<tr class="oddeven">' ;
2021-07-07 01:24:40 +02:00
print '<td class="nowrap"><label for="' . $key . '">' . $langs -> trans ( $value [ " text " ]) . '</label></td>' ;
print '<td><input type="text" class="flat inputsearch" name="' . $key . '" id="' . $key . '" size="18"></td>' ;
2021-02-26 14:25:17 +01:00
if ( $i == 0 ) {
print '<td rowspan="' . count ( $listofsearchfields ) . '"><input type="submit" value="' . $langs -> trans ( " Search " ) . '" class="button"></td>' ;
}
2020-10-31 14:32:18 +01:00
print '</tr>' ;
$i ++ ;
}
print '</table>' ;
print '</div>' ;
print '</form>' ;
print '<br>' ;
}
2009-03-09 22:59:29 +01:00
}
2005-02-01 17:57:45 +01:00
2003-10-14 17:30:39 +02:00
/*
2014-04-08 14:05:10 +02:00
* Number of products and / or services
2003-10-14 17:30:39 +02:00
*/
2021-02-26 14:25:17 +01:00
if (( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) && ( $user -> rights -> produit -> lire || $user -> rights -> service -> lire )) {
2020-01-31 18:16:16 +01:00
$prodser = array ();
$prodser [ 0 ][ 0 ] = $prodser [ 0 ][ 1 ] = $prodser [ 0 ][ 2 ] = $prodser [ 0 ][ 3 ] = 0 ;
2021-03-14 09:56:45 +01:00
$prodser [ 0 ][ 'sell' ] = 0 ;
$prodser [ 0 ][ 'buy' ] = 0 ;
$prodser [ 0 ][ 'none' ] = 0 ;
2020-01-31 18:16:16 +01:00
$prodser [ 1 ][ 0 ] = $prodser [ 1 ][ 1 ] = $prodser [ 1 ][ 2 ] = $prodser [ 1 ][ 3 ] = 0 ;
2021-03-14 09:56:45 +01:00
$prodser [ 1 ][ 'sell' ] = 0 ;
$prodser [ 1 ][ 'buy' ] = 0 ;
$prodser [ 1 ][ 'none' ] = 0 ;
2020-01-31 18:16:16 +01:00
$sql = " SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= ' WHERE p.entity IN (' . getEntity ( $product_static -> element , 1 ) . ')' ;
// Add where from hooks
$parameters = array ();
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $product_static ); // Note that $action and $object may have been modified by hook
2020-01-31 18:16:16 +01:00
$sql .= $hookmanager -> resPrint ;
$sql .= " GROUP BY p.fk_product_type, p.tosell, p.tobuy " ;
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
while ( $objp = $db -> fetch_object ( $result )) {
2020-01-31 18:16:16 +01:00
$status = 3 ; // On sale + On purchase
2021-02-26 14:25:17 +01:00
if ( ! $objp -> tosell && ! $objp -> tobuy ) {
$status = 0 ; // Not on sale, not on purchase
}
if ( $objp -> tosell && ! $objp -> tobuy ) {
$status = 1 ; // On sale only
}
if ( ! $objp -> tosell && $objp -> tobuy ) {
$status = 2 ; // On purchase only
}
2020-01-31 18:16:16 +01:00
$prodser [ $objp -> fk_product_type ][ $status ] = $objp -> total ;
2021-02-26 14:25:17 +01:00
if ( $objp -> tosell ) {
$prodser [ $objp -> fk_product_type ][ 'sell' ] += $objp -> total ;
}
if ( $objp -> tobuy ) {
$prodser [ $objp -> fk_product_type ][ 'buy' ] += $objp -> total ;
}
if ( ! $objp -> tosell && ! $objp -> tobuy ) {
$prodser [ $objp -> fk_product_type ][ 'none' ] += $objp -> total ;
}
2019-08-30 04:17:07 +02:00
}
2020-01-31 18:16:16 +01:00
2021-02-26 14:25:17 +01:00
if ( $conf -> use_javascript_ajax ) {
2020-01-31 18:16:16 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
2020-03-05 00:17:16 +01:00
print '<tr class="liste_titre"><th>' . $langs -> trans ( " Statistics " ) . '</th></tr>' ;
print '<tr><td class="center nopaddingleftimp nopaddingrightimp">' ;
2020-01-31 18:16:16 +01:00
$SommeA = $prodser [ 0 ][ 'sell' ];
$SommeB = $prodser [ 0 ][ 'buy' ];
$SommeC = $prodser [ 0 ][ 'none' ];
$SommeD = $prodser [ 1 ][ 'sell' ];
$SommeE = $prodser [ 1 ][ 'buy' ];
$SommeF = $prodser [ 1 ][ 'none' ];
$total = 0 ;
$dataval = array ();
$datalabels = array ();
$i = 0 ;
2019-08-30 04:15:24 +02:00
2020-01-31 18:16:16 +01:00
$total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF ;
$dataseries = array ();
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> product -> enabled )) {
2020-06-26 20:35:06 +02:00
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ProductsOnSale " ), round ( $SommeA ));
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ProductsOnPurchase " ), round ( $SommeB ));
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ProductsNotOnSell " ), round ( $SommeC ));
2020-01-31 18:16:16 +01:00
}
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> service -> enabled )) {
2020-06-26 20:35:06 +02:00
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ServicesOnSale " ), round ( $SommeD ));
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ServicesOnPurchase " ), round ( $SommeE ));
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " ServicesNotOnSell " ), round ( $SommeF ));
2020-01-31 18:16:16 +01:00
}
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php' ;
$dolgraph = new DolGraph ();
$dolgraph -> SetData ( $dataseries );
2020-03-05 17:23:19 +01:00
$dolgraph -> setShowLegend ( 2 );
2020-01-31 18:16:16 +01:00
$dolgraph -> setShowPercent ( 0 );
2020-03-05 17:23:19 +01:00
$dolgraph -> SetType ( array ( 'pie' ));
2020-03-05 02:55:06 +01:00
$dolgraph -> setHeight ( '200' );
2020-01-31 18:16:16 +01:00
$dolgraph -> draw ( 'idgraphstatus' );
print $dolgraph -> show ( $total ? 0 : 1 );
print '</td></tr>' ;
print '</table>' ;
print '</div>' ;
}
2007-12-05 13:08:53 +01:00
}
2019-08-30 04:15:24 +02:00
2004-05-08 16:31:02 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $conf -> global -> CATEGORY_GRAPHSTATS_ON_PRODUCTS )) {
2014-05-04 18:42:00 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
print '<br>' ;
2017-10-19 19:53:29 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2014-05-04 18:42:00 +02:00
print '<tr class="liste_titre"><th colspan="2">' . $langs -> trans ( " Categories " ) . '</th></tr>' ;
2021-02-23 00:14:11 +01:00
print '<tr><td class="center" colspan="2">' ;
2014-05-04 18:42:00 +02:00
$sql = " SELECT c.label, count(*) as nb " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " categorie_product as cs " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " categorie as c ON cs.fk_categorie = c.rowid " ;
$sql .= " WHERE c.type = 0 " ;
$sql .= " AND c.entity IN ( " . getEntity ( 'category' ) . " ) " ;
$sql .= " GROUP BY c.label " ;
2021-12-22 10:32:50 +01:00
$sql .= " ORDER BY nb desc " ;
2019-11-12 00:15:34 +01:00
$total = 0 ;
2014-05-04 18:42:00 +02:00
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $result ) {
2014-05-04 18:42:00 +02:00
$num = $db -> num_rows ( $result );
2019-11-12 00:15:34 +01:00
$i = 0 ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2019-11-12 00:15:34 +01:00
$dataseries = array ();
$rest = 0 ;
$nbmax = 10 ;
2021-02-26 14:25:17 +01:00
while ( $i < $num ) {
2014-05-04 18:42:00 +02:00
$obj = $db -> fetch_object ( $result );
2021-02-26 14:25:17 +01:00
if ( $i < $nbmax ) {
2019-11-12 00:15:34 +01:00
$dataseries [] = array ( $obj -> label , round ( $obj -> nb ));
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$rest += $obj -> nb ;
2017-11-23 20:00:54 +01:00
}
2019-11-12 00:15:34 +01:00
$total += $obj -> nb ;
2014-05-04 18:42:00 +02:00
$i ++ ;
}
2021-02-26 14:25:17 +01:00
if ( $i > $nbmax ) {
2019-11-12 00:15:34 +01:00
$dataseries [] = array ( $langs -> trans ( " Other " ), round ( $rest ));
2017-11-23 20:00:54 +01:00
}
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php' ;
$dolgraph = new DolGraph ();
$dolgraph -> SetData ( $dataseries );
2020-03-05 17:23:19 +01:00
$dolgraph -> setShowLegend ( 2 );
2017-11-23 20:00:54 +01:00
$dolgraph -> setShowPercent ( 1 );
$dolgraph -> SetType ( array ( 'pie' ));
2020-03-05 17:23:19 +01:00
$dolgraph -> setHeight ( '200' );
2017-11-23 20:00:54 +01:00
$dolgraph -> draw ( 'idstatscategproduct' );
2019-11-12 00:15:34 +01:00
print $dolgraph -> show ( $total ? 0 : 1 );
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 14:25:17 +01:00
while ( $i < $num ) {
2014-05-04 18:42:00 +02:00
$obj = $db -> fetch_object ( $result );
2017-06-09 10:38:06 +02:00
2017-11-23 20:00:54 +01:00
print '<tr><td>' . $obj -> label . '</td><td>' . $obj -> nb . '</td></tr>' ;
2019-11-12 00:15:34 +01:00
$total += $obj -> nb ;
2014-05-04 18:42:00 +02:00
$i ++ ;
}
}
}
print '</td></tr>' ;
2019-02-24 11:18:55 +01:00
print '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td><td class="right">' ;
2014-05-04 18:42:00 +02:00
print $total ;
print '</td></tr>' ;
print '</table>' ;
2017-10-19 19:53:29 +02:00
print '</div>' ;
2014-05-04 18:42:00 +02:00
}
2021-10-24 00:37:37 +02:00
print '</div><div class="fichetwothirdright">' ;
2013-03-16 14:53:15 +01:00
2004-05-08 16:31:02 +02:00
2003-10-14 17:30:39 +02:00
/*
2019-11-01 12:52:03 +01:00
* Latest modified products
2003-10-14 17:30:39 +02:00
*/
2021-02-26 14:25:17 +01:00
if (( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) && ( $user -> rights -> produit -> lire || $user -> rights -> service -> lire )) {
2020-01-31 18:16:16 +01:00
$max = 15 ;
$sql = " SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression, " ;
$sql .= " p.entity, " ;
$sql .= " p.tms as datem " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( $product_static -> element , 1 ) . " ) " ;
2021-02-26 14:25:17 +01:00
if ( $type != '' ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.fk_product_type = " . (( int ) $type );
2021-02-26 14:25:17 +01:00
}
2020-01-31 18:16:16 +01:00
// Add where from hooks
$parameters = array ();
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $product_static ); // Note that $action and $object may have been modified by hook
2020-01-31 18:16:16 +01:00
$sql .= $hookmanager -> resPrint ;
$sql .= $db -> order ( " p.tms " , " DESC " );
$sql .= $db -> plimit ( $max , 0 );
//print $sql;
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $result ) {
2020-01-31 18:16:16 +01:00
$num = $db -> num_rows ( $result );
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
$i = 0 ;
2009-01-21 15:09:42 +01:00
2021-02-26 14:25:17 +01:00
if ( $num > 0 ) {
2020-01-31 18:16:16 +01:00
$transRecordedType = $langs -> trans ( " LastModifiedProductsAndServices " , $max );
2021-02-26 14:25:17 +01:00
if ( isset ( $_GET [ " type " ]) && $_GET [ " type " ] == 0 ) {
$transRecordedType = $langs -> trans ( " LastRecordedProducts " , $max );
}
if ( isset ( $_GET [ " type " ]) && $_GET [ " type " ] == 1 ) {
$transRecordedType = $langs -> trans ( " LastRecordedServices " , $max );
}
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder centpercent">' ;
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
$colnb = 2 ;
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
$colnb ++ ;
}
2012-04-05 21:15:09 +02:00
2020-01-31 18:16:16 +01:00
print '<tr class="liste_titre"><th colspan="' . $colnb . '">' . $transRecordedType . '</th>' ;
print '<th class="right" colspan="3"><a href="' . DOL_URL_ROOT . '/product/list.php?sortfield=p.tms&sortorder=DESC">' . $langs -> trans ( " FullList " ) . '</td>' ;
print '</tr>' ;
2009-01-21 15:09:42 +01:00
2021-02-26 14:25:17 +01:00
while ( $i < $num ) {
2020-01-31 18:16:16 +01:00
$objp = $db -> fetch_object ( $result );
$product_static -> id = $objp -> rowid ;
$product_static -> ref = $objp -> ref ;
$product_static -> label = $objp -> label ;
$product_static -> type = $objp -> fk_product_type ;
$product_static -> entity = $objp -> entity ;
$product_static -> status = $objp -> tosell ;
$product_static -> status_buy = $objp -> tobuy ;
$product_static -> status_batch = $objp -> tobatch ;
2021-07-07 01:24:40 +02:00
// Multilangs
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2020-01-31 18:16:16 +01:00
$sql = " SELECT label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product_lang " ;
2022-01-06 18:12:02 +01:00
$sql .= " WHERE fk_product = " . (( int ) $objp -> rowid );
$sql .= " AND lang = ' " . $db -> escape ( $langs -> getDefaultLang ()) . " ' " ;
2020-01-31 18:16:16 +01:00
$resultd = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resultd ) {
2020-01-31 18:16:16 +01:00
$objtp = $db -> fetch_object ( $resultd );
2021-02-26 14:25:17 +01:00
if ( $objtp && $objtp -> label != '' ) {
$objp -> label = $objtp -> label ;
}
2020-01-31 18:16:16 +01:00
}
2010-02-28 19:37:29 +01:00
}
2017-06-09 10:38:06 +02:00
2020-01-31 18:16:16 +01:00
print '<tr class="oddeven">' ;
2021-06-30 01:36:49 +02:00
print '<td class="nowraponall tdoverflowmax100">' ;
2020-01-31 18:16:16 +01:00
print $product_static -> getNomUrl ( 1 , '' , 16 );
print " </td> \n " ;
2021-06-30 01:36:49 +02:00
print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag ( $objp -> label ) . '">' . dol_escape_htmltag ( $objp -> label ) . '</td>' ;
2022-05-19 12:16:18 +02:00
print '<td title="' . dol_escape_htmltag ( $langs -> trans ( " DateModification " ) . ': ' . dol_print_date ( $db -> jdate ( $objp -> datem ), 'dayhour' , 'tzuserrel' )) . '">' ;
print dol_print_date ( $db -> jdate ( $objp -> datem ), 'day' , 'tzuserrel' );
2020-01-31 18:16:16 +01:00
print " </td> " ;
// Sell price
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
if ( ! empty ( $conf -> dynamicprices -> enabled ) && ! empty ( $objp -> fk_price_expression )) {
2020-10-31 14:32:18 +01:00
$product = new Product ( $db );
$product -> fetch ( $objp -> rowid );
$priceparser = new PriceParser ( $db );
$price_result = $priceparser -> parseProduct ( $product );
if ( $price_result >= 0 ) {
$objp -> price = $price_result ;
}
}
2021-07-07 01:24:40 +02:00
print '<td class="nowraponall amount right">' ;
2021-02-26 14:25:17 +01:00
if ( isset ( $objp -> price_base_type ) && $objp -> price_base_type == 'TTC' ) {
print price ( $objp -> price_ttc ) . ' ' . $langs -> trans ( " TTC " );
} else {
print price ( $objp -> price ) . ' ' . $langs -> trans ( " HT " );
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
2020-01-31 18:16:16 +01:00
}
print '<td class="right nowrap width25"><span class="statusrefsell">' ;
print $product_static -> LibStatut ( $objp -> tosell , 3 , 0 );
print " </span></td> " ;
2020-10-31 14:32:18 +01:00
print '<td class="right nowrap width25"><span class="statusrefbuy">' ;
print $product_static -> LibStatut ( $objp -> tobuy , 3 , 1 );
print " </span></td> " ;
2020-01-31 18:16:16 +01:00
print " </tr> \n " ;
$i ++ ;
2012-04-05 13:01:15 +02:00
}
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
$db -> free ( $result );
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
print " </table> " ;
print '</div>' ;
print '<br>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-01-31 18:16:16 +01:00
dol_print_error ( $db );
2006-12-11 23:43:40 +01:00
}
2003-07-12 12:32:11 +02:00
}
2013-08-06 21:31:32 +02:00
2013-10-10 17:34:26 +02:00
// TODO Move this into a page that should be available into menu "accountancy - report - turnover - per quarter"
2014-03-05 11:37:32 +01:00
// Also method used for counting must provide the 2 possible methods like done by all other reports into menu "accountancy - report - turnover":
2013-10-10 17:34:26 +02:00
// "commitment engagment" method and "cash accounting" method
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_PRODUCT_ACTIVITY_TRIM )) {
if ( ! empty ( $conf -> product -> enabled )) {
activitytrim ( 0 );
}
if ( ! empty ( $conf -> service -> enabled )) {
activitytrim ( 1 );
}
2013-10-10 17:34:26 +02:00
}
2013-08-06 21:31:32 +02:00
2021-10-24 00:37:37 +02:00
print '</div></div>' ;
2002-05-04 23:28:42 +02:00
2019-06-18 14:07:52 +02:00
$parameters = array ( 'type' => $type , 'user' => $user );
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'dashboardProductsServices' , $parameters , $product_static ); // Note that $action and $object may have been modified by hook
2019-06-18 14:07:52 +02:00
2018-08-15 12:48:13 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-04-05 21:15:09 +02:00
$db -> close ();
2013-08-06 21:31:32 +02:00
2013-10-10 17:34:26 +02:00
2020-05-03 22:47:43 +02:00
/**
2015-01-06 17:54:36 +01:00
* Print html activity for product type
*
* @ param int $product_type Type of product
* @ return void
*/
2013-08-06 21:31:32 +02:00
function activitytrim ( $product_type )
{
2019-11-12 00:15:34 +01:00
global $conf , $langs , $db ;
2014-03-05 11:37:32 +01:00
2014-04-12 00:53:25 +02:00
// We display the last 3 years
2019-11-12 00:15:34 +01:00
$yearofbegindate = date ( 'Y' , dol_time_plus_duree ( time (), - 3 , " y " ));
2013-08-06 21:31:32 +02:00
2014-04-08 14:05:10 +02:00
// breakdown by quarter
2013-10-10 17:34:26 +02:00
$sql = " SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f, " . MAIN_DB_PREFIX . " facturedet as fd " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement as p, " . MAIN_DB_PREFIX . " paiement_facture as pf " ;
$sql .= " WHERE f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
$sql .= " AND f.rowid = fd.fk_facture " ;
$sql .= " AND pf.fk_facture = f.rowid " ;
2021-06-09 15:36:47 +02:00
$sql .= " AND pf.fk_paiement = p.rowid " ;
$sql .= " AND fd.product_type = " . (( int ) $product_type );
2019-11-12 00:15:34 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( dol_get_first_day ( $yearofbegindate ), 1 ) . " ' " ;
$sql .= " GROUP BY annee, mois " ;
$sql .= " ORDER BY annee, mois " ;
2013-08-06 21:31:32 +02:00
$result = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $result ) {
2019-11-12 00:15:34 +01:00
$tmpyear = 0 ;
$trim1 = 0 ;
$trim2 = 0 ;
$trim3 = 0 ;
$trim4 = 0 ;
2013-08-06 21:31:32 +02:00
$lgn = 0 ;
$num = $db -> num_rows ( $result );
2014-03-05 11:37:32 +01:00
2021-02-26 14:25:17 +01:00
if ( $num > 0 ) {
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive-no-min">' ;
2013-08-06 21:31:32 +02:00
print '<table class="noborder" width="75%">' ;
2021-02-26 14:25:17 +01:00
if ( $product_type == 0 ) {
2019-02-24 11:18:55 +01:00
print '<tr class="liste_titre"><td class=left>' . $langs -> trans ( " ProductSellByQuarterHT " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
} else {
print '<tr class="liste_titre"><td class=left>' . $langs -> trans ( " ServiceSellByQuarterHT " ) . '</td>' ;
}
2019-02-24 11:18:55 +01:00
print '<td class=right>' . $langs -> trans ( " Quarter1 " ) . '</td>' ;
print '<td class=right>' . $langs -> trans ( " Quarter2 " ) . '</td>' ;
print '<td class=right>' . $langs -> trans ( " Quarter3 " ) . '</td>' ;
print '<td class=right>' . $langs -> trans ( " Quarter4 " ) . '</td>' ;
print '<td class=right>' . $langs -> trans ( " Total " ) . '</td>' ;
2013-08-06 21:31:32 +02:00
print '</tr>' ;
}
$i = 0 ;
2021-02-26 14:25:17 +01:00
while ( $i < $num ) {
2013-08-06 21:31:32 +02:00
$objp = $db -> fetch_object ( $result );
2021-02-26 14:25:17 +01:00
if ( $tmpyear != $objp -> annee ) {
if ( $trim1 + $trim2 + $trim3 + $trim4 > 0 ) {
2019-02-24 11:18:55 +01:00
print '<tr class="oddeven"><td class=left>' . $tmpyear . '</td>' ;
2019-07-24 10:42:00 +02:00
print '<td class="nowrap right">' . price ( $trim1 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim2 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim3 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim4 ) . '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="nowrap right">' . price ( $trim1 + $trim2 + $trim3 + $trim4 ) . '</td>' ;
2013-08-06 21:31:32 +02:00
print '</tr>' ;
$lgn ++ ;
}
2014-04-08 14:05:10 +02:00
// We go to the following year
2013-08-06 21:31:32 +02:00
$tmpyear = $objp -> annee ;
2019-11-12 00:15:34 +01:00
$trim1 = 0 ;
$trim2 = 0 ;
$trim3 = 0 ;
$trim4 = 0 ;
2013-08-06 21:31:32 +02:00
}
2014-03-05 11:37:32 +01:00
2021-02-26 14:25:17 +01:00
if ( $objp -> mois == " 01 " || $objp -> mois == " 02 " || $objp -> mois == " 03 " ) {
2013-08-06 21:31:32 +02:00
$trim1 += $objp -> Mnttot ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
2021-02-26 14:25:17 +01:00
if ( $objp -> mois == " 04 " || $objp -> mois == " 05 " || $objp -> mois == " 06 " ) {
2013-08-06 21:31:32 +02:00
$trim2 += $objp -> Mnttot ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
2021-02-26 14:25:17 +01:00
if ( $objp -> mois == " 07 " || $objp -> mois == " 08 " || $objp -> mois == " 09 " ) {
2013-08-06 21:31:32 +02:00
$trim3 += $objp -> Mnttot ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
2021-02-26 14:25:17 +01:00
if ( $objp -> mois == " 10 " || $objp -> mois == " 11 " || $objp -> mois == " 12 " ) {
2013-08-06 21:31:32 +02:00
$trim4 += $objp -> Mnttot ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
$i ++ ;
}
2021-02-26 14:25:17 +01:00
if ( $trim1 + $trim2 + $trim3 + $trim4 > 0 ) {
2019-02-24 11:18:55 +01:00
print '<tr class="oddeven"><td class=left>' . $tmpyear . '</td>' ;
2019-07-24 10:42:00 +02:00
print '<td class="nowrap right">' . price ( $trim1 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim2 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim3 ) . '</td>' ;
print '<td class="nowrap right">' . price ( $trim4 ) . '</td>' ;
2019-11-12 00:15:34 +01:00
print '<td class="nowrap right">' . price ( $trim1 + $trim2 + $trim3 + $trim4 ) . '</td>' ;
2013-08-06 21:31:32 +02:00
print '</tr>' ;
}
2021-02-26 14:25:17 +01:00
if ( $num > 0 ) {
2019-07-24 10:42:00 +02:00
print '</table></div>' ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
}
}