erp-construccion-database-v2/seeds/dev/11-infonavit.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

294 lines
16 KiB
PL/PgSQL

-- ═══════════════════════════════════════════════════════════════════════════════
-- SEED 11: INFONAVIT Y DERECHOHABIENTES
-- ═══════════════════════════════════════════════════════════════════════════════
-- Proyecto: ERP Construcción
-- Autor: Claude Opus 4.5
-- Fecha: 2026-02-03
-- Descripción: Registro INFONAVIT, ofertas, derechohabientes, asignaciones
-- Dependencias: 03-empresa-tenant.sql, 04-proyectos-obras.sql
-- Cobertura: 4/8 tablas (50%) - registro, oferta, derechohabientes, asignaciones
-- ═══════════════════════════════════════════════════════════════════════════════
-- UUIDs: 00000000-0000-0000-000b-XXXXXXXXXXXX
BEGIN;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 1. REGISTRO INFONAVIT (Registro del constructor)
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO infonavit.registro_infonavit (
id, tenant_id, company_id, registro_number, registro_date,
status, vigencia_start, vigencia_end,
responsable_tecnico, cedula_profesional,
metadata, created_at, created_by
) VALUES
('00000000-0000-0000-000b-000000000001', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0003-000000000001',
'REG-INFONAVIT-2024-001', '2024-01-15',
'active', '2024-01-15', '2029-01-14',
'Ing. Roberto García López', '1234567',
'{"tipo_registro": "constructor_vivienda", "zona": "centro_norte"}'::JSONB,
NOW(), '00000000-0000-0000-0002-000000000102')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 2. OFERTA DE VIVIENDAS
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO infonavit.oferta_vivienda (
id, tenant_id, registro_id, fraccionamiento_id,
oferta_number, submission_date, approval_date,
total_units, approved_units,
price_range_min, price_range_max,
status, metadata, created_at, created_by
) VALUES
-- Oferta Las Palmas Etapa 1
('00000000-0000-0000-000b-000000000101', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000001', '00000000-0000-0000-0004-000000000101',
'OFE-2024-PALMAS-001', '2024-02-15', '2024-03-01',
40, 38,
1850000.00, 3300000.00,
'approved',
'{"etapa": 1, "tipos_vivienda": ["CASA-90", "CASA-120", "CASA-150"]}'::JSONB,
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Oferta Torre Diamante
('00000000-0000-0000-000b-000000000102', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000001', '00000000-0000-0000-0004-000000000102',
'OFE-2024-DIAMANTE-001', '2024-05-10', '2024-05-25',
48, 48,
1250000.00, 2250000.00,
'approved',
'{"torre": "A", "tipos_vivienda": ["DEPTO-65", "DEPTO-85", "DEPTO-110"]}'::JSONB,
NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 3. DERECHOHABIENTES (Compradores con crédito INFONAVIT)
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO infonavit.derechohabientes (
id, tenant_id,
nss, curp, rfc, full_name,
first_name, last_name, second_last_name,
birth_date, gender, marital_status,
email, phone, mobile,
address, city, state, zip_code,
employer_name, employer_rfc, employment_start_date, salary,
cotization_weeks, credit_type, credit_number,
credit_amount, puntos_infonavit, subcuenta_vivienda,
precalificacion_date, precalificacion_amount,
status, created_at, created_by
) VALUES
-- Derechohabiente 1 - Comprador Lote A-01 (entregado)
('00000000-0000-0000-000b-000000000201', '00000000-0000-0000-0003-000000000001',
'12345678901', 'GARM800515HASRRL01', 'GARM800515ABC',
'Manuel García Rodríguez', 'Manuel', 'García', 'Rodríguez',
'1980-05-15', 'Masculino', 'Casado',
'manuel.garcia@email.com', '+52 449 111 1111', '+52 449 211 1111',
'Av. Las Torres 123', 'Aguascalientes', 'Aguascalientes', '20010',
'Nissan Mexicana S.A.', 'NME850101XXX', '2005-03-01', 25000.00,
936, 'infonavit_tradicional', 'CRED-INF-2024-001',
850000.00, 145.5, 185000.00,
'2024-01-10', 900000.00,
'owner', NOW(), '00000000-0000-0000-0002-000000000103'),
-- Derechohabiente 2 - Comprador Lote A-02 (entregado)
('00000000-0000-0000-000b-000000000202', '00000000-0000-0000-0003-000000000001',
'12345678902', 'LOPH850320MASPRL02', 'LOPH850320ABC',
'Patricia López Hernández', 'Patricia', 'López', 'Hernández',
'1985-03-20', 'Femenino', 'Soltera',
'patricia.lopez@email.com', '+52 449 111 2222', '+52 449 211 2222',
'Calle Morelos 456', 'Aguascalientes', 'Aguascalientes', '20020',
'Continental AG México', 'CAM900101XXX', '2010-06-15', 22000.00,
720, 'infonavit_tradicional', 'CRED-INF-2024-002',
800000.00, 138.2, 165000.00,
'2024-01-15', 850000.00,
'owner', NOW(), '00000000-0000-0000-0002-000000000103'),
-- Derechohabiente 3 - En proceso de escrituración
('00000000-0000-0000-000b-000000000203', '00000000-0000-0000-0003-000000000001',
'12345678903', 'SAMJ900810HASNTL03', 'SAMJ900810ABC',
'José Luis Sánchez Martínez', 'José Luis', 'Sánchez', 'Martínez',
'1990-08-10', 'Masculino', 'Casado',
'joseluis.sanchez@email.com', '+52 449 111 3333', '+52 449 211 3333',
'Blvd. Norte 789', 'Aguascalientes', 'Aguascalientes', '20030',
'Jatco México S.A.', 'JME880101XXX', '2012-01-20', 28000.00,
624, 'cofinavit', 'CRED-INF-2024-003',
1200000.00, 155.8, 210000.00,
'2024-02-01', 1250000.00,
'in_process', NOW(), '00000000-0000-0000-0002-000000000103'),
-- Derechohabiente 4 - Asignado pero pendiente de firma
('00000000-0000-0000-000b-000000000204', '00000000-0000-0000-0003-000000000001',
'12345678904', 'RORM880125MASPXR04', 'RORM880125ABC',
'María del Rosario Ramírez Ortiz', 'María del Rosario', 'Ramírez', 'Ortiz',
'1988-01-25', 'Femenino', 'Casada',
'rosario.ramirez@email.com', '+52 449 111 4444', '+52 449 211 4444',
'Av. Tecnológico 234', 'Aguascalientes', 'Aguascalientes', '20290',
'Texas Instruments', 'TIM950101XXX', '2015-07-01', 35000.00,
520, 'infonavit_total', 'CRED-INF-2024-004',
1500000.00, 168.3, 280000.00,
'2024-02-15', 1550000.00,
'assigned', NOW(), '00000000-0000-0000-0002-000000000103'),
-- Derechohabiente 5 - Precalificado, buscando vivienda
('00000000-0000-0000-000b-000000000205', '00000000-0000-0000-0003-000000000001',
'12345678905', 'HECR920605HASPSS05', 'HECR920605ABC',
'Ricardo Hernández Castro', 'Ricardo', 'Hernández', 'Castro',
'1992-06-05', 'Masculino', 'Soltero',
'ricardo.hernandez@email.com', '+52 449 111 5555', '+52 449 211 5555',
'Calle Independencia 567', 'Aguascalientes', 'Aguascalientes', '20040',
'Flextronics Manufacturing', 'FME920101XXX', '2018-02-15', 18000.00,
312, 'infonavit_tradicional', NULL,
NULL, 120.5, 95000.00,
'2024-03-01', 680000.00,
'qualified', NOW(), '00000000-0000-0000-0002-000000000103'),
-- Derechohabientes para Torre Diamante
('00000000-0000-0000-000b-000000000206', '00000000-0000-0000-0003-000000000001',
'12345678906', 'MOVP850715HASRRL06', 'MOVP850715ABC',
'Pedro Morales Vargas', 'Pedro', 'Morales', 'Vargas',
'1985-07-15', 'Masculino', 'Casado',
'pedro.morales@email.com', '+52 449 111 6666', '+52 449 211 6666',
'Av. Universidad 890', 'Aguascalientes', 'Aguascalientes', '20131',
'Bosch México', 'BME870101XXX', '2008-09-01', 32000.00,
780, 'cofinavit', 'CRED-INF-2024-006',
1100000.00, 152.4, 220000.00,
'2024-04-10', 1150000.00,
'owner', NOW(), '00000000-0000-0000-0002-000000000103'),
('00000000-0000-0000-000b-000000000207', '00000000-0000-0000-0003-000000000001',
'12345678907', 'GUAL900422MASTRX07', 'GUAL900422ABC',
'Lucía Gutiérrez Alvarado', 'Lucía', 'Gutiérrez', 'Alvarado',
'1990-04-22', 'Femenino', 'Soltera',
'lucia.gutierrez@email.com', '+52 449 111 7777', '+52 449 211 7777',
'Calle Madero 123', 'Aguascalientes', 'Aguascalientes', '20000',
'Sensata Technologies', 'STE960101XXX', '2016-11-15', 24000.00,
416, 'infonavit_tradicional', 'CRED-INF-2024-007',
720000.00, 132.8, 145000.00,
'2024-04-20', 750000.00,
'owner', NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 4. ASIGNACIÓN DE VIVIENDAS
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO infonavit.asignacion_vivienda (
id, tenant_id, derechohabiente_id,
lote_id, departamento_id, oferta_id,
assignment_date, assignment_number, status,
sale_price, credit_amount, down_payment, subsidy_amount,
notary_name, notary_number,
deed_date, deed_number,
public_registry_number, public_registry_date,
scheduled_delivery_date, actual_delivery_date,
notes, created_at, created_by
) VALUES
-- Lote A-01 - Entregado
('00000000-0000-0000-000b-000000000301', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000201',
'00000000-0000-0000-0004-000000000601', NULL,
'00000000-0000-0000-000b-000000000101',
'2024-02-20', 'ASIG-2024-001', 'delivered',
1900000.00, 850000.00, 190000.00, 60000.00,
'Lic. Juan Notario Público', 'NOT-AGS-123',
'2024-04-15', 'ESC-2024-001',
'RPP-AGS-2024-001', '2024-04-20',
'2024-05-01', '2024-05-01',
'Entrega en tiempo y forma',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Lote A-02 - Entregado
('00000000-0000-0000-000b-000000000302', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000202',
'00000000-0000-0000-0004-000000000602', NULL,
'00000000-0000-0000-000b-000000000101',
'2024-02-25', 'ASIG-2024-002', 'delivered',
1900000.00, 800000.00, 195000.00, 55000.00,
'Lic. Juan Notario Público', 'NOT-AGS-123',
'2024-04-18', 'ESC-2024-002',
'RPP-AGS-2024-002', '2024-04-22',
'2024-05-10', '2024-05-08',
'Entrega anticipada',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Lote A-05 - En proceso de escrituración
('00000000-0000-0000-000b-000000000303', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000203',
'00000000-0000-0000-0004-000000000605', NULL,
'00000000-0000-0000-000b-000000000101',
'2024-03-15', 'ASIG-2024-003', 'in_process',
1880000.00, 1200000.00, 150000.00, 50000.00,
'Lic. María Notaria Pública', 'NOT-AGS-456',
NULL, NULL,
NULL, NULL,
'2024-07-01', NULL,
'En trámite de escrituración',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Departamento 101 - Entregado
('00000000-0000-0000-000b-000000000304', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000206',
NULL, '00000000-0000-0000-0004-000000000701',
'00000000-0000-0000-000b-000000000102',
'2024-05-20', 'ASIG-2024-004', 'delivered',
1300000.00, 1100000.00, 130000.00, 70000.00,
'Lic. Juan Notario Público', 'NOT-AGS-123',
'2024-07-10', 'ESC-2024-004',
'RPP-AGS-2024-004', '2024-07-15',
'2024-08-01', '2024-08-01',
NULL,
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Departamento 102 - Entregado
('00000000-0000-0000-000b-000000000305', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-000b-000000000207',
NULL, '00000000-0000-0000-0004-000000000702',
'00000000-0000-0000-000b-000000000102',
'2024-05-25', 'ASIG-2024-005', 'delivered',
1700000.00, 720000.00, 170000.00, 60000.00,
'Lic. María Notaria Pública', 'NOT-AGS-456',
'2024-07-12', 'ESC-2024-005',
'RPP-AGS-2024-005', '2024-07-18',
'2024-08-15', '2024-08-10',
NULL,
NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- VERIFICACIÓN
-- ─────────────────────────────────────────────────────────────────────────────────
DO $$
DECLARE
v_registros INTEGER;
v_ofertas INTEGER;
v_derechohabientes INTEGER;
v_asignaciones INTEGER;
BEGIN
SELECT COUNT(*) INTO v_registros FROM infonavit.registro_infonavit;
SELECT COUNT(*) INTO v_ofertas FROM infonavit.oferta_vivienda;
SELECT COUNT(*) INTO v_derechohabientes FROM infonavit.derechohabientes;
SELECT COUNT(*) INTO v_asignaciones FROM infonavit.asignacion_vivienda;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'SEED 11 - INFONAVIT - COMPLETADO';
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'Registros INFONAVIT: %', v_registros;
RAISE NOTICE 'Ofertas de vivienda: %', v_ofertas;
RAISE NOTICE 'Derechohabientes: %', v_derechohabientes;
RAISE NOTICE 'Asignaciones: %', v_asignaciones;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'Cobertura INFONAVIT: 4/8 tablas (50%%)';
RAISE NOTICE '══════════════════════════════════════════════════════════════';
END $$;
COMMIT;
-- ═══════════════════════════════════════════════════════════════════════════════
-- FIN SEED 11
-- ═══════════════════════════════════════════════════════════════════════════════