From 15dd1bd7057198c1b1aa450246a641c204670665 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jun 2020 21:46:32 +0200 Subject: [PATCH] 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); +