#INCLUDE "PROTHEUS.CH"
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} Ponto de Entrada AT870NWMNU
/*/
//--------------------------------------------------------------------------------------------------------------------
User Function AT870NWMNU()
Local aRetMenu := {}
Local nC := 0
Local nTam := 0
If ValType(PARAMIXB) == "A"
nTam := Len(PARAMIXB)
For nC := 1 To nTam
aAdd(aRetMenu, aClone(PARAMIXB[nC]))
Next nC
EndIf
aAdd( aRetMenu, {"Importar Agendas", {||u_MoveAgenda()}, 2})
Return aRetMenu
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} MoveAgenda - Atualzar Agebndas
/*/
//--------------------------------------------------------------------------------------------------------------------
User Function MoveAgenda()
Local aInfo := {}
Local aAux := {}
Local aCodTFF := {}
Local cAliasABQ := GetNextAlias()
Local cAliasABB := GetNextAlias()
Local cAliasTGY := GetNextAlias()
Local cAliasP := "MNTPRO"
Local cCodTFJ := (cAliasP)->TFJ_CODIGO
Local cContrt := ""
Local cConRev := ""
Local cOriTFJ := ""
Local cIn2 := ""
Local cSqlTFF := ""
Local nPosTFF := 0
Local nPos := 0
Local nI := 0
Local nX := 0
BEGIN TRANSACTION
TFJ->(DbSetOrder(1)) //TFJ_FILIAL+TFJ_CODIGO
If TFJ->(DbSeek(xFilial("TFJ")+cCodTFJ))
cContrt := TFJ->TFJ_CONTRT
cConRev := TFJ->TFJ_CONREV
cOriTFJ := TFJ->TFJ_XCODOR BeginSql Alias cAliasABQ
SELECT
TFF.TFF_COD,
TFF.TFF_XCODOR,
ABQ.ABQ_CONTRT,
ABQ.ABQ_ITEM,
ABQ.ABQ_ORIGEM,
ABQ.ABQ_TOTAL,
ABQ.ABQ_SALDO
FROM %table:ABQ% ABQ
INNER JOIN %table:TFJ% TFJ ON
TFJ.TFJ_FILIAL = %xFilial:TFJ% AND
TFJ.TFJ_CODIGO = %Exp:cOriTFJ% AND
TFJ.TFJ_STATUS = '1' AND
TFJ.TFJ_XCODOR <> ' ' AND TFJ.%notdel%
INNER JOIN %table:TFL% TFL ON
TFL.TFL_FILIAL = %xFilial:TFL% AND
TFL.TFL_CODPAI = TFJ.TFJ_CODIGO AND
TFL.TFL_XCODOR <> ' ' AND TFL.%notdel%
INNER JOIN %table:TFF% TFF ON
TFF.TFF_FILIAL = %xFilial:TFF% AND
TFF.TFF_FILIAL = ABQ.ABQ_FILTFF AND
TFF.TFF_COD = ABQ.ABQ_CODTFF AND
TFF.TFF_CODPAI = TFL.TFL_CODIGO AND
TFF.TFF_XCODOR <> ' ' AND TFF.%notdel%
WHERE
ABQ.ABQ_FILIAL = %xFilial:ABQ% AND ABQ.%notdel%
EndSql
While (cAliasABQ)->(!EOF())
aAux := Array(3)
aAux[1] := (cAliasABQ)->ABQ_CONTRT+(cAliasABQ)->ABQ_ITEM+(cAliasABQ)->ABQ_ORIGEM
aAux[2] := cContrt+(cAliasABQ)->ABQ_ITEM+(cAliasABQ)->ABQ_ORIGEM
aAux[3] := (cAliasABQ)->ABQ_TOTAL -(cAliasABQ)->ABQ_SALDO // Consumido da configuração original
aAdd(aInfo, aAux)
(cAliasABQ)->(DbSkip())
EndDo
(cAliasABQ)->(DbCloseArea())
// Realiza atuação da agenda do atendente
For nX := 1 To LEN(aInfo)
cIn2 += " '" + aInfo[nX][1] + "' "
If nX <> LEN(aInfo)
cIn2 += ","
EndIf
Next nX
cIn2 := "% IN ( " + cIn2 + ") %"
BeginSQL Alias cAliasABB
SELECT ABB_IDCFAL, ABB.R_E_C_N_O_ AS REGISTRO
FROM %Table:ABB% ABB
WHERE ABB.ABB_FILIAL = %xFilial:ABB%
AND (ABB.ABB_CHEGOU == "S" OR ABB.ABB_ATENDE == "1")
AND ABB.%NotDel%
AND ABB.ABB_IDCFAL %Exp:cIn2%
EndSQL
While (cAliasABB)->(!EOF())
nPos := aScan(aInfo, {|x| x[1] == (cAliasABB)->ABB_IDCFAL}) // Encontrar registro substituido
If nPos > 0
ABB->(DbGoTo((cAliasABB)->REGISTRO))
RecLock("ABB", .F.)
ABB->ABB_IDCFAL := aInfo[nPos][2] // Atualizar IDCFAL
ABB->(MsUnlock())
EndIf
(cAliasABB)->(DbSkip())
EndDo
(cAliasABB)->(DbCloseArea())
If Empty(cContrt) .OR. At740Recor(cContrt)
For nI := 1 To Len(aInfo)
// Atualizar Saldos
ABQ->(DbSetOrder(1)) //ABQ_FILIAL + ABQ_CONTRT + ABQ_ITEM + ABQ_ORIGEM
If ABQ->(DbSeek(xFilial("ABQ")+aInfo[nI][2]))
RecLock("ABQ", .F.)
ABQ->ABQ_SALDO := ABQ->ABQ_TOTAL - aInfo[nI][3] // Desconta o que já foi consumido na configuração anterior
MsUnlock()
EndIf
Next nI
EndIf
// Atualizar informação da gestão de escalas
aCodTFF := At870CodTFF(cOriTFJ)
If Len(aCodTFF) > 0
cSqlTFF := "%("
For nI:=1 To Len(aCodTFF)
cSqlTFF += "'" + aCodTFF[ nI, 1 ] + "'"
If (nI+1) <= Len(aCodTFF)
cSqlTFF += ","
EndIf
Next nI
cSqlTFF += ")%"
// Verificar as configurações dos efetivos
BeginSql Alias cAliasTGY
SELECT
TGY.TGY_FILIAL, TGY.TGY_ESCALA, TGY.TGY_CODTDX,
TGY.TGY_CODTFF, TGY.TGY_ITEM
FROM
%table:TGY% TGY
WHERE
TGY.TGY_FILIAL = %xFilial:TGY% AND TGY.%notDel% AND
TGY.TGY_CODTFF IN %Exp:cSqlTFF%
EndSql
// Realiza a atualização das configurações do efetivo TGY
dbSelectArea("TGY")
TGY->(DbSetOrder(1)) //TGY_FILIAL+TGY_ESCALA+TGY_CODTDX+TGY_CODTFF+TGY_ITEM
While (cAliasTGY)->(!Eof())
If TGY->(DbSeek(xFilial("TGY")+(cAliasTGY)->TGY_ESCALA+(cAliasTGY)->TGY_CODTDX+(cAliasTGY)->TGY_CODTFF+(cAliasTGY)->TGY_ITEM))
nPosTFF := aScan(aCodTFF, {|x| x[1] == (cAliasTGY)->TGY_CODTFF})
If nPosTFF > 0
RecLock("TGY", .F.)
TGY->TGY_CODTFF := aCodTFF[nPosTFF, 2]
TGY->(MsUnlock())
EndIf
EndIf
(cAliasTGY)->(DbSkip())
EndDo
(cAliasTGY)->(DbCloseArea())
EndIf
EndIf
END TRANSACTION
Return Nil
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} At870CodTFF - retornar o codigo do recurso humano dentro do orçamento
/*/
//--------------------------------------------------------------------------------------------------------------------
Static Function At870CodTFF(cCodTFJ)
Local aRet := {}
Local cAliasTFJ := GetNextAlias()
BeginSql Alias cAliasTFJ
SELECT
TFF.TFF_COD, TFF.TFF_XCODOR FROM
%table:TFJ% TFJ
JOIN %table:TFL% TFL ON
TFL.TFL_FILIAL = %xFilial:TFL% AND
TFL.TFL_CODPAI = TFJ.TFJ_CODIGO AND TFL.%notDel%
JOIN %table:TFF% TFF ON
TFF.TFF_FILIAL = %xFilial:TFF% AND
TFF.TFF_CODPAI = TFL.TFL_CODIGO AND
TFF.TFF_XCODOR <> ' ' AND TFF.%notDel%
WHERE
TFJ.TFJ_FILIAL = %xFilial:TFJ% AND
TFJ.TFJ_CODIGO = %Exp:cCodTFJ% AND TFJ.%notDel%
GROUP BY
TFF.TFF_COD, TFF.TFF_XCODOR EndSql
While (cAliasTFJ)->(!Eof())
aAdd(aRet,{(cAliasTFJ)->TFF_COD, (cAliasTFJ)->TFF_XCODOR})
(cAliasTFJ)->(DbSkip())
EndDo
(cAliasTFJ)->(dbCloseArea())
Return(aRet)
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} ConsLocOri - Consulta F3 campo TFL_XCODOR /*/
//--------------------------------------------------------------------------------------------------------------------
User Function ConsLocOri()
Local cFiltro := ""
Local oModel := FwModelActive()
Local oMdlTFJ := oModel:GetModel("TFJ_REFER")
Local oMdlTFL := oModel:GetModel("TFL_LOC")
If oMdlTFL:Length() > 0
cFiltro := "TFL->TFL_LOCAL == '" + oMdlTFL:GetValue("TFL_LOCAL") + "' .AND. TFL->TFL_CONTRT <> ' ' .AND. TFL->TFL_CODPAI == '" + oMdlTFJ:GetValue("TFJ_XCODOR") + "'"
cFiltro := "@#" + cFiltro + "@#"
EndIf
Return cFiltro
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} ConsRHOri - Consulta F3 campo TFF_XCODOR /*/
//--------------------------------------------------------------------------------------------------------------------
User Function ConsRHOri()
Local cFiltro := ""
Local oModel := FwModelActive()
Local oMdlTFL := oModel:GetModel("TFL_LOC")
Local oMdlTFF := oModel:GetModel("TFF_RH")
If oMdlTFF:Length() > 0
cFiltro := "TFF->TFF_PRODUT == '" + oMdlTFF:GetValue("TFF_PRODUT") + "' .AND. TFF->TFF_CONTRT <> ' ' .AND. TFF->TFF_CODPAI == '" + oMdlTFL:GetValue("TFL_XCODOR") + "'"
cFiltro := "@#" + cFiltro + "@#"
EndIf
Return cFiltro
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} ValLocOri - Valid do campo TFL_XCODOR /*/
//--------------------------------------------------------------------------------------------------------------------
User Function ValLocOri()
Local lRet := .F.
Local oModel := FwModelActive()
Local oMdlTFJ := oModel:GetModel("TFJ_REFER")
Local oMdlTFL := oModel:GetModel("TFL_LOC")
Local cAlias := GetNextAlias()
BeginSql Alias cAlias
SELECT 1
FROM
%table:TFL% TFL
WHERE
TFL.TFL_FILIAL = %xFilial:TFL% AND
TFL.TFL_CODIGO = %Exp:oMdlTFL:GetValue("TFL_XCODOR")% AND
TFL.TFL_CODPAI = %Exp:oMdlTFJ:GetValue("TFJ_CODIGO")% AND
TFL.TFL_LOCAL = %Exp:oMdlTFL:GetValue("TFL_LOCAL")% AND
TFL.TFL_CONTRT <> ' ' AND TFL.%notDel%
EndSql
If (cAlias)->(!Eof())
lRet := .T.
EndIf
(cAlias)->(dbCloseArea())
Return lRet
//--------------------------------------------------------------------------------------------------------------------
/*/{Protheus.doc} ValRHOri - Valid do campo TFF_XCODOR /*/
//--------------------------------------------------------------------------------------------------------------------
User Function ValRHOri()
Local lRet := .F.
Local oModel := FwModelActive()
Local oMdlTFL := oModel:GetModel("TFL_LOC")
Local oMdlTFF := oModel:GetModel("TFF_RH")
Local cAlias := GetNextAlias()
BeginSql Alias cAlias
SELECT 1
FROM
%table:TFF% TFF
WHERE
TFF.TFF_FILIAL = %xFilial:TFF% AND
TFF.TFF_COD = %Exp:oMdlTFF:GetValue("TFF_XCODOR")% AND
TFF.TFF_PRODUT = %Exp:oMdlTFF:GetValue("TFF_PRODUT")% AND
TFF.TFF_LOCAL = %Exp:oMdlTFL:GetValue("TFL_LOCAL")% AND
TFF.TFF_CONTRT <> ' ' AND TFF.%notDel%
EndSql
If (cAlias)->(!Eof())
lRet := .T.
EndIf
(cAlias)->(dbCloseArea())
Return lRet
FwMsgRun(Nil,{|oSay| u_MoveAgenda(oSay)}, Nil, "Atualizando...")}, 2})
Return aRetMenu
|