*
* 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$
*
*/
require("./pre.inc.php");
require("../propal.class.php");
require("../facture.class.php");
$user->getrights('produit');
$user->getrights('propale');
$user->getrights('facture');
$mesg = '';
if (!$user->rights->produit->lire)
{
accessforbidden();
}
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->duration_value = $_POST["duration_value"];
$product->duration_unit = $_POST["duration_unit"];
$product->seuil_stock_alerte = $_POST["seuil_stock_alerte"];
$id = $product->create($user);
Header("Location: fiche.php?id=$id");
}
if ($_POST["action"] == 'update' &&
$_POST["cancel"] <> 'Annuler' &&
( $user->rights->produit->modifier || $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->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))
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
}
else
{
$_GET["action"] = 're-edit';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
else
{
$_GET["action"] = 're-edit';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
Header("Location: fiche.php?id=".$product->id);
}
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 = "erreur $result";
}
Header("Location: ../comm/propal.php?propalid=".$propal->id);
}
if ($_POST["action"] == 'addinfacture' &&
( $user->rights->facture->modifier || $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);
$action = '';
$mesg = 'Produit ajouté à la facture ';
$mesg .= ''.$facture->ref.'';
}
if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> 'Annuler')
{
$product = new Product($db);
if( $product->fetch($_GET["id"]) )
{
if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0)
{
$action = '';
$mesg = 'Founisseur ajouté';
}
else
{
$action = '';
}
}
}
if ($_GET["action"] == 'remove_fourn')
{
$product = new Product($db);
if( $product->fetch($_GET["id"]) )
{
if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0)
{
$_GET["action"] = '';
$mesg = 'Founisseur supprimé';
}
else
{
$_GET["action"] = '';
}
}
}
if ($_POST["action"] == 'update_price' &&
$_POST["cancel"] <> 'Annuler' &&
( $user->rights->produit->modifier || $user->rights->produit->creer))
{
$product = new Product($db);
$result = $product->fetch($_GET["id"]);
$product->price = ereg_replace(" ","",$_POST["price"]);
if ( $product->update_price($product->id, $user) > 0 )
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
}
else
{
$_GET["action"] = 'edit_price';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
if ($_POST["cancel"] == 'Annuler')
{
$action = '';
Header("Location: fiche.php?id=".$_POST["id"]);
}
llxHeader("","","Fiche produit");
/*
* Création du produit
*
*
*
*
*/
if ($_GET["action"] == 'create')
{
$nbligne=0;
print "
';
}
else
{
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')
{
/*
* Fiche en visu
*/
// Zone recherche
print '