From e212019ddf353b637ba8298a237a8da1dcbb65fd Mon Sep 17 00:00:00 2001 From: atm-florian Date: Fri, 17 Feb 2023 00:10:00 +0100 Subject: [PATCH 01/11] FIX: SQL error "unknown column p.fk_soc" because ANSI-92 joins take precedence over ANSI-89 joins cf. https://stackoverflow.com/questions/4065985/mysql-unknown-column-in-on-clause --- htdocs/comm/propal/class/propalestats.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 52956fa46fd..834ecd2bacb 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -248,7 +248,7 @@ class PropaleStats extends Stats global $user; $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; - $sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product"; + $sql .= " FROM (".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product)"; if (empty($user->rights->societe->client->voir) && !$user->socid) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } From c3e42f1961a4d46d0c1b40553727eebcf7be12de Mon Sep 17 00:00:00 2001 From: atm-florian Date: Fri, 17 Feb 2023 16:12:06 +0100 Subject: [PATCH 02/11] Propale stats: replace old-style joins with inner joins --- .../comm/propal/class/propalestats.class.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 834ecd2bacb..eb699e01c86 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -247,17 +247,19 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; - $sql .= " FROM (".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product)"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + $sql = 'SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.' . $this->field_line . ') as total, AVG(tl.' . $this->field_line . ') as avg'; + $sql .= ' FROM ' . $this->from; + $sql .= ' INNER JOIN ' . $this->from_line . ' ON p.rowid = tl.fk_propal'; + $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'product as product ON tl.fk_product = product.rowid'; + if (empty($user->rights->societe->client->voir) && ! $user->socid) { + $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ' . ((int) $user->id); } $sql .= $this->join; - $sql .= " WHERE ".$this->where; - $sql .= " AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid"; - $sql .= " AND ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, false))."' AND '".$this->db->idate(dol_get_last_day($year, 12, false))."'"; - $sql .= " GROUP BY product.ref"; + $sql .= ' WHERE ' . $this->where; + $sql .= ' AND ' . $this->field_date . " BETWEEN '" . $this->db->idate(dol_get_first_day($year, 1, false)) . "' AND '" . $this->db->idate(dol_get_last_day($year, 12, false)) . "'"; + $sql .= ' GROUP BY product.ref'; $sql .= $this->db->order('nb', 'DESC'); + //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql, $limit); From b29ebef05fc8394e65196fc5baf8dcb798b7d1cf Mon Sep 17 00:00:00 2001 From: atm-florian Date: Thu, 23 Feb 2023 18:03:00 +0100 Subject: [PATCH 03/11] Propale stats: reworking of the fix to comply with travis rule for SQL string building --- .../comm/propal/class/propalestats.class.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index eb699e01c86..fefc8941970 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -247,19 +247,18 @@ class PropaleStats extends Stats { global $user; - $sql = 'SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.' . $this->field_line . ') as total, AVG(tl.' . $this->field_line . ') as avg'; - $sql .= ' FROM ' . $this->from; - $sql .= ' INNER JOIN ' . $this->from_line . ' ON p.rowid = tl.fk_propal'; - $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'product as product ON tl.fk_product = product.rowid'; - if (empty($user->rights->societe->client->voir) && ! $user->socid) { - $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ' . ((int) $user->id); + $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; + $sql .= " FROM ".$this->from; + $sql .= " INNER JOIN ".$this->from_line." ON p.rowid = tl.fk_propal"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid"; + if (empty($user->rights->societe->client->voir) && !$user->socid) { + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= $this->join; - $sql .= ' WHERE ' . $this->where; - $sql .= ' AND ' . $this->field_date . " BETWEEN '" . $this->db->idate(dol_get_first_day($year, 1, false)) . "' AND '" . $this->db->idate(dol_get_last_day($year, 12, false)) . "'"; - $sql .= ' GROUP BY product.ref'; + $sql .= " WHERE ".$this->where; + $sql .= " AND ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, false))."' AND '".$this->db->idate(dol_get_last_day($year, 12, false))."'"; + $sql .= " GROUP BY product.ref"; $sql .= $this->db->order('nb', 'DESC'); - //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql, $limit); From fd371cc52b517ea26f50d588cc2c8cf19bc520ce Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Fri, 24 Feb 2023 23:31:06 +0100 Subject: [PATCH 04/11] Fix member nature display in new.php --- htdocs/public/members/new.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index d3a2a556b07..aa8498a85a1 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -539,6 +539,8 @@ if (empty($conf->global->MEMBER_NEWFORM_FORCETYPE)) { // Moral/Physic attribute $morphys["phy"] = $langs->trans("Physical"); $morphys["mor"] = $langs->trans("Moral"); +print ''.$langs->trans('MemberNature').' *'."\n"; + if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) { print ''.$langs->trans('MemberNature').' *'."\n"; print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1); From a02e88dc281c0545150ecc7e9f2716a0787208a4 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 26 Feb 2023 22:18:30 +0100 Subject: [PATCH 05/11] Drop the double Must be displayed both in the if and else --- htdocs/public/members/new.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index aa8498a85a1..2df2ec45cbc 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -542,7 +542,6 @@ $morphys["mor"] = $langs->trans("Moral"); print ''.$langs->trans('MemberNature').' *'."\n"; if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) { - print ''.$langs->trans('MemberNature').' *'."\n"; print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1); print ''."\n"; } else { From 1c57b755109a29f2dc3353d7b691287c7a090913 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:04:15 +0100 Subject: [PATCH 06/11] FIX: accountancy lettering: better error management --- htdocs/accountancy/journal/bankjournal.php | 6 ++++++ htdocs/accountancy/journal/purchasesjournal.php | 6 ++++++ htdocs/accountancy/journal/sellsjournal.php | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index a848f8505d8..85c9551b7ec 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -797,6 +797,12 @@ if (!$error && $action == 'writebookkeeping') { require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; $lettering_static = new Lettering($db); $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id)); + + if ($nb_lettering < 0) { + $error++; + $errorforline++; + setEventMessages($lettering_static->error, $lettering_static->errors, 'errors'); + } } } } diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index c175889357c..5f4182762dc 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -380,6 +380,12 @@ if ($action == 'writebookkeeping') { require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; $lettering_static = new Lettering($db); $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id), 'supplier_invoice'); + + if ($nb_lettering < 0) { + $error++; + $errorforline++; + setEventMessages($lettering_static->error, $lettering_static->errors, 'errors'); + } } } } diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index b86f138d232..cb6df055740 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -393,6 +393,13 @@ if ($action == 'writebookkeeping') { require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; $lettering_static = new Lettering($db); $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id), 'customer_invoice'); + + if ($nb_lettering < 0) { + $error++; + $errorforline++; + $errorforinvoice[$key] = 'other'; + setEventMessages($lettering_static->error, $lettering_static->errors, 'errors'); + } } } } From 49afabd440d1db9fc68cc7ea02b285b6b927579e Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:16:04 +0100 Subject: [PATCH 07/11] FIX: accountancy lettering: prevent null results when fetching link with payments --- htdocs/accountancy/class/lettering.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 405a630942e..2f86d6e7e3a 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -655,7 +655,7 @@ class Lettering extends BookKeeping // Get payment lines $sql = "SELECT DISTINCT pe2.$fk_payment_element, pe2.$fk_element"; $sql .= " FROM " . MAIN_DB_PREFIX . "$payment_element AS pe"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "$payment_element AS pe2 ON pe2.$fk_element = pe.$fk_element"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "$payment_element AS pe2 ON pe2.$fk_element = pe.$fk_element"; $sql .= " WHERE pe.$fk_payment_element IN (" . $this->db->sanitize(implode(',', $payment_ids)) . ")"; dol_syslog(__METHOD__ . " - Get payment lines", LOG_DEBUG); From d3edbbb51bfead001c9095396a2a8418668f17d2 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:56:10 +0100 Subject: [PATCH 08/11] FIX: accountancy lettering: correctly calculated number of lettering operations done --- htdocs/accountancy/class/lettering.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 2f86d6e7e3a..48e4eb56647 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -297,6 +297,7 @@ class Lettering extends BookKeeping // Update request $now = dol_now(); + $affected_rows = 0; if (!$error) { $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; @@ -309,6 +310,8 @@ class Lettering extends BookKeeping if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } else { + $affected_rows = $this->db->affected_rows($resql); } } @@ -320,7 +323,7 @@ class Lettering extends BookKeeping } return -1 * $error; } else { - return 1; + return $affected_rows; } } @@ -355,7 +358,7 @@ class Lettering extends BookKeeping } return -1 * $error; } else { - return 1; + return $this->db->affected_rows($resql); } } @@ -457,7 +460,7 @@ class Lettering extends BookKeeping else $result = $this->updateLettering($bookkeeping_lines); if ($result < 0) { $group_error++; - } else { + } elseif ($result > 0) { $nb_lettering++; } } From d9c47b93df3fbd2e77608899e26f07a75d385d71 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 5 Mar 2023 16:55:45 +0100 Subject: [PATCH 09/11] Revert "Drop the double " This reverts commit a02e88dc281c0545150ecc7e9f2716a0787208a4. --- htdocs/public/members/new.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index 2df2ec45cbc..aa8498a85a1 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -542,6 +542,7 @@ $morphys["mor"] = $langs->trans("Moral"); print ''.$langs->trans('MemberNature').' *'."\n"; if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) { + print ''.$langs->trans('MemberNature').' *'."\n"; print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1); print ''."\n"; } else { From 7a7d1c2fb1d99d74294860efdbe5036b3b98c629 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 5 Mar 2023 16:58:45 +0100 Subject: [PATCH 10/11] Revert "Fix member nature display in new.php" This reverts commit fd371cc52b517ea26f50d588cc2c8cf19bc520ce. --- htdocs/public/members/new.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index aa8498a85a1..d3a2a556b07 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -539,8 +539,6 @@ if (empty($conf->global->MEMBER_NEWFORM_FORCETYPE)) { // Moral/Physic attribute $morphys["phy"] = $langs->trans("Physical"); $morphys["mor"] = $langs->trans("Moral"); -print ''.$langs->trans('MemberNature').' *'."\n"; - if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) { print ''.$langs->trans('MemberNature').' *'."\n"; print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1); From ebac8ef1f1a07b9512ea99a276cb2626f7cc6c38 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 5 Mar 2023 17:06:32 +0100 Subject: [PATCH 11/11] Fix double morphy display when morphy is forced --- htdocs/public/members/new.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index d3a2a556b07..17234702e3c 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -544,7 +544,6 @@ if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) { print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1); print ''."\n"; } else { - print $morphys[$conf->global->MEMBER_NEWFORM_FORCEMORPHY]; print ''; }