feat(lab_empresas): módulo CRUD de empresas, convenios y tarifas
- Nuevo módulo lab_empresas: lista paginada, modal create/edit empresa, gestión de subgrupos inline y CRUD de catálogo lab_tarifas_id - APIs: empresas.php (list/get/save/toggle/delete), empresa_subgrupos.php, tarifas_id.php - Migración 09 registra el módulo en system_modules y asigna permiso admin Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
5fedd233f4
commit
b9bb4fc628
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* /api/lab/empresa_subgrupos.php
|
||||
*
|
||||
* GET ?nit_empresa= → subgrupos de la empresa
|
||||
* POST {action:save, ...} → upsert subgrupo
|
||||
* POST {action:delete, id} → elimina subgrupo
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'GET') {
|
||||
$nit = trim($_GET['nit_empresa'] ?? '');
|
||||
if ($nit === '') jsonError('nit_empresa requerido');
|
||||
$pdo = db();
|
||||
$s = $pdo->prepare(
|
||||
"SELECT es.*, ti.nombre AS tarifa_nombre
|
||||
FROM lab_empresa_subgrupos es
|
||||
LEFT JOIN lab_tarifas_id ti ON ti.id = es.tarifa_id
|
||||
WHERE es.nit_empresa = ?
|
||||
ORDER BY es.subgrupo ASC"
|
||||
);
|
||||
$s->execute([$nit]);
|
||||
jsonOk(['subgrupos' => $s->fetchAll(PDO::FETCH_ASSOC)]);
|
||||
}
|
||||
|
||||
requireMethod('POST');
|
||||
$data = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$action = $data['action'] ?? '';
|
||||
$pdo = db();
|
||||
|
||||
if ($action === 'delete') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
if ($id <= 0) jsonError('id requerido');
|
||||
$pdo->prepare("DELETE FROM lab_empresa_subgrupos WHERE id = ?")->execute([$id]);
|
||||
jsonOk(['deleted' => true]);
|
||||
}
|
||||
|
||||
if ($action === 'save') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
$nitEmpresa = trim($data['nit_empresa'] ?? '');
|
||||
$subgrupo = trim($data['subgrupo'] ?? '');
|
||||
if ($nitEmpresa === '') jsonError('nit_empresa requerido');
|
||||
if ($subgrupo === '') jsonError('subgrupo requerido');
|
||||
|
||||
$tarifaId = isset($data['tarifa_id']) && $data['tarifa_id'] !== '' ? (int)$data['tarifa_id'] : null;
|
||||
$refSub = trim($data['ref_subgrupo'] ?? '') ?: null;
|
||||
$codCon = trim($data['cod_contrato'] ?? '') ?: null;
|
||||
|
||||
if ($id > 0) {
|
||||
$pdo->prepare(
|
||||
"UPDATE lab_empresa_subgrupos
|
||||
SET subgrupo=?, tarifa_id=?, ref_subgrupo=?, cod_contrato=?
|
||||
WHERE id=? AND nit_empresa=?"
|
||||
)->execute([$subgrupo, $tarifaId, $refSub, $codCon, $id, $nitEmpresa]);
|
||||
} else {
|
||||
$pdo->prepare(
|
||||
"INSERT INTO lab_empresa_subgrupos (nit_empresa, subgrupo, tarifa_id, ref_subgrupo, cod_contrato)
|
||||
VALUES (?, ?, ?, ?, ?)"
|
||||
)->execute([$nitEmpresa, $subgrupo, $tarifaId, $refSub, $codCon]);
|
||||
$id = (int)$pdo->lastInsertId();
|
||||
}
|
||||
jsonOk(['id' => $id]);
|
||||
}
|
||||
|
||||
jsonError('Acción no reconocida', 400);
|
||||
Reference in New Issue
Block a user