Páginas filhas
  • Exemplos / ExecBlock

Nesse tópico mostraremos um exemplo de utilização de um ponto de entrada. O ponto de entrada utilizado será o SF2460I, executado após a gravação da Nota Fiscal de Saída.

 

Na rotina padrão da Nota Fiscal de Saída (MATA460), o ponto de entrada foi disponibilizado da seguinte forma (devido à extensão do código fonte, colocamos apenas as linhas pertinentes ao ponto de entrada):

 

 

LOCAL lSF2460I := ExistBlock(“SF2460I”)

 

...

...

...

 

IF lSF2460I

          ExecBlock("SF2460I",.f.,.f.)

ENDIF                     

 

 

 

Abaixo colocamos um exemplo do ponto de entrada SF2460, demonstrando o que o ponto de entrada pode realizar.

 

USER FUNCTION SF2460I()

 

Local aArea         := GetArea()

Local aAreaSC6 := SC6->(GetArea())

Local aAreaSC5 := SC5->(GetArea())

Local cTipo          := ""  

Local cTipoEE     := ""

Local cDocE        := ""        

Local cSerE         := ""

Local cItemE        := ""

Local cItemP        := ""

Local cCodForn   := ""

Local cLojForn     := ""

Local cDocS        := ""

Local cSerS         := ""

Local cItemS       := ""

Local cCodCli      := ""

Local cLojCli        := ""

Local cCodigo     := ""

Local cLocal        := ""

Local nQtdeVen  := 0

Local aFifo           := {}

Local nXv             := 0

Local aAreaSF2  := SF2->( GetArea() )

Local aAreaSD2 := SD2->( GetArea() )

 

cTipo := SC5->C5_TIPO

 

dbSelectArea("SD2")

dbSetOrder(3)

dbSeek( SF2->( F2_FILIAL+F2_DOC+F2_SERIE+F2_CLIENTE+F2_LOJA ) )

 

While SD2->( !eof() ) .and. SF2->( F2_FILIAL+F2_DOC+F2_SERIE+F2_CLIENTE+F2_LOJA ) == SD2->( D2_FILIAL+D2_DOC+D2_SERIE+D2_CLIENTE+D2_LOJA )

 

                cTipoEE                                := ""

                cDocE                   := ""        

                cSerE                    := ""

                cItemE                   := ""

                cCodForn             := ""

                cLojForn               := ""

                cPedido                := SD2->D2_PEDIDO

                cSerS                    := SD2->D2_SERIE

                cItemS                   := SD2->D2_ITEM

                cDocS                   := SD2->D2_DOC

                cItemP                   := SD2->D2_ITEMPV

                cCodCli                 := SD2->D2_CLIENTE     

                cLojCli                   := SD2->D2_LOJA

                cLocal                   := SD2->D2_LOCAL

                cCodigo                                := SD2->D2_COD             

                nQtdeVen             := SD2->D2_QUANT  

                lConsig                 := .F.

 

                dbSelectArea("SC6")

                dbSetOrder(1)

 

                If dbSeek(xFilial("SC6") + cPedido + cItemP)

                               lConsig := SC6->C6_CONSIG_ == '1'

 

                               IF cTipo == "D"

                                         aFifo := { {SC6->C6_NFORI, SC6->C6_SERIORI, SC6->C6_ITEMORI,;

nQtdeVen, cCodCli, cLojCli} }

                               Elseif cTipo == "N"

                                         aFifo := __RecNFEnt(cCodigo,cLocal,nQtdeVen)

                               Endif

               

                               If lConsig

                                               IF cTipo == 'N'     

                                                               cTipoEE                := 'VC'                       

                                                               For nXv  := 1 to len(aFifo)

                                                                              cDocE                   := aFifo[nXv, 1]

                                                                              cSerE                    := aFifo[nXv, 2]

                                                                              cItemE                   := aFifo[nXv, 3]

                                                                              nQtdeVen             := aFifo[nXv, 4]

                                                                              cCodForn             := aFifo[nXv, 5]

                                                                              cLojForn               := aFifo[nXv, 6]

                                                                              U_RegConsig( cTipoEE, cDocE, cSerE, cItemE, cCodForn, cLojForn, cDocS, cSerS, cItemS, cCodCli, cLojCli, nQtdeVen, cCodigo, cLocal )

                                                               Next nXv

                                               ElseIf cTipo == 'D'

                                                               cTipoEE := 'DC'

 

                                                               For nXv  := 1 to len(aFifo)

                                                                              cDocE                   := aFifo[nXv, 1]

                                                                              cSerE                    := aFifo[nXv, 2]

                                                                              cItemE                   := aFifo[nXv, 3]

                                                                              nQtdeVen             := aFifo[nXv, 4]

                                                                              cCodForn             := aFifo[nXv, 5]

                                                                              cLojForn               := aFifo[nXv, 6]

                                                                              U_RegConsig( cTipoEE, cDocE, cSerE, cItemE, cCodForn, cLojForn, cDocS, cSerS, cItemS, cCodCli, cLojCli, nQtdeVen, cCodigo, cLocal )

                                                               Next nXv

 

                                               Endif

                 

                                               // Registrar na NF

                                               Reclock("SD2", .F.)

                                               SD2->D2_CONSIG_ := "1"

                                               MsUnlock()

                               Else

                                               // Registrar na NF

                                               Reclock("SD2", .F.)

                                               SD2->D2_CONSIG_ := "2"

                                               MsUnlock()

                               EndIf           

 

                EndIF                        

 

                dbSelectArea("SD2")

                SD2->( dbSkip() )

End

 

RestArea( aAreaSD2 )

RestArea( aAreaSF2 )

RestArea(aAreaSC5)

RestArea(aAreaSC6)

RestArea(aArea) 

 

Return Nil

  • Sem rótulos