From 4c892d403b83168fc0dfc4ca9dafa9963bd63ecd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Sep 2008 20:49:57 +0000 Subject: [PATCH] Fix: Duplicate rows return by fetch --- htdocs/fourn/commande/fiche.php | 248 +++++++++----------- htdocs/fourn/fournisseur.commande.class.php | 37 +-- 2 files changed, 134 insertions(+), 151 deletions(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index c38dfd2cb33..68091000c7f 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -671,153 +671,135 @@ if ($id > 0) else print '
'; /* - * Lignes de commandes + * Lignes de commandes */ print ''; - $sql = "SELECT l.ref as ref_fourn, l.fk_product, l.description, l.qty"; - $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"; + $num = sizeof($commande->lignes); + $i = 0; $total = 0; - $resql = $db->query($sql); - if ($resql) + if ($num) { - $num = $db->num_rows($resql); - $i = 0; $total = 0; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + while ($i < $num) + { + $objp = $commande->lignes[$i]; + $var=!$var; - if ($num) + // Ligne en mode visu + if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - // Ligne en mode visu - if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) + print ''; + if ($objp->fk_product > 0) { - print ''; - if ($objp->fk_product > 0) - { - print '"; - } - else - { - print ''; - } - print ''; - print '\n"; - print ''; - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - //Todo: Modifier la classe pour utiliser le champ total_ttc - print ''; - if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer) - { - print ''; - - print ''; - } - else - { - print ''; - } - print ""; - } - - // Ligne en mode update - if ($_GET["action"] == 'editline' && $user->rights->fournisseur->commande->creer && $_GET["rowid"] == $objp->rowid) - { - print 'rowid.'" method="post">'; - print ''; - print ''; - print ''; - print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - print "\n"; + + print ""; } - $i++; + else + { + print ''; + } + print ''; + print '\n"; + print ''; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + //Todo: Modifier la classe pour utiliser le champ total_ttc + print ''; + if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer) + { + print ''; + + print ''; + } + else + { + print ''; + } + print ""; } - $db->free(); - } - else - { - dolibarr_print_error($db); + + // Ligne en mode update + if ($_GET["action"] == 'editline' && $user->rights->fournisseur->commande->creer && $_GET["rowid"] == $objp->rowid) + { + print 'rowid.'" method="post">'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '' . "\n"; + print "\n"; + } + $i++; } /* diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index 4b278d5fe44..f36541d78dc 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -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) { @@ -115,21 +116,20 @@ class CommandeFournisseur extends Commande $this->db->free(); if ($this->statut == 0) $this->brouillon = 1; - - // export pdf ----------- - + + // Now load lines $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.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur as pf ON l.fk_product = pf.fk_product AND l.ref = pf.ref_fourn'; + + $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.= " 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.= ' WHERE l.fk_commande = '.$this->id; - $sql.= ' ORDER BY l.rowid'; + $sql.= " WHERE l.fk_commande = ".$this->id; + $sql.= " ORDER BY l.rowid"; + + dolibarr_syslog("CommandeFournisseur::fetch sql=".$sql,LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -151,12 +151,13 @@ class CommandeFournisseur extends Commande $ligne->total_tva = $objp->total_tva; $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->product_desc = $objp->product_desc; // Description produit + $ligne->ref = $objp->ref; // Reference $ligne->ref_fourn = $objp->ref_fourn; // Reference supplier - + $this->lignes[$i] = $ligne; //dolibarr_syslog("1 ".$ligne->desc); //dolibarr_syslog("2 ".$ligne->product_desc); @@ -169,14 +170,14 @@ class CommandeFournisseur extends Commande else { $this->error=$this->db->error()." sql=".$sql; - dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); + dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); return -1; } } else { $this->error=$this->db->error()." sql=".$sql; - dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); + dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); return -1; } }
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').' 
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').' 
'; - print ''; // ancre pour retourner sur la ligne - - // Affiche ligne produit - $text = ''; - $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$objp->ref_fourn.''; - $text.= ' ('.$objp->ref.')'; - $text.= ' - '.$objp->product; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); - print $html->textwithtooltip($text,$description,3,'','',$i); - if ($conf->global->PRODUIT_DESC_IN_FORM) - { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; - } - - print "
'; - print ''; // ancre pour retourner sur la ligne - print nl2br($objp->description); - print ''.vatrate($objp->tva_tx).'%'.price($objp->subprice)."'.$objp->qty.''.dolibarr_print_reduction($objp->remise_percent)." '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).'rowid.'#'.$objp->rowid.'">'; - print img_edit(); - print 'rowid.'">'; - print img_delete(); - print '  
'; print ''; // ancre pour retourner sur la ligne - if ($objp->fk_product > 0) + + // Affiche ligne produit + $text = ''; + $text.= img_object($langs->trans('ShowProduct'),'product'); + $text.= ' '.$objp->ref_fourn.''; + $text.= ' ('.$objp->ref.')'; + $text.= ' - '.$objp->libelle; + $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->product_desc)); + print $html->textwithtooltip($text,$description,3,'','',$i); + if ($conf->global->PRODUIT_DESC_IN_FORM) { - print ''; - print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref_fourn.''; - print ' ('.$objp->ref.')'; - print ' - '.nl2br($objp->product); - print '
'; + print ($objp->product_desc && $objp->product_desc!=$objp->libelle)?'
'.dol_htmlentitiesbr($objp->product_desc):''; } - // editeur wysiwyg - if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) - { - require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('eldesc',$objp->description,200,'dolibarr_details'); - $doleditor->Create(); - } - else - { - print ''; - } - print '
'; - $html->select_tva('tva_tx',$objp->tva_tx); - print '%'; - print '
'; + print ''; // ancre pour retourner sur la ligne + print nl2br($objp->product_desc); + print ''.vatrate($objp->tva_tx).'%'.price($objp->subprice)."'.$objp->qty.''.dolibarr_print_reduction($objp->remise_percent)." '.price($objp->total_ht).'rowid.'#'.$objp->rowid.'">'; + print img_edit(); + print 'rowid.'">'; + print img_delete(); + print '  
'; + print ''; // ancre pour retourner sur la ligne + if ($objp->fk_product > 0) + { + print ''; + print img_object($langs->trans('ShowProduct'),'product'); + print ' '.$objp->ref_fourn.''; + print ' ('.$objp->ref.')'; + print ' - '.nl2br($objp->product); + print '
'; + } + // editeur wysiwyg + if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) + { + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('eldesc',$objp->description,200,'dolibarr_details'); + $doleditor->Create(); + } + else + { + print ''; + } + print '
'; + $html->select_tva('tva_tx',$objp->tva_tx); + print '%'; + print '