From 9a4897bf0c007027986aa1178fc711af49e03b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Tue, 27 Jan 2026 18:04:50 +0100 Subject: [PATCH] fixed normalizing decimal upsertAccount importer --- app/Services/ImportProcessor.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/Services/ImportProcessor.php b/app/Services/ImportProcessor.php index 68dd5b8..ee5f35c 100644 --- a/app/Services/ImportProcessor.php +++ b/app/Services/ImportProcessor.php @@ -1689,8 +1689,12 @@ private function upsertAccount(Import $import, array $mapped, $mappings, bool $h if ($existing) { // Build non-null changes for account fields $changes = array_filter($applyUpdate, fn ($v) => ! is_null($v)); - // Track balance change - $oldBalance = (float) ($existing->balance_amount ?? 0); + // Track balance change - normalize in case DB has malformed data + $rawBalance = $existing->balance_amount ?? 0; + if (is_string($rawBalance) && $rawBalance !== '') { + $rawBalance = $this->normalizeDecimal($rawBalance); + } + $oldBalance = is_numeric($rawBalance) ? (float) $rawBalance : 0; // Note: meta merging for contracts is handled in upsertContractChain, not here if (! empty($changes)) { $existing->fill($changes); @@ -1699,7 +1703,11 @@ private function upsertAccount(Import $import, array $mapped, $mappings, bool $h // If balance_amount changed and this wasn't caused by a payment (we are in account upsert), log an activity with before/after if (array_key_exists('balance_amount', $changes)) { - $newBalance = (float) ($existing->balance_amount ?? 0); + $rawNewBalance = $existing->balance_amount ?? 0; + if (is_string($rawNewBalance) && $rawNewBalance !== '') { + $rawNewBalance = $this->normalizeDecimal($rawNewBalance); + } + $newBalance = is_numeric($rawNewBalance) ? (float) $rawNewBalance : 0; if ($newBalance !== $oldBalance) { try { $contractId = $existing->contract_id;