Fix: correction erreur d'insertion de produit dans une propale et uniformisation du code
This commit is contained in:
parent
f0b6a0b468
commit
9390e1b613
@ -276,9 +276,14 @@ if ($_POST["action"] == 'addinpropal')
|
|||||||
}
|
}
|
||||||
|
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$soc->fetch($propal->socid,$user);
|
$result=$soc->fetch($propal->socid,$user);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$soc->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$prod = new Product($db, $_GET['id']);
|
$prod = new Product($db);
|
||||||
$result=$prod->fetch($_GET['id']);
|
$result=$prod->fetch($_GET['id']);
|
||||||
if ($result <= 0)
|
if ($result <= 0)
|
||||||
{
|
{
|
||||||
@ -286,29 +291,52 @@ if ($_POST["action"] == 'addinpropal')
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiprix
|
|
||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
|
||||||
{
|
|
||||||
$pu = $prod->multiprices[$soc->price_level];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$pu=$prod->price;
|
|
||||||
}
|
|
||||||
|
|
||||||
$desc = $prod->description;
|
$desc = $prod->description;
|
||||||
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
|
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
|
||||||
|
|
||||||
|
$price_base_type = 'HT';
|
||||||
|
|
||||||
|
// multiprix
|
||||||
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
|
{
|
||||||
|
$pu_ht = $prod->multiprices[$soc->price_level];
|
||||||
|
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];
|
||||||
|
$price_base_type = $prod->multiprices_base_type[$soc->price_level];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ht = $prod->price;
|
||||||
|
$pu_ttc = $prod->price_ttc;
|
||||||
|
$price_base_type = $prod->price_base_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
||||||
|
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
||||||
|
if ($tva_tx != $prod->tva_tx)
|
||||||
|
{
|
||||||
|
if ($price_base_type != 'HT')
|
||||||
|
{
|
||||||
|
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = $propal->addline($propal->id,
|
$result = $propal->addline($propal->id,
|
||||||
$desc,
|
$desc,
|
||||||
$pu,
|
$pu_ht,
|
||||||
$_POST["qty"],
|
$_POST["qty"],
|
||||||
$tva_tx,
|
$tva_tx,
|
||||||
$prod->id,
|
$prod->id,
|
||||||
$_POST["remise_percent"]);
|
$_POST["remise_percent"],
|
||||||
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
|
);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
Header("Location: ../comm/propal.php?propalid=".$propal->id);
|
Header("Location: ".DOL_URL_ROOT."/comm/propal.php?propalid=".$propal->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,76 +348,156 @@ if ($_POST["action"] == 'addinpropal')
|
|||||||
*/
|
*/
|
||||||
if ($_POST["action"] == 'addincommande')
|
if ($_POST["action"] == 'addincommande')
|
||||||
{
|
{
|
||||||
$product = new Product($db);
|
$commande = new Commande($db);
|
||||||
$result = $product->fetch($_GET["id"]);
|
$result=$commande->fetch($_POST["commandeid"]);
|
||||||
|
if ($result <= 0)
|
||||||
$commande = New Commande($db);
|
{
|
||||||
$commande->fetch($_POST["commandeid"]);
|
dolibarr_print_error($db,$commande->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$soc->fetch($commande->socid,$user);
|
$result=$soc->fetch($commande->socid,$user);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$soc->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prod = new Product($db);
|
||||||
|
$result=$prod->fetch($_GET['id']);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$prod->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$desc = $prod->description;
|
||||||
|
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
|
||||||
|
|
||||||
// multiprix
|
// multiprix
|
||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$pu = $product->multiprices[$soc->price_level];
|
$pu_ht = $prod->multiprices[$soc->price_level];
|
||||||
|
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];
|
||||||
|
$price_base_type = $prod->multiprices_base_type[$soc->price_level];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu=$product->price;
|
$pu_ht = $prod->price;
|
||||||
|
$pu_ttc = $prod->price_ttc;
|
||||||
|
$price_base_type = $prod->price_base_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tva_tx = get_default_tva($mysoc,$soc,$product->tva_tx);
|
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
||||||
|
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
||||||
|
if ($tva_tx != $prod->tva_tx)
|
||||||
|
{
|
||||||
|
if ($price_base_type != 'HT')
|
||||||
|
{
|
||||||
|
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = $commande->addline($commande->id,
|
$result = $commande->addline($commande->id,
|
||||||
$product->description,
|
$desc,
|
||||||
$pu,
|
$pu_ht,
|
||||||
$_POST["qty"],
|
$_POST["qty"],
|
||||||
$tva_tx,
|
$tva_tx,
|
||||||
$product->id,
|
$prod->id,
|
||||||
$_POST["remise_percent"]);
|
$_POST["remise_percent"],
|
||||||
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
|
);
|
||||||
|
|
||||||
Header("Location: ../commande/fiche.php?id=".$commande->id);
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ajout du produit dans une facture
|
* Ajout du produit dans une facture
|
||||||
*/
|
*/
|
||||||
if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
|
if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
$product = new Product($db);
|
|
||||||
$result = $product->fetch($_GET["id"]);
|
|
||||||
|
|
||||||
$facture = New Facture($db);
|
$facture = New Facture($db);
|
||||||
$facture->fetch($_POST["factureid"]);
|
$result=$facture->fetch($_POST["factureid"]);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$facture->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$soc->fetch($facture->socid,$user);
|
$soc->fetch($facture->socid,$user);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$soc->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prod = new Product($db);
|
||||||
|
$result = $prod->fetch($_GET["id"]);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$prod->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$desc = $prod->description;
|
||||||
|
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
|
||||||
|
|
||||||
// multiprix
|
// multiprix
|
||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$pu = $product->multiprices[$soc->price_level];
|
$pu_ht = $prod->multiprices[$soc->price_level];
|
||||||
|
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];
|
||||||
|
$price_base_type = $prod->multiprices_base_type[$soc->price_level];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu=$product->price;
|
$pu_ht = $prod->price;
|
||||||
|
$pu_ttc = $prod->price_ttc;
|
||||||
|
$price_base_type = $prod->price_base_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tva_tx = get_default_tva($mysoc,$soc,$product->tva_tx);
|
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
||||||
|
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
||||||
|
if ($tva_tx != $prod->tva_tx)
|
||||||
|
{
|
||||||
|
if ($price_base_type != 'HT')
|
||||||
|
{
|
||||||
|
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$facture->addline($facture->id,
|
$result = $facture->addline($facture->id,
|
||||||
$product->description,
|
$desc,
|
||||||
$pu,
|
$pu_ht,
|
||||||
$_POST["qty"],
|
$_POST["qty"],
|
||||||
$tva_tx,
|
$tva_tx,
|
||||||
$product->id,
|
$prod->id,
|
||||||
$_POST["remise_percent"]);
|
$_POST["remise_percent"],
|
||||||
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
|
);
|
||||||
|
|
||||||
Header("Location: ../compta/facture.php?facid=".$facture->id);
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($_POST["cancel"] == $langs->trans("Cancel"))
|
if ($_POST["cancel"] == $langs->trans("Cancel"))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user