NCM - produtos monofásicos

Forum sobre SQL.

Moderador: Moderadores

JUDIVAN CONTABIL
Usuário Nível 2
Usuário Nível 2
Mensagens: 55
Registrado em: 20 Mai 2011 07:42
Localização: IMACULADA-PB

NCM - produtos monofásicos

Mensagem por JUDIVAN CONTABIL »

Código: Selecionar todos

#Include "SYSCON.CH"    

#define CRTLF CHR(13)+ CHR(10)       
#define CRTLF CHR(13)+ CHR(10)
#define CLR_BLUEXP nRgb( 225, 245, 255)
#Define CLR_BFOOT  nRGB( 26, 120, 160 )   //--> Azul meio Verde
*-------------------------------------------------------------------------------
Function MONOF_PISCODFINS()
Local oDlpis,oBtn[2] ,oFont[3]
LOCAL cFilter := ' periodo = ' +  SR_cDBValue( TRANSFORM(M->cReferencia,"@R 99/9999") )

LOCAL lMONOF_PIS  := .T.
	  LOCAL cQuery     := "Select COD_NCM FROM NCM WHERE MONOF_PIS = " + SR_cDBValue( lMONOF_PIS  )  	
	  LOCAL aQuery     := {}

	  //-- verifica se as contas estao configurada no plano de contas 
	  IF LEN(ARRAY_SQL(cQuery,aQuery)) == 0 
		  MSGALERT("Tabela NCM não Configurado as Contas que Apuram PIS/COFINS","Alerta")		
		  Return(.F.)
	  ENDIF	

*-------------------------------------------------------------------------------   
oBd_Infc  := ABRIR("INFC",.t.)
(oBd_Infc)->( SR_SETFILTER(cFilter) )	

(oBd_Infc)->(DbGoTop())

oBd_Ncm   := ABRIR("NCM",.t.)
 
 //-- tabela NCM
 	  (oBd_Ncm)->(DBSETORDER(1))
 	  (oBd_Ncm)->( DBGOTOP() )
*---------------------------------------------------------*
WVLPIS_04:=0
WVLPIS_06:=0
WVLPIS_07:=0
WVLCOFINS_04:=0
WVLCOFINS_06:=0
WVLCOFINS_07:=0
WPIS:=0
WCOFINS:=0
WPIS_ZERO:=0
WCOFINS_ZERO:=0
WPIS_ISENTO:=0
WCOFINS_ISENTO:=0

WTOTAL_PIS:=0
WTOTAL_COFINS:=0

 (oBd_Ncm)->( DBGOTOP() )

	  WHILE ! (oBd_Ncm)->( EOF() )

       wCOD_NCM   := (oBd_Ncm)->COD_NCM

 
(oBd_Infc)->( DBGOTOP() )
	 nPos := AScan( aQuery ,{ |x| x[1] = wCOD_NCM } )
	  IF nPos > 0  //-- encontrou a conta no vetor     
		 WPIS=(oBd_Infc)->VLR_ITEM
		 WCOFINS=(oBd_Infc)->VLR_ITEM			
		 
		 WVLPIS_04=WVLPIS_04+WPIS 
		 WVLCOFINS_04=WVLCOFINS_04+WCOFINS
		 
  ENDIF
             * (oBd_Infc)->( DBSKIP() )

          WTOTAL_PIS=WVLPIS_04+WVLPIS_06+	WVLPIS_07
			 WTOTAL_COFINS=WVLCOFINS_04+WVLCOFINS_06+WVLCOFINS_07	
(oBd_Ncm)->( DBSKIP() )

Enddo
 
      M_Calcpiscofins()

