* Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2012 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 3 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"); $id=GETPOST('id','int'); $ref=GETPOST('ref','alpha'); $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $cancel=GETPOST('cancel','alpha'); $key=GETPOST('key'); $parent=GETPOST('parent'); // Security check 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); $mesg = ''; $product = new Product($db); $productid=0; if ($id > 0 || ! empty($ref)) { $result = $product->fetch($id,$ref); $productid=$product->id; $id=$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++) { if ($_POST["prod_id_chk".$i] > 0) { 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 */ $product_fourn = new ProductFournisseur($db); $productstatic = new Product($db); $form = new Form($db); // 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 (! empty($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 (! 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)."'"; $sql.= ' WHERE p.entity IN ('.getEntity("product", 1).')'; if ($key != "") { if (! empty($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 (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1) { $sql.= " AND cp.fk_categorie ='".$db->escape($parent)."'"; } $sql.= " ORDER BY p.ref ASC"; $resql = $db->query($sql); } //print $sql; llxHeader("","",$langs->trans("CardProduct".$product->type)); 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 > 0 || ! empty($ref)) { /* if ($result) { if ($action <> 'edit' && $action <> 'search' && $action <> 're-edit') { // mode visu print ''; print ""; $nblignes=6; if ($product->isproduct() && ! empty($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(); $prods_arbo=$product->get_arbo_each_prod(); $nbofsubproducts=count($prods_arbo); print ''; dol_fiche_end(); // List of products into this virtual product if (count($prods_arbo) > 0) { print ''; } // Number of parent virtual 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").''; print $form->textwithpicto($nbofsubproducts, $langs->trans('IfZeroItIsNotAVirtualProduct')); print '
'; print ''.$langs->trans("ProductAssociationList").'
'; print ''; foreach($prods_arbo as $value) { $productstatic->id=$value['id']; $productstatic->type=$value['type']; $productstatic->ref=$value['fullpath']; if (! empty($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 ''; print ''; if (! empty($conf->stock->enabled)) print ''; print ''; } print '
'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].($value['nb_total'] > $value['nb']?'->'.$value['nb_total']:'').')    '.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')    '.$langs->trans("Stock").' : '.$productstatic->stock_reel.'
'; print '
'.$langs->trans("ParentProductsNumber").''; print $form->textwithpicto(count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct')); print '
'; 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 ($user->rights->produit->lire || $user->rights->service->lire) { print ''; print ""; $nblignes=6; if ($product->isproduct() && ! empty($conf->stock->enabled)) $nblignes++; if ($product->isservice()) $nblignes++; // Reference print ''; print ''; // Label print ''; print ''; if (empty($conf->global->PRODUIT_MULTIPRICES)) { // Price print ''; // Price minimum print ''; } // Number of subproducts $prodsfather = $product->getFather(); //Parent Products $product->get_sousproduits_arbo(); // Defined $product->sousprod $prods_arbo=$product->get_arbo_each_prod(); $nbofsubproducts=count($prods_arbo); print ''; print ''; // List of subproducts if (count($prods_arbo) > 0) { $atleastonenotdefined=0; print ''; } // Number of parent virtual 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("SellingPrice").''; 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 '
'.$langs->trans("MinPrice").''; 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 '
'.$langs->trans("AssociatedProductsNumber").''; print $form->textwithpicto($nbofsubproducts, $langs->trans('IfZeroItIsNotAVirtualProduct')); print '
'; print $langs->trans("ProductAssociationList").'
'; print ''; foreach($prods_arbo as $value) { $productstatic->id=$value['id']; $productstatic->type=$value['type']; //print '
'.$productstatic->ref.'
'; //print $productstatic->getNomUrl(1).'
'; //var_dump($value); print ''; if ($value['level'] <= 1) { $notdefined=0; $productstatic->ref=$value['fullpath']; print ''; print ''; $totalline=price2num($value['nb'] * $product_fourn->fourn_unitprice, 'MT'); $total+=$totalline; print ''; if (! empty($conf->stock->enabled)) print ''; // Real stock } else { $productstatic->ref=$value['label']; print ''; print ''; // Real stock } print ''; } print ''; print ''; print ''; if (! empty($conf->stock->enabled)) print ''; print ''; print '
'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')'; 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); else { print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++; } } print ''.($notdefined?'':price($totalline,'','',0,0,-1,$conf->currency)).''.$langs->trans("Stock").': '.$value['stock'].''; for ($i=0; $i < $value['level']; $i++) { print '     '; } print $productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')'; print ''; if (! empty($conf->stock->enabled)) print '
'.$langs->trans("TotalBuyingPriceMin").': '; if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')'; print ''.($atleastonenotdefined?'':price($total,'','',0,0,-1,$conf->currency)).' 
'; print '
'.$langs->trans("ParentProductsNumber").''; print $form->textwithpicto(count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct')); print '
'; 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(); // 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 '
'; $rowspan=1; if (! empty($conf->categorie->enabled)) $rowspan++; print_fiche_titre($langs->trans("ProductToAddSearch"),'',''); print '
'; print ''; print ''; print ''; if (! empty($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, $parent).'
'; print '
'; } // List of products 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("Qty").''; print '
'.$langs->trans("NoMatchFound").'
'.$productstatic->getNomUrl(1,'',24).''.$labeltoshow.''; print '
'; print ''; if($num > 0) { print '
trans("Update").'">'; print '     '; print '
'; } print '
'; } } } llxFooter(); $db->close(); ?>