diff --git a/services/CompanyRepository.php b/services/CompanyRepository.php index 5563250..ba06d34 100644 --- a/services/CompanyRepository.php +++ b/services/CompanyRepository.php @@ -43,10 +43,13 @@ class CompanyRepository $fields = ['name', 'display_name', 'phone_number_id', 'display_phone', 'api_base_url', 'api_key', 'bot_type', 'requires_approval', 'is_active', 'config_json', 'erp_active_users']; - // Checkboxes: absent when unchecked — explicitly set to 0 so UPDATE clears them - foreach (['requires_approval', 'is_active'] as $cb) { - if (!array_key_exists($cb, $data)) { - $data[$cb] = 0; + // Checkboxes only default to 0 on full company-form saves (when 'name' is present). + // Partial saves (e.g. bot-config saving only config_json) must NOT touch is_active. + if (array_key_exists('name', $data)) { + foreach (['requires_approval', 'is_active'] as $cb) { + if (!array_key_exists($cb, $data)) { + $data[$cb] = 0; + } } }