fix: company save — cast int fields, fix error redirect URL

- 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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-29 09:02:34 -05:00
co-authored by Claude Sonnet 4.6
parent b25126e52b
commit cb348bd602
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -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);
}
+7
View File
@@ -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) {