feat: módulo de empresa con números WhatsApp y endpoints API por empresa

- DB: company_phones (3 tipos de permiso, límites por usuarios ERP)
- DB: company_endpoints (11 endpoints upload/download configurables)
- DB: erp_active_users en companies (base para calcular límites)
- Company edit: 3 pestañas — General / Números WhatsApp / Endpoints API
- Límites: tipo 1 = usuarios_erp×10, tipo 2+3 = usuarios_erp
- Endpoints: URL configurable + botón Probar + preview de respuesta JSON
- Layout::close() agregado

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-19 21:57:31 -05:00
co-authored by Claude Sonnet 4.6
parent b083d49769
commit 860e93a20b
4 changed files with 517 additions and 82 deletions
+40
View File
@@ -207,6 +207,46 @@ foreach ($seedSettings as $k => $v) {
$insertStmt->execute([$k, $v]);
}
// ─── Números WhatsApp por empresa ─────────────────────────────────────────────
$db->exec("
CREATE TABLE IF NOT EXISTS company_phones (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
wa_number VARCHAR(25) NOT NULL,
label VARCHAR(100) DEFAULT '',
permission_type TINYINT NOT NULL DEFAULT 1 COMMENT '1=solo reporta, 2=solo recibe, 3=ambos',
is_active TINYINT NOT NULL DEFAULT 1,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uq_cp (company_id, wa_number),
FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
");
// ─── Endpoints API configurables por empresa ───────────────────────────────────
$db->exec("
CREATE TABLE IF NOT EXISTS company_endpoints (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
endpoint_key VARCHAR(50) NOT NULL,
direction ENUM('upload','download') NOT NULL,
url VARCHAR(500) DEFAULT '',
method VARCHAR(10) DEFAULT 'GET',
last_response TEXT,
last_called_at DATETIME,
is_active TINYINT DEFAULT 1,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uq_ce (company_id, endpoint_key),
FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
");
// ─── Campo erp_active_users en companies ──────────────────────────────────────
try {
$db->exec("ALTER TABLE companies ADD COLUMN erp_active_users INT DEFAULT 0 AFTER is_active");
} catch (\PDOException $e) {}
// ─── Usuario admin por defecto ────────────────────────────────────────────────
$email = 'admin@palmas360.com';