Árvore de páginas

Versões comparadas

Chave

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

...

Bloco de código
languagedelphi
titleExemplo: GFEXFB11GFEA032F
linenumberstrue
#INCLUDE 'PROTHEUS.CH'
User Function GFEA032F()
Local cNrOcor := PARAMIXB[1]
Local cNrCalc := PARAMIXB[2]
Local iNrEntrega := 0
Local dVlFret := 0
Local dVlReent := 0
Local nPercEnt := 0

	dbSelectArea("GWG")
	dbSetOrder(1)
	If dbSeek(xFilial("GWG") + cNrCalc)
	
		If ALLTRIM(GWG->GWG_CDTPVC) <> '' .and. ALLTRIM(GWG->GWG_CDCLFR) == '0001'
		
			dbSelectArea("GWL")
			dbSetOrder(1)
			dbSeek(xFilial("GWL") + cNrOcor)
			While !Eof() .and. xFilial("GWL") == GWL->GWL_FILIAL .And. GWL->GWL_NROCO == cNrOcor
			
				dbSelectArea("GW1")
				dbSetOrder(1)	
				If dbSeek(xFilial("GW1") + GWL->GWL_TPDC + GWL->GWL_EMITDC + GWL->GWL_SERDC + GWL->GWL_NRDC)
					
					if !empty(GW1->GW1_NRREG)				
						dbSelectArea("GU9")
						dbSetOrder(1)
						If dbSeek(xFilial("GU9") + GW1->GW1_NRREG)					
							nPercEnt := GU9->GU9_PENT	/* Campo específico */		
						Endif	
					Endif								
				ENDIF										
				dbSelectArea("GWL")
				dbSkip()
			EndDo	
					
			dbSelectArea("GWF")
			dbSetOrder(1)
			If dbSeek(xFilial("GWF") + cNrCalc)
			
				cNrRom := GWF->GWF_NRROM
					
			Endif			
			dbSelectArea("GWF")
			dbSetOrder(4)			
			dbSeek(xFilial("GWF") + cNrRom)
			While !eof() .and. xFilial("GWF") == GWF->GWF_FILIAL .And. GWF->GWF_NRROM == cNrRom 
			
				IF GWF->GWF_TPCALC == '1'
				
					iNrEntrega := iNrEntrega + 1
					
					dbSelectArea("GWI")
					dbSetOrder(1)			
					dbSeek(xFilial("GWI") + GWF->GWF_NRCALC)
					While !eof() .and. xFilial("GWI") == GWI->GWI_FILIAL .And. GWI->GWI_NRCALC == GWF->GWF_NRCALC 
						if ALLTRIM(GWI->GWI_CDCOMP) == "VALOR VEÍCULO"
					
							dVlFret := dVlFret + GWI->GWI_VLFRET
								
						ENDIF
						dbSelectArea("GWI")
						dbSkip()
					EndDo							
				
				ENDIF			
			
				dbSelectArea("GWF")
				dbSkip()
			EndDo	
			
			dVlReent := (dVlFret / iNrEntrega) + (dVlFret * (nPercEsp / 100))		
		Endif	
	Endif
	
Return dVlReent