{
===============================================================================
  Copyright (©) 2007. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión:
  Versión actual: 1.0.0
  Fecha versión actual:
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit uBizOscOrders;

interface

uses
  uDAInterfaces, uDADataTable, uDBSelectionListUtils, schTiendaWebClient_Intf,
  uBizOscOrderProducts;

const
  BIZ_CLIENT_OSC_ORDER = 'Client.OSC.Order';

type
  IBizOscOrder = interface(Iosc_Orders)
  	['{A30188C2-CCC8-4107-A997-A7D470AD5BBC}']
    function EsNuevo : Boolean;

    procedure SetOrderProducts(AValue : IBizOscOrderProducts);
    function GetOrderProducts : IBizOscOrderProducts;
    property OrderProducts : IBizOscOrderProducts read GetOrderProducts write SetOrderProducts;
  end;

  TBizOscOrder = class(Tosc_OrdersDataTableRules, IBizOscOrder, ISeleccionable)
  protected
    FSeleccionableInterface : ISeleccionable;
    FOrderProducts : IBizOscOrderProducts;
    FOrderProductsLink : TDADataSource;

    procedure SetOrderProducts(AValue : IBizOscOrderProducts);
    function GetOrderProducts : IBizOscOrderProducts;

    procedure OnNewRecord(Sender: TDADataTable); override;
  public
    procedure IniciarValoresNuevo;
    function EsNuevo : Boolean;
    constructor Create(aDataTable: TDADataTable); override;
    destructor Destroy; override;

    property SeleccionableInterface : ISeleccionable 
    					read FSeleccionableInterface
    					write FSeleccionableInterface 
    					implements ISeleccionable;

    property OrderProducts : IBizOscOrderProducts read GetOrderProducts write SetOrderProducts;
  end;

implementation

{ TBizOscOrders }

uses
  SysUtils, uDataTableUtils;

function TBizOscOrder.GetOrderProducts: IBizOscOrderProducts;
begin
  Result := FOrderProducts;
end;

procedure TBizOscOrder.SetOrderProducts(AValue: IBizOscOrderProducts);
begin
  FOrderProducts := AValue;
  EnlazarMaestroDetalle(FOrderProductsLink, FOrderProducts);
end;

constructor TBizOscOrder.Create(aDataTable: TDADataTable);
begin
  inherited;
   FOrderProductsLink := TDADataSource.Create(NIL);
   FOrderProductsLink.DataTable := aDataTable;

	FSeleccionableInterface := TSeleccionable.Create(aDataTable);  
end;

destructor TBizOscOrder.Destroy;
begin
   FOrderProducts := NIL;
   FreeAndNIL(FOrderProductsLink);

  FSeleccionableInterface := NIL;
  inherited;
end;

function TBizOscOrder.EsNuevo: Boolean;
begin
  Result := (orders_id < 0);
end;

procedure TBizOscOrder.IniciarValoresNuevo;
begin
  //
end;

procedure TBizOscOrder.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  orders_id := GetRecNo; // -1, -2, -3...
  IniciarValoresNuevo;
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_OSC_ORDER, TBizOscOrder);

finalization

end.