Return Nil
*-------------------------------------------------------------------------------
Static Function M_Calcpiscofins()
Local oDlpis,oBtn[2] ,oFont[4]
*-------------------------------------------------------------------------------   

   DEFINE FONT	oFont[1] NAME "VERDANA"  SIZE 0,-09
	DEFINE FONT	oFont[2] NAME "VERDANA"  SIZE 0,-11 BOLD
   DEFINE FONT	oFont[3] NAME "VERDANA"  SIZE 0,-13 BOLD
	  
	DEFINE DIALOG oDlpis RESOURCE "RELMONOF_PIS" FONT oFont[1]
   oDlpis:lHelpIcon:=.F.
   REDEFINE SAY                                                             ID 051 OF oDlpis FONT oFont[3] COLOR CLR_WHITE,CLR_BFOOT    
   REDEFINE SAY                                                             ID 4006 OF oDlpis FONT oFont[3] COLOR CLR_WHITE,CLR_BFOOT    
           
  
  	REDEFINE SAY PROMPT TransForm(WVLPIS_04,'@E 999,999,999.99')            ID 101 OF oDlpis FONT oFont[2] Update 
	REDEFINE SAY PROMPT TransForm(WVLCOFINS_04,'@E 999,999,999.99')         ID 102 OF oDlpis FONT oFont[2] Update 		
  * REDEFINE SAY PROMPT TransForm(WVLPIS_06,'@E 999,999,999.99')            ID 103 OF oDlpis FONT oFont[2] Update 
	*REDEFINE SAY PROMPT TransForm(WVLCOFINS_06,'@E 999,999,999.99')         ID 104 OF oDlpis FONT oFont[2] Update 		
   *REDEFINE SAY PROMPT TransForm(WVLPIS_07,'@E 999,999,999.99')            ID 105 OF oDlpis FONT oFont[2] Update 
	*REDEFINE SAY PROMPT TransForm(WVLCOFINS_07,'@E 999,999,999.99')         ID 106 OF oDlpis FONT oFont[2] Update 		
   
   *REDEFINE SAY PROMPT TransForm(WTOTAL_PIS,'@E 999,999,999.99')            ID 107 OF oDlpis FONT oFont[2] Update 
	*REDEFINE SAY PROMPT TransForm(WTOTAL_COFINS,'@E 999,999,999.99')         ID 108 OF oDlpis FONT oFont[2] Update 		
   
	                                                                   
   REDEFINE BUTTONBMP oBtn[1] ID 1401 OF oDlpis BITMAP "BTN_SAIR" CANCEL;
     ACTION oDlpis:End() UPDATE TEXTRIGHT
     oBtn[1]:cTooltip:="Sair para menu Principal"


   ACTIVATE DIALOG oDlpis CENTERED 
   
  * aEval( oFont, {|o| o:End()})
   DbCloseAll()
   
Return Nil
gostaria de saber o que está errado neste código fonte, para vim só os valores monofásico de PIS e COFINS
Editado pela última vez por Itamar M. Lins Jr. em 17 Abr 2021 08:46, em um total de 2 vezes.
Razão: O presente tópico foi movido da seção Legislação Fiscal e Tributária, uma vez que seu conteúdo não tem relação com os objetivos daquela seção. Faz uso do SQLRDD para essa tarefa e Hwgui.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

O que menos tem na rotina é comando SQL.

Coisa que não dá pra saber:

Código: Selecionar todos

LOCAL cFilter := ' periodo = ' +  SR_cDBValue( TRANSFORM(M->cReferencia,"@R 99/9999") )
Existe cReferencia?
Qual o conteúdo?
SR_cDBValue deve ser pra string, a julgar pelo cDBValue, mas não dá pra saber, e também não dá pra saber o conteúdo de PERIODO
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
JUDIVAN CONTABIL
Usuário Nível 2
Usuário Nível 2
Mensagens: 55
Registrado em: 20 Mai 2011 07:42
Localização: IMACULADA-PB

NCM - produtos monofásicos

Mensagem por JUDIVAN CONTABIL »

o conteúdo de cReferencia é o período, ´para selecionar o valor do PIS e COFINS dentro da tabela INFC, por período.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

Tem um erro meio básico:
Está zerando as variáveis antes de buscar no banco de dados, FORA DO DO WHILE.
Isso vai causar mistura de informações
Se não encontrar o NCM, vai usar os valores do anterior.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

Depois... poderia alterar.
Ao invés de SELECT ... MONOF_PIS = xxx

SELECT ... MONOF_PIS = xxx AND COD_NCM IN ( lista de NCM )

Isso vai trazer só o que interessa, economizando tempo na transferência de informação.

Nota: conforme se esse banco de dados aceita IN ( lista )
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

ou isto, ao invés de mexer com as variáveis:

Código: Selecionar todos

   WHILE ! (oBd_Ncm)->( Eof() )

      wCOD_NCM   := (oBd_Ncm)->COD_NCM

      (oBd_Infc)->( dbGoTop() )
      nPos := AScan( aQuery ,{ |x| x[1] = wCOD_NCM } )
      IF nPos > 0  //-- encontrou a conta no vetor
         WPIS=(oBd_Infc)->VLR_ITEM
         WCOFINS=(oBd_Infc)->VLR_ITEM

         WVLPIS_04=WVLPIS_04+WPIS
         WVLCOFINS_04=WVLCOFINS_04+WCOFINS

      * (oBd_Infc)->( dbSkip() )

         WTOTAL_PIS=WVLPIS_04+WVLPIS_06+   WVLPIS_07    // <<========
         WTOTAL_COFINS=WVLCOFINS_04+WVLCOFINS_06+WVLCOFINS_07  // <<======
      ENDIF
      (oBd_Ncm)->( dbSkip() )

   ENDDO

   M_Calcpiscofins()
