diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index e6d625e8b51..ea084d901fd 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -488,39 +488,39 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
if ($_POST['qty'] && (($_POST['np_price']!='' && $_POST['np_desc']) || $_POST['idprod']))
{
$propal = new Propal($db);
- $ret=$propal->fetch($_POST['propalid']);
+ $ret=$propal->fetch($_POST['propalid']);
if ($ret < 0)
{
dolibarr_print_error($db,$propal->error);
exit;
}
- $ret=$propal->fetch_client();
+ $ret=$propal->fetch_client();
$price_base_type = 'HT';
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
- if ($_POST['idprod'])
- {
- $prod = new Product($db, $_POST['idprod']);
- $prod->fetch($_POST['idprod']);
-
+ if ($_POST['idprod'])
+ {
+ $prod = new Product($db, $_POST['idprod']);
+ $prod->fetch($_POST['idprod']);
+
$tva_tx = get_default_tva($mysoc,$propal->client,$prod->tva_tx);
- // On defini prix unitaire
- if ($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $pu_ht = $prod->multiprices[$propal->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$propal->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$propal->client->price_level];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
+ // On defini prix unitaire
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu_ht = $prod->multiprices[$propal->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$propal->client->price_level];
+ $price_base_type = $prod->multiprices_base_type[$propal->client->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).
@@ -536,18 +536,18 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
}
}
- $desc = $prod->description;
+ $desc = $prod->description;
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
- $desc.= $_POST['np_desc'];
- }
- else
- {
- $pu_ht=$_POST['np_price'];
- $tva_tx=$_POST['np_tva_tx'];
- $desc=$_POST['np_desc'];
- }
+ $desc.= $_POST['np_desc'];
+ }
+ else
+ {
+ $pu_ht=$_POST['np_price'];
+ $tva_tx=$_POST['np_tva_tx'];
+ $desc=$_POST['np_desc'];
+ }
- $propal->addline(
+ $result=$propal->addline(
$_POST['propalid'],
$desc,
$pu_ht,
@@ -557,14 +557,22 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
$_POST['remise_percent'],
$price_base_type,
$pu_ttc
- );
+ );
- if ($_REQUEST['lang_id'])
+ if ($result > 0)
{
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
- propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
+ else
+ {
+ $mesg='
'.$propal->error.'
';
+ }
+
}
}
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 206dff04ea9..9fd2ecce9ed 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -327,13 +327,13 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$pu_ht = $prod->multiprices[$commande->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$commande->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];
+ $price_base_type = $prod->multiprices_base_type[$commande->client->price_level];
}
else
{
$pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
+ $pu_ttc = $prod->price_ttc;
$price_base_type = $prod->price_base_type;
}
@@ -351,9 +351,9 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
}
}
- $desc = $prod->description;
+ $desc = $prod->description;
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
- $desc.= $_POST['np_desc'];
+ $desc.= $_POST['np_desc'];
}
else
{
@@ -374,7 +374,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
'',
$price_base_type,
$pu_ttc
- );
+ );
if ($result > 0)
{
@@ -387,7 +387,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
}
else
{
- print $commande->error;
+ $mesg=''.$commande->error.'
';
}
}
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 4bab896c421..41282cfb1a9 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -832,6 +832,20 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
);
}
+ if ($result > 0)
+ {
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ facture_pdf_create($db, $fac->id, $fac->modelpdf, $outputlangs);
+ }
+ else
+ {
+ $mesg=''.$fac->error.'
';
+ }
+
$_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition
}
diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index 0c16b1c2981..20c7a8bc4bd 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
@@ -168,50 +167,124 @@ if ($_POST["action"] == 'classin')
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
{
- if ($_POST["pqty"] && (($_POST["pu"] && $_POST["desc"]) || $_POST["p_idprod"]))
+ if ($_POST["pqty"] && (($_POST["pu"] != '' && $_POST["desc"]) || $_POST["p_idprod"]))
{
- $result = 0;
$contrat = new Contrat($db);
- $result=$contrat->fetch($_GET["id"]);
- if ($_POST["p_idprod"] > 0 && $_POST["mode"]=='predefined')
+ $ret=$contrat->fetch($_GET["id"]);
+ if ($ret < 0)
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
+ $ret=$contrat->fetch_client();
+
+ $date_start='';
+ $date_end='';
+ // Si ajout champ produit libre
+ if ($_POST['mode'] == 'libre')
+ {
+ if ($_POST['date_start_slyear'] && $_POST['date_start_slmonth'] && $_POST['date_start_slday'])
+ {
+ $date_start=dolibarr_mktime(12,0,0,$_POST['date_start_slmonth'],$_POST['date_start_slday'],$_POST['date_start_slyear']);
+ }
+ if ($_POST['date_end_slyear'] && $_POST['date_end_slmonth'] && $_POST['date_end_slday'])
+ {
+ $date_end=dolibarr_mktime(12,0,0,$_POST['date_end_slmonth'],$_POST['date_end_slday'],$_POST['date_end_slyear']);
+ }
+ }
+ // Si ajout champ produit prédéfini
+ if ($_POST['mode'] == 'predefined')
+ {
+ if ($_POST['date_startyear'] && $_POST['date_startmonth'] && $_POST['date_startday'])
+ {
+ $date_start=dolibarr_mktime(12,0,0,$_POST['date_startmonth'],$_POST['date_startday'],$_POST['date_startyear']);
+ }
+ if ($_POST['date_endyear'] && $_POST['date_endmonth'] && $_POST['date_endday'])
+ {
+ $date_end=dolibarr_mktime(12,0,0,$_POST['date_endmonth'],$_POST['date_endday'],$_POST['date_endmonth']);
+ }
+ }
+
+ $price_base_type = 'HT';
+
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ // Ecrase $base_price_type par celui du produit
+ if ($_POST['p_idprod'])
{
- //print $_POST["desc"]." - ".$_POST["pu"]." - ".$_POST["pqty"]." - ".$_POST["tva_tx"]." - ".$_POST["p_idprod"]." - ".$_POST["premise"]; exit;
- $result = $contrat->addline(
- $_POST["desc"],
- $_POST["pu"],
+ $prod = new Product($db, $_POST['p_idprod']);
+ $prod->fetch($_POST['p_idprod']);
+
+ $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx);
+
+ // On defini prix unitaire
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu_ht = $prod->multiprices[$fac->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$fac->client->price_level];
+ $price_base_type = $prod->multiprices_base_type[$fac->client->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');
+ }
+ }
+
+ $desc = $prod->description;
+ $desc.= $prod->description && $_POST['desc'] ? "\n" : "";
+ $desc.= $_POST['desc'];
+ }
+ else
+ {
+ $pu_ht=$_POST['pu'];
+ $tva_tx=$_POST['tva_tx'];
+ $desc=$_POST['desc'];
+ }
+
+ $result = $contrat->addline(
+ $desc,
+ $pu_ht,
$_POST["pqty"],
- $_POST["tva_tx"],
+ $tva_tx,
$_POST["p_idprod"],
$_POST["premise"],
$date_start,
$date_end,
- 'HT'
+ $price_base_type,
+ $pu_ttc
);
- }
- elseif ($_POST["mode"]=='libre')
- {
- $result = $contrat->addline(
- $_POST["desc"],
- $_POST["pu"],
- $_POST["pqty"],
- $_POST["tva_tx"],
- 0,
- $_POST["premise"],
- $date_start_sl,
- $date_end_sl,
- 'HT'
- );
- }
- if ($result >= 0)
- {
- Header("Location: fiche.php?id=".$contrat->id);
- exit;
- }
- else
- {
+ if ($result > 0)
+ {
+ /*
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ contrat_pdf_create($db, $contrat->id, $contrat->modelpdf, $outputlangs);
+ */
+ }
+ else
+ {
$mesg=''.$contrat->error.'
';
- }
+ }
}
}