Página 1 de 1

SPED Fiscal TXT

Enviado: 07 Jul 2014 14:50
por JUDIVAN CONTABIL
OLÁ COLEGAS

Gostaria de ajuda;
Quando mando gerar o arquivo txt do sped fiscal, os blocos C100, C170 e C190, gera da seguinte forma:

|C100|0|1|35587112000175|55|00|001|000124995|25140435587112000175550010001249951060292571|25042014|01052014|172,77|2|||172,77|9|||||||||||||
|C100|0|1|41080722000504|55|00|001|000055343|25140441080722000504550010000553431000553434|28042014|01052014|13145,50|2|||13145,50|9|||||||||||||
|C100|0|1|02437279000109|55|00|001|000019676|25140502437279000109550010000196761082620074|05052014|05052014|7050,00|2|||7050,00|9|||||||||||||
|C170|1|12||2,00000|CX|26,00||0|010|1403|||||||||||||||||||||||||||
|C170|2|6||2,00000|CX|20,00||0|010|1403|||||||||||||||||||||||||||
|C170|3|7||2,00000|CX|24,00||0|010|1403|||||||||||||||||||||||||||
|C190|010|1403||26,00|0,00|0,00|0,00|0,00|26,00|0,00||
|C190|010|1403||20,00|0,00|0,00|0,00|0,00|20,00|0,00||
|C190|010|1403||24,00|0,00|0,00|0,00|0,00|24,00|0,00||

como eu faço para gerar de acordo com txt do sped fiscal

SPED FISCAL TXT

Enviado: 07 Jul 2014 22:40
por fladimir
Judivan, não entendi muito bem sua dúvida, poderia fornecer mais detalhes do problema?

[]´s

SPED FISCAL TXT

Enviado: 08 Jul 2014 08:40
por JUDIVAN CONTABIL
É porque no SPED FISCAL o formato do txt é o seguinte:

C100|0|1|35587112000175|55|00|001|000124995|25140435587112000175550010001249951060292571|25042014|01052014|172,77|2|||172,77|9|||||||||||||
|C170|1|12||2,00000|CX|26,00||0|010|1403|||||||||||||||||||||||||||
|C190|010|1403||26,00|0,00|0,00|0,00|0,00|26,00|0,00||
|C100|0|1|41080722000504|55|00|001|000055343|25140441080722000504550010000553431000553434|28042014|01052014|13145,50|2|||13145,50|9|||||||||||||
|C170|1|12||2,00000|CX|26,00||0|010|1403|||||||||||||||||||||||||||
|C190|010|1403||26,00|0,00|0,00|0,00|0,00|26,00|0,00||
|C100|0|1|02437279000109|55|00|001|000019676|25140502437279000109550010000196761082620074|05052014|05052014|7050,00|2|||7050,00|9|||||||||||||
|C190|010|1403||26,00|0,00|0,00|0,00|0,00|26,00|0,00||

e quando eu gero o txt, fica diferente ou seja fica assim:
|C100|0|1|35587112000175|55|00|001|000124995|25140435587112000175550010001249951060292571|25042014|01052014|172,77|2|||172,77|9|||||||||||||
|C100|0|1|41080722000504|55|00|001|000055343|25140441080722000504550010000553431000553434|28042014|01052014|13145,50|2|||13145,50|9|||||||||||||
|C100|0|1|02437279000109|55|00|001|000019676|25140502437279000109550010000196761082620074|05052014|05052014|7050,00|2|||7050,00|9|||||||||||||
|C170|1|12||2,00000|CX|26,00||0|010|1403|||||||||||||||||||||||||||
|C170|2|6||2,00000|CX|20,00||0|010|1403|||||||||||||||||||||||||||
|C170|3|7||2,00000|CX|24,00||0|010|1403|||||||||||||||||||||||||||
|C190|010|1403||26,00|0,00|0,00|0,00|0,00|26,00|0,00||
|C190|010|1403||20,00|0,00|0,00|0,00|0,00|20,00|0,00||
|C190|010|1403||24,00|0,00|0,00|0,00|0,00|24,00|0,00||

SPED FISCAL TXT

Enviado: 08 Jul 2014 10:59
por fladimir
Ah entendi...

