From 8192a488165bf107e85c83910f92693c88f803b6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 5 Oct 2024 15:18:08 +1000 Subject: [PATCH] Parse floats to user formatted versions in exports --- app/Import/Transformer/BaseTransformer.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Import/Transformer/BaseTransformer.php b/app/Import/Transformer/BaseTransformer.php index 92afb9a214..b8fc5a0945 100644 --- a/app/Import/Transformer/BaseTransformer.php +++ b/app/Import/Transformer/BaseTransformer.php @@ -347,14 +347,30 @@ class BaseTransformer */ public function getFloat($data, $field) { - if (array_key_exists($field, $data)) { - return Number::parseFloat($data[$field]); + if (array_key_exists($field, $data)) {\ + return $this->parseStringToFloat($data, $field); + // return Number::parseFloat($data[$field]); } return 0; } + private function parseStringToFloat($data, $field): float + { + + $currency = $this->company->currency(); + + $amount = preg_replace('/[^\d,.-]/', '', $data[$field]); + + $amount = str_replace($currency->thousand_separator, '', $amount); + + $amount = $currency->decimal_separator !== '.' ? str_replace($currency->decimal_separator, '.', $amount) : $amount; + + return (float) $amount; + + } + /** * @param $data * @param $field