Ajout patch fonction clonage

This commit is contained in:
Laurent Destailleur 2005-09-27 22:19:00 +00:00
parent d972824682
commit 3311eabd7a
2 changed files with 192 additions and 86 deletions

View File

@ -844,10 +844,9 @@ class Product
* \brief Supprime un tarif fournisseur * \brief Supprime un tarif fournisseur
* \param user utilisateur qui défait le lien * \param user utilisateur qui défait le lien
* \param id_fourn id du fournisseur * \param id_fourn id du fournisseur
* \param qty quantité * \param qty quantit
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function remove_price($user, $id_fourn, $qty) function remove_price($user, $id_fourn, $qty)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
@ -870,7 +869,6 @@ class Product
* \param id_fourn id du fournisseur * \param id_fourn id du fournisseur
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function remove_fournisseur($user, $id_fourn) function remove_fournisseur($user, $id_fourn)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur "; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur ";
@ -887,13 +885,73 @@ class Product
} }
} }
/**
* \brief Recopie les prix d'un produit/service sur un autre
* \param fromId Id produit source
* \param toId Id produit cible
* \return int < 0 si erreur, > 0 si ok
*/
function clone_price($fromId, $toId)
{
global $db;
$db->begin();
// les prix
$sql = "insert " .MAIN_DB_PREFIX."product_price ("
. " fk_product, date_price, price, tva_tx, fk_user_author, envente )"
. " select ".$toId . ", date_price, price, tva_tx, fk_user_author, envente "
. " from ".MAIN_DB_PREFIX."product_price "
. " where fk_product = ". $fromId . ";" ;
if ( ! $db->query($sql ) ) {
$db->rollback();
return -1;
}
$db->commit();
return 1;
}
/**
* \brief Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre
* \param fromId Id produit source
* \param toId Id produit cible
* \return int < 0 si erreur, > 0 si ok
*/
function clone_fournisseurs($fromId, $toId)
{
global $db;
$db->begin();
// les fournisseurs
$sql = "insert ".MAIN_DB_PREFIX."product_fournisseur ("
. " datec, fk_product, fk_soc, ref_fourn, fk_user_author )"
. " select now(), ".$toId.", fk_soc, ref_fourn, fk_user_author"
. " from ".MAIN_DB_PREFIX."product_fournisseur "
. " where fk_product = ".$fromId .";" ;
if ( ! $db->query($sql ) ) {
$db->rollback();
return -1;
}
// les prix de fournisseurs.
$sql = "insert ".MAIN_DB_PREFIX."product_fournisseur_price ("
. " datec, fk_product, fk_soc, price, quantity, fk_user )"
. " select now(), ".$toId. ", fk_soc, price, quantity, fk_user"
. " from ".MAIN_DB_PREFIX."product_fournisseur_price"
. " where fk_product = ".$fromId.";";
if ( ! $db->query($sql ) ) {
$db->rollback();
return -1;
}
$db->commit();
return 1;
}
/** /**
* \brief Entre un nombre de piece du produit en stock dans un entrepôt * \brief Entre un nombre de piece du produit en stock dans un entrepôt
* \param id_entrepot id de l'entrepot * \param id_entrepot id de l'entrepot
* \param nbpiece nombre de pieces * \param nbpiece nombre de pieces
*/ */
function create_stock($id_entrepot, $nbpiece) function create_stock($id_entrepot, $nbpiece)
{ {
@ -920,7 +978,6 @@ class Product
* \param nbpiece nombre de pieces * \param nbpiece nombre de pieces
* \param mouvement 0 = ajout, 1 = suppression * \param mouvement 0 = ajout, 1 = suppression
*/ */
function correct_stock($user, $id_entrepot, $nbpiece, $mouvement) function correct_stock($user, $id_entrepot, $nbpiece, $mouvement)
{ {

View File

@ -20,7 +20,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -45,7 +44,6 @@ if (!$user->rights->produit->lire) accessforbidden();
$types[0] = $langs->trans("Product"); $types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service"); $types[1] = $langs->trans("Service");
/* /*
* *
*/ */
@ -103,7 +101,6 @@ if ($_POST["action"] == 'update' &&
if ($product->fetch($_POST["id"])) if ($product->fetch($_POST["id"]))
{ {
$product->ref = $_POST["ref"]; $product->ref = $_POST["ref"];
$product->libelle = $_POST["libelle"];
$product->price = $_POST["price"]; $product->price = $_POST["price"];
$product->tva_tx = $_POST["tva_tx"]; $product->tva_tx = $_POST["tva_tx"];
$product->description = $_POST["desc"]; $product->description = $_POST["desc"];
@ -136,6 +133,53 @@ if ($_POST["action"] == 'update' &&
} }
} }
// clone d'un produit
if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
{
$db->begin();
$product = new Product($db);
$originalId = $_GET["id"];
if ($product->fetch($_GET["id"]) > 0)
{
$product->ref = "Clone ".$product->ref;
$product->envente = 0;
$product->id = null;
if ($product->check())
{
$id = $product->create($user);
if ($id > 0)
{
// $product->clone_fournisseurs($originalId, $id);
$db->commit();
Header("Location: fiche.php?id=$id");
}
else if ($id == -3)
{
$db->rollback();
$_error = 1;
$_GET["action"] = "";
dolibarr_print_error($product->db);
}
else
{
$db->rollback();
dolibarr_print_error($product->db);
}
}
}
else
{
$db->rollback();
dolibarr_print_error($product->db);
}
}
if ($_POST["action"] == 'addinpropal') if ($_POST["action"] == 'addinpropal')
{ {
@ -149,6 +193,7 @@ if ($_POST["action"] == 'addinpropal')
} }
Header("Location: ../comm/propal.php?propalid=".$propal->id); Header("Location: ../comm/propal.php?propalid=".$propal->id);
exit;
} }
/* /*
@ -172,7 +217,7 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
$_POST["remise_percent"]); $_POST["remise_percent"]);
Header("Location: ../compta/facture.php?facid=".$facture->id); Header("Location: ../compta/facture.php?facid=".$facture->id);
exit;
} }
if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel")) if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel"))
@ -197,6 +242,7 @@ if ($_POST["cancel"] == $langs->trans("Cancel"))
{ {
$action = ''; $action = '';
Header("Location: fiche.php?id=".$_POST["id"]); Header("Location: fiche.php?id=".$_POST["id"]);
exit;
} }
@ -361,6 +407,7 @@ if ($_GET["id"])
$head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id;
$head[$h][1] = $langs->trans('Referers'); $head[$h][1] = $langs->trans('Referers');
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id; $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id;
$head[$h][1] = $langs->trans('Documents'); $head[$h][1] = $langs->trans('Documents');
$h++; $h++;
@ -561,6 +608,8 @@ if ($_GET["action"] == '')
if ( $user->rights->produit->creer) if ( $user->rights->produit->creer)
{ {
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>'; print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>';
print '<a class="tabAction" href="fiche.php?action=clone&amp;id='.$product->id.'">'.$langs->trans("CreateCopy").'</a>';
} }
} }