Árvore de páginas

Versões comparadas

Chave

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

...

Bloco de código
titleImplementação
#INCLUDE 'PROTHEUS.CH'

User function a740GrdV()
Local oView  :=   PARAMIXB[1] //Viewdef
 
If !isBlind() .AND. VALTYPE(oView) == 'O' .AND. isInCallStack("At870PRev")
    oView:AddUserButton("Reajuste Retroativo","",{|oView| U_RRetroat(oView)},,,)
EndIf
Return
 
User Function RRetroat(oView)
Local oModel
Local oMdlTFJ
Local oDlgSelect
Local cFuncao       := SPACE(TamSx3("TFF_FUNCAO")[1])
Local cEscala       := SPACE(TamSx3("TFF_ESCALA")[1])
Local nPerc := 0
Local nMult := 0
Local nQuant    := 0
Local dDataRef  := dDataBase
Local cTodosLoc := "2"
Local cTodasLin := "2"
Local aOpcs := {"2 - Não","1 - Sim"}
Local aQtd := {"2 - Posicionada","1 - Todos"}
Local oGrp
 
If VALTYPE(oView) == 'O' .AND. VALTYPE(oModel := oView:GetModel()) == 'O'
    oMdlTFJ := oModel:GetModel("TFJ_REFER")
    If oMdlTFJ:GetValue("TFJ_CNTREC") == '1'
        DEFINE MSDIALOG oDlgSelect FROM 0,0 TO 320,300 PIXEL TITLE "Reajuste Retroativo"
         @ 5, 9 SAY "Função" SIZE 30, 30 PIXEL
 
        oGetSRA := TGet():New( 015, 009, { | u | If(PCount() > 0, cFuncao := u, cFuncao) },oDlgSelect, ;
            060, 010, "!@",{ || .T.}, 0, 16777215,,.F.,,.T.,,.F.,;
            ,.F.,.F.,{|| .T.},.F.,.F. ,,"cFuncao",,,,.T.  )
        oGetSRA:cF3 := 'SRJ'

        @ 5, 77 SAY "Escala" SIZE 30, 30 PIXEL

        oGetTDW := TGet():New( 015, 077, { | u | If(PCount() > 0, cEscala := u, cEscala) },oDlgSelect, ;
            060, 010, "!@",{ || .T.}, 0, 16777215,,.F.,,.T.,,.F.,;
            ,.F.,.F.,{|| .T.},.F.,.F. ,,"cEscala",,,,.T.  )
        oGetTDW:cF3 := 'TDW'
 
        @ 30, 9 SAY "Percentual (%)" SIZE 50, 30 PIXEL
 
        oDataDe := TGet():New( 40, 009, { | u | If( PCount() == 0, nPerc, nPerc := u ) },oDlgSelect, ;
            060, 010, "@E 99.99",, 0, 16777215,,.F.,,.T.,,.F.,,.F.,.F.,,.F.,.F. ,,"nPerc",,,,.T.)
 
        @ 30, 77 SAY "Multiplicador" SIZE 50, 30 PIXEL
 
        oDataAte := TGet():New( 40, 077, { | u | If( PCount() == 0, nMult, nMult := u ) },oDlgSelect, ;
            060, 010, "@E 99.99",, 0, 16777215,,.F.,,.T.,,.F.,,.F.,.F.,,.F.,.F. ,,"nMult",,,,.T.)
 
        @ 64, 9 SAY "Em todos os Locais?" SIZE 80, 30 PIXEL
        
        oCombo := TComboBox():New(63,77,{|u|if(PCount()>0,cTodosLoc:=u,cTodosLoc)},;
            aOpcs,40,10,oDlgSelect,,,,,,.T.,,,,,,,,,'cTodosLoc')

        oGrp    := TGroup():New(080, 005, 135, 140, "Alteração de Quantidade", oDlgSelect,,, .T.)
        
        @ 90, 9 SAY "Nova Quantidade" SIZE 50, 30 PIXEL
 
        oQuant := TGet():New( 100, 009, { | u | If( PCount() == 0, nQuant, nQuant := u ) },oDlgSelect, ;
            060, 010, "@E 99,999,999,999",, 0, 16777215,,.F.,,.T.,,.F.,,.F.,.F.,,.F.,.F. ,,"nQuant",,,,.T.)
 
        @ 90, 77 SAY "Data de Referencia" SIZE 50, 30 PIXEL
 
        oDataAte := TGet():New( 100, 077, { | u | If( PCount() == 0, dDataRef, dDataRef := u ) },oDlgSelect, ;
            060, 010, "@D",, 0, 16777215,,.F.,,.T.,,.F.,,.F.,.F.,,.F.,.F. ,,"dDataRef",,,,.T.)

        @ 120, 9 SAY "Todas as Linhas?" SIZE 80, 30 PIXEL
 
        oCombo1 := TComboBox():New(120, 077,{|u|if(PCount()>0,cTodasLin:=u,cTodasLin)},;
            aQtd,60,10,oDlgSelect,,,,,,.T.,,,,,,,,,'cTodasLin')    
        
        oRefresh := TButton():New( 144, 005, "Aplicar",oDlgSelect,{|| U_AplicVl(oModel, cFuncao , nPerc, nMult, LEFT(cTodosLoc,1), cEscala, nQuant, dDataRef, LEFT(cTodasLin,1)) , oDlgSelect:End()}, 60,10,,,.F.,.T.,.F.,,.F.,,,.F. )
 
        oExit := TButton():New( 144  , 080, "Sair",oDlgSelect,{|| oDlgSelect:End() }, 60,10,,,.F.,.T.,.F.,,.F.,,,.F. )
        
        ACTIVATE MSDIALOG oDlgSelect CENTER
    Else
        MsgAlert("Opção disponível apenas para contratos Recorrentes")
    EndIf
