* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2011 Juanjo Menent * * 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 * the Free Software Foundation; either version 2 of the License, or * (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 * along with this program. If not, see . */ /** * \file htdocs/product/composition/fiche.php * \ingroup product * \brief Page de la fiche produit */ require("../../main.inc.php"); 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"); $langs->load("bills"); $langs->load("products"); // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) { $id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:''); } $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); $mesg = ''; $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; $ref=isset($_GET["ref"])?$_GET["ref"]:$_POST["ref"]; $key=isset($_GET["key"])?$_GET["key"]:$_POST["key"]; $catMere=isset($_GET["catMere"])?$_GET["catMere"]:$_POST["catMere"]; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $cancel=isset($_GET["cancel"])?$_GET["cancel"]:$_POST["cancel"]; $product = new Product($db); $productid=0; if ($id || $ref) { $result = $product->fetch($id,$ref); $productid=$product->id; } /* * Actions */ // Action association d'un sousproduit if ($action == 'add_prod' && $cancel <> $langs->trans("Cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) { $error=0; for($i=0;$i<$_POST["max_prod"];$i++) { // print "
: ".$_POST["prod_id_chk".$i]; if($_POST["prod_id_chk".$i] != "") { if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) > 0) { $action = 'edit'; } else { $error++; $action = 're-edit'; if ($product->error == "isFatherOfThis") $mesg = $langs->trans("ErrorAssociationIsFatherOfThis"); else $mesg=$product->error; } } else { if ($product->del_sousproduit($id, $_POST["prod_id_".$i]) > 0) { $action = 'edit'; } else { $error++; $action = 're-edit'; $mesg=$product->error; } } } if (! $error) { header("Location: ".$_SERVER["PHP_SELF"].'?id='.$product->id); exit; } } if ($cancel == $langs->trans("Cancel")) { $action = ''; Header("Location: fiche.php?id=".$_POST["id"]); exit; } /* * View */ // action recherche des produits par mot-cle et/ou par categorie if ($action == 'search') { $current_lang = $langs->getDefaultLang(); $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.price, p.fk_product_type as type'; if ($conf->global->MAIN_MULTILANGS) $sql.= ', pl.label as labelm, pl.description as descriptionm'; $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product'; if ($conf->global->MAIN_MULTILANGS) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND lang='".($current_lang)."'"; $sql.= ' WHERE p.entity IN ('.getEntity("product", 1).')'; if ($key != "") { if ($conf->global->MAIN_MULTILANGS) { $sql.= " AND (p.ref LIKE '%".$key."%'"; $sql.= " OR pl.label LIKE '%".$key."%')"; } else { $sql.= " AND (p.ref LIKE '%".$key."%'"; $sql.= " OR p.label LIKE '%".$key."%')"; } } if ($conf->categorie->enabled && $catMere != -1 and $catMere) { $sql.= " AND cp.fk_categorie ='".$db->escape($catMere)."'"; } $sql.= " ORDER BY p.ref ASC"; $resql = $db->query($sql); } //print $sql; $productstatic = new Product($db); $form = new Form($db); llxHeader("","",$langs->trans("CardProduct".$product->type)); $form = new Form($db); dol_htmloutput_errors($mesg); $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); dol_fiche_head($head, 'subproduct', $titre, 0, $picto); if ($id || $ref) { if ($result) { if ($action <> 'edit' && $action <> 'search' && $action <> 're-edit') { /* * En mode visu */ print ''; print ""; $nblignes=6; if ($product->isproduct() && $conf->stock->enabled) $nblignes++; if ($product->isservice()) $nblignes++; // Reference print ''; // Libelle print ''; print ''; // Number of subproducts $prodsfather = $product->getFather(); //Parent Products $product->get_sousproduits_arbo(); print ''; dol_fiche_end(); // List of subproducts $prods_arbo = $product->get_arbo_each_prod(); if (count($prods_arbo) > 0) { print ''; } // Number of parent products print ''; if (count($prodsfather) > 0) { print ''; } print "
'.$langs->trans("Ref").''; print $form->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("AssociatedProductsNumber").''.count($product->get_arbo_each_prod()).'
'; print ''.$langs->trans("ProductAssociationList").'
'; print ''; foreach($prods_arbo as $value) { $productstatic->id=$value['id']; $productstatic->type=$value['type']; $productstatic->ref=$value['fullpath']; if ($conf->stock->enabled) $productstatic->load_stock(); //var_dump($value); //print '
'.$productstatic->ref.'
'; //print $productstatic->getNomUrl(1).'
'; //print $value[0]; // This contains a tr line. print ''; print ''; if ($conf->stock->enabled) print ''; print ''; } print '
'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')    '.$langs->trans("Stock").' : '.$productstatic->stock_reel.'
'; print '
'.$langs->trans("ParentProductsNumber").''.count($prodsfather).'
'; print ''.$langs->trans("ProductParentList").'
'; print ''; foreach($prodsfather as $value) { $idprod= $value["id"]; $productstatic->id=$idprod;// $value["id"]; $productstatic->type=$value["fk_product_type"]; $productstatic->ref=$value['label']; print ''; print '';; print ''; } print '
'.$productstatic->getNomUrl(1,'composition').'
'; print '
\n"; dol_fiche_end(); } } /* * Fiche en mode edition */ if (($action == 'edit' || $action == 'search' || $action == 're-edit') && ($user->rights->produit->creer || $user->rights->service->creer)) { print ''; print ""; $nblignes=6; if ($product->isproduct() && $conf->stock->enabled) $nblignes++; if ($product->isservice()) $nblignes++; // Reference print ''; print ''; // Label print ''; print ''; // Number of subproducts $prodsfather = $product->getFather(); //Parent Products $product->get_sousproduits_arbo(); print ''; print ''; // List of subproducts $prods_arbo = $product->get_arbo_each_prod(); //var_dump($prods_arbo); if(count($prods_arbo) > 0) { print ''; } // Number of parent products print ''; if (count($prodsfather) > 0) { print ''; } print '
'.$langs->trans("Ref").''; print $form->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("AssociatedProductsNumber").''.count($product->get_arbo_each_prod()).'
'; print ''.$langs->trans("ProductAssociationList").'
'; print ''; foreach($prods_arbo as $value) { $productstatic->id=$value['id']; $productstatic->type=$value['type']; $productstatic->ref=$value['fullpath']; if ($conf->stock->enabled) $productstatic->load_stock(); //var_dump($value); //print '
'.$productstatic->ref.'
'; //print $productstatic->getNomUrl(1).'
'; //print $value[0]; // This contains a tr line. print ''; print ''; if ($conf->stock->enabled) print ''; print ''; } print '
'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')    '.$langs->trans("Stock").' : '.$productstatic->stock_reel.'
'; print '
'.$langs->trans("ParentProductsNumber").''.count($prodsfather).'
'; print ''.$langs->trans("ProductParentList").'
'; print ''; foreach($prodsfather as $value) { $idprod= $value["id"]; $productstatic->id=$idprod;// $value["id"]; $productstatic->type=$value["fk_product_type"]; $productstatic->ref=$value['label']; print ''; print '';; print ''; } print '
'.$productstatic->getNomUrl(1,'composition').'
'; print '
'; dol_fiche_end(); print '
'; $rowspan=1; if ($conf->categorie->enabled) $rowspan++; print_fiche_titre($langs->trans("ProductToAddSearch"),'',''); print '
'; print '
'; print ''; print ''; print ''; print ''; if ($conf->categorie->enabled) { print ''; print ''; } print '
'; print ''; print $langs->trans("KeywordFilter").'   '; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("CategoryFilter").'   '.$form->select_all_categories(0,$catMere).'
'; print '
'; print '
'; if ($action == 'search') { print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; if ($resql) { $num = $db->num_rows($resql); $i=0; $var=true; if($num == 0) print ''; while ($i < $num) { $objp = $db->fetch_object($resql); if($objp->rowid != $id) { // check if a product is not already a parent product of this one $prod_arbo=new Product($db); $prod_arbo->id=$objp->rowid; if ($prod_arbo->type==2 || $prod_arbo->type==3) { $is_pere=0; $prod_arbo->get_sousproduits_arbo(); // associations sousproduits $prods_arbo = $prod_arbo->get_arbo_each_prod(); if (count($prods_arbo) > 0) { foreach($prods_arbo as $key => $value) { if ($value[1]==$id) { $is_pere=1; } } } if ($is_pere==1) { $i++; continue; } } $var=!$var; print "\n"; $productstatic->id=$objp->rowid; $productstatic->ref=$objp->ref; $productstatic->libelle=$objp->label; $productstatic->type=$objp->type; print ''; $labeltoshow=$objp->label; if ($conf->global->MAIN_MULTILANGS && $objp->labelm) $labeltoshow=$objp->labelm; print ''; if($product->is_sousproduit($id, $objp->rowid)) { $addchecked = ' checked="checked"'; $qty=$product->is_sousproduit_qty; } else { $addchecked = ''; $qty="1"; } print ''; print ''; print ''; } $i++; } } else { dol_print_error($db); } print '
'.$langs->trans("Ref").''; print ''.$langs->trans("Label").''; print ''.$langs->trans("AddDel").''; print ''.$langs->trans("Quantity").''; print '
'.$langs->trans("NoMatchFound").'
'.$productstatic->getNomUrl(1,'',24).''.$labeltoshow.''; print '
'; print ''; if($num > 0) { print '
trans("Update").'">'; print '     '; print '
'; } print '
'; } } } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($action == '') { if ($user->rights->produit->creer || $user->rights->service->creer) { print ''.$langs->trans("EditAssociate").''; } } print "\n
\n"; llxFooter(); $db->close(); ?>