Files
MBS/PROYECTO/vedir/veprrp015_3.4gl
T

404 lines
16 KiB
Plaintext

{
-------------------------------------------------------------------------------
PROGRAMA : VEPRRP015
OBJETIVO : Relacion de Ventas Brutas y Reales.
PROGRAMADOR : Ing. Juan Soto (Johnny)
FECHA REALIZACION : Agosto 28, 1997
-------------------------------------------------------------------------------
}
GLOBALS "veprgb000.4gl"
DEFINE act,mes_ini INTEGER ,
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 veprrp015()
END MAIN
FUNCTION veprrp015()
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
DEFINE historico CHAR(2)
### Definicion del registro a exportar al reporte
DEFINE ventas RECORD
cod_n SMALLINT,
cod_grupo SMALLINT,
cod_tipo SMALLINT,
cod_sec SMALLINT,
descrip_esp CHAR(30),
unidad_med CHAR(4) ,
marca CHAR(1),
ventas CHAR(1),
cantidad_vend DECIMAL(12,2),
valor DECIMAL(12,2),
cantidad_dev DECIMAL(12,2),
valor_dev DECIMAL(12,2),
unidad_acum DECIMAL(12,2),
valor_acum DECIMAL(12,2),
codigo CHAR(20),
grupo_venta CHAR(1),
descripcion_v CHAR(30),
descripcion_p CHAR(30),
vendedor CHAR(60),
descuento DEC(12,2),
sec_vend SMALLINT,
costo_std DEC(18,5)
END RECORD,
salida CHAR(50),
costo_unitario DEC(12,5)
#WHENEVER ERROR CONTINUE
OPTIONS
FORM LINE 8,
ERROR LINE 23,
COMMENT LINE 21
OPEN FORM vefmrp015 FROM "vefmrp015"
DISPLAY FORM vefmrp015
#### Pide los parametros para busqueda de informacion
SELECT a.fecha_inicio INTO fecha_inicial FROM prdtable a
WHERE a.ano =YEAR(today) AND a.mes = MONTH(today)
#LET fecha_inicial = today-29
LET fecha_final = TODAY
LET historico = "NO"
INPUT BY NAME fecha_inicial,fecha_final,historico WITHOUT DEFAULTS
AFTER FIELD historico
IF historico IS NULL THEN
CALL msg(16)
NEXT FIELD historico
END IF
AFTER INPUT
IF INT_FLAG THEN
LET INT_FLAG = FALSE
CALL msg(2)
RETURN
END IF
IF historico IS NULL THEN
CALL msg(16)
NEXT FIELD historico
END IF
EXIT INPUT
END INPUT
#### Permite Cancelar reporte mediante el uso de CONTROL-C
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
IF salida <> "veprrp015b.4rp" THEN
CONSTRUCT criterio ON b.ventas,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,b.sec_vend
FROM pventas,cod_n,cod_grupo,cod_tipo,cod_Sec,kvendedor
BEFORE CONSTRUCT
CALL cventas1()
CALL cvendedor()
CALL cbclase()
AFTER CONSTRUCT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
EXIT CONSTRUCT
END CONSTRUCT
ELSE
CONSTRUCT criterio ON b.ventas,d.cod_cia,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec
FROM pventas,cod_cia,cod_n,cod_grupo,cod_tipo,cod_Sec
BEFORE CONSTRUCT
CALL cventas1()
CALL cvendedor()
CALL cbclase()
AFTER CONSTRUCT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
EXIT CONSTRUCT
END CONSTRUCT
END IF
# Buscando Pilas vendidas del ano actual
{ ORIGINAL
" SELECT SUM(a.cantidad) , SUM(a.cantidad * a.precio * k.tasa) , '0', '0' , f.producto, a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec, ",
" SUM((a.cantidad * a.precio) * (a.cantidad_2 / 100) * k.tasa) ",
" FROM vetb00003 AS a INNER JOIN ",
" vetb00002 AS b ON a.factura = b.factura INNER JOIN ",
" iptb00002 AS d ON a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND a.cod_tipo = d.cod_tipo AND a.cod_sec = d.cod_sec INNER JOIN ",
" vetb00061 AS c ON b.ventas = c.ventas INNER JOIN ",
" iptb00020 AS f ON a.cod_n = f.cod_n INNER JOIN ",
" cgtb00084 AS k ON b.ventas = k.ventas AND b.tipo_cliente = k.tipo_cliente INNER JOIN ",
" prdtable AS l ON k.mes = l.mes AND k.ano = l.ano ",
"WHERE (b.fecha_factura BETWEEN ? AND ?) AND (b.fecha_factura BETWEEN l.fecha_inicio AND l.fecha_corte) AND (b.status_t IS NULL) ",
" AND ",criterio CLIPPED,
" GROUP BY f.producto,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec ",
" UNION ",
"SELECT '0' , '0', SUM(q.cantidad_2) , SUM(q.cantidad_2 * a.precio * k.tasa - (q.cantidad_2 * a.precio) * (a.cantidad_2 / 100) * k.tasa) , ",
" f.producto, a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec, '0' ",
"FROM vetb00002 AS b INNER JOIN ",
" cgtb00084 AS k ON b.ventas = k.ventas AND b.tipo_cliente = k.tipo_cliente AND b.ventas = k.ventas INNER JOIN ",
" iptb00006 AS q INNER JOIN ",
" vetb00003 AS a ON q.cod_n = a.cod_n AND q.cod_grupo = a.cod_grupo AND q.cod_tipo = a.cod_tipo AND q.cod_sec = a.cod_sec INNER JOIN ",
" iptb00002 AS d ON a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND a.cod_tipo = d.cod_tipo AND a.cod_sec = d.cod_sec INNER JOIN ",
" iptb00020 AS f ON a.cod_n = f.cod_n AND a.cod_n = f.cod_n ON CAST(b.factura AS char(7)) = q.fact_no AND b.factura = a.factura INNER JOIN ",
" cctb00001 AS p ON q.cod_mov = p.banco AND q.num_doc = p.num_cheque AND b.tipo_cliente = p.tipo_cliente AND b.sec_cliente = p.sec_cliente AND ",
" b.factura = p.aplica_a INNER JOIN ",
" prdtable AS l ON k.mes = l.mes AND k.ano = l.ano INNER JOIN ",
" vetb00061 AS c ON b.ventas = c.ventas ",
" WHERE (q.cod_mov IN (12, 13)) AND (q.fecha BETWEEN ? AND ?) AND (p.tipo_doc = 'NC') AND (p.fecha_orig BETWEEN l.fecha_inicio AND ",
" l.fecha_corte) AND (q.status_t IS NULL) AND (p.status_t IS NULL) AND ",criterio CLIPPED,
" GROUP BY f.producto, a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec ",
" ORDER BY f.producto "
}
LET selec =
" SELECT sum(a.cantidad),sum((a.cantidad * a.precio)*k.tasa),'0','0',",
" f.producto, a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec, ",
" SUM((a.cantidad * a.precio) * (a.cantidad_2 / 100)*k.tasa),SUM(a.cantidad)*(x.material+x.labor+x.gastos) ",
"FROM vetb00003 a LEFT OUTER JOIN iptb00004 x ON x.ano = YEAR(?) AND x.mes_fin = 12 AND a.cod_n = x.cod_n AND ",
" a.cod_grupo = x.cod_grupo and a.cod_tipo = x.cod_tipo and a.cod_sec = x.cod_sec and x.status_t is null , ",
"vetb00002 b,vetb00061 c,iptb00002 d,iptb00020 f,cgtb00084 k,prdtable l ",
"WHERE b.fecha_factura between ? AND ? AND a.factura = b.factura and ",
"a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND a.cod_tipo = d.cod_tipo AND ",
"a.cod_Sec = d.cod_sec AND b.ventas = c.ventas AND ",
"a.cod_n = f.cod_n and ",criterio CLIPPED,
" AND b.ventas = k.ventas and b.tipo_cliente = k.tipo_cliente and ",
"b.fecha_factura between l.fecha_inicio and l.fecha_corte and ",
" l.mes = k.mes and l.ano = k.ano ",
"AND b.status_t is null ",
"GROUP BY f.producto,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,x.material,x.labor,x.gastos ",
" UNION ",
" SELECT ",
" '0','0',sum(q.cantidad_2),sum(((q.cantidad_2 * a.precio)*k.tasa)-((q.cantidad_2 * a.precio) * (a.cantidad_2 / 100)*k.tasa)), ",
" f.producto,a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec,'0', SUM(a.cantidad)*(x.material+x.labor+x.gastos) ",
" from iptb00006 q LEFT OUTER JOIN iptb00004 x ON x.ano = YEAR(?) AND x.mes_fin = 12 AND q.cod_n = x.cod_n AND ",
" q.cod_grupo = x.cod_grupo and q.cod_tipo = x.cod_tipo and q.cod_sec = x.cod_sec and x.status_t is null ,",
" vetb00003 a,cctb00001 p, vetb00002 b,cgtb00084 k,prdtable l,iptb00020 f,iptb00002 d,vetb00061 c ",
" where a.cod_n = q.cod_n and a.cod_grupo = q.cod_grupo and a.cod_tipo = q.cod_tipo and a.cod_Sec = q.cod_Sec and ",
" q.area = a.area AND ",
" a.cod_n = d.cod_n and a.cod_grupo = d.cod_grupo and a.cod_tipo = d.cod_tipo and a.cod_Sec = d.cod_Sec and ",
" a.cod_n = f.cod_n and b.ventas = k.ventas and ",
" q.cod_mov in (12,13) and q.fact_no = cast(b.factura as char(7)) and ",
" q.fecha between ? AND ? and ",
" p.banco = q.cod_mov and p.num_cheque = q.num_doc and p.tipo_doc = 'NC' AND ",
" b.tipo_cliente = p.tipo_cliente and b.sec_cliente = p.sec_cliente and ",
" p.aplica_a = b.factura and b.factura = a.factura and ",
" p.fecha_orig between l.fecha_inicio and l.fecha_corte AND ",
" k.mes = l.mes and k.ano = l.ano and k.tipo_cliente = b.tipo_cliente and ",
" f.cod_n = a.cod_n and ",criterio CLIPPED,
" AND b.ventas = k.ventas and ",
" b.ventas = c.ventas and ",
" q.status_t is null and p.status_t is null ",
"GROUP BY f.producto, a.cod_n, a.cod_grupo, a.cod_tipo, a.cod_sec ,x.material,x.labor,x.gastos ",
"ORDER BY f.producto "
PREPARE busca_act FROM selec
DECLARE act2 SCROLL CURSOR FOR busca_act
OPEN act2 USING fecha_final,fecha_inicial,fecha_final,fecha_final,fecha_inicial,fecha_final
#OPEN act2 USING fecha_final,fecha_inicial,fecha_final
-- configure report engine; the functions prefixed fgl that are called here are part of the GRW API
LET r_filename = "veprrp015b_1.4rp"
LET idx = 1
### Loop para igualar tipo de venta a la variable ventas.ventas
CALL seleccionarsalida() RETURNING r_output
FOREACH act2 INTO
ventas.unidad_acum,ventas.valor_acum,
ventas.cantidad_dev,ventas.valor_dev,
ventas.descripcion_v,ventas.cod_n,ventas.cod_grupo,ventas.cod_tipo,ventas.cod_sec,
ventas.descuento,ventas.costo_std
IF idx = 1 THEN
IF fgl_report_loadCurrentSettings(r_filename) THEN -- load the .4rp file
# LET r_output='SVG'
LET preview=TRUE
CALL fgl_report_selectDevice(r_output) -- changing default
# CALL fgl_report_selectPreview(preview) -- changing default
LET handler = fgl_report_commitCurrentSettings() -- commit changes
END IF
START REPORT grupo TO XML HANDLER HANDLER
END IF
LET idx = idx +1
IF ventas.descuento IS NULL THEN
LET ventas.descuento = 0
END IF
LET ventas.valor_acum = ventas.valor_acum - ventas.descuento
IF ventas.cantidad_dev IS NULL THEN
LET ventas.cantidad_Dev = 0
END IF
IF ventas.valor_dev IS NULL THEN
LET ventas.valor_Dev = 0
END IF
IF ventas.unidad_acum IS NULL THEN
LET ventas.unidad_acum = 0
END IF
IF ventas.valor_acum IS NULL THEN
LET ventas.valor_acum = 0
END IF
# BUSCA EL COSTO STD
LET costo_unitario = 0
# SELECT AVG(a.material+a.gastos+a.labor) INTO costo_unitario
# FROM iptb00004 a
# WHERE a.mes_fin ='12' AND a.ano = YEAR(fecha_final) AND
# a.cod_n=ventas.cod_n AND a.cod_grupo = ventas.cod_grupo AND
# a.cod_tipo = ventas.cod_tipo AND a.cod_sec = ventas.cod_sec AND
# a.status_t IS NULL
# LET ventas.costo_std=costo_unitario
OUTPUT TO REPORT grupo(ventas.unidad_acum,ventas.valor_acum,
ventas.cantidad_dev,ventas.valor_dev,
ventas.descripcion_v,
ventas.descuento,ventas.costo_std)
END FOREACH
FINISH REPORT grupo
END FUNCTION
REPORT grupo(x)
DEFINE x RECORD
unidad_acum DECIMAL(12,2),
valor_acum DECIMAL(12,2),
cantidad_dev DECIMAL(12,2),
valor_dev DECIMAL(12,2),
descripcion_v CHAR(30),
descuento DEC(12,2),
costo_std DEC(18,5)
END RECORD,
xcosto_std,cantidadReal,valorReal DEC(12,2)
DEFINE hora CHAR(5)
DEFINE t_t_t_cantidad_dev, t_t_t_valor_dev,
g_g_g_cantidad_vend,g_g_g_valor_vend,
g_g_g_unidad_acum,g_g_g_valor_acum,
t1_cantidad_dev,t1_valor_dev,
t1_total_costo,tg_total_costo,t1_margen,tg_margen DEC(12,2),
porcentaje,total_margen,total_porc DEC(12,2)
#### Especifica Formato de salida
OUTPUT
TOP MARGIN 0
LEFT MARGIN 0
BOTTOM MARGIN 4
ORDER BY x.descripcion_v
FORMAT
FIRST PAGE HEADER
LET total_margen = 0
LET total_porc = 0
LET g_g_g_unidad_acum = 0
LET g_g_g_valor_acum = 0
LET t_t_t_cantidad_dev = 0
LET t_t_t_valor_dev = 0
LET t1_cantidad_dev = 0
LET t1_valor_dev =0
LET t1_total_costo = 0
LET t1_margen =0
LET tg_margen =0
LET g_g_g_cantidad_vend = 0
LET g_g_g_valor_vend = 0
LET tg_total_costo = 0
AFTER GROUP OF x.descripcion_v
LET x.valor_acum = GROUP SUM(x.valor_acum)
LET x.cantidad_dev = GROUP SUM(x.cantidad_dev)
LET x.unidad_acum = GROUP SUM(x.unidad_acum)
LET cantidadReal = x.unidad_acum-x.cantidad_dev
LET x.valor_dev = GROUP SUM(x.valor_dev)
LET valorReal = x.valor_acum - x.valor_dev
# LET xcosto_std = cantidadReal * GROUP SUM(x.costo_std)
LET xcosto_std = GROUP SUM(x.costo_std)
LET t1_margen=valorReal-xcosto_std
IF valorReal > 0 THEN
LET porcentaje = (t1_margen/valorReal)*100
ELSE
LET porcentaje = 0
END IF
# TOTAL GENERAL
LET g_g_g_unidad_acum = x.unidad_acum + g_g_g_unidad_acum
LET g_g_g_valor_acum = x.valor_acum + g_g_g_valor_acum
LET t1_cantidad_dev = x.cantidad_dev + t1_cantidad_Dev
LET t1_valor_dev = x.valor_dev + t1_valor_Dev
LET g_g_g_cantidad_vend = (x.unidad_acum - x.cantidad_dev) + g_g_g_cantidad_vend
LET g_g_g_valor_vend = (x.valor_acum - x.valor_dev) + g_g_g_valor_vend
# CALL fgl_winmessage("INFO",g_g_g_valor_vend,"stop")
PRINTX xcosto_std,
x.valor_dev,
CantidadReal,
valorReal,
t1_margen,
p_companias.nombre,
hora,
fecha_inicial,fecha_final,
x.descripcion_v,
g_g_g_cantidad_Vend,g_g_g_valor_Vend,porcentaje
ON LAST ROW
LET tg_total_costo = SUM(x.costo_std)
LET total_margen = SUM(x.costo_std)
LET total_porc = ((g_g_g_valor_vend - tg_total_costo)/g_g_g_valor_vend)*100
PRINTX tg_total_costo,total_porc
END REPORT
FUNCTION cventas1()
DEFINE kventas SMALLINT, dventas CHAR(30)
LET pventas = ui.combobox.forname("formonly.pventas")
DECLARE bventas CURSOR FOR
SELECT a.ventas,a.descripcion FROM vetb00061 a
CALL pventas.clear()
FOREACH bventas INTO kventas,dventas
CALL pventas.additem(kventas,dventas)
END FOREACH
END FUNCTION