EndIf
 
Return .T.
 
 
User Function AplicVl(oModel, cFuncao , nPerc, nMult, cTodosLoc, cEscala, nQuant, dDataRef, cTodasLin)
Local lAllLoc   := cTodosLoc == '1'
Local lAllLinha := cTodasLin == '1'
Local oMdlTFL   := oModel:GetModel("TFL_LOC")
Local oMdlTFF   := oModel:GetModel("TFF_RH")
Local nX        := 0
Local nY        := 0
Local cLog      := "" 
Local aSaveRows := FwSaveRows()
Local nTotal    := 0
Local nGrandTot := 0
Local nVal      := 0
Local nValPrc   := 0
Local nPosTFF   := 0
Local nPosTFL   := 0
Local nValParc  := 0
Local lServRet  := .F.
Local cProdRet  := SuperGetMv('MV_PRODRET') 

DbSelectArea("TFF")
TFF->(DbSetOrder(1))

If TFF->(ColumnPos("TFF_PRDRET")) > 0 .And. TFF->(ColumnPos("TFF_VLRRET")) > 0
    lServRet := .T.
EndIf

If nQuant > 0 .And. !lAllLinha
    nPosTFF := oMdlTFF:GetLine()
    nPosTFL := oMdlTFL:GetLine()
    cLog += "Local: " + Alltrim(POSICIONE("ABS",1,xFilial("ABS") + oMdlTFL:GetValue("TFL_LOCAL"), "ABS_DESCRI")) + Chr(13) + Chr(10)
    cLog += " - RH: " + oMdlTFF:GetValue("TFF_COD") + Chr(13) + Chr(10)
    cLog += " - Função: " + Alltrim(POSICIONE("SRJ",1,xFilial("SRJ") + oMdlTFF:GetValue("TFF_FUNCAO"), "RJ_DESC")) + Chr(13) + Chr(10)
    cLog += " - Produto: " + Alltrim(Posicione("SB1",1,xFilial("SB1") + oMdlTFF:GetValue("TFF_PRODUT"), "B1_DESC")) + Chr(13) + Chr(10)
    cLog += " - Qtd. Venda Anterior: " + Alltrim(AllToChar(oMdlTFF:GetValue("TFF_QTDVEN"))) + Chr(13) + Chr(10)
    cLog += " - Qtd. Venda: " + Alltrim(AllToChar(nQuant)) + Chr(13) + Chr(10)
    cLog += " - Vlr. Venda Anterior: R$ " + Alltrim(TRANSFORM( oMdlTFF:GetValue("TFF_SUBTOT") , "@E 99,999,999,999.99" )) + Chr(13) + Chr(10)
    cLog += " - Vlr. Venda Novo: R$ " + Alltrim(TRANSFORM( ROUND(nQuant * oMdlTFF:GetValue("TFF_SUBTOT"), TamSX3("TFF_SUBTOT")[2]) , "@E 99,999,999,999.99" )) + Chr(13) + Chr(10)
    nValParc := U_AplicQtd(oMdlTFF,nQuant,dDataRef,.F.)
    nGrandTot += nValParc
    nTotal := oMdlTFF:GetValue("TFF_VLPRPA")
    //cLog += " - Valor Novo (prox. parcela): R$ " + Alltrim(TRANSFORM((nValParc), "@e 999,999,999.99" ))"
    cLog += " - Valor Novo (prox. parcela): R$ " + Alltrim(TRANSFORM((nValParc + nTotal), "@e 999,999,999.99" )) +;
    " ( R$ " + Alltrim(TRANSFORM(nValParc, "@e 999,999,999.99" )) + " )" + " + ( R$ " + Alltrim(TRANSFORM(nTotal, "@e 999,999,999.99" )) + " )" + Chr(13) + Chr(10)
    cLog += Chr(13) + Chr(10)
    cLog += Chr(13) + Chr(10)
