unit uimpDevedores; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.win.ComObj, System.StrUtils, System.MaskUtils, DB, System.UITypes, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, umstMaster, Vcl.ComCtrls, Vcl.Menus, uImportExcel, Vcl.Grids, Vcl.StdCtrls, Vcl.DBCtrls, ZAbstractRODataset, ZAbstractDataset, ZDataset; type TimpDevedores = class(TmstMaster) odExcel: TOpenDialog; MainMenu1: TMainMenu; sg_import: TStringGrid; pb_import: TProgressBar; gb_importconfig: TGroupBox; pc_import: TPageControl; tabDevedores: TTabSheet; tabTitulos: TTabSheet; cbx_razao: TComboBox; cb_fantasia: TCheckBox; cbx_fantasia: TComboBox; cb_email: TCheckBox; cbx_email: TComboBox; cbx_cpfcnpj: TComboBox; cbx_endereco: TComboBox; cb_endereco: TCheckBox; cbx_numero: TComboBox; cb_numero: TCheckBox; cbx_complemento: TComboBox; cb_complemento: TCheckBox; cbx_cep: TComboBox; cb_cep: TCheckBox; cbx_cidade: TComboBox; cb_cidade: TCheckBox; cb_bairro: TCheckBox; cbx_bairro: TComboBox; cbx_uf: TComboBox; cb_uf: TCheckBox; Importar1: TMenuItem; lbl_primeiralinha: TLabel; cbx_primeiralinha: TComboBox; cbx_telefone: TComboBox; lbl_nomerazao: TLabel; lbl_cpfcnpj: TLabel; lbl_telefone: TLabel; cbx_produto: TComboBox; lbl_produto: TLabel; cbx_valor: TComboBox; lbl_valor: TLabel; cbx_coddevt: TComboBox; cb_coddevt: TCheckBox; cbx_cpfcnpjt: TComboBox; Label1: TLabel; cbx_vencimento: TComboBox; lbl_vencimento: TLabel; lbl_relcoldados: TLabel; Label2: TLabel; dblucb_empresas: TDBLookupComboBox; lbl_empresas: TLabel; cb_pai: TCheckBox; cbx_pai: TComboBox; cb_mae: TCheckBox; cbx_mae: TComboBox; cbx_rg: TComboBox; cb_rg: TCheckBox; mnuConfigs: TMenuItem; Layouts1: TMenuItem; cb_dtnasc: TCheckBox; cbx_dtnasc: TComboBox; cb_tel2: TCheckBox; cbx_tel2: TComboBox; cb_tel3: TCheckBox; cbx_tel3: TComboBox; imp_Layout: TMenuItem; N1: TMenuItem; cb_cheque: TCheckBox; lbl_banco: TLabel; cbx_banco: TComboBox; lbl_nrcheque: TLabel; cbx_nrcheque: TComboBox; lbl_motivo: TLabel; cbx_motivo: TComboBox; zqryDuplicados: TZQuery; cbx_ddd1: TComboBox; cbx_ddd2: TComboBox; cbx_ddd3: TComboBox; lbl_ddd1: TLabel; lbl_ddd2: TLabel; lbl_ddd3: TLabel; procedure cb_fantasiaClick(Sender: TObject); procedure cb_emailClick(Sender: TObject); procedure cb_enderecoClick(Sender: TObject); procedure cb_numeroClick(Sender: TObject); procedure cb_complementoClick(Sender: TObject); procedure cb_cidadeClick(Sender: TObject); procedure cb_bairroClick(Sender: TObject); procedure cb_ufClick(Sender: TObject); procedure cb_cepClick(Sender: TObject); procedure cb_coddevtClick(Sender: TObject); procedure Layouts1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure cb_paiClick(Sender: TObject); procedure cb_maeClick(Sender: TObject); procedure cb_dtnascClick(Sender: TObject); procedure cb_tel2Click(Sender: TObject); procedure cb_tel3Click(Sender: TObject); procedure imp_LayoutClick(Sender: TObject); procedure cb_chequeClick(Sender: TObject); private function OStripAccents(const aStr: String): String; procedure Carregar; procedure ImportarLayout; procedure PovoaCB(tbSheet: TTabSheet); function CmtoPix(cm: double): integer; procedure WMMoving(var Msg: TWMMoving); message WM_MOVING; { Private declarations } public itemList: TStringList; id_emp: integer; // id_prov: integer; { Public declarations } end; var impDevedores: TimpDevedores; implementation {$R *.dfm} uses udtmSystem, uconfLayouts, ufrmEscolheLayout, urelBordero, urelDuplicados, ucadDevedores; procedure TimpDevedores.cb_bairroClick(Sender: TObject); begin cbx_bairro.Enabled := cb_bairro.Checked; end; procedure TimpDevedores.cb_cepClick(Sender: TObject); begin cbx_cep.Enabled := cb_cep.Checked; end; procedure TimpDevedores.cb_chequeClick(Sender: TObject); begin cbx_banco.Enabled := cb_cheque.Checked; cbx_nrcheque.Enabled := cb_cheque.Checked; cbx_motivo.Enabled := cb_cheque.Checked; end; procedure TimpDevedores.cb_cidadeClick(Sender: TObject); begin cbx_cidade.Enabled := cb_cidade.Checked; end; procedure TimpDevedores.cb_emailClick(Sender: TObject); begin cbx_email.Enabled := cb_email.Checked; end; procedure TimpDevedores.cb_coddevtClick(Sender: TObject); begin cbx_coddevt.Enabled := cb_coddevt.Checked; end; procedure TimpDevedores.cb_complementoClick(Sender: TObject); begin cbx_complemento.Enabled := cb_complemento.Checked; end; procedure TimpDevedores.cb_dtnascClick(Sender: TObject); begin cbx_dtnasc.Enabled := cb_dtnasc.Checked; end; procedure TimpDevedores.cb_enderecoClick(Sender: TObject); begin cbx_endereco.Enabled := cb_endereco.Checked; cb_numero.Enabled := cb_endereco.Checked; cb_complemento.Enabled := cb_endereco.Checked; cb_cidade.Enabled := cb_endereco.Checked; cb_bairro.Enabled := cb_endereco.Checked; cb_uf.Enabled := cb_endereco.Checked; cb_cep.Enabled := cb_endereco.Checked; if cb_endereco.Checked then begin cbx_numero.Enabled := cb_numero.Checked; cbx_complemento.Enabled := cb_complemento.Checked; cbx_cidade.Enabled := cb_cidade.Checked; cbx_bairro.Enabled := cb_bairro.Checked; cbx_uf.Enabled := cb_uf.Checked; cbx_cep.Enabled := cb_cep.Checked; end else begin cbx_numero.Enabled := false; cbx_complemento.Enabled := false; cbx_cidade.Enabled := false; cbx_bairro.Enabled := false; cbx_uf.Enabled := false; cbx_cep.Enabled := false; end; end; procedure TimpDevedores.cb_fantasiaClick(Sender: TObject); begin cbx_fantasia.Enabled := cb_fantasia.Checked; end; procedure TimpDevedores.cb_maeClick(Sender: TObject); begin cbx_mae.Enabled := cb_mae.Checked; end; procedure TimpDevedores.cb_numeroClick(Sender: TObject); begin cbx_numero.Enabled := cb_numero.Checked; end; procedure TimpDevedores.cb_paiClick(Sender: TObject); begin cbx_pai.Enabled := cb_pai.Checked; end; procedure TimpDevedores.cb_tel2Click(Sender: TObject); begin cbx_tel2.Enabled := cb_tel2.Checked; cbx_ddd2.Enabled := cb_tel2.Checked; end; procedure TimpDevedores.cb_tel3Click(Sender: TObject); begin cbx_tel3.Enabled := cb_tel3.Checked; cbx_ddd3.Enabled := cb_tel3.Checked; end; procedure TimpDevedores.cb_ufClick(Sender: TObject); begin cbx_uf.Enabled := cb_uf.Checked; end; procedure TimpDevedores.Carregar; var OpenOffice, OpenDesktop, OOCalc, OOExec, Planilha, LoadParams, Param, OORCCount: Variant; RCount, CCount, TotCell, Counter, ColWidth, RowHeight, PColwidth, PRowHeight: integer; // linhaList: TStringList; pathFile: string; i, j, k, l: integer; begin if odExcel.Execute then begin pathFile := StringReplace(odExcel.FileName, '\', '/', [rfReplaceAll]); pathFile := 'file:///' + pathFile; Screen.Cursor := crHourGlass; if VarIsEmpty(OpenOffice) then begin OpenOffice := CreateOleObject('com.sun.star.ServiceManager'); end; OpenDesktop := OpenOffice.CreateInstance('com.sun.star.frame.Desktop'); LoadParams := VarArrayCreate([0, 0], varVariant); Param := OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue'); Param.Name := 'Hidden'; Param.Value := true; LoadParams[0] := Param; OOExec := OpenDesktop.LoadComponentFromURL(pathFile, '_blank', 0, LoadParams); OOCalc := OOExec.Sheets; Planilha := OOCalc.getbyIndex(0); OORCCount := Planilha.createCursor; OORCCount.gotoEndOfUsedArea(false); RCount := OORCCount.RangeAddress.EndRow; CCount := OORCCount.RangeAddress.EndColumn; Inc(RCount, 1); Inc(CCount, 1); TotCell := RCount * CCount; pb_import.Max := TotCell; Counter := 0; itemList := TStringList.Create; with itemList do begin for k := 0 to CCount - 1 do begin Add(inttostr(k + 1)); end; end; for l := 0 to sg_import.ColCount - 1 do begin sg_import.Cols[l].Clear; end; sg_import.RowCount := RCount + 1; sg_import.ColCount := CCount; RowHeight := 0; for j := 0 to RCount do begin ColWidth := 0; for i := 0 to CCount - 1 do begin if j = 0 then begin sg_import.Cells[i, j] := inttostr(i + 1); end else begin PColwidth := CmtoPix(Planilha.getCellByPosition(i, j - 1) .getColumns.getbyIndex(0).Width); if ColWidth < PColwidth then begin ColWidth := PColwidth; end; PRowHeight := CmtoPix(Planilha.getCellByPosition(i, j - 1) .getRows.Height); if RowHeight < PRowHeight then begin RowHeight := PRowHeight; end; sg_import.ColWidths[i] := ColWidth; sg_import.RowHeights[j] := RowHeight; // if (j > 1) then // begin // showmessage(inttostr(i)); // showmessage(inttostr(Planilha.getCellByPosition(i, j - 1) // .NumberFormat)); // end; if ((Planilha.getCellByPosition(i, j - 1).NumberFormat = 36) or (Planilha.getCellByPosition(i, j - 1).NumberFormat = 37) or (Planilha.getCellByPosition(i, j - 1).NumberFormat = 8110) or (Planilha.getCellByPosition(i, j - 1).NumberFormat = 8109)) and (Planilha.getCellByPosition(i, j - 1).getFormula <> '') and (StrToIntDef(copy(Planilha.getCellByPosition(i, j - 1).getFormula, 1, 1), 0) <> 0) then begin try sg_import.Cells[i, j] := DateToStr(Planilha.getCellByPosition(i, j - 1).getFormula); except Messagedlg('Data não existente escrita na linha ' + inttostr(j) + ', coluna ' + inttostr(i + 1) + '. Essa data não será carregada para importação, o que irá gerar um erro.', mtWarning, [mbOK], 0); end; end else begin if copy(Planilha.getCellByPosition(i, j - 1).getFormula, 0, 1) = '''' then begin sg_import.Cells[i, j] := StringReplace(Planilha.getCellByPosition(i, j - 1).getFormula, '''', '', [rfReplaceAll, rfIgnoreCase]); end else begin sg_import.Cells[i, j] := Planilha.getCellByPosition(i, j - 1) .getFormula; end; if Planilha.getCellByPosition(i, j - 1).getFormula = '' then begin sg_import.Cells[i, j] := ''; end; end; end; Inc(Counter, 1); if Counter < TotCell then begin pb_import.Position := Counter + 1; pb_import.Position := Counter; end else begin pb_import.Max := Counter + 1; pb_import.Position := Counter + 1; pb_import.Max := Counter; end; end; Application.ProcessMessages; end; try OOExec.Close(false); OpenDesktop.Terminate; finally OpenOffice := Unassigned; Screen.Cursor := crDefault; SetFocus; end; end; { case AnsiIndexStr(conteudo, ['devedores', 'titulos', 'misto']) of 0: begin pc_import.ActivePageIndex := 0; PovoaCB(tabDevedores); end; 1: begin pc_import.ActivePageIndex := 1; PovoaCB(tabTitulos); end; 2: begin pc_import.ActivePageIndex := 0; PovoaCB(tabDevedores); PovoaCB(tabTitulos); end; end; } pc_import.ActivePageIndex := 0; PovoaCB(tabDevedores); PovoaCB(tabTitulos); // linhaList := TStringList.Create; // with linhaList do // begin // for c := 0 to RCount - 1 do // begin // Add(inttostr(c + 1)); // end; // end; // // cbx_primeiralinha.Items.BeginUpdate; // try // begin // cbx_primeiralinha.Items.AddStrings(linhaList); // end; // finally // cbx_primeiralinha.Items.EndUpdate; // linhaList.Clear; // end; stbStatus.Panels[0].Text := 'Número de linhas: ' + inttostr(RCount - 1) + '.'; stbStatus.Panels[1].Text := 'Arquivo: ' + odExcel.FileName; end; function TimpDevedores.CmtoPix(cm: double): integer; var ppcm: double; begin ppcm := Screen.PixelsPerInch / 2540; Result := Trunc(ppcm * cm); end; procedure TimpDevedores.FormCreate(Sender: TObject); begin inherited; pc_import.ActivePageIndex := 0; with dtmSystem do begin if not tblDevedores.active then begin tblDevedores.Open; end else begin tblDevedores.Refresh; end; if not tblEmail.active then begin tblEmail.Open; end else begin tblEmail.Refresh; end; if not tblEnderecos.active then begin tblEnderecos.Open; end else begin tblEnderecos.Refresh; end; if not tblTelefones.active then begin tblTelefones.Open; end else begin tblTelefones.Refresh; end; if not tblCidades.active then begin tblCidades.Open; end; if not tblEstados.active then begin tblEstados.Open; end; if not tblCHGEmpresa.active then begin tblCHGEmpresa.Open; end else begin tblCHGEmpresa.Refresh; end; if not tblTitulos.active then begin tblTitulos.Open; end else begin tblTitulos.Refresh; end; if not tblHistorico.active then begin tblHistorico.Open; end else begin tblHistorico.Refresh; end; if not tblDuplicados.active then begin tblDuplicados.Open; end else begin tblDuplicados.Refresh; end; end; end; procedure TimpDevedores.ImportarLayout; var lista: TStringList; cpf_helper, cnpj_helper, string_helper, cep_helper, k, tel, field, helper: string; i, j, repetido, resp: integer; adiciona, achou_cidade, achou_estado: boolean; h, Counter: integer; hist_postou: boolean; begin with dtmSystem do begin if tblDuplicados.RecordCount <> 0 then begin tblDuplicados.Close; zqryDuplicados.Close; zqryDuplicados.SQL.Text := 'delete from SYS_DUPLICADOS'; zqryDuplicados.ExecSQL; end; tblDuplicados.Open; end; { Nome; Nome do Pai; Nome da Mãe; CPF/CNPJ; RG; "Email"; Data de Nascimento; Endereço; Número; Complemento; Bairro; Cidade; Estado; CEP; Telefone1; Telefone2; Telefone3; Produto; Valor; Data de Vencimento; Código do Devedor; É cheque; Banco; Nº do Cheque; Motivo; DDD1; DDD2; DDD3; Obs deTítulo; Obs Devedor } repetido := 0; adiciona := true; lista := TStringList.Create; // try lista.Clear; lista.Delimiter := ';'; lista.DelimitedText := dtmSystem.tblLayoutsSTR_CAMPOS.AsString; // finally pb_import.Position := 0; pb_import.Max := sg_import.RowCount - 2; Counter := 0; if strtoint(lista[3]) = 0 then begin Messagedlg ('Por favor carregue um layout que possua CPF/CNPJ do Devedor em suas configurações.', mtWarning, [mbOK], 0); abort; end else begin for i := 2 to sg_import.RowCount - 1 do begin sg_import.Row := i; achou_cidade := false; achou_estado := false; try k := lista[3]; if sg_import.Cells[strtoint(lista[3]) - 1, i] = '' then begin showmessage('O devedor nº ' + inttostr(i - 1) + ' não possuia CPF. Pulando para o próximo.'); continue; end; string_helper := StringReplace(sg_import.Cells[strtoint(lista[3]) - 1, i], '.', '', [rfReplaceAll, rfIgnoreCase]); string_helper := StringReplace(string_helper, '-', '', [rfReplaceAll, rfIgnoreCase]); string_helper := StringReplace(string_helper, '/', '', [rfReplaceAll, rfIgnoreCase]); string_helper := StringReplace(string_helper, ' ', '', [rfReplaceAll, rfIgnoreCase]); cpf_helper := 'aaa'; cnpj_helper := 'aaa'; helper := 'aaa'; field := ''; if length(string_helper) = 11 then begin cpf_helper := copy(string_helper, 1, 3) + '.' + copy(string_helper, 4, 3) + '.' + copy(string_helper, 7, 3) + '-' + copy(string_helper, 10, 2); helper := cpf_helper; field := 'CD_CPF'; end; if length(string_helper) = 14 then begin cnpj_helper := copy(string_helper, 1, 2) + '.' + copy(string_helper, 3, 3) + '.' + copy(string_helper, 6, 3) + '/' + copy(string_helper, 9, 4) + '-' + copy(string_helper, 13, 2); helper := cnpj_helper; field := 'CD_CNPJ'; end; if length(string_helper) < 11 then begin string_helper := RightStr(StringOfChar('0', 11 - length(string_helper) ) + string_helper, 11); cpf_helper := copy(string_helper, 1, 3) + '.' + copy(string_helper, 4, 3) + '.' + copy(string_helper, 7, 3) + '-' + copy(string_helper, 10, 2); helper := cpf_helper; field := 'CD_CPF'; end; // cpf_helper := FormatMaskText('000\.000\.000\-00;0;', string_helper); // cnpj_helper := FormatMaskText('00\.000\.000\/0000\-00;0;', // string_helper); with dtmSystem do begin if (tblDevedores.Locate(field, helper, [])) then begin if (lista[1] <> '0') or (lista[2] <> '0') or (lista[29] <> '0') then begin tblDevedores.Edit; k := lista[1]; if (lista[1] <> '0') and (tblDevedoresTX_PAI.AsString = '') then begin tblDevedoresTX_PAI.AsString := sg_import.Cells [strtoint(lista[1]) - 1, i]; end else begin if lista[1] <> '0' then begin tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + sLineBreak + 'Pai: ' + sg_import.Cells [strtoint(lista[1]) - 1, i]; end; end; k := lista[2]; if (lista[2] <> '0') and (tblDevedoresTX_MAE.AsString = '') then begin tblDevedoresTX_MAE.AsString := sg_import.Cells [strtoint(lista[2]) - 1, i]; end else begin if lista[2] <> '0' then begin tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + sLineBreak + 'Mãe: ' + sg_import.Cells [strtoint(lista[2]) - 1, i]; end; end; k := lista[29]; if (lista[29] <> '0') and (tblDevedoresTL_MEMO.AsString = '') then begin tblDevedoresTL_MEMO.AsString := 'Obs Extra: ' + sg_import.Cells [strtoint(lista[29]) - 1, i]; end else begin if lista[29] <> '0' then begin tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + sLineBreak + 'Obs Extra: ' + sg_import.Cells [strtoint(lista[29]) - 1, i]; end; end; k := lista[30]; if lista[30] <> '0' then begin tblDevedoresCD_DEVEDOR.AsString := sg_import.Cells[strtoint(lista[30]) - 1, i]; end; tblDevedores.Post; end; k := lista[19]; if (lista[19] <> '0') then begin k := lista[18]; if (tblTitulos.Locate ('DT_VENCIMENTO;ID_EMPRESA;VL_TITULO;ID_DEVEDOR', VarArrayOf([StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]), tblCHGEmpresaID_EMPRESA.AsInteger, sg_import.Cells[strtoint(lista[18]) - 1, i], tblDevedoresID_DEVEDOR.AsInteger]), [])) then begin tblDuplicados.Append; tblDuplicadosTX_NOMEDEVEDOR.AsString := tblDevedoresTX_NOME.AsString; tblDuplicadosCD_CPF.AsString := tblDevedoresCD_CPF.AsString; tblDuplicadosCD_CNPJ.AsString := tblDevedoresCD_CNPJ.AsString; tblDuplicadosTX_NOMETITULO.AsString := sg_import.Cells[strtoint(lista[18]) - 1, i]; tblDuplicadosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); k := lista[19]; tblDuplicadosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); case repetido of 0: begin resp := Messagedlg('O título com vencimento "' + sg_import.Cells[strtoint(lista[19]) - 1, i] + '" pode ser repetido.' + #13 + '(Mesma data de Vencimento que outro título)' + #13 + '' + ' Deseja adicioná-lo mesmo assim?', mtWarning, [mbYes, mbYesToAll, mbNo, mbNoToAll], 0); case resp of mrYes: begin repetido := 0; adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; mrNo: begin repetido := 0; adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; mrYesToAll: begin repetido := 1; adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; mrNoToAll: begin repetido := 2; adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; end; end; 1: begin adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; 2: begin adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; end; tblDuplicados.Post; if adiciona = true then begin tblTitulos.Append; tblTitulosID_EMPRESA.AsInteger := id_empimport; tblTitulosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); tblTitulosTP_SITUACAO.AsString := 'A'; tblTitulosDT_ENTRADA.AsDateTime := Date; k := lista[17]; if sg_import.Cells[strtoint(lista[17]) - 1, i] <> '0' then begin tblTitulosTX_PRODUTO.AsString := sg_import.Cells[strtoint(lista[17]) - 1, i]; end; k := lista[19]; if sg_import.Cells[strtoint(lista[19]) - 1, i] <> '0' then begin tblTitulosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); end; k := lista[20]; if lista[20] <> '0' then begin if sg_import.Cells[strtoint(lista[20]) - 1, i] <> '0' then begin tblTitulosCD_DEVEDOR.AsString := sg_import.Cells[strtoint(lista[20]) - 1, i]; end; end; k := lista[21]; if lista[21] <> '0' then begin if sg_import.Cells[strtoint(lista[21]) - 1, i] = 'S' then begin tblTitulosTP_CHEQUE.AsString := 'S'; k := lista[22]; if sg_import.Cells[strtoint(lista[22]) - 1, i] <> '0' then begin tblTitulosID_BANCO.AsString := sg_import.Cells[strtoint(lista[22]) - 1, i]; end; k := lista[23]; if sg_import.Cells[strtoint(lista[23]) - 1, i] <> '' then begin tblTitulosTX_NRCHEQUE.AsString := sg_import.Cells[strtoint(lista[23]) - 1, i]; end; k := lista[24]; if sg_import.Cells[strtoint(lista[24]) - 1, i] <> '0' then begin tblTitulosTP_MOTIVO.AsString := sg_import.Cells[strtoint(lista[24]) - 1, i]; end; end else begin tblTitulosTP_CHEQUE.AsString := 'N'; end; end; k := lista[28]; if lista[28] <> '0' then begin tblTitulosTX_OBS.AsString := sg_import.Cells [strtoint(lista[28]) - 1, i]; end; k := lista[31]; if lista[31] <> '0' then begin if sg_import.Cells[strtoint(lista[31]) - 1, i] <> '0' then begin tblTitulosDT_PAGAMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[31]) - 1, i]); tblTitulosTP_SITUACAO.AsString := 'QC'; tblTitulosVL_CORRIGIDO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells [strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); end; end; tblTitulos.Post; if not tblHistorico.active then begin tblHistorico.Open; end; tblHistorico.Append; tblHistoricoID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblHistoricoID_TITULO.AsInteger := tblTitulosID_TITULO.AsInteger; // tblHistoricoID_PROVIDENCIA.AsInteger := 52; tblHistoricoID_PROVIDENCIA.AsInteger := frmEscolheLayout.id_prov; tblHistoricoDT_CONTATO.AsDateTime := Date; tblHistorico.Post; end else begin // break; end; end else begin tblTitulos.Append; tblTitulosID_EMPRESA.AsInteger := id_empimport; tblTitulosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); tblTitulosTP_SITUACAO.AsString := 'A'; tblTitulosDT_ENTRADA.AsDateTime := Date; k := lista[17]; if sg_import.Cells[strtoint(lista[17]) - 1, i] <> '0' then begin tblTitulosTX_PRODUTO.AsString := sg_import.Cells[strtoint(lista[17]) - 1, i]; end; k := lista[19]; if sg_import.Cells[strtoint(lista[19]) - 1, i] <> '0' then begin tblTitulosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); end; k := lista[20]; if lista[20] <> '0' then begin if sg_import.Cells[strtoint(lista[20]) - 1, i] <> '0' then begin tblTitulosCD_DEVEDOR.AsString := sg_import.Cells[strtoint(lista[20]) - 1, i]; end; end; k := lista[21]; if lista[21] <> '0' then begin if sg_import.Cells[strtoint(lista[21]) - 1, i] = 'S' then begin tblTitulosTP_CHEQUE.AsString := 'S'; k := lista[22]; if sg_import.Cells[strtoint(lista[22]) - 1, i] <> '0' then begin tblTitulosID_BANCO.AsString := sg_import.Cells[strtoint(lista[22]) - 1, i]; end; k := lista[23]; if sg_import.Cells[strtoint(lista[23]) - 1, i] <> '' then begin tblTitulosTX_NRCHEQUE.AsString := sg_import.Cells[strtoint(lista[23]) - 1, i]; end; k := lista[24]; if sg_import.Cells[strtoint(lista[24]) - 1, i] <> '0' then begin tblTitulosTP_MOTIVO.AsString := sg_import.Cells[strtoint(lista[24]) - 1, i]; end; end else begin tblTitulosTP_CHEQUE.AsString := 'N'; end; end; k := lista[28]; if lista[28] <> '0' then begin tblTitulosTX_OBS.AsString := sg_import.Cells [strtoint(lista[28]) - 1, i]; end; k := lista[31]; if lista[31] <> '0' then begin if sg_import.Cells[strtoint(lista[31]) - 1, i] <> '0' then begin tblTitulosDT_PAGAMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[31]) - 1, i]); tblTitulosTP_SITUACAO.AsString := 'QC'; tblTitulosVL_CORRIGIDO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells [strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); end; end; tblTitulos.Post; if not tblHistorico.active then begin tblHistorico.Open; end; tblHistorico.Append; tblHistoricoID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblHistoricoID_TITULO.AsInteger := tblTitulosID_TITULO.AsInteger; // tblHistoricoID_PROVIDENCIA.AsInteger := 52; tblHistoricoID_PROVIDENCIA.AsInteger := frmEscolheLayout.id_prov; tblHistoricoDT_CONTATO.AsDateTime := Date; tblHistorico.Post; end; end; k := lista[5]; if lista[5] <> '0' then begin if not tblEmail.Locate('TX_EMAIL', sg_import.Cells[strtoint(lista[5]) - 1, i], []) then begin tblEmail.Append; tblEmailTX_EMAIL.AsString := sg_import.Cells [strtoint(lista[5]) - 1, i]; tblEmailID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblEmail.Post; end; // tblDevedorestx_email.AsString := sg_import.Cells // [strtoint(lista[5]) - 1, i]; end; k := lista[7]; if lista[7] <> '0' then begin if not tblEnderecos.Locate('TX_LOGRADOURO;ID_DEVEDOR', VarArrayOf([sg_import.Cells[strtoint(lista[7]) - 1, i], tblDevedoresID_DEVEDOR.AsInteger]), [loCaseInsensitive, loPartialKey]) then begin tblEnderecos.Append; tblEnderecosTX_LOGRADOURO.AsString := sg_import.Cells[strtoint(lista[7]) - 1, i]; k := lista[8]; if lista[8] <> '0' then begin tblEnderecosNR_NUMERO.AsString := sg_import.Cells[strtoint(lista[8]) - 1, i]; end; k := lista[9]; if lista[9] <> '0' then begin tblEnderecosTX_COMPLEMENTO.AsString := sg_import.Cells[strtoint(lista[9]) - 1, i]; end; k := lista[10]; if lista[10] <> '0' then begin tblEnderecosTX_BAIRRO.AsString := sg_import.Cells[strtoint(lista[10]) - 1, i]; end; k := lista[12]; if lista[12] <> '0' then begin tblEstados.First; while (not(tblEstados.Eof)) and (not(achou_estado)) do begin if (UpperCase(OStripAccents(tblEstadosTX_NOME.AsString)) = UpperCase(OStripAccents(sg_import.Cells [strtoint(lista[12]) - 1, i]))) or (UpperCase(OStripAccents(tblEstadosTX_SIGLA.AsString)) = UpperCase(OStripAccents(sg_import.Cells [strtoint(lista[12]) - 1, i]))) then begin achou_estado := true; end else begin tblEstados.Next; end; end; if achou_estado then begin tblEnderecosID_ESTADO.AsInteger := tblEstadosID_ESTADO.AsInteger; tblEnderecosTX_ESTADO.AsString := tblEstadosTX_NOME.AsString; end else begin { tblEnderecos.Post; tblDevedores.Edit; tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + 'Houve um erro na importação do estado deste devedor.' + ' Por favor corrija manualmente.'; tblDevedores.Post; tblEnderecos.Edit; } end; end; k := lista[11]; if lista[11] <> '0' then begin tblCidades.First; while (not(tblCidades.Eof)) and (not(achou_cidade)) do begin if UpperCase(OStripAccents(tblCidadesTX_NOME.AsString)) = UpperCase (OStripAccents(sg_import.Cells[strtoint(lista[11]) - 1, i])) then begin achou_cidade := true; end else begin tblCidades.Next; end; end; if achou_cidade then begin tblEnderecosID_CIDADE.AsInteger := tblCidadesID_CIDADE.AsInteger; tblEnderecosTX_CIDADE.AsString := tblCidadesTX_NOME.AsString; end else begin { tblEnderecos.Post; tblDevedores.Edit; tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + 'Houve um erro na importação da cidade deste devedor.' + ' Por favor corrija manualmente.'; tblDevedores.Post; tblEnderecos.Edit; } end; end; k := lista[13]; if lista[13] <> '0' then begin cep_helper := sg_import.Cells[strtoint(lista[13]) - 1, i]; cep_helper := StringReplace(cep_helper, '.', '', [rfReplaceAll]); cep_helper := StringReplace(cep_helper, '-', '', [rfReplaceAll]); tblEnderecosTX_CEP.AsString := cep_helper; end; tblEnderecos.Post; end; end; k := lista[14]; if lista[14] <> '0' then begin if sg_import.Cells[strtoint(lista[14]) - 1, i] <> '' then begin tel := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[14]) - 1, i]); if not tblTelefones.Locate('NR_NUMERO;ID_DEVEDOR', VarArrayOf([tel, dtmSystem.id_devedor]), [loCaseInsensitive]) then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[14]) - 1, i]); if lista[25] <> '0' then begin if sg_import.Cells[strtoint(lista[25]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[25]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; end; k := lista[15]; if lista[15] <> '0' then begin if sg_import.Cells[strtoint(lista[15]) - 1, i] <> '' then begin if not tblTelefones.Locate('NR_NUMERO;ID_DEVEDOR', VarArrayOf([dtmSystem.FormatTelefone(sg_import.Cells [strtoint(lista[15]) - 1, i]), tblDevedoresID_DEVEDOR.AsInteger]), []) then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[15]) - 1, i]); if lista[26] <> '0' then begin if sg_import.Cells[strtoint(lista[25]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[26]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; end; k := lista[16]; if lista[16] <> '0' then begin if sg_import.Cells[strtoint(lista[16]) - 1, i] <> '' then begin if not tblTelefones.Locate('NR_NUMERO;ID_DEVEDOR', VarArrayOf([dtmSystem.FormatTelefone(sg_import.Cells [strtoint(lista[16]) - 1, i]), tblDevedoresID_DEVEDOR.AsInteger]), []) then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[16]) - 1, i]); if lista[27] <> '0' then begin if sg_import.Cells[strtoint(lista[27]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[27]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; end; end else begin tblDevedores.Append; tblDevedoresDT_CADASTRO.AsDateTime := Date; k := lista[0]; if lista[0] <> '0' then begin tblDevedoresTX_NOME.AsString := OStripAccents(sg_import.Cells[strtoint(lista[0]) - 1, i]); end; k := lista[1]; if lista[1] <> '0' then begin tblDevedoresTX_PAI.AsString := sg_import.Cells [strtoint(lista[1]) - 1, i]; end; k := lista[2]; if lista[2] <> '0' then begin tblDevedoresTX_MAE.AsString := sg_import.Cells [strtoint(lista[2]) - 1, i]; end; k := lista[3]; if lista[3] <> '0' then begin if length(string_helper) = 11 then begin tblDevedoresCD_CPF.AsString := cpf_helper; tblDevedoresTP_CLIENTE.AsString := 'F' end else begin tblDevedoresCD_CNPJ.AsString := cnpj_helper; tblDevedoresTP_CLIENTE.AsString := 'J' end; end; k := lista[4]; if lista[4] <> '0' then begin tblDevedoresCD_RG.AsString := sg_import.Cells [strtoint(lista[4]) - 1, i]; end; k := lista[6]; if lista[6] <> '0' then begin if (ansipos('/', sg_import.Cells[strtoint(lista[6]) - 1, i]) = 0) or (sg_import.Cells[strtoint(lista[6]) - 1, i] = '') then begin tblDevedoresDT_NASC.Clear; end else begin tblDevedoresDT_NASC.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[6]) - 1, i]); end; end; k := lista[29]; if (lista[29] <> '0') and (tblDevedoresTL_MEMO.AsString = '') then begin tblDevedoresTL_MEMO.AsString := 'Obs Extra: ' + sg_import.Cells [strtoint(lista[29]) - 1, i] end else begin if lista[29] <> '0' then begin tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + sLineBreak + 'Obs Extra: ' + sg_import.Cells [strtoint(lista[29]) - 1, i]; end; end; k := lista[30]; if lista[30] <> '0' then begin tblDevedoresCD_DEVEDOR.AsString := sg_import.Cells [strtoint(lista[30]) - 1, i]; end; tblDevedores.Post; k := lista[5]; if lista[5] <> '0' then begin if not tblEmail.Locate('TX_EMAIL', sg_import.Cells[strtoint(lista[5]) - 1, i], []) then begin tblEmail.Append; tblEmailTX_EMAIL.AsString := sg_import.Cells [strtoint(lista[5]) - 1, i]; tblEmailID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblEmail.Post; end; // tblDevedorestx_email.AsString := sg_import.Cells // [strtoint(lista[5]) - 1, i]; end; k := lista[7]; if lista[7] <> '0' then begin tblEnderecos.Append; tblEnderecosTX_LOGRADOURO.AsString := sg_import.Cells[strtoint(lista[7]) - 1, i]; k := lista[8]; if lista[8] <> '0' then begin tblEnderecosNR_NUMERO.AsString := sg_import.Cells[strtoint(lista[8]) - 1, i]; end; k := lista[9]; if lista[9] <> '0' then begin tblEnderecosTX_COMPLEMENTO.AsString := sg_import.Cells[strtoint(lista[9]) - 1, i]; end; k := lista[10]; if lista[10] <> '0' then begin tblEnderecosTX_BAIRRO.AsString := sg_import.Cells[strtoint(lista[10]) - 1, i]; end; k := lista[12]; if lista[12] <> '0' then begin tblEstados.First; while (not(tblEstados.Eof)) and (not(achou_estado)) do begin if (UpperCase(OStripAccents(tblEstadosTX_NOME.AsString)) = UpperCase(OStripAccents(sg_import.Cells[strtoint(lista[12] ) - 1, i]))) or (UpperCase(OStripAccents(tblEstadosTX_SIGLA.AsString)) = UpperCase(OStripAccents(sg_import.Cells[strtoint(lista[12] ) - 1, i]))) then begin achou_estado := true; end else begin tblEstados.Next; end; end; if achou_estado then begin tblEnderecosID_ESTADO.AsInteger := tblEstadosID_ESTADO.AsInteger; tblEnderecosTX_ESTADO.AsString := tblEstadosTX_NOME.AsString; end else begin { tblEnderecos.Post; tblDevedores.Edit; tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + 'Houve um erro na importação do estado deste devedor.' + ' Por favor corrija manualmente.'; tblDevedores.Post; tblEnderecos.Edit; } end; end; k := lista[11]; if lista[11] <> '0' then begin tblCidades.First; while (not(tblCidades.Eof)) and (not(achou_cidade)) do begin if UpperCase(OStripAccents(tblCidadesTX_NOME.AsString)) = UpperCase (OStripAccents(sg_import.Cells[strtoint(lista[11]) - 1, i])) then begin achou_cidade := true; end else begin tblCidades.Next; end; end; if achou_cidade then begin tblEnderecosID_CIDADE.AsInteger := tblCidadesID_CIDADE.AsInteger; tblEnderecosTX_CIDADE.AsString := tblCidadesTX_NOME.AsString; end else begin { tblEnderecos.Post; tblDevedores.Edit; tblDevedoresTL_MEMO.AsString := tblDevedoresTL_MEMO.AsString + 'Houve um erro na importação da cidade deste devedor.' + ' Por favor corrija manualmente.'; tblDevedores.Post; tblEnderecos.Edit; } end; end; k := lista[13]; if lista[13] <> '0' then begin cep_helper := sg_import.Cells[strtoint(lista[13]) - 1, i]; cep_helper := StringReplace(cep_helper, '.', '', [rfReplaceAll]); cep_helper := StringReplace(cep_helper, '-', '', [rfReplaceAll]); tblEnderecosTX_CEP.AsString := cep_helper; end; tblEnderecos.Post; end; k := lista[14]; if lista[14] <> '0' then begin if sg_import.Cells[strtoint(lista[14]) - 1, i] <> '' then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[14]) - 1, i]); if lista[25] <> '0' then begin if sg_import.Cells[strtoint(lista[25]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[25]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; k := lista[15]; if lista[15] <> '0' then begin if sg_import.Cells[strtoint(lista[15]) - 1, i] <> '' then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[15]) - 1, i]); if lista[26] <> '0' then begin if sg_import.Cells[strtoint(lista[26]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[26]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; k := lista[16]; if lista[16] <> '0' then begin if sg_import.Cells[strtoint(lista[16]) - 1, i] <> '' then begin tblTelefones.Append; tblTelefonesNR_NUMERO.AsString := dtmSystem.FormatTelefone (sg_import.Cells[strtoint(lista[16]) - 1, i]); if lista[27] <> '0' then begin if sg_import.Cells[strtoint(lista[27]) - 1, i] <> '' then begin tblTelefonesNR_DDD.AsString := sg_import.Cells[strtoint(lista[27]) - 1, i]; end; end; if length(tblTelefonesNR_NUMERO.AsString) = 10 then begin tblTelefonesTP_TIPOTEL.AsString := 'M'; end else if length(tblTelefonesNR_NUMERO.AsString) = 9 then begin tblTelefonesTP_TIPOTEL.AsString := 'F'; end; tblTelefones.Post; end; end; k := lista[19]; if (lista[19] <> '0') then begin k := lista[18]; if (tblTitulos.Locate ('DT_VENCIMENTO;ID_EMPRESA;VL_TITULO;ID_DEVEDOR', VarArrayOf([StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]), tblCHGEmpresaID_EMPRESA.AsInteger, sg_import.Cells[strtoint(lista[18]) - 1, i], tblDevedoresID_DEVEDOR.AsInteger]), [])) then begin tblDuplicados.Append; tblDuplicadosTX_NOMEDEVEDOR.AsString := tblDevedoresTX_NOME.AsString; tblDuplicadosCD_CPF.AsString := tblDevedoresCD_CPF.AsString; tblDuplicadosCD_CNPJ.AsString := tblDevedoresCD_CNPJ.AsString; tblDuplicadosTX_NOMETITULO.AsString := sg_import.Cells[strtoint(lista[18]) - 1, i]; tblDuplicadosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll]));; tblDuplicadosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); case repetido of 0: begin resp := Messagedlg('O título com vencimento "' + sg_import.Cells[strtoint(lista[19]) - 1, i] + '" pode ser repetido.' + #13 + '(Mesma data de Vencimento que outro título)' + #13 + '' + ' Deseja adicioná-los mesmo assim?', mtWarning, [mbYes, mbYesToAll, mbNo, mbNoToAll], 0); case resp of mrYes: begin repetido := 0; adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; mrNo: begin repetido := 0; adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; mrYesToAll: begin repetido := 1; adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; mrNoToAll: begin repetido := 2; adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; end; end; 1: begin adiciona := true; tblDuplicadosTP_ACAO.AsString := 'S'; // adicionou end; 2: begin adiciona := false; tblDuplicadosTP_ACAO.AsString := 'N'; // ñ adicionou end; end; tblDuplicados.Post; if adiciona = true then begin tblTitulos.Append; tblTitulosID_EMPRESA.AsInteger := id_empimport; tblTitulosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); tblTitulosTP_SITUACAO.AsString := 'A'; tblTitulosDT_ENTRADA.AsDateTime := Date; k := lista[17]; if sg_import.Cells[strtoint(lista[17]) - 1, i] <> '0' then begin tblTitulosTX_PRODUTO.AsString := sg_import.Cells[strtoint(lista[17]) - 1, i]; end; k := lista[19]; if sg_import.Cells[strtoint(lista[19]) - 1, i] <> '0' then begin tblTitulosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); end; k := lista[20]; if lista[20] <> '0' then begin if sg_import.Cells[strtoint(lista[20]) - 1, i] <> '0' then begin tblTitulosCD_DEVEDOR.AsString := sg_import.Cells[strtoint(lista[20]) - 1, i]; end; end; k := lista[21]; if lista[21] <> '0' then begin if sg_import.Cells[strtoint(lista[21]) - 1, i] = 'S' then begin tblTitulosTP_CHEQUE.AsString := 'S'; k := lista[22]; if sg_import.Cells[strtoint(lista[22]) - 1, i] <> '0' then begin tblTitulosID_BANCO.AsString := sg_import.Cells[strtoint(lista[22]) - 1, i]; end; k := lista[23]; if sg_import.Cells[strtoint(lista[23]) - 1, i] <> '' then begin tblTitulosTX_NRCHEQUE.AsString := sg_import.Cells[strtoint(lista[23]) - 1, i]; end; k := lista[24]; if sg_import.Cells[strtoint(lista[24]) - 1, i] <> '0' then begin tblTitulosTP_MOTIVO.AsString := sg_import.Cells[strtoint(lista[24]) - 1, i]; end; end else begin tblTitulosTP_CHEQUE.AsString := 'N'; end; end; k := lista[28]; if lista[28] <> '0' then begin tblTitulosTX_OBS.AsString := sg_import.Cells [strtoint(lista[28]) - 1, i]; end; k := lista[31]; if lista[31] <> '0' then begin if sg_import.Cells[strtoint(lista[31]) - 1, i] <> '0' then begin tblTitulosDT_PAGAMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[31]) - 1, i]); tblTitulosTP_SITUACAO.AsString := 'QC'; tblTitulosVL_CORRIGIDO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells [strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); end; end; tblTitulos.Post; if not tblHistorico.active then begin tblHistorico.Open; end; tblHistorico.Append; tblHistoricoID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblHistoricoID_TITULO.AsInteger := tblTitulosID_TITULO.AsInteger; // tblHistoricoID_PROVIDENCIA.AsInteger := 52; tblHistoricoID_PROVIDENCIA.AsInteger := frmEscolheLayout.id_prov; tblHistoricoDT_CONTATO.AsDateTime := Date; tblHistorico.Post; end else begin // break; end; end else begin tblTitulos.Append; tblTitulosID_EMPRESA.AsInteger := id_empimport; tblTitulosVL_TITULO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells[strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); tblTitulosTP_SITUACAO.AsString := 'A'; tblTitulosDT_ENTRADA.AsDateTime := Date; k := lista[17]; if sg_import.Cells[strtoint(lista[17]) - 1, i] <> '0' then begin tblTitulosTX_PRODUTO.AsString := sg_import.Cells[strtoint(lista[17]) - 1, i]; end; k := lista[19]; if sg_import.Cells[strtoint(lista[19]) - 1, i] <> '0' then begin tblTitulosDT_VENCIMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[19]) - 1, i]); end; k := lista[20]; if lista[20] <> '0' then begin if sg_import.Cells[strtoint(lista[20]) - 1, i] <> '0' then begin tblTitulosCD_DEVEDOR.AsString := sg_import.Cells[strtoint(lista[20]) - 1, i]; end; end; k := lista[21]; if lista[21] <> '0' then begin if sg_import.Cells[strtoint(lista[21]) - 1, i] = 'S' then begin tblTitulosTP_CHEQUE.AsString := 'S'; k := lista[22]; if sg_import.Cells[strtoint(lista[22]) - 1, i] <> '0' then begin tblTitulosID_BANCO.AsString := sg_import.Cells[strtoint(lista[22]) - 1, i]; end; k := lista[23]; if sg_import.Cells[strtoint(lista[23]) - 1, i] <> '' then begin tblTitulosTX_NRCHEQUE.AsString := sg_import.Cells[strtoint(lista[23]) - 1, i]; end; k := lista[24]; if sg_import.Cells[strtoint(lista[24]) - 1, i] <> '0' then begin tblTitulosTP_MOTIVO.AsString := sg_import.Cells[strtoint(lista[24]) - 1, i]; end; end else begin tblTitulosTP_CHEQUE.AsString := 'N'; end; end; k := lista[28]; if lista[28] <> '0' then begin tblTitulosTX_OBS.AsString := sg_import.Cells [strtoint(lista[28]) - 1, i]; end; k := lista[31]; if lista[31] <> '0' then begin if sg_import.Cells[strtoint(lista[31]) - 1, i] <> '0' then begin tblTitulosDT_PAGAMENTO.AsDateTime := StrToDate(sg_import.Cells[strtoint(lista[31]) - 1, i]); tblTitulosTP_SITUACAO.AsString := 'QC'; tblTitulosVL_CORRIGIDO.AsCurrency := StrtoCurr(StringReplace(sg_import.Cells [strtoint(lista[18]) - 1, i], '.', ',', [rfReplaceAll])); end; end; tblTitulos.Post; if not tblHistorico.active then begin tblHistorico.Open; end; tblHistorico.Append; tblHistoricoID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger; tblHistoricoID_TITULO.AsInteger := tblTitulosID_TITULO.AsInteger; // tblHistoricoID_PROVIDENCIA.AsInteger := 52; tblHistoricoID_PROVIDENCIA.AsInteger := frmEscolheLayout.id_prov; tblHistoricoDT_CONTATO.AsDateTime := Date; tblHistorico.Post; end; end; end; end; except on E: Exception do begin if (Pos(E.Message, 'PRYMARY OR UNIQUE') > 0) and (Pos(E.Message, 'CHG_HISTORICO') > 0) then begin hist_postou := false; while not(hist_postou) do begin try dtmSystem.tblHistorico.Post; hist_postou := true; except hist_postou := false; end; end; end else begin if Messagedlg('Houve um erro ao tentar importar o dado na linha: ' + inttostr(i) + ', coluna: ' + k + '. Erro: ' + E.Message + sLineBreak + 'Deseja continuar?', mtError, [mbYes, mbNo], 0) = mrNo then begin // dtmSystem.tblDevedores.Delete; with dtmSystem do begin tblDevedores.EnableControls; tblEnderecos.EnableControls; tblTelefones.EnableControls; tblCidades.EnableControls; tblEstados.EnableControls; tblCHGEmpresa.EnableControls; tblTitulos.EnableControls; tblHistorico.EnableControls; tblDuplicados.EnableControls; end; abort; end else begin // dtmSystem.tblDevedores.Delete; end; end; // showmessage('Houve um erro ao tentar importar o dado na linha: ' + // inttostr(i) + ', coluna: ' + k + '. Erro: ' + E.Message); end; end; Inc(Counter, 1); if Counter < (sg_import.RowCount - 2) then begin pb_import.Position := Counter + 1; pb_import.Position := Counter; end else begin pb_import.Max := Counter + 1; pb_import.Position := Counter + 1; pb_import.Max := Counter; end; Application.ProcessMessages; end; end; with dtmSystem do begin tblDevedores.EnableControls; tblEnderecos.EnableControls; tblTelefones.EnableControls; tblCidades.EnableControls; tblEstados.EnableControls; tblCHGEmpresa.EnableControls; tblTitulos.EnableControls; tblHistorico.EnableControls; tblDuplicados.EnableControls; end; // end; end; procedure TimpDevedores.imp_LayoutClick(Sender: TObject); begin Messagedlg('Certifique-se de que o arquivo' + ' a ser importado corresponde ao layout a ser escolhido. CPFs e CNPJ devem conter ''0''s a esquerda.', mtWarning, [mbOK], 0); dtmSystem.tblLayouts.Open; frmEscolheLayout := TfrmEscolheLayout.Create(self); with frmEscolheLayout do begin ShowModal; if escolheu = true then begin try Carregar; ImportarLayout; if Messagedlg ('Deseja montar um relatório de entrada? (Ele só será preenchido caso novos títulos tenham sido inseridos)', mtInformation, mbYesNo, 0) = mrYes then begin relBordero := TrelBordero.Create(self); with relBordero do begin with zqryRel.SQL do begin Clear; Add('select'); Add('A.id_devedor,'); Add('A.tx_nome as NOME,'); Add('case when a.tp_cliente = ''F'' then A.cd_cpf'); Add('when a.tp_cliente = ''J'' then a.cd_cnpj end as TX_DOCUMENTO,'); Add('A.cd_devedor AS CODIGO,'); Add('B.dt_entrada AS DATA_ENTRADA,'); Add('B.tx_produto AS PRODUTO,'); Add('B.vl_titulo AS VALOR,'); Add('B.dt_vencimento as DATA_VENCIMENTO'); Add('from chg_devedores A'); Add('inner join chg_titulos B'); Add('on (A.id_devedor = B.id_devedor)'); Add('where (B.id_empresa = ' + inttostr(dtmSystem.id_empimport) + ') and'); Add('(CAST(B.dt_entrada AS DATE) >= ' + QuotedStr(FormatDateTime('mm/dd/YYYY', Date)) + ')'); Add('order by A.tx_nome'); end; zqryRel.Open; frBordero.PreviewModal; end; if not dtmSystem.tblDuplicados.active then begin dtmSystem.tblDuplicados.Open; end; if dtmSystem.tblDuplicados.RecordCount <> 0 then begin relDuplicados := TrelDuplicados.Create(self); relDuplicados.frDuplicados.PreviewModal; end; end; cadDevedores.importou := true; except end; end; end; end; procedure TimpDevedores.Layouts1Click(Sender: TObject); begin confLayouts := TconfLayouts.Create(self); confLayouts.ShowModal; end; function TimpDevedores.OStripAccents(const aStr: String): String; type USASCIIString = type AnsiString(20127); // 20127 = us ascii begin Result := String(USASCIIString(aStr)); end; procedure TimpDevedores.PovoaCB(tbSheet: TTabSheet); var i: integer; begin for i := 0 to tbSheet.ControlCount - 1 do begin if tbSheet.Controls[i] is TComboBox then begin with tbSheet.Controls[i] as TComboBox do begin Items.BeginUpdate; try begin Items.Clear; Items.AddStrings(itemList); end; finally Items.EndUpdate; end; end; end; end; end; procedure TimpDevedores.WMMoving(var Msg: TWMMoving); begin end; end.