From fbfff99b80c99bbc9d7c5ebd3bc84c21c32c98e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 28 Mar 2012 17:26:53 +0200 Subject: [PATCH] Fix: Can delete a paiement if bank line was deleted. --- htdocs/compta/bank/class/account.class.php | 16 ++++++++++------ htdocs/compta/paiement/class/paiement.class.php | 6 ++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index a828a22a5aa..c0fc021aa40 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1066,7 +1066,7 @@ class AccountLine extends CommonObject * @param int $rowid Id of bank transaction to load * @param string $ref Ref of bank transaction to load * @param string $num External num to load (ex: num of transaction for paypal fee) - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, 0 if OK but not found, >0 if OK and found */ function fetch($rowid,$ref='',$num='') { @@ -1081,18 +1081,20 @@ class AccountLine extends CommonObject $sql.= " b.fk_bordereau, b.banque, b.emetteur,"; //$sql.= " b.author"; // Is this used ? $sql.= " ba.label as bank_account_label"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b,"; + $sql.= " ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; $sql.= " AND ba.entity = ".$conf->entity; - if ($num) $sql.= " AND b.num_chq='".$num."'"; - else if ($ref) $sql.= " AND b.rowid='".$ref."'"; + if ($num) $sql.= " AND b.num_chq='".$this->db->escape($num)."'"; + else if ($ref) $sql.= " AND b.rowid='".$this->db->escape($ref)."'"; else $sql.= " AND b.rowid=".$rowid; dol_syslog(get_class($this)."::fetch sql=".$sql); $result = $this->db->query($sql); if ($result) { + $ret=0; + $obj = $this->db->fetch_object($result); if ($obj) { @@ -1120,9 +1122,11 @@ class AccountLine extends CommonObject $this->fk_account = $obj->fk_account; $this->bank_account_label = $obj->bank_account_label; + + $ret=1; } $this->db->free($result); - return 1; + return $ret; } else { diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index d5cc2ce4e3f..025372849de 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -287,11 +287,13 @@ class Paiement extends CommonObject return -2; } - // Delete bank urls. If payment if on a conciliated line, return error. + // Delete bank urls. If payment is on a conciliated line, return error. if ($bank_line_id) { $accline = new AccountLine($this->db); - $accline->fetch($bank_line_id); + $result=$accline->fetch($bank_line_id); + if ($result == 0) $accline->rowid=$bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url + $result=$accline->delete_urls($user); if ($result < 0) {