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

@ -840,60 +840,118 @@ 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";
$sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn and quantity = '".$qty."';"; $sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn and quantity = '".$qty."';";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
/** /**
* \brief Délie un fournisseur au produit/service * \brief Délie un fournisseur au produit/service
* \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
* \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 ";
$sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn;"; $sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
}
/**
* \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,19 +133,67 @@ 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')
{ {
$propal = New Propal($db); $propal = New Propal($db);
$propal->fetch($_POST["propalid"]); $propal->fetch($_POST["propalid"]);
$result = $propal->insert_product($_GET["id"], $_POST["qty"], $_POST["remise_percent"]); $result = $propal->insert_product($_GET["id"], $_POST["qty"], $_POST["remise_percent"]);
if ( $result < 0) if ( $result < 0)
{ {
$mesg = $langs->trans("ErrorUnknown").": $result"; $mesg = $langs->trans("ErrorUnknown").": $result";
} }
Header("Location: ../comm/propal.php?propalid=".$propal->id); Header("Location: ../comm/propal.php?propalid=".$propal->id);
exit;
} }
/* /*
@ -156,47 +201,48 @@ if ($_POST["action"] == 'addinpropal')
*/ */
if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer) if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
{ {
$product = new Product($db); $product = new Product($db);
$result = $product->fetch($_GET["id"]); $result = $product->fetch($_GET["id"]);
$facture = New Facture($db); $facture = New Facture($db);
$facture->fetch($_POST["factureid"]); $facture->fetch($_POST["factureid"]);
$facture->addline($_POST["factureid"], $facture->addline($_POST["factureid"],
addslashes($product->libelle), addslashes($product->libelle),
$product->price, $product->price,
$_POST["qty"], $_POST["qty"],
$product->tva_tx, $product->tva_tx,
$product->id, $product->id,
$_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"))
{ {
$product = new Product($db); $product = new Product($db);
if( $product->fetch($_GET["id"]) ) if( $product->fetch($_GET["id"]) )
{ {
if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0) if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0)
{ {
$action = ''; $action = '';
$mesg = $langs->trans("SupplierAdded"); $mesg = $langs->trans("SupplierAdded");
} }
else else
{ {
$action = ''; $action = '';
} }
} }
} }
if ($_POST["cancel"] == $langs->trans("Cancel")) if ($_POST["cancel"] == $langs->trans("Cancel"))
{ {
$action = ''; $action = '';
Header("Location: fiche.php?id=".$_POST["id"]); Header("Location: fiche.php?id=".$_POST["id"]);
exit;
} }
@ -353,17 +399,18 @@ if ($_GET["id"])
$head[$h][1] = $langs->trans('Statistics'); $head[$h][1] = $langs->trans('Statistics');
$h++; $h++;
//erics: pour créer des produits composés de x 'sous' produits //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][0] = DOL_URL_ROOT."/product/pack.php?id=".$product->id;
$head[$h][1] = $langs->trans('Packs'); $head[$h][1] = $langs->trans('Packs');
$h++; $h++;
$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][1] = $langs->trans('Documents'); $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id;
$h++; $head[$h][1] = $langs->trans('Documents');
$h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref);
@ -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>';
} }
} }