Permalink
Browse files

Fix: missing fields and compatibility with milestone

  • Loading branch information...
1 parent d6a4d5e commit 2e73cd7ddf385b82a60f8d752c359c6bc39de873 Regis Houssin committed Aug 1, 2012
@@ -309,7 +309,7 @@ function insert_discount($idremise)
*
* @see add_product
*/
- function addline($propalid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht = 0)
+ function addline($propalid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht = 0)
{
global $conf;
@@ -399,9 +399,9 @@ function addline($propalid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txloca
$this->line->special_code=$special_code;
$this->line->fk_parent_line=$fk_parent_line;
- // infos marge
- $this->line->fk_fournprice = $fk_fournprice;
- $this->line->pa_ht = $pa_ht;
+ // infos marge
+ $this->line->fk_fournprice = $fk_fournprice;
+ $this->line->pa_ht = $pa_ht;
// Mise en option de la ligne
//if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty) $ligne->special_code=3;
@@ -1072,9 +1072,9 @@ function fetch($rowid,$ref='')
/*
* Lignes propales liees a un produit ou non
- */
+ */
$sql = "SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
- $sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
+ $sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label';
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
@@ -1113,11 +1113,11 @@ function fetch($rowid,$ref='')
$line->total_localtax1 = $objp->total_localtax1;
$line->total_localtax2 = $objp->total_localtax2;
$line->total_ttc = $objp->total_ttc;
- $line->fk_fournprice = $objp->fk_fournprice;
- $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
- $line->pa_ht = $marginInfos[0];
- $line->marge_tx = $marginInfos[1];
- $line->marque_tx = $marginInfos[2];
+ $line->fk_fournprice = $objp->fk_fournprice;
+ $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
+ $line->pa_ht = $marginInfos[0];
+ $line->marge_tx = $marginInfos[1];
+ $line->marque_tx = $marginInfos[2];
$line->special_code = $objp->special_code;
$line->rang = $objp->rang;
@@ -2381,7 +2381,7 @@ function getLinesArray()
$sql = 'SELECT pt.rowid, pt.description, pt.fk_product, pt.fk_remise_except,';
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
- $sql.= ' pt.date_start, pt.date_end, pt.product_type, pt.rang,';
+ $sql.= ' pt.date_start, pt.date_end, pt.product_type, pt.rang, pt.fk_parent_line,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt';
@@ -2400,7 +2400,8 @@ function getLinesArray()
$obj = $this->db->fetch_object($resql);
$this->lines[$i] = (object) array();
- $this->lines[$i]->id = $obj->rowid;
+ $this->lines[$i]->id = $obj->rowid; // for backward compatibility
+ $this->lines[$i]->rowid = $obj->rowid;
$this->lines[$i]->description = $obj->description;
$this->lines[$i]->fk_product = $obj->fk_product;
$this->lines[$i]->ref = $obj->ref;
@@ -2417,11 +2418,12 @@ function getLinesArray()
$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]->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_parent_line = $obj->fk_parent_line;
$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);
@@ -2436,7 +2438,7 @@ function getLinesArray()
else
{
$this->error=$this->db->error();
- dol_syslog("Error sql=$sql, error=".$this->error,LOG_ERR);
+ dol_syslog(get_class($this)."::getLinesArray Error sql=$sql, error=".$this->error,LOG_ERR);
return -1;
}
}
@@ -2471,10 +2473,10 @@ class PropaleLigne
var $rang = 0;
- var $fk_fournprice;
- var $pa_ht;
- var $marge_tx;
- var $marque_tx;
+ var $fk_fournprice;
+ var $pa_ht;
+ var $marge_tx;
+ var $marque_tx;
var $special_code; // Liste d'options non cumulabels:
// 1: frais de port
@@ -2556,7 +2558,8 @@ function fetch($rowid)
$this->total_ttc = $objp->total_ttc;
$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);
+
+ $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];
@@ -2623,7 +2626,7 @@ function insert($notrigger=0)
$sql.= ' (fk_propal, fk_parent_line, description, fk_product, product_type, fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx,';
$sql.= ' subprice, remise_percent, ';
$sql.= ' info_bits, ';
- $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, special_code, rang, fk_product_fournisseur_price, buy_price_ht)';
+ $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang)';
$sql.= " VALUES (".$this->fk_propal.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
$sql.= " '".$this->db->escape($this->desc)."',";
@@ -2648,7 +2651,7 @@ function insert($notrigger=0)
$sql.= ' '.$this->rang;
$sql.= ')';
- dol_syslog("PropaleLigne::insert sql=$sql");
+ dol_syslog(get_class($this).'::insert sql='.$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -2671,7 +2674,7 @@ function insert($notrigger=0)
else
{
$this->error=$this->db->error()." sql=".$sql;
- dol_syslog("PropaleLigne::insert Error ".$this->error, LOG_ERR);
+ dol_syslog(get_class($this).'::insert Error '.$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
@@ -2741,13 +2744,13 @@ function update($notrigger=0)
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 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
+ $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
+ }
$this->db->begin();
@@ -2769,8 +2772,8 @@ function update($notrigger=0)
$sql.= " , total_tva=".price2num($this->total_tva)."";
$sql.= " , total_ttc=".price2num($this->total_ttc)."";
}
- $sql.= " , fk_product_fournisseur_price='".$this->fk_fournprice."'";
- $sql.= " , buy_price_ht='".price2num($this->pa_ht)."'";
+ $sql.= " , fk_product_fournisseur_price='".$this->fk_fournprice."'";
+ $sql.= " , buy_price_ht='".price2num($this->pa_ht)."'";
$sql.= " , info_bits=".$this->info_bits;
if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
$sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
@@ -2743,10 +2743,9 @@ function getLinesArray()
$lines = array();
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, ';
- $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,l.rang,l.special_code,';
+ $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits, l.rang, l.special_code, l.fk_parent_line';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.localtax1_tx, l.localtax2_tx,';
- $sql.= ' l.date_start,';
- $sql.= ' l.date_end,';
+ $sql.= ' l.date_start, l.date_end,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, ';
$sql.= ' p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
@@ -2781,15 +2780,16 @@ function getLinesArray()
$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_parent_line = $obj->fk_parent_line;
$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);
$this->lines[$i]->date_end = $this->db->jdate($obj->date_end);
- $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];
$i++;
}
@@ -3001,13 +3001,13 @@ function insert($notrigger=0)
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 renseigne et utilise 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);
+ }
// Check parameters
if ($this->product_type < 0) return -1;
@@ -3027,34 +3027,28 @@ function insert($notrigger=0)
$sql.= " '".price2num($this->tva_tx)."',";
$sql.= " '".price2num($this->localtax1_tx)."',";
$sql.= " '".price2num($this->localtax2_tx)."',";
- if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; }
- else { $sql.='null,'; }
+ $sql.= ' '.(! empty($this->fk_product)?$this->fk_product:"null").',';
$sql.= " '".$this->product_type."',";
$sql.= " '".price2num($this->remise_percent)."',";
$sql.= " ".($this->subprice!=''?"'".price2num($this->subprice)."'":"null").",";
$sql.= " ".($this->price!=''?"'".price2num($this->price)."'":"null").",";
$sql.= " '".price2num($this->remise)."',";
- if ($this->fk_remise_except) $sql.= $this->fk_remise_except.",";
- else $sql.= 'null,';
+ $sql.= ' '.(! empty($this->fk_remise_except)?$this->fk_remise_except:"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.= ' '.(! empty($this->fk_fournprice)?$this->fk_fournprice:"null").',';
+ $sql.= ' '.price2num($this->pa_ht).',';
$sql.= " '".$this->info_bits."',";
$sql.= " '".price2num($this->total_ht)."',";
$sql.= " '".price2num($this->total_tva)."',";
$sql.= " '".price2num($this->total_localtax1)."',";
$sql.= " '".price2num($this->total_localtax2)."',";
$sql.= " '".price2num($this->total_ttc)."',";
- if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; }
- else { $sql.='null,'; }
- if ($this->date_end) { $sql.= "'".$this->db->idate($this->date_end)."'"; }
- else { $sql.='null'; }
+ $sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").',';
+ $sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ')';
- dol_syslog("OrderLine::insert sql=".$sql);
+ dol_syslog(get_class($this)."::insert sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -3076,7 +3070,7 @@ function insert($notrigger=0)
else
{
$this->error=$this->db->error();
- dol_syslog("OrderLine::insert Error ".$this->error, LOG_ERR);
+ dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
@@ -3140,9 +3134,8 @@ function update($notrigger=0)
$sql.= " , total_localtax1=".price2num($this->total_localtax1);
$sql.= " , total_localtax2=".price2num($this->total_localtax2);
$sql.= " , info_bits=".$this->info_bits;
- if ($this->date_start) { $sql.= " , date_start='".$this->db->idate($this->date_start)."'"; }
- else { $sql.=' , date_start=null'; }
- if ($this->date_end) { $sql.= " , date_end='".$this->db->idate($this->date_end)."'"; }
+ $sql.= " , date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
+ $sql.= " , date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= " , product_type=".$this->product_type;
$sql.= " , fk_parent_line=".(! empty($this->fk_parent_line)?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
Oops, something went wrong.

0 comments on commit 2e73cd7

Please sign in to comment.