Merge pull request #15880 from frederic34/api_bank_account

fix unknown variable
This commit is contained in:
Laurent Destailleur 2021-01-05 18:55:35 +01:00 committed by GitHub
commit a044d1b91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,10 +81,8 @@ class BankAccounts extends DolibarrApi
$sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_account = t.rowid "; $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_account = t.rowid ";
} }
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -93,8 +91,7 @@ class BankAccounts extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
if ($limit) { if ($limit) {
if ($page < 0) if ($page < 0) {
{
$page = 0; $page = 0;
} }
$offset = $limit * $page; $offset = $limit * $page;
@ -222,12 +219,10 @@ class BankAccounts extends DolibarrApi
throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.'); throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.');
} }
if ($accountto->currency_code == $accountfrom->currency_code) if ($accountto->currency_code == $accountfrom->currency_code) {
{
$amount_to = $amount; $amount_to = $amount;
} else { } else {
if (!$amount_to || empty($amount_to)) if (!$amount_to || empty($amount_to)) {
{
throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.'); throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.');
} }
} }
@ -244,8 +239,7 @@ class BankAccounts extends DolibarrApi
$typefrom = 'PRE'; $typefrom = 'PRE';
$typeto = 'VIR'; $typeto = 'VIR';
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) {
{
// This is transfer of change // This is transfer of change
$typefrom = 'LIQ'; $typefrom = 'LIQ';
$typeto = 'LIQ'; $typeto = 'LIQ';
@ -291,8 +285,7 @@ class BankAccounts extends DolibarrApi
$error++; $error++;
} }
if (!$error) if (!$error) {
{
$this->db->commit(); $this->db->commit();
return array( return array(
@ -327,12 +320,13 @@ class BankAccounts extends DolibarrApi
} }
foreach ($request_data as $field => $value) { foreach ($request_data as $field => $value) {
if ($field == 'id') continue; if ($field == 'id') {
continue;
}
$account->$field = $value; $account->$field = $value;
} }
if ($account->update(DolibarrApiAccess::$user) > 0) if ($account->update(DolibarrApiAccess::$user) > 0) {
{
return $this->get($id); return $this->get($id);
} else { } else {
throw new RestException(500, $account->error); throw new RestException(500, $account->error);
@ -380,8 +374,9 @@ class BankAccounts extends DolibarrApi
{ {
$account = array(); $account = array();
foreach (BankAccounts::$FIELDS as $field) { foreach (BankAccounts::$FIELDS as $field) {
if (!isset($data[$field])) if (!isset($data[$field])) {
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
}
$account[$field] = $data[$field]; $account[$field] = $data[$field];
} }
return $account; return $account;
@ -433,10 +428,8 @@ class BankAccounts extends DolibarrApi
$sql .= " WHERE fk_account = ".$id; $sql .= " WHERE fk_account = ".$id;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -457,7 +450,7 @@ class BankAccounts extends DolibarrApi
} }
} }
} else { } else {
throw new RestException(503, 'Error when retrieving list of account lines: '.$accountLine->error); throw new RestException(503, 'Error when retrieving list of account lines: '.$this->db->lasterror());
} }
return $list; return $list;
@ -476,8 +469,8 @@ class BankAccounts extends DolibarrApi
* @param string $cheque_writer Name of cheque writer {@from body} * @param string $cheque_writer Name of cheque writer {@from body}
* @param string $cheque_bank Bank of cheque writer {@from body} * @param string $cheque_bank Bank of cheque writer {@from body}
* @param string $accountancycode Accountancy code {@from body} * @param string $accountancycode Accountancy code {@from body}
* @param int $datev Payment date value (timestamp) {@from body} {@type timestamp} * @param int $datev Payment date value (timestamp) {@from body} {@type timestamp}
* @param string $num_releve Bank statement numero {@from body} * @param string $num_releve Bank statement numero {@from body}
* @return int ID of line * @return int ID of line
* *
* @url POST {id}/lines * @url POST {id}/lines
@ -502,8 +495,11 @@ class BankAccounts extends DolibarrApi
$cheque_number, $cheque_number,
$category, $category,
DolibarrApiAccess::$user, DolibarrApiAccess::$user,
$cheque_writer, $cheque_bank, $accountancycode, $cheque_writer,
$datev, $num_releve $cheque_bank,
$accountancycode,
$datev,
$num_releve
); );
if ($result < 0) { if ($result < 0) {
throw new RestException(503, 'Error when adding line to account: '.$account->error); throw new RestException(503, 'Error when adding line to account: '.$account->error);