diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 2f636d47475..1d1262b339b 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -689,7 +689,7 @@ else if ($action == "addline" && $user->rights->propale->creer)
{
$result=0;
- if (empty($_POST['idprod']) && $_POST["type"] < 0)
+ if (empty($_POST['idprod']) && GETPOST('type') < 0)
{
$mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
';
$result = -1 ;
@@ -700,9 +700,9 @@ else if ($action == "addline" && $user->rights->propale->creer)
$result = -1 ;
}
- if ($result >= 0 && isset($_POST['qty']) && (($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
+ if ($result >= 0 && isset($_POST['qty']) && ((GETPOST('np_price')!='' && (GETPOST('np_desc') || GETPOST('dp_desc'))) || GETPOST('idprod')))
{
- $ret=$object->fetch($_POST["id"]);
+ $ret=$object->fetch($id);
if ($ret < 0)
{
dol_print_error($db,$object->error);
@@ -710,15 +710,18 @@ else if ($action == "addline" && $user->rights->propale->creer)
}
$ret=$object->fetch_thirdparty();
+ $pu_ht=0;
+ $pu_ttc=0;
+ $price_min=0;
$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'])
+ if (GETPOST('idprod'))
{
$prod = new Product($db);
- $prod->fetch($_POST['idprod']);
+ $prod->fetch(GETPOST('idprod'));
$tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
$localtax1_tx= get_localtax($tva_tx, 1, $object->client); //get_default_localtax($mysoc,$object->client,1,$prod->id);
@@ -775,32 +778,25 @@ else if ($action == "addline" && $user->rights->propale->creer)
$desc = $prod->description;
}
- $desc.= ($desc && $_POST['np_desc']) ? ((dol_textishtml($desc) || dol_textishtml($_POST['np_desc']))?"
\n":"\n") : "";
- $desc.= $_POST['np_desc'];
+ $desc.= ($desc && GETPOST('np_desc')) ? ((dol_textishtml($desc) || dol_textishtml(GETPOST('np_desc')))?"
\n":"\n") : "";
+ $desc.= GETPOST('np_desc');
$type = $prod->type;
}
else
{
- $pu_ht=$_POST['np_price'];
- $tva_tx=str_replace('*','',$_POST['np_tva_tx']);
- $tva_npr=preg_match('/\*/',$_POST['np_tva_tx'])?1:0;
- $desc=$_POST['dp_desc'];
- $type=$_POST["type"];
+ $pu_ht=GETPOST('np_price');
+ $tva_tx=str_replace('*','',GETPOST('np_tva_tx'));
+ $tva_npr=preg_match('/\*/',GETPOST('np_tva_tx'))?1:0;
+ $desc=GETPOST('dp_desc');
+ $type=GETPOST('type');
$localtax1_tx=get_localtax($tva_tx,1,$object->client);
$localtax2_tx=get_localtax($tva_tx,2,$object->client);
}
- // ajout prix achat
- $fk_fournprice = $_POST['np_fournprice'];
- if ( ! empty($_POST['np_buying_price']) )
- $pa_ht = $_POST['np_buying_price'];
- else
- $pa_ht = null;
-
$info_bits=0;
if ($tva_npr) $info_bits |= 0x01;
- if ($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
+ if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
{
$mesg = ''.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'
' ;
}
@@ -808,24 +804,24 @@ else if ($action == "addline" && $user->rights->propale->creer)
{
// Insert line
$result=$object->addline(
- $_POST["id"],
+ $id,
$desc,
$pu_ht,
- $_POST['qty'],
+ GETPOST('qty'),
$tva_tx,
$localtax1_tx,
$localtax2_tx,
- $_POST['idprod'],
- $_POST['remise_percent'],
+ GETPOST('idprod'),
+ GETPOST('remise_percent'),
$price_base_type,
$pu_ttc,
$info_bits,
$type,
-1,
0,
- $_POST['fk_parent_line'],
- $fk_fournprice,
- $pa_ht
+ GETPOST('fk_parent_line'),
+ GETPOST('np_fournprice'),
+ GETPOST('np_buying_price')
);
if ($result > 0)
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 7fa779c9659..5c588bd482b 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -2397,6 +2397,7 @@ class Propal extends CommonObject
{
$obj = $this->db->fetch_object($resql);
+ $this->lines[$i] = (object) array();
$this->lines[$i]->id = $obj->rowid;
$this->lines[$i]->description = $obj->description;
$this->lines[$i]->fk_product = $obj->fk_product;
@@ -2414,11 +2415,11 @@ class Propal extends CommonObject
$this->lines[$i]->total_ht = $obj->total_ht;
$this->lines[$i]->total_tva = $obj->total_tva;
$this->lines[$i]->total_ttc = $obj->total_ttc;
- $this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
- $marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
- $this->lines[$i]->pa_ht = $marginInfos[0];
- $this->lines[$i]->marge_tx = $marginInfos[1];
- $this->lines[$i]->marque_tx = $marginInfos[2];
+ $this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
+ $marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
+ $this->lines[$i]->pa_ht = $marginInfos[0];
+ $this->lines[$i]->marge_tx = $marginInfos[1];
+ $this->lines[$i]->marque_tx = $marginInfos[2];
$this->lines[$i]->special_code = $obj->special_code;
$this->lines[$i]->rang = $obj->rang;
$this->lines[$i]->date_start = $this->db->jdate($obj->date_start);
@@ -2518,59 +2519,62 @@ class PropaleLigne
* @param int $rowid Propal line id
* @return int <0 if KO, >0 if OK
*/
- function fetch($rowid)
- {
- $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.description, pd.price, pd.qty, pd.tva_tx,';
- $sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
- $sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
- $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
- $sql.= ' WHERE pd.rowid = '.$rowid;
- $result = $this->db->query($sql);
- if ($result)
- {
- $objp = $this->db->fetch_object($result);
+ function fetch($rowid)
+ {
+ $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.description, pd.price, pd.qty, pd.tva_tx,';
+ $sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
+ $sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
+ $sql.= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
+ $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
+ $sql.= ' WHERE pd.rowid = '.$rowid;
- $this->rowid = $objp->rowid;
- $this->fk_propal = $objp->fk_propal;
- $this->fk_parent_line = $objp->fk_parent_line;
- $this->desc = $objp->description;
- $this->qty = $objp->qty;
- $this->price = $objp->price; // deprecated
- $this->subprice = $objp->subprice;
- $this->tva_tx = $objp->tva_tx;
- $this->remise = $objp->remise;
- $this->remise_percent = $objp->remise_percent;
- $this->fk_remise_except = $objp->fk_remise_except;
- $this->fk_product = $objp->fk_product;
- $this->info_bits = $objp->info_bits;
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $objp = $this->db->fetch_object($result);
- $this->total_ht = $objp->total_ht;
- $this->total_tva = $objp->total_tva;
- $this->total_ttc = $objp->total_ttc;
+ $this->rowid = $objp->rowid;
+ $this->fk_propal = $objp->fk_propal;
+ $this->fk_parent_line = $objp->fk_parent_line;
+ $this->desc = $objp->description;
+ $this->qty = $objp->qty;
+ $this->price = $objp->price; // deprecated
+ $this->subprice = $objp->subprice;
+ $this->tva_tx = $objp->tva_tx;
+ $this->remise = $objp->remise;
+ $this->remise_percent = $objp->remise_percent;
+ $this->fk_remise_except = $objp->fk_remise_except;
+ $this->fk_product = $objp->fk_product;
+ $this->info_bits = $objp->info_bits;
- $this->fk_fournprice = $objp->fk_fournprice;
- $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
- $this->pa_ht = $marginInfos[0];
- $this->marge_tx = $marginInfos[1];
- $this->marque_tx = $marginInfos[2];
- $this->special_code = $objp->special_code;
- $this->rang = $objp->rang;
+ $this->total_ht = $objp->total_ht;
+ $this->total_tva = $objp->total_tva;
+ $this->total_ttc = $objp->total_ttc;
- $this->ref = $objp->product_ref; // deprecated
- $this->product_ref = $objp->product_ref;
- $this->libelle = $objp->product_libelle; // deprecated
- $this->product_label = $objp->product_libelle;
- $this->product_desc = $objp->product_desc;
+ $this->fk_fournprice = $objp->fk_fournprice;
+ $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
+ $this->pa_ht = $marginInfos[0];
+ $this->marge_tx = $marginInfos[1];
+ $this->marque_tx = $marginInfos[2];
- $this->db->free($result);
- }
- else
- {
- dol_print_error($this->db);
- }
- }
+ $this->special_code = $objp->special_code;
+ $this->rang = $objp->rang;
+
+ $this->ref = $objp->product_ref; // deprecated
+ $this->product_ref = $objp->product_ref;
+ $this->libelle = $objp->product_libelle; // deprecated
+ $this->product_label = $objp->product_libelle;
+ $this->product_desc = $objp->product_desc;
+
+ $this->db->free($result);
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
/**
* Insert object line propal in database
@@ -2599,13 +2603,13 @@ class PropaleLigne
if (empty($this->special_code)) $this->special_code=0;
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
- if (empty($this->pa_ht)) $this->pa_ht=0;
+ if (empty($this->pa_ht)) $this->pa_ht=0;
- // si prix d'achat non renseign� et utilis� pour calcul des marges alors prix achat = prix vente (idem pour remises)
- if ($this->pa_ht == 0) {
- if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
- $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
- }
+ // si prix d'achat non renseign� et utilis� pour calcul des marges alors prix achat = prix vente (idem pour remises)
+ if ($this->pa_ht == 0) {
+ if ($this->subprice < 0 || (isset($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice) && $conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
+ $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
+ }
// Check parameters
if ($this->product_type < 0) return -1;
@@ -2636,12 +2640,10 @@ class PropaleLigne
$sql.= " ".price2num($this->total_localtax1).",";
$sql.= " ".price2num($this->total_localtax2).",";
$sql.= " ".price2num($this->total_ttc).",";
+ $sql.= " ".(isset($this->fk_fournprice)?"'".$this->fk_fournprice."'":"null").",";
+ $sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").",";
$sql.= ' '.$this->special_code.',';
- $sql.= ' '.$this->rang.',';
- if (isset($this->fk_fournprice)) $sql.= ' '.$this->fk_fournprice.',';
- else $sql.= ' null,';
- if (isset($this->pa_ht)) $sql.= ' '.price2num($this->pa_ht);
- else $sql.= ' null';
+ $sql.= ' '.$this->rang;
$sql.= ')';
dol_syslog("PropaleLigne::insert sql=$sql");
diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php
index 5f55b18173d..80e16e0fadd 100644
--- a/htdocs/core/tpl/predefinedproductline_create.tpl.php
+++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php
@@ -1,7 +1,7 @@
- * Copyright (C) 2010-2011 Laurent Destailleur
- * Copyright (C) 2012 Christophe Battarel
+/* Copyright (C) 2010-2012 Regis Houssin
+ * Copyright (C) 2010-2011 Laurent Destailleur
+ * Copyright (C) 2012 Christophe Battarel
*
* 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
@@ -42,7 +42,7 @@
trans('ReductionShort'); ?> |
margin->enabled)) {
+if (! empty($conf->margin->enabled)) {
?>
trans('BuyingPrice'); ?> |
margin->enabled)) {