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 >
2024-03-27 10:46:04 +01:00
* Copyright ( C ) 2019 - 2024 Frédéric France < frederic . france @ free . fr >
2019-06-18 14:07:52 +02:00
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
2025-02-08 21:53:48 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . 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
2022-08-29 18:47:35 +02:00
// Load Dolibarr environment
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' ;
2024-03-27 10:46:04 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.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
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2024-03-08 19:43:57 +01:00
$type = GETPOST ( " type " , 'intcomma' );
2023-04-18 14:04:27 +02:00
if ( $type == '' && ! $user -> hasRight ( 'produit' , 'lire' ) && $user -> hasRight ( 'service' , 'lire' )) {
2021-02-26 14:25:17 +01:00
$type = '1' ; // Force global page on service page only
}
2023-04-18 14:04:27 +02:00
if ( $type == '' && ! $user -> hasRight ( 'service' , 'lire' ) && $user -> hasRight ( 'produit' , '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' ));
2024-06-30 21:02:50 +02:00
// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
2021-04-01 11:01:07 +02:00
$hookmanager -> initHooks ( array ( 'productindex' ));
2022-08-29 18:47:35 +02:00
// Initialize objects
2021-04-01 11:01:07 +02:00
$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 {
2023-04-18 14:04:27 +02:00
$result = restrictedArea ( $user , 'produit|service|expedition|reception' );
2021-02-26 14:25:17 +01:00
}
2003-08-06 14:28:02 +02:00
2024-03-27 10:46:04 +01:00
// Load $resultboxes
$resultboxes = FormOther :: getBoxesArea ( $user , " 4 " );
if ( GETPOST ( 'addbox' )) {
// Add box (when submit is done from a form when ajax disabled)
require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php' ;
2024-10-23 23:28:38 +02:00
$zone = GETPOSTINT ( 'areacode' );
$userid = GETPOSTINT ( 'userid' );
2024-03-27 10:46:04 +01:00
$boxorder = GETPOST ( 'boxorder' , 'aZ09' );
$boxorder .= GETPOST ( 'boxcombo' , 'aZ09' );
$result = InfoBox :: saveboxorder ( $db , $zone , $boxorder , $userid );
if ( $result > 0 ) {
setEventMessages ( $langs -> trans ( " BoxAdded " ), null );
}
}
2024-04-03 15:30:10 +02:00
$max = getDolGlobalInt ( 'MAIN_SIZE_SHORTLIST_LIMIT' , 5 );
2024-04-01 13:08:35 +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
2024-04-01 13:33:15 +02:00
$producttmp = new Product ( $db );
$warehouse = new Entrepot ( $db );
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 = '' ;
2024-03-08 19:47:05 +01:00
if ( ! GETPOSTISSET ( " 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
}
2024-03-08 19:47:05 +01:00
if (( GETPOSTISSET ( " type " ) && GETPOST ( " type " ) == '0' ) || ! isModEnabled ( " service " )) {
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
}
2024-03-08 19:47:05 +01:00
if (( GETPOSTISSET ( " type " ) && GETPOST ( " type " ) == '1' ) || ! isModEnabled ( " product " )) {
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
2024-06-07 17:48:51 +02:00
llxHeader ( " " , $langs -> trans ( " ProductsAndServices " ), $helpurl , '' , 0 , 0 , '' , '' , '' , 'mod-product page-index' );
2002-04-30 12:57:25 +02:00
2024-03-27 10:46:04 +01:00
print load_fiche_titre ( $transAreaType , $resultboxes [ 'selectboxlist' ], 'product' );
2013-03-16 14:53:15 +01:00
2003-08-06 14:07:24 +02:00
2023-11-27 11:56:32 +01:00
if ( getDolGlobalString ( 'MAIN_SEARCH_FORM_ON_HOME_AREAS' )) { // This may be useless due to the global search combo
2025-02-08 21:53:48 +01:00
if ( ! isset ( $listofsearchfields ) || ! is_array ( $listofsearchfields )) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset
2024-03-09 16:32:02 +01:00
// Ensure $listofsearchfields is set and array
$listofsearchfields = array ();
}
2020-10-31 14:32:18 +01:00
// Search contract
2023-06-19 23:05:59 +02:00
if (( isModEnabled ( " product " ) || isModEnabled ( " service " )) && ( $user -> hasRight ( 'produit' , 'lire' ) || $user -> hasRight ( 'service' , 'lire' ))) {
2024-03-09 16:32:02 +01:00
$listofsearchfields [ 'search_product' ] = array ( 'text' => 'ProductOrService' );
2020-10-31 14:32:18 +01:00
}
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
*/
2024-03-27 10:46:04 +01:00
$graph = '' ;
2022-10-28 15:48:46 +02:00
if (( isModEnabled ( " product " ) || isModEnabled ( " service " )) && ( $user -> hasRight ( " produit " , " lire " ) || $user -> hasRight ( " 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 ) {
2024-03-27 10:46:04 +01:00
$graph .= '<div class="div-table-responsive-no-min">' ;
$graph .= '<table class="noborder centpercent">' ;
$graph .= '<tr class="liste_titre"><th>' . $langs -> trans ( " Statistics " ) . '</th></tr>' ;
$graph .= '<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 ();
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " product " )) {
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
}
2022-08-23 20:02:37 +02:00
if ( isModEnabled ( " service " )) {
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' );
2024-03-27 10:46:04 +01:00
$graph .= $dolgraph -> show ( $total ? 0 : 1 );
2020-01-31 18:16:16 +01:00
2024-03-27 10:46:04 +01:00
$graph .= '</td></tr>' ;
$graph .= '</table>' ;
$graph .= '</div>' ;
$graph .= '<br>' ;
2020-01-31 18:16:16 +01:00
}
2007-12-05 13:08:53 +01:00
}
2019-08-30 04:15:24 +02:00
2024-03-27 10:46:04 +01:00
$graphcat = '' ;
2024-08-31 13:53:45 +02:00
if ( isModEnabled ( 'category' ) && getDolGlobalString ( 'CATEGORY_GRAPHSTATS_ON_PRODUCTS' ) && $user -> hasRight ( 'categorie' , 'read' )) {
2014-05-04 18:42:00 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2024-03-27 10:46:04 +01:00
$graphcat .= '<br>' ;
$graphcat .= '<div class="div-table-responsive-no-min">' ;
$graphcat .= '<table class="noborder centpercent">' ;
$graphcat .= '<tr class="liste_titre"><th colspan="2">' . $langs -> trans ( " Categories " ) . '</th></tr>' ;
$graphcat .= '<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 ;
2024-03-27 10:46:04 +01:00
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 ) {
2023-07-02 20:07:19 +02:00
$dataseries [] = array ( $langs -> transnoentitiesnoconv ( " 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' );
2024-03-27 10:46:04 +01:00
$graphcat .= $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
2024-03-27 10:46:04 +01:00
$graphcat .= '<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 ++ ;
}
}
}
2024-03-27 10:46:04 +01:00
$graphcat .= '</td></tr>' ;
$graphcat .= '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td><td class="right">' ;
$graphcat .= $total ;
$graphcat .= '</td></tr>' ;
$graphcat .= '</table>' ;
$graphcat .= '</div>' ;
$graphcat .= '<br>' ;
2014-05-04 18:42:00 +02:00
}
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
*/
2022-10-28 15:48:46 +02:00
if (( isModEnabled ( " product " ) || isModEnabled ( " service " )) && ( $user -> hasRight ( " produit " , " lire " ) || $user -> hasRight ( " service " , " lire " ))) {
2020-01-31 18:16:16 +01:00
$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 ) . " ) " ;
2024-04-01 13:08:35 +02:00
/* if ( $type != '' ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.fk_product_type = " . (( int ) $type );
2024-04-01 13:08:35 +02:00
} */
2024-08-31 14:03:28 +02:00
if ( ! $user -> hasRight ( " produit " , " lire " )) {
$sql .= " AND p.fk_product_type <> " . (( int ) Product :: TYPE_PRODUCT );
}
if ( ! $user -> hasRight ( " service " , " lire " )) {
$sql .= " AND p.fk_product_type <> " . (( int ) Product :: TYPE_SERVICE );
}
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;
2024-10-24 14:01:30 +02:00
$lastmodified = " " ;
2020-01-31 18:16:16 +01:00
$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 );
2024-04-01 13:08:35 +02:00
if ( ! isModEnabled ( 'service' )) {
2021-02-26 14:25:17 +01:00
$transRecordedType = $langs -> trans ( " LastRecordedProducts " , $max );
}
2024-04-01 13:08:35 +02:00
if ( ! isModEnabled ( 'product' )) {
2021-02-26 14:25:17 +01:00
$transRecordedType = $langs -> trans ( " LastRecordedServices " , $max );
}
2009-01-21 15:09:42 +01:00
2024-03-27 10:46:04 +01:00
$lastmodified .= '<div class="div-table-responsive-no-min">' ;
$lastmodified .= '<table class="noborder centpercent">' ;
2009-01-21 15:09:42 +01:00
2020-01-31 18:16:16 +01:00
$colnb = 2 ;
2023-11-27 11:56:32 +01:00
if ( ! getDolGlobalString ( 'PRODUIT_MULTIPRICES' )) {
2021-02-26 14:25:17 +01:00
$colnb ++ ;
}
2012-04-05 21:15:09 +02:00
2024-04-19 15:54:09 +02:00
$lastmodified .= '<tr class="liste_titre"><th colspan="' . $colnb . '">' ;
$lastmodified .= $transRecordedType ;
$lastmodified .= '<a href="' . DOL_URL_ROOT . '/product/list.php?sortfield=p.tms&sortorder=DESC" title="' . $langs -> trans ( " FullList " ) . '">' ;
$lastmodified .= '<span class="badge marginleftonlyshort">...</span>' ;
$lastmodified .= '</a>' ;
/* $lastmodified .= '<a href="' . DOL_URL_ROOT . '/product/list.php?sortfield=p.tms&sortorder=DESC&type=0" title="' . $langs -> trans ( " FullList " ) . ' - ' . $langs -> trans ( " Products " ) . '">' ;
$lastmodified .= '<span class="badge marginleftonlyshort">...</span>' ;
//$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Products"), 'product');
2024-04-01 13:08:35 +02:00
$lastmodified .= '</a> ' ;
2024-04-19 15:54:09 +02:00
$lastmodified .= '<a href="' . DOL_URL_ROOT . '/product/list.php?sortfield=p.tms&sortorder=DESC&type=1" title="' . $langs -> trans ( " FullList " ) . ' - ' . $langs -> trans ( " Services " ) . '">' ;
$lastmodified .= '<span class="badge marginleftonlyshort">...</span>' ;
//$lastmodified .= img_picto($langs->trans("FullList").' - '.$langs->trans("Services"), 'service');
*/
$lastmodified .= '</th>' ;
$lastmodified .= '<th>' ;
$lastmodified .= '</th>' ;
$lastmodified .= '<th>' ;
$lastmodified .= '</th>' ;
$lastmodified .= '<th>' ;
2024-04-01 13:08:35 +02:00
$lastmodified .= '</th>' ;
2024-03-27 10:46:04 +01:00
$lastmodified .= '</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 ;
2023-12-04 13:49:31 +01:00
$usercancreadprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'product' , 'product_advance' , 'read_prices' ) : $user -> hasRight ( 'product' , 'read' );
2022-09-01 09:51:10 +02:00
if ( $product_static -> isService ()) {
2023-12-04 13:49:31 +01:00
$usercancreadprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'service' , 'service_advance' , 'read_prices' ) : $user -> hasRight ( 'service' , 'read' );
2022-09-01 09:51:10 +02:00
}
2021-07-07 01:24:40 +02:00
// Multilangs
2022-09-24 14:52:21 +02:00
if ( getDolGlobalInt ( '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
2024-03-27 10:46:04 +01:00
$lastmodified .= '<tr class="oddeven">' ;
$lastmodified .= '<td class="nowraponall tdoverflowmax100">' ;
$lastmodified .= $product_static -> getNomUrl ( 1 );
$lastmodified .= " </td> \n " ;
$lastmodified .= '<td class="tdoverflowmax200" title="' . dol_escape_htmltag ( $objp -> label ) . '">' . dol_escape_htmltag ( $objp -> label ) . '</td>' ;
$lastmodified .= '<td title="' . dol_escape_htmltag ( $langs -> trans ( " DateModification " ) . ': ' . dol_print_date ( $db -> jdate ( $objp -> datem ), 'dayhour' , 'tzuserrel' )) . '">' ;
$lastmodified .= dol_print_date ( $db -> jdate ( $objp -> datem ), 'day' , 'tzuserrel' );
$lastmodified .= " </td> " ;
2020-01-31 18:16:16 +01:00
// Sell price
2023-11-27 11:56:32 +01:00
if ( ! getDolGlobalString ( 'PRODUIT_MULTIPRICES' )) {
2022-12-13 20:06:56 +01:00
if ( isModEnabled ( 'dynamicprices' ) && ! empty ( $objp -> fk_price_expression )) {
2020-10-31 14:32:18 +01:00
$product = new Product ( $db );
$product -> fetch ( $objp -> rowid );
2022-12-13 20:06:56 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2020-10-31 14:32:18 +01:00
$priceparser = new PriceParser ( $db );
$price_result = $priceparser -> parseProduct ( $product );
if ( $price_result >= 0 ) {
$objp -> price = $price_result ;
}
}
2024-03-27 10:46:04 +01:00
$lastmodified .= '<td class="nowraponall amount right">' ;
2022-09-01 09:51:10 +02:00
if ( $usercancreadprice ) {
if ( isset ( $objp -> price_base_type ) && $objp -> price_base_type == 'TTC' ) {
2024-03-27 10:46:04 +01:00
$lastmodified .= price ( $objp -> price_ttc ) . ' ' . $langs -> trans ( " TTC " );
2022-09-01 09:51:10 +02:00
} else {
2024-03-27 10:46:04 +01:00
$lastmodified .= price ( $objp -> price ) . ' ' . $langs -> trans ( " HT " );
2022-09-01 09:51:10 +02:00
}
2021-02-26 14:25:17 +01:00
}
2024-03-27 10:46:04 +01:00
$lastmodified .= '</td>' ;
2020-01-31 18:16:16 +01:00
}
2024-03-27 10:46:04 +01:00
$lastmodified .= '<td class="right nowrap width25"><span class="statusrefsell">' ;
$lastmodified .= $product_static -> LibStatut ( $objp -> tosell , 3 , 0 );
$lastmodified .= " </span></td> " ;
$lastmodified .= '<td class="right nowrap width25"><span class="statusrefbuy">' ;
$lastmodified .= $product_static -> LibStatut ( $objp -> tobuy , 3 , 1 );
$lastmodified .= " </span></td> " ;
$lastmodified .= " </tr> \n " ;
2020-01-31 18:16:16 +01:00
$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
2024-03-27 10:46:04 +01:00
$lastmodified .= " </table> " ;
$lastmodified .= '</div>' ;
$lastmodified .= '<br>' ;
2020-01-31 18:16:16 +01:00
}
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
}
2024-08-31 13:53:45 +02:00
// Latest modified warehouses
2024-04-01 13:33:15 +02:00
$latestwarehouse = '' ;
2024-08-31 13:53:45 +02:00
if ( isModEnabled ( 'stock' ) && $user -> hasRight ( 'stock' , 'read' )) {
2024-04-01 13:33:15 +02:00
$sql = " SELECT e.rowid, e.ref as label, e.lieu, e.statut as status " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " entrepot as e " ;
$sql .= " WHERE e.statut in ( " . Entrepot :: STATUS_CLOSED . " , " . Entrepot :: STATUS_OPEN_ALL . " ) " ;
$sql .= " AND e.entity IN ( " . getEntity ( 'stock' ) . " ) " ;
$sql .= $db -> order ( 'e.tms' , 'DESC' );
$sql .= $db -> plimit ( $max + 1 , 0 );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$latestwarehouse .= '<div class="div-table-responsive-no-min">' ;
$latestwarehouse .= '<table class="noborder centpercent">' ;
$latestwarehouse .= '<tr class="liste_titre">' ;
$latestwarehouse .= '<th>' ;
$latestwarehouse .= $langs -> trans ( " LatestModifiedWarehouses " , $max );
//$latestwarehouse .= '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
// TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
//print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
//$latestwarehouse .= '<span class="badge">'.$num.'</span>';
2024-04-19 15:54:09 +02:00
$latestwarehouse .= '<a href="' . DOL_URL_ROOT . '/product/stock/list.php?sortfield=p.tms&sortorder=DESC" title="' . $langs -> trans ( " FullList " ) . '">' ;
$latestwarehouse .= '<span class="badge marginleftonlyshort">...</span>' ;
2024-04-01 13:33:15 +02:00
$latestwarehouse .= '</a>' ;
2024-04-19 15:54:09 +02:00
$latestwarehouse .= '</th><th class="right">' ;
2024-04-01 13:33:15 +02:00
$latestwarehouse .= '</th>' ;
$latestwarehouse .= '</tr>' ;
$i = 0 ;
if ( $num ) {
while ( $i < min ( $max , $num )) {
$objp = $db -> fetch_object ( $result );
$warehouse -> id = $objp -> rowid ;
$warehouse -> statut = $objp -> status ;
$warehouse -> label = $objp -> label ;
$warehouse -> lieu = $objp -> lieu ;
$latestwarehouse .= '<tr class="oddeven">' ;
$latestwarehouse .= '<td>' ;
$latestwarehouse .= $warehouse -> getNomUrl ( 1 );
$latestwarehouse .= '</td>' . " \n " ;
$latestwarehouse .= '<td class="right">' ;
$latestwarehouse .= $warehouse -> getLibStatut ( 5 );
$latestwarehouse .= '</td>' ;
$latestwarehouse .= " </tr> \n " ;
$i ++ ;
}
$db -> free ( $result );
} else {
$latestwarehouse .= '<tr><td>' . $langs -> trans ( " None " ) . '</td><td></td></tr>' ;
}
/* if ( $num > $max ) {
$latestwarehouse .= '<tr><td><span class="opacitymedium">' . $langs -> trans ( " More " ) . '...</span></td><td></td></tr>' ;
} */
$latestwarehouse .= " </table> " ;
$latestwarehouse .= '</div>' ;
$latestwarehouse .= '<br>' ;
} else {
dol_print_error ( $db );
}
}
2024-08-31 13:53:45 +02:00
// Latest movements
2024-04-01 13:08:35 +02:00
$latestmovement = '' ;
2024-08-31 13:53:45 +02:00
if ( isModEnabled ( 'stock' ) && $user -> hasRight ( 'stock' , 'mouvement' , 'read' )) {
include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php' ;
$sql = " SELECT p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.tobatch, p.tosell, p.tobuy, " ;
2024-04-01 13:08:35 +02:00
$sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status, " ;
2024-08-31 13:53:45 +02:00
$sql .= " m.rowid as mid, m.label as mlabel, m.inventorycode as mcode, m.value as qty, m.datem, m.batch, m.eatby, m.sellby " ;
2024-04-01 13:08:35 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " entrepot as e " ;
$sql .= " , " . MAIN_DB_PREFIX . " stock_mouvement as m " ;
$sql .= " , " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " WHERE m.fk_product = p.rowid " ;
$sql .= " AND m.fk_entrepot = e.rowid " ;
$sql .= " AND e.entity IN ( " . getEntity ( 'stock' ) . " ) " ;
if ( ! getDolGlobalString ( 'STOCK_SUPPORTS_SERVICES' )) {
$sql .= " AND p.fk_product_type = " . Product :: TYPE_PRODUCT ;
}
$sql .= $db -> order ( " datem " , " DESC " );
$sql .= $db -> plimit ( $max , 0 );
dol_syslog ( " Index:list stock movements " , LOG_DEBUG );
2024-05-01 18:24:51 +02:00
2024-04-01 13:08:35 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$latestmovement .= '<div class="div-table-responsive-no-min">' ;
$latestmovement .= '<table class="noborder centpercent">' ;
$latestmovement .= '<tr class="liste_titre">' ;
2024-08-31 13:53:45 +02:00
$latestmovement .= '<th colspan="3">' . $langs -> trans ( " LatestStockMovements " , min ( $num , $max ));
2024-04-19 15:54:09 +02:00
$latestmovement .= '<a class="notasortlink" href="' . DOL_URL_ROOT . '/product/stock/movement_list.php">' ;
$latestmovement .= '<span class="badge marginleftonlyshort">...</span>' ;
//$latestmovement .= img_picto($langs->trans("FullList"), 'movement');
$latestmovement .= '</a>' ;
$latestmovement .= '</th>' ;
2024-04-01 13:08:35 +02:00
if ( isModEnabled ( 'productbatch' )) {
2024-04-19 15:54:09 +02:00
$latestmovement .= '<th></th>' ;
2024-04-01 13:08:35 +02:00
}
2024-04-19 15:54:09 +02:00
$latestmovement .= '<th></th>' ;
$latestmovement .= '<th class="right">' ;
$latestmovement .= '</th>' ;
2024-04-01 13:08:35 +02:00
$latestmovement .= " </tr> \n " ;
$tmplotstatic = new Productlot ( $db );
2024-08-31 13:53:45 +02:00
$tmpstockmovement = new MouvementStock ( $db );
2024-04-01 13:08:35 +02:00
$i = 0 ;
while ( $i < min ( $num , $max )) {
$objp = $db -> fetch_object ( $resql );
2024-08-31 13:53:45 +02:00
$tmpstockmovement -> id = $objp -> mid ;
$tmpstockmovement -> date = $db -> jdate ( $objp -> datem );
$tmpstockmovement -> label = $objp -> mlabel ;
$tmpstockmovement -> inventorycode = $objp -> mcode ;
$tmpstockmovement -> qty = $objp -> qty ;
$producttmp -> id = $objp -> product_id ;
$producttmp -> ref = $objp -> product_ref ;
$producttmp -> label = $objp -> product_label ;
2024-04-01 13:08:35 +02:00
$producttmp -> status_batch = $objp -> tobatch ;
$producttmp -> status_sell = $objp -> tosell ;
$producttmp -> status_buy = $objp -> tobuy ;
$warehouse -> id = $objp -> warehouse_id ;
$warehouse -> ref = $objp -> warehouse_ref ;
$warehouse -> statut = $objp -> warehouse_status ;
$warehouse -> label = $objp -> warehouse_label ;
$warehouse -> lieu = $objp -> lieu ;
$tmplotstatic -> batch = $objp -> batch ;
$tmplotstatic -> sellby = $objp -> sellby ;
$tmplotstatic -> eatby = $objp -> eatby ;
$latestmovement .= '<tr class="oddeven">' ;
2024-08-31 13:53:45 +02:00
$latestmovement .= '<td class="nowraponall">' ;
$latestmovement .= $tmpstockmovement -> getNomUrl ( 1 );
//$latestmovement .= img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour');
$latestmovement .= '</td>' ;
$latestmovement .= '<td class="nowraponall">' ;
$latestmovement .= dol_print_date ( $tmpstockmovement -> date , 'dayhour' , 'tzuserrel' );
$latestmovement .= " </td> \n " ;
2024-04-01 13:08:35 +02:00
$latestmovement .= '<td class="tdoverflowmax150">' ;
$latestmovement .= $producttmp -> getNomUrl ( 1 );
$latestmovement .= " </td> \n " ;
if ( isModEnabled ( 'productbatch' )) {
$latestmovement .= '<td>' ;
$latestmovement .= $tmplotstatic -> getNomUrl ( 0 , 'nolink' );
$latestmovement .= '</td>' ;
/* if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> sellby ), 'day' ) . '</td>' ;
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> eatby ), 'day' ) . '</td>' ;
} */
}
$latestmovement .= '<td class="tdoverflowmax150">' ;
$latestmovement .= $warehouse -> getNomUrl ( 1 );
$latestmovement .= " </td> \n " ;
$latestmovement .= '<td class="right">' ;
2024-04-01 13:33:15 +02:00
if ( $objp -> qty < 0 ) {
$latestmovement .= '<span class="stockmovementexit">' ;
}
2024-04-01 13:08:35 +02:00
if ( $objp -> qty > 0 ) {
2024-04-01 13:33:15 +02:00
$latestmovement .= '<span class="stockmovemententry">' ;
2024-04-01 13:08:35 +02:00
$latestmovement .= '+' ;
}
2024-04-01 13:33:15 +02:00
$latestmovement .= $objp -> qty ;
$latestmovement .= '</span>' ;
$latestmovement .= '</td>' ;
2024-04-01 13:08:35 +02:00
$latestmovement .= " </tr> \n " ;
$i ++ ;
}
$db -> free ( $resql );
2024-05-01 18:24:51 +02:00
if ( empty ( $num )) {
2025-02-14 23:54:43 +01:00
$colspan = 5 ;
2024-05-01 18:24:51 +02:00
if ( isModEnabled ( 'productbatch' )) {
$colspan ++ ;
}
2024-06-17 03:02:30 +02:00
$latestmovement .= '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2024-05-01 18:24:51 +02:00
}
2024-04-01 13:08:35 +02:00
$latestmovement .= " </table> " ;
$latestmovement .= '</div>' ;
2024-04-01 13:33:15 +02:00
$latestmovement .= '<br>' ;
2024-04-01 13:08:35 +02:00
} else {
dol_print_error ( $db );
}
}
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":
2024-01-12 17:55:52 +01:00
// "commitment engagement" method and "cash accounting" method
2024-03-27 10:46:04 +01:00
$activity = '' ;
2022-09-02 10:01:16 +02:00
if ( isModEnabled ( " invoice " ) && $user -> hasRight ( 'facture' , 'lire' ) && getDolGlobalString ( 'MAIN_SHOW_PRODUCT_ACTIVITY_TRIM' )) {
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " product " )) {
2024-03-27 10:46:04 +01:00
$activity .= activitytrim ( 0 );
2021-02-26 14:25:17 +01:00
}
2022-08-23 20:02:37 +02:00
if ( isModEnabled ( " service " )) {
2024-03-27 10:46:04 +01:00
$activity .= activitytrim ( 1 );
2021-02-26 14:25:17 +01:00
}
2013-10-10 17:34:26 +02:00
}
2013-08-06 21:31:32 +02:00
2024-03-27 10:46:04 +01:00
// print '</div></div>';
// boxes
print '<div class="clearboth"></div>' ;
print '<div class="fichecenter fichecenterbis">' ;
$boxlist = '<div class="twocolumns">' ;
$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">' ;
$boxlist .= $graph ;
$boxlist .= $graphcat ;
$boxlist .= $activity ;
$boxlist .= '<br>' ;
$boxlist .= $resultboxes [ 'boxlista' ];
$boxlist .= " </div> \n " ;
$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">' ;
$boxlist .= $lastmodified ;
2024-04-01 13:33:15 +02:00
$boxlist .= $latestwarehouse ;
2024-04-01 13:08:35 +02:00
$boxlist .= $latestmovement ;
2024-03-27 10:46:04 +01:00
$boxlist .= $resultboxes [ 'boxlistb' ];
$boxlist .= '</div>' . " \n " ;
$boxlist .= " </div> \n " ;
print $boxlist ;
print '</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
2024-03-27 10:46:04 +01:00
* @ return string
2015-01-06 17:54:36 +01:00
*/
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
2024-08-16 20:13:02 +02:00
$yearofbegindate = ( int ) date ( 'Y' , dol_time_plus_duree ( time (), - 3 , " y " ));
2024-03-27 10:46:04 +01:00
$out = '' ;
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 );
2025-02-08 21:53:48 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( dol_get_first_day ( $yearofbegindate , 1 )) . " ' " ;
2019-11-12 00:15:34 +01:00
$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 ) {
2024-03-27 10:46:04 +01:00
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="noborder" width="75%">' ;
2013-08-06 21:31:32 +02:00
2021-02-26 14:25:17 +01:00
if ( $product_type == 0 ) {
2024-03-27 10:46:04 +01:00
$out .= '<tr class="liste_titre"><td class=left>' . $langs -> trans ( " ProductSellByQuarterHT " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
} else {
2024-03-27 10:46:04 +01:00
$out .= '<tr class="liste_titre"><td class=left>' . $langs -> trans ( " ServiceSellByQuarterHT " ) . '</td>' ;
2021-02-26 14:25:17 +01:00
}
2024-03-27 10:46:04 +01:00
$out .= '<td class=right>' . $langs -> trans ( " Quarter1 " ) . '</td>' ;
$out .= '<td class=right>' . $langs -> trans ( " Quarter2 " ) . '</td>' ;
$out .= '<td class=right>' . $langs -> trans ( " Quarter3 " ) . '</td>' ;
$out .= '<td class=right>' . $langs -> trans ( " Quarter4 " ) . '</td>' ;
$out .= '<td class=right>' . $langs -> trans ( " Total " ) . '</td>' ;
$out .= '</tr>' ;
2013-08-06 21:31:32 +02:00
}
$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 ) {
2024-03-27 10:46:04 +01:00
$out .= '<tr class="oddeven"><td class=left>' . $tmpyear . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim1 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim2 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim3 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim4 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim1 + $trim2 + $trim3 + $trim4 ) . '</td>' ;
$out .= '</tr>' ;
2013-08-06 21:31:32 +02:00
$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 ) {
2024-03-27 10:46:04 +01:00
$out .= '<tr class="oddeven"><td class=left>' . $tmpyear . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim1 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim2 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim3 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim4 ) . '</td>' ;
$out .= '<td class="nowrap right">' . price ( $trim1 + $trim2 + $trim3 + $trim4 ) . '</td>' ;
$out .= '</tr>' ;
2013-08-06 21:31:32 +02:00
}
2021-02-26 14:25:17 +01:00
if ( $num > 0 ) {
2024-03-27 10:46:04 +01:00
$out .= '</table></div>' ;
$out .= '<br>' ;
2021-02-26 14:25:17 +01:00
}
2013-08-06 21:31:32 +02:00
}
2024-03-27 10:46:04 +01:00
return $out ;
2013-08-06 21:31:32 +02:00
}