* Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005 Régis Houssin * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ /** \file htdocs/product/fiche.php \ingroup product \brief Page de la fiche produit \version $Revision$ */ require("./pre.inc.php"); require("../propal.class.php"); require("../facture.class.php"); $langs->load("bills"); $mesg = ''; if (!$user->rights->produit->lire) accessforbidden(); $types[0] = $langs->trans("Product"); $types[1] = $langs->trans("Service"); /* * */ if ($_GET["action"] == 'fastappro') { $product = new Product($db); $product->fetch($_GET["id"]); $result = $product->fastappro($user); Header("Location: fiche.php?id=".$_GET["id"]); } // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->produit->creer) { $product = new Product($db); $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->tva_tx = $_POST["tva_tx"]; $product->type = $_POST["type"]; $product->envente = $_POST["statut"]; $product->description = $_POST["desc"]; $product->note = $_POST["note"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $e_product = $product; $id = $product->create($user); if ($id > 0) { Header("Location: fiche.php?id=$id"); } else { if ($id == -3) { $_error = 1; $_GET["action"] = "create"; $_GET["type"] = $_POST["type"]; } } } // Action mise a jour d'un produit ou service if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer) { $product = new Product($db); if ($product->fetch($_POST["id"])) { $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->tva_tx = $_POST["tva_tx"]; $product->description = $_POST["desc"]; $product->note = $_POST["note"]; $product->envente = $_POST["statut"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; if ($product->check()) { if ($product->update($product->id, $user) > 0) { $_GET["action"] = ''; $_GET["id"] = $_POST["id"]; } else { $_GET["action"] = 're-edit'; $_GET["id"] = $_POST["id"]; $mesg = $product->mesg_error; } } else { $_GET["action"] = 're-edit'; $_GET["id"] = $_POST["id"]; $mesg = $langs->trans("ErrorProductBadRefOrLabel"); } } } if ($_POST["action"] == 'addinpropal') { $propal = New Propal($db); $propal->fetch($_POST["propalid"]); $result = $propal->insert_product($_GET["id"], $_POST["qty"], $_POST["remise_percent"]); if ( $result < 0) { $mesg = $langs->trans("ErrorUnknown").": $result"; } Header("Location: ../comm/propal.php?propalid=".$propal->id); } /* * Ajout du produit dans une facture */ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer) { $product = new Product($db); $result = $product->fetch($_GET["id"]); $facture = New Facture($db); $facture->fetch($_POST["factureid"]); $facture->addline($_POST["factureid"], addslashes($product->libelle), $product->price, $_POST["qty"], $product->tva_tx, $product->id, $_POST["remise_percent"]); Header("Location: ../compta/facture.php?facid=".$facture->id); } if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel")) { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0) { $action = ''; $mesg = $langs->trans("SupplierAdded"); } else { $action = ''; } } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; Header("Location: fiche.php?id=".$_POST["id"]); } llxHeader("","",$langs->trans("CardProductService")); /* * Action création du produit */ if ($_GET["action"] == 'create' && $user->rights->produit->creer) { $html = new Form($db); $product = new Product($db); if ($_error == 1) { $product = $e_product; } print '
'; print ''; print ''."\n"; if ($_GET["type"]==0) { $title=$langs->trans("NewProduct"); } if ($_GET["type"]==1) { $title=$langs->trans("NewService"); } print_fiche_titre($title); print ''; print ''; print ''; print ''; print ''; $langs->load("bills"); print ''; print ''; if ($_GET["type"] == 0 && $conf->stick->enabled) { print "".''; } else { print ''; } // Description print '"; if ($_GET["type"] == 1) { print ''; } // Note print '"; print ''; print '
'.$langs->trans("Ref").''; if ($_error == 1) { print $langs->trans("RefAlreadyExists"); } print '
'.$langs->trans("Label").'
'.$langs->trans("SellingPrice").'
'.$langs->trans("VATRate").''; print $html->select_tva("tva_tx",$conf->defaulttx); print '
'.$langs->trans("Status").''; print '
Seuil stock'; print ''; print '
'.$langs->trans("Description").''; print '
'.$langs->trans("Duration").'  '; print ''.$langs->trans("Day").' '; print ''.$langs->trans("Week").' '; print ''.$langs->trans("Month").' '; print ''.$langs->trans("Year").' '; print '
'.$langs->trans("Note").''; print '
 
