unit uViewFacturaProveedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, DB, uDADataTable, uCustomView,
  uViewDatosYSeleccionCliente, uBizFacturasProveedor,
  cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit, dxLayoutControl,
  cxMemo, cxMaskEdit, cxDropDownEdit, cxCalendar, cxSpinEdit, StdCtrls, Mask,
  DBCtrls, cxGraphics, dxLayoutLookAndFeels, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, uFormasPagoController, uViewDatosYSeleccionProveedor;

type
  IViewFacturaProveedor = interface(IViewBase)
  ['{DD934441-75CC-452F-8861-684961E90BB6}']
    function GetFactura: IBizFacturaProveedor;
    procedure SetFactura(const Value: IBizFacturaProveedor);
    property Factura: IBizFacturaProveedor read GetFactura write SetFactura;
  end;

  TfrViewFacturaProveedor = class(TfrViewBase, IViewFacturaProveedor)
    DADataSource: TDADataSource;
    dxLayoutControl1Group_Root: TdxLayoutGroup;
    dxLayoutControl1: TdxLayoutControl;
    dxLayoutControl1Item1: TdxLayoutItem;
    eReferencia: TcxDBTextEdit;
    dxLayoutControl1Item2: TdxLayoutItem;
    edtFecha: TcxDBDateEdit;
    dxLayoutControl1Group1: TdxLayoutGroup;
    dxLayoutControl1Group2: TdxLayoutGroup;
    dxLayoutControl1Item5: TdxLayoutItem;
    memObservaciones: TcxDBMemo;
    dxLayoutControl1Group5: TdxLayoutGroup;
    dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
    dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
    dsFormaPago: TDADataSource;
    dxLayoutControl1Item4: TdxLayoutItem;
    cbFormaPago: TcxDBLookupComboBox;
    dxLayoutControl1Item10: TdxLayoutItem;
    bFormasPago: TButton;
    dxLayoutControl1Group3: TdxLayoutGroup;
    dxLayoutControl1Group6: TdxLayoutGroup;
    dxLayoutControl1Item3: TdxLayoutItem;
    frViewProveedorFactura: TfrViewDatosYSeleccionProveedor;
    dxLayoutControl1Item6: TdxLayoutItem;
    eReferenciaProveedor: TcxDBTextEdit;
    procedure bFormasPagoClick(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);
    procedure CustomViewCreate(Sender: TObject);
  protected
    FFactura : IBizFacturaProveedor;
    FFormasPagoController : IFormasPagoController;
    function GetFactura: IBizFacturaProveedor;
    procedure SetFactura(const Value: IBizFacturaProveedor);
  public
    property Factura: IBizFacturaProveedor read GetFactura write SetFactura;
  end;


implementation

uses
  uDataModuleContactos, schFacturasProveedorClient_Intf,
  uBizFormasPago;

{$R *.dfm}

{ TfrViewFacturaProveedor }

procedure TfrViewFacturaProveedor.bFormasPagoClick(Sender: TObject);
begin
  inherited;
  FFormasPagoController.VerTodos((dsFormaPago.DataTable) as IBizFormaPago);
end;

procedure TfrViewFacturaProveedor.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FFormasPagoController := TFormasPagoController.Create;
  frViewProveedorFactura.MsgElegirProveedor := 'Elija el proveedor al que se le realizará la factura.';
end;

procedure TfrViewFacturaProveedor.CustomViewDestroy(Sender: TObject);
begin
  inherited;
  FFormasPagoController := NIL;
end;

function TfrViewFacturaProveedor.GetFactura: IBizFacturaProveedor;
begin
  Result := FFactura;
end;

procedure TfrViewFacturaProveedor.SetFactura(const Value: IBizFacturaProveedor);
begin
  FFactura := Value;
  if Assigned(FFactura) then
  begin
    DADataSource.DataTable := FFactura.DataTable;

    dsFormaPago.DataTable := FFormasPagoController.BuscarTodos.DataTable;
    dsFormaPago.DataTable.Active := True;

    //Solo se deshabilita al insertar, luego la referencia será modificable
    eReferencia.Enabled := (FFactura.DataTable.State = dsInsert);

    if FFactura.TIPO = CTE_TIPO_ABONO then
    begin
      dxLayoutControl1Item2.Caption := 'Fecha del abono:';
      dxLayoutControl1Group1.Caption := 'Datos del abono';
    end;
  end
  else begin
    DADataSource.DataTable := NIL;
    dsFormaPago.DataTable := NIL;
    frViewProveedorFactura.Proveedor := NIL
  end;
end;

end.
