332 lines
13 KiB
Plaintext
332 lines
13 KiB
Plaintext
{=======================================================
|
|
FUNCION : Reporte de costos de instalciones por mes
|
|
OBJETIVO : ***************************
|
|
PROGRAMADOR : Valentin Rodriguez
|
|
FECHA : Mayo, 2019
|
|
========================================================}
|
|
SCHEMA "smarmotech"
|
|
GLOBALS "prprgb000.4gl"
|
|
|
|
DEFINE datos RECORD
|
|
f_inicial DATE,
|
|
f_final DATE
|
|
END RECORD,
|
|
pcompanias RECORD LIKE companias.*
|
|
|
|
DEFINE instalacion RECORD
|
|
descripcion VARCHAR(50),
|
|
descrip_esp VARCHAR(70),
|
|
cliente VARCHAR(100),
|
|
orden INT,
|
|
cod_n LIKE iptb00006.cod_n,
|
|
cod_grupo LIKE iptb00006.cod_grupo,
|
|
cod_tipo LIKE iptb00006.cod_tipo,
|
|
cod_sec LIKE iptb00006.cod_sec,
|
|
fecha CHAR(2),
|
|
costo LIKE vetb00003.precio
|
|
END RECORD
|
|
|
|
MAIN
|
|
DEFER INTERRUPT
|
|
CALL ARG_VAL(1) RETURNING usuarios
|
|
CALL ARG_VAL(2) RETURNING clave
|
|
CONNECT TO "smarmotech" USER usuarios USING clave
|
|
SELECT * INTO pcompanias.* FROM companias
|
|
CALL costoInstalaciones()
|
|
END MAIN
|
|
|
|
FUNCTION costoInstalaciones()
|
|
|
|
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
|
|
|
|
DEFINE hoy DATE
|
|
|
|
OPEN WINDOW HOME_FRM WITH FORM 'prfmrp118'
|
|
DIALOG ATTRIBUTE(UNBUFFERED)
|
|
INPUT BY NAME datos.*
|
|
|
|
AFTER FIELD f_final
|
|
IF datos.f_inicial IS NULL AND DATOS.f_final IS NOT NULL THEN
|
|
CALL fgl_winmessage("INFO", "SI ESPECIFICA UN RANGO DE FECHA DEBE INDICAR FECHA INICIAL", "INFO")
|
|
NEXT FIELD f_inicial
|
|
END IF
|
|
|
|
IF datos.f_final < datos.f_inicial THEN
|
|
CALL fgl_winmessage("INFO", "LA FECHA FINAL DEBE SER MAS RECIENTE A LA INICIAL", "INFO")
|
|
NEXT FIELD f_final
|
|
END IF
|
|
|
|
AFTER INPUT
|
|
--ON ACTION mostrar
|
|
LET hoy = TODAY
|
|
LET selec = "select d.descripcion,b.descrip_esp,rtrim(f.nombre)+' '+'('+ cast(f.tipo_cliente as varchar(5)) + cast(f.sec_cliente as varchar(5))+')',
|
|
e.orden, a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,month(e.fecha_factura),sum(a.cantidad * precio)
|
|
from vetb00003 a
|
|
inner join iptb00002 b on 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
|
|
inner join iptb00035 c on b.cod_n = c.cod_n
|
|
inner join iptb00034 d on d.cod_categoria = c.cod_cat
|
|
inner join vetb00002 e on e.factura = a.factura
|
|
inner join vetb00004 f on e.tipo_cliente = f.tipo_cliente and e.sec_cliente = f.sec_cliente
|
|
where e.fecha_factura between '", datos.f_inicial USING "mm/dd/yyyy" ,"'", " and '", datos.f_final USING "mm/dd/yyyy","'","
|
|
and a.cod_n = '12' and a.status_t is null
|
|
group by d.descripcion,b.descrip_esp,f.nombre,f.tipo_cliente, f.sec_cliente, e.orden,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,month(e.fecha_factura)
|
|
order by d.descripcion, b.descrip_esp,e.orden,month(e.fecha_factura)"
|
|
DISPLAY selec
|
|
PREPARE comando FROM selec
|
|
DECLARE costos CURSOR FOR comando
|
|
|
|
LET r_filename ="prprrp118.4rp"
|
|
LET idx = 1
|
|
|
|
FOREACH costos INTO instalacion.*
|
|
|
|
IF idx = 1 THEN
|
|
IF fgl_report_loadCurrentSettings(r_filename) THEN -- load the .4rp file
|
|
|
|
LET preview=1
|
|
CALL seleccionarsalida() RETURNING r_output
|
|
CALL fgl_report_selectDevice(r_output) -- changing default
|
|
CALL fgl_report_selectPreview(preview) -- changing default
|
|
LET handler = fgl_report_commitCurrentSettings() -- commit changes
|
|
|
|
END IF
|
|
LET idx = 2
|
|
|
|
START REPORT instalacion_rpt TO XML HANDLER HANDLER
|
|
END IF
|
|
|
|
OUTPUT TO REPORT instalacion_rpt(instalacion.*)
|
|
END FOREACH
|
|
|
|
IF idx > 1 THEN
|
|
FINISH REPORT instalacion_rpt
|
|
ELSE
|
|
CALL fgl_winmessage("INFO", "NO HAY REGISTROS EN ESTE RANGO DE FECHA Y CON LOS PARAMETROS INDICADOS", "INFO")
|
|
NEXT FIELD f_final
|
|
END IF
|
|
END INPUT
|
|
|
|
ON ACTION CANCEL
|
|
CALL msg(2)
|
|
LET INT_FLAG = FALSE
|
|
EXIT PROGRAM
|
|
END DIALOG
|
|
CLOSE WINDOW HOME_FRM
|
|
END FUNCTION
|
|
|
|
REPORT instalacion_rpt(x)
|
|
|
|
DEFINE x RECORD
|
|
descripcion VARCHAR(50),
|
|
descrip_esp VARCHAR(70),
|
|
cliente VARCHAR(100),
|
|
orden INT,
|
|
cod_n LIKE iptb00006.cod_n,
|
|
cod_grupo LIKE iptb00006.cod_grupo,
|
|
cod_tipo LIKE iptb00006.cod_tipo,
|
|
cod_sec LIKE iptb00006.cod_sec,
|
|
fecha CHAR(2),
|
|
costo LIKE vetb00003.precio
|
|
END RECORD
|
|
|
|
DEFINE y RECORD
|
|
f_inicial DATE,
|
|
f_final DATE
|
|
END RECORD
|
|
|
|
DEFINE rangoFecha CHAR(30)
|
|
DEFINE fecha_reporte CHAR(15)
|
|
DEFINE orden INT
|
|
|
|
DEFINE enero,febrero,marzo,abril,mayo,junio,julio,agosto,
|
|
septiembre,octubre, noviembre,diciembre,total_reg DECIMAL(12,2)
|
|
|
|
DEFINE t_d_enero,t_d_febrero,t_d_marzo,t_d_abril,t_d_mayo,t_d_junio,
|
|
t_d_julio,t_d_agosto,t_d_septiembre,t_d_octubre,t_d_noviembre,
|
|
t_d_diciembre DECIMAL(12,2)
|
|
|
|
DEFINE t_t_d_enero,t_t_d_febrero,t_t_d_marzo,t_t_d_abril,t_t_d_mayo,
|
|
t_t_d_junio,t_t_d_julio,t_t_d_agosto,t_t_d_septiembre,t_t_d_octubre,
|
|
t_t_d_noviembre,t_t_d_diciembre DECIMAL(12,2)
|
|
|
|
DEFINE t_g_d_enero,t_g_d_febrero,t_g_d_marzo,t_g_d_abril,t_g_d_mayo,
|
|
t_g_d_junio,t_g_d_julio,t_g_d_agosto,t_g_d_septiembre,t_g_d_octubre,
|
|
t_g_d_noviembre,t_g_d_diciembre DECIMAL(12,2)
|
|
|
|
--ORDER BY x.orden
|
|
FORMAT
|
|
PAGE HEADER
|
|
LET rangoFecha = "Del ", y.f_inicial," al ", y.f_final CLIPPED
|
|
LET fecha_reporte = TODAY
|
|
|
|
--PRINTX pcompanias.nombre,rangoFecha,fecha_reporte
|
|
|
|
BEFORE GROUP OF x.descripcion
|
|
LET t_t_d_enero = 0
|
|
LET t_t_d_febrero = 0
|
|
LET t_t_d_marzo = 0
|
|
LET t_t_d_abril = 0
|
|
LET t_t_d_mayo = 0
|
|
LET t_t_d_junio = 0
|
|
LET t_t_d_julio = 0
|
|
LET t_t_d_agosto = 0
|
|
LET t_t_d_septiembre = 0
|
|
LET t_t_d_octubre = 0
|
|
LET t_t_d_noviembre = 0
|
|
LET t_t_d_diciembre = 0
|
|
|
|
PRINTX x.descripcion
|
|
|
|
BEFORE GROUP OF x.descrip_esp
|
|
LET t_d_enero = 0
|
|
LET t_d_febrero = 0
|
|
LET t_d_marzo = 0
|
|
LET t_d_abril = 0
|
|
LET t_d_mayo = 0
|
|
LET t_d_junio = 0
|
|
LET t_d_julio = 0
|
|
LET t_d_agosto = 0
|
|
LET t_d_septiembre = 0
|
|
LET t_d_octubre = 0
|
|
LET t_d_noviembre = 0
|
|
LET t_d_diciembre = 0
|
|
|
|
PRINTX x.descrip_esp
|
|
|
|
ON EVERY ROW
|
|
LET enero = 0
|
|
LET febrero = 0
|
|
LET marzo = 0
|
|
LET abril = 0
|
|
LET mayo = 0
|
|
LET junio = 0
|
|
LET julio = 0
|
|
LET agosto = 0
|
|
LET septiembre = 0
|
|
LET octubre = 0
|
|
LET noviembre = 0
|
|
LET diciembre = 0
|
|
LET total_reg = 0
|
|
LET orden = ''
|
|
|
|
CASE x.fecha
|
|
WHEN '1'
|
|
LET enero = x.costo
|
|
LET t_d_enero = t_d_enero + enero
|
|
LET t_t_d_enero = t_t_d_enero + enero
|
|
WHEN '2'
|
|
LET febrero = x.costo
|
|
LET t_d_febrero = t_d_febrero + febrero
|
|
LET t_t_d_febrero = t_t_d_febrero + febrero
|
|
WHEN '3'
|
|
LET marzo = x.costo
|
|
LET t_d_marzo = t_d_marzo + marzo
|
|
LET t_t_d_marzo = t_t_d_marzo + marzo
|
|
WHEN '4'
|
|
LET abril = x.costo
|
|
LET t_d_abril = t_d_abril + abril
|
|
LET t_t_d_abril = t_t_d_abril + abril
|
|
WHEN '5'
|
|
LET mayo = x.costo
|
|
LET t_d_mayo = t_d_mayo + mayo
|
|
LET t_t_d_mayo = t_t_d_mayo + mayo
|
|
WHEN '6'
|
|
LET junio = x.costo
|
|
LET t_d_junio = t_d_junio + junio
|
|
LET t_t_d_junio = t_t_d_junio + junio
|
|
WHEN '7'
|
|
LET julio = x.costo
|
|
LET t_d_julio = t_d_julio + julio
|
|
LET t_t_d_julio = t_t_d_julio + julio
|
|
WHEN '8'
|
|
LET agosto = x.costo
|
|
LET t_d_agosto = t_d_agosto + agosto
|
|
LET t_t_d_agosto = t_t_d_agosto + agosto
|
|
WHEN '9'
|
|
LET septiembre = x.costo
|
|
LET t_d_septiembre = t_d_septiembre + septiembre
|
|
LET t_t_d_septiembre = t_t_d_septiembre + septiembre
|
|
WHEN '10'
|
|
LET octubre = x.costo
|
|
LET t_d_octubre = t_d_octubre + octubre
|
|
LET t_t_d_octubre = t_t_d_octubre + octubre
|
|
WHEN '11'
|
|
LET noviembre = x.costo
|
|
LET t_d_noviembre = t_d_noviembre + noviembre
|
|
LET t_t_d_noviembre = t_t_d_noviembre + noviembre
|
|
WHEN '12'
|
|
LET diciembre = x.costo
|
|
LET t_d_diciembre = t_d_diciembre + t_d_diciembre
|
|
LET t_t_d_diciembre = t_t_d_diciembre + diciembre
|
|
END CASE
|
|
|
|
LET total_reg = x.costo
|
|
|
|
PRINTX x.fecha,pcompanias.nombre,rangoFecha,fecha_reporte,
|
|
x.orden, enero,febrero,marzo,abril,mayo,junio,julio,
|
|
agosto, septiembre,octubre,noviembre,diciembre,total_reg,
|
|
x.cliente
|
|
|
|
AFTER GROUP OF x.descrip_esp
|
|
|
|
--LET t_d_enero = GROUP SUM(enero)
|
|
--LET t_d_febrero = GROUP SUM(febrero)
|
|
--LET t_d_marzo = GROUP SUM(marzo)
|
|
--LET t_d_abril = GROUP SUM(abril)
|
|
--LET t_d_mayo = GROUP SUM(mayo)
|
|
--LET t_d_junio = GROUP SUM(junio)
|
|
--LET t_d_julio = GROUP SUM(julio)
|
|
--LET t_d_agosto = GROUP SUM(agosto)
|
|
--LET t_d_septiembre = GROUP SUM(septiembre)
|
|
--LET t_d_octubre = GROUP SUM(octubre)
|
|
--LET t_d_noviembre = GROUP SUM(noviembre)
|
|
--LET t_d_diciembre = GROUP SUM(diciembre)
|
|
|
|
PRINTX t_d_enero,t_d_febrero,t_d_marzo,t_d_abril,t_d_mayo,
|
|
t_d_junio,t_d_julio,t_d_agosto,t_d_septiembre,
|
|
t_d_octubre,t_d_noviembre,t_d_diciembre
|
|
|
|
AFTER GROUP OF x.descripcion
|
|
|
|
--LET t_t_d_enero = GROUP SUM(enero)
|
|
--LET t_t_d_febrero = GROUP SUM(febrero)
|
|
--LET t_t_d_marzo = GROUP SUM(marzo)
|
|
--LET t_t_d_abril = GROUP SUM(abril)
|
|
--LET t_t_d_mayo = GROUP SUM(mayo)
|
|
--LET t_t_d_junio = GROUP SUM(junio)
|
|
--LET t_t_d_julio = GROUP SUM(julio)
|
|
--LET t_t_d_agosto = GROUP SUM(agosto)
|
|
--LET t_t_d_septiembre = GROUP SUM(septiembre)
|
|
--LET t_t_d_octubre = GROUP SUM(octubre)
|
|
--LET t_t_d_noviembre = GROUP SUM(noviembre)
|
|
--LET t_t_d_diciembre = GROUP SUM(diciembre)
|
|
|
|
PRINTX t_t_d_enero,t_t_d_febrero,t_t_d_marzo,t_t_d_abril,t_t_d_mayo,
|
|
t_t_d_junio,t_t_d_julio,t_t_d_agosto,t_t_d_septiembre,
|
|
t_t_d_octubre,t_t_d_noviembre,t_t_d_diciembre
|
|
|
|
ON LAST ROW
|
|
|
|
LET t_g_d_enero = SUM(enero)
|
|
LET t_g_d_febrero = SUM(febrero)
|
|
LET t_g_d_marzo = SUM(marzo)
|
|
LET t_g_d_abril = SUM(abril)
|
|
LET t_g_d_mayo = SUM(mayo)
|
|
LET t_g_d_junio = SUM(junio)
|
|
LET t_g_d_julio = SUM(julio)
|
|
LET t_g_d_agosto = SUM(agosto)
|
|
LET t_g_d_septiembre = SUM(septiembre)
|
|
LET t_g_d_octubre = SUM(octubre)
|
|
LET t_g_d_noviembre = SUM(noviembre)
|
|
LET t_g_d_diciembre = SUM(diciembre)
|
|
|
|
PRINTX t_g_d_enero,t_g_d_febrero,t_g_d_marzo,t_g_d_abril,t_g_d_mayo,
|
|
t_g_d_junio,t_g_d_julio,t_g_d_agosto,t_g_d_septiembre,
|
|
t_g_d_octubre,t_g_d_noviembre,t_g_d_diciembre
|
|
END REPORT
|