unit frmRelatorioProdutoUnt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frmModeloRelatorioSimplesUnt, FMTBcd, DB, SqlExpr, StdCtrls,
  QuickRpt, QRCtrls, ExtCtrls;

type
  TfrmRelatorioProduto = class(TfrmModeloRelatorioSimples)
    SQLQuery1PRO_COD: TIntegerField;
    SQLQuery1PRO_DES: TStringField;
    SQLQuery1PRO_UNI: TStringField;
    SQLQuery1PRO_QTD_EST: TSmallintField;
    SQLQuery1PRO_VAL_VEN: TFMTBCDField;
    SQLQuery1PRO_TOTAL_ESTOQUE: TFMTBCDField;
    ColumnHeaderBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    QRLabel6: TQRLabel;
    QRDBText1: TQRDBText;
    QRDBText2: TQRDBText;
    QRDBText3: TQRDBText;
    QRDBText4: TQRDBText;
    QRDBText5: TQRDBText;
    QRDBText6: TQRDBText;
    PageHeaderBand1: TQRBand;
    QRSysData2: TQRSysData;
    PageFooterBand1: TQRBand;
    QRSysData3: TQRSysData;
    QRShape1: TQRShape;
    QRShape2: TQRShape;
    QRShape3: TQRShape;
    QRShape4: TQRShape;
    QRLabel7: TQRLabel;
    QRLabel8: TQRLabel;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    edtProdutoInicial: TEdit;
    edtProdutoFinal: TEdit;
    QRLabel9: TQRLabel;
    QRLabel10: TQRLabel;
    procedure evZerarTag(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure evIncrementarTag(Sender: TQRCustomBand;
      BandPrinted: Boolean);
    procedure evApresentarTag(sender: TObject; var Value: String);
    procedure evVisualizarRelatorio(Sender: TObject);
    procedure evAcumulaTotal(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure evApresentaTotalGeral(sender: TObject; var Value: String);
  private
    { Private declarations }
    // atributo para armazenar o total geral
    TotalGeral : Currency ;
   public
    { Public declarations }
  end;

var
  frmRelatorioProduto: TfrmRelatorioProduto;

implementation

uses dmVendasUnt;

{$R *.dfm}

procedure TfrmRelatorioProduto.evZerarTag(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  inherited;
  self.Tag := 0 ;
  // zera o total geral
   TotalGeral := 0 ;
end;

procedure TfrmRelatorioProduto.evIncrementarTag(Sender: TQRCustomBand;
  BandPrinted: Boolean);
begin
  inherited;
  self.tag := self.tag + 1 ;
end;

procedure TfrmRelatorioProduto.evApresentarTag(sender: TObject;
  var Value: String);
begin
  inherited;
  Value :=
  IntToStr(self.Tag);
end;

procedure TfrmRelatorioProduto.evVisualizarRelatorio(Sender: TObject);
begin
  inherited;
  with SQLQuery1 do begin
    //fecha a query
      close ;
   // atribui valores aos
   // paramentros
      ParamByName('VALOR_INICIAL').AsInteger :=
      StrToInt(edtProdutoInicial.Text);
      ParamByName('VALOR_FINAL').AsInteger :=
      StrToInt(edtProdutoFinal.Text);
  // abre a query
     open;
  end; // with
  // apresenta os dados filtrados
  QuickRep1.Preview;
end;

procedure TfrmRelatorioProduto.evAcumulaTotal(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  inherited;
  // acumula o total geral a cada impressao da
  // banda detalhe
  TotalGeral := TotalGeral +
  SQLQuery1PRO_TOTAL_ESTOQUE.AsCurrency ;
end;

procedure TfrmRelatorioProduto.evApresentaTotalGeral(sender: TObject;
  var Value: String);
begin
  inherited;
  // apresenta o total geral formatando
  // o valor para monetario
  value := Format('%m',[TotalGeral]);
end;

end.
