Update api_thirdparties.class.php

This commit is contained in:
Frédéric FRANCE 2020-04-13 09:15:01 +02:00 committed by GitHub
parent 2bf36bff6d
commit 8c8afa4b46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1120,7 +1120,7 @@ class Thirdparties extends DolibarrApi
* @param int $id ID of thirdparty
* @param array $request_data Request data
*
* @return object ID of thirdparty
* @return object BankAccount of thirdparty
*
* @url POST {id}/bankaccounts
*/
@ -1129,7 +1129,9 @@ class Thirdparties extends DolibarrApi
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
}
$account = new CompanyBankAccount($this->db);
$account->socid = $id;
@ -1141,6 +1143,12 @@ class Thirdparties extends DolibarrApi
if ($account->create(DolibarrApiAccess::$user) < 0)
throw new RestException(500, 'Error creating Company Bank account');
if (empty($account->rum)) {
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
$prelevement = new BonPrelevement($this->db);
$account->rum = $prelevement->buildRumNumber($this->company->code_client, $account->datec, $account->id);
$account->date_rum = dol_now();
}
if ($account->update(DolibarrApiAccess::$user) < 0)
throw new RestException(500, 'Error updating values');
@ -1155,7 +1163,7 @@ class Thirdparties extends DolibarrApi
* @param int $bankaccount_id ID of CompanyBankAccount
* @param array $request_data Request data
*
* @return object ID of thirdparty
* @return object BankAccount of thirdparty
*
* @url PUT {id}/bankaccounts/{bankaccount_id}
*/
@ -1164,7 +1172,9 @@ class Thirdparties extends DolibarrApi
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
}
$account = new CompanyBankAccount($this->db);
$account->fetch($bankaccount_id, $id, -1, '');