2006-08-01 23:54:39 +00:00
< ? php
2015-11-30 20:20:45 +00:00
/* Copyright ( C ) 2006 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-05-23 16:52:31 +00:00
* Copyright ( C ) 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2018-10-27 12:43:12 +00:00
* Copyright ( C ) 2009 - 2010 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-23 16:52:31 +00:00
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2016-07-23 14:37:21 +00:00
* Copyright ( C ) 2015 - 2016 Marcos García < marcosgdf @ gmail . com >
2023-02-17 09:12:19 +00:00
* Copyright ( C ) 2023 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2024-04-22 13:26:23 +00:00
* Copyright ( C ) 2024 Jean - Rémi TAPONIER < jean - remi @ netlogic . fr >
2025-02-08 17:30:42 +00:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2024-10-19 07:50:18 +00:00
* Copyright ( C ) 2024 Mélina Joum < melina . joum @ altairis . fr >
2026-03-23 22:55:51 +00:00
* Copyright ( C ) 2024 - 2026 Frédéric France < frederic . france @ free . fr >
2006-08-01 22:42:38 +00: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 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2006-08-01 22:42:38 +00: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 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2006-08-01 22:42:38 +00:00
*/
/**
2026-01-25 13:19:59 +00:00
* \file htdocs / core / lib / product . lib . php
* \brief Set of functions for the module product and service
* \ingroup product
2008-08-28 00:31:27 +00:00
*/
2008-12-11 20:12:44 +00:00
2012-02-04 09:48:47 +00:00
/**
* Prepare array with list of tabs
*
2026-01-25 13:19:59 +00:00
* @ param Product $object Object related to tabs
2024-09-22 22:37:30 +00:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2012-02-04 09:48:47 +00:00
*/
2015-04-07 01:00:11 +00:00
function product_prepare_head ( $object )
2006-08-01 23:54:39 +00:00
{
2016-01-23 16:19:34 +00:00
global $db , $langs , $conf , $user ;
2010-03-13 22:27:37 +00:00
$langs -> load ( " products " );
2020-05-28 09:51:49 +00:00
$label = $langs -> trans ( 'Product' );
2023-12-04 11:05:28 +00:00
$usercancreadprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'product' , 'product_advance' , 'read_prices' ) : $user -> hasRight ( 'product' , 'read' );
2025-03-28 23:43:13 +00:00
$usercancreadsupplierprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'product' , 'product_advance' , 'read_supplier_prices' ) : $user -> hasRight ( 'product' , 'read' );
2022-08-24 17:59:06 +00:00
2021-02-23 21:03:23 +00:00
if ( $object -> isService ()) {
$label = $langs -> trans ( 'Service' );
2023-12-04 11:05:28 +00:00
$usercancreadprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'service' , 'service_advance' , 'read_prices' ) : $user -> hasRight ( 'service' , 'read' );
2025-03-28 23:43:13 +00:00
$usercancreadsupplierprice = getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) ? $user -> hasRight ( 'service' , 'service_advance' , 'read_supplier_prices' ) : $user -> hasRight ( 'service' , 'read' );
2021-02-23 21:03:23 +00:00
}
2020-05-28 09:51:49 +00:00
2008-08-28 00:31:27 +00:00
$h = 0 ;
$head = array ();
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/card.php' , [ 'id' => $object -> id ]);
2020-05-28 09:51:49 +00:00
$head [ $h ][ 1 ] = $label ;
2008-08-28 00:31:27 +00:00
$head [ $h ][ 2 ] = 'card' ;
$h ++ ;
2023-10-17 14:39:55 +00:00
// if (!empty($object->status)) {
if ( $usercancreadprice ) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/price.php' , [ 'id' => $object -> id ]);
2023-10-17 14:39:55 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " SellingPrices " );
$head [ $h ][ 2 ] = 'price' ;
$h ++ ;
} else {
$head [ $h ][ 0 ] = '#' ;
$head [ $h ][ 1 ] = $langs -> trans ( " SellingPrices " );
$head [ $h ][ 2 ] = 'price' ;
$head [ $h ][ 5 ] = 'disabled' ;
$h ++ ;
}
// }
// if (!empty($object->status_buy) || (isModEnabled('margin') && !empty($object->status))) { // If margin is on and product on sell, we may need the cost price even if product os not on purchase
if (( isModEnabled ( " supplier_proposal " ) || isModEnabled ( " supplier_order " ) || isModEnabled ( " supplier_invoice " )) && ( $user -> hasRight ( 'fournisseur' , 'lire' ) || $user -> hasRight ( 'supplier_order' , 'read' ) || $user -> hasRight ( 'supplier_invoice' , 'read' ))
|| ( isModEnabled ( 'margin' ) && $user -> hasRight ( " margin " , " liretous " ))
2024-09-22 22:37:30 +00:00
) {
2025-03-28 23:43:13 +00:00
if ( $usercancreadsupplierprice ) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/price_suppliers.php' , [ 'id' => $object -> id ]);
2023-10-17 14:39:55 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " BuyingPrices " );
$head [ $h ][ 2 ] = 'suppliers' ;
2022-11-08 21:28:59 +00:00
$h ++ ;
} else {
$head [ $h ][ 0 ] = '#' ;
2023-10-17 14:39:55 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " BuyingPrices " );
$head [ $h ][ 2 ] = 'suppliers' ;
2022-11-08 21:28:59 +00:00
$head [ $h ][ 5 ] = 'disabled' ;
$h ++ ;
}
2010-03-13 22:27:37 +00:00
}
2023-10-17 14:39:55 +00:00
// }
2008-08-28 00:31:27 +00:00
// Multilangs
2022-09-24 12:44:16 +00:00
if ( getDolGlobalInt ( 'MAIN_MULTILANGS' )) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/traduction.php' , [ 'id' => $object -> id ]);
2022-10-08 15:09:31 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Translations " );
2024-10-15 13:39:29 +00:00
$nbTranslations = ! empty ( $object -> multilangs ) ? count ( $object -> multilangs ) : 0 ;
if ( $nbTranslations > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbTranslations . '</span>' ;
}
2008-08-28 00:31:27 +00:00
$head [ $h ][ 2 ] = 'translation' ;
$h ++ ;
}
2008-09-04 17:56:55 +00:00
// Sub products
2023-11-27 10:39:32 +00:00
if ( getDolGlobalString ( 'PRODUIT_SOUSPRODUITS' )) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/composition/card.php' , [ 'id' => $object -> id ]);
2008-08-28 00:31:27 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'AssociatedProducts' );
2017-12-01 16:48:51 +00:00
2026-01-23 18:14:45 +00:00
$nbFather = $object -> hasFatherOrChild ( - 1 );
$nbChild = $object -> hasFatherOrChild ( 1 );
if ( $nbFather > 0 || $nbChild > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' ;
if ( $nbFather ) {
$head [ $h ][ 1 ] .= $nbFather ;
}
$head [ $h ][ 1 ] .= ( $nbFather && $nbChild ) ? '+' : '' ;
if ( $nbChild ) {
$head [ $h ][ 1 ] .= $nbChild ;
}
$head [ $h ][ 1 ] .= '</span>' ;
2021-02-23 21:03:23 +00:00
}
2008-08-28 00:31:27 +00:00
$head [ $h ][ 2 ] = 'subproduct' ;
$h ++ ;
}
2022-09-25 04:09:29 +00:00
if ( isModEnabled ( 'variants' ) && ( $object -> isProduct () || $object -> isService ())) {
2016-07-23 14:37:21 +00:00
global $db ;
2017-02-08 11:37:38 +00:00
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php' ;
2016-07-23 14:37:21 +00:00
$prodcomb = new ProductCombination ( $db );
2021-02-23 21:03:23 +00:00
if ( $prodcomb -> fetchByFkProductChild ( $object -> id ) <= 0 ) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/variants/combinations.php' , [ 'id' => $object -> id ]);
2016-07-23 14:37:21 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'ProductCombinations' );
$head [ $h ][ 2 ] = 'combinations' ;
2017-02-08 13:07:54 +00:00
$nbVariant = $prodcomb -> countNbOfCombinationForFkProductParent ( $object -> id );
2021-02-23 21:03:23 +00:00
if ( $nbVariant > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbVariant . '</span>' ;
}
2020-10-31 13:32:18 +00:00
}
$h ++ ;
}
2025-03-10 09:49:53 +00:00
if (( $object -> isProduct () || ( $object -> isService () && getDolGlobalString ( 'STOCK_SUPPORTS_SERVICES' ))) && $object -> stockable_product == Product :: ENABLED_STOCK ) { // If physical product we can stock (or service with option)
2023-05-16 13:36:27 +00:00
if ( isModEnabled ( 'stock' ) && $user -> hasRight ( 'stock' , 'lire' )) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stock/product.php' , [ 'id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Stock " );
$head [ $h ][ 2 ] = 'stock' ;
$h ++ ;
}
}
// Tab to link resources
2022-08-31 19:49:10 +00:00
if ( isModEnabled ( 'resource' )) {
2023-11-27 10:39:32 +00:00
if ( $object -> isProduct () && getDolGlobalString ( 'RESOURCE_ON_PRODUCTS' )) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/resource/element_resource.php' , [ 'element' => 'product' , 'element_id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Resources " );
$head [ $h ][ 2 ] = 'resources' ;
$h ++ ;
2016-07-23 14:37:21 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $object -> isService () && getDolGlobalString ( 'RESOURCE_ON_SERVICES' )) {
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/resource/element_resource.php' , [ 'element' => 'service' , 'element_id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Resources " );
$head [ $h ][ 2 ] = 'resources' ;
$h ++ ;
}
}
2026-03-23 12:46:03 +00:00
if ( getDolGlobalString ( 'MAIN_ENABLE_PRODUCTS_CONTACTS_TAB' )) {
2025-11-05 21:50:38 +00:00
$objectsrc = $object ;
2026-03-23 12:40:13 +00:00
if ( $object -> origin_type == 'product' && $object -> origin_id > 0 ) {
2025-11-05 21:50:38 +00:00
$objectsrc = new Product ( $db );
$objectsrc -> fetch ( $object -> origin_id );
}
$nbContact = count ( $objectsrc -> liste_contact ( - 1 , 'internal' )) + count ( $objectsrc -> liste_contact ( - 1 , 'external' ));
2026-03-23 23:00:35 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/contact.php' , [ 'id' => $object -> id ]);
2025-11-05 21:50:38 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ContactsAddresses " );
if ( $nbContact > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>' ;
}
$head [ $h ][ 2 ] = 'contact' ;
$h ++ ;
}
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stats/facture.php' , [ 'showmessage' => 1 , 'id' => $object -> id ]);
2020-11-16 15:31:05 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Referers' );
$head [ $h ][ 2 ] = 'referers' ;
$h ++ ;
2026-05-19 18:07:11 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stats/index.php' , [ 'id' => $object -> id ]);
2020-11-16 15:31:05 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Statistics' );
$head [ $h ][ 2 ] = 'stats' ;
$h ++ ;
2020-10-31 13:32:18 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2022-09-22 12:06:50 +00:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'product' , 'add' , 'core' );
2020-10-31 13:32:18 +00:00
// Notes
2023-11-27 10:39:32 +00:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_NOTES_TAB' )) {
2020-10-31 13:32:18 +00:00
$nbNote = 0 ;
2021-02-23 21:03:23 +00:00
if ( ! empty ( $object -> note_private )) {
$nbNote ++ ;
}
if ( ! empty ( $object -> note_public )) {
$nbNote ++ ;
}
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/note.php' , [ 'id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Notes' );
2021-02-23 21:03:23 +00:00
if ( $nbNote > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' ;
}
2020-10-31 13:32:18 +00:00
$head [ $h ][ 2 ] = 'note' ;
2016-07-23 14:37:21 +00:00
$h ++ ;
}
2020-10-31 13:32:18 +00:00
// Attachments
2013-07-15 23:28:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-10-31 13:32:18 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
2025-10-14 17:58:04 +00:00
$upload_dir = null ;
$nbFiles = 0 ;
2022-08-23 18:01:34 +00:00
if ( isModEnabled ( " product " ) && ( $object -> type == Product :: TYPE_PRODUCT )) {
2025-09-07 23:48:52 +00:00
$upload_dir = $conf -> product -> multidir_output [ $object -> entity ? ? $conf -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
2021-02-23 21:03:23 +00:00
}
2022-08-23 18:02:37 +00:00
if ( isModEnabled ( " service " ) && ( $object -> type == Product :: TYPE_SERVICE )) {
2025-09-07 23:48:52 +00:00
$upload_dir = $conf -> service -> multidir_output [ $object -> entity ? ? $conf -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
2021-02-23 21:03:23 +00:00
}
2025-10-14 17:58:04 +00:00
if ( $upload_dir !== null ) {
$nbFiles = count ( dol_dir_list ( $upload_dir , 'files' , 0 , '' , '(\.meta|_preview.*\.png)$' ));
}
2022-10-06 14:44:52 +00:00
if ( getDolGlobalInt ( 'PRODUCT_USE_OLD_PATH_FOR_PHOTO' )) {
2022-08-23 18:01:34 +00:00
if ( isModEnabled ( " product " ) && ( $object -> type == Product :: TYPE_PRODUCT )) {
2025-09-07 23:48:52 +00:00
$upload_dir = $conf -> product -> multidir_output [ $object -> entity ? ? $conf -> entity ] . '/' . get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'product' ) . $object -> id . '/photos' ;
2021-02-23 21:03:23 +00:00
}
2022-08-23 18:02:37 +00:00
if ( isModEnabled ( " service " ) && ( $object -> type == Product :: TYPE_SERVICE )) {
2025-09-07 23:48:52 +00:00
$upload_dir = $conf -> service -> multidir_output [ $object -> entity ? ? $conf -> entity ] . '/' . get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'product' ) . $object -> id . '/photos' ;
2021-02-23 21:03:23 +00:00
}
2025-10-14 17:58:04 +00:00
if ( $upload_dir !== null ) {
$nbFiles += count ( dol_dir_list ( $upload_dir , 'files' , 0 , '' , '(\.meta|_preview.*\.png)$' ));
}
2020-10-31 13:32:18 +00:00
}
$nbLinks = Link :: count ( $db , $object -> element , $object -> id );
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/document.php' , [ 'id' => $object -> id ]);
2008-08-28 00:31:27 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Documents' );
2021-02-23 21:03:23 +00:00
if (( $nbFiles + $nbLinks ) > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . ( $nbFiles + $nbLinks ) . '</span>' ;
}
2008-08-28 00:31:27 +00:00
$head [ $h ][ 2 ] = 'documents' ;
$h ++ ;
2020-10-31 13:32:18 +00:00
// Log
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/messaging.php' , [ 'id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Events " );
2023-06-12 18:10:42 +00:00
if ( isModEnabled ( 'agenda' ) && ( $user -> hasRight ( 'agenda' , 'myactions' , 'read' ) || $user -> hasRight ( 'agenda' , 'allactions' , 'read' ))) {
2026-01-25 14:55:05 +00:00
$nbEvent = 0 ;
// Enable caching of product count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php' ;
$cachekey = 'count_events_product_' . $object -> id ;
$dataretrieved = dol_getcache ( $cachekey );
if ( ! is_null ( $dataretrieved )) {
$nbEvent = $dataretrieved ;
} else {
$sql = " SELECT COUNT(id) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm " ;
$sql .= " WHERE fk_element = " . (( int ) $object -> id );
$sql .= " AND elementtype = 'product' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$nbEvent = $obj -> nb ;
} else {
dol_syslog ( 'Failed to count actioncomm ' . $db -> lasterror (), LOG_ERR );
}
dol_setcache ( $cachekey , $nbEvent , 120 ); // If setting cache fails, this is not a problem, so we do not test result.
}
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] .= '/' ;
$head [ $h ][ 1 ] .= $langs -> trans ( " Agenda " );
2026-01-25 14:55:05 +00:00
if ( $nbEvent > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>' ;
}
2020-10-31 13:32:18 +00:00
}
$head [ $h ][ 2 ] = 'agenda' ;
$h ++ ;
2015-11-19 13:45:05 +00:00
2022-09-22 12:06:50 +00:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'product' , 'add' , 'external' );
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'product' , 'remove' );
2008-08-28 00:31:27 +00:00
return $head ;
2006-08-01 23:54:39 +00:00
}
2016-09-12 15:27:44 +00:00
/**
* Prepare array with list of tabs
*
* @ param ProductLot $object Object related to tabs
2024-09-22 22:37:30 +00:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2016-09-12 15:27:44 +00:00
*/
function productlot_prepare_head ( $object )
{
2020-10-31 13:32:18 +00:00
global $db , $langs , $conf , $user ;
2018-09-11 15:30:43 +00:00
2020-10-31 13:32:18 +00:00
// Load translation files required by the page
$langs -> loadLangs ( array ( " products " , " productbatch " ));
2017-08-02 12:10:43 +00:00
2020-10-31 13:32:18 +00:00
$h = 0 ;
$head = array ();
2016-09-12 15:27:44 +00:00
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stock/productlot_card.php' , [ 'id' => $object -> id ]);
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Lot " );
$head [ $h ][ 2 ] = 'card' ;
2018-04-12 13:10:37 +00:00
$h ++ ;
2018-09-11 15:30:43 +00:00
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stock/stats/expedition.php' , [ 'showmessage' => 1 , 'id' => $object -> id ]);
2023-02-17 08:44:38 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Referers' );
$head [ $h ][ 2 ] = 'referers' ;
$h ++ ;
2018-04-12 13:10:37 +00:00
// Attachments
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-10-31 13:32:18 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
2025-09-07 23:48:52 +00:00
$upload_dir = $conf -> productbatch -> multidir_output [ $object -> entity ? ? $conf -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
2020-10-31 13:32:18 +00:00
$nbFiles = count ( dol_dir_list ( $upload_dir , 'files' , 0 , '' , '(\.meta|_preview.*\.png)$' ));
$nbLinks = Link :: count ( $db , $object -> element , $object -> id );
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stock/productlot_document.php' , [ 'id' => $object -> id ]);
2018-04-12 13:10:37 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Documents " );
2021-02-23 21:03:23 +00:00
if (( $nbFiles + $nbLinks ) > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . ( $nbFiles + $nbLinks ) . '</span>' ;
}
2020-10-31 13:32:18 +00:00
$head [ $h ][ 2 ] = 'documents' ;
2018-04-12 13:10:37 +00:00
$h ++ ;
2016-09-12 15:27:44 +00:00
2022-09-05 14:49:57 +00:00
// Notes
2023-11-27 10:39:32 +00:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_NOTES_TAB' )) {
2022-09-05 14:49:57 +00:00
$nbNote = 0 ;
if ( ! empty ( $object -> note_private )) {
$nbNote ++ ;
}
if ( ! empty ( $object -> note_public )) {
$nbNote ++ ;
}
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/product/stock/productlot_note.php' , [ 'id' => $object -> id ]);
2022-09-05 14:49:57 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Notes' );
if ( $nbNote > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' ;
}
$head [ $h ][ 2 ] = 'note' ;
$h ++ ;
}
2020-10-31 13:32:18 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'productlot' );
2016-09-12 15:27:44 +00:00
2020-10-31 13:32:18 +00:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'productlot' , 'remove' );
2016-09-12 15:27:44 +00:00
2020-10-31 13:32:18 +00:00
// Log
/*
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/info.php' , [ 'id' => $object -> id ]);
2021-02-23 21:03:23 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Info " );
$head [ $h ][ 2 ] = 'info' ;
$h ++ ;
*/
2017-08-02 12:10:43 +00:00
2020-10-31 13:32:18 +00:00
return $head ;
2016-09-12 15:27:44 +00:00
}
2012-03-03 15:33:38 +00:00
/**
2024-10-13 23:59:44 +00:00
* Return array head with list of tabs to view object information .
*
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
*/
2014-12-04 12:20:56 +00:00
function product_admin_prepare_head ()
2012-03-03 15:33:38 +00:00
{
2026-06-13 23:09:51 +00:00
global $langs , $conf , $extrafields ;
2022-09-18 18:50:15 +00:00
$extrafields -> fetch_name_optionals_label ( 'product' );
2026-03-23 22:55:51 +00:00
$extrafields -> fetch_name_optionals_label ( 'product_lang' );
2024-10-19 07:50:18 +00:00
$extrafields -> fetch_name_optionals_label ( 'product_price' );
$extrafields -> fetch_name_optionals_label ( 'product_customer_price' );
2022-09-18 18:50:15 +00:00
$extrafields -> fetch_name_optionals_label ( 'product_fournisseur_price' );
2012-06-09 17:16:31 +00:00
2012-05-22 16:35:14 +00:00
$h = 0 ;
$head = array ();
2012-06-09 17:16:31 +00:00
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . " /product/admin/product.php " );
2012-05-22 16:35:14 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Parameters' );
$head [ $h ][ 2 ] = 'general' ;
$h ++ ;
2012-06-09 17:16:31 +00:00
2023-11-27 10:39:32 +00:00
if ( getDolGlobalString ( 'PRODUIT_MULTIPRICES' ) && getDolGlobalString ( 'PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL' )) {
2015-10-19 13:13:19 +00:00
$head [ $h ] = array (
2025-10-17 00:31:07 +00:00
0 => dolBuildUrl ( DOL_URL_ROOT . " /product/admin/price_rules.php " ),
2015-10-19 13:13:19 +00:00
1 => $langs -> trans ( 'MultipriceRules' ),
2 => 'generator'
);
$h ++ ;
}
2012-05-22 16:35:14 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
2020-10-31 13:32:18 +00:00
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2019-01-27 10:55:16 +00:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'product_admin' );
2012-06-09 17:16:31 +00:00
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product' ));
2012-05-22 16:35:14 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFields " );
2025-08-05 23:48:18 +00:00
$nbExtrafields = isset ( $extrafields -> attributes [ 'product' ][ 'count' ]) ? $extrafields -> attributes [ 'product' ][ 'count' ] : 0 ;
2022-09-18 18:50:15 +00:00
if ( $nbExtrafields > 0 ) {
2022-09-22 12:42:58 +00:00
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
2022-09-18 18:50:15 +00:00
}
2012-05-22 16:35:14 +00:00
$head [ $h ][ 2 ] = 'attributes' ;
$h ++ ;
2012-06-09 17:16:31 +00:00
2026-03-23 22:55:51 +00:00
// Multilangs Extrafields
if ( getDolGlobalInt ( 'MAIN_MULTILANGS' )) {
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product_lang' ));
2026-03-23 22:55:51 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " TranslationsExtrafields " );
$nbExtrafields = isset ( $extrafields -> attributes [ 'product_lang' ][ 'count' ]) ? $extrafields -> attributes [ 'product_lang' ][ 'count' ] : 0 ;
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
$head [ $h ][ 2 ] = 'translationAttributes' ;
$h ++ ;
}
2025-02-11 14:40:47 +00:00
// Extrafields for price levels
if ( getDolGlobalString ( 'PRODUIT_MULTIPRICES' ) || getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES' ) || getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES' )) {
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product_price' ));
2025-02-11 14:40:47 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ProductLevelExtraFields " );
2025-08-05 23:48:18 +00:00
$nbExtrafields = isset ( $extrafields -> attributes [ 'product_price' ][ 'count' ]) ? $extrafields -> attributes [ 'product_price' ][ 'count' ] : 0 ;
2025-02-11 14:40:47 +00:00
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
$head [ $h ][ 2 ] = 'levelAttributes' ;
$h ++ ;
2024-10-19 07:50:18 +00:00
}
2026-03-23 22:55:51 +00:00
// Extrafields for price per customer
2025-02-11 14:40:47 +00:00
if ( getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES' ) || getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES' )) {
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product_customer_price' ));
2025-02-11 14:40:47 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ProductCustomerExtraFields " );
2025-08-05 23:48:18 +00:00
$nbExtrafields = isset ( $extrafields -> attributes [ 'product_customer_price' ][ 'count' ]) ? $extrafields -> attributes [ 'product_customer_price' ][ 'count' ] : 0 ;
2025-02-11 14:40:47 +00:00
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
$head [ $h ][ 2 ] = 'customerAttributes' ;
$h ++ ;
2024-10-19 07:50:18 +00:00
}
2025-02-11 14:40:47 +00:00
// Supplier prices
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product_fournisseur_price' ));
2019-09-04 13:13:42 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ProductSupplierExtraFields " );
2025-08-05 23:48:18 +00:00
$nbExtrafields = isset ( $extrafields -> attributes [ 'product_fournisseur_price' ][ 'count' ]) ? $extrafields -> attributes [ 'product_fournisseur_price' ][ 'count' ] : 0 ;
2022-09-18 18:50:15 +00:00
if ( $nbExtrafields > 0 ) {
2022-09-22 12:42:58 +00:00
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
2022-09-18 18:50:15 +00:00
}
2019-09-04 13:13:42 +00:00
$head [ $h ][ 2 ] = 'supplierAttributes' ;
$h ++ ;
2019-01-27 10:55:16 +00:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'product_admin' , 'remove' );
2012-06-09 17:16:31 +00:00
2012-05-22 16:35:14 +00:00
return $head ;
2012-03-03 15:33:38 +00:00
}
2016-09-12 15:27:44 +00:00
/**
2024-01-13 18:48:20 +00:00
* Return array head with list of tabs to view object information .
2016-09-12 15:27:44 +00:00
*
2024-10-13 23:59:44 +00:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Array of tabs to show
2016-09-12 15:27:44 +00:00
*/
function product_lot_admin_prepare_head ()
{
2026-06-13 23:09:51 +00:00
global $langs , $conf , $user , $extrafields ;
2022-11-30 21:07:25 +00:00
$extrafields -> fetch_name_optionals_label ( 'product_lot' );
2016-09-12 15:27:44 +00:00
2020-10-31 13:32:18 +00:00
$h = 0 ;
$head = array ();
2016-09-12 15:27:44 +00:00
2025-10-17 00:31:07 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . " /product/admin/product_lot.php " );
2021-03-11 09:02:31 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Parameters' );
$head [ $h ][ 2 ] = 'settings' ;
$h ++ ;
2020-10-31 13:32:18 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'product_lot_admin' );
2016-09-12 15:27:44 +00:00
2026-08-11 14:51:24 +00:00
$head [ $h ][ 0 ] = dolBuildUrl ( DOL_URL_ROOT . '/admin/extrafields.php' , array ( 'elementtype' => 'product_lot' ));
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFields " );
2022-11-30 21:07:25 +00:00
$nbExtrafields = $extrafields -> attributes [ 'product_lot' ][ 'count' ];
if ( $nbExtrafields > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>' ;
}
2020-10-31 13:32:18 +00:00
$head [ $h ][ 2 ] = 'attributes' ;
$h ++ ;
2016-09-12 15:27:44 +00:00
2020-10-31 13:32:18 +00:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'product_lot_admin' , 'remove' );
2016-09-12 15:27:44 +00:00
2020-10-31 13:32:18 +00:00
return $head ;
2016-09-12 15:27:44 +00:00
}
2012-03-03 15:33:38 +00:00
/**
2024-07-03 16:02:11 +00:00
* Show stats for a product
2012-03-03 15:33:38 +00:00
*
2012-03-18 18:23:01 +00:00
* @ param Product $product Product object
* @ param int $socid Thirdparty id
2016-02-17 21:33:02 +00:00
* @ return integer NB of lines shown into array
2012-03-03 15:33:38 +00:00
*/
2019-01-27 14:20:16 +00:00
function show_stats_for_company ( $product , $socid )
2006-08-18 23:16:40 +00:00
{
2024-04-22 13:51:43 +00:00
global $langs , $user , $db , $hookmanager ;
2021-06-11 17:32:25 +00:00
2020-10-14 06:42:57 +00:00
$form = new Form ( $db );
2021-06-12 16:47:29 +00:00
2016-02-17 21:33:02 +00:00
$nblines = 0 ;
2017-08-02 12:10:43 +00:00
print '<tr class="liste_titre">' ;
2026-04-21 11:24:51 +00:00
print '<td class="liste_titre left">' ;
print $form -> textwithpicto ( $langs -> trans ( " Referers " ), $langs -> trans ( " ClinkOnALinkOfColumn " , $langs -> transnoentitiesnoconv ( " Referers " )));
print '</td>' ;
print '<td class="liste_titre right">' . $langs -> trans ( " NbOfThirdParties " ) . '</td>' ;
print '<td class="liste_titre right">' . $langs -> trans ( " NbOfObjectReferers " ) . '</td>' ;
print '<td class="liste_titre right">' . $langs -> trans ( " TotalQuantity " ) . '</td>' ;
2008-08-28 00:31:27 +00:00
print '</tr>' ;
2017-09-17 16:08:23 +00:00
// Customer proposals
2023-02-14 21:56:12 +00:00
if ( isModEnabled ( " propal " ) && $user -> hasRight ( 'propal' , 'lire' )) {
2016-02-17 21:33:02 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_propale ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2008-08-28 00:31:27 +00:00
$langs -> load ( " propal " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/propal.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'propal' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Proposals " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_propale [ 'customers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_propale [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_propale [ 'qty' ], 1 , $langs , 0 , 0 );
2008-08-28 00:31:27 +00:00
print '</td>' ;
print '</tr>' ;
}
2017-09-17 16:08:23 +00:00
// Supplier proposals
2023-05-16 13:36:27 +00:00
if ( isModEnabled ( 'supplier_proposal' ) && $user -> hasRight ( 'supplier_proposal' , 'lire' )) {
2017-09-17 16:08:23 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_proposal_supplier ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2021-02-26 10:09:15 +00:00
$langs -> load ( " supplier_proposal " );
2017-09-17 16:08:23 +00:00
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/supplier_proposal.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'supplier_proposal' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SupplierProposals " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_proposal_supplier [ 'suppliers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_proposal_supplier [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_proposal_supplier [ 'qty' ], 1 , $langs , 0 , 0 );
2017-09-17 16:08:23 +00:00
print '</td>' ;
print '</tr>' ;
}
2022-10-12 13:29:30 +00:00
// Sales orders
2024-02-27 14:30:37 +00:00
if ( isModEnabled ( 'order' ) && $user -> hasRight ( 'commande' , 'lire' )) {
2016-02-17 21:33:02 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_commande ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2008-08-28 00:31:27 +00:00
$langs -> load ( " orders " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/commande.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'order' , 'class="pictofixedwidth"' ) . $langs -> trans ( " CustomersOrders " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande [ 'customers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_commande [ 'qty' ], 1 , $langs , 0 , 0 );
2008-08-28 00:31:27 +00:00
print '</td>' ;
print '</tr>' ;
}
2017-09-17 16:08:23 +00:00
// Supplier orders
2023-11-27 10:39:32 +00:00
if (( isModEnabled ( " fournisseur " ) && ! getDolGlobalString ( 'MAIN_USE_NEW_SUPPLIERMOD' ) && $user -> hasRight ( 'fournisseur' , 'commande' , 'lire' )) || ( isModEnabled ( " supplier_order " ) && $user -> hasRight ( 'supplier_order' , 'lire' ))) {
2016-02-17 21:33:02 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_commande_fournisseur ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2008-08-28 00:31:27 +00:00
$langs -> load ( " orders " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/commande_fournisseur.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'supplier_order' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SuppliersOrders " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande_fournisseur [ 'suppliers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande_fournisseur [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_commande_fournisseur [ 'qty' ], 1 , $langs , 0 , 0 );
2008-08-28 00:31:27 +00:00
print '</td>' ;
print '</tr>' ;
}
2017-09-17 16:08:23 +00:00
// Customer invoices
2024-02-27 14:30:37 +00:00
if ( isModEnabled ( 'invoice' ) && $user -> hasRight ( 'facture' , 'lire' )) {
2016-02-17 21:33:02 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_facture ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2008-08-28 00:31:27 +00:00
$langs -> load ( " bills " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/facture.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " CustomersInvoices " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture [ 'customers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_facture [ 'qty' ], 1 , $langs , 0 , 0 );
2008-08-28 00:31:27 +00:00
print '</td>' ;
print '</tr>' ;
}
2022-06-12 09:05:12 +00:00
// Customer template invoices
2024-02-27 14:30:37 +00:00
if ( isModEnabled ( " invoice " ) && $user -> hasRight ( 'facture' , 'lire' )) {
2022-06-12 09:05:12 +00:00
$nblines ++ ;
$ret = $product -> load_stats_facturerec ( $socid );
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " bills " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/facturerec.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " RecurringInvoiceTemplate " ) . '</a>' ;
2022-06-12 09:05:12 +00:00
print '</td><td class="right">' ;
2025-01-28 13:37:42 +00:00
print $product -> stats_facturerec [ 'customers' ];
2022-06-12 09:05:12 +00:00
print '</td><td class="right">' ;
print $product -> stats_facturerec [ 'nb' ];
print '</td><td class="right">' ;
print $product -> stats_facturerec [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
2017-09-17 16:08:23 +00:00
// Supplier invoices
2023-11-27 10:39:32 +00:00
if (( isModEnabled ( " fournisseur " ) && ! getDolGlobalString ( 'MAIN_USE_NEW_SUPPLIERMOD' ) && $user -> hasRight ( 'fournisseur' , 'facture' , 'lire' )) || ( isModEnabled ( " supplier_invoice " ) && $user -> hasRight ( 'supplier_invoice' , 'lire' ))) {
2016-02-17 21:33:02 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_facture_fournisseur ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2008-08-28 00:31:27 +00:00
$langs -> load ( " bills " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/facture_fournisseur.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'supplier_invoice' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SuppliersInvoices " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture_fournisseur [ 'suppliers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture_fournisseur [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_facture_fournisseur [ 'qty' ], 1 , $langs , 0 , 0 );
2008-08-28 00:31:27 +00:00
print '</td>' ;
print '</tr>' ;
}
2025-01-28 13:37:42 +00:00
// Supplier template invoices
/* TODO
if ( isModEnabled ( " invoice " ) && $user -> hasRight ( 'fournisseur' , 'facture' , 'lire' )) {
$nblines ++ ;
$ret = $product -> load_stats_facture_fournisseurrec ( $socid );
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " bills " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/facture_facturerec.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " RecurringInvoiceTemplate " ) . '</a>' ;
2025-01-28 13:37:42 +00:00
print '</td><td class="right">' ;
print $product -> stats_facturefournrec [ 'customers' ];
print '</td><td class="right">' ;
print $product -> stats_facturefournrec [ 'nb' ];
print '</td><td class="right">' ;
print $product -> stats_facturefournrec [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
*/
2008-08-28 00:31:27 +00:00
2024-04-22 13:26:23 +00:00
// Shipments
if ( isModEnabled ( 'shipping' ) && $user -> hasRight ( 'shipping' , 'lire' )) {
$nblines ++ ;
$ret = $product -> load_stats_sending ( $socid );
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " sendings " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/expedition.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'shipment' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Shipments " ) . '</a>' ;
2024-04-22 13:26:23 +00:00
print '</td><td class="right">' ;
print $product -> stats_expedition [ 'customers' ];
print '</td><td class="right">' ;
print $product -> stats_expedition [ 'nb' ];
print '</td><td class="right">' ;
print $product -> stats_expedition [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
// Receptions
if (( isModEnabled ( " reception " ) && $user -> hasRight ( 'reception' , 'lire' ))) {
$nblines ++ ;
$ret = $product -> load_stats_reception ( $socid );
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " receptions " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/reception.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'reception' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Receptions " ) . '</a>' ;
2024-04-22 13:26:23 +00:00
print '</td><td class="right">' ;
print $product -> stats_reception [ 'suppliers' ];
print '</td><td class="right">' ;
print $product -> stats_reception [ 'nb' ];
print '</td><td class="right">' ;
print $product -> stats_reception [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
2017-09-17 16:08:23 +00:00
// Contracts
2024-02-27 14:30:37 +00:00
if ( isModEnabled ( 'contract' ) && $user -> hasRight ( 'contrat' , 'lire' )) {
2017-09-17 16:08:23 +00:00
$nblines ++ ;
2019-11-13 18:35:39 +00:00
$ret = $product -> load_stats_contrat ( $socid );
2021-02-23 21:03:23 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
2017-09-17 16:08:23 +00:00
$langs -> load ( " contracts " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/contrat.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'contract' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Contracts " ) . '</a>' ;
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_contrat [ 'customers' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_contrat [ 'nb' ];
2019-03-14 13:11:43 +00:00
print '</td><td class="right">' ;
2024-09-29 13:57:05 +00:00
print price ( $product -> stats_contrat [ 'qty' ], 1 , $langs , 0 , 0 );
2017-09-17 16:08:23 +00:00
print '</td>' ;
print '</tr>' ;
}
2020-10-14 08:30:39 +00:00
// BOM
2023-05-16 13:36:27 +00:00
if ( isModEnabled ( 'bom' ) && $user -> hasRight ( 'bom' , 'read' )) {
2020-10-14 08:30:39 +00:00
$nblines ++ ;
$ret = $product -> load_stats_bom ( $socid );
if ( $ret < 0 ) {
2020-10-14 08:34:30 +00:00
setEventMessage ( $product -> error , 'errors' );
2020-10-14 08:30:39 +00:00
}
$langs -> load ( " mrp " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/bom.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'bom' , 'class="pictofixedwidth"' ) . $langs -> trans ( " BOM " ) . '</a>' ;
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
print '</td><td class="right">' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_bom [ 'nb_toconsume' ], $langs -> trans ( " RowMaterial " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_bom [ 'nb_toproduce' ], $langs -> trans ( " Finished " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_bom [ 'qty_toconsume' ], $langs -> trans ( " RowMaterial " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_bom [ 'qty_toproduce' ], $langs -> trans ( " Finished " ));
2020-10-14 08:30:39 +00:00
print '</td>' ;
print '</tr>' ;
}
// MO
2023-10-15 13:32:35 +00:00
if ( isModEnabled ( 'mrp' ) && $user -> hasRight ( 'mrp' , 'read' )) {
2020-10-14 08:30:39 +00:00
$nblines ++ ;
$ret = $product -> load_stats_mo ( $socid );
if ( $ret < 0 ) {
2022-09-18 18:50:15 +00:00
setEventMessages ( $product -> error , $product -> errors , 'errors' );
2020-10-14 08:30:39 +00:00
}
$langs -> load ( " mrp " );
print '<tr><td>' ;
2026-04-21 11:24:51 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stats/mo.php' , [ 'id' => $product -> id ], false , 'anchorundermenu' ) . '">' . img_object ( '' , 'mrp' , 'class="pictofixedwidth"' ) . $langs -> trans ( " MO " ) . '</a>' ;
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'customers_toconsume' ], $langs -> trans ( " ToConsume " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'customers_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'customers_toproduce' ], $langs -> trans ( " QtyToProduce " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'customers_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'nb_toconsume' ], $langs -> trans ( " ToConsume " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'nb_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'nb_toproduce' ], $langs -> trans ( " QtyToProduce " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'nb_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'qty_toconsume' ], $langs -> trans ( " ToConsume " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'qty_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'qty_toproduce' ], $langs -> trans ( " QtyToProduce " ));
2024-07-03 16:02:11 +00:00
print ' ' ;
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $product -> stats_mo [ 'qty_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td>' ;
print '</tr>' ;
}
2024-09-22 22:37:30 +00:00
$parameters = array ( 'socid' => $socid );
2025-03-11 00:43:54 +00:00
$reshook = $hookmanager -> executeHooks ( 'addMoreProductStat' , $parameters , $product , $nblines ); // Note that $action and $object may have been modified by some hooks // TODO: Verify that $nblines is the correct value for argument $action
2022-09-18 18:50:15 +00:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2021-06-09 06:39:06 +00:00
2021-06-08 10:34:26 +00:00
print $hookmanager -> resPrint ;
2020-10-14 08:30:39 +00:00
2021-06-09 06:39:06 +00:00
2016-02-17 21:33:02 +00:00
return $nblines ++ ;
2006-08-18 23:16:40 +00:00
}
2023-02-17 08:44:38 +00:00
/**
2023-02-17 09:24:59 +00:00
* Show stats for product batch
2023-02-17 08:44:38 +00:00
*
2023-02-17 09:24:59 +00:00
* @ param Productlot $batch Product batch object
* @ param int $socid Thirdparty id
* @ return integer NB of lines shown into array
2023-02-17 08:44:38 +00:00
*/
function show_stats_for_batch ( $batch , $socid )
{
global $conf , $langs , $user , $db , $hookmanager ;
$langs -> LoadLangs ( array ( 'sendings' , 'orders' , 'receptions' ));
$form = new Form ( $db );
$nblines = 0 ;
print '<tr class="liste_titre">' ;
print '<td class="left" width="25%">' . $langs -> trans ( " Referers " ) . '</td>' ;
print '<td class="right" width="25%">' . $langs -> trans ( " NbOfThirdParties " ) . '</td>' ;
print '<td class="right" width="25%">' . $langs -> trans ( " NbOfObjectReferers " ) . '</td>' ;
print '<td class="right" width="25%">' . $langs -> trans ( " TotalQuantity " ) . '</td>' ;
print '</tr>' ;
// Expeditions
2024-03-12 10:07:18 +00:00
if ( isModEnabled ( 'shipping' ) && $user -> hasRight ( 'expedition' , 'lire' )) {
2023-02-17 08:44:38 +00:00
$nblines ++ ;
2023-02-17 09:24:59 +00:00
$ret = $batch -> loadStatsExpedition ( $socid );
2023-02-17 08:44:38 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " bills " );
print '<tr><td>' ;
2025-10-17 00:31:07 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stock/stats/expedition.php' , [ 'id' => $batch -> id ]) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Shipments " ) . '</a>' ;
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
print $batch -> stats_expedition [ 'customers' ];
print '</td><td class="right">' ;
print $batch -> stats_expedition [ 'nb' ];
print '</td><td class="right">' ;
print $batch -> stats_expedition [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
2023-10-15 13:32:35 +00:00
if ( isModEnabled ( " reception " ) && $user -> hasRight ( 'reception' , 'lire' )) {
2023-02-17 08:44:38 +00:00
$nblines ++ ;
2023-02-17 09:24:59 +00:00
$ret = $batch -> loadStatsReception ( $socid );
2023-02-17 08:44:38 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " bills " );
print '<tr><td>' ;
2025-10-17 00:31:07 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stock/stats/reception.php' , [ 'id' => $batch -> id ]) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Receptions " ) . '</a>' ;
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
print $batch -> stats_reception [ 'customers' ];
print '</td><td class="right">' ;
print $batch -> stats_reception [ 'nb' ];
print '</td><td class="right">' ;
print $batch -> stats_reception [ 'qty' ];
print '</td>' ;
print '</tr>' ;
2023-10-15 13:32:35 +00:00
} elseif ( isModEnabled ( 'supplier_order' ) && $user -> hasRight ( 'fournisseur' , 'commande' , 'lire' )) {
2023-02-17 08:44:38 +00:00
$nblines ++ ;
2023-02-17 09:24:59 +00:00
$ret = $batch -> loadStatsSupplierOrder ( $socid );
2023-02-17 08:44:38 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " bills " );
print '<tr><td>' ;
2025-10-17 00:31:07 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stock/stats/commande_fournisseur.php' , [ 'id' => $batch -> id ]) . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SuppliersOrders " ) . '</a>' ;
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
print $batch -> stats_supplier_order [ 'customers' ];
print '</td><td class="right">' ;
print $batch -> stats_supplier_order [ 'nb' ];
print '</td><td class="right">' ;
print $batch -> stats_supplier_order [ 'qty' ];
print '</td>' ;
print '</tr>' ;
}
2023-10-15 13:32:35 +00:00
if ( isModEnabled ( 'mrp' ) && $user -> hasRight ( 'mrp' , 'read' )) {
2023-02-17 08:44:38 +00:00
$nblines ++ ;
2023-02-17 09:24:59 +00:00
$ret = $batch -> loadStatsMo ( $socid );
2023-02-17 08:44:38 +00:00
if ( $ret < 0 ) {
dol_print_error ( $db );
}
$langs -> load ( " mrp " );
print '<tr><td>' ;
2025-10-17 00:31:07 +00:00
print '<a href="' . dolBuildUrl ( DOL_URL_ROOT . '/product/stock/stats/mo.php' , [ 'id' => $batch -> id ]) . '">' . img_object ( '' , 'mrp' , 'class="pictofixedwidth"' ) . $langs -> trans ( " MO " ) . '</a>' ;
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['customers_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'customers_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['customers_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'customers_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['nb_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'nb_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['nb_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'nb_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2023-02-17 08:44:38 +00:00
print '</td><td class="right">' ;
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['qty_toconsume'], $langs->trans("ToConsume")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'qty_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
2023-02-17 09:06:07 +00:00
// print $form->textwithpicto($batch->stats_mo['qty_toproduce'], $langs->trans("QtyToProduce")); Makes no sense with batch, at this moment we don't know batch number
2025-03-11 00:43:54 +00:00
print $form -> textwithpicto (( string ) $batch -> stats_mo [ 'qty_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2023-02-17 08:44:38 +00:00
print '</td>' ;
print '</tr>' ;
}
2024-09-22 22:37:30 +00:00
$parameters = array ( 'socid' => $socid );
2025-03-11 00:43:54 +00:00
$reshook = $hookmanager -> executeHooks ( 'addMoreBatchProductStat' , $parameters , $batch , $nblines ); // Note that $action and $object may have been modified by some hooks // TODO: Verify that $nblines is the correct value for argument $action
2023-02-17 08:44:38 +00:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
print $hookmanager -> resPrint ;
return $nblines ++ ;
}
2019-10-22 16:36:36 +00:00
/**
* Return translation label of a unit key .
* Function kept for backward compatibility .
*
2025-02-08 17:30:42 +00:00
* @ param ? int $unitscale Scale of unit : '0' , '-3' , '6' , ...
2020-12-15 10:39:18 +00:00
* @ param string $measuring_style Style of unit : weight , volume , ...
2024-11-10 17:09:18 +00:00
* @ param int $unitid ID of unit ( rowid in llx_c_units table )
2025-02-08 17:30:42 +00:00
* @ param int < 0 , 1 > $use_short_label 1 = Use short label ( 'g' instead of 'gram' ) . Short labels are not translated .
* @ param ? Translate $outputlangs Language object
2020-12-15 10:39:18 +00:00
* @ return string Unit string
2019-10-22 16:36:36 +00:00
* @ see measuringUnitString () formproduct -> selectMeasuringUnits ()
2019-10-22 16:36:36 +00:00
*/
2025-02-08 17:30:42 +00:00
function measuring_units_string ( $unitscale = null , $measuring_style = '' , $unitid = 0 , $use_short_label = 0 , $outputlangs = null )
2019-10-22 16:36:36 +00:00
{
2024-11-10 17:09:18 +00:00
return measuringUnitString ( $unitid , $measuring_style , $unitscale , $use_short_label , $outputlangs );
2019-10-22 16:36:36 +00:00
}
2008-11-16 01:09:04 +00:00
/**
2010-08-24 18:40:17 +00:00
* Return translation label of a unit key
2012-02-04 13:39:47 +00:00
*
2024-11-10 17:09:18 +00:00
* @ param int $unitid ID of unit ( rowid in llx_c_units table )
2021-10-19 19:38:36 +00:00
* @ param string $measuring_style Style of unit : 'weight' , 'volume' , ... , '' = 'net_measure' for option PRODUCT_ADD_NET_MEASURE
2025-02-08 17:30:42 +00:00
* @ param ? int $unitscale Scale of unit : '0' , '-3' , '6' , ...
* @ param int < 0 , 2 > $use_short_label 1 = Use very short label ( 'g' instead of 'gram' ), not translated . 2 = Use translated short label .
* @ param ? Translate $outputlangs Language object
2024-02-09 10:28:33 +00:00
* @ return string |- 1 Unit string if OK , - 1 if KO
2019-10-22 16:36:36 +00:00
* @ see formproduct -> selectMeasuringUnits ()
2008-11-16 01:09:04 +00:00
*/
2025-02-08 17:30:42 +00:00
function measuringUnitString ( $unitid , $measuring_style = '' , $unitscale = null , $use_short_label = 0 , $outputlangs = null )
2008-11-16 01:09:04 +00:00
{
2019-02-12 15:58:11 +00:00
global $langs , $db ;
2019-11-29 10:32:09 +00:00
global $measuring_unit_cache ;
2019-09-27 18:02:33 +00:00
2020-12-15 10:39:18 +00:00
if ( empty ( $outputlangs )) {
$outputlangs = $langs ;
}
2024-11-10 17:09:18 +00:00
if ( empty ( $measuring_unit_cache [ $unitid . '_' . $measuring_style . '_' . $unitscale . '_' . $use_short_label ])) {
2019-11-29 10:32:09 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php' ;
2020-02-21 16:53:37 +00:00
$measuringUnits = new CUnits ( $db );
2019-11-29 10:32:09 +00:00
2024-11-10 17:09:18 +00:00
if ( $measuring_style == '' && $unitscale == '' ) {
2020-02-11 19:21:53 +00:00
$arrayforfilter = array (
2024-11-10 17:09:18 +00:00
't.rowid' => $unitid ,
2020-02-11 19:21:53 +00:00
't.active' => 1
);
2024-11-10 17:09:18 +00:00
} elseif ( $unitscale !== '' ) {
2019-11-29 10:32:09 +00:00
$arrayforfilter = array (
2024-11-10 17:09:18 +00:00
't.scale' => $unitscale ,
2019-11-29 10:32:09 +00:00
't.unit_type' => $measuring_style ,
't.active' => 1
);
2020-05-21 13:05:19 +00:00
} else {
2019-11-29 10:32:09 +00:00
$arrayforfilter = array (
2024-11-10 17:09:18 +00:00
't.rowid' => $unitid ,
2019-11-29 10:32:09 +00:00
't.unit_type' => $measuring_style ,
't.active' => 1
);
}
$result = $measuringUnits -> fetchAll ( '' , '' , 0 , 0 , $arrayforfilter );
if ( $result < 0 ) {
return - 1 ;
2019-02-12 15:58:11 +00:00
} else {
2019-11-29 10:42:08 +00:00
if ( is_array ( $measuringUnits -> records ) && count ( $measuringUnits -> records ) > 0 ) {
2024-06-23 21:05:50 +00:00
if ( $use_short_label == 1 ) {
2021-02-23 21:03:23 +00:00
$labeltoreturn = $measuringUnits -> records [ key ( $measuringUnits -> records )] -> short_label ;
2024-06-23 21:05:50 +00:00
} elseif ( $use_short_label == 2 ) {
2025-10-28 00:25:30 +00:00
$labeltoreturn = $outputlangs -> transnoentitiesnoconv ( ucfirst (( string ) $measuringUnits -> records [ key ( $measuringUnits -> records )] -> label ) . 'Short' );
2021-02-23 21:03:23 +00:00
} else {
2025-10-28 00:25:30 +00:00
$labeltoreturn = $outputlangs -> transnoentitiesnoconv (( string ) $measuringUnits -> records [ key ( $measuringUnits -> records )] -> label );
2021-02-23 21:03:23 +00:00
}
2019-11-29 10:32:09 +00:00
} else {
$labeltoreturn = '' ;
}
2024-11-10 17:09:18 +00:00
$measuring_unit_cache [ $unitid . '_' . $measuring_style . '_' . $unitscale . '_' . $use_short_label ] = $labeltoreturn ;
2019-11-29 10:32:09 +00:00
return $labeltoreturn ;
2019-02-12 15:58:11 +00:00
}
2020-05-21 13:05:19 +00:00
} else {
2024-11-10 17:09:18 +00:00
return $measuring_unit_cache [ $unitid . '_' . $measuring_style . '_' . $unitscale . '_' . $use_short_label ];
2019-11-29 10:32:09 +00:00
}
2008-11-16 01:09:04 +00:00
}
2018-01-01 21:03:08 +00:00
/**
2019-10-09 09:51:10 +00:00
* Transform a given unit scale into the square of that unit , if known .
2018-01-01 21:03:08 +00:00
*
2024-11-10 17:09:18 +00:00
* @ param int $unitscale Unit scale key ( - 3 , - 2 , - 1 , 0 , 98 , 99. .. )
2018-01-01 21:03:08 +00:00
* @ return int Squared unit key ( - 6 , - 4 , - 2 , 0 , 98 , 99. .. )
2019-03-19 11:03:02 +00:00
* @ see formproduct -> selectMeasuringUnits
2018-01-01 21:03:08 +00:00
*/
2024-11-10 17:09:18 +00:00
function measuring_units_squared ( $unitscale )
2018-01-01 21:03:08 +00:00
{
2019-11-13 18:35:39 +00:00
$measuring_units = array ();
$measuring_units [ 0 ] = 0 ; // m -> m3
2018-01-01 21:03:08 +00:00
$measuring_units [ - 1 ] = - 2 ; // dm-> dm2
$measuring_units [ - 2 ] = - 4 ; // cm -> cm2
$measuring_units [ - 3 ] = - 6 ; // mm -> mm2
$measuring_units [ 98 ] = 98 ; // foot -> foot2
$measuring_units [ 99 ] = 99 ; // inch -> inch2
2024-11-10 17:09:18 +00:00
return $measuring_units [ $unitscale ];
2018-01-01 21:03:08 +00:00
}
/**
2019-10-09 09:51:10 +00:00
* Transform a given unit scale into the cube of that unit , if known
2018-01-01 21:03:08 +00:00
*
2019-10-09 09:51:10 +00:00
* @ param int $unit Unit scale key ( - 3 , - 2 , - 1 , 0 , 98 , 99. .. )
2018-01-01 21:03:08 +00:00
* @ return int Cubed unit key ( - 9 , - 6 , - 3 , 0 , 88 , 89. .. )
2019-03-19 11:03:02 +00:00
* @ see formproduct -> selectMeasuringUnits
2018-01-01 21:03:08 +00:00
*/
function measuring_units_cubed ( $unit )
{
2019-11-13 18:35:39 +00:00
$measuring_units = array ();
$measuring_units [ 0 ] = 0 ; // m -> m2
2018-01-01 21:03:08 +00:00
$measuring_units [ - 1 ] = - 3 ; // dm-> dm3
$measuring_units [ - 2 ] = - 6 ; // cm -> cm3
$measuring_units [ - 3 ] = - 9 ; // mm -> mm3
$measuring_units [ 98 ] = 88 ; // foot -> foot3
$measuring_units [ 99 ] = 89 ; // inch -> inch3
return $measuring_units [ $unit ];
}
2026-01-05 23:09:37 +00:00
/**
* Retrieve and return product for mail template .
*
* @ param int $id The ID of the product to retrieve .
* @ return array < string , mixed >| int <- 1 , - 1 > Return array if OK , - 1 if KO
*/
function getProductForEmailTemplate ( $id )
{
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
global $db , $conf ;
$productarray = array ();
$sql = " SELECT p.rowid as id, p.ref, p.label, p.description, p.entity " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'product' ) . " ) " ;
$sql .= " AND p.rowid = " . (( int ) $id );
$resql = $db -> query ( $sql );
if ( $resql ) {
$productarray = $db -> fetch_array ( $resql );
} else {
dol_print_error ( $db );
return - 1 ;
}
$object = new Product ( $db );
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error , $object -> errors );
}
$entity = ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity );
$productarray [ " image " ] = $object -> show_photos ( 'product' , $conf -> product -> multidir_output [ $entity ], 1 , 1 , 0 , 0 , 0 , 120 , 160 , 1 , '' );
if ( $object -> nbphoto <= 0 ) {
$productarray [ " image " ] = " " ;
}
return $productarray ;
}