From 5eeef771fac4fa5e81ddec1e31d0a7e01800b156 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 23 Jan 2020 06:20:31 +0100 Subject: [PATCH 1/4] FIX: FEC export format --- .../class/accountancyexport.class.php | 10 +++---- htdocs/core/lib/functions.lib.php | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index dcf59be27f3..df120e90d09 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -658,9 +658,9 @@ class AccountancyExport print $end_line; foreach ( $objectLines as $line ) { - $date_creation = dol_print_date($line->date_creation, '%d%m%Y'); - $date_doc = dol_print_date($line->doc_date, '%d%m%Y'); - $date_valid = dol_print_date($line->date_validated, '%d%m%Y'); + $date_creation = dol_print_date($line->date_creation, '%Y%m%d'); + $date_doc = dol_print_date($line->doc_date, '%Y%m%d'); + $date_valid = dol_print_date($line->date_validated, '%Y%m%d'); // FEC:JournalCode print $line->code_journal . $separator; @@ -696,10 +696,10 @@ class AccountancyExport print $line->label_operation . $separator; // FEC:Debit - print price2num($line->debit) . $separator; + print price2fec($line->debit) . $separator; // FEC:Credit - print price2num($line->credit) . $separator; + print price2fec($line->credit) . $separator; // FEC:EcritureLet print $line->lettering_code . $separator; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 89bd0622f5f..0ec230d1b87 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4523,6 +4523,35 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) return $amount; } +/** + * Function to format a value into a defined format for French administration (no thousand separator & decimal separator force to ',' with two decimals) + * Function used into accountancy FEC export + * + * @param float $amount Amount to format + * @return string Chain with formatted upright + * + * @see price2num() Revert function of price2fec + */ +function price2fec($amount) +{ + global $conf; + + // Clean parameters + if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = '' + $amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number) + + // Output decimal number by default (french) + $nbdecimal= 2; + + // Output separators by default (french) + $dec=','; $thousand=''; + + // Format number + $output=number_format($amount, $nbdecimal, $dec, $thousand); + + return $output; +} + /** * Output a dimension with best unit From 7f47b48559f1f3aa0cf27e0e556d10523e6e26be Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 23 Jan 2020 11:47:30 +0100 Subject: [PATCH 2/4] Move function to functions2.lib.php --- .../class/accountancyexport.class.php | 1 + htdocs/core/lib/functions.lib.php | 30 ------------------- htdocs/core/lib/functions2.lib.php | 29 ++++++++++++++++++ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index df120e90d09..742c3ac721c 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -38,6 +38,7 @@ */ require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; class AccountancyExport { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0ec230d1b87..a16faa50f46 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4523,36 +4523,6 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) return $amount; } -/** - * Function to format a value into a defined format for French administration (no thousand separator & decimal separator force to ',' with two decimals) - * Function used into accountancy FEC export - * - * @param float $amount Amount to format - * @return string Chain with formatted upright - * - * @see price2num() Revert function of price2fec - */ -function price2fec($amount) -{ - global $conf; - - // Clean parameters - if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = '' - $amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number) - - // Output decimal number by default (french) - $nbdecimal= 2; - - // Output separators by default (french) - $dec=','; $thousand=''; - - // Format number - $output=number_format($amount, $nbdecimal, $dec, $thousand); - - return $output; -} - - /** * Output a dimension with best unit * diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 41d8758cca0..b271a092c90 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2340,3 +2340,32 @@ function random_color($min=0, $max=255) { return random_color_part($min, $max) . random_color_part($min, $max) . random_color_part($min, $max); } + +/** + * Function to format a value into a defined format for French administration (no thousand separator & decimal separator force to ',' with two decimals) + * Function used into accountancy FEC export + * + * @param float $amount Amount to format + * @return string Chain with formatted upright + * + * @see price2num() Revert function of price2fec + */ +function price2fec($amount) +{ + global $conf; + + // Clean parameters + if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = '' + $amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number) + + // Output decimal number by default (french) + $nbdecimal= 2; + + // Output separators by default (french) + $dec=','; $thousand=''; + + // Format number + $output=number_format($amount, $nbdecimal, $dec, $thousand); + + return $output; +} From 1487158082e499ac844e5d0b1613a09a6d3d17e4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 23 Jan 2020 12:02:29 +0100 Subject: [PATCH 3/4] Update functions2.lib.php --- htdocs/core/lib/functions2.lib.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index b271a092c90..f9678c2f569 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2356,16 +2356,17 @@ function price2fec($amount) // Clean parameters if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = '' - $amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number) + $amount = (is_numeric($amount) ? $amount : 0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number) - // Output decimal number by default (french) - $nbdecimal= 2; + // Output decimal number by default + $nbdecimal = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH) ? 2 : $conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH); - // Output separators by default (french) - $dec=','; $thousand=''; + // Output separators by default + $dec = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR) ? ',' : $conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR); + $thousand = (empty($conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR) ? '' : $conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR); // Format number - $output=number_format($amount, $nbdecimal, $dec, $thousand); + $output = number_format($amount, $nbdecimal, $dec, $thousand); return $output; } From cbe396b97c0596af8a958c990e3af5f2c523ab54 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 23 Jan 2020 12:04:14 +0100 Subject: [PATCH 4/4] Update functions2.lib.php --- htdocs/core/lib/functions2.lib.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index f9678c2f569..37bc6c1cd5e 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2320,9 +2320,9 @@ function getModuleDirForApiClass($module) /* * Return 2 hexa code randomly * - * @param $min int Between 0 and 255 - * @param $max int Between 0 and 255 - * @return String + * @param int $min Between 0 and 255 + * @param int $max Between 0 and 255 + * @return String Color string */ function random_color_part($min=0,$max=255) { @@ -2332,9 +2332,9 @@ function random_color_part($min=0,$max=255) /* * Return hexadecimal color randomly * - * @param $min int Between 0 and 255 - * @param $max int Between 0 and 255 - * @return String + * @param int $min Between 0 and 255 + * @param int $max Between 0 and 255 + * @return String Color string */ function random_color($min=0, $max=255) { @@ -2346,9 +2346,8 @@ function random_color($min=0, $max=255) * Function used into accountancy FEC export * * @param float $amount Amount to format - * @return string Chain with formatted upright - * - * @see price2num() Revert function of price2fec + * @return string Chain with formatted upright + * @see price2num() Format a numeric into a price for FEC files */ function price2fec($amount) {