Skip to content

Commit

Permalink
Merge pull request #32450 from matthieu-michou-wattandsea/develop
Browse files Browse the repository at this point in the history
API REST | bank | add function to get bank account balance
  • Loading branch information
eldy authored Dec 24, 2024
2 parents 0a005ed + 0e5bfae commit 1aa8b04
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions htdocs/compta/bank/class/api_bankaccounts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,29 @@ public function deleteLine($id, $line_id)
)
);
}

/**
* Get current account balance by ID
*
* @param int $id ID of account
* @return float $balance balance
* @url GET {id}/balance
*
* @throws RestException
*/
public function getBalance($id)
{
if (!DolibarrApiAccess::$user->hasRight('banque', 'lire')) {
throw new RestException(403);
}

$account = new Account($this->db);
$result = $account->fetch($id);

if (!$result) {
throw new RestException(404, 'account not found');
}
$balance = $account->solde(1); //1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
return $balance;
}
}

0 comments on commit 1aa8b04

Please sign in to comment.