Histórico da Página
...
Bloco de código | ||
---|---|---|
| ||
// MoveAgenda - Atualizar Agendas
User Function MoveAgenda(oSay)
Local aInfo := {}
Local aAux := {}
Local aCodTFF := {}
Local aCodTec := {}
Local aCampos := {}
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 cField := ""
Local cMsg := "Nao foram encontrados agendas de atendentes em aberto para o Orcamento/Contrato/Posto/Recursos Humanos informado."
Local dDtIni := Stod("")
Local dDtFin := Stod("")
Local lFound := .F.
Local nPosTFF := 0
Local nPosTec := 0
Local nTotal := 0
Local nPos := 0
Local nI := 0
Local nX := 0
BEGIN TRANSACTION
TFJ->(DbSetOrder(1))
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.%notdel%
INNER JOIN %table:TFL% TFL ON
TFL.TFL_FILIAL = %xFilial:TFL% AND
TFL.TFL_CODPAI = TFJ.TFJ_CODIGO 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.%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 // Contrato Origem
aAux[2] := cContrt+(cAliasABQ)->ABQ_ITEM+(cAliasABQ)->ABQ_ORIGEM // Contrato Destino
aAux[3] := (cAliasABQ)->ABQ_TOTAL-(cAliasABQ)->ABQ_SALDO // Consumido da configuracao original
aAdd(aInfo, aAux)
(cAliasABQ)->(DbSkip())
EndDo
(cAliasABQ)->(DbCloseArea())
If Len(aInfo) > 0 .And. MsgYesNo("Confirma a importacao das Agendas dos Atendentes do Orcamento " + cOriTFJ + " para o Orcamento " + cCodTFJ + "?")
// Realiza atualizacao 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_CODTEC, ABB_DTINI, ABB_HRINI, ABB_DTFIM, ABB.R_E_C_N_O_ AS REGISTRO
FROM %Table:ABB% ABB
WHERE ABB.ABB_FILIAL = %xFilial:ABB%
AND (ABB.ABB_CHEGOU <> "S" AND ABB.ABB_ATENDE <> "1") AND ABB.%NotDel%
AND ABB.ABB_IDCFAL %Exp:cIn2%
ORDER BY 1, 2, 3
EndSQL
While (cAliasABB)->(!EOF())
oSay:SetText("Agenda - Atendente: "+(cAliasABB)->ABB_CODTEC+" - Data: "+(cAliasABB)->ABB_DTINI)
ProcessMessages()
// Controle data inicial final
nPosTec := aScan(aCodTec)
If nPosTec == 0
aAdd(aCodTec,{(cAliasABB)->ABB_CODTEC,SToD((cAliasABB)->ABB_DTINI),SToD((cAliasABB)->ABB_DTINI)})
Else
aCodTec[nPosTec, 3] := StoD((cAliasABB)->ABB_DTINI)
EndIf
// Encontrar substit
nPos := aScan(aInfo, {|x| x[1] == (cAliasABB)->ABB_IDCFAL})
If nPos > 0
ABB->(DbGoTo((cAliasABB)->REGISTRO))
RecLock("ABB", .F.)
ABB->ABB_IDCFAL := aInfo[nPos][2]
ABB->(MsUnlock())
nTotal++
EndIf
(cAliasABB)->(DbSkip())
EndDo
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 ja consumido na config anterior
MsUnlock()
EndIf
Next nI
EndIf
// Atualizar gestao de escalas
aCodTFF := At870CodTFF(cCodTFJ)
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 configuracoes dos efetivos
BeginSql Alias cAliasTGY
SELECT TGY.*
FROM %table:TGY% TGY
WHERE
TGY.TGY_FILIAL = %xFilial:TGY% AND
TGY.TGY_ULTALO <> ' ' AND TGY.%notDel% AND
TGY.TGY_CODTFF IN %Exp:cSqlTFF%
EndSQL
If (cAliasTGY)->(!Eof())
aCampos := FWSX3Util():GetAllFields("TGY",.F.)
If Len(aCampos) > 0
While (cAliasTGY)->(!Eof())
// Pesquisar datas Inicial e Final
nPosTFF := aScan(aCodTFF, {|x|x[1]==(cAliasTGY)->TGY_CODTFF})
If nPosTFF > 0
nPosTec := aScan(aCodTec, {|x|x[1]==(cAliasTGY)->TGY_ATEND})
dDtIni := StoD("")
dDtFin := StoD("")
If nPosTec > 0
dDtIni := aCodTec[nPosTec, 2]
dDtFin := aCodTec[nPosTec, 3]
EndIf
// Atualizacao configuracoes
dbSelectArea("TGY")
TGY->(DbSetOrder(1))
lFound := TGY->(DbSeek(xFilial("TGY")+(cAliasTGY)->TGY_ESCALA+(cAliasTGY)->TGY_CODTDX+aCodTFF[nPosTFF, 2]+(cAliasTGY)->TGY_ITEM))
RecLock("TGY", !lFound)
For nX := 1 to Len(aCampos)
cField := AllTrim(aCampos[nX])
If cField == "TGY_CODTFF"
TGY->TGY_CODTFF := aCodTFF[nPosTFF, 2]
ElseIf cField == "TGY_DTINI" .And. !Empty(dDtIni)
TGY->TGY_DTINI := dDtIni
ElseIf cField == "TGY_DTFIM" .And. !Empty(dDtFin)
TGY->TGY_DTFIM := dDtFin
ElseIf cField == "TGY_ULTALO" .And. !Empty(dDtFin)
TGY->TGY_ULTALO := dDtFin
ElseIf FWSX3Util():GetFieldType(cField) == "D"
TGY->&(cField) := SToD((cAliasTGY)->&(cField))
Else
TGY->&(cField) := (cAliasTGY)->&(cField)
EndIf
Next nX
TGY->(MsUnlock())
EndIf
(cAliasTGY)->(DbSkip())
EndDo
(cAliasTGY)->(DbCloseArea())
EndIf
EndIf
EndIf
If nTotal == 0
cMsg := "Nao foram encontradas Agendas."
Else
cMsg := "Foram processados " + cValToChar(nTotal) + " Agendas."
EndIf
Else
cMsg := "Nao foi informado nenhum Orcamento/Contrato/Posto/Recursos Humano para este Contrato."
EndIf
EndIf
END TRANSACTION
MsgAlert(cMsg)
Return Nil |
...
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas