unit uBootStrap;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uSplash, uFactuGES_App, StdCtrls;

procedure Initialize;
procedure Run;
procedure Terminate;

implementation
{$INCLUDE ..\FactuGES.inc}

uses
  uDMBase, uDataModuleConexion, uDataModuleConfiguracion,
  uMainMenuController, uNavPaneController, uPantallaPrincipal;

procedure DoAppLoadModules;
begin
  with AppFactuGES.ModuleManager do
  begin
	  LoadModule('Referencias_plugin.bpl');
//    LoadModule('TiposVenta_plugin.bpl');
    LoadModule('FormasPago_plugin.bpl');
    LoadModule('TiposIVA_plugin.bpl');
    LoadModule('Contactos_plugin.bpl');

    {$IFDEF ALMACEN}
    LoadModule('Familias_plugin.bpl');
    LoadModule('UnidadesMedida_plugin.bpl');
    LoadModule('Almacenes_plugin.bpl');
    LoadModule('Articulos_plugin.bpl');
    {$ENDIF}

    LoadModule('PresupuestosCliente_plugin.bpl');
    LoadModule('AlbaranesCliente_plugin.bpl');

    LoadModule('RecibosCliente_plugin.bpl');
    LoadModule('FacturasCliente_plugin.bpl');
    LoadModule('Comisiones_plugin.bpl');

    {$IFDEF PEDIDOSPROVEEDOR}
    LoadModule('PedidosProveedor_plugin.bpl');
    LoadModule('AlbaranesProveedor_plugin.bpl');
    {$ENDIF}

    LoadModule('RecibosProveedor_plugin.bpl');
    LoadModule('FacturasProveedor_plugin.bpl');

    LoadModule('RemesasCliente_plugin.bpl');
    LoadModule('RemesasProveedor_plugin.bpl');

    {$IFDEF ALMACEN}
    LoadModule('Inventario_plugin.bpl');
    LoadModule('HistoricoMovimientos_plugin.bpl');
    {$ENDIF}

    {$IFDEF CONTABILIDAD}
    LoadModule('Ejercicios_plugin.bpl');
    LoadModule('Contabilidad_plugin.bpl');
    {$ENDIF}

    LoadModule('GestorInformes_plugin.bpl');        
  end;
end;

procedure DoAppMainForm;
begin
  Application.CreateForm(TfPantallaPrincipal, fPantallaPrincipal);
end;

procedure Initialize;
begin
  dmConexion := TdmConexion.Create(NIL);
  dmConfiguracion := TdmConfiguracion.Create(NIL);
  dmBase := TdmBase.Create(NIL);

  AppFactuGES := TAppFactuGES.Create;
  with AppFactuGES do
  begin
    //AppSplashForm := TAppSplashForm.Create;
    DoMainFormEvent := DoAppMainForm;
    DoLoadModulesEvent := DoAppLoadModules;
  end;

  NavPaneController := TNavPaneController.Create;
  MainMenuController := TMainMenuController.Create;
end;

procedure Run;
begin
  AppFactuGES.Run;
end;

procedure Terminate;
begin
  FreeANDNIL(MainMenuController);
  FreeANDNIL(NavPaneController);

  AppFactuGES := NIL;

  FreeANDNIL(dmBase);
  FreeANDNIL(dmConfiguracion);
  FreeAndNil(dmConexion);

  Application.ProcessMessages
end;

end.