EndIf

If nPerc > 0
    For nX := 1 To oMdlTFL:Length()
        If lAllLoc
            oMdlTFL:GoLine(nX)
        EndIf
        For nY := 1 To oMdlTFF:Length()
            oMdlTFF:GoLine(nY)
            If U_VldFiltro(oMdlTFF,cFuncao,cEscala) .AND. oMdlTFF:GetValue("TFF_COBCTR") != '2'
                cLog += "Local: " + Alltrim(POSICIONE("ABS",1,xFilial("ABS") + oMdlTFL:GetValue("TFL_LOCAL"), "ABS_DESCRI")) + Chr(13) + Chr(10)
                cLog += " - RH: " + oMdlTFF:GetValue("TFF_COD") + Chr(13) + Chr(10)
                cLog += " - Função: " + Alltrim(POSICIONE("SRJ",1,xFilial("SRJ") + oMdlTFF:GetValue("TFF_FUNCAO"), "RJ_DESC")) + Chr(13) + Chr(10)
                cLog += " - Produto: " + Alltrim(Posicione("SB1",1,xFilial("SB1") + oMdlTFF:GetValue("TFF_PRODUT"), "B1_DESC")) + Chr(13) + Chr(10)
                If lAllLinha .And. nQuant > 0
                    cLog += " - Qtd. Venda Anterior: " + Alltrim(AllToChar(oMdlTFF:GetValue("TFF_QTDVEN"))) + Chr(13) + Chr(10)
                    cLog += " - Qtd. Venda: " + Alltrim(AllToChar(nQuant)) + Chr(13) + Chr(10)
                    cLog += " - Vlr. Venda Anterior: R$ " + Alltrim(TRANSFORM( oMdlTFF:GetValue("TFF_SUBTOT") , "@E 99,999,999,999.99" )) + Chr(13) + Chr(10)
                    cLog += " - Vlr. Venda Novo: R$ " + Alltrim(TRANSFORM( ROUND(nQuant * oMdlTFF:GetValue("TFF_SUBTOT"), TamSX3("TFF_SUBTOT")[2]) , "@E 99,999,999,999.99" )) + Chr(13) + Chr(10)
                    cLog += " - Valor Antigo (prox. parcela): R$ " +  Alltrim(TRANSFORM( oMdlTFF:GetValue("TFF_VLPRPA") , "@e 999,999,999.99" )) + Chr(13) + Chr(10)
                    nValParc := U_AplicQtd(oMdlTFF,nQuant,dDataRef,.F.)
                    nTotal := ROUND( (oMdlTFF:GetValue("TFF_VLPRPA") * (nPerc / 100)) * nMult , TamSX3("TFF_VLPRPA")[2] )
                    nGrandTot += nTotal
                    nValParc := oMdlTFF:GetValue("TFF_VLPRPA") + nValParc
                    cLog += " - Valor Novo (prox. parcela): R$ " + Alltrim(TRANSFORM((nValParc + nTotal), "@e 999,999,999.99" )) +;
                    " ( R$ " + Alltrim(TRANSFORM(nValParc, "@e 999,999,999.99" )) + " )" + " + ( R$ " + Alltrim(TRANSFORM(nTotal, "@e 999,999,999.99" )) + " )" + Chr(13) + Chr(10)
                    cLog += Chr(13) + Chr(10)
                Else
                    cLog += " - Valor Antigo (prox. parcela): R$ " +  Alltrim(TRANSFORM( oMdlTFF:GetValue("TFF_VLPRPA") , "@e 999,999,999.99" )) + Chr(13) + Chr(10)
                    nTotal := ROUND( (oMdlTFF:GetValue("TFF_VLPRPA") * (nPerc / 100)) * nMult , TamSX3("TFF_VLPRPA")[2] )
                    nGrandTot += nTotal
                    cLog += " - Valor Novo (prox. parcela): R$ " + Alltrim(TRANSFORM((oMdlTFF:GetValue("TFF_VLPRPA") + nTotal), "@e 999,999,999.99" )) +;
                    " ( + R$ " + Alltrim(TRANSFORM(nTotal, "@e 999,999,999.99" )) + " )" + Chr(13) + Chr(10)
                    cLog += Chr(13) + Chr(10)
                EndIf
            EndIf
        Next nY
        cLog += REPLICATE("-",10)
        cLog += Chr(13) + Chr(10)
        If !lAllLoc
            Exit
        EndIf
    Next nX
