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 >
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
*/
/**
2022-09-18 18:50:15 +00:00
* \file htdocs / core / lib / product . lib . php
2024-01-13 18:48:20 +00:00
* \brief Ensemble de functions de base pour le module produit et service
2022-09-18 18:50:15 +00:00
* \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
*
2015-03-16 23:21:17 +00:00
* @ param Product $object Object related to tabs
2014-08-30 03:30:37 +00:00
* @ return array 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' );
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' );
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 ();
2014-09-18 19:18:25 +00:00
$head [ $h ][ 0 ] = 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 ) {
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/price.php?id= " . $object -> id ;
$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 " ))
) {
2022-11-08 21:28:59 +00:00
if ( $usercancreadprice ) {
2023-10-17 14:39:55 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/fournisseurs.php?id= " . $object -> id ;
$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' )) {
2010-12-19 11:05:07 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/traduction.php?id= " . $object -> id ;
2022-10-08 15:09:31 +00:00
$head [ $h ][ 1 ] = $langs -> trans ( " Translations " );
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' )) {
2014-09-18 19:18:25 +00:00
$head [ $h ][ 0 ] = 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
$nbFatherAndChild = $object -> hasFatherOrChild ();
2021-02-23 21:03:23 +00:00
if ( $nbFatherAndChild > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbFatherAndChild . '</span>' ;
}
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 ) {
2017-02-08 11:37:38 +00:00
$head [ $h ][ 0 ] = 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 ++ ;
}
2023-11-27 10:39:32 +00:00
if ( $object -> isProduct () || ( $object -> isService () && getDolGlobalString ( 'STOCK_SUPPORTS_SERVICES' ))) { // 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' )) {
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stock/product.php?id= " . $object -> id ;
$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' )) {
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/resource/element_resource.php?element=product&ref=' . $object -> ref ;
$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' )) {
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/resource/element_resource.php?element=service&ref=' . $object -> ref ;
$head [ $h ][ 1 ] = $langs -> trans ( " Resources " );
$head [ $h ][ 2 ] = 'resources' ;
$h ++ ;
}
}
2016-07-23 14:37:21 +00:00
2020-11-16 15:31:05 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stats/facture.php?showmessage=1&id= " . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'Referers' );
$head [ $h ][ 2 ] = 'referers' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stats/card.php?id= " . $object -> id ;
$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 ++ ;
}
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/note.php?id=' . $object -> id ;
$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' ;
2022-08-23 18:01:34 +00:00
if ( isModEnabled ( " product " ) && ( $object -> type == Product :: TYPE_PRODUCT )) {
2021-02-23 21:03:23 +00:00
$upload_dir = $conf -> product -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
}
2022-08-23 18:02:37 +00:00
if ( isModEnabled ( " service " ) && ( $object -> type == Product :: TYPE_SERVICE )) {
2021-02-23 21:03:23 +00:00
$upload_dir = $conf -> service -> multidir_output [ $object -> 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)$' ));
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 )) {
2021-02-23 21:03:23 +00:00
$upload_dir = $conf -> product -> multidir_output [ $object -> entity ] . '/' . get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'product' ) . $object -> id . '/photos' ;
}
2022-08-23 18:02:37 +00:00
if ( isModEnabled ( " service " ) && ( $object -> type == Product :: TYPE_SERVICE )) {
2021-02-23 21:03:23 +00:00
$upload_dir = $conf -> service -> multidir_output [ $object -> entity ] . '/' . get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'product' ) . $object -> id . '/photos' ;
}
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 );
2016-01-23 16:19:34 +00:00
$head [ $h ][ 0 ] = 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
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/agenda.php?id=' . $object -> id ;
$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' ))) {
2020-10-31 13:32:18 +00:00
$head [ $h ][ 1 ] .= '/' ;
$head [ $h ][ 1 ] .= $langs -> trans ( " Agenda " );
}
$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
* @ return array Array of tabs to show
*/
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
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stock/productlot_card.php?id= " . $object -> id ;
$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
2023-02-17 08:44:38 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stock/stats/expedition.php?showmessage=1&id= " . $object -> id ;
$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' ;
$upload_dir = $conf -> productbatch -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> ref );
$nbFiles = count ( dol_dir_list ( $upload_dir , 'files' , 0 , '' , '(\.meta|_preview.*\.png)$' ));
$nbLinks = Link :: count ( $db , $object -> element , $object -> id );
2018-04-12 13:10:37 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/stock/productlot_document.php?id= " . $object -> id ;
$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 ++ ;
}
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/stock/productlot_note.php?id=' . $object -> id ;
$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
/*
2021-02-23 21:03:23 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/info.php?id=' . $object -> id ;
$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-01-13 18:48:20 +00:00
* Return array head with list of tabs to view object information .
2012-03-03 15:33:38 +00:00
*
* @ return array head array with tabs
*/
2014-12-04 12:20:56 +00:00
function product_admin_prepare_head ()
2012-03-03 15:33:38 +00:00
{
2022-09-18 18:50:15 +00:00
global $langs , $conf , $user , $db ;
$extrafields = new ExtraFields ( $db );
$extrafields -> fetch_name_optionals_label ( 'product' );
$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
2012-05-22 16:35:14 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/admin/product.php " ;
$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 (
0 => DOL_URL_ROOT . " /product/admin/price_rules.php " ,
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
2012-05-22 16:35:14 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/admin/product_extrafields.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFields " );
2022-09-18 18:50:15 +00:00
$nbExtrafields = $extrafields -> attributes [ 'product' ][ 'count' ];
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
2019-09-04 13:13:42 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/admin/product_supplier_extrafields.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " ProductSupplierExtraFields " );
2022-09-18 18:50:15 +00:00
$nbExtrafields = $extrafields -> attributes [ 'product_fournisseur_price' ][ 'count' ];
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
*
2022-09-18 18:50:15 +00:00
* @ return array head array with tabs
2016-09-12 15:27:44 +00:00
*/
function product_lot_admin_prepare_head ()
{
2022-11-30 21:07:25 +00:00
global $langs , $conf , $user , $db ;
$extrafields = new ExtraFields ( $db );
$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
2021-03-11 09:02:31 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /product/admin/product_lot.php " ;
$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
2020-10-31 13:32:18 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/product/admin/product_lot_extrafields.php' ;
$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
/**
2012-03-18 18:23:01 +00:00
* Show stats for company
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
{
2021-06-08 13:47:20 +00:00
global $conf , $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">' ;
2019-03-14 13:11:43 +00:00
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>' ;
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="propal.php?id=' . $product -> id . '">' . 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">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_propale [ 'qty' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="supplier_proposal.php?id=' . $product -> id . '">' . 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">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_proposal_supplier [ 'qty' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="commande.php?id=' . $product -> id . '">' . 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">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande [ 'qty' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="commande_fournisseur.php?id=' . $product -> id . '">' . 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">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_commande_fournisseur [ 'qty' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="facture.php?id=' . $product -> id . '">' . 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">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture [ 'qty' ];
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>' ;
print '<a href="facturerec.php?id=' . $product -> id . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " RecurringInvoiceTemplate " ) . '</a>' ;
print '</td><td class="right">' ;
print $product -> stats_facture [ 'customers' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="facture_fournisseur.php?id=' . $product -> id . '">' . 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">' ;
2008-08-28 00:31:27 +00:00
print $product -> stats_facture_fournisseur [ '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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="contrat.php?id=' . $product -> id . '">' . 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">' ;
2017-09-17 16:08:23 +00:00
print $product -> stats_contrat [ 'qty' ];
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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="bom.php?id=' . $product -> id . '">' . 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">' ;
2021-02-26 10:27:03 +00:00
print $form -> textwithpicto ( $product -> stats_bom [ 'nb_toconsume' ], $langs -> trans ( " RowMaterial " ));
print $form -> textwithpicto ( $product -> stats_bom [ 'nb_toproduce' ], $langs -> trans ( " Finished " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2021-02-26 10:27:03 +00:00
print $form -> textwithpicto ( $product -> stats_bom [ 'qty_toconsume' ], $langs -> trans ( " RowMaterial " ));
print $form -> textwithpicto ( $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>' ;
2022-01-28 12:52:42 +00:00
print '<a href="mo.php?id=' . $product -> id . '">' . img_object ( '' , 'mrp' , 'class="pictofixedwidth"' ) . $langs -> trans ( " MO " ) . '</a>' ;
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2020-10-14 08:34:30 +00:00
print $form -> textwithpicto ( $product -> stats_mo [ 'customers_toconsume' ], $langs -> trans ( " ToConsume " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'customers_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'customers_toproduce' ], $langs -> trans ( " QtyToProduce " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'customers_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2020-10-14 08:34:30 +00:00
print $form -> textwithpicto ( $product -> stats_mo [ 'nb_toconsume' ], $langs -> trans ( " ToConsume " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'nb_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'nb_toproduce' ], $langs -> trans ( " QtyToProduce " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'nb_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td><td class="right">' ;
2020-10-14 08:34:30 +00:00
print $form -> textwithpicto ( $product -> stats_mo [ 'qty_toconsume' ], $langs -> trans ( " ToConsume " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'qty_consumed' ], $langs -> trans ( " QtyAlreadyConsumed " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'qty_toproduce' ], $langs -> trans ( " QtyToProduce " ));
print $form -> textwithpicto ( $product -> stats_mo [ 'qty_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
2020-10-14 08:30:39 +00:00
print '</td>' ;
print '</tr>' ;
}
2021-06-08 16:11:59 +00:00
$parameters = array ( 'socid' => $socid );
2021-06-11 17:33:07 +00:00
$reshook = $hookmanager -> executeHooks ( 'addMoreProductStat' , $parameters , $product , $nblines ); // Note that $action and $object may have been modified by some hooks
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>' ;
print '<a href="' . dol_buildpath ( '/product/stock/stats/expedition.php' , 1 ) . '?id=' . $batch -> id . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Shipments " ) . '</a>' ;
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>' ;
print '<a href="' . dol_buildpath ( '/product/stock/stats/reception.php' , 1 ) . '?id=' . $batch -> id . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Receptions " ) . '</a>' ;
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>' ;
print '<a href="' . dol_buildpath ( '/product/stock/stats/commande_fournisseur.php' , 1 ) . '?id=' . $batch -> id . '">' . img_object ( '' , 'bill' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SuppliersOrders " ) . '</a>' ;
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>' ;
print '<a href="' . dol_buildpath ( '/product/stock/stats/mo.php' , 1 ) . '?id=' . $batch -> id . '">' . img_object ( '' , 'mrp' , 'class="pictofixedwidth"' ) . $langs -> trans ( " MO " ) . '</a>' ;
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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $batch -> stats_mo [ 'customers_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $batch -> stats_mo [ 'nb_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $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
2023-02-17 08:44:38 +00:00
print $form -> textwithpicto ( $batch -> stats_mo [ 'qty_produced' ], $langs -> trans ( " QtyAlreadyProduced " ));
print '</td>' ;
print '</tr>' ;
}
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'addMoreBatchProductStat' , $parameters , $batch , $nblines ); // Note that $action and $object may have been modified by some hooks
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 .
*
2020-12-15 10:39:18 +00:00
* @ param string $scale Scale of unit : '0' , '-3' , '6' , ...
* @ param string $measuring_style Style of unit : weight , volume , ...
* @ param int $unit ID of unit ( rowid in llx_c_units table )
* @ param int $use_short_label 1 = Use short label ( 'g' instead of 'gram' ) . Short labels are not translated .
* @ param Translate $outputlangs Language object
* @ return string Unit string
2019-10-22 16:36:36 +00:00
* @ see measuringUnitString () formproduct -> selectMeasuringUnits ()
2019-10-22 16:36:36 +00:00
*/
2020-12-15 10:39:18 +00:00
function measuring_units_string ( $scale = '' , $measuring_style = '' , $unit = 0 , $use_short_label = 0 , $outputlangs = null )
2019-10-22 16:36:36 +00:00
{
2020-12-15 10:39:18 +00:00
return measuringUnitString ( $unit , $measuring_style , $scale , $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
*
2021-10-19 19:38:36 +00:00
* @ param int $unit ID of unit ( rowid in llx_c_units table )
* @ param string $measuring_style Style of unit : 'weight' , 'volume' , ... , '' = 'net_measure' for option PRODUCT_ADD_NET_MEASURE
* @ param string $scale Scale of unit : '0' , '-3' , '6' , ...
* @ param int $use_short_label 1 = Use short label ( 'g' instead of 'gram' ) . Short labels are not translated .
2020-12-15 10:39:18 +00:00
* @ 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
*/
2020-12-15 10:39:18 +00:00
function measuringUnitString ( $unit , $measuring_style = '' , $scale = '' , $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 ;
}
2021-02-23 21:03:23 +00:00
if ( empty ( $measuring_unit_cache [ $unit . '_' . $measuring_style . '_' . $scale . '_' . $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
2021-02-23 21:03:23 +00:00
if ( $measuring_style == '' && $scale == '' ) {
2020-02-11 19:21:53 +00:00
$arrayforfilter = array (
't.rowid' => $unit ,
't.active' => 1
);
2021-02-23 21:03:23 +00:00
} elseif ( $scale !== '' ) {
2019-11-29 10:32:09 +00:00
$arrayforfilter = array (
't.scale' => $scale ,
'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 (
't.rowid' => $unit ,
'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 ) {
2021-02-23 21:03:23 +00:00
if ( $use_short_label ) {
$labeltoreturn = $measuringUnits -> records [ key ( $measuringUnits -> records )] -> short_label ;
} else {
$labeltoreturn = $outputlangs -> transnoentitiesnoconv ( $measuringUnits -> records [ key ( $measuringUnits -> records )] -> label );
}
2019-11-29 10:32:09 +00:00
} else {
$labeltoreturn = '' ;
}
$measuring_unit_cache [ $unit . '_' . $measuring_style . '_' . $scale . '_' . $use_short_label ] = $labeltoreturn ;
return $labeltoreturn ;
2019-02-12 15:58:11 +00:00
}
2020-05-21 13:05:19 +00:00
} else {
2019-11-29 10:32:09 +00:00
return $measuring_unit_cache [ $unit . '_' . $measuring_style . '_' . $scale . '_' . $use_short_label ];
}
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
*
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 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
*/
function measuring_units_squared ( $unit )
{
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
return $measuring_units [ $unit ];
}
/**
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 ];
}