From 94c6bea4e1e901db8a8be4eea011e78284766e13 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Apr 2026 15:36:52 +0200 Subject: [PATCH] Debug v24 --- .../template/class/myobjectstats.class.php | 20 +++++++++++-------- .../template/stats/myobject_index.php | 8 +++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/htdocs/modulebuilder/template/class/myobjectstats.class.php b/htdocs/modulebuilder/template/class/myobjectstats.class.php index 4c4afdb105d..603c1a80e4d 100644 --- a/htdocs/modulebuilder/template/class/myobjectstats.class.php +++ b/htdocs/modulebuilder/template/class/myobjectstats.class.php @@ -105,29 +105,33 @@ class MyObjectStats extends Stats $this->userid = $userid; $this->cachefilesuffix = $mode; $this->join = ''; - $object = null; $object = new MyObject($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; + if ($object->ismultientitymanaged && (string) $object->ismultientitymanaged != '1') { + // $object->ismultientitymanaged is 'field@table' + $tmparray = explode('@', (string) $object->ismultientitymanaged); + $field = $tmparray[0]; + $table = $tmparray[1]; + $this->from = " INNER JOIN ".MAIN_DB_PREFIX.$table." as e ON c.".$this->db->sanitize($field)." = e.rowid AND e.entity IN (".getEntity($table.'@mymodule').")"; + } $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; $this->field = 'total_ht'; $this->field_line = 'total_ht'; //$this->where .= " c.status > 0"; // Not draft and not cancelled $this->categ_link = MAIN_DB_PREFIX.'categorie_societe'; - //$this->where.= " AND c.socid = s.rowid AND c.entity = ".$conf->entity; - if ($object->ismultientitymanaged) { - $this->where .= ($this->where ? ' AND ' : '').'c.entity IN ('.getEntity('myobject@mymodule').')'; + if ((string) $object->ismultientitymanaged == '1') { + $this->where .= ($this->where ? ' AND ' : '')."c.entity IN (".getEntity('myobject@mymodule').")"; } - if ($this->socid) { - $this->where .= " AND c.fk_soc = ".((int) $this->socid); + $this->where .= ($this->where ? ' AND ' : '')."c.fk_soc = ".((int) $this->socid); } if ($this->userid > 0) { - $this->where .= ' AND c.fk_user_author = '.((int) $this->userid); + $this->where .= ($this->where ? ' AND ' : '')."c.fk_user_creat = ".((int) $this->userid); } if ($categid) { - $this->where .= ' AND EXISTS (SELECT rowid FROM '.$this->categ_link.' as cats WHERE cats.fk_soc = c.fk_soc AND cats.fk_categorie = '.((int) $categid).')'; + $this->where .= ($this->where ? ' AND ' : '').'EXISTS (SELECT rowid FROM '.$this->db->sanitize($this->categ_link).' as cats WHERE cats.fk_soc = c.fk_soc AND cats.fk_categorie = '.((int) $categid).')'; } // Add where from hooks $parameters = array('socid' => $socid); diff --git a/htdocs/modulebuilder/template/stats/myobject_index.php b/htdocs/modulebuilder/template/stats/myobject_index.php index cb24cff96cf..55d542a7895 100644 --- a/htdocs/modulebuilder/template/stats/myobject_index.php +++ b/htdocs/modulebuilder/template/stats/myobject_index.php @@ -351,9 +351,11 @@ print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widt print ''; */ // User -print ''.$langs->trans("CreatedBy").''; -print img_picto('', 'user', 'class="pictofixedwidth"'); -print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300'); +if (array_key_exists('fk_user_creat', $object->fields)) { + print ''.$langs->trans("CreatedBy").''; + print img_picto('', 'user', 'class="pictofixedwidth"'); + print $form->select_dolusers($userid, 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300'); +} // Status if (array_key_exists('status', $object->fields)) { print ''.$langs->trans("Status").'';