{------------------------------------------------------------------------------ PROGRAMA : edprrp118 OBJETIVO : PROGRAMADOR : VALENTIN RODRIGUEZ FECHA REALIZACION : MARZO, 13 2020 ---------------------------------------------------------------------------------} GLOBALS "cgprgb000.4gl" DEFINE p_fecha DATE DEFINE afecta CHAR(1) 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 criterio STRING MAIN DEFER INTERRUPT CALL arg_val(1) RETURNING usuarios CALL arg_val(2) RETURNING clave CALL arg_val(3) RETURNING impresor CONNECT TO "smarmotech" USER usuarios USING clave SELECT * INTO p_compania.* FROM companias CALL irprrp009() END MAIN FUNCTION irprrp009() DEFINE select_ac CHAR(1000) DEFINE c_ano CHAR(4) DEFINE entra, nombre_mes CHAR(25) DEFINE entra1 CHAR(5) DEFINE detalle CHAR(100) DEFINE numero_ent CHAR(2) DEFINE ano_act CHAR(4) DEFINE idz INT DEFINE acumulado RECORD cod_n LIKE irtb00002.cod_n, cod_grupo LIKE irtb00002.cod_grupo, cod_tipo LIKE irtb00002.cod_tipo, cod_sec LIKE irtb00002.cod_sec, descrip_esp LIKE irtb00002.descrip_esp, unidad_med LIKE irtb00002.unidad_med, cod_mov LIKE irtb00006.cod_mov, descrip_mov LIKE intb00005.descrip_mov, departamento SMALLINT, nombre CHAR(30), consumo DECIMAL(12, 2), cuenta CHAR(10), cuenta_inv CHAR(10), gasto_ind LIKE irtb00013.costo_st, consumo_cuenta DECIMAL(12, 2), nombre_cuenta VARCHAR(50) END RECORD DEFINE acumulado_arr DYNAMIC ARRAY OF RECORD cod_mov LIKE irtb00006.cod_mov, descrip_mov LIKE intb00005.descrip_mov, departamento SMALLINT, nombre CHAR(30), consumo DECIMAL(12, 2), cuenta CHAR(10), gasto_ind LIKE irtb00013.costo_st, descripcion CHAR(50), consumo_cuenta DECIMAL(12, 2), cuenta_inv CHAR(10) END RECORD OPEN FORM edfmrp118 FROM "edfmrp118" DISPLAY FORM edfmrp118 INPUT BY NAME acumulado.cod_mov, datos_cons.fech_in, datos_cons.fech_fi, entra, detalle, afecta BEFORE INPUT CALL ircmovimientos() BEFORE FIELD fech_in SELECT MAX(a.fecha) INTO p_fecha FROM cgtb00004 a WHERE a.ref[1, 9] = entra1 LET datos_cons.fech_in = p_fecha + 1 DISPLAY BY NAME datos_cons.fech_in BEFORE FIELD detalle SELECT descrip_mov INTO acumulado.descrip_mov FROM irtb00005 WHERE cod_mov = acumulado.cod_mov SELECT a.descrip INTO nombre_mes FROM mestable a WHERE a.mes = MONTH(datos_cons.fech_fi) LET detalle = 'PARA REGISTRAR ', acumulado.descrip_mov CLIPPED, ' DEL MES DE ', nombre_mes CLIPPED, ' DEL ', YEAR(datos_cons.fech_fi) DISPLAY BY NAME detalle AFTER FIELD fech_in IF datos_cons.fech_in IS NULL THEN ERROR "(16) CAMPO EN BLANCO" NEXT FIELD fech_in END IF IF datos_cons.fech_in <= p_fecha THEN ERROR "(179) EXISTE ENTRADA DE DIARIO CON ESA FECHA" NEXT FIELD fech_in END IF AFTER FIELD fech_fi IF datos_cons.fech_fi IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fech_final END IF LET ano_act = YEAR(datos_cons.fech_fi) IF datos_cons.fech_fi > TODAY THEN CALL msg(57) NEXT FIELD fech_in END IF IF datos_cons.fech_in > datos_cons.fech_fi THEN CALL msg(57) NEXT FIELD fech_in END IF LET numero_ent = 25 LET ano_act = YEAR(datos_cons.fech_fi) IF datos_cons.fech_fi > TODAY THEN CALL msg(57) NEXT FIELD fech_fi END IF IF datos_cons.fech_in > datos_cons.fech_fi THEN CALL msg(57) NEXT FIELD fech_in END IF CALL prd(datos_cons.fech_fi, usuarios) RETURNING bandera IF bandera = 1 THEN LET bandera = 0 NEXT FIELD fech_fi END IF CALL controlNumericoED( numero_ent, datos_cons.fech_fi, NULL) RETURNING entrada DISPLAY BY NAME entrada AFTER INPUT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) LET int_flag = FALSE RETURN END IF IF datos_cons.fech_fi > TODAY THEN CALL msg(57) NEXT FIELD fech_in END IF IF datos_cons.fech_in > datos_cons.fech_fi THEN CALL msg(57) NEXT FIELD fech_in END IF -- Solo si el usuario va a AFECTAR el mayor (afecta = "S") se valida -- que el periodo no este cerrado. Se usa fech_fi porque es la fecha -- con la que se registra el asiento en cgtb00004. IF afecta = "S" THEN CALL prd(datos_cons.fech_fi, usuarios) RETURNING bandera IF bandera = 1 THEN LET bandera = 0 NEXT FIELD fech_fi END IF END IF LET select_ac = "SELECT b.cod_n,b.cod_grupo,b.cod_tipo,b.cod_sec,a.descrip_esp, ", "a.unidad_med,b.cod_mov,c.descrip_mov,b.sec_a,d.nom_dpto,SUM(b.cantidad_2), a.cuenta,e.cuenta_no ", "FROM irtb00002 AS a INNER JOIN ", "irtb00006 AS b ON a.cod_n = b.cod_n AND a.cod_grupo = b.cod_grupo AND a.cod_tipo = b.cod_tipo AND ", "b.cod_mov = ", acumulado.cod_mov, " and ", "a.cod_sec = b.cod_sec and b.status_t IS NULL INNER JOIN ", " iptb00022 e ON e.cod_cia = a.cod_n INNER JOIN ", "irtb00005 AS c ON b.cod_mov = c.cod_mov LEFT OUTER JOIN ", "adtb00001 AS d ON b.sec_a = d.departamento ", "WHERE ", " b.fecha BETWEEN ? AND ? AND b.status_t IS NULL ", " GROUP BY b.cod_n,b.cod_grupo,b.cod_tipo,b.cod_sec,a.descrip_esp,a.unidad_med,b.cod_mov,c.descrip_mov,b.sec_a,d.nom_dpto, a.cuenta,e.cuenta_no ", " ORDER BY b.cod_mov,b.sec_a,b.cod_n,b.cod_grupo,b.cod_tipo,b.cod_sec" DISPLAY "<< Estoy Buscando Acumulado Del Periodo Dado >>" AT 17, 14 ATTRIBUTE(REVERSE, BOLD) PREPARE busca_ant FROM select_ac DECLARE actual SCROLL CURSOR FOR busca_ant OPEN actual USING datos_cons.fech_in, datos_cons.fech_fi LET r_filename = "edprrp118.4rp" LET idx = 1 LET idz = 1 FOREACH actual INTO acumulado.* IF idx = 1 THEN IF fgl_report_loadCurrentSettings(r_filename) THEN LET preview = 1 CALL seleccionarsalida() RETURNING r_output -- load the .4rp file CALL fgl_report_selectDevice( r_output) -- changing default CALL fgl_report_selectPreview( preview) -- changing default LET handler = fgl_report_commitCurrentSettings() -- commit changes END IF LET idx = 2 START REPORT opera TO XML HANDLER HANDLER END IF LET c_ano = YEAR(datos_cons.fech_fi) LET acumulado.gasto_ind = 0 SELECT a.costo_st INTO acumulado.gasto_ind FROM irtb00013 a WHERE (a.cod_n = acumulado.cod_n AND a.cod_grupo = acumulado.cod_grupo AND a.cod_tipo = acumulado.cod_tipo AND a.cod_sec = acumulado.cod_sec) AND # (a.mes_ini <= p_mes) and a.mes_fin >= p_mes and a.ano = c_ano and a.ano = c_ano AND a.status_t IS NULL IF acumulado.gasto_ind IS NULL THEN LET acumulado.gasto_ind = 0 END IF SELECT ISNULL(descripcion, 'NO EXISTE CUENTA') INTO acumulado_arr[idz].descripcion FROM cgtb00001 WHERE cgtb00001.cuenta_no = acumulado.cuenta IF acumulado.consumo IS NULL THEN LET acumulado.consumo = 0 END IF IF acumulado.nombre IS NULL THEN LET acumulado.nombre = 'NO ESPECIFICADO' END IF LET acumulado.nombre_cuenta = acumulado_arr[idz].descripcion LET acumulado.consumo_cuenta = acumulado.consumo * acumulado.gasto_ind LET acumulado_arr[idz].cod_mov = acumulado.cod_mov LET acumulado_arr[idz].descrip_mov = acumulado.descrip_mov LET acumulado_arr[idz].departamento = acumulado.departamento LET acumulado_arr[idz].nombre = acumulado.nombre LET acumulado_arr[idz].consumo = acumulado.consumo LET acumulado_arr[idz].cuenta = acumulado.cuenta LET acumulado_arr[idz].gasto_ind = acumulado.gasto_ind LET acumulado_arr[idz].consumo_cuenta = acumulado.consumo_cuenta LET acumulado_arr[idz].cuenta_inv = acumulado.cuenta_inv LET idz = idz + 1 OUTPUT TO REPORT opera(acumulado.*) END FOREACH IF idx > 1 THEN FINISH REPORT opera -- Solo se consume/incrementa la secuencia en cgtb00011 cuando el -- usuario decide AFECTAR el mayor (afecta = "S"). Si elige "N", se -- pasa NULL para obtener el numero en modo consulta, sin UPDATE. -- Nota: el combo guarda "S"/"N" (name), no "SI"/"NO" (text). IF afecta = "S" THEN CALL controlNumericoED( numero_ent, datos_cons.fech_fi, usuarios) RETURNING entra ELSE CALL controlNumericoED( numero_ent, datos_cons.fech_fi, NULL) RETURNING entra END IF DISPLAY "entrada: ", entra DISPLAY BY NAME entra CALL edprrp118( datos_cons.fech_in, datos_cons.fech_fi, detalle, entra, afecta, p_compania.nombre, acumulado_arr, usuarios) ELSE CALL fgl_winmessage( "INFO", "NO HAY REGISTROS EN ESTE RANGO DE FECHA Y CON LOS PARAMETROS INDICADOS", "INFO") END IF END INPUT END FUNCTION REPORT opera(x) DEFINE x RECORD cod_n LIKE irtb00002.cod_n, cod_grupo LIKE irtb00002.cod_grupo, cod_tipo LIKE irtb00002.cod_tipo, cod_sec LIKE irtb00002.cod_sec, descrip_esp LIKE irtb00002.descrip_esp, unidad_med LIKE irtb00002.unidad_med, cod_mov LIKE irtb00006.cod_mov, descrip_mov LIKE intb00005.descrip_mov, departamento SMALLINT, nombre CHAR(30), consumo DECIMAL(12, 2), cuenta CHAR(10), cuenta_inv CHAR(10), gasto_ind LIKE irtb00013.costo_st, consumo_cuenta DECIMAL(12, 2), nombre_cuenta VARCHAR(50) END RECORD DEFINE rango_fecha CHAR(30) DEFINE movimiento CHAR(50) DEFINE codigo_producto CHAR(100) DEFINE hora CHAR(5), actual VARCHAR(20) DEFINE total_material, total_movimiento, total_cuenta, total_departamento, total_general DECIMAL(12, 2) FORMAT PAGE HEADER LET hora = TIME LET actual = TODAY USING "dd/mm/yy" LET rango_fecha = datos_cons.fech_in, "--", datos_cons.fech_fi BEFORE GROUP OF x.cod_mov LET movimiento = x.cod_mov, "--", x.descrip_mov LET total_movimiento = 0 PRINTX movimiento BEFORE GROUP OF x.departamento LET total_departamento = 0 PRINTX x.nombre, x.departamento BEFORE GROUP OF x.cuenta LET total_cuenta = 0 PRINTX x.cuenta, x.nombre_cuenta ON EVERY ROW LET codigo_producto = '(', x.cod_n, '-', x.cod_grupo, '-', x.cod_tipo, '-', x.cod_sec, ')', x.descrip_esp LET total_movimiento = total_movimiento + x.consumo_cuenta LET total_departamento = total_departamento + x.consumo_cuenta LET total_cuenta = total_cuenta + x.consumo_cuenta LET total_general = total_general + x.consumo_cuenta PRINTX codigo_producto, x.unidad_med, x.consumo, x.gasto_ind, rango_fecha, p_compania.nombre, x.consumo_cuenta, hora, actual, x.cuenta AFTER GROUP OF x.departamento PRINTX x.nombre, total_departamento AFTER GROUP OF x.cod_mov PRINTX total_movimiento AFTER GROUP OF x.cuenta PRINTX total_cuenta ON LAST ROW LET total_general = SUM(x.consumo_cuenta) PRINTX total_general LET total_material = 0 END REPORT