Relatorio Absenteismo Protheus
Relatorio Absenteismo Protheus
Relatorio Absenteismo Protheus
ch'
#Include 'fileio.ch'
/*
_____________________________________________________________________________
�����������������������������������������������������������������������������
��+----------+----------+-------+-----------------------+------+----------+��
��� Programa � BSINDCAD � Autor � Lincoln Vasconcelos � Data � 19/04/16 ���
��+----------+----------+-------+-----------------------+------+----------+��
���Descri��o � R�latorio Base de indicadores, gera um excel com as ���
��� � seguintes planilhas (Admissoes, Desligamentos, ���
��� � Base Mensal, QLP, Absteismo, Turnover) com os dados dos ���
��� � funcionarios. ���
��+----------+------------------------------------------------------------+��
��� Uso � ���
��+----------+------------------------------------------------------------+��
�����������������������������������������������������������������������������
�����������������������������������������������������������������������������
*/
(cTmpADM)->(dbCloseArea())
(cTmpDEM)->(dbCloseArea())
(cTmpBMS)->(dbCloseArea())
Return
Local aPergunta := {}
// mv_par01 // De matricula.
// mv_par02 // At� matricula.
// mv_par03 // Da Periodo inicial.
// mv_par04 // At� o Periodo final.
U_CriaPerg(cPerg, aPergunta)
Return
While dDataUM <= mv_par04 // Enquanto a data atual for menor que a ultima data
selecionada pelo usuario.
/*
Layout aMeses, vetor usado para Base Mensal.
aMeses[x][1] // Numero do Mes em caracter ex: '01' -> Janeiro
aMeses[x][2] // Numero do Ano em caracter ex: '2016'
aMeses[x][3] // Nome do Mes por extenso em caracter ex: JANEIRO
aMeses[x][4] // Primeiro dia do mes corrente em data ex: 01/01/2016
aMeses[x][5] // Ultimo dia do mes corrente em data ex: 31/01/2016
*/
AADD(aMeses,{AllTrim(StrZero(Month(dDataUM),2)), AllTrim(Str(Year(dDataUM))),
Upper(AllTrim(MesExtenso(Month(dDataUM)))), dDataUM, Lastday(dDataUM, 0)})
dDataUM := Lastday(dDataUM, 0)+1 // Retorna o primeiro dia do outro mes
EndDo
Return aMeses
cArqTmpADM := CriaTrab(aEstrutura,.T.)
Use (cArqTmpADM) Alias (cTmpADM) New Exclusive
Return cArqTmpADM
AADD(aEstrutura,{"NMES" ,"C" ,2
,0 }) // Numero
do m�s.
AADD(aEstrutura,{"CODEMP" ,"C" ,2
,0 }) // Codigo
da empresa.
AADD(aEstrutura,{"CODFIL" ,"C" ,2
,0 }) // Codigo
da filial.
AADD(aEstrutura,{"DESCMES" ,"C" ,10
,0 }) // Nome
do m�s.
AADD(aEstrutura,{"DESCFILI" ,"C" ,41
,0 }) //
Descri�o da filial da empresa do funcionario.
AADD(aEstrutura,{"MATRICULA" ,TamSX3("RA_MAT")[3] ,TamSX3("RA_MAT")[1]
,TamSX3("RA_MAT")[2] }) // Matricula do Funcionario.
AADD(aEstrutura,{"CPF" ,TamSX3("RA_CIC")[3] ,TamSX3("RA_CIC")
[1]+3 ,TamSX3("RA_CIC")[2] }) // CPF do funcionario.
AADD(aEstrutura,{"CODCC" ,TamSX3("RA_CC")[3] ,TamSX3("RA_CC")[1]
,TamSX3("RA_CC")[2] }) // Codigo do Centro de Custo do Funcionario.
AADD(aEstrutura,{"DESCCC" ,TamSX3("CTT_DESC01")[3]
,TamSX3("CTT_DESC01")[1] ,TamSX3("CTT_DESC01")[2] }) // Descri��o do
Centro de Custo do Funcionario.
AADD(aEstrutura,{"NOME" ,TamSX3("RA_NOME")[3] ,TamSX3("RA_NOME")[1]
,TamSX3("RA_NOME")[2] }) // Nome do Funcionario.
AADD(aEstrutura,{"FUNCAO" ,TamSX3("RJ_DESC")[3] ,TamSX3("RJ_DESC")[1]
,TamSX3("RJ_DESC")[2] }) // Descri��o da func�o do funcionario.
AADD(aEstrutura,{"DTADMISAO" ,TamSX3("RA_ADMISSA")[3] ,TamSX3("RA_ADMISSA")[1]
,TamSX3("RA_ADMISSA")[2] }) // Data de Admiss�o do funcionario.
AADD(aEstrutura,{"DTDEMISAO" ,TamSX3("RA_DEMISSA")[3] ,TamSX3("RA_DEMISSA")[1]
,TamSX3("RA_DEMISSA")[2] }) // Data de Demiss�o do funcionario.
AADD(aEstrutura,{"SALARIO" ,TamSX3("RA_SALARIO")[3]
,TamSX3("RA_SALARIO")[1] ,TamSX3("RA_SALARIO")[2] }) // Salario do
Funcionario.
/*Se a tabela ja estiver aberta fecha*/
If Select(cTmpDEM) > 0
(cTmpDEM)->(dbCloseArea())
EndIf
cArqTmpDEM := CriaTrab(aEstrutura,.T.)
Use (cArqTmpDEM) Alias (cTmpDEM) New Exclusive
Return cArqTmpDEM
/*Static Function que cria tabela temporaria para a area de Base Mensal*/
Static Function CriaTmpBMS(cTmpBMS)
cArqTmpBMS := CriaTrab(aEstrutura,.T.)
Use (cArqTmpBMS) Alias (cTmpBMS) New Exclusive
Return cArqTmpBMS
For x := 1 To Len(aMeses)
RecLock(cTmpADM,.T.)
(cTmpADM)->NMES := aMeses[x][1]
(cTmpADM)->CODEMP := aEmp[nCont][1]
(cTmpADM)->CODFIL := (cTrbQry)->FILIAL
(cTmpADM)->DESCMES := (cTrbQry)->MES
(cTmpADM)->DESCFILI := FWFilialName(aEmp[nCont][1],(cTrbQry)-
>FILIAL)
(cTmpADM)->MATRICULA := (cTrbQry)->MATRICULA
(cTmpADM)->CPF := Transform(AllTrim((cTrbQry)->CPF), "@R
999.999.999-99")
(cTmpADM)->CODCC := (cTrbQry)->CODCC
(cTmpADM)->DESCCC := (cTrbQry)->DESCCC
(cTmpADM)->NOME := (cTrbQry)->NOME
(cTmpADM)->FUNCAO := (cTrbQry)->FUNCAO
(cTmpADM)->DTADMISAO := STOD((cTrbQry)->DTADMISAO)
(cTmpADM)->DTDEMISAO := STOD((cTrbQry)->DTDEMISAO)
(cTmpADM)->SALARIO := (cTrbQry)->SALARIO
MsUnLock(cTmpADM)
(cTrbQry)->(dbSkip())
EndDo
(cTrbQry)->(dbCloseArea())
Next x
Next nCont
Return
For x := 1 To Len(aMeses)
RecLock(cTmpDEM,.T.)
(cTmpDEM)->NMES := aMeses[x][1]
(cTmpDEM)->CODEMP := aEmp[nCont][1]
(cTmpDEM)->CODFIL := (cTrbQry)->FILIAL
(cTmpDEM)->DESCMES := (cTrbQry)->MES
(cTmpDEM)->DESCFILI := FWFilialName(aEmp[nCont][1],(cTrbQry)-
>FILIAL)
(cTmpDEM)->MATRICULA := (cTrbQry)->MATRICULA
(cTmpDEM)->CPF := Transform(AllTrim((cTrbQry)->CPF), "@R
999.999.999-99")
(cTmpDEM)->CODCC := (cTrbQry)->CODCC
(cTmpDEM)->DESCCC := (cTrbQry)->DESCCC
(cTmpDEM)->NOME := (cTrbQry)->NOME
(cTmpDEM)->FUNCAO := (cTrbQry)->FUNCAO
(cTmpDEM)->DTADMISAO := STOD((cTrbQry)->DTADMISAO)
(cTmpDEM)->DTDEMISAO := STOD((cTrbQry)->DTDEMISAO)
(cTmpDEM)->SALARIO := (cTrbQry)->SALARIO
MsUnLock(cTmpDEM)
(cTrbQry)->(dbSkip())
EndDo
(cTrbQry)->(dbCloseArea())
Next x
Next nCont
Return
For x := 1 To Len(aMeses)
(cTrbQry)->(dbGoTop())
While !(cTrbQry)->(Eof())
cFil := (cTrbQry)->FILIAL // Filial.
cMat := (cTrbQry)->MATRICULA // Matricula.
cTurno := (cTrbQry)->TURNO // Turno trabalhado.
dDemissao := STOD((cTrbQry)->DTDEMISAO) // Data de demiss�o do
Funcionario, para calculo dos dias uteis.
RecLock(cTmpBMS,.T.)
(cTmpBMS)->NMES := aMeses[x][1]
(cTmpBMS)->CODEMP := aEmp[nCont][1]
(cTmpBMS)->CODFIL := cFil
(cTmpBMS)->DESCMES := (cTrbQry)->MES
(cTmpBMS)->DESCFILI := FWFilialName(aEmp[nCont][1],(cTrbQry)-
>FILIAL)
(cTmpBMS)->MATRICULA := cMat
(cTmpBMS)->CPF := Transform(AllTrim((cTrbQry)->CPF), "@R
999.999.999-99")
(cTmpBMS)->CODCC := (cTrbQry)->CODCC
(cTmpBMS)->DESCCC := (cTrbQry)->DESCCC
(cTmpBMS)->NOME := (cTrbQry)->NOME
(cTmpBMS)->FUNCAO := (cTrbQry)->FUNCAO
(cTmpBMS)->DTADMISAO := STOD((cTrbQry)->DTADMISAO)
(cTmpBMS)->DTDEMISAO := STOD((cTrbQry)->DTDEMISAO)
(cTmpBMS)->SALARIO := (cTrbQry)->SALARIO
(cTmpBMS)->DIASUTEIS := aDiasUteis[1][1]
(cTmpBMS)->CH := aTransTudo[1]
(cTmpBMS)->CHMESPREV := aTransTudo[2]
(cTmpBMS)->ABONOAUT := aTransTudo[3]
(cTmpBMS)->ATESMED := aTransTudo[4]
(cTmpBMS)->CHNAOREA := aTransTudo[5]
(cTmpBMS)->ABSTEISMO := aTransTudo[6]
(cTmpBMS)->HEPAGA := aTransTudo[7]
(cTmpBMS)->FADESC := aTransTudo[8]
(cTmpBMS)->HPOSTRIMES := aTransTudo[9]
(cTmpBMS)->HNEGTRIMES := aTransTudo[10]
MsUnLock(cTmpBMS)
(cTrbQry)->(dbSkip())
EndDo
Next x
(cTrbQry)->(dbCloseArea())
Next nCont
Return
aLinhaADM := {(cTmpADM)->DESCMES,;
(cTmpADM)->DESCFILI,;
(cTmpADM)->MATRICULA,;
(cTmpADM)->CPF,;
(cTmpADM)->CODCC,;
(cTmpADM)->DESCCC,;
(cTmpADM)->NOME,;
(cTmpADM)->FUNCAO,;
(cTmpADM)->DTADMISAO,;
IIF(Empty((cTmpADM)->DTDEMISAO), " ",(cTmpADM)-
>DTDEMISAO),;
(cTmpADM)->SALARIO}
(cTmpADM)->(dbSkip())
EndDo
Return
aLinhaDEM := {(cTmpDEM)->DESCMES,;
(cTmpDEM)->DESCFILI,;
(cTmpDEM)->MATRICULA,;
(cTmpDEM)->CPF,;
(cTmpDEM)->CODCC,;
(cTmpDEM)->DESCCC,;
(cTmpDEM)->NOME,;
(cTmpDEM)->FUNCAO,;
(cTmpDEM)->DTADMISAO,;
(cTmpDEM)->DTDEMISAO,;
(cTmpDEM)->SALARIO}
(cTmpDEM)->(dbSkip())
EndDo
Return
(cTmpBMS)->(dbGoTop())
While !(cTmpBMS)->(EOF())
aLinhaBMS := {(cTmpBMS)->DESCMES,;
(cTmpBMS)->DESCFILI,;
(cTmpBMS)->MATRICULA,;
(cTmpBMS)->CPF,;
(cTmpBMS)->CODCC,;
(cTmpBMS)->DESCCC,;
(cTmpBMS)->NOME,;
(cTmpBMS)->FUNCAO,;
(cTmpBMS)->DTADMISAO,;
IIF(Empty((cTmpBMS)->DTDEMISAO), " ",(cTmpBMS)-
>DTDEMISAO),;
(cTmpBMS)->SALARIO,;
(cTmpBMS)->DIASUTEIS,;
(cTmpBMS)->CH,;
(cTmpBMS)->CHMESPREV,;
(cTmpBMS)->ABONOAUT,;
(cTmpBMS)->ATESMED,;
(cTmpBMS)->CHNAOREA,;
(cTmpBMS)->ABSTEISMO,;
(cTmpBMS)->HEPAGA,;
(cTmpBMS)->FADESC,;
(cTmpBMS)->HPOSTRIMES,;
(cTmpBMS)->HNEGTRIMES}
(cTmpBMS)->(dbSkip())
EndDo
Return
/*------------------------------------Static Function
Auxiliares------------------------------------*/
/*Verifica os dias de feriados, final de semana, dias n�o trabalhados na
tabela RCG por periodo e turno, para calculo de dias uteis.*/
Static Function VeriFerRCG(cFil, cMat, aEmp, nCont, x, aMeses, cTurno)
EndIf
(cTrbQry)->(dbGoTop())
While !(cTrbQry)->(Eof())
AADD(aFerRCG, (cTrbQry)->(RCG_DIAMES)) // Grava feriados, finais de
semanas, dias n�o trabalhados do m�s -> Formato AAAAMMDD.
(cTrbQry)->(dbSkip())
EndDo
(cTrbQry)->(dbCloseArea())
EndDo
Return aFerRCG
(cTrbQry)->(dbGoTop())
While !(cTrbQry)->(Eof())
AADD(aAfast, {(cTrbQry)->TPAFAST, (cTrbQry)->INIAFAST, (cTrbQry)->FIMAFAST,
(cTrbQry)->NUMDAFAST})
(cTrbQry)->(dbSkip())
EndDo
(cTrbQry)->(dbCloseArea())
Return aAfast
aFerRCG[y] -> Grava feriados, finais de semanas, dias n�o trabalhados no m�s dos
funcionarios -> Formato AAAAMMDD.
SPF->(dbSetOrder(1)) // PF_FILIAL+PF_MAT+DTOS(PF_DATA)
// testa pra ver se o dia � de feriado, DSR, n�o trabalhado na tabela RCG.
If aScan(aFerRCG, dTos(dDataIni)) <> 0
lFlag := .F.
EndIf
If lFlag // se ainda n�o entrou em nenhuma das regras acima, testa na regra
de afastamento.
lFlag := .F.
Endif
Next y
EndIf
EndDo
Return aDiasUteis
Return nCH
Return nCHMesPrev
Return nSomaAbono
(cTrbQry)->(dbGoTop())
While !(cTrbQry)->(Eof())
dDataIni := aMeses[x][4]
(cTrbQry)->(dbSkip())
EndDo
(cTrbQry)->(dbCloseArea())
Return nSomaAtest
Return nCHNaoReal
Return nAbstsm
Return nFTDesc
Local nHoras := 1
Local nSaldo := 0
Local nSaldoAnt := 0
Local nHPosNegTri := 0 // Hora mais menos trimestre -> pega da regra do relatorio
TOTVS -> PONTO ELETRONICO -> RELATORIOS -> BANCO DE HORAS -> RELATORIO DE
HORAS(PONR100.PRX)
Private dDataAux := Ctod('') //-- Variavel auxiliar para armazenar a ultima
data considerada no calculo do Saldo Anterior
dDataAux := CTOD(SPACE(8))
SPI->(dbSetOrder(2)) // PI_FILIAL+PI_MAT+Dtos(PI_DATA)+PI_PD
SPI->(dbGoTop()) // Primeiro Registro
SPI->(dbSeek(cFil+cMat)) // posiciona no banco de horas
If SP9->P9_TIPOCOD $ "1*3"
nValor:=If(SPI->PI_STATUS=="B",0,If(nHoras=1,SPI->PI_QUANT,SPI-
>PI_QUANTV))
//-- Para valor nao nulo considera a Data para Referencia do Saldo
dDataAux:=If(Empty(nValor),dDataAux,SPI->PI_DATA)
nSaldoAnt:=__TimeSum(nSaldoAnt,nValor)
Else
nValor:=If(SPI->PI_STATUS=="B",0,If(nHoras=1,SPI->PI_QUANT,SPI-
>PI_QUANTV))
//-- Para valor nao nulo considera a Data para Referencia do Saldo
dDataAux:=If(Empty(nValor),dDataAux,SPI->PI_DATA)
nSaldoAnt:=__TimeSub(nSaldoAnt,nValor)
Endif
nSaldo := nSaldoAnt
SPI->(dbSkip())
EndDo
nHPosNegTri := nSaldo
Return nHPosNegTri
If nPosNegTri >= 0
nHPosNeg := Int(nPosNegTri) // Hora + Trimestre
nMPosNeg := (nPosNegTri-nHPosNeg) * 100 // Minutos + Trimestre
cPosTri := AllTrim(Str(nHPosNeg))+':'+AllTrim(Str(nMPosNeg)) // Hora +
Minutos positivos trimestre
cNegTri := "0:0"
Else
nPosNegTri := nPosNegTri * -1 // Transforma de negativo pra positivo
nHPosNeg := Int(nPosNegTri) // Hora + Trimestre
nMPosNeg := (nPosNegTri-nHPosNeg) * 100 // Minutos + Trimestre
cNegTri := AllTrim(Str(nHPosNeg))+':'+AllTrim(Str(nMPosNeg)) // Hora +
Minutos faltas e descontos
cPosTri := "0:0" // Hora + Minutos negativo trimestre
EndIf
Return aTransTudo