2006-03-20 09:54:48 +01:00
< ? php
2015-05-23 18:52:31 +02:00
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2017-09-15 19:13:40 +02:00
* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2018 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
* Copyright ( C ) 2011 - 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2006-03-20 09:54:48 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-03-20 09:54:48 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2006-03-20 09:54:48 +01:00
*/
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / product / composition / card . php
2008-09-04 17:16:30 +02:00
* \ingroup product
* \brief Page de la fiche produit
*/
2006-03-20 09:54:48 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2010-03-22 14:24:43 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2008-10-23 23:54:30 +02:00
2018-05-26 17:57:30 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'bills' , 'products' , 'stocks' ));
2006-03-20 09:54:48 +01:00
2012-07-09 12:31:21 +02:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
$key = GETPOST ( 'key' );
2012-10-08 20:44:12 +02:00
$parent = GETPOST ( 'parent' );
2012-07-09 12:31:21 +02:00
2009-04-27 22:37:50 +02:00
// Security check
2012-07-09 12:31:21 +02:00
if ( ! empty ( $user -> societe_id )) $socid = $user -> societe_id ;
$fieldvalue = ( ! empty ( $id ) ? $id : ( ! empty ( $ref ) ? $ref : '' ));
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
$result = restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
2009-04-27 22:37:50 +02:00
2015-03-11 14:55:45 +01:00
$object = new Product ( $db );
$objectid = 0 ;
2013-11-14 17:16:17 +01:00
if ( $id > 0 || ! empty ( $ref ))
2008-10-23 23:54:30 +02:00
{
2015-03-11 14:55:45 +01:00
$result = $object -> fetch ( $id , $ref );
$objectid = $object -> id ;
$id = $object -> id ;
2008-10-23 23:54:30 +02:00
}
2006-03-20 09:54:48 +01:00
2011-06-17 09:32:07 +02:00
/*
* Actions
*/
2015-02-24 19:55:59 +01:00
if ( $cancel ) $action = '' ;
2006-03-20 12:34:32 +01:00
// Action association d'un sousproduit
2015-02-24 19:55:59 +01:00
if ( $action == 'add_prod' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
2006-03-20 09:54:48 +01:00
{
2010-03-04 20:42:01 +01:00
$error = 0 ;
2013-11-15 11:43:16 +01:00
for ( $i = 0 ; $i < $_POST [ " max_prod " ]; $i ++ )
2008-10-23 23:54:30 +02:00
{
2015-02-24 19:55:59 +01:00
if ( $_POST [ " prod_qty_ " . $i ] > 0 )
2006-03-20 12:34:32 +01:00
{
2015-03-11 14:55:45 +01:00
if ( $object -> add_sousproduit ( $id , $_POST [ " prod_id_ " . $i ], $_POST [ " prod_qty_ " . $i ], $_POST [ " prod_incdec_ " . $i ]) > 0 )
2008-10-23 23:54:30 +02:00
{
2015-02-24 19:55:59 +01:00
//var_dump($id.' - '.$_POST["prod_id_".$i].' - '.$_POST["prod_qty_".$i]);exit;
2008-10-23 23:54:30 +02:00
$action = 'edit' ;
}
else
{
2010-03-04 20:42:01 +01:00
$error ++ ;
2008-10-23 23:54:30 +02:00
$action = 're-edit' ;
2015-03-11 14:55:45 +01:00
if ( $object -> error == " isFatherOfThis " ) {
2015-12-12 10:59:02 +01:00
setEventMessages ( $langs -> trans ( " ErrorAssociationIsFatherOfThis " ), null , 'errors' );
2017-06-12 16:26:25 +02:00
}
else
2015-12-12 10:59:02 +01:00
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-07-20 01:43:46 +02:00
}
2008-10-23 23:54:30 +02:00
}
}
else
{
2015-03-11 14:55:45 +01:00
if ( $object -> del_sousproduit ( $id , $_POST [ " prod_id_ " . $i ]) > 0 )
2008-10-23 23:54:30 +02:00
{
$action = 'edit' ;
}
else
{
2010-03-04 20:42:01 +01:00
$error ++ ;
2008-10-23 23:54:30 +02:00
$action = 're-edit' ;
2015-12-12 10:59:02 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2008-10-23 23:54:30 +02:00
}
}
}
2010-03-04 20:42:01 +01:00
if ( ! $error )
{
2015-03-11 14:55:45 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2010-03-04 20:42:01 +01:00
exit ;
}
2006-03-20 09:54:48 +01:00
}
2015-02-24 19:55:59 +01:00
else if ( $action === 'save_composed_product' )
{
2015-02-23 12:19:19 +01:00
$TProduct = GETPOST ( 'TProduct' , 'array' );
2016-06-09 21:22:07 +02:00
if ( ! empty ( $TProduct ))
2015-02-24 19:55:59 +01:00
{
foreach ( $TProduct as $id_product => $row )
{
2015-03-11 14:55:45 +01:00
if ( $row [ 'qty' ] > 0 ) $object -> update_sousproduit ( $id , $id_product , $row [ 'qty' ], isset ( $row [ 'incdec' ]) ? 1 : 0 );
else $object -> del_sousproduit ( $id , $id_product );
2015-02-23 12:19:19 +01:00
}
2016-06-09 21:22:07 +02:00
setEventMessages ( 'RecordSaved' , null );
2015-02-23 12:19:19 +01:00
}
2015-02-24 19:55:59 +01:00
$action = '' ;
2011-06-17 09:32:07 +02:00
}
/*
* View
*/
2013-11-14 17:16:17 +01:00
$product_fourn = new ProductFournisseur ( $db );
$productstatic = new Product ( $db );
$form = new Form ( $db );
2008-10-23 10:10:59 +02:00
// action recherche des produits par mot-cle et/ou par categorie
2011-10-05 23:49:05 +02:00
if ( $action == 'search' )
2006-03-20 09:54:48 +01:00
{
2011-06-17 09:32:07 +02:00
$current_lang = $langs -> getDefaultLang ();
2017-09-15 19:13:40 +02:00
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type as type, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,' ;
2014-11-15 11:59:02 +01:00
$sql .= ' p.fk_product_type, p.tms as datem' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) $sql .= ', pl.label as labelm, pl.description as descriptionm' ;
2006-03-20 09:54:48 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p' ;
2009-04-27 22:37:50 +02:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'categorie_product as cp ON p.rowid = cp.fk_product' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_lang as pl ON pl.fk_product = p.rowid AND lang=' " . ( $current_lang ) . " ' " ;
2017-05-30 18:50:54 +02:00
$sql .= ' WHERE p.entity IN (' . getEntity ( 'product' ) . ')' ;
2012-02-11 10:18:09 +01:00
if ( $key != " " )
2006-03-20 09:54:48 +01:00
{
2014-11-15 11:59:02 +01:00
// For natural search
$params = array ( 'p.ref' , 'p.label' , 'p.description' , 'p.note' );
// multilang
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ))
2011-06-17 09:32:07 +02:00
{
2014-11-15 11:59:02 +01:00
$params [] = 'pl.label' ;
$params [] = 'pl.description' ;
$params [] = 'pl.note' ;
2011-06-17 09:32:07 +02:00
}
2014-11-15 11:59:02 +01:00
if ( ! empty ( $conf -> barcode -> enabled )) {
$params [] = 'p.barcode' ;
2011-06-17 09:32:07 +02:00
}
2014-11-15 11:59:02 +01:00
$sql .= natural_search ( $params , $key );
2006-03-20 09:54:48 +01:00
}
2012-10-08 20:44:12 +02:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $parent ) && $parent != - 1 )
2006-03-20 09:54:48 +01:00
{
2012-10-08 20:44:12 +02:00
$sql .= " AND cp.fk_categorie =' " . $db -> escape ( $parent ) . " ' " ;
2006-03-20 09:54:48 +01:00
}
2009-07-16 22:41:55 +02:00
$sql .= " ORDER BY p.ref ASC " ;
2009-06-08 20:14:37 +02:00
2011-09-20 15:32:16 +02:00
$resql = $db -> query ( $sql );
2006-03-20 09:54:48 +01:00
}
2008-10-23 10:10:59 +02:00
2016-08-10 07:40:40 +02:00
$title = $langs -> trans ( 'ProductServiceCard' );
$helpurl = '' ;
$shortlabel = dol_trunc ( $object -> label , 16 );
if ( GETPOST ( " type " ) == '0' || ( $object -> type == Product :: TYPE_PRODUCT ))
{
$title = $langs -> trans ( 'Product' ) . " " . $shortlabel . " - " . $langs -> trans ( 'AssociatedProducts' );
$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos' ;
}
if ( GETPOST ( " type " ) == '1' || ( $object -> type == Product :: TYPE_SERVICE ))
{
$title = $langs -> trans ( 'Service' ) . " " . $shortlabel . " - " . $langs -> trans ( 'AssociatedProducts' );
$helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios' ;
}
2009-07-16 22:41:55 +02:00
2016-08-10 07:40:40 +02:00
llxHeader ( '' , $title , $helpurl );
2006-03-20 09:54:48 +01:00
2015-04-07 03:00:11 +02:00
$head = product_prepare_head ( $object );
2015-03-11 14:55:45 +01:00
$titre = $langs -> trans ( " CardProduct " . $object -> type );
2015-03-30 03:14:07 +02:00
$picto = ( $object -> type == Product :: TYPE_SERVICE ? 'service' : 'product' );
2017-05-22 15:20:52 +02:00
dol_fiche_head ( $head , 'subproduct' , $titre , - 1 , $picto );
2006-03-20 09:54:48 +01:00
2011-06-17 09:32:07 +02:00
2013-10-26 16:34:31 +02:00
if ( $id > 0 || ! empty ( $ref ))
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
/*
* Fiche en mode edition
*/
2013-10-26 16:34:31 +02:00
if ( $user -> rights -> produit -> lire || $user -> rights -> service -> lire )
2008-10-23 23:54:30 +02:00
{
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/product/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-12 16:26:25 +02:00
$shownav = 1 ;
if ( $user -> societe_id && ! in_array ( 'product' , explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL ))) $shownav = 0 ;
2017-09-26 10:58:24 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , $shownav , 'ref' , '' , '' , '' , 0 , '' , '' , 0 );
2017-06-12 16:26:25 +02:00
2016-10-24 20:56:48 +02:00
if ( $object -> type != Product :: TYPE_SERVICE || empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
{
2017-05-22 15:20:52 +02:00
print '<div class="fichecenter">' ;
2017-06-12 16:26:25 +02:00
print '<div class="underbanner clearboth"></div>' ;
2013-11-14 20:54:40 +01:00
2017-06-12 18:22:51 +02:00
print '<table class="border tableforfield" width="100%">' ;
2017-05-22 15:20:52 +02:00
// Nature
if ( $object -> type != Product :: TYPE_SERVICE )
{
2017-09-15 19:13:40 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Nature " ) . '</td><td>' ;
2017-05-22 15:20:52 +02:00
print $object -> getLibFinished ();
print '</td></tr>' ;
}
2017-06-12 18:22:51 +02:00
2017-05-22 15:20:52 +02:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
{
// Price
2017-09-15 19:13:40 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " SellingPrice " ) . '</td><td>' ;
2017-05-22 15:20:52 +02:00
if ( $object -> price_base_type == 'TTC' )
{
print price ( $object -> price_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
}
else
{
print price ( $object -> price ) . ' ' . $langs -> trans ( $object -> price_base_type ? $object -> price_base_type : 'HT' );
}
print '</td></tr>' ;
2017-06-12 18:22:51 +02:00
2017-05-22 15:20:52 +02:00
// Price minimum
print '<tr><td>' . $langs -> trans ( " MinPrice " ) . '</td><td>' ;
if ( $object -> price_base_type == 'TTC' )
{
print price ( $object -> price_min_ttc ) . ' ' . $langs -> trans ( $object -> price_base_type );
}
else
{
print price ( $object -> price_min ) . ' ' . $langs -> trans ( $object -> price_base_type ? $object -> price_base_type : 'HT' );
}
print '</td></tr>' ;
}
print '</table>' ;
print '</div>' ;
2016-10-24 20:56:48 +02:00
}
2015-03-11 14:55:45 +01:00
dol_fiche_end ();
2016-09-18 13:58:17 +02:00
print '<br>' ;
2017-06-12 16:26:25 +02:00
2015-03-11 14:55:45 +01:00
$prodsfather = $object -> getFather (); // Parent Products
2016-05-12 19:44:49 +02:00
$object -> get_sousproduits_arbo (); // Load $object->sousprods
2017-06-12 16:26:25 +02:00
$prods_arbo = $object -> get_arbo_each_prod ();
2015-03-11 14:55:45 +01:00
$nbofsubsubproducts = count ( $prods_arbo ); // This include sub sub product into nb
$prodschild = $object -> getChildsArbo ( $id , 1 );
$nbofsubproducts = count ( $prodschild ); // This include only first level of childs
// Number of parent virtual products
2015-05-03 21:15:08 +02:00
//print $form->textwithpicto($langs->trans("ParentProductsNumber").': '.count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct'));
2015-03-11 14:55:45 +01:00
2015-05-03 21:15:08 +02:00
//if (count($prodsfather) > 0)
//{
2017-05-22 15:20:52 +02:00
print load_fiche_titre ( $langs -> trans ( " ProductParentList " ), '' , '' );
2015-05-03 21:15:08 +02:00
print '<table class="centpercent noborder">' ;
print '<tr class="liste_titre">' ;
2016-05-04 13:49:05 +02:00
print '<td>' . $langs -> trans ( 'ParentProducts' ) . '</td>' ;
2015-05-03 21:15:08 +02:00
print '<td>' . $langs -> trans ( 'Label' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '</td>' ;
if ( count ( $prodsfather ) > 0 )
{
$class = 'pair' ;
foreach ( $prodsfather as $value )
{
$idprod = $value [ " id " ];
$productstatic -> id = $idprod ; // $value["id"];
$productstatic -> type = $value [ " fk_product_type " ];
$productstatic -> ref = $value [ 'ref' ];
$productstatic -> label = $value [ 'label' ];
2015-10-29 12:28:28 +01:00
$productstatic -> entity = $value [ 'entity' ];
2015-05-03 21:15:08 +02:00
$class = ( $class == 'impair' ) ? 'pair' : 'impair' ;
print '<tr class="' . $class . '">' ;
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . '</td>' ;
print '<td>' . $productstatic -> label . '</td>' ;
print '<td>' . $value [ 'qty' ] . '</td>' ;
print '</tr>' ;
}
}
else
2015-03-11 14:55:45 +01:00
{
2015-06-19 06:06:46 +02:00
print '<tr class="impair">' ;
2016-06-07 15:58:02 +02:00
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2015-03-11 14:55:45 +01:00
print '</tr>' ;
}
print '</table>' ;
2015-05-03 21:15:08 +02:00
//}
2015-03-11 14:55:45 +01:00
print '<br>' . " \n " ;
2010-03-04 20:42:01 +01:00
// Number of subproducts
2015-05-03 21:15:08 +02:00
//print $form->textwithpicto($langs->trans("AssociatedProductsNumber").': '.(empty($conf->global->PRODUCT_SHOW_SUB_SUB_PRODUCTS)?$nbofsubproducts:$nbofsubsubproducts), $langs->trans('IfZeroItIsNotAVirtualProduct'));
2009-07-16 22:41:55 +02:00
2010-03-04 20:42:01 +01:00
// List of subproducts
2015-05-03 21:15:08 +02:00
//if (count($prods_arbo) > 0)
//{
2013-11-15 11:43:16 +01:00
$atleastonenotdefined = 0 ;
2017-05-22 15:20:52 +02:00
print load_fiche_titre ( $langs -> trans ( " ProductAssociationList " ), '' , '' );
2015-02-24 19:55:59 +01:00
print '<form name="formComposedProduct" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="post">' ;
2015-02-23 12:19:19 +01:00
print '<input type="hidden" name="action" value="save_composed_product" />' ;
print '<input type="hidden" name="id" value="' . $id . '" />' ;
2015-02-24 19:55:59 +01:00
2015-03-11 14:55:45 +01:00
print '<table class="centpercent noborder">' ;
2015-02-24 19:55:59 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'ComposedProduct' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Label' ) . '</td>' ;
print '<td align="right" colspan="2">' . $langs -> trans ( 'MinSupplierPrice' ) . '</td>' ;
2016-05-04 14:43:40 +02:00
print '<td align="right" colspan="2">' . $langs -> trans ( 'MinCustomerPrice' ) . '</td>' ;
2015-02-24 19:55:59 +01:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td align="right">' . $langs -> trans ( 'Stock' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2015-02-25 23:04:13 +01:00
print '<td align="center">' . $langs -> trans ( 'ComposedProductIncDecStock' ) . '</td>' ;
2015-03-11 14:55:45 +01:00
print '</tr>' . " \n " ;
2015-02-24 19:55:59 +01:00
2015-05-03 21:15:08 +02:00
$class = 'pair' ;
2018-06-22 15:51:26 +02:00
$totalsell = 0 ;
2015-05-22 00:46:53 +02:00
if ( count ( $prods_arbo ))
2010-03-04 20:42:01 +01:00
{
2015-05-22 00:46:53 +02:00
foreach ( $prods_arbo as $value )
2013-11-14 17:16:17 +01:00
{
2016-05-04 14:43:40 +02:00
$productstatic -> fetch ( $value [ 'id' ]);
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
if ( $value [ 'level' ] <= 1 )
2013-11-14 17:16:17 +01:00
{
2015-05-22 00:46:53 +02:00
$class = ( $class == 'impair' ) ? 'pair' : 'impair' ;
print '<tr class="' . $class . '">' ;
$notdefined = 0 ;
$nb_of_subproduct = $value [ 'nb' ];
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . '</td>' ;
print '<td>' . $productstatic -> label . '</td>' ;
// Best buying price
print '<td align="right">' ;
if ( $product_fourn -> find_min_price_product_fournisseur ( $productstatic -> id ) > 0 )
{
2016-05-04 14:43:40 +02:00
print $langs -> trans ( " BuyingPriceMinShort " ) . ': ' ;
2015-05-22 00:46:53 +02:00
if ( $product_fourn -> product_fourn_price_id > 0 ) print $product_fourn -> display_price_product_fournisseur ( 0 , 0 );
else { print $langs -> trans ( " NotDefined " ); $notdefined ++ ; $atleastonenotdefined ++ ; }
}
print '</td>' ;
2018-06-19 18:26:37 +02:00
// For avoid a non-numeric value
$fourn_unitprice = ( ! empty ( $product_fourn -> fourn_unitprice ) ? $product_fourn -> fourn_unitprice : 0 );
$fourn_remise_percent = ( ! empty ( $product_fourn -> fourn_remise_percent ) ? $product_fourn -> fourn_remise_percent : 0 );
$fourn_remise = ( ! empty ( $product_fourn -> fourn_remise ) ? $product_fourn -> fourn_remise : 0 );
2018-06-22 15:51:26 +02:00
$totalline = price2num ( $value [ 'nb' ] * ( $fourn_unitprice * ( 1 - $fourn_remise_percent / 100 ) - $fourn_remise ), 'MT' );
2015-05-22 00:46:53 +02:00
$total += $totalline ;
2017-06-12 16:26:25 +02:00
2015-05-22 00:46:53 +02:00
print '<td align="right">' ;
2018-06-19 18:26:37 +02:00
print ( $notdefined ? '' : ( $value [ 'nb' ] > 1 ? $value [ 'nb' ] . 'x' : '' ) . price ( $fourn_unitprice , '' , '' , 0 , 0 , - 1 , $conf -> currency ));
2015-05-22 00:46:53 +02:00
print '</td>' ;
2016-05-04 14:43:40 +02:00
// Best selling price
$pricesell = $productstatic -> price ;
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
{
2018-06-22 15:51:26 +02:00
$pricesell = 'Variable' ;
}
else
{
$totallinesell = price2num ( $value [ 'nb' ] * ( $pricesell ), 'MT' );
$totalsell += $totallinesell ;
2016-05-04 14:43:40 +02:00
}
print '<td align="right" colspan="2">' ;
2018-06-23 17:11:19 +02:00
print ( $notdefined ? '' : ( $value [ 'nb' ] > 1 ? $value [ 'nb' ] . 'x' : '' ));
2018-06-23 12:57:41 +02:00
if ( is_numeric ( $pricesell )) print price ( $pricesell , '' , '' , 0 , 0 , - 1 , $conf -> currency );
2018-06-22 15:51:26 +02:00
else print $langs -> trans ( $pricesell );
2016-05-04 14:43:40 +02:00
print '</td>' ;
2017-06-12 16:26:25 +02:00
2015-05-22 00:46:53 +02:00
// Stock
if ( ! empty ( $conf -> stock -> enabled )) print '<td align="right">' . $value [ 'stock' ] . '</td>' ; // Real stock
// Qty + IncDec
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )
{
print '<td align="center"><input type="text" value="' . $nb_of_subproduct . '" name="TProduct[' . $productstatic -> id . '][qty]" size="4" /></td>' ;
print '<td align="center"><input type="checkbox" name="TProduct[' . $productstatic -> id . '][incdec]" value="1" ' . ( $value [ 'incdec' ] == 1 ? 'checked' : '' ) . ' /></td>' ;
}
else {
print '<td>' . $nb_of_subproduct . '</td>' ;
print '<td>' . ( $value [ 'incdec' ] == 1 ? 'x' : '' ) . '</td>' ;
}
print '</tr>' . " \n " ;
2013-11-14 17:16:17 +01:00
}
2016-05-12 19:44:49 +02:00
else
2015-05-22 00:46:53 +02:00
{
$hide = '' ;
2016-05-12 19:44:49 +02:00
if ( empty ( $conf -> global -> PRODUCT_SHOW_SUB_SUB_PRODUCTS )) $hide = ' hideobject' ; // By default, we do not show this. It makes screen very difficult to understand
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
$class = ( $class == 'impair' ) ? 'pair' : 'impair' ;
print '<tr class="' . $class . $hide . '" id="sub-' . $value [ 'id_parent' ] . '">' ;
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
//$productstatic->ref=$value['label'];
$productstatic -> ref = $value [ 'ref' ];
print '<td>' ;
for ( $i = 0 ; $i < $value [ 'level' ]; $i ++ ) print ' ' ; // Add indentation
print $productstatic -> getNomUrl ( 1 , 'composition' ) . '</td>' ;
print '<td>' . $productstatic -> label . '</td>' ;
2015-02-24 19:55:59 +01:00
2016-05-12 19:44:49 +02:00
// Best buying price
2015-05-22 00:46:53 +02:00
print '<td> </td>' ;
print '<td> </td>' ;
2016-05-12 19:44:49 +02:00
// Best selling price
print '<td> </td>' ;
print '<td> </td>' ;
2017-06-12 16:26:25 +02:00
2015-05-22 00:46:53 +02:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td></td>' ; // Real stock
print '<td align="center">' . $value [ 'nb' ] . '</td>' ;
print '<td> </td>' ;
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '</tr>' . " \n " ;
}
2015-02-24 19:55:59 +01:00
}
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '<tr class="liste_total">' ;
print '<td class="liste_total"></td>' ;
print '<td class="liste_total"></td>' ;
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
// Minimum buying price
print '<td class="liste_total" align="right">' ;
2016-05-04 14:43:40 +02:00
print $langs -> trans ( " TotalBuyingPriceMinShort " );
2015-05-22 00:46:53 +02:00
print '</td>' ;
2015-02-24 19:55:59 +01:00
2015-05-22 00:46:53 +02:00
print '<td class="liste_total" align="right">' ;
if ( $atleastonenotdefined ) print $langs -> trans ( " Unknown " ) . ' (' . $langs -> trans ( " SomeSubProductHaveNoPrices " ) . ')' ;
print ( $atleastonenotdefined ? '' : price ( $total , '' , '' , 0 , 0 , - 1 , $conf -> currency ));
print '</td>' ;
2015-02-24 19:55:59 +01:00
2016-05-04 14:43:40 +02:00
// Minimum selling price
print '<td class="liste_total" align="right">' ;
print $langs -> trans ( " TotalSellingPriceMinShort " );
print '</td>' ;
print '<td class="liste_total" align="right">' ;
if ( $atleastonenotdefined ) print $langs -> trans ( " Unknown " ) . ' (' . $langs -> trans ( " SomeSubProductHaveNoPrices " ) . ')' ;
print ( $atleastonenotdefined ? '' : price ( $totalsell , '' , '' , 0 , 0 , - 1 , $conf -> currency ));
print '</td>' ;
2017-06-12 16:26:25 +02:00
2015-05-22 00:46:53 +02:00
// Stock
if ( ! empty ( $conf -> stock -> enabled )) print '<td class="liste_total" align="right"> </td>' ;
2015-03-11 14:55:45 +01:00
2015-05-22 00:46:53 +02:00
print '<td align="right" colspan="2">' ;
if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer )
{
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Save' ) . '">' ;
2013-11-14 17:16:17 +01:00
}
2015-05-22 00:46:53 +02:00
print '</td>' ;
print '</tr>' . " \n " ;
2010-03-04 20:42:01 +01:00
}
2015-05-22 00:46:53 +02:00
else
2015-02-24 19:55:59 +01:00
{
2018-02-28 15:29:52 +01:00
$colspan = 8 ;
2015-05-22 00:46:53 +02:00
if ( ! empty ( $conf -> stock -> enabled )) $colspan ++ ;
2015-06-19 00:36:03 +02:00
print '<tr class="impair">' ;
2016-06-07 15:58:02 +02:00
print '<td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2015-05-22 00:46:53 +02:00
print '</tr>' ;
2015-02-24 19:55:59 +01:00
}
2015-05-22 00:46:53 +02:00
2010-03-04 20:42:01 +01:00
print '</table>' ;
2015-02-24 19:55:59 +01:00
/* if ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) {
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Save' ) . '">' ;
} */
2015-02-23 12:19:19 +01:00
print '</form>' ;
2015-05-03 21:15:08 +02:00
//}
2011-08-31 16:55:54 +02:00
2013-10-26 16:34:31 +02:00
// Form with product to add
if (( empty ( $action ) || $action == 'view' || $action == 'edit' || $action == 'search' || $action == 're-edit' ) && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
{
print '<br>' ;
2011-09-07 21:09:21 +02:00
2013-10-26 16:34:31 +02:00
$rowspan = 1 ;
if ( ! empty ( $conf -> categorie -> enabled )) $rowspan ++ ;
2011-09-07 21:09:21 +02:00
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " ProductToAddSearch " ), '' , '' );
2014-09-18 21:18:25 +02:00
print '<form action="' . DOL_URL_ROOT . '/product/composition/card.php?id=' . $id . '" method="POST">' ;
2013-10-26 16:34:31 +02:00
print '<input type="hidden" name="action" value="search">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
2016-05-04 14:43:40 +02:00
print '<div class="inline-block">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print $langs -> trans ( " KeywordFilter " ) . ': ' ;
print '<input type="text" name="key" value="' . $key . '"> ' ;
print '</div>' ;
2013-10-26 16:34:31 +02:00
if ( ! empty ( $conf -> categorie -> enabled ))
{
2015-05-23 23:32:12 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2016-05-04 14:43:40 +02:00
print '<div class="inline-block">' . $langs -> trans ( " CategoryFilter " ) . ': ' ;
2018-02-28 15:27:21 +01:00
print $form -> select_all_categories ( Categorie :: TYPE_PRODUCT , $parent , 'parent' ) . ' </div>' ;
print ajax_combobox ( 'parent' );
2013-10-26 16:34:31 +02:00
}
2016-05-04 14:43:40 +02:00
print '<div class="inline-block">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " Search " ) . '">' ;
print '</div>' ;
2013-10-26 16:34:31 +02:00
print '</form>' ;
2008-10-23 23:54:30 +02:00
}
2009-01-29 21:56:14 +01:00
2013-10-26 16:34:31 +02:00
// List of products
2011-10-05 23:49:05 +02:00
if ( $action == 'search' )
2008-10-23 23:54:30 +02:00
{
2009-07-16 22:41:55 +02:00
print '<br>' ;
2014-09-18 21:18:25 +02:00
print '<form action="' . DOL_URL_ROOT . '/product/composition/card.php?id=' . $id . '" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2011-06-17 09:32:07 +02:00
print '<input type="hidden" name="action" value="add_prod">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
2016-05-04 14:43:40 +02:00
print '<table class="noborder centpercent">' ;
2009-07-16 22:41:55 +02:00
print '<tr class="liste_titre">' ;
2015-02-24 19:55:59 +01:00
print '<th class="liste_titre">' . $langs -> trans ( " ComposedProduct " ) . '</td>' ;
2011-09-07 21:09:21 +02:00
print '<th class="liste_titre">' . $langs -> trans ( " Label " ) . '</td>' ;
2015-02-24 19:55:59 +01:00
//print '<th class="liste_titre" align="center">'.$langs->trans("IsInPackage").'</td>';
2013-11-14 17:16:17 +01:00
print '<th class="liste_titre" align="right">' . $langs -> trans ( " Qty " ) . '</td>' ;
2015-02-25 23:04:13 +01:00
print '<th align="center">' . $langs -> trans ( 'ComposedProductIncDecStock' ) . '</th>' ;
2009-07-16 22:41:55 +02:00
print '</tr>' ;
2008-10-23 23:54:30 +02:00
if ( $resql )
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2009-07-16 22:41:55 +02:00
if ( $num == 0 ) print '<tr><td colspan="4">' . $langs -> trans ( " NoMatchFound " ) . '</td></tr>' ;
2008-10-23 23:54:30 +02:00
while ( $i < $num )
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
$objp = $db -> fetch_object ( $resql );
if ( $objp -> rowid != $id )
2006-03-20 09:54:48 +01:00
{
2008-10-23 23:54:30 +02:00
// check if a product is not already a parent product of this one
2010-03-04 20:42:01 +01:00
$prod_arbo = new Product ( $db );
$prod_arbo -> id = $objp -> rowid ;
2017-09-15 19:08:39 +02:00
// This type is not supported (not required to have virtual products working).
if ( $prod_arbo -> type == Product :: TYPE_ASSEMBLYKIT || $prod_arbo -> type == Product :: TYPE_STOCKKIT )
2006-03-21 10:06:33 +01:00
{
2008-10-23 23:54:30 +02:00
$is_pere = 0 ;
2011-10-05 23:49:05 +02:00
$prod_arbo -> get_sousproduits_arbo ();
2008-10-23 23:54:30 +02:00
// associations sousproduits
$prods_arbo = $prod_arbo -> get_arbo_each_prod ();
2011-09-17 21:49:50 +02:00
if ( count ( $prods_arbo ) > 0 )
2010-03-04 20:42:01 +01:00
{
2009-07-16 22:41:55 +02:00
foreach ( $prods_arbo as $key => $value )
{
if ( $value [ 1 ] == $id )
{
2008-10-23 23:54:30 +02:00
$is_pere = 1 ;
}
}
2006-03-21 12:46:39 +01:00
}
2011-10-05 23:49:05 +02:00
if ( $is_pere == 1 )
{
2008-10-23 23:54:30 +02:00
$i ++ ;
continue ;
2006-03-21 12:46:39 +01:00
}
2006-03-21 10:06:33 +01:00
}
2017-06-12 18:22:51 +02:00
2017-09-15 19:13:40 +02:00
print " \n " . '<tr class="oddeven">' ;
2009-07-16 22:41:55 +02:00
$productstatic -> id = $objp -> rowid ;
$productstatic -> ref = $objp -> ref ;
2015-05-04 03:03:24 +02:00
$productstatic -> label = $objp -> label ;
2009-07-16 22:41:55 +02:00
$productstatic -> type = $objp -> type ;
2015-10-29 12:28:28 +01:00
$productstatic -> entity = $objp -> entity ;
2009-07-16 22:41:55 +02:00
print '<td>' . $productstatic -> getNomUrl ( 1 , '' , 24 ) . '</td>' ;
2011-06-17 09:32:07 +02:00
$labeltoshow = $objp -> label ;
if ( $conf -> global -> MAIN_MULTILANGS && $objp -> labelm ) $labeltoshow = $objp -> labelm ;
print '<td>' . $labeltoshow . '</td>' ;
2015-02-24 19:55:59 +01:00
2015-03-11 14:55:45 +01:00
if ( $object -> is_sousproduit ( $id , $objp -> rowid ))
2008-10-23 23:54:30 +02:00
{
2015-05-07 11:39:26 +02:00
//$addchecked = ' checked';
2015-03-11 14:55:45 +01:00
$qty = $object -> is_sousproduit_qty ;
$incdec = $object -> is_sousproduit_incdec ;
2008-10-23 23:54:30 +02:00
}
else
{
2015-02-24 19:55:59 +01:00
//$addchecked = '';
$qty = 0 ;
$incdec = 0 ;
2008-10-23 23:54:30 +02:00
}
2015-02-24 19:55:59 +01:00
// Contained into package
/* print '<td align="center"><input type="hidden" name="prod_id_' . $i . '" value="' . $objp -> rowid . '">' ;
print '<input type="checkbox" ' . $addchecked . 'name="prod_id_chk' . $i . '" value="' . $objp -> rowid . '"></td>' ; */
// Qty
print '<td align="right"><input type="hidden" name="prod_id_' . $i . '" value="' . $objp -> rowid . '"><input type="text" size="2" name="prod_qty_' . $i . '" value="' . ( $qty ? $qty : '' ) . '"></td>' ;
// Inc Dec
print '<td align="center">' ;
2015-05-07 11:39:26 +02:00
if ( $qty ) print '<input type="checkbox" name="prod_incdec_' . $i . '" value="1" ' . ( $incdec ? 'checked' : '' ) . '>' ;
2015-02-24 19:55:59 +01:00
else
{
// TODO Hide field and show it when setting a qty
2015-05-07 11:39:26 +02:00
print '<input type="checkbox" name="prod_incdec_' . $i . '" value="1" checked>' ;
2015-05-07 11:57:23 +02:00
//print '<input type="checkbox" disabled name="prod_incdec_'.$i.'" value="1" checked>';
2015-02-24 19:55:59 +01:00
}
print '</td>' ;
2008-10-23 23:54:30 +02:00
print '</tr>' ;
}
$i ++ ;
2006-03-20 09:54:48 +01:00
}
2008-10-23 23:54:30 +02:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-03-20 09:54:48 +01:00
}
2008-10-23 23:54:30 +02:00
print '</table>' ;
2011-06-17 09:32:07 +02:00
print '<input type="hidden" name="max_prod" value="' . $i . '">' ;
2011-08-10 13:53:25 +02:00
2010-03-04 20:42:01 +01:00
if ( $num > 0 )
{
2014-11-25 20:13:43 +01:00
print '<br><div class="center">' ;
2015-02-24 19:55:59 +01:00
print '<input type="submit" class="button" name="save" value="' . $langs -> trans ( " Add " ) . '/' . $langs -> trans ( " Update " ) . '">' ;
2014-11-25 20:13:43 +01:00
print ' ' ;
2015-02-24 19:55:59 +01:00
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2010-03-04 20:42:01 +01:00
}
2009-07-16 22:41:55 +02:00
print '</form>' ;
2008-10-23 23:54:30 +02:00
}
}
2006-03-20 09:54:48 +01:00
}
2018-08-14 09:55:58 +02:00
// End of page
2011-10-05 23:49:05 +02:00
llxFooter ();
2006-03-20 09:54:48 +01:00
$db -> close ();