Page tree
Skip to end of metadata
Go to start of metadata

01. DADOS GERAIS

Linha de Produto:Microsiga Protheus®
Segmento:Serviços
Módulo:Gestão de Serviços
Função:TECA353
Ticket:Não há. 
Requisito/Story/Issue (informe o requisito relacionado) :

DSERSGS-5422


02. SITUAÇÃO/REQUISITO

Ponto de Entrada para Exportação de Adicional de Periculosidade, que será habilitado caso o parâmetro  MV_GSRHOTP contenha o valor 2

03. SOLUÇÃO 

Ponto de Entrada 

Descrição:Microsiga Protheus®
Localização:Serviços
Programa Fonte:TECA353.PRW
Função:at353EnvRH
Parâmetros
NomeTipoDescrição
MV_PAR01

Caractere

Atendente Inicial

MV_PAR02

Caractere

Atendente Final

MV_PAR03Data

Data Inicial da Agenda

MV_PAR04

Data

Data Final da Agenda

MV_PAR05

Data

Data de Referência
MV_PAR06Caractere

Processamento  1= Envio;2=Estorno

MV_PAR07CaractereLog 1=Total;2=Somente Erro
Retorno:


#INCLUDE "PROTHEUS.CH"
#INCLUDE "FILEIO.CH"

#DEFINE INSALUBRIDADE 1

#DEFINE PERICULOSIDADE 2

#DEFINE NENHUM ""

#DEFINE MINIMO "2"

#DEFINE MEDIO "3"

#DEFINE MAXIMO "4"

#DEFINE INTEGRAL "2"

#DEFINE PROPORCIONAL "3"

#DEFINE ADICIONAIS_FILMAT  1

#DEFINE ADICIONAIS_MATRICULA        2

#DEFINE ADICIONAIS_CODTEC 3

#DEFINE ADICIONAIS_ADICIONAL          4

#DEFINE ADICIONAIS_TIPO                                       5

#DEFINE ADICIONAIS_GRAU                                    6

#DEFINE ADICIONAIS_HORAS                                  7

#DEFINE ADICIONAIS_PREV                                      7


User Function At353EvRH()

Local nY := 0

Local cDetLinha := ""

Local nC := 0

Local cDirArq := "\EXPCSVTEC\"+FWGrpCompany()+"\" + StrTran(FwCodFil(), " ", "_")+"\"

Local cMsg := ""

Local lRet := .F.

Local cCodTecDe := ""

Local cCodTecAt := ""

Local dDataDe := CtoD("")

Local dDataAte := Ctod("")

Local dDataRef := Ctod("")

Local lEnvio :=  .F.//"1"

Local lLogtot := .F. //"1"

Local nTotReg := 0

Local aAdicionais := {}   

Local nPos := 0

Local cAliasA := GetNextAlias()

Local cQuery := ""

