GLOBALS "cgprgb000.4gl" #DEFINE usuarios,clave VARCHAR(50), idx,scr_l SMALLINT DEFINE pcompanias RECORD LIKE companias.* MAIN DEFER INTERRUPT --CALL STARTLOG("CGPRMT021.TXT") CALL ARG_VAL(1) RETURNING usuarios CALL ARG_VAL(2) RETURNING clave CONNECT to "smarmotech" AS "MSSQL" USER usuarios USING clave SELECT a.* INTO pcompanias.* FROM companias a CALL cgprcs024() END MAIN FUNCTION cgprcs024() DEFINE gastos DYNAMIC ARRAY OF RECORD cuenta_no VARCHAR(10), descripcion VARCHAR(100), ac_mes_anterior , gastos_r_fecha , ac_fecha_ac , anio_anterior DECIMAL(12,2) END RECORD DEFINE fecha RECORD desde DATE, hasta DATE END RECORD, usuario_c VARCHAR(50), p_arr1 SMALLINT, ent_diario CHAR(14), ch_ano CHAR(4), cdepartamentos INT, fecha_ini_act,fecha_ini_ant,fecha_fin_ant DATE, fechaISO VARCHAR(10) DEFINE handler om.SaxDocumentHandler, -- return value from fgl_report_commitCurrentSettings() r_filename STRING, -- filename of Report Design Document including .4rp extension r_output STRING, -- output format option preview INTEGER -- TRUE/FALSE, to set preview option OPEN WINDOW w1 WITH FORM "cgfmcs024" CALL ui.Interface.LoadStyles("formularios") DIALOG ATTRIBUTE(UNBUFFERED) INPUT BY NAME fecha.desde, fecha.hasta,cdepartamentos ATTRIBUTE(WITHOUT defaults) BEFORE INPUT SELECT RTRIM(a.nom1_emp)||' '||a.apell1_emp INTO usuario_c FROM adtb00003 a,seg0001 b WHERE b.usuario = usuarios AND a.num_emp = b.num_emp LET fecha.desde = '' LET fecha.hasta = TODAY DISPLAY BY NAME usuario_c CALL deptoSupervisa(usuarios) BEFORE FIELD cdepartamentos IF fecha.desde IS NULL OR fecha.hasta IS NULL THEN CALL fgl_winmessage("INFO","DEBE ESPECIFICAR AMBAS FECHAS DE BUSQUEDA","INFO") NEXT FIELD desde END IF AFTER FIELD desde IF fecha.desde IS NULL THEN LET numero_msg = 16 --CALL msg(numero_msg) NEXT FIELD desde END IF SELECT MIN(a.fecha_inicio) INTO fecha_ini_act FROM prdtable a WHERE a.ano = YEAR(fecha.desde) AFTER FIELD hasta IF fecha.hasta IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD hasta END IF SELECT MIN(a.fecha_inicio) INTO fecha_ini_ant FROM prdtable a WHERE a.ano = YEAR(fecha.desde)-1 SELECT MAX(a.fecha_corte) INTO fecha_fin_ant FROM prdtable a WHERE a.ano = YEAR(fecha.desde)-1 AFTER FIELD cdepartamentos IF cdepartamentos IS NULL THEN CALL msg(16) NEXT FIELD cdepartamentos END IF ON CHANGE cdepartamentos IF cdepartamentos IS NULL THEN CALL msg(16) NEXT FIELD cdepartamentos END IF CALL gastos.clear() LET fechaISO = fecha.hasta USING "YYYYMMDD" DISPLAY "FECHA: ",fechaISO DISPLAY "fecha: ",fecha.hasta LET selec = "SELECT distinct a.cuenta_no,b.descripcion ", "FROM cgtb00001 b, cgtb00004 a, chequeo d,adtb00001 c ", "WHERE (a.cuenta_no = b.cuenta_no) AND (SUBSTRING(b.cuenta_no,1,1) = '7') AND ", "(a.departamento = d.departamento) AND a.status_t IS NULL AND ", "(a.departamento = c.departamento) AND ", "(a.fecha <= '",fechaISO clipped,"') AND ", "(a.departamento = ", cdepartamentos, ") AND ", " a.ref NOT LIKE 'ED.99%' AND a.cuenta_no <> '7600' and ", "b.status_t is null ", "ORDER BY a.cuenta_no, b.descripcion " LET idx = 1 DISPLAY selec PREPARE comando FROM selec DECLARE busco CURSOR FOR comando LET ch_ano = YEAR(fecha.hasta) using "&&&&" LET ch_ano = ch_ano[3,4] LET ent_diario = "ED.99-999/12",ch_ano CLIPPED #DISPLAY "ent_diario: ",ent_diario FOREACH busco INTO gastos[idx].cuenta_no, gastos[idx].descripcion #ACUMULADO AL MES ANTERIOR SELECT ISNULL(SUM(a.debito-a.credito),0) INTO gastos[idx].ac_mes_anterior FROM cgtb00004 a WHERE (a.ref =a.ref AND a.tipo<>3) AND (a.cuenta_no = gastos[idx].cuenta_no) AND (a.fecha BETWEEN fecha_ini_act AND fecha.desde ) AND (a.departamento = cdepartamentos) AND a.status_t is NULL --227-1322-2108 IF gastos[idx].ac_mes_anterior IS NULL THEN LET gastos[idx].ac_mes_anterior = 0 END IF #GASTOS RANGO DE FECHAS: SELECT ISNULL(SUM(a.debito-a.credito),0) INTO gastos[idx].gastos_r_fecha FROM cgtb00004 a WHERE (a.cuenta_no = gastos[idx].cuenta_no) AND (a.fecha BETWEEN fecha.desde AND fecha.hasta) AND (a.departamento = cdepartamentos) AND (a.ref =a.ref AND a.tipo <>3) AND a.status_t IS NULL IF gastos[idx].gastos_r_fecha IS NULL THEN LET gastos[idx].gastos_r_fecha = 0 END IF #ACUMULADO A LA FECHA LET gastos[idx].ac_fecha_ac = gastos[idx].ac_mes_anterior + gastos[idx].gastos_r_fecha #REALIZADO MES ANO ANTERIOR: SELECT ISNULL(SUM(a.debito-a.credito),0) INTO gastos[idx].anio_anterior FROM cgtb00004 a WHERE (a.ref =a.ref AND a.tipo<>3) AND (a.cuenta_no = gastos[idx].cuenta_no) AND (a.fecha BETWEEN fecha_ini_ant AND fecha_fin_ant) AND (a.departamento = cdepartamentos) AND a.status_t is NULL IF gastos[idx].anio_anterior = 0 AND gastos[idx].gastos_r_fecha = 0 AND gastos[idx].ac_mes_anterior =0 AND gastos[idx].ac_fecha_ac = 0 THEN CALL gastos.deleteElement(idx) CONTINUE FOREACH END IF LET idx = idx + 1 END FOREACH END INPUT { LET ch_ano = YEAR(fe) using "&&&&" LET ch_ano = ch_ano[3,4] LET ent_diario = "ED.99-999/12",ch_ano CLIPPED} INPUT ARRAY gastos FROM recordd.* BEFORE INPUT CALL DIALOG.setActionActive("insert", FALSE) CALL DIALOG.setActionActive("append", FALSE) CALL DIALOG.setActionActive("delete", FALSE) BEFORE ROW LET p_arr1 = arr_curr() LET scr_l = scr_line() ON ACTION reporte CALL generaReporte(gastos,fecha.*) ON ACTION acumesant CALL detalleGastos(ent_diario,gastos[p_arr1].cuenta_no, cdepartamentos, 'acumesant',fecha.*) ON ACTION gasranfech CALL detalleGastos(ent_diario,gastos[p_arr1].cuenta_no, cdepartamentos, 'gasranfech',fecha.*) --ON ACTION acufechaant -- CALL detalleGastos(gastosDetalle,ent_diario,gastos[p_arr1].cuenta_no, -- cdepartamentos, 'acufechaant') ON ACTION anioant CALL detalleGastos("ED.99-999/12*",gastos[p_arr1].cuenta_no, cdepartamentos, 'anioant',fecha.*) END INPUT ON ACTION CANCEL EXIT DIALOG CLOSE WINDOW w1 END DIALOG CLOSE WINDOW w1 END FUNCTION FUNCTION generaReporte(gastos, fecha) DEFINE fecha RECORD desde DATE, hasta DATE END RECORD DEFINE gastos DYNAMIC ARRAY OF RECORD cuenta_no VARCHAR(10), descripcion VARCHAR(100), ac_mes_anterior , gastos_r_fecha , ac_fecha_ac , anio_anterior DECIMAL(12,2) END RECORD, idz INT LET r_filename ="cgprcs024.4rp" FOR idz = 1 TO gastos.getLength() #DISPLAY gastos[idz].ac_fecha_ac,gastos[idz].ac_mes_anterior,gastos[idz].anio_anterior,gastos[idz].gastos_r_fecha, gastos[idz].descripcion IF idz = 1 THEN IF fgl_report_loadCurrentSettings(r_filename) THEN -- load the .4rp file --LET r_output='SVG' LET preview=1 CALL seleccionarsalida() RETURNING r_output CALL fgl_report_selectDevice(r_output) -- changing default CALL fgl_report_selectPreview(preview) -- changing default LET handler = fgl_report_commitCurrentSettings() -- commit changes START REPORT gastos_gral TO XML HANDLER HANDLER END IF END IF OUTPUT TO REPORT gastos_gral(gastos[idz].*,fecha.*) END FOR IF idx > 1 THEN FINISH REPORT gastos_gral ELSE CALL fgl_winmessage("INFO","NO EXISTEN REGISTROS","INFO") END IF END FUNCTION REPORT gastos_gral(x,y) DEFINE y RECORD desde DATE, hasta DATE END RECORD DEFINE x RECORD cuenta_no VARCHAR(10), descripcion VARCHAR(50), ac_mes_anterior DECIMAL(12,5), gastos_r_fecha DECIMAL(12,5), ac_fecha_ac DECIMAL(12,5), anio_anterior DECIMAL(12,5) END RECORD, totalAc_mes_anterior DECIMAL(12,2), totalGastos_r_fecha DECIMAL(12,2), totalAc_fecha_ac DECIMAL(12,2), totaAnio_anterior DECIMAL(12,2), fecha_reporte char(30), fechas VARCHAR (35) FORMAT FIRST PAGE HEADER LET totalAc_mes_anterior = 0 LET totalGastos_r_fecha = 0 LET totalAc_fecha_ac = 0 LET totaAnio_anterior = 0 LET fecha_reporte = CURRENT LET fechas = "Desde ",y.desde USING "dd/mm/yyyy"," Hasta ",y.hasta USING "dd/mm/yyyy" DISPLAY pcompanias.nombre PRINTX pcompanias.nombre, fechas, fecha_reporte ON EVERY ROW LET totalAc_mes_anterior = totalAc_mes_anterior + x.ac_mes_anterior LET totalGastos_r_fecha = totalGastos_r_fecha + x.gastos_r_fecha LET totalAc_fecha_ac = totalAc_fecha_ac + x.ac_fecha_ac LET totaAnio_anterior = totaAnio_anterior + x.anio_anterior PRINTX x.cuenta_no, x.descripcion, x.ac_mes_anterior, x.gastos_r_fecha, x.ac_fecha_ac, x.anio_anterior ON LAST ROW LET totalAc_mes_anterior = SUM(x.ac_mes_anterior) LET totalGastos_r_fecha = SUM(x.gastos_r_fecha) LET totalAc_fecha_ac = SUM(x.ac_fecha_ac) LET totaAnio_anterior = SUM(x.anio_anterior) PRINTX totalAc_mes_anterior,totalGastos_r_fecha,totalAc_fecha_ac, totaAnio_anterior END REPORT