unit ufrmCentralBoletos; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.StrUtils, System.DateUtils, System.UITypes, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, umstMaster, Vcl.ComCtrls, Vcl.StdCtrls, Data.DB, Datasnap.DBClient, Vcl.Grids, Vcl.DBGrids, Vcl.Buttons, System.JSON, MidasLib, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent, IdComponent, IdGlobal, IdTCPConnection, IdTCPClient, IdHTTP, REST.Response.Adapter, rDBComponents, Vcl.Mask, Vcl.DBCtrls, Vcl.Menus, IdCoder, IdCoder3to4, IdCoderMIME, ZAbstractRODataset, ZDataset, Vcl.ExtCtrls; type TStringArray = array of string; TfrmCentralBoletos = class(TmstMaster) dtsBoletos: TDataSource; tblBoletos: TClientDataSet; IdHTTP: TIdHTTP; IdSSLHandler: TIdSSLIOHandlerSocketOpenSSL; tblDesc1: TClientDataSet; dtsDesc1: TDataSource; tblDesc2: TClientDataSet; dtsDesc2: TDataSource; tblDesc3: TClientDataSet; dtsDesc3: TDataSource; tblMulta: TClientDataSet; dtsMulta: TDataSource; tblMora: TClientDataSet; dtsMora: TDataSource; tblBoletosnossoNumero: TStringField; tblBoletosseuNumero: TStringField; tblBoletoscnpjCpfSacado: TStringField; tblBoletosnomeSacado: TStringField; tblBoletoscodigoBaixa: TStringField; tblBoletossituacao: TStringField; tblBoletosdataPagtoBaixa: TDateField; tblBoletosdataVencimento: TDateField; tblBoletosvalorNominal: TCurrencyField; tblBoletosvalorTotalRecebimento: TCurrencyField; tblBoletostelefone: TStringField; tblBoletosemail: TStringField; tblBoletosdataEmissao: TDateField; tblBoletosdataLimite: TDateField; tblBoletoslinhaDigitavel: TStringField; tblBoletosvalorJuros: TCurrencyField; tblBoletosvalorMulta: TCurrencyField; tblBoletosdesconto1: TBlobField; tblBoletosdesconto2: TBlobField; tblBoletosdesconto3: TBlobField; tblBoletosmulta: TBlobField; tblBoletosmora: TBlobField; tblBoletosvalorAbatimento: TCurrencyField; tblDesc1codigo: TStringField; tblDesc1taxa: TFloatField; tblDesc1valor: TCurrencyField; tblDesc2codigo: TStringField; tblDesc2taxa: TFloatField; tblDesc2valor: TCurrencyField; tblDesc3codigo: TStringField; tblDesc3taxa: TFloatField; tblDesc3valor: TCurrencyField; tblMultacodigo: TStringField; tblMultataxa: TFloatField; tblMultavalor: TCurrencyField; tblMultadata: TDateField; tblMoracodigo: TStringField; tblMorataxa: TFloatField; tblMoravalor: TCurrencyField; tblMoradata: TDateField; pcBoletos: TPageControl; tsPesquisa: TTabSheet; gb_searchfilter: TGroupBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; SpeedButton1: TSpeedButton; cb_filtrosituacao: TComboBox; cb_filtrotipodata: TComboBox; dt_inicio: TDateTimePicker; dt_fim: TDateTimePicker; cb_filtroordem: TComboBox; dbgrd_boletos: TDBGrid; gb_desc1: TGroupBox; Label6: TLabel; Label7: TLabel; Label8: TLabel; DBEdit1: TDBEdit; DBEdit2: TDBEdit; DBEdit3: TDBEdit; gb_desc2: TGroupBox; Label9: TLabel; Label10: TLabel; Label11: TLabel; DBEdit4: TDBEdit; DBEdit5: TDBEdit; DBEdit6: TDBEdit; gb_desc3: TGroupBox; Label12: TLabel; Label13: TLabel; Label14: TLabel; DBEdit7: TDBEdit; DBEdit8: TDBEdit; DBEdit9: TDBEdit; gb_multa: TGroupBox; Label15: TLabel; Label16: TLabel; Label17: TLabel; Label18: TLabel; DBEdit10: TDBEdit; DBEdit11: TDBEdit; DBEdit12: TDBEdit; rdbdt_entrada: TrDBDateTimePicker; gb_mora: TGroupBox; Label19: TLabel; Label20: TLabel; Label21: TLabel; Label22: TLabel; DBEdit13: TDBEdit; DBEdit14: TDBEdit; DBEdit15: TDBEdit; rDBDateTimePicker1: TrDBDateTimePicker; tsGeraBoleto: TTabSheet; pum_download: TPopupMenu; mnuDownload: TMenuItem; SaveDialog: TSaveDialog; IdDecoderMIME: TIdDecoderMIME; pcGeraBoletos: TPageControl; tsGeraUm: TTabSheet; tsGeraAuto: TTabSheet; zroqryBolUnico: TZReadOnlyQuery; dtsBolUnico: TDataSource; MainMenu1: TMainMenu; mnuCadastro: TMenuItem; mnhGrupoBoletos: TMenuItem; zroqryBolUnicoID_DEVEDOR: TIntegerField; zroqryBolUnicoTX_NOME: TWideStringField; zroqryBolUnicoTX_DOCUMENTO: TWideStringField; zroqryBolUnicoTX_PRODUTO: TWideStringField; zroqryBolUnicoVL_TITULO: TFloatField; zroqryBolUnicoVL_CORRIGIDO: TFloatField; zroqryBolUnicoDT_VENCIMENTO: TDateTimeField; zroqryBolUnicoID_EMPRESA: TIntegerField; zroqryEmails: TZReadOnlyQuery; zroqryEmailsTX_EMAIL: TWideStringField; dtsEmails: TDataSource; zroqryEmailsID_EMAIL: TIntegerField; zroqryEmailsID_DEVEDOR: TIntegerField; zroqryEmailsID_ULTIMO_USUARIO: TIntegerField; zroqryEmailsDT_HORA_ULTIMA_ATT: TDateTimeField; zroqryTelefones: TZReadOnlyQuery; dtsTelefones: TDataSource; zroqryTelefonesNR_DDD: TWideStringField; zroqryTelefonesNR_NUMERO: TWideStringField; zroqryTelefonesTP_ATIVO: TWideStringField; zroqryTelefonesTP_TIPOTEL: TWideStringField; zroqryTelefonesTX_DESC: TWideStringField; zroqryTelefonesTP_SMS: TWideStringField; zroqryTelefonesID_TELEFONE: TIntegerField; zroqryTelefonesID_DEVEDOR: TIntegerField; zroqryTelefonesTX_OBS: TWideMemoField; zroqryTelefonesID_ULTIMO_USUARIO: TIntegerField; zroqryTelefonesDT_HORA_ULTIMA_ATT: TDateTimeField; zroqryEnderecos: TZReadOnlyQuery; dtsEnderecos: TDataSource; zroqryEnderecosID_ENDERECO: TIntegerField; zroqryEnderecosID_DEVEDOR: TIntegerField; zroqryEnderecosTP_ENDERECO: TWideStringField; zroqryEnderecosTP_ATIVO: TWideStringField; zroqryEnderecosTX_LOGRADOURO: TWideStringField; zroqryEnderecosTX_BAIRRO: TWideStringField; zroqryEnderecosID_CIDADE: TIntegerField; zroqryEnderecosID_ESTADO: TIntegerField; zroqryEnderecosTX_CEP: TWideStringField; zroqryEnderecosTX_COMPLEMENTO: TWideStringField; zroqryEnderecosNR_NUMERO: TFloatField; zroqryEnderecosTP_REFERENCIA: TWideStringField; zroqryEnderecosID_HIGIENIZADORA: TIntegerField; zroqryEnderecosTP_CONFIRMADO: TWideStringField; zroqryEnderecosID_ULTIMO_USUARIO: TIntegerField; pum_incldel: TPopupMenu; mnuIncluir: TMenuItem; mnuRemover: TMenuItem; N1: TMenuItem; pcPesquisaGerar: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; dbgrd_bolunico: TDBGrid; dbgrd_emailsbolunico: TDBGrid; DBGrid1: TDBGrid; DBGrid2: TDBGrid; GroupBox1: TGroupBox; Label23: TLabel; Label24: TLabel; Label25: TLabel; SpeedButton2: TSpeedButton; dblucb_filtrobolunico: TDBLookupComboBox; dtp_vencinbolunico: TDateTimePicker; dtp_vencoutbolunico: TDateTimePicker; edt_bairrobolunico: TEdit; edt_cepbolunico: TEdit; edt_cidadebolunico: TEdit; edt_compbolunico: TEdit; edt_dddbolunico: TEdit; edt_docbolunico: TEdit; edt_emailbolunico: TEdit; edt_endbolunico: TEdit; edt_endnumbolunico: TEdit; edt_estadobolunico: TEdit; edt_nomebolunico: TEdit; edt_telbolunico: TEdit; Label26: TLabel; Label27: TLabel; Label28: TLabel; Label29: TLabel; Label30: TLabel; Label31: TLabel; Label32: TLabel; lbl_dddbolunico: TLabel; lbl_docbolunico: TLabel; lbl_emailbolunico: TLabel; lbl_nomebolunico: TLabel; lbl_telbolunico: TLabel; dt_vencbolunico: TDateTimePicker; Panel1: TPanel; Label33: TLabel; GroupBox2: TGroupBox; cb_desc1: TComboBox; Label34: TLabel; edt_taxa1bol: TEdit; Label35: TLabel; edt_val1bol: TEdit; Label36: TLabel; dtp_desc1: TDateTimePicker; GroupBox3: TGroupBox; Label37: TLabel; Label38: TLabel; Label39: TLabel; cb_desc2: TComboBox; edt_taxa2bol: TEdit; edt_val2bol: TEdit; dtp_desc2: TDateTimePicker; GroupBox4: TGroupBox; Label40: TLabel; Label41: TLabel; Label42: TLabel; cb_desc3: TComboBox; edt_taxa3bol: TEdit; edt_val3bol: TEdit; dtp_desc3: TDateTimePicker; Label43: TLabel; edt_valorboleto: TEdit; Label44: TLabel; edt_abatimentobol: TEdit; GroupBox5: TGroupBox; Label45: TLabel; Label46: TLabel; cb_multabol: TComboBox; edt_taxamultabol: TEdit; edt_vlmultabol: TEdit; GroupBox6: TGroupBox; Label47: TLabel; Label48: TLabel; cb_morabol: TComboBox; edt_taxamorabol: TEdit; edt_vlmorabol: TEdit; GroupBox7: TGroupBox; Label49: TLabel; edt_linha1bol: TEdit; edt_linha2bol: TEdit; edt_linha3bol: TEdit; edt_linha4bol: TEdit; Label50: TLabel; Label51: TLabel; Label52: TLabel; btn_gerarbolunico: TButton; Label53: TLabel; Label54: TLabel; cb_dtlimitebol: TComboBox; cb_agendabol: TComboBox; zroqryBolUnicoID_TITULO: TIntegerField; zroqryEnderecosTX_ESTADO: TStringField; zroqryEnderecosTX_CIDADE: TStringField; Label55: TLabel; dtp_multa: TDateTimePicker; Label56: TLabel; dtp_mora: TDateTimePicker; Label57: TLabel; edt_linha5bol: TEdit; N2: TMenuItem; mnuBaixarInter: TMenuItem; mnuAcertos: TMenuItem; mnuProtestado: TMenuItem; mnuDevolucao: TMenuItem; mnuProtestoAposBaixa: TMenuItem; mnuPagoDireto: TMenuItem; mnuSubstituicao: TMenuItem; mnuFalta: TMenuItem; mnuAPedidoCliente: TMenuItem; mnuBaixarCob: TMenuItem; rotblRepasseFase: TZReadOnlyQuery; rotblRepasseFaseID_FASE: TIntegerField; rotblRepasseFasePR_PRINCIPAL: TFloatField; rotblRepasseFasePR_JUROS: TFloatField; rotblRepasseFasePR_MULTA: TFloatField; rotblRepasseFasePR_ENCARGOS: TFloatField; rotblRepasseFasePR_CORRIGIDO: TFloatField; rotblRepasseFaseMIN_ATRASO: TIntegerField; rotblRepasseFaseMAX_ATRASO: TIntegerField; rotblRepasseFaseID_REPASSE: TIntegerField; rotblRepasseFaseID_ULTIMO_USUARIO: TIntegerField; rotblRepasseFaseDT_HORA_ULTIMA_ATT: TDateTimeField; procedure FormCreate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure dtsBoletosDataChange(Sender: TObject; Field: TField); procedure dbgrd_boletosDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); procedure mnuDownloadClick(Sender: TObject); procedure dbgrd_boletosMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure mnhGrupoBoletosClick(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure dbgrd_bolunicoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure mnuIncluirClick(Sender: TObject); procedure edt_valorboletoKeyPress(Sender: TObject; var Key: Char); procedure edt_abatimentobolKeyPress(Sender: TObject; var Key: Char); procedure btn_gerarbolunicoClick(Sender: TObject); procedure mnuAcertosClick(Sender: TObject); procedure mnuProtestadoClick(Sender: TObject); procedure mnuDevolucaoClick(Sender: TObject); procedure mnuProtestoAposBaixaClick(Sender: TObject); procedure mnuPagoDiretoClick(Sender: TObject); procedure mnuSubstituicaoClick(Sender: TObject); procedure mnuFaltaClick(Sender: TObject); procedure mnuAPedidoClienteClick(Sender: TObject); procedure mnuBaixarCobClick(Sender: TObject); private opcoes_situacao, opcoes_datatipo, opcoes_ordem: TStringList; JSONBoletoUnico: TJSONObject; vl_bol: currency; function RequestJSON(URL: String; Body: TStringStream = nil): TJSONObject; function RequestBase64(URL: String; Body: TStringStream = nil): string; function SendJSON(URL: String; JSON: TJSONObject): string; function ValidadorPagador: TStringArray; function ValidadorDescontos: TStringArray; function ValidadorMultaMora: TStringArray; procedure JsonToDataset2(aDataset: TDataSet; aJSON: string); { Private declarations } public { Public declarations } end; var frmCentralBoletos: TfrmCentralBoletos; implementation {$R *.dfm} uses udtmSystem, ufrmGrupoBoletoEmpresas; var jsonBoletoBase: string = '{' + ' "pagador":{' + ' "cnpjCpf":"",' + ' "nome":"",' + ' "cep":"",' + ' "endereco":"",' + ' "numero":"",' + ' "complemento":"",' + ' "bairro":"",' + ' "cidade":"",' + ' "uf":"",' + ' "email":"",' + ' "ddd":"",' + ' "telefone":"",' + ' "tipoPessoa":""' + ' },' + ' "dataEmissao":"",' + ' "seuNumero":"",' + ' "dataLimite":"",' + ' "dataVencimento":"",' + ' "mensagem":{' + ' "linha1":"",' + ' "linha2":"",' + ' "linha3":"",' + ' "linha4":"",' + ' "linha5":""' + ' },' + ' "desconto1":{' + ' "codigoDesconto":"",' + ' "taxa":0,' + ' "valor":0,' + ' "data":""' + ' },' + ' "desconto2":{' + ' "codigoDesconto":"",' + ' "taxa":0,' + ' "valor":0,' + ' "data":""' + ' },' + ' "desconto3":{' + ' "codigoDesconto":"",' + ' "taxa":0,' + ' "valor":0,' + ' "data":""' + ' },' + ' "valorNominal":0,' + ' "valorAbatimento":0,' + ' "multa":{' + ' "codigoMulta":"",' + ' "valor":0,' + ' "taxa":0,' + ' "data":""' + ' },' + ' "mora":{' + ' "codigoMora":"",' + ' "valor":0,' + ' "taxa":0,' + ' "data":""' + ' },' + ' "cnpjCPFBeneficiario":"",' + ' "numDiasAgenda":""' + '}'; procedure TfrmCentralBoletos.btn_gerarbolunicoClick(Sender: TObject); var pagador, mensagem, desc1, desc2, desc3, multa, mora, resposta: TJSONObject; JSONPair: TJSONPair; i: Integer; resp: string; begin inherited; if MessageDlg ('Por favor verifique se as datas para Multa e Mora estão preenchidas corretamente.' + ' Esses valor não são calculados automaticamente.' + ' Deseja continuar?', mtWarning, [mbYes, mbNo], 0) = mrNo then begin abort; end; if ValidadorPagador[0] = 'False' then begin MessageDlg(ValidadorPagador[1], mtError, [mbOK], 0); abort; end; if ValidadorDescontos[0] = 'False' then begin MessageDlg(ValidadorDescontos[1], mtError, [mbOK], 0); abort; end; if ValidadorMultaMora[0] = 'False' then begin MessageDlg(ValidadorMultaMora[1], mtError, [mbOK], 0); abort; end; with dtmSystem do begin tblBoletos.Append; tblBoletosNR_NOSSO_NUMERO.AsString := inttostr(dtmSystem.seqBoletos.GetCurrentValue + 1).PadLeft(15, '0'); tblBoletosDT_EMISSAO.AsDateTime := Date; tblBoletosVL_NOMINAL.AsCurrency := StrToCurr(edt_valorboleto.Text); if edt_abatimentobol.Text <> '' then begin tblBoletosVL_ABATIMENTO.AsCurrency := StrToCurr(edt_abatimentobol.Text); end else begin tblBoletosVL_ABATIMENTO.AsCurrency := 0; end; tblBoletosDT_VENCIMENTO.AsDateTime := dt_vencbolunico.Date; tblBoletosID_GRUPO.AsInteger := tblGrupoBoletosID_GRUPO.AsInteger; tblBoletos.Post; for i := 0 to dbgrd_bolunico.SelectedRows.Count - 1 do begin zroqryBolUnico.GotoBookmark (pointer(dbgrd_bolunico.SelectedRows.Items[i])); tblBoletoTitulos.Append; tblBoletoTitulosID_DEVEDOR.AsInteger := zroqryBolUnicoID_DEVEDOR.AsInteger; tblBoletoTitulosID_TITULO.AsInteger := zroqryBolUnicoID_TITULO.AsInteger; tblBoletoTitulosID_BOLETO.AsInteger := tblBoletosID.AsInteger; tblBoletoTitulos.Post; end; end; try JSONBoletoUnico := TJSONObject.ParseJSONValue(jsonBoletoBase) as TJSONObject; except end; JSONPair := JSONBoletoUnico.Get('seuNumero'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create (dtmSystem.tblBoletosNR_NOSSO_NUMERO.AsString); JSONPair := JSONBoletoUnico.Get('cnpjCPFBeneficiario'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create (StringReplace(StringReplace(StringReplace(dtmSystem.tblEmpresaTX_CNPJ. AsString, '.', '', [rfReplaceAll]), '-', '', [rfReplaceAll]), '/', '', [rfReplaceAll])); JSONPair := JSONBoletoUnico.Get('valorNominal'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create (dtmSystem.tblBoletosVL_NOMINAL.AsString); JSONPair := JSONBoletoUnico.Get('valorAbatimento'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create (dtmSystem.tblBoletosVL_ABATIMENTO.AsString); JSONPair := JSONBoletoUnico.Get('dataEmissao'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', Date)); JSONPair := JSONBoletoUnico.Get('dataVencimento'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtmSystem.tblBoletosDT_VENCIMENTO.AsDateTime)); JSONPair := JSONBoletoUnico.Get('numDiasAgenda'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_agendabol.Text); JSONPair := JSONBoletoUnico.Get('dataLimite'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_dtlimitebol.Text); pagador := JSONBoletoUnico.Values['pagador'] as TJSONObject; JSONPair := pagador.Get('cnpjCpf'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_docbolunico.Text); JSONPair := pagador.Get('tipoPessoa'); JSONPair.JsonValue.Free; if length(edt_docbolunico.Text) = 11 then begin JSONPair.JsonValue := TJSONString.create('FISICA'); end else begin JSONPair.JsonValue := TJSONString.create('JURIDICA'); end; JSONPair := pagador.Get('nome'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_nomebolunico.Text); JSONPair := pagador.Get('endereco'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_endbolunico.Text); JSONPair := pagador.Get('numero'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_endnumbolunico.Text); JSONPair := pagador.Get('complemento'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_compbolunico.Text); JSONPair := pagador.Get('bairro'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_bairrobolunico.Text); JSONPair := pagador.Get('cidade'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_cidadebolunico.Text); JSONPair := pagador.Get('uf'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_estadobolunico.Text); JSONPair := pagador.Get('cep'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_cepbolunico.Text); JSONPair := pagador.Get('email'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_emailbolunico.Text); JSONPair := pagador.Get('ddd'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_dddbolunico.Text); JSONPair := pagador.Get('telefone'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_telbolunico.Text); mensagem := JSONBoletoUnico.Values['mensagem'] as TJSONObject; JSONPair := mensagem.Get('linha1'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_linha1bol.Text); JSONPair := mensagem.Get('linha2'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_linha2bol.Text); JSONPair := mensagem.Get('linha3'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_linha3bol.Text); JSONPair := mensagem.Get('linha4'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_linha4bol.Text); JSONPair := mensagem.Get('linha5'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(edt_linha5bol.Text); desc1 := JSONBoletoUnico.Values['desconto1'] as TJSONObject; JSONPair := desc1.Get('codigoDesconto'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_desc1.Text); JSONPair := desc1.Get('data'); JSONPair.JsonValue.Free; if cb_desc1.ItemIndex = 0 then begin JSONPair.JsonValue := TJSONString.create(''); end else begin JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtp_desc1.Date)); end; JSONPair := desc1.Get('taxa'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_taxa1bol.Text); JSONPair := desc1.Get('valor'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_val1bol.Text); desc2 := JSONBoletoUnico.Values['desconto2'] as TJSONObject; JSONPair := desc2.Get('codigoDesconto'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_desc2.Text); JSONPair := desc2.Get('data'); JSONPair.JsonValue.Free; if cb_desc2.ItemIndex = 0 then begin JSONPair.JsonValue := TJSONString.create(''); end else begin JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtp_desc2.Date)); end; JSONPair := desc2.Get('taxa'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_taxa2bol.Text); JSONPair := desc2.Get('valor'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_val2bol.Text); desc3 := JSONBoletoUnico.Values['desconto3'] as TJSONObject; JSONPair := desc3.Get('codigoDesconto'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_desc3.Text); JSONPair := desc3.Get('data'); JSONPair.JsonValue.Free; if cb_desc3.ItemIndex = 0 then begin JSONPair.JsonValue := TJSONString.create(''); end else begin JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtp_desc3.Date)); end; JSONPair := desc3.Get('taxa'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_taxa3bol.Text); JSONPair := desc3.Get('valor'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_val3bol.Text); multa := JSONBoletoUnico.Values['multa'] as TJSONObject; JSONPair := multa.Get('codigoMulta'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_multabol.Text); JSONPair := multa.Get('data'); JSONPair.JsonValue.Free; if cb_multabol.ItemIndex = 0 then begin JSONPair.JsonValue := TJSONString.create(''); end else begin JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtp_multa.Date)); end; JSONPair := multa.Get('taxa'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_taxamultabol.Text); JSONPair := multa.Get('valor'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_vlmultabol.Text); mora := JSONBoletoUnico.Values['mora'] as TJSONObject; JSONPair := mora.Get('codigoMora'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONString.create(cb_morabol.Text); JSONPair := mora.Get('data'); JSONPair.JsonValue.Free; if cb_morabol.ItemIndex = 2 then begin JSONPair.JsonValue := TJSONString.create(''); end else begin JSONPair.JsonValue := TJSONString.create(FormatDateTime('yyyy-mm-dd', dtp_mora.Date)); end; JSONPair := mora.Get('taxa'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_taxamorabol.Text); JSONPair := mora.Get('valor'); JSONPair.JsonValue.Free; JSONPair.JsonValue := TJSONNumber.create(edt_vlmorabol.Text); resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos', JSONBoletoUnico); if resp = 'Error' then begin while dtmSystem.tblBoletoTitulos.Locate('ID_BOLETO', dtmSystem.tblBoletosID.AsInteger, []) do begin dtmSystem.tblBoletoTitulos.Delete; end; dtmSystem.tblBoletos.Delete; dtmSystem.seqBoletos.BlockSize := -1; dtmSystem.seqBoletos.GetNextValue; dtmSystem.seqBoletos.BlockSize := 1; end else begin resposta := TJSONObject.ParseJSONValue(resp) as TJSONObject; dtmSystem.tblBoletos.Edit; dtmSystem.tblBoletosCD_COD_BARRAS.AsString := resposta.Values['codigoBarras'].Value; dtmSystem.tblBoletosCD_COD_BARRAS.AsString := resposta.Values['linhaDigitavel'].Value; dtmSystem.tblBoletos.Post; Showmessage('Boleto de Nº ' + dtmSystem.tblBoletosNR_NOSSO_NUMERO.AsString + ' gerado com sucesso!'#13#10 + ' Aguarde aproximadamente por 5 minutos para poder consultá-lo.'); end; end; procedure TfrmCentralBoletos.dbgrd_boletosDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin case AnsiIndexStr(tblBoletossituacao.AsString, ['BAIXADO', 'PAGO']) of 0: dbgrd_boletos.Canvas.Brush.Color := $7AA0FF; 1: dbgrd_boletos.Canvas.Brush.Color := $FFF8F0; end; dbgrd_boletos.DefaultDrawColumnCell(Rect, DataCol, Column, State); end; procedure TfrmCentralBoletos.dbgrd_boletosMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Pt: TPoint; Coord: TGridCoord; begin inherited; Pt := dbgrd_boletos.ScreenToClient(Mouse.CursorPos); Coord := dbgrd_boletos.MouseCoord(Pt.X, Pt.Y); if (Coord.Y > 0) and not(tblBoletos.IsEmpty) and (Button = mbRight) then begin pum_download.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y); end; end; procedure TfrmCentralBoletos.dbgrd_bolunicoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Pt: TPoint; Coord: TGridCoord; begin inherited; Pt := dbgrd_bolunico.ScreenToClient(Mouse.CursorPos); Coord := dbgrd_bolunico.MouseCoord(Pt.X, Pt.Y); if (Coord.Y > 0) and not(zroqryBolUnico.IsEmpty) and (Button = mbRight) then begin pum_incldel.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y); end; end; procedure TfrmCentralBoletos.dtsBoletosDataChange(Sender: TObject; Field: TField); begin if not tblBoletos.IsEmpty then begin if tblBoletosdesconto1.AsString <> '' then begin tblDesc1.ReadOnly := False; JsonToDataset2(tblDesc1, '[' + TJSONObject.ParseJSONValue (tblBoletosdesconto1.AsString).ToString + ']'); tblDesc1.ReadOnly := True; end; if tblBoletosdesconto2.AsString <> '' then begin tblDesc2.ReadOnly := False; JsonToDataset2(tblDesc2, '[' + TJSONObject.ParseJSONValue (tblBoletosdesconto2.AsString).ToString + ']'); tblDesc2.ReadOnly := True; end; if tblBoletosdesconto3.AsString <> '' then begin tblDesc3.ReadOnly := False; JsonToDataset2(tblDesc3, '[' + TJSONObject.ParseJSONValue (tblBoletosdesconto3.AsString).ToString + ']'); tblDesc3.ReadOnly := True; end; if tblBoletosmulta.AsString <> '' then begin tblMulta.ReadOnly := False; JsonToDataset2(tblMulta, '[' + TJSONObject.ParseJSONValue (tblBoletosmulta.AsString).ToString + ']'); tblMulta.ReadOnly := True; end; if tblBoletosmora.AsString <> '' then begin tblMora.ReadOnly := False; JsonToDataset2(tblMora, '[' + TJSONObject.ParseJSONValue (tblBoletosmora.AsString).ToString + ']'); tblMora.ReadOnly := True; end; end; end; procedure TfrmCentralBoletos.edt_abatimentobolKeyPress(Sender: TObject; var Key: Char); begin inherited; if not(Key in [#8, '0' .. '9', System.SysUtils.FormatSettings.DecimalSeparator]) then begin Key := #0; end else if (Key = System.SysUtils.FormatSettings.DecimalSeparator) and (Pos(Key, edt_abatimentobol.Text) > 0) then begin Key := #0; end; end; procedure TfrmCentralBoletos.edt_valorboletoKeyPress(Sender: TObject; var Key: Char); begin inherited; if not(Key in [#8, '0' .. '9', System.SysUtils.FormatSettings.DecimalSeparator]) then begin Key := #0; end else if (Key = System.SysUtils.FormatSettings.DecimalSeparator) and (Pos(Key, edt_valorboleto.Text) > 0) then begin Key := #0; end; end; procedure TfrmCentralBoletos.FormCreate(Sender: TObject); begin inherited; vl_bol := 0; opcoes_situacao := TStringList.create; opcoes_situacao.Add('TODOS'); opcoes_situacao.Add('VENCIDOSAVENCER'); opcoes_situacao.Add('EXPIRADOS'); opcoes_situacao.Add('PAGOS'); opcoes_situacao.Add('TODOSBAIXADOS'); opcoes_datatipo := TStringList.create; opcoes_datatipo.Add('VENCIMENTO'); opcoes_datatipo.Add('EMISSAO'); opcoes_datatipo.Add('SITUACAO'); opcoes_ordem := TStringList.create; opcoes_ordem.Add('NOSSONUMERO'); opcoes_ordem.Add('SEUNUMERO'); opcoes_ordem.Add('DATAVENCIMENTO_ASC'); opcoes_ordem.Add('DATAVENCIMENTO_DSC'); opcoes_ordem.Add('NOMESACADO'); opcoes_ordem.Add('VALOR_ASC'); opcoes_ordem.Add('VALOR_DSC'); opcoes_ordem.Add('STATUS_ASC'); opcoes_ordem.Add('STATUS_DSC'); dt_inicio.Date := StartOfTheMonth(Date); dt_fim.Date := EndOfTheMonth(Date); dt_vencbolunico.Date := Date; dtp_vencinbolunico.Date := StartOfTheMonth(Date); dtp_vencoutbolunico.Date := EndOfTheMonth(Date); IdSSLHandler.SSLOptions.CertFile := dtmSystem.public_key; IdSSLHandler.SSLOptions.KeyFile := dtmSystem.private_key; IdSSLHandler.SSLOptions.RootCertFile := dtmSystem.certificate_key; with dtmSystem do begin if not tblEstados.Active then begin tblEstados.Open; end else begin tblEstados.Refresh; end; if not tblCidades.Active then begin tblCidades.Open; end else begin tblCidades.Refresh; end; if not tblCidadesConsulta.Active then begin tblCidadesConsulta.Open; end else begin tblCidadesConsulta.Refresh; end; if not tblGrupoBoletos.Active then begin tblGrupoBoletos.Open; end; tblGrupoBoletos.First; if not tblBoletos.Active then begin tblBoletos.Open; end; if not tblBoletoTitulos.Active then begin tblBoletoTitulos.Open; end; dblucb_filtrobolunico.KeyValue := tblGrupoBoletosID_GRUPO.AsInteger; end; zroqryBolUnico.Open; zroqryEmails.Open; zroqryTelefones.Open; zroqryEnderecos.Open; pcGeraBoletos.TabIndex := 0; pcBoletos.TabIndex := 0; pcPesquisaGerar.TabIndex := 0; end; procedure TfrmCentralBoletos.JsonToDataset2(aDataset: TDataSet; aJSON: string); var JObj: TJSONArray; vConv: TCustomJSONDataSetAdapter; begin if (aJSON = EmptyStr) then begin Exit; end; JObj := TJSONObject.ParseJSONValue(aJSON) as TJSONArray; vConv := TCustomJSONDataSetAdapter.create(Nil); try vConv.DataSet := aDataset; vConv.UpdateDataSet(JObj); finally vConv.Free; JObj.Free; end; end; procedure TfrmCentralBoletos.mnhGrupoBoletosClick(Sender: TObject); begin inherited; frmGrupoBoletoEmpresas := TfrmGrupoBoletoEmpresas.create(self); frmGrupoBoletoEmpresas.ShowModal; end; procedure TfrmCentralBoletos.mnuAcertosClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "ACERTOS"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuAPedidoClienteClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "APEDIDODOCLIENTE"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuBaixarCobClick(Sender: TObject); var total_recebido, nominal_boleto, recebido_rateio, help_pr, help_j, help_m, help_cor: currency; prct_rateio: double; atraso, atraso_repasse: Integer; mes, ano: string; begin inherited; if not dtmSystem.tblBoletos.Locate('NR_NOSSO_NUMERO', tblBoletosseuNumero.AsString, []) then begin Showmessage('Não foi possível encontrar o boleto desejado no sistema.'); abort; end else begin with dtmSystem do begin total_recebido := tblBoletosvalorTotalRecebimento.AsCurrency; nominal_boleto := tblBoletosvalorNominal.AsCurrency; tblBoletoTitulos.First; while not tblBoletoTitulos.Eof do begin tblDevedores.Locate('ID_DEVEDOR', tblBoletoTitulosID_DEVEDOR.AsInteger, []); tblTitulos.Locate('ID_TITULO', tblBoletoTitulosID_TITULO.AsInteger, []); prct_rateio := ((tblTitulosVL_TITULO.AsCurrency * 100) / nominal_boleto) / 100; recebido_rateio := (prct_rateio * total_recebido); tblTitulos.Edit; tblTitulosVL_CORRIGIDO.AsCurrency := recebido_rateio; if recebido_rateio < tblTitulosVL_TITULO.AsCurrency then begin tblTitulosVL_DESC_PRINCIPAL.AsCurrency := tblTitulosVL_TITULO.AsCurrency - recebido_rateio; end; if tblMultacodigo.AsString <> 'NAOTEMMULTA' then begin atraso := DaysBetween(tblBoletosdataPagtoBaixa.AsDateTime, IncDay(tblMultadata.AsDateTime, -1)); if atraso > 0 then begin if tblMultacodigo.AsString = 'VALORFIXO' then begin tblTitulosVL_MULTA.AsCurrency := (tblMultavalor.AsCurrency * prct_rateio); end else begin tblTitulosVL_MULTA.AsCurrency := ((tblTitulosVL_TITULO.AsCurrency * tblMultataxa.AsFloat) / 100) * prct_rateio; end; end; end; if tblMoracodigo.AsString <> 'ISENTO' then begin atraso := DaysBetween(tblBoletosdataPagtoBaixa.AsDateTime, IncDay(tblMoradata.AsDateTime, -1)); if atraso > 0 then begin if tblMoracodigo.AsString = 'VALORDIA' then begin tblTitulosVL_JUROS.AsCurrency := (tblMoravalor.AsCurrency * atraso) * prct_rateio; end else begin tblTitulosVL_MULTA.AsCurrency := ((tblTitulosVL_TITULO.AsCurrency * ((tblMultataxa.AsFloat / 30) / 100)) * atraso) * prct_rateio; end; end; end; mes := inttostr(strtoint(copy(FormatDateTime('yyyy-mm-dd', tblBoletosdataPagtoBaixa.AsDateTime), 6, 2))); ano := copy(FormatDateTime('yyyy-mm-dd', tblBoletosdataPagtoBaixa.AsDateTime), 1, 4); atraso_repasse := DaysBetween(tblBoletosdataPagtoBaixa.AsDateTime, tblTitulosDT_VENCIMENTO.AsDateTime); tblCHGEmpresa.Locate('ID_EMPRESA', tblTitulosID_EMPRESA.AsInteger, []); tblEmpresaRepasse.Locate('ID_MES;ID_ANO', VarArrayOf([mes, ano]), []); rotblRepasseFase.Close; rotblRepasseFase.SQL.Text := 'select * from sys_repasses_fases where id_repasse = ' + QuotedStr(tblEmpresaRepasseID_ITEM.AsString) + ' and min_atraso <= ' + inttostr(atraso_repasse) + ' and ' + inttostr(atraso_repasse) + ' <= max_atraso'; rotblRepasseFase.Open; if not rotblRepasseFase.IsEmpty then begin help_pr := (rotblRepasseFasePR_PRINCIPAL.AsCurrency / 100); help_j := (rotblRepasseFasePR_JUROS.AsCurrency / 100); help_m := (rotblRepasseFasePR_MULTA.AsCurrency / 100); help_cor := (rotblRepasseFasePR_CORRIGIDO.AsCurrency / 100); end else begin help_pr := (dtmSystem.tblEmpresaRepassePR_PRINCIPAL.AsCurrency / 100); help_j := (dtmSystem.tblEmpresaRepassePR_JUROS.AsCurrency / 100); help_m := (dtmSystem.tblEmpresaRepassePR_MULTA.AsCurrency / 100); help_cor := (dtmSystem.tblEmpresaRepassePR_CORRIGIDO.AsCurrency / 100); end; tblTitulosVL_REPASSE_PRIN.AsCurrency := (tblTitulosVL_TITULO.AsCurrency - tblTitulosVL_DESC_PRINCIPAL.AsCurrency) * help_pr; tblTitulosVL_REPASSE_JUROS.AsCurrency := tblTitulosVL_JUROS.AsCurrency * help_j; tblTitulosVL_REPASSE_MULTA.AsCurrency := tblTitulosVL_MULTA.AsCurrency * help_m; tblTitulosVL_REPASSE_ENCARGOS.AsCurrency := 0; tblTitulosVL_REPASSE_CORRIGIDO.AsCurrency := tblTitulosVL_CORRIGIDO.AsCurrency * help_cor; tblTitulosTP_SITUACAO.AsString := 'QC'; tblTitulosTP_PRESTACAO.AsString := 'N'; tblTitulos.Post; tblHistorico.Append; tblHistoricoID_DEVEDOR.AsInteger := tblTitulosID_DEVEDOR.AsInteger; tblHistoricoID_COBRADOR.AsInteger := id_usuario; tblHistoricoDT_CONTATO.AsDateTime := Now; tblHistoricoTL_MEMO.AsString := 'Título ' + tblTitulosTX_PRODUTO.AsString + ' foi baixado pelo boleto de nº ' + tblBoletosseuNumero.AsString + '.'; tblHistorico.Post; tblBoletoTitulos.Next; end; Showmessage('Títulos baixados com sucesso!'); end; end; end; procedure TfrmCentralBoletos.mnuDevolucaoClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "DEVOLUCAO"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuDownloadClick(Sender: TObject); var Base64: string; fileStream: TFileStream; begin inherited; IdHTTP.Request.CustomHeaders.Clear; IdHTTP.Request.CustomHeaders.Add('Content-Type: application/json'); IdHTTP.Request.CustomHeaders.Add('x-inter-conta-corrente: ' + dtmSystem.conta_corrente); try Base64 := RequestBase64 ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/pdf'); except on E: EIdHTTPProtocolException do Showmessage(IdHTTP.ResponseText + #13#10 + E.ErrorMessage) else showexception(exceptobject, exceptaddr); end; if IdHTTP.ResponseCode <> 200 then begin Showmessage('Transação não pode ser inicada (' + inttostr(IdHTTP.ResponseCode) + ').'); end else begin with SaveDialog do begin Execute; try fileStream := TFileStream.create(FileName, fmCreate); IdDecoderMIME.DecodeStream(Base64, fileStream); Screen.Cursor := crHourGlass; finally fileStream.Free; Screen.Cursor := crDefault; FileName := ''; end; end; end; end; procedure TfrmCentralBoletos.mnuFaltaClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "FALTADESOLUCAO"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuIncluirClick(Sender: TObject); var i: Integer; begin dtmSystem.tblGrupoBoletos.Refresh; zroqryBolUnico.GotoBookmark(pointer(dbgrd_bolunico.SelectedRows.Items[0])); edt_nomebolunico.Text := zroqryBolUnicoTX_NOME.AsString; edt_docbolunico.Text := StringReplace (StringReplace(StringReplace(zroqryBolUnicoTX_DOCUMENTO.AsString, '.', '', [rfReplaceAll]), '-', '', [rfReplaceAll]), '/', '', [rfReplaceAll]); // edt_docbolunico.Text := zroqryBolUnicoTX_DOCUMENTO.AsString; if not zroqryEmails.IsEmpty then begin edt_emailbolunico.Text := zroqryEmailsTX_EMAIL.AsString; end; if not zroqryTelefones.IsEmpty then begin edt_dddbolunico.Text := zroqryTelefonesNR_DDD.AsString; edt_telbolunico.Text := StringReplace(zroqryTelefonesNR_NUMERO.AsString, '-', '', [rfReplaceAll]); end; if not zroqryEnderecos.IsEmpty then begin edt_cepbolunico.Text := StringReplace(StringReplace(zroqryEnderecosTX_CEP.AsString, '.', '', [rfReplaceAll]), '-', '', [rfReplaceAll]); edt_endnumbolunico.Text := zroqryEnderecosNR_NUMERO.AsString; edt_compbolunico.Text := zroqryEnderecosTX_COMPLEMENTO.AsString; edt_bairrobolunico.Text := zroqryEnderecosTX_BAIRRO.AsString; edt_cidadebolunico.Text := zroqryEnderecosTX_CIDADE.AsString; edt_estadobolunico.Text := zroqryEnderecosTX_ESTADO.AsString; edt_endbolunico.Text := zroqryEnderecosTX_LOGRADOURO.AsString; end; dt_vencbolunico.Date := zroqryBolUnicoDT_VENCIMENTO.AsDateTime; cb_desc1.ItemIndex := dtmSystem.tblGrupoBoletosTP_DESC1.AsInteger; cb_desc2.ItemIndex := dtmSystem.tblGrupoBoletosTP_DESC2.AsInteger; cb_desc3.ItemIndex := dtmSystem.tblGrupoBoletosTP_DESC3.AsInteger; cb_multabol.ItemIndex := dtmSystem.tblGrupoBoletosTP_MULTA.AsInteger; cb_morabol.ItemIndex := dtmSystem.tblGrupoBoletosTP_MORA.AsInteger; edt_taxa1bol.Text := dtmSystem.tblGrupoBoletosPR_DESC1.AsString; edt_taxa2bol.Text := dtmSystem.tblGrupoBoletosPR_DESC2.AsString; edt_taxa3bol.Text := dtmSystem.tblGrupoBoletosPR_DESC3.AsString; edt_taxamultabol.Text := dtmSystem.tblGrupoBoletosPR_MULTA.AsString; edt_taxamorabol.Text := dtmSystem.tblGrupoBoletosPR_MORA.AsString; edt_val1bol.Text := dtmSystem.tblGrupoBoletosNR_DESC1.AsString; edt_val2bol.Text := dtmSystem.tblGrupoBoletosNR_DESC2.AsString; edt_val3bol.Text := dtmSystem.tblGrupoBoletosNR_DESC3.AsString; edt_vlmultabol.Text := dtmSystem.tblGrupoBoletosNR_MULTA.AsString; edt_vlmorabol.Text := dtmSystem.tblGrupoBoletosNR_MORA.AsString; dtp_desc1.Date := dtmSystem.tblGrupoBoletosDT_DESC1.AsDateTime; dtp_desc2.Date := dtmSystem.tblGrupoBoletosDT_DESC2.AsDateTime; dtp_desc3.Date := dtmSystem.tblGrupoBoletosDT_DESC3.AsDateTime; for i := 0 to dbgrd_bolunico.SelectedRows.Count - 1 do begin zroqryBolUnico.GotoBookmark(pointer(dbgrd_bolunico.SelectedRows.Items[i])); vl_bol := vl_bol + zroqryBolUnicoVL_TITULO.AsCurrency; end; edt_valorboleto.Text := FormatFloat('0.##', vl_bol); pcPesquisaGerar.TabIndex := 1; edt_nomebolunico.SetFocus; end; procedure TfrmCentralBoletos.mnuPagoDiretoClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "PAGODIRETOAOCLIENTE"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuProtestadoClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "PROTESTADO"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuProtestoAposBaixaClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "PROTESTOAPOSBAIXA"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; procedure TfrmCentralBoletos.mnuSubstituicaoClick(Sender: TObject); var resp: string; begin inherited; resp := SendJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos/' + tblBoletosnossoNumero.AsString + '/baixas', TJSONObject.ParseJSONValue('{"codigoBaixa": "SUBSTITUICAO"}') as TJSONObject); if resp <> 'Error' then begin Showmessage('Boleto Nº ' + tblBoletosseuNumero.AsString + ' baixado com sucesso!'); end; end; function TfrmCentralBoletos.RequestBase64(URL: String; Body: TStringStream): string; var Response: TStringStream; begin Screen.Cursor := crHourGlass; Response := TStringStream.create('', TEncoding.utf8); try IdHTTP.Get(URL, Response); except on E: EIdHTTPProtocolException do Showmessage('Error on request: '#13#10 + E.ErrorMessage); end; Result := Response.DataString; Screen.Cursor := crDefault; end; function TfrmCentralBoletos.RequestJSON(URL: String; Body: TStringStream) : TJSONObject; var Response: TStringStream; begin Screen.Cursor := crHourGlass; Response := TStringStream.create('', TEncoding.utf8); IdHTTP.Request.CustomHeaders.Clear; IdHTTP.Request.CustomHeaders.Add('Content-Type: application/json'); IdHTTP.Request.CustomHeaders.Add('x-inter-conta-corrente: ' + dtmSystem.conta_corrente); try IdHTTP.Get(URL, Response); except on E: EIdHTTPProtocolException do Showmessage('Error on request: '#13#10 + E.ErrorMessage); end; Result := TJSONObject.ParseJSONValue(Response.DataString) as TJSONObject; Screen.Cursor := crDefault; end; function TfrmCentralBoletos.SendJSON(URL: String; JSON: TJSONObject): string; var // JSONToReturn: TStringStream; JSONToSend: TStringStream; string_return: string; begin Screen.Cursor := crHourGlass; try JSONToSend := TStringStream.create(JSON.ToString, TEncoding.utf8); except end; // JSONToReturn := TStringStream.create(''); try IdHTTP.Request.ContentType := 'application/json'; IdHTTP.Request.Accept := 'application/json'; IdHTTP.Request.CharSet := 'utf-8'; IdHTTP.Request.CustomHeaders.Clear; IdHTTP.Request.CustomHeaders.Add('x-inter-conta-corrente: ' + dtmSystem.conta_corrente); try string_return := IdHTTP.Post(URL, JSONToSend); Result := string_return; except on E: EIdHTTPProtocolException do begin Showmessage('Error on request: '#13#10 + E.ErrorMessage); Result := 'Error'; end; end; finally JSONToSend.Free; end; Screen.Cursor := crDefault; end; procedure TfrmCentralBoletos.SpeedButton1Click(Sender: TObject); var JSON: TJSONObject; Params: string; begin Params := '?'; Params := Params + 'filtrarPor=' + opcoes_situacao [cb_filtrosituacao.ItemIndex] + '&'; Params := Params + 'dataInicial=' + FormatDateTime('yyyy-mm-dd', dt_inicio.Date) + '&'; Params := Params + 'dataFinal=' + FormatDateTime('yyyy-mm-dd', dt_fim.Date) + '&'; Params := Params + 'filtrarDataPor=' + opcoes_datatipo [cb_filtroordem.ItemIndex] + '&'; // Params := Params + 'ordenarPor=NOMESACADO' + opcoes_ordem // [cb_filtrotipodata.ItemIndex]; try JSON := RequestJSON ('https://apis.bancointer.com.br/openbanking/v1/certificado/boletos' + Params); except on E: EIdHTTPProtocolException do begin Showmessage(IdHTTP.ResponseText + #13#10 + E.ErrorMessage); Screen.Cursor := crDefault; end else begin showexception(exceptobject, exceptaddr); Screen.Cursor := crDefault; end; end; if IdHTTP.ResponseCode <> 200 then begin Showmessage('Transação não pode ser inicada (' + inttostr(IdHTTP.ResponseCode) + ').'); end else begin tblBoletos.ReadOnly := False; Screen.Cursor := crHourGlass; JsonToDataset2(tblBoletos, JSON.GetValue('content').ToString); // if tblBoletos.IsEmpty then // begin // dbgrd_boletos.PopupMenu := nil; // end // else // begin // dbgrd_boletos.PopupMenu := pum_download; // end; Screen.Cursor := crDefault; tblBoletos.ReadOnly := True; end; end; procedure TfrmCentralBoletos.SpeedButton2Click(Sender: TObject); var emp: string; begin inherited; zroqryBolUnico.Close; emp := dblucb_filtrobolunico.KeyValue; with zroqryBolUnico.SQL do begin Clear; Add('select'); Add('d.ID_DEVEDOR,'); Add('d.TX_NOME,'); Add('case when d.TP_CLIENTE = ' + QuotedStr('F') + ' then d.CD_CPF when d.TP_CLIENTE = ' + QuotedStr('F') + ' then d.CD_CNPJ end as TX_DOCUMENTO,'); Add('t.TX_PRODUTO,'); Add('t.VL_TITULO,'); Add('t.VL_CORRIGIDO,'); Add('t.DT_VENCIMENTO,'); Add('t.ID_EMPRESA,'); Add('t.ID_TITULO'); Add('from chg_titulos t'); Add('left join CHG_DEVEDORES d on d.ID_DEVEDOR = t.ID_DEVEDOR'); Add('where'); Add('t.ID_EMPRESA in (select ID_EMPRESA from CHG_GRUPO_BOLETO_EMPRESAS where ID_GRUPO_BOLETO = ' + emp + ')'); Add('and'); Add('(t.TP_SITUACAO = ' + QuotedStr('A') + ' or t.TP_SITUACAO = ' + QuotedStr('AC') + ')'); Add('and'); Add('(t.DT_VENCIMENTO >= cast(' + QuotedStr(FormatDateTime('yyyy-mm-dd', dtp_vencinbolunico.Date)) + ' as date) and t.DT_VENCIMENTO <= cast(' + QuotedStr(FormatDateTime('yyyy-mm-dd', dtp_vencoutbolunico.Date)) + ' as date))'); Add('order by d.TX_NOME, t.TX_PRODUTO'); end; zroqryBolUnico.Open; with dtmSystem do begin edt_taxa1bol.Text := dtmSystem.tblGrupoBoletosPR_DESC1.AsString; edt_val1bol.Text := dtmSystem.tblGrupoBoletosNR_DESC1.AsString; dtp_desc1.Date := dtmSystem.tblGrupoBoletosDT_DESC1.AsDateTime; cb_desc1.ItemIndex := dtmSystem.tblGrupoBoletosTP_DESC1.AsInteger;; end; end; function TfrmCentralBoletos.ValidadorDescontos: TStringArray; begin setlength(Result, 2); Result[0] := 'True'; Result[1] := ''; case cb_desc1.ItemIndex of 2, 5, 6: begin if edt_taxa1bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 1 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 1, 3, 4: begin if edt_val1bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 1 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 0: begin if edt_taxa1bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 1 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; if edt_val1bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 1 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; end; end; case cb_desc2.ItemIndex of 2, 5, 6: begin if edt_taxa2bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 2 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 1, 3, 4: begin if edt_val2bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 2 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 0: begin if edt_taxa2bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 2 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; if edt_val2bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 2 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; end; end; case cb_desc3.ItemIndex of 2, 5, 6: begin if edt_taxa3bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 3 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 1, 3, 4: begin if edt_val3bol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 3 não pode estar vazia para o tipo de desconto escolhido.'; Exit; end; end; 0: begin if edt_taxa3bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Taxa do Desconto 3 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; if edt_val3bol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Valor do Desconto 3 deve ser 0 para o tipo de desconto escolhido.'; Exit; end; end; end; end; function TfrmCentralBoletos.ValidadorMultaMora: TStringArray; begin setlength(Result, 2); Result[0] := 'True'; Result[1] := ''; case cb_multabol.ItemIndex of 1: begin if edt_vlmultabol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Valor da Multa não pode estar vazia para o tipo de multa escolhida.'; Exit; end; end; 2: begin if edt_taxamultabol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Taxa da Multa não pode estar vazia para o tipo de multa escolhida.'; Exit; end; end; 0: begin if edt_vlmultabol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Valor da Multa 3 deve ser 0 para o tipo de multa escolhida.'; Exit; end; if edt_taxamultabol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Taxa da Multa deve ser 0 para o tipo de multa escolhida.'; Exit; end; end; end; case cb_morabol.ItemIndex of 1: begin if edt_taxamorabol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Taxa de Mora não pode estar vazia para o tipo de mora escolhida.'; Exit; end; end; 2: begin if edt_vlmorabol.Text = '' then begin Result[0] := 'False'; Result[1] := 'Valor de Mora não pode estar vazia para o tipo de mora escolhida.'; Exit; end; end; 0: begin if edt_taxamorabol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Taxa de Mora deve ser 0 para o tipo de mora escolhida.'; Exit; end; if edt_vlmorabol.Text <> '0' then begin Result[0] := 'False'; Result[1] := 'Valor de Mora deve ser 0 para o tipo de mora escolhido.'; Exit; end; end; end; end; function TfrmCentralBoletos.ValidadorPagador: TStringArray; begin setlength(Result, 2); Result[0] := 'True'; Result[1] := ''; if edt_nomebolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Nome do pagador não pode estar vazio.'; Exit; end; if edt_docbolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Documento do pagador não pode estar vazio.'; Exit; end else if (length(edt_docbolunico.Text) <> 11) and (length(edt_docbolunico.Text) <> 14) then begin Result[0] := 'False'; Result[1] := 'Documento do pagador inválido.'; Exit; end; if edt_cepbolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'CEP do pagador não pode estar vazio.'; Exit; end else if length(edt_cepbolunico.Text) <> 8 then begin Result[0] := 'False'; Result[1] := 'CEP do pagador inválido.'; Exit; end; if edt_endbolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Endereço do pagador não pode estar vazio.'; Exit; end; if edt_endnumbolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Número do Endereço do pagador não pode estar vazio.'; Exit; end; if edt_bairrobolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Bairro do pagador não pode estar vazio.'; Exit; end; if edt_cidadebolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'Cidade do pagador não pode estar vazio.'; Exit; end; if edt_estadobolunico.Text = '' then begin Result[0] := 'False'; Result[1] := 'UF do pagador não pode estar vazio.'; Exit; end; end; end.