235 lines
8.8 KiB
Plaintext
235 lines
8.8 KiB
Plaintext
{
|
|
-------------------------------------------------------------------------------
|
|
PROGRAMA : VEPRRP015
|
|
OBJETIVO : Generacion ventas por mes
|
|
PROGRAMADOR : Ing. Juan Soto (Johnny)
|
|
FECHA REALIZACION : Agosto 08, 2022
|
|
-------------------------------------------------------------------------------
|
|
}
|
|
|
|
IMPORT JAVA javax.mail.Session
|
|
|
|
GLOBALS "veprgb000.4gl"
|
|
DEFINE mes,ano INTEGER ,
|
|
fecha_inicial,fecha_final DATE,
|
|
subject,attachment VARCHAR(100),
|
|
cuerpo_correo STRING,
|
|
|
|
toEmail string,
|
|
retorne BOOLEAN
|
|
|
|
DEFINE rutafile,nombreusuario VARCHAR(200)
|
|
|
|
DEFINE xusername,xsmtphost,xsmtpport,xpassword,pusuario,etiqueta STRING
|
|
MAIN
|
|
DEFER INTERRUPT
|
|
|
|
CALL STARTLOG("ventasmes.txt")
|
|
CALL ARG_VAL(1) RETURNING usuarios
|
|
CALL ARG_VAL(2) RETURNING clave
|
|
|
|
CALL ARG_VAL(3) RETURNING toEmail
|
|
|
|
CALL ARG_VAL(4) RETURNING pusuario
|
|
CALL ARG_VAL(5) RETURNING etiqueta
|
|
|
|
|
|
CONNECT TO "smarmotech" USER usuarios USING clave
|
|
IF pusuario IS NOT NULL THEN
|
|
SELECT a.nombreusuario INTO nombreusuario FROM seg0001 a
|
|
WHERE a.usuario = pusuario
|
|
END IF
|
|
SELECT * INTO p_companias.* FROM companias
|
|
CALL ventas_mes()
|
|
|
|
END MAIN
|
|
|
|
FUNCTION ventas_mes()
|
|
|
|
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) ,
|
|
mensajes STRING,
|
|
idex1,idx2 VARCHAR(50)
|
|
|
|
DEFINE ventas RECORD
|
|
mes,
|
|
moneda VARCHAR(50),
|
|
bruto,
|
|
devolucion,neto DEC(12,2),
|
|
numero_mes SMALLINT
|
|
END RECORD
|
|
DEFINE
|
|
salida,titulomes CHAR(50),
|
|
gastos_totales,ventas_totales DEC(12,2)
|
|
|
|
|
|
|
|
|
|
#### Pide los parametros para busqueda de informacion
|
|
LET rutafile ='.\\FILES\\'
|
|
|
|
#SELECT a.fecha_inicio INTO fecha_inicial FROM prdtable a
|
|
#WHERE a.ano =YEAR(today) AND a.mes = MONTH(today)
|
|
LET ano = YEAR(TODAY)
|
|
LET mes = MONTH(TODAY)
|
|
SELECT a.fecha_inicio,a.fecha_corte INTO fecha_inicial,fecha_final FROM prdtable a
|
|
WHERE a.ano =ano AND a.mes = mes
|
|
#LET mes = 1
|
|
SELECT a.descrip INTO titulomes FROM mestable a WHERE a.mes = mes
|
|
# Buscando Pilas vendidas del ano actual
|
|
|
|
IF pusuario IS NULL THEN
|
|
LET selec =
|
|
"
|
|
select a.mes, a.moneda,sum(a.neto),'0','0',a.numero_mes,a.idventas from ventas_facturas a
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='VENTAS' AND a.clase not in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,a.numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, a.moneda,'0',SUM(a.neto),'0',a.numero_mes,a.idventas from ventas_facturas a
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='NOTAS CREDITOS' AND a.clase not in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, RTRIM(a.moneda)+' '+'AGREGADOS',sum(a.neto),'0','0',a.numero_mes,a.idventas from ventas_facturas a
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='VENTAS' AND a.clase in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,a.numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, RTRIM(a.moneda)+' '+'AGREGADOS','0',SUM(a.neto),'0',a.numero_mes,a.idventas from ventas_facturas a
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='NOTAS CREDITOS' AND a.clase in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,numero_mes,a.moneda
|
|
order by a.numero_mes,a.idventas
|
|
"
|
|
ELSE
|
|
LET selec =
|
|
"select a.mes, a.moneda,sum(a.neto),'0','0',a.numero_mes,a.idventas from ventas_facturas a,seg0007 b
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='VENTAS' and
|
|
b.usuario = ? AND a.codigovendedor = b.sec_vend AND a.clase NOT in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,a.numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, a.moneda,'0',SUM(a.neto),'0',a.numero_mes,a.idventas from ventas_facturas a,seg0007 b
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='NOTAS CREDITOS' and
|
|
b.usuario = ? AND a.codigovendedor = b.sec_vend AND a.clase NOT in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, a.moneda,sum(a.neto),'0','0',a.numero_mes,a.idventas from ventas_facturas a,seg0007 b
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='VENTAS' and
|
|
b.usuario = ? AND a.codigovendedor = b.sec_vend AND a.clase in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,a.numero_mes,a.moneda
|
|
UNION
|
|
select a.mes, a.moneda,'0',SUM(a.neto),'0',a.numero_mes,a.idventas from ventas_facturas a,seg0007 b
|
|
where a.ano = ? and a.numero_mes <= ? and a.tipotransaccion='NOTAS CREDITOS' and
|
|
b.usuario = ? AND a.codigovendedor = b.sec_vend AND a.clase in ('AGREGADO','MATERIAL SIN PROCESAR')
|
|
group by a.mes, a.idventas,numero_mes,a.moneda
|
|
order by a.numero_mes,a.idventas
|
|
"
|
|
END IF
|
|
|
|
|
|
PREPARE busca_act FROM selec
|
|
DECLARE act2 SCROLL CURSOR FOR busca_act
|
|
|
|
IF pusuario IS NULL THEN
|
|
OPEN act2 USING ano,mes,ano,mes,ano,mes,ano,mes
|
|
ELSE
|
|
OPEN act2 USING ano,mes,pusuario,ano,mes,pusuario,ano,mes,pusuario,ano,mes,pusuario
|
|
END IF
|
|
LET salida = "ventas_mes.4rp"
|
|
|
|
IF NOT fgl_report_loadCurrentSettings(salida) THEN
|
|
EXIT PROGRAM
|
|
END IF
|
|
|
|
CALL fgl_report_selectDevice("PDF")
|
|
CALL fgl_report_selectPreview(FALSE)
|
|
|
|
|
|
LET attachment = rutafile CLIPPED,'ventasmes.pdf'
|
|
|
|
CALL fgl_report_setOutputFileName(attachment)
|
|
|
|
{ CALL fgl_report_configureXLSXDevice (
|
|
NULL, #fromPage INTEGER,
|
|
NULL, #toPage INTEGER,
|
|
TRUE, #removeWhitespace BOOLEAN,
|
|
NULL, #ignoreRowAlignment BOOLEAN,
|
|
NULL, #ignoreColumnAlignment BOOLEAN,
|
|
NULL, #removeBackgroundImages BOOLEAN,
|
|
TRUE ) #mergePages TRUE
|
|
}
|
|
LET handler = fgl_report_commitCurrentSettings()
|
|
|
|
START REPORT ventasmes TO XML HANDLER HANDLER
|
|
|
|
|
|
FOREACH act2 INTO ventas.*
|
|
LET idex1 = ventas.numero_mes CLIPPED
|
|
LET idx2 = ventas.numero_mes USING "<<<","-", ventas.moneda CLIPPED
|
|
LET ventas.devolucion = ventas.devolucion * -1
|
|
LET ventas.neto = ventas.bruto - ventas.devolucion
|
|
|
|
OUTPUT TO REPORT ventasmes(ventas.*,idex1,idx2)
|
|
END FOREACH
|
|
|
|
FINISH REPORT ventasmes
|
|
#LET toEmail = 'jsoto@marmotech.com.do'
|
|
LET xusername ='notificacion@marmotech.com.do'
|
|
LET xsmtphost ='smtp.office365.com'
|
|
LET xsmtpport = '587'
|
|
LET xpassword = 'Lmmjvsd2020'
|
|
|
|
LET subject = 'VENTAS DIARIAS Y ACUMULADAS HASTA EL MES DE ',titulomes CLIPPED," DEL PERIODO ",ano USING "<<<<<",
|
|
" ",etiqueta CLIPPED
|
|
LET cuerpo_correo="<!DOCTYPE html><body>", "<h1>FAVOR DE ABRIR EL DOCUMENTO ATADO A ESTE EMAIL ",
|
|
"</h1>div>Todos los valores estan en RD$</h1></div></body>"
|
|
# DISPLAY "attachment ",attachment
|
|
CALL enviaemail(toEmail,subject,cuerpo_correo,attachment,xusername,xsmtphost,xsmtpport,xpassword) #RETURNING mensajes
|
|
|
|
END FUNCTION
|
|
|
|
|
|
REPORT ventasmes(x,clave1,clave2)
|
|
|
|
DEFINE x RECORD
|
|
mes,
|
|
|
|
moneda VARCHAR(50),
|
|
bruto,
|
|
devolucion,neto DEC(12,2),
|
|
numero_mes SMALLINT
|
|
END RECORD,
|
|
clave1,clave2 VARCHAR(50)
|
|
|
|
|
|
DEFINE ventas_brutas,devoluciones,neto,tventas_brutas,tdevoluciones,tneto,ttventas_brutas,ttdevoluciones,ttneto
|
|
DECIMAL(12,2)
|
|
|
|
|
|
FORMAT
|
|
FIRST PAGE HEADER
|
|
|
|
PRINTX p_companias.nombre,nombreusuario
|
|
BEFORE GROUP OF clave1
|
|
PRINTX x.mes
|
|
AFTER GROUP OF clave1
|
|
LET tventas_brutas = GROUP SUM(x.bruto)
|
|
LET tdevoluciones = GROUP SUM(x.devolucion)
|
|
LET tneto = GROUP SUM(x.neto)
|
|
|
|
PRINTX tventas_brutas, tdevoluciones,tneto
|
|
AFTER GROUP OF clave2
|
|
|
|
LET ventas_brutas = GROUP SUM(x.bruto)
|
|
LET devoluciones = GROUP SUM(x.devolucion)
|
|
LET neto = GROUP SUM(x.neto)
|
|
PRINTX x.moneda,ventas_brutas,devoluciones,neto
|
|
|
|
ON LAST ROW
|
|
LET ttventas_brutas = SUM(x.bruto)
|
|
LET ttdevoluciones = SUM(x.devolucion)
|
|
LET ttneto = SUM(x.neto)
|
|
|
|
PRINTX ttventas_brutas,ttdevoluciones,ttneto
|
|
END REPORT
|