Fix: phpunit error
This commit is contained in:
parent
56867b6fd9
commit
afa5bdb837
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
* Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
|
* Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Class to manage bank accounts description of third parties
|
* Class to manage bank accounts description of third parties
|
||||||
*/
|
*/
|
||||||
class CompanyBankAccount extends Account
|
class CompanyBankAccount extends Account
|
||||||
{
|
{
|
||||||
@ -232,48 +232,56 @@ class CompanyBankAccount extends Account
|
|||||||
/**
|
/**
|
||||||
* Set RIB as Default
|
* Set RIB as Default
|
||||||
*
|
*
|
||||||
* @param int $id RIB id
|
* @param int $rid RIB id
|
||||||
* @return int 0 if KO, 1 if OK
|
* @return int 0 if KO, 1 if OK
|
||||||
*/
|
*/
|
||||||
function setAsDefault($id)
|
function setAsDefault($rib=0)
|
||||||
{
|
{
|
||||||
if ($id) {
|
$sql1 = "SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX."societe_rib";
|
||||||
$sql1 = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib";
|
$sql1.= " WHERE rowid = ".($rib?$rib:$this->id);
|
||||||
$sql1.= " WHERE rowid = ".$id;
|
|
||||||
|
|
||||||
$result1 = $this->db->query($sql1);
|
dol_syslog(get_class($this).'::setAsDefault sql='.$sql1);
|
||||||
if ($result1) {
|
$result1 = $this->db->query($sql1);
|
||||||
if ($this->db->num_rows($result1) == 0) {
|
if ($result1)
|
||||||
return 0;
|
{
|
||||||
} else {
|
if ($this->db->num_rows($result1) == 0)
|
||||||
$obj = $this->db->fetch_object($result1);
|
{
|
||||||
$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0 ";
|
return 0;
|
||||||
$sql2.= "WHERE fk_soc = ".$obj->fk_soc;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($result1);
|
||||||
|
|
||||||
$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1 ";
|
$this->db->begin();
|
||||||
$sql3.= "WHERE rowid = ".$id;
|
|
||||||
|
|
||||||
$this->db->begin();
|
$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0 ";
|
||||||
|
$sql2.= "WHERE fk_soc = ".$obj->fk_soc;
|
||||||
|
dol_syslog(get_class($this).'::setAsDefault sql='.$sql2);
|
||||||
|
$result2 = $this->db->query($sql2);
|
||||||
|
|
||||||
$result2 = $this->db->query($sql2);
|
$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1 ";
|
||||||
$result3 = $this->db->query($sql3);
|
$sql3.= "WHERE rowid = ".$obj->id;
|
||||||
|
dol_syslog(get_class($this).'::setAsDefault sql='.$sql3);
|
||||||
|
$result3 = $this->db->query($sql3);
|
||||||
|
|
||||||
if (!$result2 || !$result3) {
|
if (!$result2 || !$result3)
|
||||||
dol_print_error($this->db);
|
{
|
||||||
$this->db->rollback();
|
dol_print_error($this->db);
|
||||||
return 0;
|
$this->db->rollback();
|
||||||
} else {
|
return -1;
|
||||||
$this->db->commit();
|
}
|
||||||
return 1;
|
else
|
||||||
}
|
{
|
||||||
}
|
$this->db->commit();
|
||||||
} else {
|
return 1;
|
||||||
dol_print_error($this->db);
|
}
|
||||||
return 0;
|
}
|
||||||
}
|
}
|
||||||
} else {
|
else
|
||||||
return 0;
|
{
|
||||||
}
|
dol_print_error($this->db);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -131,9 +131,9 @@ class CompanyBankAccountTest extends PHPUnit_Framework_TestCase
|
|||||||
$localobject->initAsSpecimen();
|
$localobject->initAsSpecimen();
|
||||||
$result=$localobject->create($user);
|
$result=$localobject->create($user);
|
||||||
|
|
||||||
|
print __METHOD__." result=".$result." id=".$localobject->id."\n";
|
||||||
$this->assertLessThan($result, 0);
|
$this->assertLessThan($result, 0);
|
||||||
print __METHOD__." result=".$result."\n";
|
return $localobject->id;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,9 +155,8 @@ class CompanyBankAccountTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$localobject=new CompanyBankAccount($this->savdb);
|
$localobject=new CompanyBankAccount($this->savdb);
|
||||||
$result=$localobject->fetch($id);
|
$result=$localobject->fetch($id);
|
||||||
|
|
||||||
$this->assertLessThan($result, 0);
|
|
||||||
print __METHOD__." id=".$id." result=".$result."\n";
|
print __METHOD__." id=".$id." result=".$result."\n";
|
||||||
|
$this->assertLessThan($result, 0);
|
||||||
return $localobject;
|
return $localobject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +177,6 @@ class CompanyBankAccountTest extends PHPUnit_Framework_TestCase
|
|||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
|
||||||
$result=$localobject->setAsDefault($localobject->id);
|
$result=$localobject->setAsDefault($localobject->id);
|
||||||
|
|
||||||
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
||||||
$this->assertLessThan($result, 0);
|
$this->assertLessThan($result, 0);
|
||||||
return $localobject;
|
return $localobject;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user