233 lines
11 KiB
Plaintext
233 lines
11 KiB
Plaintext
{
|
|
-------------------------------------------------------------------------------
|
|
PROGRAMA : VEPRRP050
|
|
OBJETIVO : Ventas por vendedor/Devoluciones
|
|
PROGRAMADOR : Valentin Rodriguez
|
|
FECHA REALIZACION :
|
|
-------------------------------------------------------------------------------
|
|
}
|
|
|
|
SCHEMA "smarmotech"
|
|
GLOBALS
|
|
DEFINE datos RECORD
|
|
fecha_inicial DATE,
|
|
fecha_final DATE,
|
|
modo_plantilla char(1)
|
|
END RECORD,
|
|
usuarios VARCHAR(20),
|
|
clave VARCHAR(20),
|
|
selec STRING,
|
|
pcompanias RECORD LIKE companias.*,
|
|
idx INT,
|
|
valorCot,
|
|
montoFac FLOAT
|
|
|
|
DEFINE reporteCot RECORD
|
|
vendedor LIKE seg0000.nombre,
|
|
sec_vend LIKE seg0000.sec_vend,
|
|
equipo LIKE seg0008.nombre,
|
|
cotizacion_no LIKE vetb00050.cotizacion_no,
|
|
num_oc LIKE prtb00012.num_oc,
|
|
factura LIKE vetb00002.factura,
|
|
producto LIKE vetb00051.descripcion,
|
|
tasa LIKE cgtb00084.tasa,
|
|
cantidad_cotizada LIKE vetb00051.cantidad,
|
|
precio_cotizado LIKE vetb00051.precio,
|
|
descuento LIKE vetb00051.porc_desc,
|
|
cantidad_ordenada LIKE prtb00013.cantidad,
|
|
cantidad_facturada LIKE vetb00003.cantidad,
|
|
precio_facturado LIKE vetb00003.precio
|
|
END RECORD
|
|
END GLOBALS
|
|
|
|
MAIN
|
|
DEFER INTERRUPT
|
|
CALL ARG_VAL(1) RETURNING usuarios
|
|
CALL ARG_VAL(2) RETURNING clave
|
|
CONNECT TO "smarmotech" USER usuarios USING clave
|
|
CALL ventas_report()
|
|
END MAIN
|
|
|
|
FUNCTION ventas_report ()
|
|
|
|
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
|
|
criterio STRING
|
|
|
|
OPEN WINDOW HOME_FRM WITH FORM 'vefmrp053'
|
|
DIALOG ATTRIBUTE(UNBUFFERED)
|
|
INPUT BY NAME datos.*
|
|
AFTER FIELD fecha_inicial
|
|
IF datos.fecha_inicial IS NULL THEN
|
|
CALL fgl_winmessage("INFO", "FECHA INICIAL NO PUEDE SER EN BLANCO", "INFO")
|
|
NEXT FIELD fecha_inicial
|
|
END IF
|
|
|
|
AFTER FIELD fecha_final
|
|
IF datos.fecha_final IS NULL THEN
|
|
CALL fgl_winmessage("INFO", "FECHA FINAL NO PUEDE SER EN BLANCO", "INFO")
|
|
NEXT FIELD fecha_final
|
|
END IF
|
|
IF datos.fecha_final < datos.fecha_inicial THEN
|
|
CALL fgl_winmessage("INFO", "FECHA FINAL NO PUEDE SER MENOR A FECHA INICIAL", "INFO")
|
|
NEXT FIELD fecha_final
|
|
END IF
|
|
|
|
END INPUT
|
|
CONSTRUCT criterio ON b.cod_n, b.cod_grupo, b.cod_tipo, b.cod_sec,
|
|
a.cotizacion_no, c.num_oc, g.depto, c.sec_vend
|
|
FROM cod_n,cod_grupo,cod_tipo,cod_sec, cotizacion_no, num_oc, equipos, kvendedor
|
|
BEFORE CONSTRUCT
|
|
CALL cequipos()
|
|
CALL cvendedor(usuarios)
|
|
ON ACTION mostrar
|
|
LET selec = " select g.nombre, g.sec_vend, h.nombre, a.cotizacion_no, c.num_oc, e.factura,
|
|
'('+cast(b.cod_n as varchar(5))+'-'+cast(b.cod_grupo as varchar(5))+'-'+cast(b.cod_tipo as varchar(5))+'-'+cast(b.cod_sec as varchar(5))+')'+' '+ ISNULL(b.descripcion,' '),
|
|
i.tasa, b.cantidad, b.precio, b.porc_desc, d.cantidad, f.cantidad, f.precio
|
|
from vetb00050 a
|
|
inner join vetb00051 b on a.cotizacion_no = b.cotizacion_no and a.status_t is null and b.status_t is null
|
|
inner join prtb00012 c on a.cotizacion_no = c.cotizacion_no and c.status_t is null
|
|
inner join prtb00013 d on c.num_oc = d.num_oc and b.cod_n = d.cod_n and b.cod_grupo = d.cod_grupo and b.cod_tipo = d.cod_tipo and b.cod_sec = d.cod_sec and d.status_t is null
|
|
left join vetb00002 e on a.cotizacion_no = e.cotizacion_no and a.tipo_cliente = e.tipo_cliente and a.sec_cliente = e.sec_cliente and e.status_t is null
|
|
inner join vetb00003 f on e.factura = f.factura and b.cod_n = f.cod_n and b.cod_sec = f.cod_sec and b.cod_tipo = f.cod_tipo and b.cod_sec = f.cod_sec and f.status_t is null
|
|
inner join seg0000 g on c.sec_vend = g.sec_vend
|
|
inner join seg0008 h on g.depto = h.depto
|
|
inner join cgtb00084 i on a.tipo_cliente = i.tipo_cliente and a.ventas = i.ventas
|
|
inner join prdtable j on i.mes = j.mes and i.ano = j.ano
|
|
where " , criterio CLIPPED, " and ","
|
|
a.fech_crea between '", datos.fecha_inicial USING "mm/dd/yyyy" , "' and '",datos.fecha_final USING "mm/dd/yyyy","' and
|
|
i.ano between year('", datos.fecha_inicial USING "mm/dd/yyyy" ,"') and year('", datos.fecha_final USING "mm/dd/yyyy" ,"') and
|
|
i.mes between month('", datos.fecha_inicial USING "mm/dd/yyyy" ,"') and month('", datos.fecha_final USING "mm/dd/yyyy" ,"') and
|
|
c.fecha_oc BETWEEN j.fecha_inicio AND j.fecha_corte and
|
|
a.status_t is null"
|
|
|
|
PREPARE comando FROM selec
|
|
DECLARE cotizaciones CURSOR FOR comando
|
|
|
|
LET r_filename ="veprrp053.4rp"
|
|
LET idx = 1
|
|
|
|
FOREACH cotizaciones INTO reporteCot.*
|
|
|
|
LET valorCot = ((reporteCot.precio_cotizado - ((reporteCot.precio_cotizado * reporteCot.descuento)/100)) * reporteCot.tasa) * reporteCot.cantidad_cotizada
|
|
LET montoFac = ((reporteCot.precio_facturado - ((reporteCot.precio_facturado * reporteCot.descuento)/100)) * reporteCot.tasa) * reporteCot.cantidad_facturada
|
|
|
|
IF idx = 1 THEN
|
|
IF fgl_report_loadCurrentSettings(r_filename) THEN
|
|
|
|
LET preview=1
|
|
CALL seleccionarsalida() RETURNING r_output -- 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
|
|
ELSE
|
|
CALL fgl_winmessage("INFO", "NO HAY REGISTROS EN ESTE RANGO DE FECHA Y CON LOS PARAMETROS INDICADOS", "INFO")
|
|
NEXT FIELD fecha_final
|
|
END IF
|
|
LET idx = 2
|
|
|
|
START REPORT reporteCot_rpt TO XML HANDLER HANDLER
|
|
|
|
END IF
|
|
|
|
OUTPUT TO REPORT reporteCot_rpt(reporteCot.*, datos.*, valorCot, montoFac)
|
|
|
|
END FOREACH
|
|
|
|
IF idx > 1 THEN
|
|
FINISH REPORT reporteCot_rpt
|
|
END IF
|
|
END CONSTRUCT
|
|
|
|
ON ACTION CANCEL
|
|
CALL msg(2)
|
|
LET INT_FLAG = FALSE
|
|
EXIT PROGRAM
|
|
END DIALOG
|
|
CLOSE WINDOW HOME_FRM
|
|
END FUNCTION
|
|
|
|
REPORT reporteCot_rpt(x,y, vCot, Mcot)
|
|
DEFINE x RECORD
|
|
vendedor LIKE seg0000.nombre,
|
|
sec_vend LIKE seg0000.sec_vend,
|
|
equipo LIKE seg0008.nombre,
|
|
cotizacion_no LIKE vetb00050.cotizacion_no,
|
|
num_oc LIKE prtb00012.num_oc,
|
|
factura LIKE vetb00002.factura,
|
|
producto LIKE vetb00051.descripcion,
|
|
tasa LIKE cgtb00084.tasa,
|
|
cantidad_cotizada LIKE vetb00051.cantidad,
|
|
precio_cotizado LIKE vetb00051.precio,
|
|
descuento LIKE vetb00051.porc_desc,
|
|
cantidad_ordenada LIKE prtb00013.cantidad,
|
|
cantidad_facturada LIKE vetb00003.cantidad,
|
|
precio_facturado LIKE vetb00003.precio
|
|
END RECORD
|
|
|
|
DEFINE y RECORD
|
|
fecha_inicial DATE,
|
|
fecha_final DATE,
|
|
modo_plantilla char(1)
|
|
END RECORD,
|
|
fecha_reporte char(30),
|
|
fecha char(30),
|
|
nombre_vend varchar(40),
|
|
|
|
--VARIABLES TOTAL POR CADA VENDEDOR
|
|
totalCanCotVendor,
|
|
totalValCotVendor,
|
|
totalCanOrdVendor,
|
|
totalCanFacVendor,
|
|
totalMonFacVendor,
|
|
|
|
--VARIABLES TOTAL GENERAL POR VENDEDOR
|
|
totalGenCanCotVendor,
|
|
totalGenValCotVendor,
|
|
totalGenCanOrdVendor,
|
|
totalGenCanFacVendor,
|
|
totalGenMonFacVendor,
|
|
vCot,
|
|
mCot FLOAT
|
|
|
|
FORMAT
|
|
BEFORE GROUP OF x.vendedor
|
|
LET totalCanCotVendor = 0
|
|
LET totalValCotVendor = 0
|
|
LET totalCanOrdVendor = 0
|
|
LET totalMonFacVendor = 0
|
|
|
|
PRINTX x.vendedor
|
|
|
|
ON EVERY ROW
|
|
LET fecha_reporte = today USING "mm/dd/yyyy"
|
|
LET fecha = y.fecha_inicial USING "mm/dd/yyyy",'--',y.fecha_final USING "mm/dd/yyyy"
|
|
LET nombre_vend = '(',x.sec_vend,')',x.vendedor
|
|
|
|
PRINTX x.cotizacion_no, x.num_oc, x.factura, x.producto, x.cantidad_cotizada, vCot,
|
|
x.cantidad_ordenada, x.cantidad_facturada, Mcot, fecha,
|
|
fecha_reporte, pcompanias.nombre, y.modo_plantilla, nombre_vend
|
|
|
|
AFTER GROUP OF x.vendedor
|
|
LET totalCanCotVendor = GROUP SUM(x.cantidad_cotizada)
|
|
LET totalValCotVendor = GROUP SUM(vCot)
|
|
LET totalCanOrdVendor = GROUP SUM(x.cantidad_ordenada)
|
|
LET totalCanFacVendor = GROUP SUM(x.cantidad_facturada)
|
|
LET totalMonFacVendor = GROUP SUM(mCot)
|
|
|
|
PRINTX totalCanCotVendor, totalValCotVendor, totalCanOrdVendor,
|
|
totalCanFacVendor, totalMonFacVendor
|
|
ON LAST ROW
|
|
LET totalGenCanCotVendor = SUM(x.cantidad_cotizada)
|
|
LET totalGenValCotVendor = SUM(vCot)
|
|
LET totalGenCanOrdVendor = SUM(x.cantidad_ordenada)
|
|
LET totalGenCanFacVendor = SUM(x.cantidad_facturada)
|
|
LET totalGenMonFacVendor = SUM(mCot)
|
|
|
|
PRINTX totalGenCanCotVendor, totalGenValCotVendor,
|
|
totalGenCanOrdVendor, totalGenCanFacVendor,
|
|
totalGenMonFacVendor
|
|
|
|
END REPORT |