Fix: Duplicate rows return by fetch
This commit is contained in:
parent
c7ca1db2df
commit
4c892d403b
@ -675,19 +675,7 @@ if ($id > 0)
|
|||||||
*/
|
*/
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
|
|
||||||
$sql = "SELECT l.ref as ref_fourn, l.fk_product, l.description, l.qty";
|
$num = sizeof($commande->lignes);
|
||||||
$sql.= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice";
|
|
||||||
$sql.= ", l.total_ht, l.total_tva, l.total_ttc";
|
|
||||||
$sql.= ", p.rowid as product_id, p.label as product, p.ref";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
|
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
|
||||||
$sql.= " WHERE l.fk_commande = ".$commande->id;
|
|
||||||
$sql.= " ORDER BY l.rowid";
|
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$num = $db->num_rows($resql);
|
|
||||||
$i = 0; $total = 0;
|
$i = 0; $total = 0;
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
@ -705,7 +693,7 @@ if ($id > 0)
|
|||||||
$var=true;
|
$var=true;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$objp = $db->fetch_object($resql);
|
$objp = $commande->lignes[$i];
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
|
|
||||||
// Ligne en mode visu
|
// Ligne en mode visu
|
||||||
@ -718,16 +706,16 @@ if ($id > 0)
|
|||||||
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
||||||
|
|
||||||
// Affiche ligne produit
|
// Affiche ligne produit
|
||||||
$text = '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->product_id.'">';
|
$text = '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">';
|
||||||
$text.= img_object($langs->trans('ShowProduct'),'product');
|
$text.= img_object($langs->trans('ShowProduct'),'product');
|
||||||
$text.= ' '.$objp->ref_fourn.'</a>';
|
$text.= ' '.$objp->ref_fourn.'</a>';
|
||||||
$text.= ' ('.$objp->ref.')';
|
$text.= ' ('.$objp->ref.')';
|
||||||
$text.= ' - '.$objp->product;
|
$text.= ' - '.$objp->libelle;
|
||||||
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description));
|
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->product_desc));
|
||||||
print $html->textwithtooltip($text,$description,3,'','',$i);
|
print $html->textwithtooltip($text,$description,3,'','',$i);
|
||||||
if ($conf->global->PRODUIT_DESC_IN_FORM)
|
if ($conf->global->PRODUIT_DESC_IN_FORM)
|
||||||
{
|
{
|
||||||
print ($objp->description && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
|
print ($objp->product_desc && $objp->product_desc!=$objp->libelle)?'<br>'.dol_htmlentitiesbr($objp->product_desc):'';
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</td>";
|
print "</td>";
|
||||||
@ -736,7 +724,7 @@ if ($id > 0)
|
|||||||
{
|
{
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
||||||
print nl2br($objp->description);
|
print nl2br($objp->product_desc);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
}
|
}
|
||||||
print '<td align="right" nowrap="nowrap">'.vatrate($objp->tva_tx).'%</td>';
|
print '<td align="right" nowrap="nowrap">'.vatrate($objp->tva_tx).'%</td>';
|
||||||
@ -751,7 +739,7 @@ if ($id > 0)
|
|||||||
print '<td> </td>';
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
//Todo: Modifier la classe pour utiliser le champ total_ttc
|
//Todo: Modifier la classe pour utiliser le champ total_ttc
|
||||||
print '<td align="right" nowrap="nowrap">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).'</td>';
|
print '<td align="right" nowrap="nowrap">'.price($objp->total_ht).'</td>';
|
||||||
if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer)
|
if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer)
|
||||||
{
|
{
|
||||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">';
|
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">';
|
||||||
@ -813,12 +801,6 @@ if ($id > 0)
|
|||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$db->free();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_print_error($db);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ajouter une ligne
|
* Ajouter une ligne
|
||||||
|
|||||||
@ -71,7 +71,8 @@ class CommandeFournisseur extends Commande
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lit une commande
|
* \brief Load a supplier order
|
||||||
|
* \param Id of order to load
|
||||||
*/
|
*/
|
||||||
function fetch($id)
|
function fetch($id)
|
||||||
{
|
{
|
||||||
@ -116,20 +117,19 @@ class CommandeFournisseur extends Commande
|
|||||||
|
|
||||||
if ($this->statut == 0) $this->brouillon = 1;
|
if ($this->statut == 0) $this->brouillon = 1;
|
||||||
|
|
||||||
// export pdf -----------
|
// Now load lines
|
||||||
|
|
||||||
$this->lignes = array();
|
$this->lignes = array();
|
||||||
$sql = 'SELECT l.fk_product, l.description, l.total_ht, l.total_tva, l.total_ttc, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice';
|
|
||||||
$sql.= ', p.label, p.description as product_desc, p.rowid as prodid';
|
|
||||||
$sql.= ', pf.ref_fourn';
|
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as l';
|
|
||||||
|
|
||||||
//Todo: revoir le fonctionnement de la base produit fournisseurs
|
$sql = "SELECT l.rowid, l.ref as ref_fourn, l.fk_product, l.label, l.description, l.qty,";
|
||||||
|
$sql.= " l.tva_tx, l.remise_percent, l.subprice,";
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur as pf ON l.fk_product = pf.fk_product AND l.ref = pf.ref_fourn';
|
$sql.= " l.total_ht, l.total_tva, l.total_ttc,";
|
||||||
|
$sql.= " p.rowid as product_id, p.ref, p.label as product, p.description as product_desc";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
||||||
$sql.= ' WHERE l.fk_commande = '.$this->id;
|
$sql.= " WHERE l.fk_commande = ".$this->id;
|
||||||
$sql.= ' ORDER BY l.rowid';
|
$sql.= " ORDER BY l.rowid";
|
||||||
|
|
||||||
|
dolibarr_syslog("CommandeFournisseur::fetch sql=".$sql,LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -151,10 +151,11 @@ class CommandeFournisseur extends Commande
|
|||||||
$ligne->total_tva = $objp->total_tva;
|
$ligne->total_tva = $objp->total_tva;
|
||||||
$ligne->total_ttc = $objp->total_ttc;
|
$ligne->total_ttc = $objp->total_ttc;
|
||||||
|
|
||||||
$ligne->fk_product = $objp->fk_product; // Id du produit
|
$ligne->fk_product = $objp->product_id; // Id du produit
|
||||||
$ligne->libelle = $objp->label; // Label produit
|
$ligne->libelle = $objp->label; // Label produit
|
||||||
$ligne->product_desc = $objp->product_desc; // Description produit
|
$ligne->product_desc = $objp->product_desc; // Description produit
|
||||||
|
|
||||||
|
$ligne->ref = $objp->ref; // Reference
|
||||||
$ligne->ref_fourn = $objp->ref_fourn; // Reference supplier
|
$ligne->ref_fourn = $objp->ref_fourn; // Reference supplier
|
||||||
|
|
||||||
$this->lignes[$i] = $ligne;
|
$this->lignes[$i] = $ligne;
|
||||||
@ -169,14 +170,14 @@ class CommandeFournisseur extends Commande
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error()." sql=".$sql;
|
$this->error=$this->db->error()." sql=".$sql;
|
||||||
dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error);
|
dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error()." sql=".$sql;
|
$this->error=$this->db->error()." sql=".$sql;
|
||||||
dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error);
|
dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user