unit uconfrelRecibosEmitidos; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.StrUtils, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls; type TconfrelRecibosEmitidos = class(TForm) gb_data: TGroupBox; Label1: TLabel; dtp_inicio: TDateTimePicker; dtp_fim: TDateTimePicker; btn_viewreport: TButton; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure btn_viewreportClick(Sender: TObject); private procedure WMMoving(var Msg: TWMMoving); message WM_MOVING; { Private declarations } public { Public declarations } end; var confrelRecibosEmitidos: TconfrelRecibosEmitidos; implementation {$R *.dfm} uses urelRecibosEmitidos, udtmSystem; procedure TconfrelRecibosEmitidos.btn_viewreportClick(Sender: TObject); var sum : double; begin relRecibosEmitidos := TrelRecibosEmitidos.Create(self); if dtp_inicio.Date = dtp_fim.Date then begin relRecibosEmitidos.frlbl_datas.Caption := DateToStr(dtp_inicio.Date); end else begin relRecibosEmitidos.frlbl_datas.Caption := DateToStr(dtp_inicio.Date) + ' a ' + DateToStr(dtp_fim.Date); end; if not dtmSystem.tblRecibo.Active then begin dtmSystem.tblRecibo.Open; end; relRecibosEmitidos.qryReport.SQL.Clear; relRecibosEmitidos.qryReport.SQL.Text := 'select sys_recibos.*, case when tx_cpf = '''' then tx_cnpj when tx_cpf <> '''' then tx_cpf end as tx_documento from sys_recibos where (' + QuotedStr(FormatDateTime('mm/dd/yyyy', dtp_inicio.Date)) + ' <= CAST(DT_IMPRESSAO AS DATE)) and (' + QuotedStr(FormatDateTime('mm/dd/yyyy', dtp_fim.Date)) + ' >= CAST(DT_IMPRESSAO AS DATE))'{' and TP_CANCELADO <> ''S'' '}+' order by id_recibo'; relRecibosEmitidos.qryReport.Open; relRecibosEmitidos.qryReport.First; sum := 0; while not(relRecibosEmitidos.qryReport.Eof) do begin if relRecibosEmitidos.qryReport.FieldByName('TP_CANCELADO').AsString <> 'S' then begin sum := sum + relRecibosEmitidos.qryReport.FieldByName('vl_corrigido').AsCurrency; end; relRecibosEmitidos.qryReport.Next; end; relRecibosEmitidos.frlbl_total.Caption := 'Total: ' + CurrToStrF(sum, ffCurrency, 2, dtmSystem.CusFmt); relRecibosEmitidos.fr_recibosemitidos.PreviewModal; end; procedure TconfrelRecibosEmitidos.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; confrelRecibosEmitidos := nil; end; procedure TconfrelRecibosEmitidos.FormCreate(Sender: TObject); begin dtp_inicio.Date := Date; dtp_fim.Date := Date; end; procedure TconfrelRecibosEmitidos.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_ESCAPE then begin Key := 0; Close; end; end; procedure TconfrelRecibosEmitidos.WMMoving(var Msg: TWMMoving); var workArea: TRect; begin workArea := Screen.WorkareaRect; with Msg.DragRect^ do begin if left < workArea.left then OffsetRect(Msg.DragRect^, workArea.left - left, 0); if top < workArea.top then OffsetRect(Msg.DragRect^, 0, workArea.top - top); if Right > workArea.Right then OffsetRect(Msg.DragRect^, workArea.Right - Right, 0); if Bottom > workArea.Bottom then OffsetRect(Msg.DragRect^, 0, workArea.Bottom - Bottom); end; end; end.