diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 46b80e7f77e..defcc71a3e5 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4396,12 +4396,8 @@ class Societe extends CommonObject $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); */ - if ($mode == 'supplier') { - $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - } else { - $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - } - $sql .= " WHERE fk_soc = ".$this->id; + $sql = "SELECT rowid, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ".((int) $this->id); if (!empty($late)) { $sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'"; } @@ -4453,6 +4449,7 @@ class Societe extends CommonObject } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' } else { + dol_syslog("Sql error ".$this->db->lasterror, LOG_ERR); return array(); } } diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 177458fb621..9a4f58540e9 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -387,6 +387,35 @@ class SocieteTest extends PHPUnit\Framework\TestCase * @depends testSocieteOther * The depends says test is run only if previous is ok */ + public function testGetOutstandingBills($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Societe($this->savdb); + $localobject->fetch($id); + + $result=$localobject->getOutstandingBills(); + + print __METHOD__." id=".$id." result=".var_export($result, true)."\n"; + $this->assertLessThan($result, 0); + + return $id; + } + + + /** + * testSocieteDelete + * + * @param int $id Id of company + * @return int + * + * @depends testGetOutstandingBills + * The depends says test is run only if previous is ok + */ public function testSocieteDelete($id) { global $conf,$user,$langs,$db;