From 225e69a4de04b4c8b825165b00449e97854d7177 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Fri, 1 Feb 2019 15:59:58 +0100 Subject: [PATCH 1/5] Fix filter by event type Emailing in show actions done (companylib) --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 8b8bfb923f0..2d0b08b22d4 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1469,7 +1469,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. - if (! empty($conf->mailing->enabled) && ! empty($objcon->email)) + if (! empty($conf->mailing->enabled) && ! empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) { $langs->load("mails"); From f4c5f1e3f1e5ab4104eca7409c7bb82952bf1a56 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Tue, 5 Feb 2019 17:02:43 +0100 Subject: [PATCH 2/5] Revert "Fix filter by event type Emailing in show actions done (companylib)" This reverts commit 225e69a4de04b4c8b825165b00449e97854d7177. --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2d0b08b22d4..8b8bfb923f0 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1469,7 +1469,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. - if (! empty($conf->mailing->enabled) && ! empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) + if (! empty($conf->mailing->enabled) && ! empty($objcon->email)) { $langs->load("mails"); From 727213a5fdc28704505a5ca58f6f8d8797b20fea Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Tue, 5 Feb 2019 17:04:46 +0100 Subject: [PATCH 3/5] Fix margin by users when a thirdparty have many sellers --- htdocs/margin/agentMargins.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index d42a2b8d6e3..a8cd77b846f 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -126,7 +126,8 @@ dol_fiche_end(); print ''; $sql = "SELECT"; -if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; +$sql.= " s.rowid as socid,"; +if ($agentid > 0) $sql.= " s.nom as name, s.code_client, s.client,"; $sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; $sql.= " sum(d.total_ht) as selling_price,"; // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this) @@ -213,9 +214,29 @@ if ($result) { $objp = $db->fetch_object($result); - $pa = $objp->buying_price; - $pv = $objp->selling_price; - $marge = $objp->marge; + $seller_nb = 1; + if ($objp->socid > 0) { + // sql nb sellers + $sql_seller = "SELECT COUNT(sc.rowid) as nb"; + $sql_seller .= " FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql_seller .= " WHERE sc.fk_soc = " . $objp->socid; + $sql_seller .= " LIMIT 1"; + + $resql_seller = $db->query($sql_seller); + if (!$resql_seller) { + dol_print_error($db); + } else { + if ($obj_seller = $db->fetch_object($resql_seller)) { + if ($obj_seller->nb > 0) { + $seller_nb = $obj_seller->nb; + } + } + } + } + + $pa = $objp->buying_price / $seller_nb; + $pv = $objp->selling_price / $seller_nb; + $marge = $objp->marge / $seller_nb; if ($marge < 0) { From b87df1829258761c62d0933a75ee41f8c33e51e3 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Wed, 6 Feb 2019 09:37:19 +0100 Subject: [PATCH 4/5] Fix the margin rate by seller when the margin is negative --- htdocs/margin/agentMargins.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index a8cd77b846f..0ad6563767c 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -238,16 +238,8 @@ if ($result) $pv = $objp->selling_price / $seller_nb; $marge = $objp->marge / $seller_nb; - if ($marge < 0) - { - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; - } - else - { - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; - } + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; print ''; if ($agentid > 0) { From 3f01cd554bf561ef646647c82003c1092d977120 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Feb 2019 09:50:45 +0100 Subject: [PATCH 5/5] Update agentMargins.php --- htdocs/margin/agentMargins.php | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 0ad6563767c..aae859666e7 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -214,32 +214,31 @@ if ($result) { $objp = $db->fetch_object($result); - $seller_nb = 1; - if ($objp->socid > 0) { - // sql nb sellers - $sql_seller = "SELECT COUNT(sc.rowid) as nb"; - $sql_seller .= " FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; - $sql_seller .= " WHERE sc.fk_soc = " . $objp->socid; - $sql_seller .= " LIMIT 1"; + $seller_nb = 1; + if ($objp->socid > 0) { + // sql nb sellers + $sql_seller = "SELECT COUNT(sc.rowid) as nb"; + $sql_seller .= " FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql_seller .= " WHERE sc.fk_soc = " . $objp->socid; - $resql_seller = $db->query($sql_seller); - if (!$resql_seller) { - dol_print_error($db); - } else { - if ($obj_seller = $db->fetch_object($resql_seller)) { - if ($obj_seller->nb > 0) { - $seller_nb = $obj_seller->nb; + $resql_seller = $db->query($sql_seller); + if (!$resql_seller) { + dol_print_error($db); + } else { + if ($obj_seller = $db->fetch_object($resql_seller)) { + if ($obj_seller->nb > 0) { + $seller_nb = $obj_seller->nb; + } + } } } - } - } - $pa = $objp->buying_price / $seller_nb; - $pv = $objp->selling_price / $seller_nb; - $marge = $objp->marge / $seller_nb; + $pa = $objp->buying_price / $seller_nb; + $pv = $objp->selling_price / $seller_nb; + $marge = $objp->marge / $seller_nb; - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; print ''; if ($agentid > 0) {