Merge remote-tracking branch 'upstream/develop' into new_branch_20_09_2018

This commit is contained in:
Philippe GRAND 2018-09-20 17:10:48 +02:00
commit ef95be1ed7

View File

@ -1184,6 +1184,8 @@ class Thirdparties extends DolibarrApi
*/
public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate')
{
global $conf;
$this->langs->load("database");
$this->langs->load("main");
$this->langs->load("dict");
@ -1204,9 +1206,7 @@ class Thirdparties extends DolibarrApi
if(! DolibarrApiAccess::$user->rights->societe->creer)
throw new RestException(401);
// Reload to get all modified line records and be ready for hooks
$this->company->setDocModel($user, $model);
$this->company->setDocModel(DolibarrApiAccess::$user, $model);
$this->company->fk_bank = $this->company->fk_account;
@ -1222,6 +1222,8 @@ class Thirdparties extends DolibarrApi
}
// To be sure vars is defined
$hidedetails = $hidedesc = $hideref = 0;
$moreparams=null;
if (empty($hidedetails)) $hidedetails=0;
if (empty($hidedesc)) $hidedesc=0;
if (empty($hideref)) $hideref=0;
@ -1233,24 +1235,23 @@ class Thirdparties extends DolibarrApi
if ($id) $sql.= " WHERE fk_soc = ".$id." ";
if ($companybankid) $sql.= " AND id = ".$companybankid."";
$result = $this->db->query($sql);
if($result->num_rows == 0 ){
throw new RestException(404, 'Account not found');
}
$i=0;
$accounts=array();
$accounts =[];
$result = $this->db->query($sql);
if ($result)
{
if ($result->num_rows == 0) {
throw new RestException(404, 'Bank account not found');
}
$num = $this->db->num_rows($result);
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$account = new CompanyBankAccount($this->db);
if($account->fetchFromApi($obj->rowid)) {
if ($account->fetch($obj->rowid)) {
$accounts[] = $account;
}
$i++;
@ -1258,10 +1259,9 @@ class Thirdparties extends DolibarrApi
}
else
{
throw new RestException(404, 'Account not found');
throw new RestException(404, 'Bank account not found');
}
$moreparams = array(
'use_companybankid'=>$accounts[0]->id,
'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id)