diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index d6ed78ff457..10cd9c8c5ad 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -91,42 +91,8 @@ class Account return 1; } - /** - * \brief Efface une entree dans la table ".MAIN_DB_PREFIX."bank - * \param rowid Id de l'ecriture a effacer - * \return int <0 si ko, >0 si ok - */ - function deleteline($rowid) - { - $nbko=0; - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$rowid; - $result = $this->db->query($sql); - if (! $result) $nbko++; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$rowid; - $result = $this->db->query($sql); - if (! $result) $nbko++; - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$rowid; - $result = $this->db->query($sql); - if (! $result) $nbko++; - - if (! $nbko) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -$nbko; - } - } - - /** + /** * \brief Ajoute lien entre ecriture bancaire et sources * \param line_id Id ecriture bancaire * \param url_id Id parametre url @@ -140,6 +106,7 @@ class Account $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (fk_bank, url_id, url, label, type)"; $sql .= " VALUES ('$line_id', '$url_id', '$url', '$label', '$type')"; + dolibarr_syslog("Account::add_url_line sql=".$sql); if ($this->db->query($sql)) { $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url"); @@ -528,6 +495,8 @@ class Account { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; $sql .= " WHERE rowid = ".$this->rowid; + + dolibarr_syslog("Account::delete sql=".$sql); $result = $this->db->query($sql); if ($result) { return 1; @@ -761,6 +730,9 @@ class AccountLine { var $db; + var $rappro; + + /** * Constructeur */ @@ -785,6 +757,7 @@ class AccountLine $sql.= " FROM ".MAIN_DB_PREFIX."bank"; $sql.= " WHERE rowid = ".$rowid; + dolibarr_syslog("AccountLine::fetch sql=".$sql); $result = $this->db->query($sql); if ($result) { @@ -820,6 +793,51 @@ class AccountLine } + /** + * \brief Efface ligne bancaire + * \return int <0 si KO, >0 si OK + */ + function delete() + { + $nbko=0; + + if ($this->rappro) + { + // Protection pour eviter tout suppression d'une ligne consolidée + $this->error="DeleteNotPossibleLineIsConsolidated"; + return -1; + } + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid; + dolibarr_syslog("AccountLine::delete sql=".$sql); + $result = $this->db->query($sql); + if (! $result) $nbko++; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid; + dolibarr_syslog("AccountLine::delete sql=".$sql); + $result = $this->db->query($sql); + if (! $result) $nbko++; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$this->rowid; + dolibarr_syslog("AccountLine::delete sql=".$sql); + $result = $this->db->query($sql); + if (! $result) $nbko++; + + if (! $nbko) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -$nbko; + } + } + + /** * \brief Charge les informations d'ordre info dans l'objet facture * \param id Id de la facture a charger diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 096aa0c88bc..2e1aac106e2 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -97,9 +97,9 @@ if ($_POST["action"] == 'add' && $account && ! isset($_POST["cancel"]) && $user- } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier) { - $acct=new Account($db); - $acct->id=$account; - $result=$acct->deleteline($_GET["rowid"]); + $accline=new AccountLine($db); + $accline->fetch($_GET["rowid"]); + $result=$accline->delete(); } diff --git a/htdocs/compta/bank/rappro.php b/htdocs/compta/bank/rappro.php index 337b6f22772..24fd84d048a 100644 --- a/htdocs/compta/bank/rappro.php +++ b/htdocs/compta/bank/rappro.php @@ -96,10 +96,12 @@ if ($user->rights->banque->consolidate && $_POST["action"] == 'rappro') */ if ($_GET["action"] == 'del') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$_GET["rowid"]; - $resql = $db->query($sql); - if (! $resql) { - dolibarr_print_error($db); + $accline=new AccountLine($db); + $accline->fetch($_GET["rowid"]); + $result=$accline->delete(); + if ($result < 0) + { + dolibarr_print_error($db,$accline->error); } } diff --git a/htdocs/fourn/facture/paiementfourn.class.php b/htdocs/fourn/facture/paiementfourn.class.php index ae75dcb8eb7..edc1e3fbe31 100644 --- a/htdocs/fourn/facture/paiementfourn.class.php +++ b/htdocs/fourn/facture/paiementfourn.class.php @@ -262,14 +262,15 @@ class PaiementFourn // Supprimer l'écriture bancaire si paiement lié à écriture if ($bank_line_id) { - $acc = new Account($this->db); - $result=$acc->deleteline($bank_line_id); - if ($result < 0) - { - $this->error=$acc->error; - $this->db->rollback(); - return -4; - } + $accline = new AccountLine($this->db); + $accline->fetch($bank_line_id); + $result=$accline->delete(); + if ($result < 0) + { + $this->error=$accline->error; + $this->db->rollback(); + return -4; + } } $this->db->commit(); return 1; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index c4e00d43aa1..f46abf1d959 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -117,7 +117,6 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade') * Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH * Pour MagpieRss: MAGPIERSS_PATH * Pour PHPlot: PHPLOT_PATH - * Pour JPGraph: JPGRAPH_PATH * Pour NuSOAP: NUSOAP_PATH * Pour TCPDF: TCPDF_PATH */ @@ -126,7 +125,6 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade') if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); } if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); } if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); } - if (! defined('JPGRAPH_PATH')) { define('JPGRAPH_PATH', DOL_DOCUMENT_ROOT .'/includes/jpgraph/'); } if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', DOL_DOCUMENT_ROOT .'/includes/nusoap/lib/'); } if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/tcpdf/'); } // Les autres path diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php index 7aa2332f52b..f891b8480bb 100644 --- a/htdocs/paiement.class.php +++ b/htdocs/paiement.class.php @@ -269,11 +269,12 @@ class Paiement // Supprimer l'écriture bancaire si paiement lié à écriture if ($bank_line_id) { - $acc = new Account($this->db); - $result=$acc->deleteline($bank_line_id); + $accline = new AccountLine($this->db); + $accline->fetch($bank_line_id); + $result=$accline->delete(); if ($result < 0) { - $this->error=$acc->error; + $this->error=$accline->error; $this->db->rollback(); return -4; }