Files
MBS/PROYECTO/gedir/geprrp013.4gl
T

281 lines
11 KiB
Plaintext

{
=======================================================================
Programa : GEPRRP013
Sistema : Sistema de Informacion Gerencia
Proceso : Ranking de Ventas por Vendedor, Compania y Producto
Autor : Tadeo A. Ferreras
Fecha : Enero 18, 1995
Modificado Por : Juan Soto
Descripcion : Se quito las columnas devoluciones y neto. Se Agrego la
columna VENTAS DEL ANO ANTERIOR AL ACTUAL.
Fecha : MAyo 21, 1996.
Modificado Por :Juan Soto
Descripcion : Insertar el cliente
Fecha : Febrero 28, 2001
=======================================================================
}
GLOBALS
"geprgb000.4gl"
DEFINE ger_comp131 RECORD
cod_n SMALLINT,
cod_grupo SMALLINT,
cod_tipo SMALLINT,
cod_sec SMALLINT,
descrip_esp LIKE intb00001.descrip_esp,
unidad_med LIKE intb00001.unidad_med,
cantidad DECIMAL(16,4),
valor DECIMAL(12,2),
cantidad_ant DECIMAL(14,2),
codigo CHAR(7)
END RECORD,
desc_mes CHAR(12),
tipo_ranking CHAR(30),
cantidad_registros SMALLINT
DEFINE ger_comp132 RECORD LIKE ranking.*
DEFINE
p_mes,p_ano,p_ano_ant SMALLINT,
idx2 INTEGER
DEFINE fecha1,fecha2,fecha_inicial,fecha_final DATE
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 geprrp013()
END MAIN
FUNCTION geprrp013()
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
LET int_flag = FALSE
OPTIONS
FORM LINE 8
OPEN FORM gefmrp013 FROM "gefmrp013"
DISPLAY "geprrp013" AT 4,3 ATTRIBUTE(RED)
DISPLAY FORM gefmrp013
DISPLAY "Ranking de Ventas Por Vendedor, Compania y Producto" AT 6,15
ATTRIBUTE(BLACK)
INPUT BY NAME p_ano,p_mes,cantidad_registros,tipo_ranking
BEFORE INPUT
{ CALL combo_din("formonly.p_ano","select distinct a.ano from prdtable a order by a.ano")
CALL combo_din("formonly.p_mes","select a.descrip from mestable a order by a.mes")
}
LET p_ano= YEAR(TODAY)
LET p_mes = MONTH(today)
DISPLAY BY NAME p_ano,p_mes
AFTER INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = FALSE
RETURN
END IF
LET p_ano_ant = p_ano - 1
SELECT MIN(a.fecha_inicio)INTO fecha_inicial
FROM prdtable a
WHERE a.ano = p_ano
SELECT a.fecha_corte INTO fecha_final
FROM prdtable a
WHERE a.mes = p_mes and
a.ano = p_ano
SELECT MIN(a.fecha_inicio) INTO fecha1
FROM prdtable a
WHERE a.ano = p_ano_ant
SELECT a.fecha_corte INTO fecha2
FROM prdtable a
WHERE a.mes = p_mes AND
a.ano = p_ano_ant
EXIT INPUT
END INPUT
CONSTRUCT criterio ON b.cod_n,b.cod_grupo,b.cod_tipo,b.cod_sec
FROM cod_n,cod_grupo,cod_tipo,cod_sec
IF int_flag tHEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = FALSE
RETURN
END IF
CALL seleccionarsalida() RETURNING r_output
# CALL configureoutput(r_output) RETURNING HANDLER
DELETE FROM ranking
IF tipo_ranking = "CANTIDAD" THEN
LET selec1 =
" SELECT TOP ",cantidad_registros USING "<<<","a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med,",
" SUM(b.cantidad),SUM(b.cantidad*b.precio*f.tasa) FROM iptb00002 a,vetb00003 b,vetb00002 c,prdtable d,cgtb00084 f ",
" WHERE 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.factura = c.factura and c.fecha_factura between '",fecha_inicial USING "dd/mm/yyyy","' and '",fecha_final USING "mm/dd/yyyy","' and ",
" c.fecha_factura between d.fecha_inicio and d.fecha_corte and ",
" d.ano =f.ano and d.mes = f.mes and c.ventas = f.ventas and c.tipo_cliente = f.tipo_cliente and ",
" c.status_t is null and ",criterio CLIPPED,
" GROUP BY a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med",
" ORDER BY SUM(b.cantidad) desc "
ELSE
LET selec1 =" SELECT TOP ",cantidad_registros USING "<<<"," a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med,",
" SUM(b.cantidad),SUM(b.cantidad*b.precio*f.tasa) FROM iptb00002 a,vetb00003 b,vetb00002 c,prdtable d,cgtb00084 f ",
" WHERE 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.factura = c.factura and c.fecha_factura between '",fecha_inicial USING "dd/mm/yyyy","' and '",fecha_final USING "mm/dd/yyyy","' and ",
" c.fecha_factura between d.fecha_inicio and d.fecha_corte and ",
" d.ano =f.ano and d.mes = f.mes and c.ventas = f.ventas and c.tipo_cliente = f.tipo_cliente and ",
" c.status_t is null and ",criterio CLIPPED,
" GROUP BY a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med",
" ORDER BY SUM(b.cantidad*b.precio) desc "
END IF
PREPARE comando1 FROM selec1
DECLARE buscar1 CURSOR FOR comando1
OPEN buscar1
LET r_filename = "geprrp013.4rp"
LET preview = 1
# LET r_output = "SVG"
IF fgl_report_loadCurrentSettings(r_filename) THEN -- 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
START REPORT repor_13 TO XML HANDLER handler
# Busqueda de los registros que estan en el ano actual y estan en el
# Ano anterior
LET idx = 1
FOREACH buscar1 INTO ger_comp131.*
SELECT a.cod_n FROM ranking a
WHERE a.cod_n = ger_comp131.cod_n AND
a.cod_grupo = ger_comp131.cod_grupo AND
a.cod_tipo = ger_comp131.cod_tipo AND
a.cod_sec = ger_comp131.cod_sec
IF STATUS= NOTFOUND THEN
INSERT INTO ranking VALUES (idx,'0',ger_comp131.cod_n,ger_comp131.cod_grupo,
ger_comp131.cod_tipo,ger_comp131.cod_sec,
ger_comp131.descrip_esp,ger_comp131.unidad_med,
ger_comp131.cantidad,ger_comp131.valor,'0','0')
END IF
LET idx = idx + 1
END FOREACH
IF tipo_ranking = "CANTIDAD" THEN
LET selec1 =
" SELECT a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med,",
" SUM(b.cantidad),SUM(b.cantidad*b.precio*f.tasa) FROM iptb00002 a,vetb00003 b,vetb00002 c,prdtable d,cgtb00084 f ",
" WHERE 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.factura = c.factura and c.fecha_factura between '",fecha1 USING "dd/mm/yyyy","' and '",fecha2 USING "mm/dd/yyyy","' and ",
" c.fecha_factura between d.fecha_inicio and d.fecha_corte and ",
" d.ano =f.ano and d.mes = f.mes and c.ventas = f.ventas and c.tipo_cliente = f.tipo_cliente and ",
" c.status_t is null and ",criterio CLIPPED,
" GROUP BY a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med",
" ORDER BY SUM(b.cantidad) desc "
DISPLAY "fecha ",fecha1," fecha 2 ",fecha2
ELSE
LET selec1 =" SELECT a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med,",
" SUM(b.cantidad),SUM(b.cantidad*b.precio*f.tasa) FROM iptb00002 a,vetb00003 b,vetb00002 c,prdtable d,cgtb00084 f ",
" WHERE 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.factura = c.factura and c.fecha_factura between '",fecha1 USING "dd/mm/yyyy","' and '",fecha2 USING "mm/dd/yyyy","' and ",
" c.fecha_factura between d.fecha_inicio and d.fecha_corte and ",
" d.ano =f.ano and d.mes = f.mes and c.ventas = f.ventas and c.tipo_cliente = f.tipo_cliente and ",
" c.status_t is null and ",criterio CLIPPED,
" GROUP BY a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med",
" ORDER BY SUM(b.cantidad*b.precio) desc "
END IF
PREPARE comando2 FROM selec1
DECLARE buscar2 CURSOR FOR comando2
OPEN buscar2
LET idx2 = 1
LET idx =0
FOREACH buscar2 INTO ger_comp131.*
SELECT a.cod_n FROM ranking a
WHERE a.cod_n = ger_comp131.cod_n AND
a.cod_grupo = ger_comp131.cod_grupo AND
a.cod_tipo = ger_comp131.cod_tipo AND
a.cod_sec = ger_comp131.cod_sec
IF STATUS<> NOTFOUND THEN
UPDATE ranking SET rankingant = idx2,
cantidad_ant = ger_comp131.cantidad,
valor_ant = ger_comp131.valor
WHERE cod_n = ger_comp131.cod_n AND
cod_Grupo = ger_comp131.cod_grupo AND
cod_tipo = ger_comp131.cod_tipo AND
cod_sec = ger_comp131.cod_sec
END IF
LET idx2 = idx2 + 1
END FOREACH
DECLARE busca_ranking CURSOR FOR
SELECT a.* FROM ranking a
ORDER BY a.rankingact
LET idx = 1
FOREACH busca_ranking INTO ger_comp132.*
IF idx < cantidad_registros THEN
OUTPUT TO REPORT repor_13(ger_comp132.*)
END IF
END FOREACH
FINISH REPORT repor_13
END IF
END FUNCTION
REPORT repor_13(x)
DEFINE x RECORD LIKE ranking.*
DEFINE hora CHAR(16)
FORMAT
FIRST PAGE HEADER
LET hora = TODAY USING "dd/mm/yyyy"
PRINTX desc_mes
ON EVERY ROW
PRINTX x.rankingact, x.rankingant,
x.cod_n,x.cod_grupo,
x.cod_tipo,x.cod_sec,cantidad_registros,
x.descripcion,x.unidad_med,
x.cantidad,x.cantidad_ant,x.valor_ant,
x.valor,p_companias.nombre,p_ano,p_ano_ant,tipo_ranking,hora
END REPORT