Fix: Can delete a paiement if bank line was deleted.

This commit is contained in:
Laurent Destailleur 2012-03-28 17:26:53 +02:00
parent 7af701af4a
commit fbfff99b80
2 changed files with 14 additions and 8 deletions

View File

@ -1066,7 +1066,7 @@ class AccountLine extends CommonObject
* @param int $rowid Id of bank transaction to load * @param int $rowid Id of bank transaction to load
* @param string $ref Ref 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) * @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='') function fetch($rowid,$ref='',$num='')
{ {
@ -1081,18 +1081,20 @@ class AccountLine extends CommonObject
$sql.= " b.fk_bordereau, b.banque, b.emetteur,"; $sql.= " b.fk_bordereau, b.banque, b.emetteur,";
//$sql.= " b.author"; // Is this used ? //$sql.= " b.author"; // Is this used ?
$sql.= " ba.label as bank_account_label"; $sql.= " ba.label as bank_account_label";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b,";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= " WHERE b.fk_account = ba.rowid"; $sql.= " WHERE b.fk_account = ba.rowid";
$sql.= " AND ba.entity = ".$conf->entity; $sql.= " AND ba.entity = ".$conf->entity;
if ($num) $sql.= " AND b.num_chq='".$num."'"; if ($num) $sql.= " AND b.num_chq='".$this->db->escape($num)."'";
else if ($ref) $sql.= " AND b.rowid='".$ref."'"; else if ($ref) $sql.= " AND b.rowid='".$this->db->escape($ref)."'";
else $sql.= " AND b.rowid=".$rowid; else $sql.= " AND b.rowid=".$rowid;
dol_syslog(get_class($this)."::fetch sql=".$sql); dol_syslog(get_class($this)."::fetch sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$ret=0;
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($obj) if ($obj)
{ {
@ -1120,9 +1122,11 @@ class AccountLine extends CommonObject
$this->fk_account = $obj->fk_account; $this->fk_account = $obj->fk_account;
$this->bank_account_label = $obj->bank_account_label; $this->bank_account_label = $obj->bank_account_label;
$ret=1;
} }
$this->db->free($result); $this->db->free($result);
return 1; return $ret;
} }
else else
{ {

View File

@ -287,11 +287,13 @@ class Paiement extends CommonObject
return -2; 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) if ($bank_line_id)
{ {
$accline = new AccountLine($this->db); $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); $result=$accline->delete_urls($user);
if ($result < 0) if ($result < 0)
{ {