* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-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/fournisseurs.php * \ingroup product * \brief Page of tab suppliers for products */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php"); $langs->load("products"); $langs->load("suppliers"); $langs->load("bills"); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action=GETPOST('action', 'alpha'); $socid=GETPOST('socid', 'int'); $error=0; $mesg = ''; // If socid provided by ajax company selector if (! empty($_REQUEST['search_fourn_id'])) { $_GET['id_fourn'] = $_GET['search_fourn_id']; $_POST['id_fourn'] = $_POST['search_fourn_id']; $_REQUEST['id_fourn'] = $_REQUEST['search_fourn_id']; } // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service&fournisseur',$fieldvalue,'product&product','','',$fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); $hookmanager=new HookManager($db); $hookmanager->initHooks(array('pricesuppliercard')); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); if (! $sortfield) $sortfield="s.nom"; if (! $sortorder) $sortorder="ASC"; /* * Actions */ if ($action == 'remove_pf') { $product = new ProductFournisseur($db); if ($product->fetch($id) > 0) { if ($_GET["rowid"]) { $result=$product->remove_product_fournisseur_price($_GET["rowid"]); $action = ''; $mesg = '
'.$langs->trans("PriceRemoved").'.
'; } } } if ($action == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) { $id_fourn=GETPOST("id_fourn"); if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); $ref_fourn=GETPOST("ref_fourn"); if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn"); $quantity=GETPOST("qty"); $tva_tx=price2num(GETPOST('tva_tx','alpha')); if (empty($quantity)) { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'
'; } if (empty($ref_fourn)) { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")).'
'; } if ($id_fourn <= 0) { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")).'
'; } if ($_POST["price"] < 0 || $_POST["price"] == '') { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'
'; } $product = new ProductFournisseur($db); $result=$product->fetch($id); if ($result <= 0) { $error++; $mesg=$product->error; } if (! $error) { $db->begin(); if (! $error) { $ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice if ($ret == -3) { $error++; $product->fetch($product->product_id_already_linked); $productLink = $product->getNomUrl(1,'supplier'); $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink).'
'; } else if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } if (! $error) { $supplier=new Fournisseur($db); $result=$supplier->fetch($id_fourn); $ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx); if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } if (! $error) { $db->commit(); $action=''; } else { $db->rollback(); } } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; Header("Location: fournisseurs.php?id=".$_GET["id"]); exit; } /* * view */ $form = new Form($db); if ($id || $ref) { if ($action <> 're-edit') { $product = new ProductFournisseur($db); $result = $product->fetch($id,$ref); //$result = $product->fetch_fourn_data($_REQUEST["id_fourn"]); llxHeader("","",$langs->trans("CardProduct".$product->type)); } if ($result) { if ($action <> 'edit' && $action <> 're-edit') { /* * En mode visu */ $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); dol_fiche_head($head, 'suppliers', $titre, 0, $picto); print ''; // Reference print ''; print ''; print ''; // Label print ''; // Minimum Price print ''; print ''; // Status (to buy) print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("BuyingPriceMin").''; $product_fourn = new ProductFournisseur($db); if ($product_fourn->find_min_price_product_fournisseur($product->id) > 0) { if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(); else print $langs->trans("NotDefined"); } print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; print $product->getLibStatut(2,1); print '
'; print "\n"; dol_htmloutput_mesg($mesg); // Form to add or update a price if (($action == 'add_price' || $action == 'updateprice' ) && ($user->rights->produit->creer || $user->rights->service->creer)) { $langs->load("suppliers"); if ($_GET["rowid"]) { $product->fetch_product_fournisseur_price($_GET["rowid"]); print_fiche_titre($langs->trans("ChangeSupplierPrice")); } else { print_fiche_titre($langs->trans("AddSupplierPrice")); } print '
'; print ''; print ''; print ''; print ''; // Ref supplier print ''; print ''; // Vat rate print ''; print ''; // Availability if (! empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) { $langs->load("propal"); print ''."\n"; } // Qty min print ''; print ''; print ''; // Price qty min print ''; print ''; print ''; print '
'.$langs->trans("Supplier").''; if ($_GET["rowid"]) { $supplier=new Fournisseur($db); $supplier->fetch($socid); print $supplier->getNomUrl(1); print ''; print ''; print ''; } else { $events=array(); $events[]=array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php',1), 'htmlname' => 'tva_tx', 'params' => array()); print $form->select_company(GETPOST("id_fourn"),'id_fourn','fournisseur=1',1,0,0,$events); if (is_object($hookmanager)) { $parameters=array('filtre'=>"fournisseur=1",'html_name'=>'id_fourn','selected'=>GETPOST("id_fourn"),'showempty'=>1,'prod_id'=>$product->id); echo $hookmanager->executeHooks('formCreateThirdpartyOptions',$parameters,$object,$action); } } print '
'.$langs->trans("SupplierRef").''; if ($_GET["rowid"]) { print $product->fourn_ref; } else { print ''; } print '
'.$langs->trans("VATRate").''; //print $form->load_tva('tva_tx',$product->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country print 'tva_tx).'">'; print '
'.$langs->trans("Availability").''; $form->select_availability($product->fk_availability,"oselDispo",1); print '
'.$langs->trans("QtyMin").''; $quantity = $_REQUEST["qty"] ? $_REQUEST["qty"] : "1"; if ($_GET["rowid"]) { print ''; print $product->fourn_qty; } else { print ''; } print ''.$langs->trans("PriceQtyMin").'fourn_price)?price($product->fourn_price):'')).'">'; print ' '; print $form->select_PriceBaseType(($_POST["price_base_type"]?$_POST["price_base_type"]:$product->price_base_type), "price_base_type"); print '
'; print '
'; print '   '; print '
'; print '
'; } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($action != 'add_price' && $action != 'updateprice') { if ($user->rights->produit->creer || $user->rights->service->creer) { print ''; print $langs->trans("AddSupplierPrice").''; } } print "\n
\n"; print '
'; if ($user->rights->fournisseur->lire) { // Suppliers list title print ''; if ($product->isproduct()) $nblignefour=4; else $nblignefour=4; $param="&id=".$product->id; print ''; print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder); print ''; if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder); print ''; print ''; print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder); print ''; print "\n"; $product_fourn = new ProductFournisseur($db); $product_fourn_list = $product_fourn->list_product_fournisseur_price($product->id); if (count($product_fourn_list)>0) { $var=true; foreach($product_fourn_list as $productfourn) { $var=!$var; print ""; print ''; // Supplier print ''; //Availability if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) { $form->load_cache_availability(); $availability= $form->cache_availability[$productfourn->fk_availability]['label']; print ''; } // Quantity print ''; // VAT rate print ''; // Price quantity print ''; // Unit price print ''; // Modify-Remove print ''; print ''; } } print '
'.$langs->trans("SupplierRef").''.$langs->trans("VATRate").''.$langs->trans("PriceQtyMinHT").'
'.$productfourn->getSocNomUrl(1).''.$productfourn->fourn_ref.''.$availability.''; print $productfourn->fourn_qty; print ''; print vatrate($productfourn->fourn_tva_tx,true); print ''; print $productfourn->fourn_price?price($productfourn->fourn_price):""; print ''; print price($productfourn->fourn_unitprice); //print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" "); print ''; if ($user->rights->produit->creer || $user->rights->service->creer) { print ''.img_edit().""; print ''.img_picto($langs->trans("Remove"),'disable.png').''; } print '
'; } } } } else { print $langs->trans("ErrorUnknown"); } // End of page llxFooter(); $db->close(); ?>