unit uBizAsientosServer;

interface

uses
  uDAInterfaces, uDADelta, uDABusinessProcessor,
  schContabilidadServer_Intf;

const
  BIZ_SERVER_ASIENTOS = 'Server.Asientos';

type
  TBizAsientosServer = class(TAsientosBusinessProcessorRules)
  protected
    procedure BeforeProcessDelta(Sender: TDABusinessProcessor; const aDelta: IDADelta); override;
  end;

implementation

uses
  Variants, uDAClasses, uBusinessUtils, uROClasses,  uDataModuleServer,
  SysUtils, uROServer, FactuGES_Intf;

{ TBizAsientosServer }

procedure TBizAsientosServer.BeforeProcessDelta(Sender: TDABusinessProcessor; const aDelta: IDADelta);
var
  AContabilidadService : IsrvContabilidad;
  Intf : IInterface;
  AClientID : TGUID;
begin
  case Sender.CurrentChange.ChangeType of
    ctInsert, ctUpdate: begin
      //Si el orden del asiento no ha sido asignado le asignamos uno nosotros
      if (ORDENIsNull) or (ORDEN = 0) then
      begin
        CreateGUID(AClientID);

        GetClassFactory('srvContabilidad').CreateInstance(AClientID, Intf);
        AContabilidadService := Intf as IsrvContabilidad;
        ORDEN := AContabilidadService.DarNumOrdenAsiento;
      end;
    end;
  end;
end;

initialization
  RegisterBusinessProcessorRules(BIZ_SERVER_ASIENTOS, TBizAsientosServer);

end.
