Definir Alfa IMPAReg; /*Indica o código do registro que está sendo executado pela gera neste momento*/ Definir Alfa IMPAPRMSQL; /*Parâmetro adicional do registro. Utilizado para identificar o processo em que o SQL será utilizado. */ Definir Alfa IMPAEveReg; /*Indica se está sendo realizada a alteração do SQL ou REGISTRO*/ Definir Alfa IMPACMDSQL; /*Recebe o SQL alterado para a composição do registro*/ /**************************************************************************************************/ /* BUSCA A CONTA CONTA CONTÁBIL 2 DO CADASTRO DO DEPÓSITO PARA O REGISTRO H010 */ /**************************************************************************************************/ Se ((IMPAReg = "H010") e (IMPAEveReg = "SQL") e (IMPAPRMSQL = "E210SFE")) Inicio IMPACMDSQL = "SELECT "+ "E210SFE.CODPRO, E075PRO.UNIMED, E075PRO.CODCLF, "+ "E210SFE.QTDPRP, E210SFE.VLRPRP, E205DEP.CtaRcr AS CTARED, "+ "E210SFE.CODDER, E210SFE.QTDELA, E210SFE.VLRELA "+ "FROM "+ "E210SFE, E075PRO, E205DEP "+ "WHERE "+ "E210SFE.CODEMP = E075PRO.CODEMP AND "+ "E210SFE.CODPRO = E075PRO.CODPRO AND "+ "E205DEP.CODEMP = E210SFE.CODEMP AND "+ "E205DEP.CODDEP = E210SFE.CODDEP AND "+ "E210SFE.CODEMP = {CODEMP} AND "+ "E210SFE.CODFIL = {CODFIL} AND "+ "(E210SFE.MESANO >= {MESINI} AND "+ "E210SFE.MESANO <= {MESFIM})"; Fim; /**************************************************************************************************/ /* GERA O REGISTRO G126 - REGISTRO NÃO ATENDIDO POR PADRÃO PELO ERP SENIOR */ /**************************************************************************************************/ Se ((IMPAReg = "G126") e (IMPAEveReg = "SQL")) Inicio IMPACMDSQL = "SELECT "+ "USU_DATINI AS DATINI, USU_DATFIM AS DATFIM, USU_NUMPAR AS NUMPAR, USU_VLRPAR AS VLRPAR, "+ "USU_VLRTRI AS VLRTRI, USU_VLRTOT AS VLRTOT, USU_PERSAI AS PERSAI, USU_VLRAPR AS VLRAPR "+ "FROM "+ "USU_T700G126 "+ "WHERE "+ "USU_CODEMP = {CODEMP} AND "+ "USU_CODFIL = {CODFIL} AND "+ "USU_CODBEM = {CODBEM} AND "+ "USU_DATMOV = {DATMOV}"; Fim; /**************************************************************************************************/ /* BUSCA A DESCRIÇÃO DA TRANSAÇÃO AO INVÉS DOS DETALHES DA TRANSAÇÃO, NO REGISTRO 0400 */ /**************************************************************************************************/ Definir Alfa IMPACOD_NAT; Definir Alfa IMPADESCR_NAT; Definir Numero nCodEmp; nCodEmp = CodEmp; @Recebe Empresa logada@ Definir Cursor CurE001TNS; Se ((IMPAEVEREG = "REGISTRO") e (IMPAREG = "0400")) Inicio CurE001TNS.SQL "SELECT DESTNS \ FROM E001TNS \ WHERE CODTNS =:IMPACOD_NAT \ AND CODEMP =:nCodEmp"; CurE001TNS.AbrirCursor(); Se (CurE001TNS.Achou) Inicio IMPADESCR_NAT = CurE001TNS.DESTNS; Fim; CurE001TNS.FecharCursor(); Fim; /**************************************************************************************************/ /* TRANSFERIR O VALOR DO CAMPO VL_OUTROS DO REGISTRO C197 PARA O CAMPO VL_ICMS */ /**************************************************************************************************/ Definir Numero IMPNVL_ICMS; Definir Numero IMPNVL_OUTROS; Definir Alfa IMPACOD_AJ; Se ((IMPAEVEREG = "REGISTRO") e (IMPAREG = "C197") e (IMPACOD_AJ = "SC40000003") ) Inicio IMPNVL_ICMS = IMPNVL_OUTROS; IMPNVL_OUTROS = 0; Fim; /**************************************************************************************************/ /* REGRA DO CONSULTOR DIMITRI PARA TRATAMENTO DO REGISTRO 0205 DO SPED FISCAL */ /**************************************************************************************************/ Definir Alfa IMPACod_Item; Definir Alfa IMPADescr_Item; Definir Alfa IMPACod_Ant_Item; Definir Alfa IMPADescr_Ant_Item; Definir Data IMPDDt_Ini; Definir Data IMPDDt_Fim; Definir Data R0000_IMPDDT_ini; Definir Data R0000_IMPDDT_fin; Definir Data dDatIni; Definir Data dDatFim; Definir Alfa aSqlE; Definir Alfa aSqlS; Definir Cursor Cur_E075Der; Definir Numero IMPNCodEmp; se ((IMPAReg = "0205") e (IMPAPRMSQL = "HPR")) { se (IMPAEveReg = "SQL") { intparaalfa(IMPNCodFil,aSqlE); aSqlS = aSqlE; aSqlE = " and E660INC.CodFil = " + aSqlE + " "; aSqlS = " and E660INV.CodFil = " + aSqlS + " "; IMPACmdSql = "SELECT E075VDR.DATFIS AS DATFIS, MAX(E075VDR.HORATU) AS HORATU " + "FROM E075VDR " + "WHERE E075VDR.CODEMP = {CODEMP} " + "AND E075VDR.CODPRO = {CODPRO} " + "AND E075VDR.CODDER = {CODDER} " + "AND E075VDR.DATFIS > {DATINI} " + "AND E075VDR.DATFIS < {DATFIM} " + "AND E075VDR.DATFIS > E075VDR.DATGER " + "group by E075VDR.DATFIS "; IMPACmdSql = IMPACmdSql + "Union " + "Select E075VDR.DATFIS AS DATFIS, MAX(E075VDR.HORATU) as HORATU " + "From E075VDR " + "WHERE E075VDR.CODEMP = {CODEMP} " + "AND E075VDR.CODPRO = {CODPRO} " + "AND E075VDR.CODDER = {CODDER} " + "AND E075VDR.USU_GERSPD = 'S' " + "AND E075VDR.DATFIS <= {DATINI} " + "AND NOT EXISTS (Select 1 " + "from E660Inc, E660Nfc " + "where E660INC.CodEmp=E075VDR.CodEmp " + aSqlE + "and E660INC.CodPro=E075VDR.CodPro " + "and E660INC.CodDer=E075VDR.CodDer " + "and E660NFC.DatEnt< {DATINI} " + "and E660NFC.DatEnt> to_date('31/08/2014','dd/mm/yyyy') " + "and E660NFC.SitNfc='2' " + "and E660NFC.CodEmp=E660INC.CodEmp " + "and E660NFC.CodFil=E660INC.CodFil " + "and E660NFC.CodFor=E660INC.CodFor " + "and E660NFC.NumNfi=E660INC.NumNfi " + "and E660NFC.NumNff=E660INC.NumNff " + "and E660NFC.CodSnf=E660INC.CodSnf " + "and E660NFC.CodTns=E660INC.CodTns) " + "AND NOT EXISTS (Select 1 " + "from E660Inv, E660Nfv " + "where E660INV.CodEmp=E075VDR.CodEmp " + aSqlS + "and E660INV.CodPro=E075VDR.CodPro " + "and E660INV.CodDer=E075VDR.CodDer " + "and E660NFV.DatEmi< {DATINI} " + "and E660NFV.DatEmi> to_date('31/08/2014','dd/mm/yyyy') " + "and E660NFV.SiTNfv='2' " + "and E660NFV.CodEmp=E660INV.CodEmp " + "and E660NFV.CodFil=E660INV.CodFil " + "and E660NFV.CodCli=E660INV.CodCli " + "and E660NFV.NumNfi=E660INV.NumNfi " + "and E660NFV.NumNff=E660INV.NumNff " + "and E660NFV.CodSnf=E660INV.CodSnf " + "and E660NFV.CodTns=E660INV.CodTns) " + "group by E075VDR.DATFIS "; IMPACmdSql = IMPACmdSql + "ORDER BY DATFIS, HORATU"; } }