From 94f6b8ce6ca5043b9f4cd32cf9e4ddb080aa71c7 Mon Sep 17 00:00:00 2001 From: jyhere Date: Fri, 12 Apr 2024 12:21:03 +0200 Subject: [PATCH 01/29] FIX : db transaction not rolled back if Product::setMultilangs() returns an error (#29332) --- htdocs/product/class/product.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 479d6b9e6b2..47e83839598 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1329,6 +1329,7 @@ class Product extends CommonObject if (getDolGlobalInt('MAIN_MULTILANGS')) { if ($this->setMultiLangs($user) < 0) { $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql; + $this->db->rollback(); return -2; } } From 12400725919483300d80a16163d00c361331f578 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 13:53:18 +0200 Subject: [PATCH 02/29] QUAL Make the same condition only once. --- dev/translation/ignore_translation_keys.lst | 1 - htdocs/core/class/html.form.class.php | 48 +++++++++++-------- htdocs/langs/en_US/main.lang | 1 + .../tpl/linesalesrepresentative.tpl.php | 1 + 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/dev/translation/ignore_translation_keys.lst b/dev/translation/ignore_translation_keys.lst index 908b56407cc..9540dbdb8ad 100644 --- a/dev/translation/ignore_translation_keys.lst +++ b/dev/translation/ignore_translation_keys.lst @@ -312,7 +312,6 @@ Empty End EnterAnIP EnterNameOfDictionnaryToDeleteDesc -EntityNameNotDefined Entries ErrSCAAuthentication Error sql diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 79895728c3d..9de260d1aaa 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1993,23 +1993,23 @@ class Form /** * Return select list of users * - * @param string|int|User $selected User id or user object of user preselected. If 0 or < -2, we use id of current user. If -1 or '', keep unselected (if empty is allowed) - * @param string $htmlname Field name in form + * @param string|int|User $selected User id or user object of user preselected. If 0 or < -2, we use id of current user. If -1 or '', keep unselected (if empty is allowed) + * @param string $htmlname Field name in form * @param int<0,1>|string $show_empty 0=list with no empty value, 1=add also an empty value into list - * @param int[]|null $exclude Array list of users id to exclude - * @param int $disabled If select list must be disabled - * @param int[]|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me - * @param array|string $enableonly Array list of users id to be enabled. If defined, it means that others will be disabled - * @param string $force_entity '0' or list of Ids of environment to force separated by a coma - * @param int $maxlength Maximum length of string into list (0=no limit) - * @param int<-1,1> $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status - * @param string $morefilter Add more filters into sql request (Example: 'employee = 1'). This value must not come from user input. - * @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list - * @param string $enableonlytext If option $enableonlytext is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. - * @param string $morecss More css - * @param int<0,1> $notdisabled Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). - * @param int<0,2> $outputmode 0=HTML select string, 1=Array - * @param bool $multiple add [] in the name of element and add 'multiple' attribute + * @param int[]|null $exclude Array list of users id to exclude + * @param int $disabled If select list must be disabled + * @param int[]|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me + * @param array|string $enableonly Array list of users id to be enabled. If defined, it means that others will be disabled + * @param string $force_entity '0' or list of Ids of environment to force separated by a coma + * @param int $maxlength Maximum length of string into list (0=no limit) + * @param int<-1,1> $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status + * @param string $morefilter Add more filters into sql request (Example: 'employee = 1'). This value must not come from user input. + * @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list + * @param string $enableonlytext If option $enableonlytext is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. + * @param string $morecss More css + * @param int<0,1> $notdisabled Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). + * @param int<0,2> $outputmode 0=HTML select string, 1=Array + * @param bool $multiple add [] in the name of element and add 'multiple' attribute * @param int<0,1> $forcecombo Force the component to be a simple combo box without ajax * @return string|array HTML select string * @see select_dolgroups() @@ -2053,14 +2053,21 @@ class Form $outarray = array(); $outarray2 = array(); + // Do we want to show the label of entity into the combo list ? + $showlabelofentity = isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity); + // Forge request to select users $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo"; - if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { + if ($showlabelofentity) { $sql .= ", e.label"; } $sql .= " FROM " . $this->db->prefix() . "user as u"; - if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { + if ($showlabelofentity) { $sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity"; + } + // The rule here to link with entity was not the same tham into getSalesRepresentatives->getSalesRepresentatives + // So i modified to match the samerule. + if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { if (!empty($force_entity)) { $sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")"; } else { @@ -2073,6 +2080,7 @@ class Form $sql .= " WHERE u.entity IN (" . getEntity('user') . ")"; } } + if (!empty($user->socid)) { $sql .= " AND u.fk_soc = " . ((int) $user->socid); } @@ -2182,14 +2190,14 @@ class Form $moreinfohtml .= ($moreinfohtml ? ' - ' : ' (') . $langs->trans('Disabled'); } } - if (isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity)) { + if ($showlabelofentity) { if (empty($obj->entity)) { $moreinfo .= ($moreinfo ? ' - ' : ' (') . $langs->trans("AllEntities"); $moreinfohtml .= ($moreinfohtml ? ' - ' : ' (') . $langs->trans("AllEntities"); } else { if ($obj->entity != $conf->entity) { $moreinfo .= ($moreinfo ? ' - ' : ' (') . ($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined")); - $moreinfohtml .= ($moreinfohtml ? ' - ' : ' (') . ($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined")); + $moreinfohtml .= ($moreinfohtml ? ' - ' : ' (').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined")); } } } diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 235f2d7c037..862b17d247a 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1284,3 +1284,4 @@ ShowSearchFields=Do a search MyUserCard=My user file PublicFile=Public file FillPageWithALayout=Fill page with a layout +EntityNameNotDefined=No entity name diff --git a/htdocs/societe/tpl/linesalesrepresentative.tpl.php b/htdocs/societe/tpl/linesalesrepresentative.tpl.php index 58c6e20f93c..28395b37897 100644 --- a/htdocs/societe/tpl/linesalesrepresentative.tpl.php +++ b/htdocs/societe/tpl/linesalesrepresentative.tpl.php @@ -51,6 +51,7 @@ if ($action == 'editsalesrepresentatives') { print ''; } else { $listsalesrepresentatives = $object->getSalesRepresentatives($user); + $nbofsalesrepresentative = count($listsalesrepresentatives); if ($nbofsalesrepresentative > 0 && is_array($listsalesrepresentatives)) { $userstatic = new User($db); From 3187d2888ead9fd11e29b1265ec16a7ab22729a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 13:55:41 +0200 Subject: [PATCH 03/29] Trans --- dev/translation/ignore_translation_keys.lst | 1 - htdocs/langs/en_US/main.lang | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/translation/ignore_translation_keys.lst b/dev/translation/ignore_translation_keys.lst index 9540dbdb8ad..49834451dab 100644 --- a/dev/translation/ignore_translation_keys.lst +++ b/dev/translation/ignore_translation_keys.lst @@ -103,7 +103,6 @@ Adherent AdherentNotLinkedToThirdParty AdvTgtUse Agents -AllEntities AllFilesDidAlreadyExist AlreadyInV7 AmountOfOrders diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 862b17d247a..147758437b0 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1285,3 +1285,4 @@ MyUserCard=My user file PublicFile=Public file FillPageWithALayout=Fill page with a layout EntityNameNotDefined=No entity name +AllEntities=All entities From 19d4726e4c3b0c4ec3ba6e87ef7d21d69f674bd7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 14:22:02 +0200 Subject: [PATCH 04/29] Use WHERE IN instead of SELECT DISTINCT --- htdocs/core/class/html.form.class.php | 8 ++++---- htdocs/societe/class/societe.class.php | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9de260d1aaa..15678014cf4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2000,7 +2000,7 @@ class Form * @param int $disabled If select list must be disabled * @param int[]|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me * @param array|string $enableonly Array list of users id to be enabled. If defined, it means that others will be disabled - * @param string $force_entity '0' or list of Ids of environment to force separated by a coma + * @param string $force_entity '0' or list of Ids of environment to force, separated by a coma * @param int $maxlength Maximum length of string into list (0=no limit) * @param int<-1,1> $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request (Example: 'employee = 1'). This value must not come from user input. @@ -2055,6 +2055,7 @@ class Form // Do we want to show the label of entity into the combo list ? $showlabelofentity = isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity); + $userissuperadminonentityone = isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity); // Forge request to select users $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo"; @@ -2065,9 +2066,8 @@ class Form if ($showlabelofentity) { $sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity"; } - // The rule here to link with entity was not the same tham into getSalesRepresentatives->getSalesRepresentatives - // So i modified to match the samerule. - if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { + // Condition here should be the same than into societe->getSalesRepresentatives(). + if ($userissuperadminonentityone) { if (!empty($force_entity)) { $sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")"; } else { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index e2da61fb620..93043ed0367 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2518,10 +2518,10 @@ class Societe extends CommonObject * Return array of sales representatives * * @param User $user Object user (not used) - * @param int $mode 0=Array with properties, 1=Array of id. + * @param int $mode 0=Array with properties, 1=Array of IDs. * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; - * @return array|int Array of sales representatives of third party or <0 if KO + * @return array|int Array of sales representatives of the current third party or <0 if KO */ public function getSalesRepresentatives(User $user, $mode = 0, $sortfield = null, $sortorder = null) { @@ -2529,16 +2529,14 @@ class Societe extends CommonObject $reparray = array(); - $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo, u.gender"; + $sql = "SELECT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo, u.gender"; $sql .= ", u.office_fax, u.user_mobile, u.personal_mobile"; $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u"; + // Condition here should be the same than into select_dolusers() if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) { - $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; - $sql .= " WHERE ((ug.fk_user = sc.fk_user"; - $sql .= " AND ug.entity = ".$conf->entity.")"; - $sql .= " OR u.admin = 1)"; + $sql .= " WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))"; } else { - $sql .= " WHERE entity in (0, ".$conf->entity.")"; + $sql .= " WHERE entity IN (0, ".$this->db->sanitize($conf->entity).")"; } $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".((int) $this->id); From 60578402f4ee67f1298c8fa65ca429e6bc96553b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 14:32:27 +0200 Subject: [PATCH 05/29] Fix when we assign sale representatives to a thirdparty, list must be the default list with same condition than into getSalesRepresentatives() --- htdocs/core/class/html.form.class.php | 6 +++--- htdocs/societe/tpl/linesalesrepresentative.tpl.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 15678014cf4..16366d4e257 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2000,7 +2000,7 @@ class Form * @param int $disabled If select list must be disabled * @param int[]|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me * @param array|string $enableonly Array list of users id to be enabled. If defined, it means that others will be disabled - * @param string $force_entity '0' or list of Ids of environment to force, separated by a coma + * @param string $force_entity '0' or list of Ids of environment to force, separated by a coma, or 'default' = do no extend to all entities allowed to superadmin. * @param int $maxlength Maximum length of string into list (0=no limit) * @param int<-1,1> $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request (Example: 'employee = 1'). This value must not come from user input. @@ -2055,7 +2055,7 @@ class Form // Do we want to show the label of entity into the combo list ? $showlabelofentity = isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity); - $userissuperadminonentityone = isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity); + $userissuperadminentityone = isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity); // Forge request to select users $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo"; @@ -2067,7 +2067,7 @@ class Form $sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity"; } // Condition here should be the same than into societe->getSalesRepresentatives(). - if ($userissuperadminonentityone) { + if ($userissuperadminentityone && $force_entity != 'default') { if (!empty($force_entity)) { $sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")"; } else { diff --git a/htdocs/societe/tpl/linesalesrepresentative.tpl.php b/htdocs/societe/tpl/linesalesrepresentative.tpl.php index 28395b37897..fa766a17d5c 100644 --- a/htdocs/societe/tpl/linesalesrepresentative.tpl.php +++ b/htdocs/societe/tpl/linesalesrepresentative.tpl.php @@ -41,7 +41,8 @@ if ($action == 'editsalesrepresentatives') { print ''; print ''; print ''; - $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); + $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 'default', 0, 0, '', 0, '', '', 0, 1); + $arrayselected = GETPOST('commercial', 'array'); if (empty($arrayselected)) { $arrayselected = $object->getSalesRepresentatives($user, 1); From e414f06835865d8c7d994d5e1c0b37471b5721f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:57:08 +0200 Subject: [PATCH 06/29] add thirdparty category filter (#29313) * add thirdparty category filter * Update cabyprodserv.php --- htdocs/compta/stats/cabyprodserv.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index 0d364c64625..fd49e5bfef4 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -4,6 +4,7 @@ * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2018 Frédéric France * Copyright (C) 2022 Alexandre Spangaro + * Copyright (C) 2024 Charlene Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,6 +66,7 @@ if (!$sortfield) { // Category $selected_cat = GETPOSTINT('search_categ'); +$selected_catsoc = (int) GETPOST('search_categ_soc', 'int'); $selected_soc = GETPOSTINT('search_soc'); $subcat = false; if (GETPOST('subcat', 'alpha') === 'yes') { @@ -196,6 +198,9 @@ $tableparams = array(); if (!empty($selected_cat)) { $tableparams['search_categ'] = $selected_cat; } +if (!empty($selected_catsoc)) { + $tableparams['search_categ_soc'] = $selected_catsoc; +} if (!empty($selected_soc)) { $tableparams['search_soc'] = $selected_soc; } @@ -303,6 +308,9 @@ if ($modecompta == 'CREANCES-DETTES') { if ($selected_cat === -2) { // Without any category $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; } + if ($selected_catsoc === -2) { // Without any category + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as ct ON soc.rowid = ct.fk_soc"; + } $parameters = array(); $hookmanager->executeHooks('printFieldListFrom', $parameters); @@ -346,6 +354,14 @@ if ($modecompta == 'CREANCES-DETTES') { } $sql .= "))"; } + if ($selected_catsoc === -2) { // Without any category + $sql .= " AND ct.fk_soc is null"; + } elseif ($selected_catsoc > 0) { // Into a specific category + $sql .= " AND (soc.rowid IN "; + $sql .= " (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ct WHERE "; + $sql .= "ct.fk_categorie = ".((int) $selected_catsoc); + $sql .= "))"; + } if ($selected_soc > 0) { $sql .= " AND soc.rowid=".((int) $selected_soc); } @@ -415,6 +431,9 @@ if ($modecompta == 'CREANCES-DETTES') { //select thirdparty print '
'; + print img_picto('', 'category', 'class="paddingrightonly"'); + print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc, 'search_categ_soc', 0, $langs->trans("CustomersProspectsCategoriesShort")); + print '
'; print img_picto('', 'company', 'class="paddingrightonly"'); print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); print ''; From e5240123a12a973a80e02c26b551c7cf67858e6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 19:24:31 +0200 Subject: [PATCH 07/29] Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop --- htdocs/compta/stats/cabyprodserv.php | 125 ++++++++++++++++++-------- htdocs/core/class/html.form.class.php | 10 +-- 2 files changed, 92 insertions(+), 43 deletions(-) diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index fd49e5bfef4..d7b4aaaa5ad 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -65,9 +65,9 @@ if (!$sortfield) { } // Category -$selected_cat = GETPOSTINT('search_categ'); -$selected_catsoc = (int) GETPOST('search_categ_soc', 'int'); -$selected_soc = GETPOSTINT('search_soc'); +$selected_cat = GETPOST('search_categ', 'intcomma'); +$selected_catsoc = GETPOST('search_categ_soc', 'intcomma'); +$selected_soc = GETPOST('search_soc', 'intcomma'); $subcat = false; if (GETPOST('subcat', 'alpha') === 'yes') { $subcat = true; @@ -75,7 +75,7 @@ if (GETPOST('subcat', 'alpha') === 'yes') { $categorie = new Categorie($db); // product/service -$selected_type = GETPOSTINT('search_type'); +$selected_type = GETPOST('search_type', 'intcomma'); if ($selected_type == '') { $selected_type = -1; } @@ -216,7 +216,7 @@ $tableparams = array_merge($commonparams, $tableparams); $paramslink = ""; foreach ($allparams as $key => $value) { - $paramslink .= '&'.$key.'='.$value; + $paramslink .= '&'.urlencode($key).'='.urlencode($value); } @@ -282,7 +282,6 @@ if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { } - $name = array(); // SQL request @@ -291,7 +290,7 @@ $catotal_ht = 0; $qtytotal = 0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,"; + $sql = "SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,"; $sql .= " SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,"; $sql .= " SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty"; @@ -305,12 +304,14 @@ if ($modecompta == 'CREANCES-DETTES') { } $sql .= ",".MAIN_DB_PREFIX."facturedet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid"; + /* if ($selected_cat === -2) { // Without any category $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; } if ($selected_catsoc === -2) { // Without any category $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as ct ON soc.rowid = ct.fk_soc"; } + */ $parameters = array(); $hookmanager->executeHooks('printFieldListFrom', $parameters); @@ -330,38 +331,81 @@ if ($modecompta == 'CREANCES-DETTES') { if ($selected_type >= 0) { $sql .= " AND l.product_type = ".((int) $selected_type); } - if ($selected_cat === -2) { // Without any category - $sql .= " AND cp.fk_product is null"; - } elseif ($selected_cat > 0) { // Into a specific category - if ($subcat) { - $TListOfCats = $categorie->get_full_arbo('product', $selected_cat, 1); - $listofcatsql = ""; - foreach ($TListOfCats as $key => $cat) { - if ($key !== 0) { - $listofcatsql .= ","; + // Search for tag/category ($searchCategoryProductList is an array of ID) + $searchCategoryProductOperator = -1; + $searchCategoryProductList = array($selected_cat); + if ($subcat) { + $TListOfCats = $categorie->get_full_arbo('product', $selected_cat, 1); + + $listofcatsql = ""; + foreach ($TListOfCats as $key => $cat) { + if ($key !== 0) { + $listofcatsql .= ","; + } + $listofcatsql .= $cat['rowid']; + } + $searchCategoryProductList = explode(',', $listofcatsql); + } + if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); } - $listofcatsql .= $cat['rowid']; } } - - $sql .= " AND (p.rowid IN "; - $sql .= " (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product cp WHERE "; - if ($subcat) { - $sql .= "cp.fk_categorie IN (".$db->sanitize($listofcatsql).")"; - } else { - $sql .= "cp.fk_categorie = ".((int) $selected_cat); + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } } - $sql .= "))"; } - if ($selected_catsoc === -2) { // Without any category - $sql .= " AND ct.fk_soc is null"; - } elseif ($selected_catsoc > 0) { // Into a specific category - $sql .= " AND (soc.rowid IN "; - $sql .= " (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ct WHERE "; - $sql .= "ct.fk_categorie = ".((int) $selected_catsoc); - $sql .= "))"; + + // Search for tag/category ($searchCategorySocieteList is an array of ID) + $searchCategorySocieteOperator = -1; + $searchCategorySocieteList = array($selected_catsoc); + if (!empty($searchCategorySocieteList)) { + $searchCategorySocieteSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategorySocieteList as $searchCategorySociete) { + if (intval($searchCategorySociete) == -2) { + $searchCategorySocieteSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc)"; + } elseif (intval($searchCategorySociete) > 0) { + if ($searchCategorySocieteOperator == 0) { + $searchCategorySocieteSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategorySociete).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySociete); + } + } + } + if ($listofcategoryid) { + $searchCategorySocieteSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategorySocieteOperator == 1) { + if (!empty($searchCategorySocieteSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategorySocieteSqlList).")"; + } + } else { + if (!empty($searchCategorySocieteSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategorySocieteSqlList).")"; + } + } } + if ($selected_soc > 0) { $sql .= " AND soc.rowid=".((int) $selected_soc); } @@ -376,6 +420,7 @@ if ($modecompta == 'CREANCES-DETTES') { dol_syslog("cabyprodserv", LOG_DEBUG); $result = $db->query($sql); + $amount_ht = array(); $amount = array(); $qty = array(); @@ -384,6 +429,7 @@ if ($modecompta == 'CREANCES-DETTES') { $i = 0; while ($i < $num) { $obj = $db->fetch_object($result); + $amount_ht[$obj->rowid] = $obj->amount; $amount[$obj->rowid] = $obj->amount_ttc; $qty[$obj->rowid] = $obj->qty; @@ -415,7 +461,7 @@ if ($modecompta == 'CREANCES-DETTES') { // Category filter print ''; print ''; - print img_picto('', 'category', 'class="paddingrightonly"'); + print img_picto('', 'category', 'class="pictofixedwidth"'); print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', 0, $langs->trans("Category")); print ' '; print $langs->trans("SubCats").'? '; @@ -430,12 +476,13 @@ if ($modecompta == 'CREANCES-DETTES') { $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); //select thirdparty - print '
'; - print img_picto('', 'category', 'class="paddingrightonly"'); + print '
'; + print img_picto('', 'category', 'class="pictofixedwidth"'); print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc, 'search_categ_soc', 0, $langs->trans("CustomersProspectsCategoriesShort")); - print '
'; - print img_picto('', 'company', 'class="paddingrightonly"'); - print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); + print '
'; + print img_picto('', 'company', 'class="pictofixedwidth"'); + print $form->select_company($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); + //print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); print ''; print ''; @@ -573,6 +620,8 @@ if ($modecompta == 'CREANCES-DETTES') { print ''; $db->free($result); + } else { + print ''.$langs->trans("NoRecordFound");''; } print ""; print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ca12d6e20b4..69e74aab4d3 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1396,6 +1396,7 @@ class Form * @param string[] $excludeids Exclude IDs from the select combo * @param int<0,1> $showcode Show code in list * @return array|string HTML string with + * @see select_company() */ public function select_thirdparty_list($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false, $excludeids = array(), $showcode = 0) { @@ -1510,11 +1511,6 @@ class Form dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - if (!$forcecombo) { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out .= ajax_combobox($htmlname, $events, getDolGlobalString("COMPANY_USE_SEARCH_TO_SELECT")); - } - // Construct $out and $outarray $out .= '' . "\n"; + if (!$forcecombo) { + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname, $events, getDolGlobalString("COMPANY_USE_SEARCH_TO_SELECT")); + } } else { dol_print_error($this->db); } From 5e74bd4db8882c990dd329a31474721891ea46ce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2024 19:45:49 +0200 Subject: [PATCH 08/29] Fix filter on company. --- htdocs/compta/stats/cabyprodserv.php | 33 ++++++--------------------- htdocs/core/class/html.form.class.php | 18 ++++++++++----- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index d7b4aaaa5ad..b58ccbe9a83 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -22,7 +22,7 @@ /** * \file htdocs/compta/stats/cabyprodserv.php - * \brief Page reporting TO by Products & Services + * \brief Page reporting Turnover billed by Products & Services */ // Load Dolibarr environment @@ -299,19 +299,8 @@ if ($modecompta == 'CREANCES-DETTES') { $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - if ($selected_soc > 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)"; - } $sql .= ",".MAIN_DB_PREFIX."facturedet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid"; - /* - if ($selected_cat === -2) { // Without any category - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; - } - if ($selected_catsoc === -2) { // Without any category - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as ct ON soc.rowid = ct.fk_soc"; - } - */ $parameters = array(); $hookmanager->executeHooks('printFieldListFrom', $parameters); @@ -337,15 +326,10 @@ if ($modecompta == 'CREANCES-DETTES') { $searchCategoryProductList = array($selected_cat); if ($subcat) { $TListOfCats = $categorie->get_full_arbo('product', $selected_cat, 1); - - $listofcatsql = ""; + $searchCategoryProductList = array(); foreach ($TListOfCats as $key => $cat) { - if ($key !== 0) { - $listofcatsql .= ","; - } - $listofcatsql .= $cat['rowid']; + $searchCategoryProductList[] = $cat['rowid']; } - $searchCategoryProductList = explode(',', $listofcatsql); } if (!empty($searchCategoryProductList)) { $searchCategoryProductSqlList = array(); @@ -407,7 +391,7 @@ if ($modecompta == 'CREANCES-DETTES') { } if ($selected_soc > 0) { - $sql .= " AND soc.rowid=".((int) $selected_soc); + $sql .= " AND f.fk_soc = ".((int) $selected_soc); } $sql .= " AND f.entity IN (".getEntity('invoice').")"; @@ -464,16 +448,14 @@ if ($modecompta == 'CREANCES-DETTES') { print img_picto('', 'category', 'class="pictofixedwidth"'); print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', 0, $langs->trans("Category")); print ' '; - print $langs->trans("SubCats").'? '; - print ''; + print ''; // type filter (produit/service) - print ' '; - print $langs->trans("Type").': '; - $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); + $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', $langs->trans("Type"), 1, 1); //select thirdparty print '
'; @@ -482,7 +464,6 @@ if ($modecompta == 'CREANCES-DETTES') { print '
'; print img_picto('', 'company', 'class="pictofixedwidth"'); print $form->select_company($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); - //print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); print ''; print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 69e74aab4d3..7c96c34a295 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1148,11 +1148,11 @@ class Form * Return list of types of lines (product or service) * Example: 0=product, 1=service, 9=other (for external module) * - * @param string $selected Preselected type - * @param string $htmlname Name of field in html form - * @param int<0,1> $showempty Add an empty field - * @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select) - * @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, 2=Force to show only Products, 3=Force to show only services, -1=Force none (and set hidden field to 'service') + * @param string $selected Preselected type + * @param string $htmlname Name of field in html form + * @param int<0,1>|string $showempty Add an empty field + * @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select) + * @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, 2=Force to show only Products, 3=Force to show only services, -1=Force none (and set hidden field to 'service') * @return void */ public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0) @@ -1172,7 +1172,13 @@ class Form if ($selected == -1) { print ' selected'; } - print '> '; + print '>'; + if (is_numeric($showempty)) { + print ' '; + } else { + print $showempty; + } + print ''; } print '