From f181719769c27f9125f1bb6f379098a8afdbccef Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 10 Apr 2018 18:11:08 +0200 Subject: [PATCH] Can fetch a companypaymentmode of a thirdparty --- htdocs/core/class/commonobject.class.php | 10 ++++++---- htdocs/societe/class/companypaymentmode.class.php | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 25fa78b1067..4eceecbe655 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6792,14 +6792,16 @@ abstract class CommonObject */ public function fetchCommon($id, $ref = null, $morewhere = '') { - if (empty($id) && empty($ref)) return false; + if (empty($id) && empty($ref) && empty($morewhere)) return -1; $sql = 'SELECT '.$this->getFieldList(); $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; - else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); - if ($morewhere) $sql.=$morewhere; + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; + elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); + else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare + if ($morewhere) $sql.= $morewhere; + $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record $res = $this->db->query($sql); if ($res) diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 6a6dfa4d38c..4403d5b8fde 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -268,8 +268,9 @@ class CompanyPaymentMode extends CommonObject */ public function fetch($id, $ref = null, $socid = 0, $type = '') { - if ($socid) $sql.= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1"; - if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; + $morewhere = ''; + if ($socid) $morewhere.= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1"; + if ($type) $morewhere.= " AND type = '".$this->db->escape($type)."'"; $result = $this->fetchCommon($id, $ref, $morewhere); if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();