Files
2026-09-22 20:38:51 -04:00

316 lines
15 KiB
Plaintext

{
-------------------------------------------------------------------------------
PROGRAMA : VEPRRP050
OBJETIVO : Relacion de Ventas Brutas y Reales para los vendedor
PROGRAMADOR : Ing. Juan Soto (Johnny)
FECHA REALIZACION : Agosto 26,2010
-------------------------------------------------------------------------------
}
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 "decomarmol" USER usuarios USING clave
SELECT * INTO p_companias.* FROM companias
CALL veprrp050()
END MAIN
FUNCTION veprrp050()
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
cliente CHAR(15),
nombre CHAR(40),
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(7),
grupo_venta CHAR(1),
descripcion_v CHAR(30),
descripcion_p CHAR(30),
vendedor CHAR(60),
descuento DEC(12,2),
sec_vend SMALLINT
END RECORD
OPTIONS
FORM LINE 8,
ERROR LINE 23,
COMMENT LINE 21
OPEN FORM vefmrp015 FROM "vefmrp050"
DISPLAY FORM vefmrp015
#### Pide los parametros para busqueda de informacion
LET fecha_inicial = today-29
LET fecha_final = today
INPUT BY NAME fecha_inicial,fecha_final,historico WITHOUT DEFAULTS
#### 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
CONSTRUCT criterio ON b.ventas,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,b.tipo_cliente,b.sec_cliente
FROM pventas,cod_n,cod_grupo,cod_tipo,cod_Sec,tipo_cliente,sec_cliente
BEFORE CONSTRUCT
CALL cventas1()
CALL cvendedor1()
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
# Buscando Pilas vendidas del ano actual
IF historico = "NO" THEN
LET selec =
"SELECT b.ventas,CAST(b.tipo_cliente AS VARCHAR(3))+'-'+ CAST(b.sec_cliente AS VARCHAR(6)),o.nombre,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
" sum(a.cantidad),sum((a.cantidad * a.precio)*k.tasa),'0','0',c.descripcion,d.descrip_esp, ",
" f.producto,ISNULL(RTRIM(CAST(g.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(g.apell1_emp AS CHAR(30))),g.nom1_emp), ",
" SUM((a.cantidad * a.precio) * (a.cantidad_2 / 100)*k.tasa),b.sec_vend ",
"FROM vetb00003 a,vetb00002 b,vetb00061 c,iptb00002 d,iptb00020 f,adtb00003 g,cgtb00084 k,prdtable l,seg0007 m, ",
" vetb00004 o ",
"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 ",
" 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.sec_vend = m.sec_vend AND m.usuario = SUSER_SNAME() AND ",
criterio CLIPPED,
" AND b.sec_vend = g.num_emp ",
" AND b.tipo_cliente = o.tipo_cliente AND b.sec_cliente = o.sec_cliente ",
" AND b.status_t is null ",
"GROUP BY B.VENTAS,b.sec_vend,c.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,d.descrip_esp,f.producto,g.nom1_emp,g.apell1_emp,b.tipo_cliente,b.sec_cliente,o.nombre ",
" UNION ",
"SELECT b.ventas,CAST(b.tipo_cliente AS VARCHAR(3))+'-'+ CAST(b.sec_cliente AS VARCHAR(6)),o.nombre,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
"'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)),c.descripcion,d.descrip_esp, ",
"f.producto,ISNULL(RTRIM(CAST(i.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(i.apell1_emp AS CHAR(30))),i.nom1_emp), ",
"'0',b.sec_vend ",
"from iptb00006 q,vetb00003 a,cctb00001 p, vetb00002 b,cgtb00084 k,prdtable l,iptb00020 f,adtb00003 i,iptb00002 d,vetb00061 c,seg0007 m, ",
" vetb00004 o ",
"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 ",
"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 p.cod_emp_Sec = i.num_emp and ",
"b.ventas = k.ventas and ", criterio CLIPPED,
" and b.ventas = c.ventas and m.usuario = SUSER_SNAME() AND ",
" m.sec_vend = b.sec_vend and ",
" b.tipo_cliente = o.tipo_cliente AND b.sec_cliente = o.sec_cliente and ",
"q.status_t is null and p.status_t is null ",
"group by b.ventas,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
"c.descripcion,d.descrip_esp, ",
"f.producto,ISNULL(RTRIM(CAST(i.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(i.apell1_emp AS CHAR(30))),i.nom1_emp), ",
"b.sec_vend,b.tipo_cliente,b.sec_cliente,o.nombre ",
"ORDER BY b.sec_vend,b.ventas,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_Sec"
ELSE
LET selec =
"SELECT b.ventas,CAST(b.tipo_cliente AS VARCHAR(3))+'-'+ CAST(b.sec_cliente AS VARCHAR(6)),o.nombre,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
" sum(a.cantidad),sum((a.cantidad * a.precio)*k.tasa),'0','0',c.descripcion,d.descrip_esp, ",
" f.producto,ISNULL(RTRIM(CAST(g.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(g.apell1_emp AS CHAR(30))),g.nom1_emp), ",
" SUM((a.cantidad * a.precio) * (a.cantidad_2 / 100)*k.tasa),b.sec_vend ",
"FROM historicoMTECH.dbo.vetb00003 a,historicoMTECH.dbo.vetb00002 b,historicoMTECH.dbo.vetb00061 c,",
"historicoMTECH.dbo.iptb00002 d,historicoMTECH.dbo.iptb00020 f,historicoMTECH.dbo.adtb00003 g,historicoMTECH.dbo.cgtb00084 k,",
"historicoMTECH.dbo.prdtable l,historicoMTECH.dbo.seg0007 m, ",
" historicoMTECH.dbo.vetb00004 o ",
"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 ",
" 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.sec_vend = m.sec_vend AND m.usuario = SUSER_SNAME() AND ",
criterio CLIPPED,
" AND b.sec_vend = g.num_emp ",
" AND b.tipo_cliente = o.tipo_cliente AND b.sec_cliente = o.sec_cliente ",
" AND b.status_t is null ",
"GROUP BY B.VENTAS,b.sec_vend,c.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,d.descrip_esp,f.producto,g.nom1_emp,g.apell1_emp,b.tipo_cliente,b.sec_cliente,o.nombre ",
" UNION ",
"SELECT b.ventas,b.tipo_cliente,b.sec_cliente,o.nombre,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
"'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)),c.descripcion,d.descrip_esp, ",
"f.producto,ISNULL(RTRIM(CAST(i.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(i.apell1_emp AS CHAR(30))),i.nom1_emp), ",
"'0',b.sec_vend ",
"from iptb00006 q,vetb00003 a,cctb00001 p, vetb00002 b,cgtb00084 k,prdtable l,iptb00020 f,adtb00003 i,iptb00002 d,vetb00061 c,seg0007 m, ",
" vetb00004 o ",
"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 ",
"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 p.cod_emp_Sec = i.num_emp and ",
"b.ventas = k.ventas and ", criterio CLIPPED,
" and b.ventas = c.ventas and m.usuario = SUSER_SNAME() AND ",
" m.sec_vend = b.sec_vend and ",
" b.tipo_cliente = o.tipo_cliente AND b.sec_cliente = o.sec_cliente and ",
"q.status_t is null and p.status_t is null ",
"group by b.ventas,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec, ",
"c.descripcion,d.descrip_esp, ",
"f.producto,ISNULL(RTRIM(CAST(i.nom1_emp AS CHAR(30))) +' '+ RTRIM(CAST(i.apell1_emp AS CHAR(30))),i.nom1_emp), ",
"b.sec_vend,b.tipo_cliente,b.sec_cliente,o.nombre ",
"ORDER BY b.sec_vend,b.ventas,b.tipo_cliente,b.sec_cliente,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_Sec"
END IF
DISPLAY "<< Estoy Buscando Ventas Del Mes ... Espere Por Favor. >>"
AT 19,14 ATTRIBUTE (BOLD,REVERSE)
PREPARE busca_act FROM selec
DECLARE act2 SCROLL CURSOR FOR busca_act
OPEN act2 USING fecha_inicial,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 = "veprrp050b.4rp"
IF fgl_report_loadCurrentSettings(r_filename) THEN -- load the .4rp file
LET r_output='SVG'
LET preview=1
CALL fgl_report_selectDevice(r_output) -- changing default
CALL fgl_report_selectPreview(preview) -- changing default
LET handler = fgl_report_commitCurrentSettings() -- commit changes
END IF
### Loop para igualar tipo de venta a la variable ventas.ventas
IF handler IS NOT NULL THEN -- report engine was configured ok
START REPORT verp50 TO XML HANDLER handler
FOREACH act2 INTO ventas.ventas,ventas.cliente,ventas.nombre,
ventas.cod_n,ventas.cod_grupo,ventas.cod_tipo,
ventas.cod_sec,ventas.unidad_acum,ventas.valor_acum,
ventas.cantidad_dev,ventas.valor_dev,
ventas.descripcion_v,ventas.descrip_esp,ventas.descripcion_p,
ventas.vendedor,ventas.descuento,ventas.sec_vend
IF ventas.descuento IS NULL THEN
LET ventas.descuento = 0
END IF
LET ventas.valor_acum = ventas.valor_acum - ventas.descuento
{ #DEVOLUCIONES
LET ventas.valor_dev = 0
LET ventas.cantidad_dev = 0
SELECT SUM(a.cantidad_2),SUM(a.cantidad_2*b.precio*d.tasa)
INTO ventas.cantidad_dev,ventas.valor_dev
FROM iptb00006 a,vetb00003 b,cctb00001 c,cgtb00084 d,prdtable e,vetb00002 f
WHERE 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.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
c.fecha_orig between fecha_inicial and fecha_final AND
e.fecha_inicio >= fecha_inicial and e.fecha_corte <= fecha_final and
e.ano = d.ano and e.mes = d.mes and
c.tipo_cliente = d.tipo_cliente and
d.tipo_cliente = a.cod_sp and
b.factura = f.factura and
f.ventas = ventas.ventas and
f.tipo_cliente = c.tipo_cliente and
f.sec_cliente = c.sec_cliente and
c.aplica_a = b.factura and
a.fact_no = cast(b.factura as char(6)) AND
c.cod_emp_sec = ventas.sec_vend and
c.banco = a.cod_mov AND
a.num_doc = c.num_cheque AND
c.tipo_doc = 'NC' AND
a.status_t IS NULL
}
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
OUTPUT TO REPORT verp50(ventas.*)
END FOREACH
FINISH REPORT verp50
END IF
END FUNCTION
REPORT ventasClientesDetalle(x)
DEFINE x RECORD
cliente CHAR(15),
nombre CHAR(40),
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(7),
grupo_venta CHAR(1),
descripcion_v CHAR(30),
descripcion_p CHAR(30),
vendedor CHAR(60),
descuento DEC(12,2),
sec_vend SMALLINT
END RECORD,
hora VARCHAR(25)
ORDER BY x.sec_vend,x.ventas,x.cliente
FORMAT
ON EVERY ROW
PRINTX x.*,p_companias.nombre,fecha_inicial,fecha_final
END REPORT