E fica confuso de onde vém, ou pra que servem, WVLPIS_06 e WVLPIS_07 e WVLCOFINS_06 e WVLCOFINS_07
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

Pra se interessar por -w3 -es2....

Código: Selecionar todos

FUNCTION MONOF_PISCODFINS()

   LOCAL cFilter := ' periodo = ' +  SR_cDBValue( Transform(M->cReferencia,"@R 99/9999") )
   LOCAL WTOTAL_PIS, WVLPIS_07, WVLCOFINS_04, WVLCOFINS_07, WCOFINS, WVLPIS_04
   LOCAL WPIS, WVLPIS_06, WVLCOFINS_06, wTOTAL_COFINS, nPos, WPIS_ZERO, WCOFINS_ZERO
   LOCAL WPIS_ISENTO, WCOFINS_ISENTO, OBD_INFC, OBD_NCM, WCOD_NCM

   LOCAL lMONOF_PIS  := .T.
   LOCAL cQuery     := "Select COD_NCM FROM NCM WHERE MONOF_PIS = " + SR_cDBValue( lMONOF_PIS  )
   LOCAL aQuery     := {}
d:\temp>hbmk2 test2 -w3 -es2
hbmk2: Processing environment options: -comp=mingw
hbmk2: Processing configuration: d:\harbour\bin\hbmk.hbc
Harbour 3.4.0dev (4edd687) (2021-03-07 23:56)
Copyright (c) 1999-2021, https://github.com/JoseQuintas/harbour_34/
Compiling 'test2.prg'...

test2.prg:76: warning W0032 Variable 'WPIS' is assigned but not used in function '39:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WCOFINS' is assigned but not used in function '40:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WPIS_ZERO' is assigned bt not used in function '41:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WCOFINS_ZERO' is assigned but not used in function '42:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WPIS_ISENTO' is assigned but not used in function '43:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WCOFINS_ISENTO' is assigned but not used in function '44:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WTOTAL_PIS' is assigned but not used in function '46:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WTOTAL_COFINS' is assigned but not used in function '47:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WTOTAL_PIS' is assigned but not used in function '66:MONOF_PISCODFINS'

test2.prg:76: warning W0032 Variable 'WTOTAL_COFINS' is assigned but not used in function '67:MONOF_PISCODFINS'
Compilando com -w3 -es2 está mostrando aonde atribui valor à toa.
Acabaria resolvendo vários problemas sem nem precisar perguntar.

E tem este também:

Código: Selecionar todos

#define CRTLF Chr(13)+ Chr(10)
#define CRTLF Chr(13)+ Chr(10)
test2.prg:3: warning W0002 Redefinition or duplicate definition of #define CRTLF
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

JoséQuintas escreveu:Compilando com -w3 -es2 está mostrando aonde atribui valor à toa.
Acabaria resolvendo vários problemas sem nem precisar perguntar.
NÃO é reclamando sobre perguntas.

O comentário foi pra mostrar como vale a pena usar -w3 -es2.
E o exemplo é interessante pra isso, porque mostra uma situação onde faz diferença.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

JUDIVAN CONTABIL escreveu:gostaria de saber o que está errado neste código fonte, para vim só os valores monofásico de PIS e COFINS
Mas a rotina só calcula o valor monofásico, a quais valores está se referindo.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
JUDIVAN CONTABIL
Usuário Nível 2
Usuário Nível 2
Mensagens: 55
Registrado em: 20 Mai 2011 07:42
Localização: IMACULADA-PB

NCM - produtos monofásicos

Mensagem por JUDIVAN CONTABIL »

A rotina é para pesquisar na tabela NCM e selecionar o código marcado e o com o código selecionado pegar o valor na tabela INFC o valor do PIS e COFINS referente aos códigos selecionados na tabela NCM.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

NCM - produtos monofásicos

Mensagem por JoséQuintas »

Ok, me confundi porque num ponto pesquisa apenas aonde é monofásico, mas não tem a ver com o restante.

No erro que mencionei, acabava usando os valores do último encontrado na soma, o que não explica os sem cálculo.

À primeira vista, não vai calcular se não existir o NCM na base.

Confirme se os campos tem o mesmo tamanho, ou se são numéricos, ou altere como falei pra buscar a lista dos NCMs necessários, e verifica o tamanho desse retorno.
Com certeza pode ser menor do que a lista de produtos, já que pode ter NCM repetido, o que causaria um retorno menor que a quantidade.

Também pode colocar aí pra calcular quantos encontrados e quantos não encontrados, deve ajudar.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder