From f0ca29cc6ea1a9218ee114adf0717b3b78f787ee Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:19:31 +0200 Subject: [PATCH 01/12] Fix supplier sepa --- htdocs/compta/facture/class/facture.class.php | 29 ++++++++++++++----- htdocs/compta/facture/prelevement.php | 13 +++++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 791273a4fda..19f7b1e7109 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3984,11 +3984,13 @@ class Facture extends CommonInvoice * Create a withdrawal request for a standing order. * Use the remain to pay excluding all existing open direct debit requests. * - * @param User $fuser User asking the direct debit transfer - * @param float $amount Amount we request direct debit for - * @return int <0 if KO, >0 if OK + * @param User $fuser User asking the direct debit transfer + * @param float $amount Amount we request direct debit for + * @param string $type 'direct-debit' or 'bank-transfer' + * @param string $source_type Source ('facture' or 'supplier_invoice') + * @return int <0 if KO, >0 if OK */ - public function demande_prelevement($fuser, $amount = 0) + public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $source_type = 'facture') { // phpcs:enable @@ -4004,7 +4006,11 @@ class Facture extends CommonInvoice $sql = 'SELECT count(*)'; $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - $sql .= ' WHERE fk_facture = '.$this->id; + if ($type == 'bank-transfer') { + $sql .= ' WHERE fk_facture_fourn = '.$this->id; + } else { + $sql .= ' WHERE fk_facture = '.$this->id; + } $sql .= ' AND traite = 0'; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); @@ -4029,8 +4035,13 @@ class Facture extends CommonInvoice if (is_numeric($amount) && $amount != 0) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)'; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + if ($type == 'bank-transfer') { + $sql .= 'fk_facture_fourn, '; + } else { + $sql .= 'fk_facture, '; + } + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, source_type)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; @@ -4038,7 +4049,9 @@ class Facture extends CommonInvoice $sql .= ",'".$bac->code_banque."'"; $sql .= ",'".$bac->code_guichet."'"; $sql .= ",'".$bac->number."'"; - $sql .= ",'".$bac->cle_rib."')"; + $sql .= ",'".$bac->cle_rib."'"; + $sql .= ",'".$source_type."'"; + $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index ba6cc96e3dd..2ca0b342fa3 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -24,7 +24,7 @@ /** * \file htdocs/compta/facture/prelevement.php * \ingroup facture - * \brief Management of direct debit order of invoices + * \brief Management of direct debit order or credit tranfer of invoices */ require '../../main.inc.php'; @@ -83,7 +83,13 @@ if (empty($reshook)) { $db->begin(); - $result = $object->demande_prelevement($user, GETPOST('withdraw_request_amount')); + $newtype = $type; + $source_type = 'facture'; + if ($type == 'bank-transfer') { + $source_type = 'supplier_invoice'; + } + + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount'), 'alpha'), $newtype, $source_type); if ($result > 0) { $db->commit(); @@ -101,7 +107,7 @@ if (empty($reshook)) { if ($object->id > 0) { - $result = $object->demande_prelevement_delete($user, GETPOST('did')); + $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int')); if ($result == 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -197,6 +203,7 @@ if ($object->id > 0) $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; + $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; From c22a9781d835d2ca9a18dd71bc8ed87a3f60ca7f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:21:18 +0200 Subject: [PATCH 02/12] Fix rounding --- htdocs/compta/facture/prelevement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 2ca0b342fa3..f38053e5844 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -89,7 +89,7 @@ if (empty($reshook)) $source_type = 'supplier_invoice'; } - $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount'), 'alpha'), $newtype, $source_type); + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $source_type); if ($result > 0) { $db->commit(); From abb8cd260f7eaebbe5ccaaeff0b2aa317f05e5a9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:22:44 +0200 Subject: [PATCH 03/12] Fix escape fields --- htdocs/compta/facture/class/facture.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 19f7b1e7109..a2a6e9fc1c4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3987,10 +3987,10 @@ class Facture extends CommonInvoice * @param User $fuser User asking the direct debit transfer * @param float $amount Amount we request direct debit for * @param string $type 'direct-debit' or 'bank-transfer' - * @param string $source_type Source ('facture' or 'supplier_invoice') + * @param string $sourcetype Source ('facture' or 'supplier_invoice') * @return int <0 if KO, >0 if OK */ - public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $source_type = 'facture') + public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') { // phpcs:enable @@ -4041,16 +4041,16 @@ class Facture extends CommonInvoice } else { $sql .= 'fk_facture, '; } - $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, source_type)'; + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; $sql .= ",".$fuser->id; - $sql .= ",'".$bac->code_banque."'"; - $sql .= ",'".$bac->code_guichet."'"; - $sql .= ",'".$bac->number."'"; - $sql .= ",'".$bac->cle_rib."'"; - $sql .= ",'".$source_type."'"; + $sql .= ",'".$this->db->escape($bac->code_banque)."'"; + $sql .= ",'".$this->db->escape($bac->code_guichet)."'"; + $sql .= ",'".$this->db->escape($bac->number)."'"; + $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; + $sql .= ",'".$this->db->escape($sourcetype)."'"; $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); From 2d5c35b12a2cef521e680d57a364252f0b9d42f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:46:32 +0200 Subject: [PATCH 04/12] Fix debug sepa module --- htdocs/compta/facture/class/facture.class.php | 7 ++++-- htdocs/compta/facture/list.php | 2 +- htdocs/compta/facture/prelevement.php | 10 ++++++--- htdocs/core/lib/invoice.lib.php | 1 + .../install/mysql/migration/11.0.0-12.0.0.sql | 4 ++++ .../install/mysql/migration/12.0.0-13.0.0.sql | 2 ++ .../llx_prelevement_facture_demande.key.sql | 22 +++++++++++++++++++ 7 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a2a6e9fc1c4..369f4f0ee25 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3981,7 +3981,7 @@ class Facture extends CommonInvoice // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Create a withdrawal request for a standing order. + * Create a withdrawal request for a direct debit order or a credit transfer order. * Use the remain to pay excluding all existing open direct debit requests. * * @param User $fuser User asking the direct debit transfer @@ -3993,6 +3993,7 @@ class Facture extends CommonInvoice public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') { // phpcs:enable + global $conf; $error = 0; @@ -4011,6 +4012,7 @@ class Facture extends CommonInvoice } else { $sql .= ' WHERE fk_facture = '.$this->id; } + $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments $sql .= ' AND traite = 0'; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); @@ -4041,7 +4043,7 @@ class Facture extends CommonInvoice } else { $sql .= 'fk_facture, '; } - $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype)'; + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; @@ -4051,6 +4053,7 @@ class Facture extends CommonInvoice $sql .= ",'".$this->db->escape($bac->number)."'"; $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; $sql .= ",'".$this->db->escape($sourcetype)."'"; + $sql .= ",".$conf->entity; $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c21d19ad538..574b1f7d52a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -376,7 +376,7 @@ if ($massaction == 'makepayment'){ foreach ($listofbills as $aBill) { $db->begin(); - $result = $aBill->demande_prelevement($user, $aBill->resteapayer); + $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'direct-debit', 'facture'); if ($result > 0) { $db->commit(); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index f38053e5844..10cde50f478 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -84,12 +84,12 @@ if (empty($reshook)) $db->begin(); $newtype = $type; - $source_type = 'facture'; + $sourcetype = 'facture'; if ($type == 'bank-transfer') { - $source_type = 'supplier_invoice'; + $sourcetype = 'supplier_invoice'; } - $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $source_type); + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype); if ($result > 0) { $db->commit(); @@ -497,6 +497,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result_sql = $db->query($sql); @@ -518,6 +519,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $result_sql = $db->query($sql); if ($result_sql) @@ -601,6 +603,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result_sql = $db->query($sql); @@ -653,6 +656,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 1"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result = $db->query($sql); diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 4094da1375f..82b9e8cee9b 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -62,6 +62,7 @@ function facture_prepare_head($object) $sql = "SELECT COUNT(pfd.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " WHERE pfd.fk_facture = ".$object->id; + $sql .= " AND pfd.ext_payment_id IS NULL"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index a9099ee49c0..4ee3696d904 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -308,4 +308,8 @@ ALTER TABLE llx_emailcollector_emailcollector ADD COLUMN hostcharset varchar(16) ALTER TABLE llx_adherent_type MODIFY subscription varchar(3) NOT NULL DEFAULT '1'; ALTER TABLE llx_adherent_type MODIFY vote varchar(3) NOT NULL DEFAULT '1'; +UPDATE llx_prelevement_facture_demande SET entity = 1 WHERE entity IS NULL; + +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture_fourn (fk_facture_fourn); diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 14c176b1c20..db7cddbd018 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -32,6 +32,8 @@ ALTER TABLE llx_prelevement_bons ADD COLUMN type varchar(16) DEFAULT 'debit-order'; +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture_fourn (fk_facture_fourn); -- For v13 diff --git a/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql new file mode 100644 index 00000000000..4f9aedb9cdf --- /dev/null +++ b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql @@ -0,0 +1,22 @@ +-- =================================================================== +-- Copyright (C) 2005 Rodolphe Quiedeville +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + + +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture_fourn (fk_facture_fourn); + From 83263cc174380ba1300cf15aca45bfe4da1bf199 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:19:31 +0200 Subject: [PATCH 05/12] Fix supplier sepa --- htdocs/compta/facture/class/facture.class.php | 29 ++++++++++++++----- htdocs/compta/facture/prelevement.php | 13 +++++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 80b68182363..3a1b4d7dc9e 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4083,11 +4083,13 @@ class Facture extends CommonInvoice * Create a withdrawal request for a standing order. * Use the remain to pay excluding all existing open direct debit requests. * - * @param User $fuser User asking the direct debit transfer - * @param float $amount Amount we request direct debit for - * @return int <0 if KO, >0 if OK + * @param User $fuser User asking the direct debit transfer + * @param float $amount Amount we request direct debit for + * @param string $type 'direct-debit' or 'bank-transfer' + * @param string $source_type Source ('facture' or 'supplier_invoice') + * @return int <0 if KO, >0 if OK */ - public function demande_prelevement($fuser, $amount = 0) + public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $source_type = 'facture') { // phpcs:enable @@ -4103,7 +4105,11 @@ class Facture extends CommonInvoice $sql = 'SELECT count(*)'; $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - $sql .= ' WHERE fk_facture = '.$this->id; + if ($type == 'bank-transfer') { + $sql .= ' WHERE fk_facture_fourn = '.$this->id; + } else { + $sql .= ' WHERE fk_facture = '.$this->id; + } $sql .= ' AND traite = 0'; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); @@ -4128,8 +4134,13 @@ class Facture extends CommonInvoice if (is_numeric($amount) && $amount != 0) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)'; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + if ($type == 'bank-transfer') { + $sql .= 'fk_facture_fourn, '; + } else { + $sql .= 'fk_facture, '; + } + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, source_type)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; @@ -4137,7 +4148,9 @@ class Facture extends CommonInvoice $sql .= ",'".$bac->code_banque."'"; $sql .= ",'".$bac->code_guichet."'"; $sql .= ",'".$bac->number."'"; - $sql .= ",'".$bac->cle_rib."')"; + $sql .= ",'".$bac->cle_rib."'"; + $sql .= ",'".$source_type."'"; + $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 984c29d75ed..bdf45514229 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -24,7 +24,7 @@ /** * \file htdocs/compta/facture/prelevement.php * \ingroup facture - * \brief Management of direct debit order of invoices + * \brief Management of direct debit order or credit tranfer of invoices */ require '../../main.inc.php'; @@ -83,7 +83,13 @@ if (empty($reshook)) { $db->begin(); - $result = $object->demande_prelevement($user, GETPOST('withdraw_request_amount')); + $newtype = $type; + $source_type = 'facture'; + if ($type == 'bank-transfer') { + $source_type = 'supplier_invoice'; + } + + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount'), 'alpha'), $newtype, $source_type); if ($result > 0) { $db->commit(); @@ -103,7 +109,7 @@ if (empty($reshook)) { if ($object->id > 0) { - $result = $object->demande_prelevement_delete($user, GETPOST('did')); + $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int')); if ($result == 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -199,6 +205,7 @@ if ($object->id > 0) $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; + $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; From f9da31e6584e882f8b2a8c087441c8ac3863c2f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:21:18 +0200 Subject: [PATCH 06/12] Fix rounding --- htdocs/compta/facture/prelevement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index bdf45514229..541ae9cb459 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -89,7 +89,7 @@ if (empty($reshook)) $source_type = 'supplier_invoice'; } - $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount'), 'alpha'), $newtype, $source_type); + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $source_type); if ($result > 0) { $db->commit(); From 964f17c5076db0eec7e5ac118d7f5e5e5aa463ea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:22:44 +0200 Subject: [PATCH 07/12] Fix escape fields --- htdocs/compta/facture/class/facture.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 3a1b4d7dc9e..1b1169d6fad 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4086,10 +4086,10 @@ class Facture extends CommonInvoice * @param User $fuser User asking the direct debit transfer * @param float $amount Amount we request direct debit for * @param string $type 'direct-debit' or 'bank-transfer' - * @param string $source_type Source ('facture' or 'supplier_invoice') + * @param string $sourcetype Source ('facture' or 'supplier_invoice') * @return int <0 if KO, >0 if OK */ - public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $source_type = 'facture') + public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') { // phpcs:enable @@ -4140,16 +4140,16 @@ class Facture extends CommonInvoice } else { $sql .= 'fk_facture, '; } - $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, source_type)'; + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; $sql .= ",".$fuser->id; - $sql .= ",'".$bac->code_banque."'"; - $sql .= ",'".$bac->code_guichet."'"; - $sql .= ",'".$bac->number."'"; - $sql .= ",'".$bac->cle_rib."'"; - $sql .= ",'".$source_type."'"; + $sql .= ",'".$this->db->escape($bac->code_banque)."'"; + $sql .= ",'".$this->db->escape($bac->code_guichet)."'"; + $sql .= ",'".$this->db->escape($bac->number)."'"; + $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; + $sql .= ",'".$this->db->escape($sourcetype)."'"; $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); From 15dd1bd7057198c1b1aa450246a641c204670665 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:46:32 +0200 Subject: [PATCH 08/12] Merge --- htdocs/compta/facture/class/facture.class.php | 7 ++++-- htdocs/compta/facture/list.php | 2 +- htdocs/compta/facture/prelevement.php | 10 ++++++--- htdocs/core/lib/invoice.lib.php | 1 + .../install/mysql/migration/11.0.0-12.0.0.sql | 4 ++++ .../llx_prelevement_facture_demande.key.sql | 22 +++++++++++++++++++ 6 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 1b1169d6fad..9a80ad91d24 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4080,7 +4080,7 @@ class Facture extends CommonInvoice // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Create a withdrawal request for a standing order. + * Create a withdrawal request for a direct debit order or a credit transfer order. * Use the remain to pay excluding all existing open direct debit requests. * * @param User $fuser User asking the direct debit transfer @@ -4092,6 +4092,7 @@ class Facture extends CommonInvoice public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') { // phpcs:enable + global $conf; $error = 0; @@ -4110,6 +4111,7 @@ class Facture extends CommonInvoice } else { $sql .= ' WHERE fk_facture = '.$this->id; } + $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments $sql .= ' AND traite = 0'; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); @@ -4140,7 +4142,7 @@ class Facture extends CommonInvoice } else { $sql .= 'fk_facture, '; } - $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype)'; + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; @@ -4150,6 +4152,7 @@ class Facture extends CommonInvoice $sql .= ",'".$this->db->escape($bac->number)."'"; $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; $sql .= ",'".$this->db->escape($sourcetype)."'"; + $sql .= ",".$conf->entity; $sql .= ")"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 8b9e204f17e..b09f7f00ffe 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -381,7 +381,7 @@ elseif ($massaction == 'withdrawrequest') foreach ($listofbills as $aBill) { $db->begin(); - $result = $aBill->demande_prelevement($user, $aBill->resteapayer); + $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'direct-debit', 'facture'); if ($result > 0) { $db->commit(); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 541ae9cb459..bc3762b41ea 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -84,12 +84,12 @@ if (empty($reshook)) $db->begin(); $newtype = $type; - $source_type = 'facture'; + $sourcetype = 'facture'; if ($type == 'bank-transfer') { - $source_type = 'supplier_invoice'; + $sourcetype = 'supplier_invoice'; } - $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $source_type); + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype); if ($result > 0) { $db->commit(); @@ -515,6 +515,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result_sql = $db->query($sql); @@ -538,6 +539,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $result_sql = $db->query($sql); if ($result_sql) @@ -630,6 +632,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result_sql = $db->query($sql); @@ -684,6 +687,7 @@ if ($object->id > 0) $sql .= " WHERE fk_facture = ".$object->id; } $sql .= " AND pfd.traite = 1"; + $sql .= " AND pfd.ext_payment_id IS NULL"; $sql .= " ORDER BY pfd.date_demande DESC"; $result = $db->query($sql); diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 703d50c97f8..a669b12adfe 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -62,6 +62,7 @@ function facture_prepare_head($object) $sql = "SELECT COUNT(pfd.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " WHERE pfd.fk_facture = ".$object->id; + $sql .= " AND pfd.ext_payment_id IS NULL"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index b7ac95b8cea..7a6f2333346 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -307,4 +307,8 @@ ALTER TABLE llx_emailcollector_emailcollector ADD COLUMN hostcharset varchar(16) ALTER TABLE llx_adherent_type MODIFY subscription varchar(3) NOT NULL DEFAULT '1'; ALTER TABLE llx_adherent_type MODIFY vote varchar(3) NOT NULL DEFAULT '1'; +UPDATE llx_prelevement_facture_demande SET entity = 1 WHERE entity IS NULL; + +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture_fourn (fk_facture_fourn); diff --git a/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql new file mode 100644 index 00000000000..4f9aedb9cdf --- /dev/null +++ b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.key.sql @@ -0,0 +1,22 @@ +-- =================================================================== +-- Copyright (C) 2005 Rodolphe Quiedeville +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + + +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); +ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture_fourn (fk_facture_fourn); + From 1736ecfa2689edba7946565b6e1e90314532b464 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Jun 2020 04:32:59 +0200 Subject: [PATCH 09/12] Fix phpcs --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/tpl/login.tpl.php | 2 +- htdocs/core/tpl/passwordforgotten.tpl.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 119a981891c..2187d6dc655 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7508,7 +7508,7 @@ function printCommonFooter($zone = 'private') if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) { $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID); - foreach($tmptagarray as $tmptag) { + foreach ($tmptagarray as $tmptag) { print "\n"; print "\n"; print " diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 6f2ca762a7c..a12616e2bd5 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -339,7 +339,7 @@ if (!empty($morelogincontent) && is_array($morelogincontent)) { if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) { $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID); - foreach($tmptagarray as $tmptag) { + foreach ($tmptagarray as $tmptag) { print "\n"; print "\n"; print " diff --git a/htdocs/core/tpl/passwordforgotten.tpl.php b/htdocs/core/tpl/passwordforgotten.tpl.php index 4a37ea8ab3e..5cd672ddea4 100644 --- a/htdocs/core/tpl/passwordforgotten.tpl.php +++ b/htdocs/core/tpl/passwordforgotten.tpl.php @@ -229,7 +229,7 @@ if (!empty($morelogincontent) && is_array($morelogincontent)) { if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) { $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID); - foreach($tmptagarray as $tmptag) { + foreach ($tmptagarray as $tmptag) { print "\n"; print "\n"; print " From 7b64e8643fe2e78a78ca877ee9533bf59078e941 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Jun 2020 16:08:48 +0200 Subject: [PATCH 10/12] Trans and css --- htdocs/langs/en_US/admin.lang | 2 +- htdocs/theme/eldy/info-box.inc.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 7cf5788f53d..c31a480239e 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1983,7 +1983,7 @@ SmallerThan=Smaller than LargerThan=Larger than IfTrackingIDFoundEventWillBeLinked=Note that If a tracking ID is found into incoming email, the event will be automatically linked to the related objects. WithGMailYouCanCreateADedicatedPassword=With a GMail account, if you enabled the 2 steps validation, it is recommanded to create a dedicated second password for the application instead of using your own account passsword from https://myaccount.google.com/. -EmailCollectorTargetDir=It may be a desired behaviour to move the email into another tag/directory when it was processed successfully. Just set a value here to use this feature. Note that you must also use a read/write login account. +EmailCollectorTargetDir=It may be a desired behaviour to move the email into another tag/directory when it was processed successfully. Just set name of directory here to use this feature (Do NOT use special characters in name). Note that you must also use a read/write login account. EmailCollectorLoadThirdPartyHelp=You can use this action to use the email content to find and load an existing thirdparty in your database. The found (or created) thirdparty will be used for following actions that need it. In the parameter field you can use for example 'EXTRACT:BODY:Name:\s([^\s]*)' if you want to extract the name of the thirdparty from a string 'Name: name to find' found into the body. EndPointFor=End point for %s : %s DeleteEmailCollector=Delete email collector diff --git a/htdocs/theme/eldy/info-box.inc.php b/htdocs/theme/eldy/info-box.inc.php index 604aff91a3e..c5f4b8d248c 100644 --- a/htdocs/theme/eldy/info-box.inc.php +++ b/htdocs/theme/eldy/info-box.inc.php @@ -28,9 +28,9 @@ if (!defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?> } .info-box-more { float: right; - top: 6px; + top: 5px; position: absolute; - right: 10px; + right: 8px; } .info-box small { @@ -385,6 +385,16 @@ if (GETPOSTISSET('THEME_SATURATE_RATIO')) $conf->global->THEME_SATURATE_RATIO = min-width: 350px; max-width: 350px; } +.info-box-title { + width: calc(100% - 20px); +} +@media only screen and (max-width: 767px) { + .info-box-module { + min-width: 260px; + } +} + + .info-box-module .info-box-content { height: 6.4em; } From 9ec8051a378980cf4d7b156428debae1607f47d3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Jun 2020 02:56:48 +0200 Subject: [PATCH 11/12] NEW Add param to not show links when output tags --- htdocs/categories/class/categorie.class.php | 6 +++++- htdocs/core/class/html.form.class.php | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 3076b9ecacd..748a9501101 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1347,7 +1347,7 @@ class Categorie extends CommonObject * separated by $sep (" >> " by default) * * @param string $sep Separator - * @param string $url Url + * @param string $url Url ('', 'none' or 'urltouse') * @param int $nocolor 0 * @param string $addpicto Add picto into link * @return array @@ -1386,6 +1386,10 @@ class Categorie extends CommonObject $link = ''; $linkend = ''; $w[] = $link.($addpicto ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend; + } elseif ($url == 'none') { + $link = ''; + $linkend = ''; + $w[] = $link.($addpicto ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend; } else { $w[] = "".($addpicto ? img_object('', 'category') : '').$cat->label.""; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 289b92f84ae..efae43e02ee 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6554,9 +6554,10 @@ class Form * @param int $id Id of object * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated. * @param int $rendermode 0=Default, use multiselect. 1=Emulate multiselect (recommended) + * @param int $nolink 1=Do not add html links * @return string String with categories */ - public function showCategories($id, $type, $rendermode = 0) + public function showCategories($id, $type, $rendermode = 0, $nolink = 0) { global $db; @@ -6570,7 +6571,7 @@ class Form $toprint = array(); foreach ($categories as $c) { - $ways = $c->print_all_ways(' >> ', '', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text + $ways = $c->print_all_ways(' >> ', ($nolink ? 'none' : ''), 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text foreach ($ways as $way) { $toprint[] = '
  • color ? ' style="background: #'.$c->color.';"' : ' style="background: #aaa"').'>'.$way.'
  • '; From e8b44ef89e72437586b307e9ffea160040f5df99 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Jun 2020 17:55:46 +0200 Subject: [PATCH 12/12] css --- htdocs/theme/eldy/global.inc.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index f74183b633e..428902d1782 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -2977,22 +2977,22 @@ td.border, div.tagtable div div.border { } table.liste, table.noborder, table.formdoc, div.noborder { width: 100%; - border-collapse: separate !important; border-spacing: 0px; - border-top-width: px; border-top-color: rgb(); border-top-style: solid; - /* border-top-width: 2px; - border-top-color: var(--colorbackhmenu1); - border-top-style: solid; */ - - /*border-bottom-width: 1px; - border-bottom-color: rgb(); - border-bottom-style: solid;*/ - margin: 0px 0px 5px 0px; + + /*width: calc(100% - 7px); + border-collapse: separate !important; + border-spacing: 0px; + border-top-width: 0px; + border-top-color: rgb(215,215,215); + border-top-style: solid; + margin: 0px 0px 5px 2px; + box-shadow: 1px 1px 5px #ddd; + */ } #tablelines { border-bottom-width: 1px;