unit uViewDetallesAlbaranCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, ImgList, PngImageList,
  uDADataTable, ActnList, ComCtrls, ToolWin, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, cxImageComboBox, cxTextEdit, cxMaskEdit, cxCheckBox, cxCurrencyEdit,
  Grids, DBGrids, StdCtrls, ExtCtrls, cxRichEdit, ExtActns, StdActns,
  JvExStdCtrls, JvCombobox, JvColorCombo, TB2Item, SpTBXItem, TB2Dock, TB2Toolbar,
  uControllerDetallesArticulos, uBizAlbaranesCliente, cxDropDownEdit,
  cxCalendar, cxDBEdit, dxLayoutControl, cxContainer, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, uDAInterfaces, cxButtonEdit,
  uViewDetallesArticulos, Menus, cxGridCustomPopupMenu, cxGridPopupMenu, 
  uViewDetallesArticulosParaVenta, cxEditRepositoryItems, cxLookAndFeels,
  cxLookAndFeelPainters;

type
  IViewDetallesAlbaranCliente = interface(IViewDetallesArticulos)
  ['{9326E1A0-BD5E-4BE1-BB3B-6A52C3394118}']
    function GetAlbaran: IBizAlbaranCliente;
    procedure SetAlbaran(const Value: IBizAlbaranCliente);
    property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
  end;

  TfrViewDetallesAlbaranCliente = class(TfrViewDetallesArticulosParaVenta, IViewDetallesAlbaranCliente)
    N2: TMenuItem;
    Aadirartculos1: TMenuItem;
    TBXItem18: TSpTBXItem;
    cxGridViewCANTIDAD2: TcxGridDBColumn;
    procedure cxGridViewCANTIDAD2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  protected
    FAlbaran: IBizAlbaranCliente;
    function GetAlbaran: IBizAlbaranCliente;
    procedure SetAlbaran(const Value: IBizAlbaranCliente);

    procedure AnadirArticulosInterno; override;
    procedure RellenarArticulosInterno; override;
    function AnadirArticulo(pReferencia: String; TipoReferencia: TEnumReferencia): Boolean; override;

  public
    property Albaran: IBizAlbaranCliente read GetAlbaran write SetAlbaran;
  end;

implementation
{$R *.dfm}

uses uDetallesAlbaranClienteController, uViewDetallesBase;

{ TfrViewDetallesAlbaranProveedor }

function TfrViewDetallesAlbaranCliente.AnadirArticulo(pReferencia: String; TipoReferencia: TEnumReferencia): Boolean;
begin
  if (Albaran.TIPO = CTE_TIPO_ALBARAN_DEV) then
     Result := (Controller as IDetallesAlbaranClienteController).AnadirArticulo(Detalles, pReferencia, TipoReferencia, Albaran.Cliente.ID, -1)
  else
     Result := (Controller as IDetallesAlbaranClienteController).AnadirArticulo(Detalles, pReferencia, TipoReferencia, Albaran.Cliente.ID, 0);
end;

procedure TfrViewDetallesAlbaranCliente.AnadirArticulosInterno;
begin
  if (Albaran.TIPO = CTE_TIPO_ALBARAN_DEV) then
    (Controller as IDetallesAlbaranClienteController).AnadirArticulos(Detalles, Albaran.Cliente, true, -1)
  else
    (Controller as IDetallesAlbaranClienteController).AnadirArticulos(Detalles, Albaran.Cliente, true, 0);
end;

procedure TfrViewDetallesAlbaranCliente.cxGridViewCANTIDAD2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  inherited;
  (Controller as IDetallesAlbaranClienteController).ModificarCantidadColores(Detalles);
end;

function TfrViewDetallesAlbaranCliente.GetAlbaran: IBizAlbaranCliente;
begin
  Result := FAlbaran; 
end;

procedure TfrViewDetallesAlbaranCliente.RellenarArticulosInterno;
begin
  if (Albaran.TIPO = CTE_TIPO_ALBARAN_DEV) then
    (Controller as IDetallesAlbaranClienteController).AnadirArticulos(Detalles, Albaran.Cliente, False, -1)
  else
    (Controller as IDetallesAlbaranClienteController).AnadirArticulos(Detalles, Albaran.Cliente, False, 0);
end;

procedure TfrViewDetallesAlbaranCliente.SetAlbaran(const Value: IBizAlbaranCliente);
begin
  FAlbaran := Value;
end;

end.
