From 8d3df7ea5751136bc01cdbca4608d16255766475 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Thu, 12 Oct 2017 09:59:25 +0200 Subject: [PATCH 1/2] Fix can not distinct which credit note are in select list --- htdocs/core/class/html.form.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 25cdfa2d887..5330ce24048 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1188,12 +1188,17 @@ class Form // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source"; + if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql.= ", f.facnumber"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; + if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture f ON (f.rowid = re.fk_facture_source)"; $sql.= " WHERE re.fk_soc = ".(int) $socid; $sql.= " AND re.entity = " . $conf->entity; if ($filter) $sql.= " AND ".$filter; $sql.= " ORDER BY re.description ASC"; + // Prevent sql error on the ambiguous column + if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql = preg_replace('/(.*)(?!re\.)fk_facture_source(.*)/m', '\1 re.fk_facture_source \2', $sql); + dol_syslog(get_class($this)."::select_remises", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -1225,6 +1230,8 @@ class Form $disabled=' disabled'; } + if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->facnumber)) $desc=$desc.' - '.$obj->facnumber; + print ''; $i++; } From 647c4036cf105436048febbefd391702193fd845 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Fri, 13 Oct 2017 09:21:37 +0200 Subject: [PATCH 2/2] Fix simplification of code --- htdocs/core/class/html.form.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 5330ce24048..8de5ba47ceb 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1188,17 +1188,12 @@ class Form // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source"; - if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql.= ", f.facnumber"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; - if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture f ON (f.rowid = re.fk_facture_source)"; $sql.= " WHERE re.fk_soc = ".(int) $socid; $sql.= " AND re.entity = " . $conf->entity; if ($filter) $sql.= " AND ".$filter; $sql.= " ORDER BY re.description ASC"; - // Prevent sql error on the ambiguous column - if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST)) $sql = preg_replace('/(.*)(?!re\.)fk_facture_source(.*)/m', '\1 re.fk_facture_source \2', $sql); - dol_syslog(get_class($this)."::select_remises", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -1230,7 +1225,11 @@ class Form $disabled=' disabled'; } - if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->facnumber)) $desc=$desc.' - '.$obj->facnumber; + if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) + { + $tmpfac = new Facture($this->db); + if ($tmpfac->fetch($obj->fk_facture_source) > 0) $desc=$desc.' - '.$tmpfac->ref; + } print ''; $i++;