.dpr
library %0:s;

uses
  nMem,
  SysUtils, Classes, npqTypes, npqClass, nrwClass, nrwBaseDll, nrwBaseDllReg,
  nrwUtilApp, Variants, nUtilForm, nUtilDB, nClientDataSet_U, nUtil, DB,
  nUtilInclusao;

{.$R *.res}
type

  T%0:s = class(TnrwBaseDll)
  private
    FCabecalho: TnCabecalhoRelatorio;
    
    FCodigoEstab,
    FCodigoEmpresa: Integer;  
    
    FDataInicial,
    FDataFinal: TDateTime;
    
    FMultiplaSelecaoFilial: Boolean;
    
    procedure LinhaEmBranco;
    procedure ImprimirDescricao(_ADescricao: string);
  public
    class function Versao: String; override;
  
    procedure ImprimirInterno; override;

    procedure DoParamChange(Sender: TObject; _AParam: TnpqParamItem); override;
    procedure DoParamEnter(Sender: TObject; _AParam: TnpqParamItem); override;
    procedure DoParamExit(Sender: TObject; _AParam: TnpqParamItem); override;
    procedure DoAfterSection(Sender :TObject; Section :Integer);
  end;

{ T%0:s }

class function T%0:s.Versao: String;
begin
  // Quando vc alterar a dll obrigatóriamente deve alterar a esta versão para a versao atual de liberação.
  result := '[versao: 1.0.0.0]';
end;

procedure T%0:s.ImprimirInterno;
var
  ARegistro,
  ATotalRegistro,
  
  ixCodigoEstab,
  ixCodigoEmpresa: Integer;
begin
  if Query.isEmpty then
    Exit;
  
  FDataInicial := StrToDateDef(RepParam('pDataInicial'), 0);
  FDataFinal := StrToDateDef(RepParam('pDataFinal'), 0);
  FMultiplaSelecaoFilial := (StrToIntDef(RepParam('pCodigoEstab'), 0) = 0);

  if FDataInicial > FDataFinal then
    raise Exception.Create('A data inicial deve ser inferior a data final.');  
  
  ixCodigoEstab := Query.FieldByName('CODIGOESTAB').Index;
  ixCodigoEmpresa := Query.FieldByName('CODIGOEMPRESA').Index;
     
  try
    FCabecalho := TnCabecalhoRelatorio.Create(Report,
                                              False, False, False, False, False,
                                              varArrayOf([D0, D0]), -1, 1, 1,
                                              Trim(RepParam('pCodigoEstab')));
    Report.OnAfterSection := DoAfterSection;
    
    
  
    ARegistro := 0;
    ATotalRegistro := Query.RecordCount;
  
    Query.First;
  
    while not Query.Eof do
    begin
      FCodigoEstab := Query.Fields[ixCodigoEstab].AsInteger;
      FCodigoEmpresa := Query.Fields[ixCodigoEmpresa].AsInteger;
      
      FCabecalho.CodigoEmpresa := FCodigoEmpresa;
      
      
       
      inc(ARegistro);
      Report.CSLShowProgress(ARegistro, ATotalRegistro);
      Query.Next;          
    end;
    
  finally
    FreeAndNil(FCabecalho);
    Report.OnAfterSection := nil;
  end;
  
end;

procedure T%0:s.DoParamChange(Sender: TObject; _AParam: TnpqParamItem); 
begin
  { Exemplo:
  if CompareText(_AParam.Alias, 'pParametro') = 0 then
  begin
    ...
  end;}
end;

procedure T%0:s.DoParamEnter(Sender: TObject; _AParam: TnpqParamItem); 
begin

end;

procedure T%0:s.DoParamExit(Sender: TObject; _AParam: TnpqParamItem); 
begin

end;

procedure T%0:s.DoAfterSection(Sender: TObject;
  Section: Integer);
begin
  if Section = 1 then
  begin
    FCabecalho.ImpressaoCabecalho;
  end;  
end;

procedure T%0:s.LinhaEmBranco;
begin
  RepParam('RTexto', '');
  if Report.DelphiCanPrintSection(D2) then
    Report.RepPrintSection(D2);
end;

procedure T%0:s.ImprimirDescricao(_ADescricao: string);
begin
  RepParam('RTexto', _ADescricao);
  Report.RepPrintSection(D2);
end;

begin
  FClassDll := T%0:s;
end.