é q vc esta gerando primeiro os C100 cabeçalhos depois os C170 e depois os C190, ... o q vc tem q fazer é o seguinte, não sei como vc armazena os dados ai, suponhamos q vc grave suas notas fiscais em 2 tabelas, 01 para o cabeçalho e outra para os itens..., se for, vc tem q posicionar no primeiro registro do cabeçalho q satisfaça a condição do periodo q vc vai gerar o SPED e a partir dele gerar os itens e o agrupamento CSTXCFOPXICMS (C190), Exemplo (a grosso modo):

Nota 123 Total R$ 36,00
Itens da nota 123
ITEM A CFOP 1102 Valor 11,00 CST 000
ITEM B CFOP 1102 Valor 12,00 CST 000
ITEM C CFOP 1403 Valor 13,00 CST 060

Ai vc para no registro da nota 123 e gera o C100 dela, AI ANTES DE IR PARA A PROXIMA NOTA VC GERA OS C170 E OS C190, VEJA::

C170 ITEM A
C170 ITEM B
C170 ITEM C

C190 23,00 Referente CFOP1102 com CST 000
C190 13,00 Referente CFOP 1403 com CST 060

DEPOIS VC VAI PARA A PROXIMA NOTA E FAZ A MESMA LÓGICA ACIMA.

Agora se vc armazena de forma única as notas, então terá q tratar a situação exposta acima conforme sua realidade, exemplo

Estou Nota 123 (ai na mesma tabela tenho os itens)
nRegAtual := Tabela->(recno())
Ai vc pode criar um indice temporario filtrando a Nota 123 do periodo X do fornecedor Z
Ai gera os C170 e os C190

Depois reposiciona no nRegAtual.

Não sei se conseguiu entender, da uma analisada ai e qualquer coisa retorna aqui pra entendermos melhor tua realidade e ver o q conseguimos ajudar.

[]´s

SPED FISCAL TXT

Enviado: 08 Jul 2014 14:26
por JUDIVAN CONTABIL
É dessa forma que eu uso, a onde está o erro:

Código: Selecionar todos

**********************************************************
Function GeraBlocoC()
Local x ,nOk := 0
Local cPesq, _cPesq
Cen_tra('Selecionando Notas......')
        
SELECT ENTRADA

 *SET ORDER TO 1
 *     ENTRADA->(DBGOTOP())

Index on PERIODO+DATA to ENTRADA1
GO TOP
SEEK M->vMes
DO WHILE (PERIODO=M->vMes)

