erp-construccion-database-v2/seeds/dev/02b-hr-employees.sql
Adrian Flores Cortes 6cd5507fc2 feat(seeds): Add comprehensive seed validation and new data files
- Add 02b-hr-employees.sql: 15 puestos, 15 employees for HSE EPP assignments
- Add 11-infonavit.sql: registro, ofertas, derechohabientes, asignaciones
- Add validate-seeds-comprehensive.sql: FK integrity, calculations, coverage
- Update 06-estimaciones.sql: Document formula in header
- Update 08-hse.sql: Fix hse.capacitacion → hse.capacitaciones, add 6 new tables
- Update validate-seeds.sql: Fix table name reference

New tables seeded: tipos_inspeccion, inspecciones, epp_matriz_puesto,
epp_asignaciones, cumplimiento_obra, dias_sin_accidente

Coverage increased: HSE 7%→17%, INFONAVIT 0%→50%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 11:31:59 -06:00

280 lines
16 KiB
PL/PgSQL

-- ═══════════════════════════════════════════════════════════════════════════════
-- SEED 02b: PUESTOS Y EMPLEADOS
-- ═══════════════════════════════════════════════════════════════════════════════
-- Proyecto: ERP Construcción
-- Autor: Claude Opus 4.5
-- Fecha: 2026-02-03
-- Descripción: Puestos de trabajo y empleados para demo HSE y RRHH
-- Dependencias: 02-users-profiles.sql, 03-empresa-tenant.sql
-- Nota: Requerido por HSE para asignaciones de EPP y capacitaciones
-- ═══════════════════════════════════════════════════════════════════════════════
-- UUIDs: 00000000-0000-0000-002b-XXXXXXXXXXXX
BEGIN;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 1. PUESTOS DE TRABAJO
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO hr.puestos (
id, tenant_id, codigo, nombre, descripcion,
nivel_riesgo, requiere_capacitacion_especial, activo,
created_at
) VALUES
-- Administración
('00000000-0000-0000-002b-000000000001', '00000000-0000-0000-0003-000000000001',
'PTO-DIR', 'Director General', 'Máxima autoridad ejecutiva',
'bajo', false, true, NOW()),
('00000000-0000-0000-002b-000000000002', '00000000-0000-0000-0003-000000000001',
'PTO-GER', 'Gerente de Proyectos', 'Responsable de múltiples proyectos',
'bajo', false, true, NOW()),
('00000000-0000-0000-002b-000000000003', '00000000-0000-0000-0003-000000000001',
'PTO-ADM', 'Administrativo', 'Personal de oficina y administración',
'bajo', false, true, NOW()),
-- Obra
('00000000-0000-0000-002b-000000000004', '00000000-0000-0000-0003-000000000001',
'PTO-RES', 'Residente de Obra', 'Responsable directo de una obra',
'medio', true, true, NOW()),
('00000000-0000-0000-002b-000000000005', '00000000-0000-0000-0003-000000000001',
'PTO-SUP', 'Supervisor de Campo', 'Supervisa trabajos de campo',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000006', '00000000-0000-0000-0003-000000000001',
'PTO-ALB', 'Albañil', 'Trabajos de albañilería y acabados',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000007', '00000000-0000-0000-0003-000000000001',
'PTO-FIE', 'Fierrero', 'Armado y habilitado de acero',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000008', '00000000-0000-0000-0003-000000000001',
'PTO-CAR', 'Carpintero', 'Cimbra y trabajos de carpintería',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000009', '00000000-0000-0000-0003-000000000001',
'PTO-ELE', 'Electricista', 'Instalaciones eléctricas',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000010', '00000000-0000-0000-0003-000000000001',
'PTO-PLO', 'Plomero', 'Instalaciones hidráulicas y sanitarias',
'medio', true, true, NOW()),
('00000000-0000-0000-002b-000000000011', '00000000-0000-0000-0003-000000000001',
'PTO-OPE', 'Operador de Maquinaria', 'Opera maquinaria pesada',
'alto', true, true, NOW()),
('00000000-0000-0000-002b-000000000012', '00000000-0000-0000-0003-000000000001',
'PTO-AYU', 'Ayudante General', 'Apoyo en diversas actividades',
'medio', true, true, NOW()),
-- Especializados
('00000000-0000-0000-002b-000000000013', '00000000-0000-0000-0003-000000000001',
'PTO-HSE', 'Coordinador HSE', 'Seguridad, salud y medio ambiente',
'medio', true, true, NOW()),
('00000000-0000-0000-002b-000000000014', '00000000-0000-0000-0003-000000000001',
'PTO-CAL', 'Inspector de Calidad', 'Control de calidad en obra',
'bajo', false, true, NOW()),
('00000000-0000-0000-002b-000000000015', '00000000-0000-0000-0003-000000000001',
'PTO-ALM', 'Almacenista', 'Control de almacén e inventarios',
'bajo', false, true, NOW())
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 2. EMPLEADOS DEMO
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO hr.employees (
id, tenant_id, codigo, nombre, apellido_paterno, apellido_materno,
curp, rfc, nss, fecha_nacimiento, genero,
email, telefono,
fecha_ingreso, puesto_id, departamento, tipo_contrato, salario_diario,
estado, created_at, created_by
) VALUES
-- Personal administrativo vinculado a usuarios
('00000000-0000-0000-002b-000000000101', '00000000-0000-0000-0003-000000000001',
'EMP-001', 'Juan Carlos', 'Director', 'Méndez',
'DIMJ800515HAGRXN01', 'DIMJ800515ABC', '12345678901', '1980-05-15', 'M',
'director@demo.com', '+52 449 200 0002',
'2020-01-15', '00000000-0000-0000-002b-000000000001', 'Dirección', 'indefinido', 5000.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000102', '00000000-0000-0000-0003-000000000001',
'EMP-002', 'María Elena', 'Gerente', 'Torres',
'GETM850320MAGRRL02', 'GETM850320ABC', '12345678902', '1985-03-20', 'F',
'gerente1@demo.com', '+52 449 200 0003',
'2021-03-01', '00000000-0000-0000-002b-000000000002', 'Construcción', 'indefinido', 3500.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000103', '00000000-0000-0000-0003-000000000001',
'EMP-003', 'Carlos Alberto', 'Residente', 'López',
'RELC880810HAGSPS03', 'RELC880810ABC', '12345678903', '1988-08-10', 'M',
'residente1@demo.com', '+52 449 200 0004',
'2022-06-15', '00000000-0000-0000-002b-000000000004', 'Construcción', 'indefinido', 2500.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000104', '00000000-0000-0000-0003-000000000001',
'EMP-004', 'Ana María', 'Supervisora', 'García',
'SAGA900125MASPRN04', 'SAGA900125ABC', '12345678904', '1990-01-25', 'F',
'supervisor1@demo.com', '+52 449 200 0005',
'2022-08-01', '00000000-0000-0000-002b-000000000005', 'Construcción', 'indefinido', 2000.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000105', '00000000-0000-0000-0003-000000000001',
'EMP-005', 'Elena Patricia', 'Seguridad', 'Sánchez',
'SASE870605MASGLN05', 'SASE870605ABC', '12345678905', '1987-06-05', 'F',
'hse1@demo.com', '+52 449 200 0009',
'2023-01-10', '00000000-0000-0000-002b-000000000013', 'HSE', 'indefinido', 2200.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000106', '00000000-0000-0000-0003-000000000001',
'EMP-006', 'Diego Armando', 'Calidad', 'Rodríguez',
'CARD850715HASLDS06', 'CARD850715ABC', '12345678906', '1985-07-15', 'M',
'calidad1@demo.com', '+52 449 200 0010',
'2023-02-01', '00000000-0000-0000-002b-000000000014', 'Calidad', 'indefinido', 2000.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
-- Personal de obra (sin usuario del sistema)
('00000000-0000-0000-002b-000000000107', '00000000-0000-0000-0003-000000000001',
'EMP-007', 'Roberto', 'Martínez', 'Hernández',
'MAHR750420HASRRB07', 'MAHR750420ABC', '12345678907', '1975-04-20', 'M',
NULL, '+52 449 300 0001',
'2023-03-15', '00000000-0000-0000-002b-000000000006', 'Construcción', 'obra_determinada', 450.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000108', '00000000-0000-0000-0003-000000000001',
'EMP-008', 'José Luis', 'Pérez', 'Gómez',
'PEGJ800830HASPRX08', 'PEGJ800830ABC', '12345678908', '1980-08-30', 'M',
NULL, '+52 449 300 0002',
'2023-04-01', '00000000-0000-0000-002b-000000000007', 'Construcción', 'obra_determinada', 500.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000109', '00000000-0000-0000-0003-000000000001',
'EMP-009', 'Francisco', 'López', 'Ruiz',
'LORF780315HASPPR09', 'LORF780315ABC', '12345678909', '1978-03-15', 'M',
NULL, '+52 449 300 0003',
'2023-04-15', '00000000-0000-0000-002b-000000000008', 'Construcción', 'obra_determinada', 480.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000110', '00000000-0000-0000-0003-000000000001',
'EMP-010', 'Miguel Ángel', 'Jiménez', 'Morales',
'JIMM850912HASMGR10', 'JIMM850912ABC', '12345678910', '1985-09-12', 'M',
NULL, '+52 449 300 0004',
'2023-05-01', '00000000-0000-0000-002b-000000000009', 'Construcción', 'indefinido', 550.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000111', '00000000-0000-0000-0003-000000000001',
'EMP-011', 'Ricardo', 'Sánchez', 'Flores',
'SAFR820607HASSNC11', 'SAFR820607ABC', '12345678911', '1982-06-07', 'M',
NULL, '+52 449 300 0005',
'2023-05-15', '00000000-0000-0000-002b-000000000010', 'Construcción', 'indefinido', 520.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000112', '00000000-0000-0000-0003-000000000001',
'EMP-012', 'Jesús Manuel', 'Herrera', 'Castro',
'HECJ901225HASRRS12', 'HECJ901225ABC', '12345678912', '1990-12-25', 'M',
NULL, '+52 449 300 0006',
'2023-06-01', '00000000-0000-0000-002b-000000000011', 'Construcción', 'indefinido', 700.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000113', '00000000-0000-0000-0003-000000000001',
'EMP-013', 'Pedro', 'Ramírez', 'Díaz',
'RADP950503HASPRD13', 'RADP950503ABC', '12345678913', '1995-05-03', 'M',
NULL, '+52 449 300 0007',
'2024-01-15', '00000000-0000-0000-002b-000000000012', 'Construcción', 'obra_determinada', 350.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000114', '00000000-0000-0000-0003-000000000001',
'EMP-014', 'Juan Pablo', 'Vargas', 'Mendoza',
'VAMJ970817HASRGN14', 'VAMJ970817ABC', '12345678914', '1997-08-17', 'M',
NULL, '+52 449 300 0008',
'2024-02-01', '00000000-0000-0000-002b-000000000012', 'Construcción', 'obra_determinada', 350.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101'),
('00000000-0000-0000-002b-000000000115', '00000000-0000-0000-0003-000000000001',
'EMP-015', 'Marco Antonio', 'Ortiz', 'Luna',
'OILM880422HASRTN15', 'OILM880422ABC', '12345678915', '1988-04-22', 'M',
NULL, '+52 449 300 0009',
'2024-03-01', '00000000-0000-0000-002b-000000000006', 'Construcción', 'obra_determinada', 450.00,
'activo', NOW(), '00000000-0000-0000-0002-000000000101')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 3. ASIGNACIÓN DE EMPLEADOS A FRACCIONAMIENTOS
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO hr.employee_fraccionamientos (
id, tenant_id, employee_id, fraccionamiento_id,
fecha_inicio, fecha_fin, rol, activo,
created_at
) VALUES
-- Las Palmas
('00000000-0000-0000-002b-000000000201', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000103', '00000000-0000-0000-0004-000000000101',
'2024-03-01', NULL, 'Residente', true, NOW()),
('00000000-0000-0000-002b-000000000202', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000104', '00000000-0000-0000-0004-000000000101',
'2024-03-01', NULL, 'Supervisor', true, NOW()),
('00000000-0000-0000-002b-000000000203', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000105', '00000000-0000-0000-0004-000000000101',
'2024-03-01', NULL, 'HSE', true, NOW()),
('00000000-0000-0000-002b-000000000204', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000107', '00000000-0000-0000-0004-000000000101',
'2024-03-15', NULL, 'Albañil', true, NOW()),
('00000000-0000-0000-002b-000000000205', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000108', '00000000-0000-0000-0004-000000000101',
'2024-04-01', NULL, 'Fierrero', true, NOW()),
('00000000-0000-0000-002b-000000000206', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000112', '00000000-0000-0000-0004-000000000101',
'2024-03-01', NULL, 'Operador', true, NOW()),
-- Torre Diamante
('00000000-0000-0000-002b-000000000207', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000105', '00000000-0000-0000-0004-000000000102',
'2024-06-01', NULL, 'HSE', true, NOW()),
('00000000-0000-0000-002b-000000000208', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-002b-000000000110', '00000000-0000-0000-0004-000000000102',
'2024-06-01', NULL, 'Electricista', true, NOW())
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- VERIFICACIÓN
-- ─────────────────────────────────────────────────────────────────────────────────
DO $$
DECLARE
v_puestos INTEGER;
v_empleados INTEGER;
v_asignaciones INTEGER;
BEGIN
SELECT COUNT(*) INTO v_puestos FROM hr.puestos;
SELECT COUNT(*) INTO v_empleados FROM hr.employees;
SELECT COUNT(*) INTO v_asignaciones FROM hr.employee_fraccionamientos;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'SEED 02b - HR EMPLOYEES - COMPLETADO';
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'Puestos: %', v_puestos;
RAISE NOTICE 'Empleados: %', v_empleados;
RAISE NOTICE 'Asignaciones a obra: %', v_asignaciones;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
END $$;
COMMIT;
-- ═══════════════════════════════════════════════════════════════════════════════
-- FIN SEED 02b
-- ═══════════════════════════════════════════════════════════════════════════════