From 6789b7bd1ef54e32142997b4bf16e0c75b121fbf Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 18 Dec 2019 18:23:31 +0100 Subject: [PATCH 1/7] Fix day scale unit --- htdocs/install/mysql/data/llx_c_units.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/data/llx_c_units.sql b/htdocs/install/mysql/data/llx_c_units.sql index f055561f633..905f3d344be 100644 --- a/htdocs/install/mysql/data/llx_c_units.sql +++ b/htdocs/install/mysql/data/llx_c_units.sql @@ -55,7 +55,7 @@ INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VAL INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('S', '0','second','s', 'time', 1); INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('MI', '60','minute','i', 'time', 1); INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('H', '3600','hour','h', 'time', 1); -INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('D','12960000','day','d', 'time', 1); +INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('D', '86400','day','d', 'time', 1); INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('W', '604800','week','w', 'time', 1); INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('MO','2629800','month','m', 'time', 1); INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('Y','31557600','year','y', 'time', 1); From 063c139feefe0a7d6552a14c0649aa3c83aa5ca0 Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 19 Dec 2019 11:52:30 +0100 Subject: [PATCH 2/7] Situation Invoice Compatibility take progress percent into account in buying price --- htdocs/margin/productMargins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index 22dfd0146b1..8ec46c3e8ed 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -181,8 +181,8 @@ if ($id > 0) $sql.= " d.fk_product,"; if ($id > 0) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; $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) -$sql.= " SUM(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; -$sql.= " SUM(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge"; +$sql.= " SUM(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1 * (d.situation_percent / 100)', 'd.qty * d.buy_price_ht * (d.situation_percent / 100)').") as buying_price,"; +$sql.= " SUM(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100)))', 'd.total_ht - (d.buy_price_ht * d.qty * (d.situation_percent / 100))').") as marge"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; From 14cf295f22b10269cbb5a111c32f0f8ccb7c4714 Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 19 Dec 2019 11:58:25 +0100 Subject: [PATCH 3/7] Update to integer situation invoice Before : Situation invoice with situation_percent < 100 => Negative and Bad margin (not proportional) Now : Situation invoice with situation_percent < 100 => Correct and proportional. --- htdocs/margin/tabs/productMargins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/margin/tabs/productMargins.php b/htdocs/margin/tabs/productMargins.php index afb1dda37a9..9b62c1b1bca 100644 --- a/htdocs/margin/tabs/productMargins.php +++ b/htdocs/margin/tabs/productMargins.php @@ -137,8 +137,8 @@ if ($id > 0 || ! empty($ref)) if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,"; $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive $sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty) as qty,"; // not always positive in case of Credit note - $sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note - $sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ; // not always positive in case of Credit note + $sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,"; // not always positive in case of Credit note + $sql.= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge" ; // not always positive in case of Credit note $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; From 347eae05acf9b5cc613bb6c946648ddabde28053 Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 19 Dec 2019 12:03:09 +0100 Subject: [PATCH 4/7] Update to integer situation invoice Before : Situation invoice with situation_percent < 100 => Negative and Bad margin (not proportional) Now : Situation invoice with situation_percent < 100 => Correct and proportional. --- htdocs/margin/customerMargins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index 78d105ad5cb..36e033a5e50 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -205,8 +205,8 @@ $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; $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) -$sql.= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; -$sql.= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge"; +$sql.= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1 * (d.situation_percent / 100)', 'd.qty * d.buy_price_ht * (d.situation_percent / 100)').") as buying_price,"; +$sql.= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100)))', 'd.total_ht - (d.buy_price_ht * d.qty * (d.situation_percent / 100))').") as marge"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; From a82f996fcf63d35cb3eb455635cd728f802f3eba Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 19 Dec 2019 12:04:48 +0100 Subject: [PATCH 5/7] Update to integer situation invoice Before : Situation invoice with situation_percent < 100 => Negative and Bad margin (not proportional) Now : Situation invoice with situation_percent < 100 => Correct and proportional. --- htdocs/margin/tabs/thirdpartyMargins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/margin/tabs/thirdpartyMargins.php b/htdocs/margin/tabs/thirdpartyMargins.php index 1d0897a72b0..337190b6c15 100644 --- a/htdocs/margin/tabs/thirdpartyMargins.php +++ b/htdocs/margin/tabs/thirdpartyMargins.php @@ -147,8 +147,8 @@ if ($socid > 0) $sql.= " f.rowid as facid, f.ref, f.total as total_ht,"; $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive - $sql.= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive - $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive + $sql.= " sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,"; // always positive + $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge"; // always positive $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; From 91e2fe9a9997f52d901a6cd964d97ac7b48705e9 Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 19 Dec 2019 12:06:18 +0100 Subject: [PATCH 6/7] Update to integer situation invoice Before : Situation invoice with situation_percent < 100 => Negative and Bad margin (not proportional) Now : Situation invoice with situation_percent < 100 => Correct and proportional. --- htdocs/margin/agentMargins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index b4e323a54c0..96787b1231b 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -139,8 +139,8 @@ $sql.= " s.rowid as socid, 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) -$sql.= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; -$sql.= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge" ; +$sql.= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1 * (d.situation_percent / 100)', 'd.qty * d.buy_price_ht * (d.situation_percent / 100)').") as buying_price,"; +$sql.= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100)))', 'd.total_ht - (d.buy_price_ht * d.qty * (d.situation_percent / 100))').") as marge" ; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE); From 8321fe6ad2b36623600b00f877111be92f8c0661 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 22 Dec 2019 09:13:34 +0100 Subject: [PATCH 7/7] FIX missing nl2br conversion --- htdocs/core/class/CMailFile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 9b1a5a69525..4d796bbcd07 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -444,7 +444,7 @@ class CMailFile } else { $this->message->setBody($msg, 'text/plain'); // And optionally an alternative body - $this->message->addPart($msg, 'text/html'); + $this->message->addPart(dol_nl2br($msg), 'text/html'); } if ($this->atleastonefile)