EndIf
 
cLog += REPLICATE("-",15)
cLog += Chr(13) + Chr(10)
cLog += "Valor adicional prox. parcela: R$ " + Alltrim(TRANSFORM(nGrandTot, "@e 999,999,999.99" ))
 
AtShowLog(cLog,"Prévia de Valores",/*lVScroll*/,/*lHScroll*/,/*lWrdWrap*/,.F.)
 
If MsgYesNo("Aplicar valores calculados?")

    //Verifica se vai aplicar a quantidade somente para a linha posicionada
    If !lAllLinha .And. nQuant > 0
        oMdlTFL:GoLine(nPosTFL)
        oMdlTFF:GoLine(nPosTFF)    
        U_AplicQtd(oMdlTFF,nQuant,dDataRef,.T.)
    EndIf

    For nX := 1 To oMdlTFL:Length()
        If lAllLoc
            oMdlTFL:GoLine(nX)
        EndIf
        For nY := 1 To oMdlTFF:Length()
            oMdlTFF:GoLine(nY)
            If U_VldFiltro(oMdlTFF,cFuncao,cEscala) .AND. oMdlTFF:GetValue("TFF_COBCTR") != '2'

                //aplicar a quantidade para todas as linhas encontradas conforme os filtros
                If lAllLinha .And. nQuant > 0
                    U_AplicQtd(oMdlTFF,nQuant,dDataRef,.T.)
                EndIf

                nVal := oMdlTFF:GetValue("TFF_VLPRPA")
                nValPrc := oMdlTFF:GetValue("TFF_PRCVEN")
                //4.886,670
                //488,67
                If lServRet .And. nMult > 0
                    
                    nTotal := (nValPrc + (nValPrc * (nPerc / 100)))

                    oMdlTFF:SetValue("TFF_PRCVEN", nTotal)

                    nTotal := ROUND((((nValPrc * (nPerc / 100)) * nMult)) * oMdlTFF:GetValue("TFF_QTDVEN"),;
                            TamSX3("TFF_VLPRPA")[2])

                    oMdlTFF:SetValue("TFF_VLPRPA",nVal + nTotal)
                    
                    If !Empty(cProdRet)
                        oMdlTFF:SetValue("TFF_PRDRET",cProdRet)
                    EndIf

                    oMdlTFF:SetValue("TFF_VLRRET",;
                         ROUND((((nValPrc * (nPerc / 100)) * nMult)) * oMdlTFF:GetValue("TFF_QTDVEN"),TamSX3("TFF_VLPRPA")[2]))
                Else
                    oMdlTFF:SetValue("TFF_PRCVEN",;
                        ROUND((nValPrc + (nValPrc * (nPerc / 100))),;
                        TamSX3("TFF_PRCVEN")[2]))
    
                    oMdlTFF:SetValue("TFF_VLPRPA",;
                        ROUND((nVal + ((nVal * (nPerc / 100)) * nMult)),;
                        TamSX3("TFF_VLPRPA")[2]))
                EndIf    
            EndIf
        Next nY
        If !lAllLoc
            Exit
        EndIf
    Next nX
