-- ============================================
-- BCV Exchange Rate Plugin - Registro en iDempiere
-- ============================================
-- Ejecutar este script en la base de datos de iDempiere
-- ANTES de instalar el plugin OSGi
-- ============================================

-- 1. Crear el Proceso
INSERT INTO AD_Process (
    AD_Process_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, Value, Description, Help, Classname,
    AccessLevel, EntityType, IsDirectPrint, IsReport, IsServerProcess, ShowHelp
) VALUES (
    5000000, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'BCV_ExchangeRateUpdate', 'BCV_ExchangeRateUpdate',
    'Actualización automática de tasa de cambio oficial BCV (USD/VES)',
    'Obtiene la tasa de cambio oficial del Banco Central de Venezuela y la registra en C_Conversion_Rate.',
    'com.venezuela.bcvrate.process.BCVExchangeRateProcess',
    '4', 'U', 'N', 'N', 'Y', 'L'
)
ON CONFLICT (AD_Process_ID) DO NOTHING;

-- 2. Parámetro: AD_Client_ID (Grupo Empresarial)
INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, ColumnName, Description, AD_Process_ID, SeqNo,
    AD_Reference_ID, AD_Reference_Value_ID, IsMandatory, DefaultValue,
    FieldLength, IsRange
) VALUES (
    5000000, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'Client', 'AD_Client_ID', 'Grupo empresarial destino',
    5000000, 10, 19, 157, 'Y', '', 10, 'N'
)
ON CONFLICT (AD_Process_Para_ID) DO NOTHING;

-- 3. Parámetro: C_ConversionType_ID (Tipo de Conversión)
INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, ColumnName, Description, AD_Process_ID, SeqNo,
    AD_Reference_ID, AD_Reference_Value_ID, IsMandatory, DefaultValue,
    FieldLength, IsRange
) VALUES (
    5000001, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'Currency Conversion Type', 'C_ConversionType_ID', 'Tipo de conversión (Spot, Corporate, etc.)',
    5000000, 20, 19, 232, 'N', '', 10, 'N'
)
ON CONFLICT (AD_Process_Para_ID) DO NOTHING;

-- 4. Parámetro: DateFrom (Fecha Desde)
INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, ColumnName, Description, AD_Process_ID, SeqNo,
    AD_Reference_ID, IsMandatory, DefaultValue,
    FieldLength, IsRange
) VALUES (
    5000002, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'Date From', 'DateFrom', 'Fecha inicio (default: hoy)',
    5000000, 30, 16, 'N', '@#Date@', 10, 'N'
)
ON CONFLICT (AD_Process_Para_ID) DO NOTHING;

-- 5. Parámetro: DateTo (Fecha Hasta)
INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, ColumnName, Description, AD_Process_ID, SeqNo,
    AD_Reference_ID, IsMandatory, DefaultValue,
    FieldLength, IsRange
) VALUES (
    5000003, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'Date To', 'DateTo', 'Fecha fin (default: hoy)',
    5000000, 40, 16, 'N', '@#Date@', 10, 'N'
)
ON CONFLICT (AD_Process_Para_ID) DO NOTHING;

-- 6. Parámetro: IsSimulation (Modo Simulación)
INSERT INTO AD_Process_Para (
    AD_Process_Para_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
    Name, ColumnName, Description, AD_Process_ID, SeqNo,
    AD_Reference_ID, IsMandatory, DefaultValue,
    FieldLength, IsRange
) VALUES (
    5000004, 0, 0, 'Y', CURRENT_TIMESTAMP, 100, CURRENT_TIMESTAMP, 100,
    'Simulation', 'IsSimulation', 'Si está marcado, solo muestra qué haría sin grabar',
    5000000, 50, 20, 'N', 'N', 1, 'N'
)
ON CONFLICT (AD_Process_Para_ID) DO NOTHING;

-- ============================================
-- NOTA: El Scheduler se crea manualmente en iDempiere:
-- Ir a: Procesos > Scheduler > Nuevo
-- Nombre: BCV_DailyRateUpdate
-- Patrón Cron: 0 0/15 16-23 * * 1-5
-- Proceso: BCV_ExchangeRateUpdate
-- ============================================
