unit uPluginAlbaranesCliente;

interface

uses
  uModuleController, uInterfaces, uHostManager, Menus, Classes, ActnList,
  ImgList, Controls, PngImageList, uPlugins_Intf;

type
  TPluginAlbaranesCliente = class(TModuleController, IMCAlbaranesCliente)
    actAlbaranesCliente: TAction;
    ExtraImages: TPngImageList;
    LargeImages: TPngImageList;
    MainMenu: TMainMenu;
    ModuleActionList: TActionList;
    SmallImages: TPngImageList;
    Compras1: TMenuItem;
    AlbaranesdeCliente1: TMenuItem;
    actAlbaranesDevCliente: TAction;
    Ordenesdedevolucin1: TMenuItem;
    procedure actAlbaranesClienteExecute(Sender: TObject);
    procedure actAlbaranesDevClienteExecute(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure VerAlbaranes(const ID_Cliente: Integer;
      const ANombreCliente : String = '');    
  end;

implementation

{$R *.dfm}

uses
  Forms, Dialogs, SysUtils, cxControls, uAlbaranesClienteViewRegister,
  uAlbaranesClienteController, uBizAlbaranesCliente;

function GetModule : TModuleController;
begin
  Result := TPluginAlbaranesCliente.Create(NIL);
end;

exports
  GetModule name GET_MODULE_FUNC;

procedure TPluginAlbaranesCliente.actAlbaranesClienteExecute(Sender: TObject);
var
  AAlbaranesClienteController : IAlbaranesClienteController;
  AAlbaranesCliente : IBizAlbaranCliente;

begin
  AAlbaranesClienteController := TAlbaranesClienteController.Create;
  AAlbaranesCliente := (AAlbaranesClienteController.BuscarAlbaranesNormales as IBizAlbaranCliente);
  AAlbaranesClienteController.VerTodosAlbaranes(AAlbaranesCliente);
end;

procedure TPluginAlbaranesCliente.actAlbaranesDevClienteExecute(Sender: TObject);
var
  AAlbaranesClienteController : IAlbaranesClienteController;
  AAlbaranesCliente : IBizAlbaranCliente;

begin
  AAlbaranesClienteController := TAlbaranesClienteController.Create;
  AAlbaranesCliente := (AAlbaranesClienteController.BuscarAlbaranesDevolucion as IBizAlbaranCliente);
  AAlbaranesClienteController.VerTodosAlbaranesDev(AAlbaranesCliente);
end;

procedure TPluginAlbaranesCliente.VerAlbaranes(const ID_Cliente: Integer;
  const ANombreCliente : String = '');
var
  AAlbaranesClienteController : IAlbaranesClienteController;
  AAlbaranesCliente : IBizAlbaranCliente;
  AText : String;
begin
  AText := Format('Lista de albaranes del cliente %s', [ANombreCliente]);
  AAlbaranesClienteController := TAlbaranesClienteController.Create;
  try
    ShowHourglassCursor;
    try
      AAlbaranesCliente := AAlbaranesClienteController.BuscarTodos(ID_Cliente);
    finally
      HideHourglassCursor;
    end;
    AAlbaranesClienteController.VerTodosAlbaranes(AAlbaranesCliente, True, AText);
  finally
    AAlbaranesCliente := NIL;
    AAlbaranesClienteController := NIL;
  end;
end;


constructor TPluginAlbaranesCliente.Create(AOwner: TComponent);
begin
  inherited;
  ModuleName := MODULENAME_ALBARANES_CLIENTE;  
  uAlbaranesClienteViewRegister.RegisterViews;
end;

destructor TPluginAlbaranesCliente.Destroy;
begin
  uAlbaranesClienteViewRegister.UnregisterViews;
  inherited;
end;

initialization
  RegisterModuleClass(TPluginAlbaranesCliente);

finalization
  UnRegisterModuleClass(TPluginAlbaranesCliente);

end.