EndIf
 
FwRestRows( aSaveRows )
 
Return

User Function VldFiltro(oMdlTFF,cFuncao,cEscala)
Local lRetorno := .F.

If !Empty(cFuncao) .Or. !Empty(cEscala)
    If !Empty(cFuncao) .And. !Empty(cEscala)
        If oMdlTFF:GetValue("TFF_FUNCAO") == cFuncao .And. oMdlTFF:GetValue("TFF_ESCALA") == cEscala
            lRetorno := .T.
        EndIf
    Else
        If !Empty(cFuncao)
            If oMdlTFF:GetValue("TFF_FUNCAO") == cFuncao
                lRetorno := .T.
            EndIf
        Else
            If oMdlTFF:GetValue("TFF_ESCALA") == cEscala
                lRetorno := .T.
            EndIf
        EndIf
    EndIf
Else
    //Considera qualquer TFF quando os filtros estiverem vazios
    lRetorno := .T.
EndIf


Return lRetorno

User Function AplicQtd(oMdlTFF,nQuant,dDataRef,lSetValue)
Local lRet          := .T.
Local nDataFim      := Day(LastDate(dDataRef)) // ultimo dia do mes
Local nValor        := 0
Local nVlrPrx       := oMdlTFF:GetValue("TFF_VLPRPA") //Valor da proxima parcela   
Local nDataIni      := Day(dDataRef) //dia de inicio do contrato
Local nQtdAnt       := oMdlTFF:GetValue("TFF_QTDVEN")

If lSetValue
    //Altera a quantidade do campo TFF_QTDVEN
    lRet := oMdlTFF:SetValue("TFF_QTDVEN",nQuant)

    //Realiza o calculo da proxima parcela
    If lRet
        nValor  := oMdlTFF:GetValue("TFF_PRCVEN") * (nQuant - nQtdAnt) // preço de venda do contrato

        nValor := (nValor/nDataFim)*((nDataFim-nDataIni)+1)
    
        //Arredonda o valor
        nValor := Round(nValor,TamSX3("TFL_VLPRPA")[2])
        nValor := nVlrPrx + nValor
        oMdlTFF:SetValue("TFF_VLPRPA",nValor)
    EndIf
Else
    nValor   := oMdlTFF:GetValue("TFF_PRCVEN") * (nQuant - nQtdAnt)  // Valor a ser reajustado

    nValor := (nValor/nDataFim)*((nDataFim-nDataIni)+1)
    
    //Arredonda o valor
    nValor := Round(nValor,TamSX3("TFL_VLPRPA")[2])
EndIf

Return nValor


...