xBase source code in PHC

Embed Size (px)

DESCRIPTION

xBase language used in ERP PHC.

Citation preview

**************************************************************************************************************** ** DESCRIO DA ROTINA: EVENTO PARA PROCESSAR RECIBOS QUE IRIAM TER VALOR NEGATIVO OU POSITIVO MAS QUE TM ** FALTAS NA TOTALIDADE DO PERIODO PROCESSADO ** AUTOR: LUIS COELHO ** DATA: 2014/03/13 ** ** PROJECTO (S/N)? N ** QUEM PEDIU? DR. VITOR AGUIAR ** ***************************************************************************************************************** ** PRESSUPOSTOS: ** ** ***************************************************************************************************************** OBSERVAES: VALIDAR O CDIGO DE PROCESSAMENTO DE FALTAS DO FUNCIONRIO (U_PROCFALTAS) ** ** ****************************************************************************************************************xTemFaltas = .f.select prTEXT TO m.msql TEXTMERGE NOSHOWselect hsemana, hdia, u_codprocf, diai, mesi, diaf, mesf, no from pe (nolock) inner join u_procfaltas as pf (nolock) on (pe.u_codprocf = pf.codigo)where pe.no=> and pf.anoproc = > and pf.mesproc = >ENDTEXTu_sqlexec(m.msql, 'crpe')xValorAbono = 0********************************************** ** CRIAMOS O CURSOR DE FALTAS PARA DEPOIS AS ** COMPARARMOS COM O PERIODO TOTAL DE FALTAS ** **********************************************create cursor crFaltas (qtt n(10,2), valorunit n(12,2), valortotal n(12,2))**************************************************************************** ** PERCORREMOS AS LINHAS DE REMUNERAES PARA VALIDARMOS SE EXISTEM FALTAS ** ****************************************************************************select prregoto topscanxCm = PRRE.CRu_sqlexec("select cm, cmdesc, u_ofaltas, u_bmedica, u_ferias, codbase from cm6 (nolock) where cm6.cm = " + astr(prre.cr), 'crcm6')select crcm6****************************************************************** ** VAMOS CARREGAR AS FALTAS NUM CURSOR E OS ABONOS NUMA VARIAVEL ** ******************************************************************if crcm6.u_ofaltas = .t. or crcm6.u_bmedica = .t.select crFaltasappend blankreplace crFaltas.qtt with prre.rqttreplace crFaltas.valorunit with prre.ervureplace crFaltas.valortotal with prre.erexTemFaltas = .t.elseif crcm6.codbase = .t.xValorAbono = xValorAbono + prre.ereendifendifselect prreendscan********************************************* ** SE NO TEM UMA NICA FALTA SAI DA ROTINA ** *********************************************if xTemFaltas = .f.return .t.endif************************************************************************* ** VAMOS VALIDAR OS DIAS E HORAS TEIS DO INTERVALO DO CDIGO DE FALTAS ** *************************************************************************select crpeif crpe.mesi = 12 thenxDataInicial = ctod(right('00' + astr(crpe.diai), 2) + '.' + right('00' + astr(crpe.mesi), 2) + '.' + right('0000' + astr(year(pr.data)-1), 4))elsexDataInicial = ctod(right('00' + astr(crpe.diai), 2) + '.' + right('00' + astr(crpe.mesi), 2) + '.' + right('0000' + astr(year(pr.data)), 4))endifxDataFinal = ctod(right('00' + astr(crpe.diaf), 2) + '.' + right('00' + astr(crpe.mesf), 2) + '.' + right('0000' + astr(year(pr.data)), 4))select prxDiasUteis = u_diasuteis(xDataInicial, xDataFinal, pr.no)select crpexHorasUteis = xDiasUteis * crpe.hdiaxHorasFalta = 0***************************************************************************************** ** VALIDAR SE AS HORAS TEIS DO INTERVALO DO CDIGO DE FALTAS SO IGUAIS AOS DAS FALTAS ** *****************************************************************************************select crFaltasgoto topscanxHorasFalta = xHorasFalta + crFaltas.qttendscanxRestante = round(xValorABono, 2)if xHorasFalta == xHorasUteis thenxValorUnit = -(xValorAbono / xHorasFalta)select prregoto topscanxCm = PRRE.CRu_sqlexec("select cm, cmdesc, u_ofaltas, u_bmedica, u_ferias from cm6 (nolock) where cm6.cm = " + astr(prre.cr), 'crcm6')select crcm6if crcm6.u_ofaltas = .t. or crcm6.u_bmedica = .t.if xRestante >= abs(prre.rqtt * xValorUnit)replace prre.ervu with round(xValorUnit, 2)replace prre.ere with round(xValorUnit * prre.rqtt, 2)xRestante = xRestante + round((xValorUnit * prre.rqtt), 2)elsereplace prre.ervu with - round((xRestante / prre.rqtt), 2)replace prre.ere with - xRestantexRestante = 0endifendifselect prreendscan****************************************************************************** ** SE AINDA EXISTIR VALOR RESTANTE, VAMOS ATRIBUIR PRIMEIRA LINHA DE FALTA ** ******************************************************************************if xRestante > 0 thenselect prregoto topscanxCm = PRRE.CRu_sqlexec("select cm, cmdesc, u_ofaltas, u_bmedica, u_ferias from cm6 (nolock) where cm6.cm = " + astr(prre.cr), 'crcm6')select crcm6if crcm6.u_ofaltas = .t. or crcm6.u_bmedica = .t.replace prre.ere with prre.ere - xRestantereplace prre.ervu with round(prre.ere / prre.rqtt, 2)xRestante = 0exitendifselect prreendscanendifendif**************************************** ** CALCULAMOS O VALOR TOTAL DAS LINHAS ** ****************************************xValor = 0select prregoto topscanxValor = xValor + prre.ereendscan*************************************** ** SE NO TIVERMOS VALORES DE ABONOS, ** LIMPAMOS AS LINHAS DE DESCONTOS ** ***************************************if xValor = 0 thenselect prdegoto topscandeleteendscanendif*********************************************************************** ** SE NO HOUVER NENHUM ABONO, ENTO LIMPAMOS OS VALORES DO CABEALHO ** DO RECIBO E NO RECALCULAMOS PELAS FUNES DO PHC ** ***********************************************************************if xValor = 0 thenselect PRreplace PR.EFCTVALOR with 0replace PR.EFGCTVALOR with 0replace PR.EFGCTVALREEMB with 0replace PR.EHETT with 0replace PR.ELIQUIDO with 0replace PR.ESSEVALOR with 0replace PR.ESSHEXTRA with 0replace PR.ESUBSIDIO with 0replace PR.ETTDESC with 0replace PR.ETTNSUJ with 0replace PR.ETTSUJ with 0replace PR.ETTSUJCX with 0replace PR.EVALORJAEMTB with 0replace PR.EVALOROL with 0replace PR.FCTVALOR with 0replace PR.FGCTVALOR with 0replace PR.FGCTVALREEMB with 0replace PR.HETT with 0replace PR.LIQUIDO with 0replace PR.SSEVALOR with 0replace PR.SSHEXTRA with 0replace PR.SUBSIDIO with 0replace PR.TTDESC with 0replace PR.TTNSUJ with 0replace PR.TTSUJ with 0replace PR.TTSUJCX with 0replace PR.VALORJAEMTB with 0replace PR.VALOROL with 0return .t.else******************************** ** CLCULO DE TOTAIS DO RECIBO ** ********************************m.mxsujirs=0m.mvirs=0Declare a_diff(1),a_mesano(1),a_dtsuj(1)a_dtsuj=0a_mesano=0a_diff=0Do prantirs With pr.no,pr.data,m.eur_defDo prprocDo prprocfendif***************************************************************** ** VALIDAMOS AGORA SE O TOTAL DE ABONOS ESTARIA SUJEITO ** A IRS E SS CASO ESTIVESSEM AS FALTAS NO MS DO PROCESSAMENTO ** *****************************************************************if used('crprre') thenfecha('crprre')endifduplicursor('prre', 'crprre')xTemDeZerar = .f.************************************************ ** VAMOS VALIDAR A DATA REFERNCIA DO ORD.BASE ** ************************************************select prregoto toplocate for prre.cr = 1if found() thenxData = prre.dtrefselect prregoto topscanreplace prre.dtref with xDataendscan******************************** ** CLCULO DE TOTAIS DO RECIBO ** ********************************m.mxsujirs=0m.mvirs=0Declare a_diff(1),a_mesano(1),a_dtsuj(1)a_dtsuj=0a_mesano=0a_diff=0Do prantirs With pr.no,pr.data,m.eur_defDo prprocDo prprocf******************************************************************************** ** SE TODOS OS ABONOS ESTIVEREM MESMA DATA E SE NO EXISTIR NENHUM DESCONTO, ** ENTO NO DEVERIA DESCONTAR NADA MESMO COM OUTRAS DATAS ** ********************************************************************************select prdeif reccount('prde') = 0 thenxTemdeZerar = .t.endifendif************************************************* ** REPOMOS AGORA AS DATAS REFERNCIA DAS LINHAS ** *************************************************select prregoto topscanselect crprrelocate for crprre.prrestamp = prre.prrestampif found() thenreplace prre.dtref with crprre.dtrefendifselect prreendscan**************************************************** ** SE TEM DE ZERAR, ENTO APAGA TODOS OS DESCONTOS ** ****************************************************if xTemDeZerar thenselect prdescandeleteendscanselect PRreplace PR.EFCTVALOR with 0replace PR.EFGCTVALOR with 0replace PR.EFGCTVALREEMB with 0replace PR.EHETT with 0replace PR.ELIQUIDO with 0replace PR.ESSEVALOR with 0replace PR.ESSHEXTRA with 0replace PR.ESUBSIDIO with 0replace PR.ETTDESC with 0replace PR.ETTNSUJ with 0replace PR.ETTSUJ with 0replace PR.ETTSUJCX with 0replace PR.EVALORJAEMTB with 0replace PR.EVALOROL with 0replace PR.FCTVALOR with 0replace PR.FGCTVALOR with 0replace PR.FGCTVALREEMB with 0replace PR.HETT with 0replace PR.LIQUIDO with 0replace PR.SSEVALOR with 0replace PR.SSHEXTRA with 0replace PR.SUBSIDIO with 0replace PR.TTDESC with 0replace PR.TTNSUJ with 0replace PR.TTSUJ with 0replace PR.TTSUJCX with 0replace PR.VALORJAEMTB with 0replace PR.VALOROL with 0endif