*
* 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();
}
llxHeader("","","Fiche produit");
if ($action == 'add')
{
$product = new Product($db);
$product->ref = $HTTP_POST_VARS["ref"];
$product->libelle = $HTTP_POST_VARS["libelle"];
$product->price = $HTTP_POST_VARS["price"];
$product->tva_tx = $HTTP_POST_VARS["tva_tx"];
$product->type = $HTTP_POST_VARS["type"];
$product->envente = $HTTP_POST_VARS["statut"];
$product->description = $HTTP_POST_VARS["desc"];
$product->duration_value = $HTTP_POST_VARS["duration_value"];
$product->duration_unit = $HTTP_POST_VARS["duration_unit"];
$product->seuil_stock_alerte = $HTTP_POST_VARS["seuil_stock_alerte"];
$id = $product->create($user);
$action = '';
}
if ($action == 'addinpropal')
{
$propal = New Propal($db);
$propal->fetch($HTTP_POST_VARS["propalid"]);
$result = $propal->insert_product($id, $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["remise_percent"]);
if ( $result < 0)
{
$mesg = "erreur $result";
}
else
{
$mesg = ucfirst($types[$type]) . ' ajouté à la proposition ';
$mesg .= ''.$propal->ref.'';
}
$action = '';
}
if ($HTTP_POST_VARS["action"] == 'addinfacture' &&
( $user->rights->facture->modifier || $user->rights->facture->creer))
{
$product = new Product($db);
$result = $product->fetch($id);
$facture = New Facture($db);
$facture->fetch($HTTP_POST_VARS["factureid"]);
$facture->addline($HTTP_POST_VARS["factureid"],
addslashes($product->libelle),
$product->price,
$HTTP_POST_VARS["qty"],
$product->tva_tx, $id);
$action = '';
$mesg = 'Produit ajouté à la facture ';
$mesg .= ''.$facture->ref.'';
}
if ($HTTP_POST_VARS["action"] == 'add_fourn' && $cancel <> 'Annuler')
{
$product = new Product($db);
if( $product->fetch($id) )
{
if ($product->add_fournisseur($user, $HTTP_POST_VARS["id_fourn"], $HTTP_POST_VARS["ref_fourn"]) > 0)
{
$action = '';
$mesg = 'Founisseur ajouté';
}
else
{
$action = '';
}
}
}
if ($HTTP_POST_VARS["action"] == 'update' &&
$cancel <> 'Annuler' &&
( $user->rights->produit->modifier || $user->rights->produit->creer))
{
$product = new Product($db);
if ($product->fetch($id))
{
$product->ref = $HTTP_POST_VARS["ref"];
$product->libelle = $HTTP_POST_VARS["libelle"];
$product->price = $HTTP_POST_VARS["price"];
$product->tva_tx = $HTTP_POST_VARS["tva_tx"];
$product->description = $HTTP_POST_VARS["desc"];
$product->envente = $HTTP_POST_VARS["statut"];
$product->seuil_stock_alerte = $HTTP_POST_VARS["seuil_stock_alerte"];
$product->duration_value = $HTTP_POST_VARS["duration_value"];
$product->duration_unit = $HTTP_POST_VARS["duration_unit"];
if ($product->check())
{
if ( $product->update($id, $user))
{
$action = '';
$mesg = 'Fiche mise à jour';
}
else
{
$action = 're-edit';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
else
{
$action = 're-edit';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
}
if ($HTTP_POST_VARS["action"] == 'update_price' &&
$cancel <> 'Annuler' &&
( $user->rights->produit->modifier || $user->rights->produit->creer))
{
$product = new Product($db);
$result = $product->fetch($id);
$product->price = $HTTP_POST_VARS["price"];
if ( $product->update_price($id, $user) > 0 )
{
$action = '';
$mesg = 'Fiche mise à jour';
}
else
{
$action = 'edit_price';
$mesg = 'Fiche non mise à jour !' . " " . $product->mesg_error;
}
}
if ($cancel == 'Annuler')
{
$action = '';
}
/*
*
*
*/
if ($action == 'create')
{
$nbligne=0;
print "
';
}
else
{
if ($id)
{
if ($action <> 're-edit')
{
$product = new Product($db);
$result = $product->fetch($id);
}
if ( $result )
{
if ($action <> 'edit' && $action <> 're-edit')
{
print '