unit frmRelatorioVendaUnt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, SimpleDS, QRCtrls, QuickRpt, ExtCtrls, StdCtrls;

type
  TfrmRelatorioVenda = class(TForm)
    sdsVenda: TSimpleDataSet;
    dtsVendaItemMD: TDataSource;
    sdsItem: TSimpleDataSet;
    QuickRep1: TQuickRep;
    DetailBand1: TQRBand;
    TitleBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRDBText1: TQRDBText;
    QRLabel2: TQRLabel;
    QRDBText2: TQRDBText;
    QRLabel3: TQRLabel;
    QRDBText3: TQRDBText;
    QRLabel4: TQRLabel;
    QRDBText4: TQRDBText;
    QRLabel5: TQRLabel;
    QRDBText5: TQRDBText;
    QRSysData1: TQRSysData;
    QRShape1: TQRShape;
    QRSubDetail1: TQRSubDetail;
    GroupHeaderBand1: TQRBand;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRLabel8: TQRLabel;
    QRLabel9: TQRLabel;
    QRLabel10: TQRLabel;
    QRShape2: TQRShape;
    GroupFooterBand1: TQRBand;
    QRDBText6: TQRDBText;
    QRDBText7: TQRDBText;
    QRDBText8: TQRDBText;
    QRDBText9: TQRDBText;
    QRDBText10: TQRDBText;
    sdsItemPED_NUM: TIntegerField;
    sdsItemPRO_COD: TIntegerField;
    sdsItemPRO_DES: TStringField;
    sdsItemITE_QTD: TSmallintField;
    sdsItemITE_VAL_UNI: TFMTBCDField;
    sdsItemITE_TOTAL: TFMTBCDField;
    QRShape3: TQRShape;
    Button1: TButton;
    QRLabel11: TQRLabel;
    QRLabel12: TQRLabel;
    procedure evFecharJanela(Sender: TObject; var Action: TCloseAction);
    procedure evAtualizaDetalhe(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure evVisualizarRelatorio(Sender: TObject);
    procedure evTotaliza(Sender: TQRCustomBand; var PrintBand: Boolean);
    procedure evApresentaTotalVenda(sender: TObject; var Value: String);
  private
    { Private declarations }
    // atributo totalizador
    TotalVenda : currency ;
  public
    { Public declarations }
  end;

var
  frmRelatorioVenda: TfrmRelatorioVenda;

implementation

uses dmVendasUnt;

{$R *.dfm}

procedure TfrmRelatorioVenda.evFecharJanela(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree ;
end;

procedure TfrmRelatorioVenda.evAtualizaDetalhe(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  // realiza o refresh no sdsItem
  sdsItem.Refresh ;
  // zera o totalizador
  TotalVenda := 0 ;
end;

procedure TfrmRelatorioVenda.evVisualizarRelatorio(Sender: TObject);
begin
  quickRep1.Preview ;
end;

procedure TfrmRelatorioVenda.evTotaliza(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  // acumula o valor total de cada item para a venda
  // corrente
  TotalVenda :=
  sdsItemITE_TOTAL.AsCurrency + TotalVenda;
end;

procedure TfrmRelatorioVenda.evApresentaTotalVenda(sender: TObject;
  var Value: String);
begin
  // formata o valor como monetario
  value := format('%m',[TotalVenda]);
end;

end.
