Fix: Corrige bug sur methode fetch_lines de commande mal réinitialisé
This commit is contained in:
parent
c9628249a9
commit
ef82553324
@ -1116,66 +1116,70 @@ class Commande extends CommonObject
|
|||||||
* \param only_product Ne renvoie que ligne liées à des produits physiques prédéfinis
|
* \param only_product Ne renvoie que ligne liées à des produits physiques prédéfinis
|
||||||
* \return array Tableau de CommandeLigne
|
* \return array Tableau de CommandeLigne
|
||||||
*/
|
*/
|
||||||
function fetch_lines($only_product=0)
|
function fetch_lines($only_product=0)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
$this->lignes=array();
|
||||||
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits,';
|
|
||||||
$sql.= ' l.total_ht, l.total_ttc, l.total_tva,';
|
$sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
||||||
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label';
|
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits,';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
$sql.= ' l.total_ht, l.total_ttc, l.total_tva,';
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
|
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label';
|
||||||
$sql.= ' WHERE l.fk_commande = '.$this->id;
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
||||||
if ($only_product==1) $sql .= ' AND p.fk_product_type = 0';
|
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
|
||||||
$sql .= ' ORDER BY l.rang';
|
$sql.= ' WHERE l.fk_commande = '.$this->id;
|
||||||
|
if ($only_product==1) $sql .= ' AND p.fk_product_type = 0';
|
||||||
|
$sql .= ' ORDER BY l.rang';
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
dolibarr_syslog("Commande::fetch_lines sql=".$sql,LOG_DEBUG);
|
||||||
if ($result)
|
$result = $this->db->query($sql);
|
||||||
{
|
if ($result)
|
||||||
$num = $this->db->num_rows($result);
|
{
|
||||||
$i = 0;
|
$num = $this->db->num_rows($result);
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$objp = $this->db->fetch_object($result);
|
|
||||||
|
|
||||||
$ligne = new CommandeLigne($this->db);
|
$i = 0;
|
||||||
$ligne->rowid = $objp->rowid;
|
while ($i < $num)
|
||||||
$ligne->id = $objp->rowid; // \deprecated
|
{
|
||||||
$ligne->fk_commande = $objp->fk_commande;
|
$objp = $this->db->fetch_object($result);
|
||||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
|
||||||
$ligne->desc = $objp->description; // Description ligne
|
|
||||||
$ligne->qty = $objp->qty;
|
|
||||||
$ligne->tva_tx = $objp->tva_tx;
|
|
||||||
$ligne->total_ht = $objp->total_ht;
|
|
||||||
$ligne->total_ttc = $objp->total_ttc;
|
|
||||||
$ligne->total_tva = $objp->total_tva;
|
|
||||||
$ligne->subprice = $objp->subprice;
|
|
||||||
$ligne->fk_remise_except = $objp->fk_remise_except;
|
|
||||||
$ligne->remise_percent = $objp->remise_percent;
|
|
||||||
$ligne->price = $objp->price;
|
|
||||||
$ligne->fk_product = $objp->fk_product;
|
|
||||||
$ligne->marge_tx = $objp->marge_tx;
|
|
||||||
$ligne->marque_tx = $objp->marque_tx;
|
|
||||||
$ligne->rang = $objp->rang;
|
|
||||||
$ligne->info_bits = $objp->info_bits;
|
|
||||||
|
|
||||||
$ligne->ref = $objp->product_ref;
|
$ligne = new CommandeLigne($this->db);
|
||||||
$ligne->libelle = $objp->label;
|
$ligne->rowid = $objp->rowid;
|
||||||
$ligne->product_desc = $objp->product_desc; // Description produit
|
$ligne->id = $objp->rowid; // \deprecated
|
||||||
$ligne->fk_product_type = $objp->fk_product_type; // Produit ou service
|
$ligne->fk_commande = $objp->fk_commande;
|
||||||
|
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||||
|
$ligne->desc = $objp->description; // Description ligne
|
||||||
|
$ligne->qty = $objp->qty;
|
||||||
|
$ligne->tva_tx = $objp->tva_tx;
|
||||||
|
$ligne->total_ht = $objp->total_ht;
|
||||||
|
$ligne->total_ttc = $objp->total_ttc;
|
||||||
|
$ligne->total_tva = $objp->total_tva;
|
||||||
|
$ligne->subprice = $objp->subprice;
|
||||||
|
$ligne->fk_remise_except = $objp->fk_remise_except;
|
||||||
|
$ligne->remise_percent = $objp->remise_percent;
|
||||||
|
$ligne->price = $objp->price;
|
||||||
|
$ligne->fk_product = $objp->fk_product;
|
||||||
|
$ligne->marge_tx = $objp->marge_tx;
|
||||||
|
$ligne->marque_tx = $objp->marque_tx;
|
||||||
|
$ligne->rang = $objp->rang;
|
||||||
|
$ligne->info_bits = $objp->info_bits;
|
||||||
|
|
||||||
$this->lignes[$i] = $ligne;
|
$ligne->ref = $objp->product_ref;
|
||||||
$i++;
|
$ligne->libelle = $objp->label;
|
||||||
}
|
$ligne->product_desc = $objp->product_desc; // Description produit
|
||||||
$this->db->free($result);
|
$ligne->fk_product_type = $objp->fk_product_type; // Produit ou service
|
||||||
return 1;
|
|
||||||
}
|
$this->lignes[$i] = $ligne;
|
||||||
else
|
$i++;
|
||||||
{
|
}
|
||||||
$this->error=$this->db->error();
|
$this->db->free($result);
|
||||||
dolibarr_syslog('Commande::fetch_lines: Error '.$this->error);
|
return 1;
|
||||||
return -3;
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog('Commande::fetch_lines: Error '.$this->error);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1195,17 +1199,21 @@ class Commande extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* \brief Charge tableau avec les expéditions par ligne
|
* \brief Charge tableau avec les expéditions par ligne
|
||||||
* \param filtre_statut Filtre sur statut
|
* \param filtre_statut Filtre sur statut
|
||||||
* \return int 0 si OK, <0 si KO
|
* \return int <0 if KO, Nb of records if OK
|
||||||
*/
|
*/
|
||||||
function loadExpeditions($filtre_statut=-1)
|
function loadExpeditions($filtre_statut=-1)
|
||||||
{
|
{
|
||||||
|
$num=0;
|
||||||
$this->expeditions = array();
|
$this->expeditions = array();
|
||||||
|
|
||||||
$sql = 'SELECT fk_product, sum(ed.qty)';
|
$sql = 'SELECT fk_product, sum(ed.qty)';
|
||||||
$sql.=' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'expedition as e, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
|
$sql.=' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'expedition as e, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
|
||||||
$sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
|
$sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
|
||||||
$sql.=' AND cd.fk_commande =' .$this->id;
|
$sql.=' AND cd.fk_commande =' .$this->id;
|
||||||
if ($filtre_statut >= 0) $sql.=' AND e.fk_statut = '.$filtre_statut;
|
if ($filtre_statut >= 0) $sql.=' AND e.fk_statut = '.$filtre_statut;
|
||||||
$sql .= ' GROUP BY fk_product ';
|
$sql .= ' GROUP BY fk_product ';
|
||||||
|
|
||||||
|
dolibarr_syslog("Commande::loadExpedition sql=".$sql,LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -1218,9 +1226,14 @@ class Commande extends CommonObject
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
|
return $num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user