2006-03-20 09:54:48 +01:00
< ? php
2007-01-02 16:27:51 +01:00
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-11-14 20:54:40 +01:00
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2006-03-20 09:54:48 +01:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2006-03-20 09:54:48 +01:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
2011-08-10 12:00:48 +02:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
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
*/
/**
2010-03-22 14:24:43 +01:00
* \file htdocs / product / composition / fiche . 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
2006-03-20 09:54:48 +01:00
$langs -> load ( " bills " );
2006-06-10 11:27:34 +02:00
$langs -> load ( " products " );
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
2006-03-20 09:54:48 +01:00
$mesg = '' ;
2009-04-27 22:37:50 +02:00
2009-07-16 22:41:55 +02:00
$product = new Product ( $db );
2009-07-16 23:22:17 +02:00
$productid = 0 ;
2013-11-14 17:16:17 +01:00
if ( $id > 0 || ! empty ( $ref ))
2008-10-23 23:54:30 +02:00
{
2009-07-16 22:41:55 +02:00
$result = $product -> fetch ( $id , $ref );
2009-07-16 23:22:17 +02:00
$productid = $product -> id ;
2013-11-14 17:16:17 +01:00
$id = $product -> 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
*/
2006-03-20 12:34:32 +01:00
// Action association d'un sousproduit
2008-10-23 23:54:30 +02:00
if ( $action == 'add_prod' &&
$cancel <> $langs -> trans ( " Cancel " ) &&
2009-06-08 20:14:37 +02:00
( $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
{
2013-04-22 01:59:52 +02:00
if ( $_POST [ " prod_id_chk " . $i ] > 0 )
2006-03-20 12:34:32 +01:00
{
2008-10-23 23:54:30 +02:00
if ( $product -> add_sousproduit ( $id , $_POST [ " prod_id_ " . $i ], $_POST [ " prod_qty_ " . $i ]) > 0 )
{
$action = 'edit' ;
}
else
{
2010-03-04 20:42:01 +01:00
$error ++ ;
2008-10-23 23:54:30 +02:00
$action = 're-edit' ;
2010-03-04 20:42:01 +01:00
if ( $product -> error == " isFatherOfThis " ) $mesg = $langs -> trans ( " ErrorAssociationIsFatherOfThis " );
else $mesg = $product -> error ;
2008-10-23 23:54:30 +02:00
}
}
else
{
2010-03-04 20:42:01 +01:00
if ( $product -> 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' ;
2010-03-04 20:42:01 +01:00
$mesg = $product -> error ;
2008-10-23 23:54:30 +02:00
}
}
}
2010-03-04 20:42:01 +01:00
if ( ! $error )
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?id=' . $product -> id );
exit ;
}
2006-03-20 09:54:48 +01:00
}
2010-03-04 20:42:01 +01:00
2011-06-17 09:32:07 +02:00
if ( $cancel == $langs -> trans ( " Cancel " ))
{
$action = '' ;
2012-08-31 05:58:38 +02:00
header ( " Location: fiche.php?id= " . $_POST [ " id " ]);
2011-06-17 09:32:07 +02:00
exit ;
}
/*
* 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 ();
2009-07-16 22:41:55 +02:00
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.price, p.fk_product_type as type' ;
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 ) . " ' " ;
2012-02-11 10:18:09 +01:00
$sql .= ' WHERE p.entity IN (' . getEntity ( " product " , 1 ) . ')' ;
if ( $key != " " )
2006-03-20 09:54:48 +01:00
{
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ))
2011-06-17 09:32:07 +02:00
{
2012-02-11 10:18:09 +01:00
$sql .= " AND (p.ref LIKE '% " . $key . " %' " ;
$sql .= " OR pl.label LIKE '% " . $key . " %') " ;
2011-06-17 09:32:07 +02:00
}
else
{
2012-02-11 10:18:09 +01:00
$sql .= " AND (p.ref LIKE '% " . $key . " %' " ;
$sql .= " OR p.label LIKE '% " . $key . " %') " ;
2011-06-17 09:32:07 +02:00
}
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
}
2011-06-17 09:32:07 +02:00
//print $sql;
2008-10-23 10:10:59 +02:00
2009-07-16 22:41:55 +02:00
2006-06-10 11:27:34 +02:00
llxHeader ( " " , " " , $langs -> trans ( " CardProduct " . $product -> type ));
2006-03-20 09:54:48 +01:00
2008-10-23 23:54:30 +02:00
2011-06-17 09:32:07 +02:00
dol_htmloutput_errors ( $mesg );
2008-10-23 23:54:30 +02:00
2007-05-01 21:54:14 +02:00
$head = product_prepare_head ( $product , $user );
$titre = $langs -> trans ( " CardProduct " . $product -> type );
2009-08-06 15:21:23 +02:00
$picto = ( $product -> type == 1 ? 'service' : 'product' );
dol_fiche_head ( $head , 'subproduct' , $titre , 0 , $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
{
2013-10-26 16:34:31 +02:00
/* if ( $result )
2006-12-01 16:45:52 +01:00
{
2011-10-05 23:49:05 +02:00
if ( $action <> 'edit' && $action <> 'search' && $action <> 're-edit' )
2006-03-20 09:54:48 +01:00
{
2013-10-26 16:34:31 +02:00
// mode visu
2008-10-23 23:54:30 +02:00
print '<table class="border" width="100%">' ;
print " <tr> " ;
$nblignes = 6 ;
2012-09-15 11:21:22 +02:00
if ( $product -> isproduct () && ! empty ( $conf -> stock -> enabled )) $nblignes ++ ;
2008-10-23 23:54:30 +02:00
if ( $product -> isservice ()) $nblignes ++ ;
// Reference
print '<td width="25%">' . $langs -> trans ( " Ref " ) . '</td><td>' ;
2011-11-08 10:18:45 +01:00
print $form -> showrefnav ( $product , 'ref' , '' , 1 , 'ref' );
2008-10-23 23:54:30 +02:00
print '</td></tr>' ;
// Libelle
print '<tr><td>' . $langs -> trans ( " Label " ) . '</td><td>' . $product -> libelle . '</td>' ;
print '</tr>' ;
2010-03-04 20:42:01 +01:00
// Number of subproducts
2013-04-22 12:30:52 +02:00
$prodsfather = $product -> getFather (); // Parent Products
2012-01-22 21:17:02 +01:00
$product -> get_sousproduits_arbo ();
2013-04-22 12:30:52 +02:00
$prods_arbo = $product -> get_arbo_each_prod ();
$nbofsubproducts = count ( $prods_arbo );
2013-04-22 10:33:06 +02:00
print '<tr><td>' . $langs -> trans ( " AssociatedProductsNumber " ) . '</td><td>' ;
print $form -> textwithpicto ( $nbofsubproducts , $langs -> trans ( 'IfZeroItIsNotAVirtualProduct' ));
print '</td>' ;
2008-10-23 23:54:30 +02:00
2011-06-17 09:32:07 +02:00
dol_fiche_end ();
2011-08-10 13:53:25 +02:00
2013-04-22 10:33:06 +02:00
// List of products into this virtual product
2011-10-05 23:49:05 +02:00
if ( count ( $prods_arbo ) > 0 )
2006-03-21 16:33:45 +01:00
{
2008-10-23 23:54:30 +02:00
print '<tr><td colspan="2">' ;
print '<b>' . $langs -> trans ( " ProductAssociationList " ) . '</b><br>' ;
2010-03-04 20:42:01 +01:00
print '<table class="nobordernopadding">' ;
foreach ( $prods_arbo as $value )
2008-10-23 23:54:30 +02:00
{
2010-03-04 20:42:01 +01:00
$productstatic -> id = $value [ 'id' ];
$productstatic -> type = $value [ 'type' ];
$productstatic -> ref = $value [ 'fullpath' ];
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled )) $productstatic -> load_stock ();
2009-04-23 10:18:22 +02:00
//var_dump($value);
//print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>';
2010-03-04 20:42:01 +01:00
//print $value[0]; // This contains a tr line.
print '<tr>' ;
2013-04-22 12:30:52 +02:00
//print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].($value['nb_total'] > $value['nb']?'->'.$value['nb_total']:'').')    </td>';
2013-04-22 13:01:22 +02:00
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . ' (' . $value [ 'nb' ] . ')    </td>' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td>' . $langs -> trans ( " Stock " ) . ' : <b>' . $productstatic -> stock_reel . '</b></td>' ;
2010-03-04 20:42:01 +01:00
print '</tr>' ;
2008-10-23 23:54:30 +02:00
}
2010-03-04 20:42:01 +01:00
print '</table>' ;
2008-10-23 23:54:30 +02:00
print '</td></tr>' ;
2006-03-21 16:33:45 +01:00
}
2011-08-31 16:55:54 +02:00
2013-04-22 10:33:06 +02:00
// Number of parent virtual products
print '<tr><td>' . $langs -> trans ( " ParentProductsNumber " ) . '</td><td>' ;
print $form -> textwithpicto ( count ( $prodsfather ), $langs -> trans ( 'IfZeroItIsNotUsedByVirtualProduct' ));
print '</td>' ;
2011-08-31 16:55:54 +02:00
2011-10-05 23:49:05 +02:00
if ( count ( $prodsfather ) > 0 )
2011-08-18 18:16:04 +02:00
{
print '<tr><td colspan="2">' ;
print '<b>' . $langs -> trans ( " ProductParentList " ) . '</b><br>' ;
print '<table class="nobordernopadding">' ;
foreach ( $prodsfather as $value )
{
$idprod = $value [ " id " ];
$productstatic -> id = $idprod ; // $value["id"];
$productstatic -> type = $value [ " fk_product_type " ];
$productstatic -> ref = $value [ 'label' ];
print '<tr>' ;
2011-09-07 21:18:28 +02:00
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . '</td>' ;;
2011-08-18 18:16:04 +02:00
print '</tr>' ;
}
print '</table>' ;
print '</td></tr>' ;
}
2008-10-23 23:54:30 +02:00
print " </table> \n " ;
2011-06-17 09:32:07 +02:00
dol_fiche_end ();
2008-10-23 23:54:30 +02:00
}
}
2013-10-26 16:34:31 +02: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
{
print '<table class="border" width="100%">' ;
print " <tr> " ;
$nblignes = 6 ;
2012-09-15 11:21:22 +02:00
if ( $product -> isproduct () && ! empty ( $conf -> stock -> enabled )) $nblignes ++ ;
2008-10-23 23:54:30 +02:00
if ( $product -> isservice ()) $nblignes ++ ;
// Reference
print '<td width="25%">' . $langs -> trans ( " Ref " ) . '</td><td>' ;
2011-11-08 10:18:45 +01:00
print $form -> showrefnav ( $product , 'ref' , '' , 1 , 'ref' );
2008-10-23 23:54:30 +02:00
print '</td>' ;
print '</tr>' ;
2010-03-04 20:42:01 +01:00
// Label
2008-10-23 23:54:30 +02:00
print '<tr><td>' . $langs -> trans ( " Label " ) . '</td><td>' . $product -> libelle . '</td>' ;
print '</tr>' ;
2009-07-16 22:41:55 +02:00
2013-11-14 17:16:17 +01:00
if ( empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
2013-11-14 20:54:40 +01:00
{
2013-11-14 17:16:17 +01:00
// Price
print '<tr><td>' . $langs -> trans ( " SellingPrice " ) . '</td><td>' ;
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 );
}
print '</td></tr>' ;
2013-11-14 20:54:40 +01:00
2013-11-14 17:16:17 +01: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 );
}
print '</td></tr>' ;
}
2010-03-04 20:42:01 +01:00
// Number of subproducts
2011-08-18 18:32:08 +02:00
$prodsfather = $product -> getFather (); //Parent Products
2013-11-14 17:16:17 +01:00
$product -> get_sousproduits_arbo (); // Defined $product->sousprod
2013-04-22 13:01:22 +02:00
$prods_arbo = $product -> get_arbo_each_prod ();
$nbofsubproducts = count ( $prods_arbo );
print '<tr><td>' . $langs -> trans ( " AssociatedProductsNumber " ) . '</td><td>' ;
print $form -> textwithpicto ( $nbofsubproducts , $langs -> trans ( 'IfZeroItIsNotAVirtualProduct' ));
print '</td>' ;
2008-10-23 23:54:30 +02:00
print '</tr>' ;
2009-07-16 22:41:55 +02:00
2010-03-04 20:42:01 +01:00
// List of subproducts
2013-11-14 17:16:17 +01:00
if ( count ( $prods_arbo ) > 0 )
2010-03-04 20:42:01 +01:00
{
2013-11-15 11:43:16 +01:00
$atleastonenotdefined = 0 ;
2010-03-04 20:42:01 +01:00
print '<tr><td colspan="2">' ;
2013-11-14 17:16:17 +01:00
print $langs -> trans ( " ProductAssociationList " ) . '<br>' ;
print '<table class="nobordernopadding centpercent">' ;
2010-03-04 20:42:01 +01:00
foreach ( $prods_arbo as $value )
{
$productstatic -> id = $value [ 'id' ];
$productstatic -> type = $value [ 'type' ];
//print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>';
2013-11-14 17:16:17 +01:00
//var_dump($value);
2010-03-04 20:42:01 +01:00
print '<tr>' ;
2013-11-14 17:16:17 +01:00
if ( $value [ 'level' ] <= 1 )
{
2013-11-14 20:54:40 +01:00
$notdefined = 0 ;
2013-11-14 17:16:17 +01:00
$productstatic -> ref = $value [ 'fullpath' ];
2013-11-15 11:43:16 +01:00
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . ' (' . $value [ 'nb' ] . ')</td>' ;
2013-11-14 17:16:17 +01:00
print '<td align="right">' ;
if ( $product_fourn -> find_min_price_product_fournisseur ( $productstatic -> id , $value [ 'nb' ]) > 0 )
{
print $langs -> trans ( " BuyingPriceMinShort " ) . ': ' ;
if ( $product_fourn -> product_fourn_price_id > 0 ) print $product_fourn -> display_price_product_fournisseur ( 0 , 0 );
2013-11-15 11:43:16 +01:00
else { print $langs -> trans ( " NotDefined " ); $notdefined ++ ; $atleastonenotdefined ++ ; }
2013-11-14 17:16:17 +01:00
}
print '</td>' ;
$totalline = price2num ( $value [ 'nb' ] * $product_fourn -> fourn_unitprice , 'MT' );
$total += $totalline ;
2013-11-14 20:54:40 +01:00
print '<td align="right">' . ( $notdefined ? '' : price ( $totalline , '' , '' , 0 , 0 , - 1 , $conf -> currency )) . '</td>' ;
2013-11-14 17:16:17 +01:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td align="right">' . $langs -> trans ( " Stock " ) . ': ' . $value [ 'stock' ] . '</td>' ; // Real stock
}
else {
$productstatic -> ref = $value [ 'label' ];
print '<td>' ;
for ( $i = 0 ; $i < $value [ 'level' ]; $i ++ )
{
2013-11-14 20:54:40 +01:00
print ' ' ;
2013-11-14 17:16:17 +01:00
}
2013-11-15 11:43:16 +01:00
print $productstatic -> getNomUrl ( 1 , 'composition' ) . ' (' . $value [ 'nb' ] . ')</td>' ;
2013-11-14 20:54:40 +01:00
print '<td><td>' ;
print '<td><td>' ;
2013-11-14 17:16:17 +01:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td align="right"></td>' ; // Real stock
}
2010-03-04 20:42:01 +01:00
print '</tr>' ;
}
2013-11-14 20:54:40 +01:00
print '<tr>' ;
2013-11-15 11:43:16 +01:00
print '<td colspan="2">' . $langs -> trans ( " TotalBuyingPriceMin " ) . ': ' ;
if ( $atleastonenotdefined ) print $langs -> trans ( " Unknown " ) . ' (' . $langs -> trans ( " SomeSubProductHaveNoPrices " ) . ')' ;
2014-01-05 15:46:39 +01:00
print '</td>' ;
2013-11-18 14:25:53 +01:00
print '<td align="right">' . ( $atleastonenotdefined ? '' : price ( $total , '' , '' , 0 , 0 , - 1 , $conf -> currency )) . '</td>' ;
2013-11-14 17:16:17 +01:00
if ( ! empty ( $conf -> stock -> enabled )) print '<td class="liste_total" align="right"> </td>' ;
print '</tr>' ;
2010-03-04 20:42:01 +01:00
print '</table>' ;
print '</td></tr>' ;
}
2011-08-31 16:55:54 +02:00
2013-04-22 13:01:22 +02:00
// Number of parent virtual products
print '<tr><td>' . $langs -> trans ( " ParentProductsNumber " ) . '</td><td>' ;
print $form -> textwithpicto ( count ( $prodsfather ), $langs -> trans ( 'IfZeroItIsNotUsedByVirtualProduct' ));
print '</td>' ;
2011-08-31 16:55:54 +02:00
2011-10-05 23:49:05 +02:00
if ( count ( $prodsfather ) > 0 )
2011-08-18 18:32:08 +02:00
{
print '<tr><td colspan="2">' ;
2013-11-14 17:16:17 +01:00
print $langs -> trans ( " ProductParentList " ) . '<br>' ;
2011-08-18 18:32:08 +02:00
print '<table class="nobordernopadding">' ;
foreach ( $prodsfather as $value )
{
$idprod = $value [ " id " ];
$productstatic -> id = $idprod ; // $value["id"];
$productstatic -> type = $value [ " fk_product_type " ];
$productstatic -> ref = $value [ 'label' ];
print '<tr>' ;
2011-09-07 21:18:28 +02:00
print '<td>' . $productstatic -> getNomUrl ( 1 , 'composition' ) . '</td>' ;;
2011-08-18 18:32:08 +02:00
print '</tr>' ;
}
print '</table>' ;
print '</td></tr>' ;
}
2010-03-04 20:42:01 +01:00
2009-07-16 22:41:55 +02:00
print '</table>' ;
2011-06-17 09:32:07 +02:00
dol_fiche_end ();
2011-08-10 13:53:25 +02:00
2009-07-16 22:41:55 +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
2013-10-26 16:34:31 +02:00
print_fiche_titre ( $langs -> trans ( " ProductToAddSearch " ), '' , '' );
print '<form action="' . DOL_URL_ROOT . '/product/composition/fiche.php?id=' . $id . '" method="POST">' ;
print '<table class="border" width="100%"><tr><td>' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print $langs -> trans ( " KeywordFilter " ) . ' ' ;
print '</td>' ;
print '<td><input type="text" name="key" value="' . $key . '">' ;
print '<input type="hidden" name="action" value="search">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '</td>' ;
print '<td rowspan="' . $rowspan . '" valign="middle">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " Search " ) . '">' ;
print '</td></tr>' ;
if ( ! empty ( $conf -> categorie -> enabled ))
{
print '<tr><td>' . $langs -> trans ( " CategoryFilter " ) . ' </td>' ;
2014-01-05 15:46:39 +01:00
print '<td class="maxwidthonsmartphone">' . $form -> select_all_categories ( 0 , $parent ) . '</td></tr>' ;
2013-10-26 16:34:31 +02:00
}
print '</table>' ;
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>' ;
2010-03-22 23:42:11 +01:00
print '<form action="' . DOL_URL_ROOT . '/product/composition/fiche.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 . '">' ;
2009-07-16 22:41:55 +02:00
print '<table class="nobordernopadding" width="100%">' ;
print '<tr class="liste_titre">' ;
2011-09-07 21:09:21 +02:00
print '<th class="liste_titre">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<th class="liste_titre">' . $langs -> trans ( " Label " ) . '</td>' ;
print '<th class="liste_titre" align="center">' . $langs -> trans ( " AddDel " ) . '</td>' ;
2013-11-14 17:16:17 +01:00
print '<th class="liste_titre" align="right">' . $langs -> trans ( " Qty " ) . '</td>' ;
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
$var = true ;
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 ;
2008-10-23 23:54:30 +02:00
if ( $prod_arbo -> type == 2 || $prod_arbo -> type == 3 )
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
}
2009-07-16 22:41:55 +02:00
$var =! $var ;
print " \n <tr " . $bc [ $var ] . " > " ;
$productstatic -> id = $objp -> rowid ;
$productstatic -> ref = $objp -> ref ;
$productstatic -> libelle = $objp -> label ;
$productstatic -> type = $objp -> type ;
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>' ;
2008-10-23 23:54:30 +02:00
if ( $product -> is_sousproduit ( $id , $objp -> rowid ))
{
2011-08-31 16:55:54 +02:00
$addchecked = ' checked="checked"' ;
2008-10-23 23:54:30 +02:00
$qty = $product -> is_sousproduit_qty ;
}
else
{
$addchecked = '' ;
$qty = " 1 " ;
}
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>' ;
2013-11-14 17:16:17 +01:00
print '<td align="right"><input type="text" size="2" name="prod_qty_' . $i . '" value="' . $qty . '"></td>' ;
2008-10-23 23:54:30 +02:00
print '</tr>' ;
}
$i ++ ;
2006-03-20 09:54:48 +01:00
}
2009-01-29 21:56:14 +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 )
{
print '<br><center><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '/' . $langs -> trans ( " Update " ) . '">' ;
print ' <input type="submit" class="button" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</center>' ;
}
2009-07-16 22:41:55 +02:00
print '</form>' ;
2008-10-23 23:54:30 +02:00
}
2009-01-29 21:56:14 +01:00
2008-10-23 23:54:30 +02:00
}
2006-03-20 09:54:48 +01:00
}
2009-07-16 22:41:55 +02:00
2011-10-05 23:49:05 +02:00
llxFooter ();
2006-03-20 09:54:48 +01:00
$db -> close ();
2013-10-26 16:34:31 +02:00
?>