unit urelBordero; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, RLReport, RLFilters, RLPDFFilter, Data.DB, ZAbstractRODataset, ZAbstractDataset, ZDataset; type TrelBordero = class(TForm) frBordero: TRLReport; frbnd_header: TRLBand; frbnd_footer: TRLBand; frpnl_logo: TRLPanel; frdbimg_logo: TRLDBImage; frfilterpdf: TRLPDFFilter; dtsEmpresa: TDataSource; zqryRel: TZQuery; dtsQry: TDataSource; zqryRelNOME: TWideStringField; zqryRelCODIGO: TWideStringField; zqryRelPRODUTO: TWideStringField; zqryRelVALOR: TFloatField; zqryRelID_DEVEDOR: TIntegerField; frlbl_titulorel: TRLLabel; frbnd_dados: TRLBand; frdblbl_data: TRLDBText; frdblbl_titulo: TRLDBText; frdblbl_valor: TRLDBText; frbnd_footerrel: TRLBand; frdbresult_sumvalor: TRLDBResult; frdblbl_codigo: TRLDBText; RLSystemInfo2: TRLSystemInfo; RLSystemInfo1: TRLSystemInfo; frlbl_empresanome: TRLLabel; zqryRelDATA_VENCIMENTO: TDateTimeField; RLDBText1: TRLDBText; frbnd_columnheader: TRLBand; RLLabel2: TRLLabel; RLLabel3: TRLLabel; RLLabel4: TRLLabel; RLLabel5: TRLLabel; RLLabel6: TRLLabel; RLLabel7: TRLLabel; RLDBText2: TRLDBText; zqryRelTX_DOCUMENTO: TWideStringField; zqryRelDATA_ENTRADA: TDateTimeField; frdblbl_usuario: TRLDBText; procedure frBorderoBeforePrint(Sender: TObject; var PrintIt: Boolean); procedure frBorderoAfterPrint(Sender: TObject); procedure frdblbl_usuarioBeforePrint(Sender: TObject; var AText: string; var PrintIt: Boolean); private procedure SalvarRelPDF; { Private declarations } public { Public declarations } end; var relBordero: TrelBordero; meses: array [1 .. 12] of string = ( 'JANEIRO', 'FEVEREIRO', 'MARCO', 'ABRIL', 'MAIO', 'JUNHO', 'JULHO', 'AGOSTO', 'SETEMBRO', 'OUTUBRO', 'NOVEMBRO', 'DEZEMBRO' ); implementation {$R *.dfm} uses udtmSystem; procedure TrelBordero.frBorderoAfterPrint(Sender: TObject); begin SalvarRelPDF; end; procedure TrelBordero.frBorderoBeforePrint(Sender: TObject; var PrintIt: Boolean); begin if not dtsEmpresa.DataSet.Active then begin dtsEmpresa.DataSet.Open; end; if not dtmSystem.tblCHGEmpresa.Active then begin dtmSystem.tblCHGEmpresa.Open; end; if frdbimg_logo.Picture.Height > frdbimg_logo.Picture.Width then begin frdbimg_logo.Height := 170; frdbimg_logo.Width := 133; end; if frdbimg_logo.Picture.Height < frdbimg_logo.Picture.Width then begin frdbimg_logo.Height := 133; frdbimg_logo.Width := 170; end; if frdbimg_logo.Picture.Height = frdbimg_logo.Picture.Width then begin frdbimg_logo.Height := 133; frdbimg_logo.Width := 133; end; dtmSystem.tblCHGEmpresa.Locate('ID_EMPRESA', dtmSystem.id_empimport, []); frlbl_empresanome.Caption := UpperCase(dtmSystem.tblCHGEmpresaTX_NOME.AsString); end; procedure TrelBordero.frdblbl_usuarioBeforePrint(Sender: TObject; var AText: string; var PrintIt: Boolean); begin if not dtmSystem.tblUsuariosConsulta.Active then begin dtmSystem.tblUsuariosConsulta.Open; end; dtmSystem.tblUsuariosConsulta.Locate('ID_USUARIO', dtmSystem.id_usuario,[]); frdblbl_usuario.Caption := dtmSystem.tblUsuariosConsultaTX_NOME.AsString; end; procedure TrelBordero.SalvarRelPDF; var path, file_name: string; Fmt: TFormatSettings; i: Integer; begin Fmt := TFormatSettings.Create; for i := 0 to High(meses) do begin Fmt.LongMonthNames[i] := meses[i]; end; // path := ExtractFilePath(Application.ExeName) + 'RELATORIOS'; path := dtmSystem.path_executavel + '\RELATORIOS'; if not DirectoryExists(path) then begin ForceDirectories(path); end; path := path + '\ENTRADA'; if not DirectoryExists(path) then begin ForceDirectories(path); end; path := path + '\' + dtmSystem.tblCHGEmpresaTX_NOME.AsString; if not DirectoryExists(path) then begin ForceDirectories(path); end; path := TrimRight(path); path := path + '\' + FormatDateTime('YYYY', Date); if not DirectoryExists(path) then begin ForceDirectories(path); end; path := path + '\' + FormatDateTime('mmmm', Date, Fmt); if not DirectoryExists(path) then begin ForceDirectories(path); end; path := path + '\' + FormatDateTime('dd', Date); if not DirectoryExists(path) then begin ForceDirectories(path); end; file_name := path + '\RELATORIO_ENTRADA-' + FormatDateTime('HH-mm', Time) + '.pdf'; frfilterpdf.FileName := file_name; frBordero.SaveToFile(file_name); end; end.