Ariston Santos Posted March 16, 2017 Report Share Posted March 16, 2017 Olá. Alguém tem código para importar arquivos TDM (de ECFs), que possa compartilhar? Desde já, agradeço. Quote Link to comment Share on other sites More sharing options...
fladimir Posted March 17, 2017 Report Share Posted March 17, 2017 Desculpe a lógica pq qdo fiz na época foi as pressas (kkkk como se nossas demandas não fossem pra ontem...) Espero q ajude, no caso a importação abaixo fiz conforme a necessidade aki, talvez tenha campos q vc precise q não estejam ou alguns q não precise, ai tem q rever o Layout do arquivo q no momento não achei, tem q dar uma procurada na net, mas lembro q acha fácil. /* * Projeto..: ERP * Arquivo..: Aux_Fiscal.prg * Descrição: Importa Mapa Resumo baseado no ATO_TDM_DATA // Modo CONSOLE * Autor....: Fladimir * Data.....: 21-10-2013 */ function ImportaMapaResdoAtoTDM() LOCAL getlist:= {}, nOpcAddouDel xCancelamentos := 0 ; xAcrescimos := 0 ; xDescontos := 0 xST := 0 ; xIS := 0 ; xNT := 0 xAliq1 := 0 ; xVlr_Aliq1 := 0 xAliq2 := 0 ; xVlr_Aliq2 := 0 xAliq3 := 0 ; xVlr_Aliq3 := 0 xAliq4 := 0 ; xVlr_Aliq4 := 0 xAliq5 := 0 ; xVlr_Aliq5 := 0 xAliq6 := 0 ; xVlr_Aliq6 := 0 xAliq7 := 0 ; xVlr_Aliq7 := 0 xAliq8 := 0 ; xVlr_Aliq8 := 0 xAliq9 := 0 ; xVlr_Aliq9 := 0 xAliquota := 0 CLS ALERT('É necessario o arquivo ATO_TDM_DATA.TXT na pasta',{'Ok'}) SET(_SET_DATEFORMAT,"DD/MM/YYYY") SET DATE TO BRITISH // Preciso do Arquivo texto com o nome de: cArqTXT := 'ATO_TDM_DATA.TXT' + SPACE(10) nGTBase := 0 @ 10,05 say 'Arquivo..........................:' get cArqTXT @ 11,05 say 'GT ap¢s ultimo periodo do arquivo:' GET nGTBase PICT '@E 999,999,999.999' READ cArqTXT := ALLTRIM(cArqTXT) cArqPonte := 'Ponte.dbf' FErase(cArqPonte) aStru := { {"Linha" ,'C', 255,0} } DBCREATE(cArqPonte,aStru) Use Ponte ALIAS Ponte shared new APPEND FROM &cArqTXT SDF USE MAPARES ALIAS MAPARES EXCLUSIVE NEW ZAP Ponte->(dbgotop()) While Ponte->(!EOF()) if LEFT(Ponte->Linha,3) == 'E01' .OR.; LEFT(Ponte->Linha,3) == 'E02' .OR.; LEFT(Ponte->Linha,3) == 'E03' .OR.; LEFT(Ponte->Linha,3) == 'E04' .OR.; LEFT(Ponte->Linha,3) == 'E05' .OR.; LEFT(Ponte->Linha,3) == 'E06' .OR.; LEFT(Ponte->Linha,3) == 'E07' .OR.; LEFT(Ponte->Linha,3) == 'E08' .OR.; LEFT(Ponte->Linha,3) == 'E09' .OR.; LEFT(Ponte->Linha,3) == 'E10' Ponte->(dbskip()) LOOP endif if LEFT(Ponte->Linha,3) == 'E11' nGTFin := SUBSTR(Ponte->Linha, 105, 18) nGTFin := Val( nGTFin ) / 100 lE11 := .T. endif if ! lE11 // Se nao tem E11 sinal q o arquivo de origem esta incorreto com o layout Alert('Falha no arquivo processo interrompido') QUIT endif Ponte->(dbskip()) // vai pro(s) E12 While LEFT(Ponte->Linha,3) == 'E12' xNumECF := SUBSTR(Ponte->Linha, 45, 02 ) //-- Campo 05 = Nr Ordem ECF xSerie := SUBSTR(Ponte->Linha, 04, 20 ) //-- Campo 02 = Nr Serie ECF xDataMovZ := SUBSTR(Ponte->Linha, 65, 08 ) //-- Campo 09 20140115 xDataMovZ := RIGHT(xDataMovZ,2) + '/' + SUBSTR(xDataMovZ, 5,2) + '/' + LEFT(xDataMovZ,4) xCRO := SUBSTR(Ponte->Linha, 59, 06 ) //-- Campo 08 CRZ_E12 := SUBSTR(Ponte->Linha, 47, 06 ) //-- Campo 06 xCOO_FIM := SUBSTR(Ponte->Linha, 53, 06 ) //-- Campo 07 xVendaBruta := SUBSTR(Ponte->Linha, 87, 14 ) //-- Campo 12 xVendaBruta := VAL( xVendaBruta) / 100 nRecE12 := Ponte->(recno()) // pra saber qual linha estava no E12 pois as E12 sao seguidas entÆo se 5 reducoes 5 E12 //-- Vai para o proximo E13 While .T. Ponte->(dbskip()) if LEFT(Ponte->Linha,3) == 'E12' // Se ainda é E12 vai pra proxima else EXIT endif end // Tenho q pegar o CRZ do E12 e avaliar se tem E13 com mesma reducao ai processo. xAliq1 := 0 ; xVlr_Aliq1 := 0 xAliq2 := 0 ; xVlr_Aliq2 := 0 xAliq3 := 0 ; xVlr_Aliq3 := 0 xAliq4 := 0 ; xVlr_Aliq4 := 0 xAliq5 := 0 ; xVlr_Aliq5 := 0 xAliq6 := 0 ; xVlr_Aliq6 := 0 xAliq7 := 0 ; xVlr_Aliq7 := 0 xAliq8 := 0 ; xVlr_Aliq8 := 0 xAliq9 := 0 ; xVlr_Aliq9 := 0 While .T. CRZ_E13 := SUBSTR(Ponte->Linha, 47, 6 ) // Define o q é Entao se Campo 7 for Can-T == Cancelament if LEFT(Ponte->Linha,3) == 'E13' .AND. CRZ_E12 == CRZ_E13 // To no E13 ainda se E12 terminou o E13 ai grava o q tiver xCampo7 := SUBSTR(Ponte->Linha, 53, 5 ) // Define o q é Entao se Campo 7 for Can-T == Cancelament xCampo8 := SUBSTR(Ponte->Linha, 60, 13 ) // Valor xCampo8 := VAL(xCampo8) / 100 //Campo 8 se Campo 7 == Fxx if left(xCampo7,3) == 'Can-T' ; xCancelamentos := xCampo8 ; endif if left(xCampo7,2) == 'DT' ; xDescontos := xCampo8 ; endif if left(xCampo7,2) == 'AT' ; xAcrescimos := xCampo8 ; endif if left(xCampo7,1) == 'I' ; xIS := xCampo8 ; endif if left(xCampo7,1) == 'F' ; xST := xCampo8 ; endif if left(xCampo7,1) == 'N' ; xNT := xCampo8 ; endif if VAL(LEFT(xCampo7,2)) > 0 // Tributadas '03T17' // Tributadas nIDAliq := VAL(LEFT(xCampo7,2)) // 03 xAliquota := VAL(ALLTRIM(SUBSTR(xCampo7, 4)) + '00')/100 // 17,00 if nIDAliq == 1 xAliq1 := xAliquota xVlr_Aliq1 := xCampo8 elseif nIDAliq == 2 xAliq2 := xAliquota xVlr_Aliq2 := xCampo8 elseif nIDAliq == 3 xAliq3 := xAliquota xVlr_Aliq3 := xCampo8 elseif nIDAliq == 4 xAliq4 := xAliquota xVlr_Aliq4 := xCampo8 elseif nIDAliq == 5 xAliq5 := xAliquota xVlr_Aliq5 := xCampo8 elseif nIDAliq == 6 xAliq6 := xAliquota xVlr_Aliq6 := xCampo8 elseif nIDAliq == 7 xAliq7 := xAliquota xVlr_Aliq7 := xCampo8 elseif nIDAliq == 8 xAliq8 := xAliquota xVlr_Aliq8 := xCampo8 elseif nIDAliq == 9 xAliq9 := xAliquota xVlr_Aliq9 := xCampo8 endif endif endif Ponte->(dbskip()) if Ponte->(EOF()) EXIT endif end // do E13 AuxImpMP() // Grava a Redu‡Æo Z Ponte->(dbgoto(nRecE12)) //Posiciona no Registro 12 ultimo Ponte->(DbSkip()) //Pula pra ver se tem outro 12 e repete o processo end //se nÆo tem outro 12 ‚ pq terminou os 12 ai termina EXIT end DbCloseAll() *-- Ajusta GTFinal Use mapares alias mapares shared new Ferase('_TempImpZ.CDX') index on MapaRes->datamovz to _TempImpZ DESCENDING Go Top nSaldo := nGTBase While !EOF() Mapares->(BlokRegistro()) MapaRes->GT_Final := nSaldo nSaldo := MapaRes->GT_Final - MapaRes->VendaBruta DbSkip() end DbCommitAll() MapaRes->(DBCLOSEAREA()) Alert('Rotina finalizada com sucesso', aOk) cls return //-- Para o MapaResumo #define D_NR_MAPARES 1 #define D_DATAMOVZ 2 #define D_HORA_Z 3 #define D_NUMECF 4 #define D_NUMSERIE 5 #define D_GNF 6 #define D_CRO 7 #define D_CRZ 8 #define D_CCF 9 #define D_CFD 10 #define D_CCDC 11 #define D_GRG 12 #define D_GNFC 13 #define D_CFC 14 #define D_COO_INI 15 #define D_COO_FIM 16 #define D_GT_INICIAL 17 #define D_GT_FINAL 18 #define D_VENDABRUTA 19 #define D_CANCELAMEN 20 #define D_DESCONTOS 21 #define D_ACRESCIMOS 22 #define D_ALIQUOTA1 23 #define D_VLR_ALIQ1 24 #define D_ALIQUOTA2 25 #define D_VLR_ALIQ2 26 #define D_ALIQUOTA3 27 #define D_VLR_ALIQ3 28 #define D_ALIQUOTA4 29 #define D_VLR_ALIQ4 30 #define D_ALIQUOTA5 31 #define D_VLR_ALIQ5 32 #define D_ALIQUOTA6 33 #define D_VLR_ALIQ6 34 #define D_ALIQUOTA7 35 #define D_VLR_ALIQ7 36 #define D_ALIQUOTA8 37 #define D_VLR_ALIQ8 38 #define D_ALIQUOTA9 39 #define D_VLR_ALIQ9 40 #define D_SUBST_TRIB 41 #define D_ISENTO 42 #define D_NAO_INCIDE 43 ******************************************************************************** function AuxImpMP LOCAL getlist :={}, aGet:={} aGet := InicializaVar('MAPARES', aGet) aGet := ZeraVariaveis('MAPARES', aGet) aGet[D_NR_MAPARES] := PegaNrMapaResumo() // sequencial MapaRes->( AdicionaReg() ) aGet[D_DATAMOVZ] := CTOD( xDataMovZ ) aGet[D_NUMSERIE] := xSerie aGet[D_NUMECF] := STRZERO(VAL(xNumECF),3) // Coloquei para for‡ar o formato 001 ao inv‚s de 1 aGet[D_COO_FIM] := VAL( xCOO_FIM ) //= 000119 aGet[D_CRZ] := VAL( CRZ_E12 ) //= 0008 aGet[D_CRO] := VAL( xCRO ) //= 0002 aGet[D_GT_FINAL] := nGTFin aGet[D_VENDABRUTA] := xVendaBruta aGet[D_DESCONTOS] := xDescontos aGet[D_CANCELAMEN] := xCancelamentos aGet[D_ACRESCIMOS] := xAcrescimos aGet[D_SUBST_TRIB] := xST aGet[D_NAO_INCIDE] := xNT aGet[D_ISENTO] := xIS aGet[D_ALIQUOTA1] := xAliq1 aGet[D_VLR_ALIQ1] := xVlr_Aliq1 aGet[D_ALIQUOTA2] := xAliq2 aGet[D_VLR_ALIQ2] := xVlr_Aliq2 aGet[D_ALIQUOTA3] := xAliq3 aGet[D_VLR_ALIQ3] := xVlr_Aliq3 aGet[D_ALIQUOTA4] := xAliq4 aGet[D_VLR_ALIQ4] := xVlr_Aliq4 aGet[D_ALIQUOTA5] := xAliq5 aGet[D_VLR_ALIQ5] := xVlr_Aliq5 aGet[D_ALIQUOTA6] := xAliq6 aGet[D_VLR_ALIQ6] := xVlr_Aliq6 aGet[D_ALIQUOTA7] := xAliq7 aGet[D_VLR_ALIQ7] := xVlr_Aliq7 aGet[D_ALIQUOTA8] := xAliq8 aGet[D_VLR_ALIQ8] := xVlr_Aliq8 aGet[D_ALIQUOTA9] := xAliq9 aGet[D_VLR_ALIQ9] := xVlr_Aliq9 MapaRes->( BlokRegistro() ) GravaVariaveis('MAPARES', aGet) return Quote Link to comment Share on other sites More sharing options...
Ariston Santos Posted March 17, 2017 Author Report Share Posted March 17, 2017 Obrigado, amigo. Vou testar e aviso se encontrar qualquer dificuldade. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.