If ValType(PARAMIXB) == "A" .AND. Len(PARAMIXB) >= 7

                If !ExistDir(cDirArq)

                               MakeDir("\EXPCSVTEC\")

                               MakeDir("\EXPCSVTEC\"+FWGrpCompany()+"\")

                               MakeDir(cDirArq)

                EndIf

                cCodTecDe := PARAMIXB[01]

                cCodTecAt := PARAMIXB[02]    

                dDataDe := PARAMIXB[03]

                dDataAte := PARAMIXB[04]

                dDataRef := PARAMIXB[05]

                lEnvio := PARAMIXB[06] == 1

                lLogtot := PARAMIXB[07] == 1             

                cNomeArq := "U_At353EvRH"+Dtos(Date())+IIF(lEnvio, "3", "5")+".txt"


                cQuery :="SELECT AA1.AA1_FUNFIL AS RA_FILIAL, AA1.AA1_CDFUNC AS RA_MAT, SRA.RA_NOME, SRA.RA_ADCINS, SRA.RA_ADCPERI, SRA.RA_PROCES, SRA.RA_HRSMES, SRA.RA_CC, SRA.RA_CODFUNC, "

                cQuery += CRLF + "TFF.TFF_PERICU, TFF.TFF_INSALU, TFF.TFF_GRAUIN, TFF.TFF_FUNCAO, "

                cQuery += CRLF + "AA1.AA1_FUNFIL, AA1.AA1_CDFUNC, AA1.AA1_NOMTEC, AA1.AA1_CODTEC, "

                cQuery += CRLF + "ABS.ABS_CCUSTO, "

                cQuery += CRLF + "AB9.R_E_C_N_O_ AS RECAB9, ABA_QUANT HORAS "

               

                cQuery += CRLF + " FROM " + RetSqlName("ABB")+ " ABB "

                cQuery += CRLF + " INNER JOIN " + RetSqlName("AA1")+ " AA1 ON  "

                cQuery += CRLF + "(    AA1.AA1_FILIAL  = '"+ xFilial("AA1") +"'"

                cQuery += CRLF + " AND AA1.AA1_CODTEC  = ABB.ABB_CODTEC"

                cQuery += CRLF + " AND AA1.D_E_L_E_T_  = ' ' )"           

               

               

                cQuery += CRLF + " LEFT JOIN " + RetSqlName("SRA")+ " SRA ON "

                cQuery += CRLF + " (   SRA.RA_FILIAL   = AA1.AA1_FUNFIL"

                cQuery += CRLF + " AND SRA.RA_MAT      = AA1.AA1_CDFUNC"

                cQuery += CRLF + " AND SRA.D_E_L_E_T_  = ' ' ) "          

               

                cQuery += CRLF + " INNER JOIN " + RetSqlName("AB9")+ " AB9 ON "

                cQuery += CRLF + " (   AB9.AB9_FILIAL  = '"+ xFilial("AB9") +"'"

                cQuery += CRLF + " AND AB9.AB9_ATAUT   = ABB.ABB_CODIGO"          

                cQuery += CRLF + " AND SUBSTRING( AB9.AB9_NUMOS, 1, 6 ) = ABB.ABB_NUMOS"

                cQuery += CRLF + " AND AB9.AB9_CODTEC = ABB.ABB_CODTEC"

                cQuery += CRLF + " AND AB9.D_E_L_E_T_ = ' ' )"            

               

                cQuery += CRLF + " INNER JOIN " + RetSqlName("ABA")+ " ABA ON "

                cQuery += CRLF + " (   ABA.ABA_FILIAL = '"+ xFilial("ABA") +"'"

                cQuery += CRLF + " AND ABA.ABA_NUMOS = AB9.AB9_NUMOS"

                cQuery += CRLF + " AND ABA.ABA_SEQ = AB9.AB9_SEQ"

                cQuery += CRLF + " AND ABA.D_E_L_E_T_ = ' ' )"

               

                cQuery += CRLF + " INNER JOIN " +RetSqlName("ABQ")+ " ABQ ON "

                cQuery += CRLF + " (   ABQ.ABQ_FILIAL  = '"+ xFilial("ABQ") +"'"

                cQuery += CRLF + " AND ABQ.ABQ_CONTRT || ABQ.ABQ_ITEM || ABQ.ABQ_ORIGEM = ABB.ABB_IDCFAL"

                cQuery += CRLF + " AND ABQ.D_E_L_E_T_  = ' ' ) "         


                cQuery += CRLF + " INNER JOIN " + RetSqlName("TFF")+ " TFF ON "

                cQuery += CRLF + " (   TFF.TFF_FILIAL  = ABQ.ABQ_FILTFF"

                cQuery += CRLF + " AND TFF.TFF_COD     = ABQ.ABQ_CODTFF"

                cQuery += CRLF + " AND (TFF.TFF_PERICU <> '1' OR TFF.TFF_INSALU <> '1')"

                cQuery += CRLF + " AND TFF.D_E_L_E_T_  = ' ' ) "


                cQuery += CRLF + " INNER JOIN " + RetSqlName("ABS")+ " ABS ON "

                cQuery += CRLF + " (   ABS.ABS_FILIAL  = '"+ xFilial("ABS") +"'"

                cQuery += CRLF + " AND ABS.ABS_LOCAL = ABB.ABB_LOCAL "

                cQuery += CRLF + " AND ABS.D_E_L_E_T_  = ' ' ) "


                cQuery += CRLF + " WHERE ABB.ABB_FILIAL  = '"+ xFilial("ABB") +"'"

                cQuery += CRLF + " AND ABB.ABB_CODTEC BETWEEN '"+ cCodTecDe +"' AND '"+ cCodTecAt +"'"

                cQuery += CRLF + " AND ABB.ABB_DTINI  >= '"+ DtoS(dDataDe) +"'"

                cQuery += CRLF + " AND ABB.ABB_DTFIM  <= '"+ DtoS(dDataAte) +"'"

                cQuery += CRLF + " AND ABB.ABB_ATENDE  = '1'"

                cQuery += CRLF + " AND ABB.ABB_ATIVO   = '1'"

                cQuery += CRLF + " AND ABB.ABB_LOCAL  <> ' '"

                cQuery += CRLF + " AND ABB.D_E_L_E_T_  = ' '"

                cQuery += CRLF + " ORDER BY ABB.ABB_CODTEC"

               

               cQuery := ChangeQuery(cQuery)

                DbUseArea( .T., 'TOPCONN', TCGENQRY(,,cQuery), cAliasA , .T., .T.)

                aEval( ABB->(DbStruct()),{|x| If(x[2] != "C", TcSetField(cAliasA, AllTrim(x[1]), x[2], x[3], x[4]),Nil)})


                While (cAliasA)->(!Eof())

                                //Periculosidade

                               If !Empty((cAliasA)->TFF_PERICU) .AND. (cAliasA)->TFF_PERICU != "1"

                                              

                                               //Busca posição por tipo e grau

                                               nPos := aScan(aAdicionais, {|x|               x[ADICIONAIS_FILMAT] == (cAliasA)->RA_FILIAL .AND. ;

                                                                                                                                                                                            x[ADICIONAIS_MATRICULA] == (cAliasA)->RA_MAT.and. ;

                                                                                                                                                                                            x[ADICIONAIS_CODTEC] == (cAliasA)->AA1_CODTEC .and. ;

                                                                                                                                                                                            x[ADICIONAIS_ADICIONAL] == PERICULOSIDADE .AND.;

                                                                                                                                                                                            x[ADICIONAIS_TIPO] == (cAliasA)->TFF_PERICU .AND.;

                                                                                                                                                                                            x[ADICIONAIS_GRAU] == NENHUM})

                                                                                                                                                                                           

                                               If nPos == 0

                                                               aAdd(aAdicionais, Array(ADICIONAIS_PREV))

                                                               nPos := Len(aAdicionais)

                                                               aAdicionais[nPos][ADICIONAIS_FILMAT]            := (cAliasA)->RA_FILIAL

                                                               aAdicionais[nPos][ADICIONAIS_MATRICULA]                  := (cAliasA)->RA_MAT

                                                               aAdicionais[nPos][ADICIONAIS_CODTEC] := (cAliasA)->AA1_CODTEC

                                                               aAdicionais[nPos][ADICIONAIS_ADICIONAL]    := PERICULOSIDADE

                                                               aAdicionais[nPos][ADICIONAIS_TIPO]                  := (cAliasA)->TFF_PERICU

                                                               aAdicionais[nPos][ADICIONAIS_GRAU]                               := NENHUM

                                                               aAdicionais[nPos][ADICIONAIS_HORAS]                             := (cAliasA)->HORAS

               

                                               Else

                                                               aAdicionais[nPos][ADICIONAIS_HORAS] += (cAliasA)->HORAS

                                               EndIf                    

                                              

                               EndIf

                               //Insalubridade

                               If !Empty((cAliasA)->TFF_INSALU) .AND. (cAliasA)->TFF_INSALU != "1"             

                                              

                                               //Busca posição por tipo e grau

                                               nPos := aScan(aAdicionais, {|x|               x[ADICIONAIS_FILMAT] == (cAliasA)->RA_FILIAL .AND. ;

                                                                                                                                                                                            x[ADICIONAIS_MATRICULA] == (cAliasA)->RA_MAT.and. ;

                                                                                                                                                                                            x[ADICIONAIS_CODTEC] == (cAliasA)->AA1_CODTEC .and. ;

                                                                                                                                                                                            x[ADICIONAIS_ADICIONAL] == INSALUBRIDADE .AND. ;

                                                                                                                                                                                            x[ADICIONAIS_TIPO] == (cAliasA)->TFF_INSALU .AND.;

                                                                                                                                                                                            x[ADICIONAIS_GRAU] == (cAliasA)->TFF_GRAUIN})                                   

                                               If nPos == 0

                                                               aAdd(aAdicionais, Array(ADICIONAIS_PREV))

                                                               nPos := Len(aAdicionais)

                                                               aAdicionais[nPos][ADICIONAIS_FILMAT]            := (cAliasA)->RA_FILIAL

                                                               aAdicionais[nPos][ADICIONAIS_MATRICULA]                  := (cAliasA)->RA_MAT

                                                               aAdicionais[nPos][ADICIONAIS_CODTEC] := (cAliasA)->AA1_CODTEC

                                                               aAdicionais[nPos][ADICIONAIS_ADICIONAL]    := INSALUBRIDADE

                                                               aAdicionais[nPos][ADICIONAIS_TIPO]                  := (cAliasA)->TFF_INSALU

                                                               aAdicionais[nPos][ADICIONAIS_GRAU]                               := (cAliasA)->TFF_GRAUIN

                                                              aAdicionais[nPos][ADICIONAIS_HORAS]                             := (cAliasA)->HORAS

                              

                                               Else

                                                               aAdicionais[nPos][ADICIONAIS_HORAS] +=       (cAliasA)->HORAS

                                               EndIf

                                              

                               EndIf              

                               (cAliasA)->(DbSkip())

                End

               

                If Len(aAdicionais) = 0

                               cMsg := "Não há dados, verifique parâmetros"

                Else

                               If  File(cDirArq+cNomeArq)

                                               fErase(cDirArq+cNomeArq)

                               EndIf

                              

                               If !File(cDirArq+cNomeArq)

                                               nHandle := FCreate(cDirArq+cNomeArq)

                               EndIf

               

                               If nHandle <> -1


                                               cCab := "RA_FILIAL;RA_MAT;AA1_CODTEC;ADICIONAL;TIPO;GRAU;HORAS"+CRLF

                              

                                               fWrite(nHandle, cCab)

                              

                                               For nC := 1 to Len(aAdicionais)

                                                                cDetLinha := ""

                                                               For nY := 1 to Len(aAdicionais[nC])

                                                                              cDetLinha +=  Alltrim(IIF( ValType(aAdicionais[nC, nY])<> "D",cValToChar(aAdicionais[nC, nY])  , DtoS(aAdicionais[nC, nY])))+";"

                                                               Next nY

                                                                 cDetLinha := Substr(cDetLinha, 1, Len(cDetLinha)-1) + CRLF

                                                               fWrite(nHandle, cDetLinha)

                                               Next nC

                                               lRet := .T.

                                               fClose(nHandle)

                               Else

                                               cMsg := "Problemas na criação do arquivo"

                               EndIf

                EndIf


                (cAliasA)->(DbCloseArea())

Else

                cMsg := "Não enviados dados válidos referente à periculosidade"

EndIf


If !lRet

                Help(,,"At353EvRH",cMsg,,1,0)

EndIf


Return

04. DEMAIS INFORMAÇÕES

Não há.

05. ASSUNTOS RELACIONADOS