From cb348bd602929639ef26ecb975d8a6d00428660a Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 29 Jun 2026 09:02:34 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20company=20save=20=E2=80=94=20cast=20int?= =?UTF-8?q?=20fields,=20fix=20error=20redirect=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Cast erp_active_users (and requires_approval, is_active) to int before INSERT/UPDATE so empty string '' doesn't fail the INT column - Fix error redirect for new company: was /admin/companies/new (404), now /admin/company/edit (the actual new-company route) Co-Authored-By: Claude Sonnet 4.6 --- public/index.php | 2 +- services/CompanyRepository.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 46ed24d..0d4283e 100644 --- a/public/index.php +++ b/public/index.php @@ -249,7 +249,7 @@ $routes = [ } catch (\RuntimeException $e) { $errMsg = urlencode($e->getMessage()); $redirect = $isNew - ? '/admin/companies/new?error=' . $errMsg + ? '/admin/company/edit?error=' . $errMsg : '/admin/company/edit?id=' . (int)$data['id'] . '&error=' . $errMsg; header('Location: ' . $redirect); } diff --git a/services/CompanyRepository.php b/services/CompanyRepository.php index 4cece14..5563250 100644 --- a/services/CompanyRepository.php +++ b/services/CompanyRepository.php @@ -50,6 +50,13 @@ class CompanyRepository } } + // Integer fields: cast so empty string '' doesn't fail the INT column + foreach (['requires_approval', 'is_active', 'erp_active_users'] as $f) { + if (array_key_exists($f, $data)) { + $data[$f] = (int)$data[$f]; + } + } + $params = []; $sets = []; foreach ($fields as $f) {