SELECT NOTA
*Index on PERIODO+DATA TO (M->CAMINHO+"\"+M->CODIGO+"\NOTA1")
Index on PERIODO+DATA TO NOTA1
DBSETORDER(1)            
  
Sele C100
Append Blank
Repla C100->Reg         With 'C100'
Repla C100->IndOper     With ALLTRIM(entrada->CONTA) //indicador do tipo de opercao->0-entrada e 1-saida
Repla C100->IndEmit     With ENTRADA->IND_EMIT          // Ver
Repla C100->CodPart     With ALLTRIM(STRZERO(Val(LimpaStr(ENTRADA->CNPJ_CPF)),14))
Repla C100->CodSit      With '00'
Repla C100->CodMod      With entrada->COD_MOD
Repla C100->Ser         With entrada->serie
Repla C100->NumDoc      With StrZero(val(entrada->nota),9)
Repla C100->chvnfe      With entrada->CHV_NFE
Repla C100->dtdoc       With entrada->d_doc
Repla C100->Dtes        With entrada->(LimpaStr(DATA))
Repla C100->vldoc       With entrada->VL_CONTABI
Repla C100->indpagto    With entrada->IND_PGTO
*Repla C100->vldesc     With entrada->vlr_Desco              //
*Repla C100->vlabatnt   With entrada->
Repla C100->vlmerc      With entrada->VL_CONTABI
Repla C100->indfrt      With entrada->IND_FRT              //
*Repla C100->vlfrt      With entrada->              //
*Repla C100->vlSeg      With entrada->
*Repla C100->vloutda    With entrada->ValorOutro
Repla C100->vlbcicms    With entrada->B_CALCULO
Repla C100->vlicms      With entrada->VL_ICMS
Repla C100->vlbcicmsst  With entrada->VLSUBT
Repla C100->vlicmsst    With entrada->IMPSUBT
Repla C100->vlipi       With entrada->IPI
*Repla C100->vlpis      With entrada->
*Repla C100->vlcofins   With entrada->
*Repla C100->vlpisst    With entrada->
*Repla C100->vlconfisst With entrada->
Sele entrada
cTpoRegUF := entrada->UF+Iif(C100->IndEmit=='0','E',"S")
//--- JAFFILTRO
cPesq := C100->CodPart+C100->NumDoc+C100->Ser
Skip+1
*CLOSE ENTRADA
Enddo
*******************************
SELECT NOTA
NOTA->(DBGOTOP())
*Index on PERIODO+DATA TO (M->CAMINHO+"\"+M->CODIGO+"\NOTA1")
Index on PERIODO+DATA TO NOTA1
*GO TOP
SEEK M->vMes
DO WHILE (PERIODO=M->vMes)
 IF TIPO_ES="E"
Sele C170
Append Blank
Repla C170->Reg          With 'C170'
Repla C170->numitem      With Alltrim(str(nota->nr_item))
Repla C170->Coditem      With Alltrim(str((nota->codigo)))
Repla C170->descricao    With Alltrim(nota->desc_compl)
Repla C170->qtd          With nota->quant_unid
Repla C170->unid         With Alltrim(nota->unid_med)
Repla C170->vlitem       With nota->vlr_item                         //
Repla C170->vldesc       With nota->vlr_desc
Repla C170->indmov       With nota->ind_movi
Repla C170->csticms      With nota->cstr_icms
Repla C170->cfop         With LimpaStr(nota->operacao)                         //
Repla C170->codnat       With ""
Repla C170->vlbcicms     With nota->vlr_bc_icm
Repla C170->Aliqicms     With nota->aliq_icmnf
Repla C170->vlicms       With nota->vlr_icms
Repla C170->vlbcicmsst   With nota->vlrbcicmst                         //
Repla C170->aliqst       With nota->aliq_stnf
Repla C170->vlicmsst     With nota->vlr_icm_st 
Repla C170->indapur      With nota->ind_apura                         //
Repla C170->cstipi       With nota->cst_ipinf                         //
Repla C170->codenq       With nota->cod_enqnf                       //
Repla C170->vlbcipi      With nota->vlr_bc_ipi                         //
Repla C170->aliqipi      With nota->aliq_ipinf
Repla C170->vlipi        With nota->vlr_ipi                         //
Repla C170->cstpis       With nota->cst_pisnf                         //
Repla C170->vlbcpis      With nota->vlr_bc_pis                         //
Repla C170->aliqpis      With nota->aliq_pisnf                         //
Repla C170->quantbcpis   With nota->q_bc_pis                         //
Repla C170->aliqpis      With nota->aliqpisr
Repla C170->vlpis        With nota->vlr_pis                         //
Repla C170->cstcofins    With nota->cst_cofinf                         //
Repla C170->vlbcconfis   With nota->vlr_bc_cof                         //
Repla C170->aliqconfis   With nota->aliq_cofin                         //
Repla C170->qtdbcconfi   With nota->quan_bc_co                         //
Repla C170->aliqconfis   With nota->aliqcofins
Repla C170->vlcofins     With nota->vlr_cofins                         //
Repla C170->codcta       With nota->cod_ctanf
Repla C170->JAFFiltro    With nota->_cPesq
Select NOTA
ENDIF
*Skip
*Enddo
NOTA->(DBSKIP())
ENDDO
**********************************************************

SPED FISCAL TXT

Enviado: 08 Jul 2014 15:10
por fladimir
O erro esta nas linha 57 e 59, observe q vc vai para proxima nota (SKIP) no mesmo laço 59 (ENDDO), ou seja vc esta fazendo todos os C100 pra depois ir para o C170

Vc tem q antes de fazer o skip na nota fazer os c170 dessa nota e os c190 pra depois pular pra próxima...

Veja abaixo o teu código q eu dei uma reformulada pra vc entender a lógica, mas perceba q não esta concluído, vc como conhecedor das tabelas, estrutura de campos etc vai conseguir basear agora e fazer a alteração necessária.

Código: Selecionar todos

**********************************************************
Function GeraBlocoC()
   Local x ,nOk := 0
   Local cPesq, _cPesq
   Cen_tra('Selecionando Notas......')
    
   SELECT ENTRADA
   Index on PERIODO+DATA to ENTRADA1
   GO TOP
   SEEK M->vMes
   DO WHILE (PERIODO=M->vMes)

      SELECT NOTA
      *Index on PERIODO+DATA TO (M->CAMINHO+"\"+M->CODIGO+"\NOTA1")
      Index on PERIODO+DATA TO NOTA1
      DBSETORDER(1)
 
      Sele C100
      Append Blank
      Repla C100->Reg        With 'C100'
      Repla C100->IndOper    With ALLTRIM(entrada->CONTA) //indicador do tipo de opercao->0-entrada e 1-saida
      Repla C100->IndEmit    With ENTRADA->IND_EMIT     // Ver
      Repla C100->CodPart    With ALLTRIM(STRZERO(Val(LimpaStr(ENTRADA->CNPJ_CPF)),14))
      Repla C100->CodSit     With '00'
      Repla C100->CodMod     With entrada->COD_MOD
      Repla C100->Ser        With entrada->serie
      Repla C100->NumDoc     With StrZero(val(entrada->nota),9)
      Repla C100->chvnfe     With entrada->CHV_NFE
      Repla C100->dtdoc      With entrada->d_doc
      Repla C100->Dtes       With entrada->(LimpaStr(DATA))
      Repla C100->vldoc      With entrada->VL_CONTABI
      Repla C100->indpagto   With entrada->IND_PGTO
      Repla C100->vlmerc     With entrada->VL_CONTABI
      Repla C100->indfrt     With entrada->IND_FRT       //
      Repla C100->vlbcicms   With entrada->B_CALCULO
      Repla C100->vlicms     With entrada->VL_ICMS
      Repla C100->vlbcicmsst With entrada->VLSUBT
      Repla C100->vlicmsst   With entrada->IMPSUBT
      Repla C100->vlipi      With entrada->IPI
      Sele entrada
      cTpoRegUF := entrada->UF+Iif(C100->IndEmit=='0','E',"S")
      //--- JAFFILTRO
      cPesq := C100->CodPart+C100->NumDoc+C100->Ser
      
      //--> Aki vc tem q fazer os itens desta nota q vc incluiu no C100
      
      //--> Tipo eu peguei o código q estava ap¢s o ENDDO e coloquei aki pra vc ter uma ideia, 
		//--> como não sei exatamente como estao as informações na tabela apenas coloquei pra vc perceber
	   
		SELECT NOTA
	   NOTA->(DBGOTOP())

		//--> aki vc tem q filtrar a nota acima ENTRADA->Nota pra jogar os itens (C170) dela
	   
	   DO WHILE //--> FA€A ENQUANTO FOR OS ITENS DA NOTA ACIMA DO C100
	      IF TIPO_ES="E"
	         Sele C170
	         Append Blank
	         Repla C170->Reg        With 'C170'
	         Repla C170->numitem    With Alltrim(str(nota->nr_item))
	         Repla C170->Coditem    With Alltrim(str((nota->codigo)))
	         Repla C170->descricao  With Alltrim(nota->desc_compl)
	         Repla C170->qtd        With nota->quant_unid
	         Repla C170->unid       With Alltrim(nota->unid_med)
	         Repla C170->vlitem     With nota->vlr_item            //
	         Repla C170->vldesc     With nota->vlr_desc
	         Repla C170->indmov     With nota->ind_movi
	         Repla C170->csticms    With nota->cstr_icms
	         Repla C170->cfop       With LimpaStr(nota->operacao)            //
	         Repla C170->codnat     With ""
	         Repla C170->vlbcicms   With nota->vlr_bc_icm
	         Repla C170->Aliqicms   With nota->aliq_icmnf
	         Repla C170->vlicms     With nota->vlr_icms
	         Repla C170->vlbcicmsst With nota->vlrbcicmst            //
	         Repla C170->aliqst     With nota->aliq_stnf
	         Repla C170->vlicmsst   With nota->vlr_icm_st
	         Repla C170->indapur    With nota->ind_apura            //
	         Repla C170->cstipi     With nota->cst_ipinf            //
	         Repla C170->codenq     With nota->cod_enqnf           //
	         Repla C170->vlbcipi    With nota->vlr_bc_ipi            //
	         Repla C170->aliqipi    With nota->aliq_ipinf
	         Repla C170->vlipi      With nota->vlr_ipi            //
	         Repla C170->cstpis     With nota->cst_pisnf            //
	         Repla C170->vlbcpis    With nota->vlr_bc_pis            //
	         Repla C170->aliqpis    With nota->aliq_pisnf            //
	         Repla C170->quantbcpis With nota->q_bc_pis            //
	         Repla C170->aliqpis    With nota->aliqpisr
	         Repla C170->vlpis      With nota->vlr_pis            //
	         Repla C170->cstcofins  With nota->cst_cofinf            //
	         Repla C170->vlbcconfis With nota->vlr_bc_cof            //
	         Repla C170->aliqconfis With nota->aliq_cofin            //
	         Repla C170->qtdbcconfi With nota->quan_bc_co            //
	         Repla C170->aliqconfis With nota->aliqcofins
	         Repla C170->vlcofins   With nota->vlr_cofins            //
	         Repla C170->codcta     With nota->cod_ctanf
	         Repla C170->JAFFiltro  With nota->_cPesq
	         Select NOTA
	      ENDIF
		   NOTA->(DBSKIP())
	   ENDDO
		
		//--> AI SIM APOS TER TERMINADO OS ITENS DA NOTA VC VAI PRA PROXIMA NOTA NA TABELA ENTRADA
		Skip
   Enddo
RETURN NIL
**********************************************************

SPED FISCAL TXT

Enviado: 05 Ago 2014 16:30
por JUDIVAN CONTABIL
não deu certo, não foi possível colocar o txt na orden certa.

SPED FISCAL TXT

Enviado: 05 Ago 2014 16:37
por fladimir
Algum outro colega poderia revisar o código pra ver o q estaria errado, pois até onde vi seria o q mencionei.

SPED FISCAL TXT

Enviado: 19 Ago 2014 22:53
por rubens
Acredito que a logica tá correta Fladimir... o colega Josivam poderia compactar o código pra ficar mais fácil analisar... mas como você disse para ele primeiro pega os dados de uma c100, depois filtra os c170 dessa c100 e depois os c190.. só depois disso que volta no c100 e pula o registro...

Tipo assim...

Código: Selecionar todos

Sele c100
append blank 
Repla C100->Reg        With 'C100'
Repla C100->IndOper    With ALLTRIM(entrada->CONTA) 
Repla C100->Numero With cNumero

Sele c170
Set Filter to itensdoc170 = cNumero do C100
append blank 
Repla c170->Reg With 'C170'

Sele c190
Set Filter to itensdoc190 = cNumero do C100
append blank 
Repla c190->Reg With 'C170'

Sele c100
dbskip()


SPED FISCAL TXT

Enviado: 08 Set 2014 18:14
por Mário Isa
No caso em pauta o colega está fazendo somente das notas de entrada ?

Ou as de saída também ?

E os cupons fiscais ? também tem que incluir ?

Mário

SPED Fiscal TXT

Enviado: 11 Set 2014 17:59
por JoséQuintas
Pra facilitar essas coisas, eu faço assim, supondo que fossem NFs, contendo pedidos, que contém produtos:

Código: Selecionar todos

SELECT NOTAS
DO WHILE .NOT. Eof()
   ? "NF - 100"
   GeraPedidos() // 170
   SKIP
ENDDO
RETURN

FUNCTION GeraPedidos() // 170
   LOCAL nSelect := Select()
   SELECT PEDIDOS
   SEEK nota->NF
   DO WHILE pedido->NF == nota->nf .AND. .NOT. Eof()
     ? "pedido -= 170"
      GeraProdutoPedido() // 190
      SKIP
   ENDDO
   SELECT (nSelect)
   RETURN NIL

FUNCTION GeraPedidoProduto() // 190
   LOCAL nSelect := Select()
   SELECT produtopedido
   SEEK pedidos->Pedido
   DO WHILE produtopedido->Pedido == pedidos->pedido .and. .not. eof()
        ? "Produto pedido - 190"
        SKIP
   ENDDO
   SELECT (nSelect)
   RETURN NIL

Ao invés de encher de DO WHILE, cada rotina faz sua parte.
O primeiro processa as notas, os registros 100.
geraPedido() mostra os pedidos daquela nota, os registros 170
GeraProdutoPedido() mostra os produtos daquele pedido, os registros 190.

Comparando com sua rotina, é como se voce colocasse todas as notas, depois todos os pedidos, e depois todos os produtos.
Acaba ficando tudo misturado, sem saber o que percente a cada coisa.

Como dizia uma regra antiga de programação:
Se você tem um problema grande, divida em pequenos problemas, e resolva um pequeno problema por vez.

Nota: usei esses arquivos só pra exemplificar, não é isso que vai no sped...