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

166 lines
7.3 KiB
Plaintext

FUNCTION geprcs50_1(tipoReporte,ano1,mes)
DEFINE ano1,mes SMALLINT,
selec STRING,
data RECORD
valor_bruto DEC(12,2),
devoluciones,neto DEC(12,2),
conducesSinFactura DEC(12,2),
tipo_ventas,mes,moneda VARCHAR(60),
ano,numero_mes SMALLINT
END RECORD,
idx SMALLINT,
r_filename,r_output,tipoReporte,nombrecia,reporte STRING,
preview BOOLEAN,
HANDLER om.SaxDocumentHandler,
nombremes VARCHAR(30),
fechaFinal,fechaInicial DATE,
uuid INT,
renderingHints om.SaxAttributes
SELECT a.nombre INTO nombrecia FROM companias a
SELECT a.fecha_corte INTO fechaFinal FROM prdtable a WHERE a.ano = ano1 AND a.mes = mes
SELECT MIN(a.fecha_inicio) INTO fechaInicial FROM prdtable a WHERE a.ano = ano1 AND a.mes <= mes
LET selec =
"SELECT SUM((x.sub_total*x4.tasa) - (x.monto_desc*x4.tasa)) ,'0','0','0',
x1.descripcion,x2.descrip,x2.mes,x.ventas
FROM marmotech.dbo.prdtable AS x3 INNER JOIN
marmotech.dbo.mestable AS x2 ON x3.mes = x2.mes INNER JOIN
marmotech.dbo.cgtb00084 AS x4 ON x3.mes = x4.mes AND
x3.ano = x4.ano CROSS JOIN
marmotech.dbo.vetb00002 AS x INNER JOIN
marmotech.dbo.vetb00061 AS x1 ON x.ventas = x1.ventas and
(x.fecha_factura BETWEEN x3.fecha_inicio AND x3.fecha_corte)
and x3.ano = ",ano1, " and x3.mes= ",mes,
" and x.status_t is null and x.ventas = x1.ventas and
x4.tipo_cliente = x.tipo_cliente
GROUP BY x1.descripcion,
x2.descrip,
x2.mes,
x.ventas
UNION
SELECT '0', ISNULL(SUM((c.valor_cheque+c.monto_desc)*x8.tasa),0),'0','0',
x1.descripcion,x2.descrip,x2.mes ,x1.ventas
FROM marmotech.dbo.cctb00001 c, marmotech.dbo.prdtable d,
marmotech.dbo.vetb00060 x7,marmotech.dbo.cgtb00084 x8,
marmotech.dbo.vetb00061 x1,marmotech.dbo.mestable x2
WHERE c.tipo_doc in('NC') and x7.ventas = x8.ventas and
d.ano = x8.ano and d.mes = x8.mes and
d.mes = x2.mes AND
x7.tipo_cliente = x8.tipo_cliente and
c.tipo_cliente = x7.tipo_cliente and
c.fecha_orig between d.fecha_inicio and d.fecha_corte and c.status_t is null and
d.ano = ",ano1," AND d.mes = ",mes," and
x7.ventas = x1.ventas
GROUP BY x1.descripcion,x2.descrip,x1.ventas,x2.mes
UNION
select '0','0','0',sum((a.cantidad_2*c.precio*x8.tasa)-((a.cantidad_2*c.precio*x8.tasa)*(c.descuento/100))),
x1.descripcion,e.descrip,e.mes,x1.ventas
from iptb00006 a,prtb00013 c,prdtable d,mestable e,iptb00005 f,vetb00060 x7,vetb00061 x1,cgtb00084 x8
where a.fecha between d.fecha_inicio and d.fecha_corte and d.ano = x8.ano and d.mes = x8.mes and
x8.tipo_cliente = a.cod_sp and
d.ano = ",ano1," and d.mes = ",mes," and d.mes = e.mes and x7.tipo_cliente = a.cod_sp and x7.ventas = x1.ventas and
a.cod_mov = f.cod_mov and f.control_clientes = 'SI' AND f.control_despacho = 'SI' AND
a.status_t is null and a.cod_mov = 30 and a.factura is null
and a.cod_n = c.cod_n and a.cod_grupo = c.cod_grupo and a.cod_tipo = c.cod_tipo and a.cod_sec = c.cod_sec and a.num_oc = c.num_oc
group by x1.descripcion,e.descrip,e.mes,x1.ventas
"
PREPARE comando FROM selec
DECLARE buscar CURSOR FOR comando
LET idx = 1
LET r_output = 'HTML'
LET preview = 1
FOREACH buscar INTO data.*
IF idx = 1 THEN
LET r_filename ="geprcs050_1.4rp"
IF fgl_report_loadCurrentSettings(r_filename) THEN -- load the .4rp file
LET preview=1
CALL fgl_report_selectDevice(r_output) -- changing default
CALL fgl_report_selectPreview(preview) -- changing default
CALL fgl_report_configureHTMLDevice(
NULL, --fromPage INTEGER,
NULL, --toPage INTEGER,
NULL, --embedImages INTEGER,
NULL, --imageGenerationDirectory STRING,
NULL, --imageURLPrefix STRING,
NULL, --removeWhitespace BOOLEAN,
NULL, --ignoreRowAlignment BOOLEAN,
NULL, --ignoreColumnAlignment BOOLEAN,
NULL) --removeBackgroundImages BOOLEAN )
LET handler = fgl_report_commitCurrentSettings() -- commit changes
START REPORT reporte TO XML HANDLER HANDLER
LET idx = 2
END IF
END IF
LET data.ano = ano1
IF data.devoluciones < 0 THEN
LET data.devoluciones = data.devoluciones * -1
END IF
IF data.conducesSinFactura < 0 THEN
LET data.conducesSinFactura = data.conducesSinFactura * -1
END IF
OUTPUT TO REPORT reporte(data.*,nombreCia,tiporeporte)
END FOREACH
IF idx > 1 THEN
FINISH REPORT reporte
CALL ui.Interface.frontCall( "standard", "launchurl", [reporte], [] )
END IF
END FUNCTION
REPORT reporte(x,nombrecia,tipoReporte)
DEFINE x RECORD
valor_bruto DEC(12,2),
devoluciones,neto DEC(12,2),
conducesSinFactura DEC(12,2),
tipo_ventas,mes,moneda VARCHAR(60),
ano,numero_mes SMALLINT
END RECORD,
mes STRING,
vbruto,vdevolucion,veconduces,tvbruto,tvdevolucion,tveconduces,tneto DEC(12,2),
nombrecia VARCHAR(100),
tipoReporte,hora VARCHAR(50)
ORDER BY x.tipo_ventas
FORMAT
FIRST PAGE HEADER
LET tneto = 0
LET hora = current
AFTER GROUP OF x.tipo_ventas
LET vbruto = GROUP SUM(x.valor_bruto)
LET vdevolucion = GROUP SUM(x.devoluciones)
LET veconduces = GROUP SUM(x.conducesSinFactura)
LET x.neto = vbruto - vdevolucion
PRINTX mes,x.*,nombrecia,tipoReporte,vbruto,vdevolucion,veconduces,hora
LET tneto = x.neto + tneto
ON LAST ROW
LET tvbruto = SUM(x.valor_bruto)
LET tvdevolucion = SUM(x.devoluciones)
LET tveconduces = SUM(x.conducesSinFactura)
PRINTX tvbruto,tvdevolucion,tveconduces,tneto
END REPORT