Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Bloco de código
languagecpp
themeRDark
titleExemplo de PE
User Function ESPISRL()

	Local cArqTmp := IxbParam[1]
	Local dDataIni := IxbParam[2]
	Local dDataFim := IxbParam[3]
	Local cPeriodo := IxbParam[4]
	Local cQuery1 := ""
	Local aStrQRY1 :={}
	Local nI := 1
	Local XSFE
	Local XSA2
	Local cRIFAGENTE
	Local cArqtrb
	Local  cNomIND
	Local cORDPAGO
	Local nORDPAGO
	Local cORDPAGO1
	Local nPERCENT
	Local cNFISCAL

	DBSELECTAREA("SM0")
	
	cRIFAGENTE := alltrim(M0_CGC)

	DBSELECTAREA("SA2")
	DBSETORDER(1)

	XSA2 := xFilial("SA2") 

	DBSELECTAREA("SFE")
	DBSETORDER(1)

	XSFE := xFilial("CT1") 
	aadd(aStrQRY1,{ "RIFAGENTE" , "C", 14, 0 })
	aadd(aStrQRY1,{ "EMISSAO"   , "C", 06, 0 })
	aadd(aStrQRY1,{ "RIFSUJEITO", "C", 14, 0 })
	aadd(aStrQRY1,{ "NUMFATURA" , "C", 10, 0 })
	aadd(aStrQRY1,{ "ORDEMPAGO" , "C", 08, 0 })
	aadd(aStrQRY1,{ "CONCEITO"  , "C", 03, 0 })
	aadd(aStrQRY1,{ "VALORBASE" , "C", 17, 0 })
	aadd(aStrQRY1,{ "PERCENT"   , "C", 06, 0 })

  	cQUERY1 := "SELECT DISTINCT '" + cRIFAGENTE + "' RIFAGENTE, FE_EMISSAO EMISSAO , A2_CGC , FE_ORDPAGO, FE_NFISCAL, FE_SERIE "
	cQUERY1 +=      ", FE_VALBASE VALORBASE, FE_ALIQ , FE_CONCEPT" 	cQUERY1 += " FROM SFE000  SFE"
	cQUERY1 +=     ", SA2000 SA2"
	cQUERY1 += " WHERE SFE.FE_FILIAL = '" + XSFE + "'"
 	
	cQUERY1 +=   " AND SFE.D_E_L_E_T_ = ' '"
	cQUERY1 +=   " AND SFE.FE_TIPO='R'" 	
	cQUERY1 +=   " AND SFE.FE_EMISSAO BETWEEN '" + DTOS(MV_PAR01) + "' AND '" + DTOS(MV_PAR02) + "'" 	
	cQUERY1 +=   " AND SA2.D_E_L_E_T_ = ' ' " 

	cQUERY1 +=   " ORDER BY SFE.FE_EMISSAO, A2_CGC "  
 
     cQUERY1 := CHANGEQUERY(cQUERY1) 

    IF SELECT("TOPISRL") > 0   
		DBSELECTAREA("TOPISRL")   
		DBCLOSEAREA()
	ENDIF

	TcQuery cQUERY1 New Alias "TOPISRL"

	DBSELECTAREA("TOPISRL")

	IF (EOF() .OR. BOF())   
		MsgAlert("Não existe retenções geradas","Atenção")//Não existe retenções geradas! ### Atenção   
		RETURN
	ENDIF

	IF SELECT("ISRL") > 0   
		DBSELECTAREA("ISRL")   
		DBCLOSEAREA()
	ENDIF

	cArqtrb  := CriaTrab( aStrQRY1, .T. )
	cNomIND  := ALLTRIM(cArqtrb)
	cIndTRB  := "EMISSAO + RIFSUJEITO + NUMFATURA + ORDEMPAGO"

	dbUseArea( .T., "DBFCDX", cArqtrb, "ISRL", .T. ,.F. )
	dbSelectArea("ISRL")
	
	IndRegua( "ISRL", cNomIND , cIndTRB )
	
	set index todbSetIndex(cNomIND +OrdBagExt())

	dbSetOrder(1)
	DBSELECTAREA("TOPISRL")

	TOPISRL->(DBGOTOP())
	DO WHILE ! TOPISRL->(EOF())	
		
		DBSELECTAREA("TOPISRL")   
		
		cNFISCAL := (ALLTRIM(TOPISRL->FE_SERIE) + ALLTRIM(TOPISRL->FE_NFISCAL) )   
	
		IF "" == cNFISCAL .or. EMPTY(cNFISCAL)      
			cNFISCAL:= "0"   
		ELSE      
			IF LEN(cNFISCAL) > 10         
				cNFISCAL := RIGHT(cNFISCAL,10)      
			ENDIF    
		ENDIF	
	
		cORDPAGO1:=  ALLTRIM(TOPISRL->FE_ORDPAGO)	
		cORDPAGO := ""   
		
		IF EMPTY(cORDPAGO1)		
			cORDPAGO := "NA"	
		ELSE			
		
			nORDPAGO := LEN(cORDPAGO1)		
		
			FOR nI := 1 TO nORDPAGO		   
				IF subs(cORDPAGO1, nI,1) $ "0123456789"			   
					cORDPAGO += subs(cORDPAGO1, nI,1)		   
				ENDIF		
			NEXT	
			
		ENDIF   
	
		nPERCENT := STR(FE_ALIQ,6,2)   
	
		IF SUBS( nPERCENT , 4, 3) == ".00" // 010.00	   
			nPERCENT := STR(FE_ALIQ,3,0)   
		ENDIF                                                 	
	
		dbSelectArea("ISRL")	
		RECLOCK("ISRL", .T.)	
			ISRL->RIFAGENTE  := ALLTRIM(TOPISRL->RIFAGENTE)	
			ISRL->EMISSAO    := cPERIODO // SUBS(TOPISRL->EMISSAO,1,6)			
			ISRL->RIFSUJEITO := ALLTRIM(TOPISRL->A2_CGC)	
			ISRL->NUMFATURA  := cNFISCAL	
			ISRL->ORDEMPAGO  := cORDPAGO	
			ISRL->CONCEITO   := TOPISRL->FE_CONCEPT	
			ISRL->VALORBASE  := alltrim(STR(TOPISRL->VALORBASE,17,2))	
			ISRL->PERCENT    := ALLTRIM(nPERCENT)	
		MSUNLOCK()	
		
		DBSELECTAREA("TOPISRL")	
		
		TOPISRL->(DBSKIP())
	ENDDO	

	dbSelectArea("ISRL")
	DBGOTOP()

Return ("ISRL")

...