'; print '
'; } /* * Fiche produit */ if ($_GET["id"]) { if ($_GET["action"] <> 're-edit') { $product = new Product($db); $result = $product->fetch($_GET["id"]); } if ( $result ) { if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { /* * En mode visu */ $h=0; $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans("Card"); $hselected = $h; $h++; $head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id; $head[$h][1] = $langs->trans("Price"); $h++; if($product->type == 0) { if ($user->rights->barcode->lire) { if ($conf->barcode->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$product->id; $head[$h][1] = $langs->trans("BarCode"); $h++; } } } $head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id; $head[$h][1] = $langs->trans("Photos"); $h++; if($product->type == 0) { if ($conf->stock->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; $head[$h][1] = $langs->trans("Stock"); $h++; } } if ($conf->fournisseur->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$product->id; $head[$h][1] = $langs->trans("Suppliers"); $h++; } $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans('Statistics'); $h++; //erics: pour créer des produits composés de x 'sous' produits $head[$h][0] = DOL_URL_ROOT."/product/pack.php?id=".$product->id; $head[$h][1] = $langs->trans('Packs'); $h++; $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id; $head[$h][1] = $langs->trans('Referers'); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); print($mesg); print ''; print ""; $nblignes=6; if ($product->type == 0 && $conf->stock->enabled) $nblignes++; if ($product->type == 1) $nblignes++; // Reference print ''; if ($product->is_photo_available($conf->produit->dir_output)) { // Photo print ''; } print ''; // Libellé print ''; print ''; // Prix print ''; print ''; // Statut print ''; // TVA $langs->load("bills"); print ''; // Stock if ($product->type == 0 && $conf->stock->enabled) { print ''; if ($product->no_stock) { print "'; } // Description print ''; // Durée if ($product->type == 1) { print ''; } // Note print ''; print "
'.$langs->trans("Ref").''.$product->ref.''; $nbphoto=$product->show_photo($conf->produit->dir_output,1); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''.price($product->price).'
'.$langs->trans("Status").''; if ($product->envente) print $langs->trans("OnSell"); else print $langs->trans("NotOnSell"); print '
'.$langs->trans("VATRate").''.$product->tva_tx.' %
'.$langs->trans("Stock").'Pas de définition de stock pour ce produit"; } else { if ($product->stock_reel <= $product->seuil_stock_alerte) { print ''.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte; } else { print "".$product->stock_reel; } } print '
'.$langs->trans("Description").''.nl2br($product->description).'
'.$langs->trans("Duration").''.$product->duration_value.' '; if ($product->duration_value > 1) { $dur=array("d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years")); } else { $dur=array("d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year")); } print $langs->trans($dur[$product->duration_unit])." "; print '
'.$langs->trans("Note").''.nl2br($product->note).'
\n"; print "\n"; } } /* * Fiche en mode edition */ if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) { print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, ""); if ($mesg) { print '
'.$mesg.'

'; } print "
\n"; print ''; print ''; print ''; print ''; print ''; $langs->load("bills"); print ''; print ''; if ($product->type == 0 && $conf->stock->enabled) { print "".''; } else { print ''; } // Description print '"; if ($product->type == 1) { print ''; } // Note print '"; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("VATRate").''; $html = new Form($db); print $html->select_tva("tva_tx", $product->tva_tx); print '
'.$langs->trans("Status").''; print '
Seuil stock'; print ''; print '
'.$langs->trans("Description").''; print '
'.$langs->trans("Duration").''; print '  '; print 'duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); print '  '; print 'duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); print '  '; print 'duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); print '  '; print 'duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); print '
'.$langs->trans("NoteNotVisibleOnBill").''; print '
 '; print '
'; print '
'; } } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($_GET["action"] == '') { if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1) { print ''; print $langs->trans("Order").''; } if ( $user->rights->produit->creer) { print ''.$langs->trans("Edit").''; } } print "\n

\n"; if ($_GET["id"] && $_GET["action"] == '' && $product->envente) { $htmls = new Form($db); $propal = New Propal($db); print ''; // Propals if($user->rights->propale->creer) { $langs->load("propal"); print ''; print ''; print ''; // Liste de "Mes propals" print ''; // Liste de "Other propals" print ''; print ''; } // Factures if($user->rights->facture->creer) { $langs->load("bills"); print ''; // Liste de Mes factures print ''; } print '
'; print_titre($langs->trans("AddToMyProposals")) . ''; print_titre($langs->trans("AddToOtherProposals")) . '
'; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; $sql .=" WHERE p.fk_soc = s.idp AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id; $sql .= " ORDER BY p.datec DESC, tms DESC"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { $i = 0; print ''; $var=true; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ''; print ""; print "\n"; print "\n"; print "\n"; print ''; print ''; print ''; print ''; $i++; } print "
propalid\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."idp\">".dolibarr_trunc($objp->nom,18)."". strftime("%d %b",$objp->dp)."'; print ''.$langs->trans("Discount"); print '%'; print " ".$product->stock_proposition; print ''; print ''; print '
"; } else { print $langs->trans("NoOpenedPropals"); } $db->free($result); } print '
'; $otherprop = $propal->liste_array(1, ' <> s'.$user->id); if (is_array($otherprop) && sizeof($otherprop)) { $var=false; print '
'; print ''.$otherprop; print ''; print ''; print ''; print '
'.$langs->trans("OtherPropals").''; $htmls->select_array("propalid", $otherprop); print '
'. strftime("%d %b",$objp->dp)."\n"; print ''.$langs->trans("Discount"); print '%'; print ''; print ''; print '
'; print '
'; } else { print $langs->trans("NoOtherOpenedPropals"); } print '
'; print_titre($langs->trans("AddToMyBills")); print ''; print_titre($langs->trans("AddToOtherBills")); print '
'; $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id; $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { $i = 0; print ''; $var=true; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ''; print ""; print "\n"; print "\n"; print "\n"; print ''; print ''; print ''; print ''; $i++; } print "
factureid\">".img_object($langs->trans("ShowBills"),"bill")." ".$objp->facnumber."idp\">".dolibarr_trunc($objp->nom,18)."". strftime("%d %b",$objp->df)."'; print ''.$langs->trans("Discount"); print '%'; print ''; print ''; print '
"; } else { print $langs->trans("NoDraftBills"); } $db->free($result); } else { dolibarr_print_error($db); } print '
'; // Liste de Autres factures $var=true; $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author <> ".$user->id; $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { $i = 0; print ''; $var=true; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ''; print ""; print "\n"; print "\n"; print "\n"; print ''; print ''; print ''; print ''; $i++; } print "
factureid\">$objp->facnumberidp\">$objp->nom". strftime("%d %b",$objp->df)."'; print ''.$langs->trans("Discount"); print '%'; print ''; print ''; print '
"; } else { print $langs->trans("NoOtherDraftBills"); } $db->free($result); } else { dolibarr_print_error($db); } print '
'; } $db->close(); llxFooter('$Date$ - $Revision$'); ?>