Files
MBS/PROYECTOS/irdir/irprrp044.4gl
T

280 lines
11 KiB
Plaintext

{------------------------------------------------------------------------------
PROGRAMA : IRPRRP009
OBJETIVO : Operacion por Tipo de Movimiento Repuestos
PROGRAMADOR : VALENTIN RODRIGUEZ
FECHA REALIZACION : MARZO, 13 2020
---------------------------------------------------------------------------------}
GLOBALS "irprgb000.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_companias.* FROM companias
CALL irprrp009()
END MAIN
FUNCTION irprrp009()
DEFINE select_ac CHAR(1000)
DEFINE c_ano CHAR(4)
DEFINE entra,nombre_mes CHAR(14)
DEFINE entra1 CHAR(5)
DEFINE detalle CHAR(100)
DEFINE numero_ent CHAR(2)
DEFINE p_ano, ano_act CHAR(4)
DEFINE tiempo 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 irfmmt044 FROM "irfmrp044"
DISPLAY FORM irfmmt044
DIALOG ATTRIBUTE(UNBUFFERED)
CONSTRUCT criterio ON a.cuenta_no,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec
FROM xcuenta, cod_n,cod_grupo,cod_tipo,cod_Sec
BEFORE CONSTRUCT
CALL cuentas()
CALL ircmovimientos()
AFTER CONSTRUCT
END CONSTRUCT
INPUT BY NAME acumulado.cod_mov,datos_cons.fech_in,datos_cons.fech_fi
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
AFTER FIELD fech_in
IF datos_cons.fech_in IS NULL THEN
CALL msg(16)
NEXT FIELD fech_in
END IF
AFTER FIELD fech_fi
IF datos_cons.fech_fi IS NULL THEN
CALL msg(16)
NEXT FIELD fech_final
END IF
LET ano_act = year(datos_cons.fech_fi)
ON ACTION generar ATTRIBUTE(TEXT="Genera Informacion",IMAGE="printer")
IF acumulado.cod_mov IS NULL THEN
CALL msg(16)
NEXT FIELD cod_mov
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 ",
"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.cod_mov = ",acumulado.cod_mov,
" AND 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 ="irprrp044.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
CALL fgl_report_configurexlsxdevice(null,null,null,false,false,null,1)
LET handler = fgl_report_commitCurrentSettings() -- commit changes
END IF
SELECT descrip_mov INTO acumulado.descrip_mov FROM irtb00005
WHERE cod_mov = acumulado.cod_mov
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
ELSE
CALL fgl_winmessage("INFO", "NO HAY REGISTROS EN ESTE RANGO DE FECHA Y CON LOS PARAMETROS INDICADOS", "INFO")
END IF
END INPUT
ON ACTION CANCEL
EXIT PROGRAM
END DIALOG
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 codigo_producto CHAR(100)
DEFINE hora CHAR(5),
actual VARCHAR(20)
DEFINE total_material, total_cuenta,
total_general DECIMAL (12,2)
ORDER BY x.cod_mov,x.cuenta
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
PRINTX x.descrip_mov
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_general = total_general + x.consumo_cuenta
PRINTX codigo_producto,x.unidad_med,x.consumo,x.gasto_ind,
rango_fecha,p_companias.nombre, x.consumo_cuenta,
hora,actual,x.cuenta
AFTER GROUP OF x.cuenta
LET total_cuenta = GROUP SUM(x.consumo_cuenta)
PRINTX total_cuenta
ON LAST ROW
LET total_general = SUM(x.consumo_cuenta)
PRINTX total_general
LET total_material = 0
END REPORT