Add LineItem CSV import and fix Unit API
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
class ApiDataTransformer
|
||||
@@ -11,7 +12,7 @@ public static function snakeToCamel(array $data): array
|
||||
$result = [];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$camelKey = self::convertSnakeToCamel($key);
|
||||
$camelKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key))));
|
||||
|
||||
if (is_array($value)) {
|
||||
$result[$camelKey] = self::snakeToCamel($value);
|
||||
@@ -33,7 +34,7 @@ public static function camelToSnake(array $data): array
|
||||
$result = [];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$snakeKey = self::convertCamelToSnake($key);
|
||||
$snakeKey = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key));
|
||||
|
||||
if (is_array($value)) {
|
||||
$result[$snakeKey] = self::camelToSnake($value);
|
||||
@@ -47,19 +48,23 @@ public static function camelToSnake(array $data): array
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a single string from snake_case to camelCase
|
||||
*/
|
||||
protected static function convertSnakeToCamel(string $string): string
|
||||
{
|
||||
return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $string))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a single string from camelCase to snake_case
|
||||
*/
|
||||
protected static function convertCamelToSnake(string $string): string
|
||||
protected function parseGermanNumber($value)
|
||||
{
|
||||
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $string));
|
||||
if (is_numeric($value)) {
|
||||
return (float)$value;
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Remove all dots (thousands separators)
|
||||
$value = str_replace('.', '', $value);
|
||||
|
||||
// Replace comma with dot for decimal separator
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
return (float)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user