From 687370071b245e9f15a5441bbe65c31c8aead3ea Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 14 Dec 2015 21:38:30 +0100 Subject: [PATCH 1/2] A function to remove zero at the end of the account --- htdocs/core/lib/accounting.lib.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 6e6da6bd686..0b1bfb8f4fc 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -91,6 +91,33 @@ function accounting_prepare_head(AccountingAccount $object) return $head; } +/** + * Return accounting account without zero on the right + * + * @param string $account Accounting account + * @return string String without zero on the right + */ +function clean_account($account) +{ + global $conf; + + // Clean parameters + $i = strlen($account); + + if ($i >= 1) { + if (substr($account, -1) == 0) { + while ( $i >= 1 ) { + $account = substr($account, $i); + + $i --; + } + return $account; + } + } else { + return $account; + } +} + /** * Return general accounting account with defined length * @@ -131,7 +158,7 @@ function length_accountg($account) */ function length_accounta($accounta) { - global $conf, $langs; + global $conf; $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT; From c1e77daeb1208e9c944e93725cbe5cbeb775f9ad Mon Sep 17 00:00:00 2001 From: aspangaro Date: Tue, 15 Dec 2015 20:48:06 +0100 Subject: [PATCH 2/2] New: Accountancy add a function to remove all zero at the right of the account. Thanks to Florian --- htdocs/core/lib/accounting.lib.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 0b1bfb8f4fc..502e83010f7 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -99,23 +99,9 @@ function accounting_prepare_head(AccountingAccount $object) */ function clean_account($account) { - global $conf; - - // Clean parameters - $i = strlen($account); - - if ($i >= 1) { - if (substr($account, -1) == 0) { - while ( $i >= 1 ) { - $account = substr($account, $i); - - $i --; - } - return $account; - } - } else { - return $account; - } + $account = rtrim($account,"0"); + + return $account; } /**