erp-construccion-database-v2/seeds/dev/06-estimaciones.sql
Adrian Flores Cortes 8df74f73d2 [TASK-2026-02-03-SEEDS] feat: Add complete development seeds for demo
Seeds include:
- 01-core-catalogs.sql: Units, currencies, taxes, banks, states (~100 records)
- 02-users-profiles.sql: 12 roles, 50+ permissions, 12 demo users
- 03-empresa-tenant.sql: Demo company with 2 branches, 4 warehouses
- 04-proyectos-obras.sql: 3 projects, stages, lots, apartments
- 05-presupuestos.sql: CMIC-based concepts, 5 budgets
- 06-estimaciones.sql: Contracts, estimates, advances
- 07-avances-calidad.sql: Progress, logbook, quality checklists
- 08-hse.sql: PPE catalog, training, incidents
- 09-finanzas.sql: Chart of accounts, CxP, CxC, balanced entries
- 10-activos-documentos.sql: Assets, maintenance, documents

Total: ~940 records for complete demo coverage

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

232 lines
13 KiB
PL/PgSQL

-- ═══════════════════════════════════════════════════════════════════════════════
-- SEED 06: CONTRATOS Y ESTIMACIONES
-- ═══════════════════════════════════════════════════════════════════════════════
-- Proyecto: ERP Construcción
-- Autor: Claude Opus 4.5
-- Fecha: 2026-02-03
-- Descripción: Contratos, estimaciones, generadores, anticipos, retenciones
-- Dependencias: 04-proyectos-obras.sql, 05-presupuestos.sql
-- ═══════════════════════════════════════════════════════════════════════════════
-- UUIDs: 00000000-0000-0000-0006-XXXXXXXXXXXX
BEGIN;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 1. CONTRATOS DE OBRA
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO construction.contratos (
id, tenant_id, subcontratista_id, fraccionamiento_id,
contract_number, name, contract_type,
start_date, end_date,
total_amount, advance_percentage, retention_percentage,
status, signed_at, signed_by,
created_at, created_by
) VALUES
-- Contrato Cimentaciones - Las Palmas
('00000000-0000-0000-0006-000000000001', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0004-000000000801', '00000000-0000-0000-0004-000000000101',
'CONT-2024-001', 'Cimentación Etapa 1 Las Palmas', 'unit_price',
'2024-03-01', '2024-08-31',
2500000.00, 30.00, 5.00,
'active', '2024-02-28', '00000000-0000-0000-0002-000000000102',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Contrato Instalaciones Eléctricas - Las Palmas
('00000000-0000-0000-0006-000000000002', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0004-000000000802', '00000000-0000-0000-0004-000000000101',
'CONT-2024-002', 'Instalaciones Eléctricas Etapa 1 Las Palmas', 'unit_price',
'2024-05-01', '2024-12-31',
1800000.00, 20.00, 5.00,
'active', '2024-04-25', '00000000-0000-0000-0002-000000000102',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Contrato Plomería - Las Palmas
('00000000-0000-0000-0006-000000000003', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0004-000000000803', '00000000-0000-0000-0004-000000000101',
'CONT-2024-003', 'Instalaciones Hidro-Sanitarias Etapa 1', 'unit_price',
'2024-05-15', '2025-01-31',
1650000.00, 20.00, 5.00,
'active', '2024-05-10', '00000000-0000-0000-0002-000000000102',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Contrato Acabados - Las Palmas
('00000000-0000-0000-0006-000000000004', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0004-000000000804', '00000000-0000-0000-0004-000000000101',
'CONT-2024-004', 'Acabados y Pintura Etapa 1 Las Palmas', 'unit_price',
'2024-07-01', '2025-03-31',
2200000.00, 15.00, 5.00,
'active', '2024-06-28', '00000000-0000-0000-0002-000000000102',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Contrato Estructura - Torre Diamante
('00000000-0000-0000-0006-000000000005', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0004-000000000801', '00000000-0000-0000-0004-000000000102',
'CONT-2024-005', 'Estructura Torre Diamante', 'fixed_price',
'2024-06-01', '2025-12-31',
8500000.00, 25.00, 5.00,
'active', '2024-05-28', '00000000-0000-0000-0002-000000000102',
NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 2. ESTIMACIONES
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO estimates.estimaciones (
id, tenant_id, contrato_id, fraccionamiento_id,
estimate_number, period_start, period_end, sequence_number,
status, subtotal, advance_amount, retention_amount, tax_amount, total_amount,
submitted_at, submitted_by, approved_at, approved_by,
created_at, created_by
) VALUES
-- Estimaciones del Contrato Cimentaciones
('00000000-0000-0000-0006-000000000101', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001', '00000000-0000-0000-0004-000000000101',
'EST-2024-001-01', '2024-03-01', '2024-03-15', 1,
'paid', 350000.00, 105000.00, 17500.00, 56000.00, 283500.00,
'2024-03-18', '00000000-0000-0000-0002-000000000104',
'2024-03-20', '00000000-0000-0000-0002-000000000103',
NOW(), '00000000-0000-0000-0002-000000000104'),
('00000000-0000-0000-0006-000000000102', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001', '00000000-0000-0000-0004-000000000101',
'EST-2024-001-02', '2024-03-16', '2024-03-31', 2,
'paid', 420000.00, 126000.00, 21000.00, 67200.00, 340200.00,
'2024-04-03', '00000000-0000-0000-0002-000000000104',
'2024-04-05', '00000000-0000-0000-0002-000000000103',
NOW(), '00000000-0000-0000-0002-000000000104'),
('00000000-0000-0000-0006-000000000103', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001', '00000000-0000-0000-0004-000000000101',
'EST-2024-001-03', '2024-04-01', '2024-04-15', 3,
'approved', 380000.00, 114000.00, 19000.00, 60800.00, 307800.00,
'2024-04-18', '00000000-0000-0000-0002-000000000104',
'2024-04-20', '00000000-0000-0000-0002-000000000103',
NOW(), '00000000-0000-0000-0002-000000000104'),
('00000000-0000-0000-0006-000000000104', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001', '00000000-0000-0000-0004-000000000101',
'EST-2024-001-04', '2024-04-16', '2024-04-30', 4,
'submitted', 450000.00, 135000.00, 22500.00, 72000.00, 364500.00,
'2024-05-03', '00000000-0000-0000-0002-000000000104',
NULL, NULL,
NOW(), '00000000-0000-0000-0002-000000000104'),
-- Estimaciones del Contrato Eléctrico
('00000000-0000-0000-0006-000000000105', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000002', '00000000-0000-0000-0004-000000000101',
'EST-2024-002-01', '2024-05-01', '2024-05-15', 1,
'paid', 280000.00, 56000.00, 14000.00, 44800.00, 254800.00,
'2024-05-18', '00000000-0000-0000-0002-000000000104',
'2024-05-20', '00000000-0000-0000-0002-000000000103',
NOW(), '00000000-0000-0000-0002-000000000104'),
('00000000-0000-0000-0006-000000000106', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000002', '00000000-0000-0000-0004-000000000101',
'EST-2024-002-02', '2024-05-16', '2024-05-31', 2,
'approved', 320000.00, 64000.00, 16000.00, 51200.00, 291200.00,
'2024-06-03', '00000000-0000-0000-0002-000000000104',
'2024-06-05', '00000000-0000-0000-0002-000000000103',
NOW(), '00000000-0000-0000-0002-000000000104')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 3. ANTICIPOS
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO estimates.anticipos (
id, tenant_id, contrato_id,
advance_type, advance_number, advance_date,
gross_amount, tax_amount, net_amount,
amortization_percentage, amortized_amount,
is_fully_amortized,
approved_at, approved_by, paid_at, payment_reference,
created_at, created_by
) VALUES
-- Anticipo Contrato Cimentaciones (30%)
('00000000-0000-0000-0006-000000000201', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001',
'initial', 'ANT-2024-001-01', '2024-02-28',
750000.00, 120000.00, 870000.00,
30.00, 480000.00, false,
'2024-02-28', '00000000-0000-0000-0002-000000000102',
'2024-03-01', 'TRANSF-BBVA-001',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Anticipo Contrato Eléctrico (20%)
('00000000-0000-0000-0006-000000000202', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000002',
'initial', 'ANT-2024-002-01', '2024-04-25',
360000.00, 57600.00, 417600.00,
20.00, 120000.00, false,
'2024-04-25', '00000000-0000-0000-0002-000000000102',
'2024-04-26', 'TRANSF-BBVA-002',
NOW(), '00000000-0000-0000-0002-000000000103'),
-- Anticipo Contrato Estructura Torre (25%)
('00000000-0000-0000-0006-000000000203', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000005',
'initial', 'ANT-2024-005-01', '2024-05-28',
2125000.00, 340000.00, 2465000.00,
25.00, 0.00, false,
'2024-05-28', '00000000-0000-0000-0002-000000000102',
'2024-05-30', 'TRANSF-BBVA-005',
NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- 4. FONDO DE GARANTÍA
-- ─────────────────────────────────────────────────────────────────────────────────
INSERT INTO estimates.fondo_garantia (
id, tenant_id, contrato_id,
accumulated_amount, released_amount,
created_at, created_by
) VALUES
('00000000-0000-0000-0006-000000000301', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000001',
80000.00, 0.00, NOW(), '00000000-0000-0000-0002-000000000103'),
('00000000-0000-0000-0006-000000000302', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000002',
30000.00, 0.00, NOW(), '00000000-0000-0000-0002-000000000103'),
('00000000-0000-0000-0006-000000000303', '00000000-0000-0000-0003-000000000001',
'00000000-0000-0000-0006-000000000005',
0.00, 0.00, NOW(), '00000000-0000-0000-0002-000000000103')
ON CONFLICT (id) DO NOTHING;
-- ─────────────────────────────────────────────────────────────────────────────────
-- VERIFICACIÓN
-- ─────────────────────────────────────────────────────────────────────────────────
DO $$
DECLARE
v_contratos INTEGER;
v_estimaciones INTEGER;
v_anticipos INTEGER;
v_fondos INTEGER;
BEGIN
SELECT COUNT(*) INTO v_contratos FROM construction.contratos;
SELECT COUNT(*) INTO v_estimaciones FROM estimates.estimaciones;
SELECT COUNT(*) INTO v_anticipos FROM estimates.anticipos;
SELECT COUNT(*) INTO v_fondos FROM estimates.fondo_garantia;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'SEED 06 - ESTIMACIONES - COMPLETADO';
RAISE NOTICE '══════════════════════════════════════════════════════════════';
RAISE NOTICE 'Contratos: %', v_contratos;
RAISE NOTICE 'Estimaciones: %', v_estimaciones;
RAISE NOTICE 'Anticipos: %', v_anticipos;
RAISE NOTICE 'Fondos de garantía: %', v_fondos;
RAISE NOTICE '══════════════════════════════════════════════════════════════';
END $$;
COMMIT;
-- ═══════════════════════════════════════════════════════════════════════════════
-- FIN SEED 06
-- ═══════════════════════════════════════════════════════════════════════════════