unit uEditorCobrosCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, DB, uDADataTable, JvAppStorage,
  JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
  PngImageList, StdActns, ActnList, ComCtrls, TB2ExtItems, TBXExtItems,
  TBX, TB2Item, TB2Dock, TB2Toolbar, ExtCtrls, JvExControls,
  JvNavigationPane, uViewGrid, pngimage, JvComponentBase,
  uEditorGridBase,  uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
  uBizCobrosCliente, uIEditorCobrosCliente, uCobrosClienteController,
  uViewCobrosCliente, JvExComCtrls, JvStatusBar;

type

  TfEditorCobrosCliente = class(TfEditorGridBase, IEditorCobrosCliente)
    frViewCobrosCliente1: TfrViewCobrosCliente;
    procedure FormShow(Sender: TObject);
  private
    FCobros: IBizCobroCliente;
    FController : ICobrosClienteController;
  protected
    function GetCobros: IBizCobroCliente;
    procedure SetCobros(const Value: IBizCobroCliente);

    function GetController : ICobrosClienteController; virtual;
    procedure SetController (const Value : ICobrosClienteController); virtual;
    procedure NuevoInterno; override;
    procedure ModificarInterno; override;
    procedure EliminarInterno; override;
    procedure DuplicarInterno; override;
  public
    procedure PonerTitulos(const ATitulo: string = ''); override;
    property Cobros: IBizCobroCliente read GetCobros write SetCobros;
    property Controller : ICobrosClienteController read GetController write SetController;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;


implementation

uses
  uDataModuleCobrosCliente, uDataModuleUsuarios;

{$R *.dfm}

{
*************************** TfEditorCobrosCliente ***************************
}
constructor TfEditorCobrosCliente.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewCobrosCliente1; //  CreateView(TfrViewCobrosCliente) as IViewCobrosCliente;
end;

destructor TfEditorCobrosCliente.Destroy;
begin
  FCobros := NIL;
  inherited;
end;

procedure TfEditorCobrosCliente.DuplicarInterno;
var
  ACobro : IBizCobroCliente;
begin
  inherited;
  ACobro := FController.Duplicar(FCobros);
  try
    FController.Ver(ACobro);
  finally
    actRefrescar.Execute;
  end;
end;

procedure TfEditorCobrosCliente.EliminarInterno;
begin
  if (Application.MessageBox('¿Desea borrar este cobro de cliente?', 'Atención', MB_YESNO) = IDYES) then
  begin
    FController.Eliminar(Cobros);
    inherited;
  end;
end;

procedure TfEditorCobrosCliente.FormShow(Sender: TObject);
begin
  inherited;

  if not Assigned(ViewGrid) then
    raise Exception.Create('No hay ninguna vista asignada');

  if not Assigned(Cobros) then
    raise Exception.Create('No hay ningún presupuesto asignado');

  Cobros.DataTable.Active := True;
  ViewGrid.GotoFirst;
end;

function TfEditorCobrosCliente.GetController: ICobrosClienteController;
begin
  Result := FController;
end;

procedure TfEditorCobrosCliente.ModificarInterno;
begin
  inherited;
  FController.Ver(Cobros);
end;

procedure TfEditorCobrosCliente.NuevoInterno;
begin
  inherited;
  FController.Anadir(Cobros);
  FController.Ver(Cobros);
end;

function TfEditorCobrosCliente.GetCobros: IBizCobroCliente;
begin
  Result := FCobros;
end;

procedure TfEditorCobrosCliente.PonerTitulos(const ATitulo: string);
var
  FTitulo : String;
begin
  FTitulo := 'Lista de Cobros de cliente - ' + dmUsuarios.EmpresaActual.NOMBRE;
  inherited PonerTitulos(FTitulo);
end;

procedure TfEditorCobrosCliente.SetController(const Value: ICobrosClienteController);
begin
  FController := Value;
end;

procedure TfEditorCobrosCliente.SetCobros(const Value: IBizCobroCliente);
begin
  FCobros := Value;
  dsDataTable.DataTable := FCobros.DataTable;
  if Assigned(ViewGrid) then
    (ViewGrid as IViewCobrosCliente).Cobros := Cobros;
end;

end.
