427 lines
15 KiB
Plaintext
427 lines
15 KiB
Plaintext
{
|
|
=======================================================================
|
|
Programa : GEPRRP010
|
|
Sistema : Sistema de Informacion Gerencia Mayoristas
|
|
Proceso : Clientes con Ventas Mayores a X Cantidad
|
|
Autor : Tadeo A. Ferreras
|
|
Fecha : Junio 21,1993
|
|
=======================================================================
|
|
}
|
|
GLOBALS
|
|
"geprgb000.4gl"
|
|
|
|
DEFINE ger_comp10 RECORD
|
|
tipo_cliente SMALLINT,
|
|
sec_cliente SMALLINT,
|
|
nombre CHAR(30),
|
|
status_t CHAR(1),
|
|
tipo_negocio SMALLINT,
|
|
descripcion CHAR(30),
|
|
nombre_pro LIKE vetb00020.nombre_provincia,
|
|
cantidad2 DECIMAL(14,2),
|
|
cantidad1 DECIMAL(14,2),
|
|
posicion INTEGER,
|
|
devolucion1 DECIMAL(12,2),
|
|
devolucion2 DECIMAL(12,2),
|
|
codigo CHAR(6)
|
|
END RECORD,
|
|
cod1 SMALLINT,
|
|
ventas_dev1,ventas_dev2,ventas_totales1,ventas_totales2 DECIMAL(12,2)
|
|
|
|
DEFINE selec9 CHAR(1000)
|
|
DEFINE salir,salir9,compa CHAR(1)
|
|
DEFINE idx9,idx1,j,m,p,s,s1 INTEGER
|
|
DEFINE ano19 CHAR(4)
|
|
DEFINE ano1,mes1 SMALLINT
|
|
DEFINE nom_mes CHAR(15)
|
|
|
|
DEFINE fecha_in,fecha_fi,fecha_in9,fecha_fi9 DATE,
|
|
cod_cli SMALLINT,
|
|
total2,cantidad1,cantidad2,cantidad3,cantidad4,cantidad5,cantidad6,
|
|
cantidad7,cantidad8,cantida9 DECIMAL(12,2)
|
|
|
|
FUNCTION geprrp010()
|
|
LET int_flag = FALSE
|
|
OPTIONS
|
|
FORM LINE 8
|
|
|
|
OPEN FORM gefmrp009 FROM "gefmrp009"
|
|
DISPLAY FORM gefmrp009
|
|
CALL pantalla()
|
|
DISPLAY "geprrp010" AT 4,3 ATTRIBUTE(RED)
|
|
|
|
DISPLAY "Ranking de Ventas Comparativas Al Ano Anterior Mayoristas" AT 6,11
|
|
ATTRIBUTE(BLACK)
|
|
|
|
LET tipo_papel = 1
|
|
CALL msgrp000(tipo_papel)
|
|
CALL defecto(impresor) RETURNING imprime, letras.*, archivo
|
|
|
|
INPUT BY NAME ano1,mes1,cantidad1
|
|
ON KEY(CONTROL-P)
|
|
CALL busca_printer() RETURNING imprime,letras.*, archivo
|
|
|
|
AFTER FIELD ano1
|
|
IF ano1 IS NULL THEN
|
|
LET numero_msg = 16
|
|
CALL msg(numero_msg)
|
|
NEXT FIELD ano1
|
|
END IF
|
|
|
|
SELECT MIN(fecha_inicio) INTO fecha_in9 FROM prdtable
|
|
WHERE ano = ano1 - 1
|
|
|
|
LET ano19 = ano1 - 1 USING "&&&&"
|
|
|
|
BEFORE FIELD mes1
|
|
LET mes1 = MONTH(today) USING "&&"
|
|
DISPLAY BY NAME mes1
|
|
|
|
AFTER FIELD mes1
|
|
IF mes1 IS NULL THEN
|
|
LET mes1 = MONTH(today) USING "&&"
|
|
END IF
|
|
DISPLAY BY NAME mes1
|
|
|
|
SELECT MIN(fecha_inicio) INTO fecha_in FROM prdtable
|
|
WHERE ano = ano1 #and mes = mes1
|
|
|
|
SELECT fecha_corte INTO fecha_fi FROM prdtable
|
|
WHERE ano = ano1 AND mes = mes1
|
|
|
|
SELECT fecha_corte INTO fecha_fi9 FROM prdtable
|
|
WHERE ano = ano1 - 1 AND mes = mes1
|
|
|
|
SELECT descrip INTO nom_mes FROM mestable
|
|
WHERE mes = mes1
|
|
|
|
# Busca Ventas totales
|
|
SELECT SUM(a.sub_total-a.monto_desc) INTO ventas_totales1
|
|
FROM vetb00002 a
|
|
WHERE a.fecha_factura BETWEEN fecha_in AND fecha_fi AND a.ventas = 1 AND
|
|
a.status_t IS NULL
|
|
|
|
SELECT SUM(a.sub_total-a.monto_desc) INTO ventas_totales2
|
|
FROM vetb00002 a
|
|
WHERE a.fecha_factura BETWEEN fecha_in9 AND fecha_fi9 AND a.ventas = 1 AND
|
|
a.status_t IS NULL
|
|
# Devoluciones
|
|
|
|
SELECT SUM(a.cantidad*a.precio) INTO ventas_dev1
|
|
FROM iptb00023 a
|
|
WHERE a.fecha BETWEEN fecha_in AND fecha_fi AND a.cod_mov = 12 AND
|
|
a.status_t IS NULL
|
|
|
|
|
|
SELECT SUM(a.cantidad*a.precio) INTO ventas_dev2
|
|
FROM iptb00023 a
|
|
WHERE a.fecha BETWEEN fecha_in9 AND fecha_fi9 AND a.cod_mov = 12 AND
|
|
a.status_t IS NULL
|
|
|
|
LET ventas_totales1 = ventas_totales1 - ventas_dev1
|
|
LET ventas_totales2 = ventas_totales2 - ventas_dev2
|
|
|
|
AFTER FIELD cantidad1
|
|
IF cantidad1 IS NULL OR cantidad1 < 0 THEN
|
|
LET numero_msg = 16
|
|
CALL msg(numero_msg)
|
|
NEXT FIELD cantidad1
|
|
END IF
|
|
END INPUT
|
|
|
|
IF int_flag tHEN
|
|
LET numero_msg = 2
|
|
CALL msg(numero_msg)
|
|
LET int_flag = FALSE
|
|
RETURN
|
|
END IF
|
|
|
|
CONSTRUCT BY NAME criterio ON a.tipo_cliente,a.sec_cliente
|
|
IF int_flag tHEN
|
|
LET numero_msg = 2
|
|
CALL msg(numero_msg)
|
|
LET int_flag = FALSE
|
|
RETURN
|
|
END IF
|
|
|
|
|
|
LET selec =
|
|
"SELECT a.tipo_cliente, a.sec_cliente,c.nombre,c.status_t,",
|
|
"d.tipo_negocio, e.descripcion,f.nombre_provincia, ",
|
|
"SUM(a.sub_total-a.monto_desc) ",
|
|
"FROM vetb00002 a,vetb00004 c, cctb00012 d, cctb00013 e,vetb00020 f,vetb00009 h ",
|
|
"WHERE (a.status_t IS NULL) AND (a.fecha_factura BETWEEN ? AND ?) AND ",
|
|
" (a.tipo_cliente= c.tipo_cliente) AND ",
|
|
" (a.sec_cliente = c.sec_cliente) AND ",
|
|
" (a.sec_cliente = d.sec_cliente) AND ",
|
|
" (a.sec_cliente != 51) AND ",
|
|
" (d.tipo_negocio= e.tipo_negocio) ",
|
|
" AND c.cod_zona = h.cod_zona AND c.cod_provincia = h.cod_provincia AND ",
|
|
" c.cod_provincia = f.cod_provincia ",
|
|
"GROUP BY 1,2,3,4,5,6,7 HAVING SUM(a.sub_total-a.monto_desc) >= ? ORDER BY 8 DESC,1,2 "
|
|
|
|
DISPLAY "Buscando Informacion Ano Actual... Espere por Favor" AT 17,14
|
|
ATTRIBUTE(BOLD)
|
|
|
|
PREPARE comando FROM selec
|
|
DECLARE buscar CURSOR FOR comando
|
|
OPEN buscar USING fecha_in,fecha_fi,cantidad1
|
|
|
|
START REPORT gerencia10 TO archivo
|
|
|
|
DISPLAY "Impresion en Proceso..... Espere por Favor " AT 17,14
|
|
|
|
LET idx = 0
|
|
LET salir = "N"
|
|
WHILE salir != "S"
|
|
FETCH buscar INTO ger_comp10.*
|
|
IF STATUS = NOTFOUND THEN
|
|
LET salir = "S"
|
|
EXIT WHILE
|
|
END IF
|
|
|
|
IF int_flag THEN
|
|
LET numero_msg = 2
|
|
CALL msg(numero_msg)
|
|
LET int_flag = FALSE
|
|
RETURN
|
|
END IF
|
|
|
|
LET idx = idx + 1
|
|
LET ger_comp10.posicion = idx
|
|
LET ger_comp10.cantidad1 = 0
|
|
|
|
|
|
SELECT SUM(a.sub_total-a.monto_desc) INTO ger_comp10.cantidad1
|
|
FROM vetb00002 a
|
|
WHERE (a.status_t IS NULL) AND
|
|
(a.fecha_factura BETWEEN fecha_in9 AND fecha_fi9) AND
|
|
(a.tipo_cliente = ger_comp10.tipo_cliente) AND
|
|
(a.sec_cliente=ger_comp10.sec_cliente)
|
|
|
|
SELECT SUM(a.cantidad*a.precio) INTO ger_comp10.devolucion1
|
|
FROM iptb00023 a
|
|
WHERE a.fecha BETWEEN fecha_in9 AND fecha_fi9 AND a.cod_mov = 12 AND
|
|
a.tipo_cliente = ger_comp10.tipo_cliente AND
|
|
a.sec_cliente = ger_comp10.sec_cliente AND
|
|
a.status_t IS NULL
|
|
|
|
SELECT SUM(a.cantidad*a.precio) INTO ger_comp10.devolucion2
|
|
FROM iptb00023 a
|
|
WHERE a.fecha BETWEEN fecha_in AND fecha_fi AND a.cod_mov = 12 AND
|
|
a.tipo_cliente = ger_comp10.tipo_cliente AND
|
|
a.sec_cliente = ger_comp10.sec_cliente AND
|
|
a.status_t IS NULL
|
|
|
|
IF ger_comp10.devolucion1 IS NULL THEN
|
|
LET ger_comp10.devolucion1 = 0
|
|
END IF
|
|
|
|
IF ger_comp10.devolucion2 IS NULL THEN
|
|
LET ger_comp10.devolucion2 = 0
|
|
END IF
|
|
|
|
LET ger_comp10.cantidad1 = ger_comp10.cantidad1 - ger_comp10.devolucion1
|
|
LET ger_comp10.cantidad2 = ger_comp10.cantidad2 - ger_comp10.devolucion2
|
|
|
|
IF ger_comp10.cantidad1 IS NULL THEN
|
|
LET ger_comp10.cantidad1 = 0
|
|
END IF
|
|
|
|
LET ger_comp10.codigo = ger_comp10.tipo_cliente USING "&&",
|
|
ger_comp10.sec_cliente USING "&&&&"
|
|
|
|
OUTPUT TO REPORT gerencia10(ger_comp10.*)
|
|
END WHILE
|
|
|
|
|
|
LET selec =
|
|
"SELECT a.tipo_cliente,a.sec_cliente,c.nombre,c.status_t,'1','N ','N ',SUM(b.total) ",
|
|
"FROM cotb00057 a,vetb00004 c,cotb00056 b ",
|
|
"WHERE (a.status_t IS NULL) AND (a.fecha_factura BETWEEN ? AND ?) AND ",
|
|
" a.factura = b.factura AND ",
|
|
" (a.tipo_cliente = c.tipo_cliente) AND ",criterio CLIPPED,
|
|
" AND (a.sec_cliente = c.sec_cliente) ",
|
|
"GROUP BY 1,2,3,4,5 HAVING SUM(b.total) >= ? ORDER BY 5 DESC,1,2 "
|
|
|
|
PREPARE comando1 FROM selec
|
|
DECLARE buscar1 CURSOR FOR comando1
|
|
OPEN buscar1 USING fecha_in,fecha_fi,cantidad1
|
|
|
|
LET idx = 0
|
|
LET salir = "N"
|
|
WHILE salir != "S"
|
|
FETCH buscar1 INTO ger_comp10.*
|
|
IF STATUS = NOTFOUND THEN
|
|
LET salir = "S"
|
|
EXIT WHILE
|
|
END IF
|
|
|
|
IF int_flag THEN
|
|
LET numero_msg = 2
|
|
CALL msg(numero_msg)
|
|
LET int_flag = FALSE
|
|
RETURN
|
|
END IF
|
|
|
|
LET idx = idx + 1
|
|
LET ger_comp10.posicion = idx
|
|
LET ger_comp10.cantidad1 = 0
|
|
|
|
|
|
IF ger_comp10.cantidad1 IS NULL THEN
|
|
LET ger_comp10.cantidad1 = 0
|
|
END IF
|
|
LET ger_comp10.codigo = ger_comp10.tipo_cliente USING "&&",
|
|
ger_comp10.sec_cliente USING "&&&&"
|
|
OUTPUT TO REPORT gerencia10(ger_comp10.*)
|
|
END WHILE
|
|
|
|
FINISH REPORT gerencia10
|
|
RUN imprime
|
|
END FUNCTION
|
|
|
|
REPORT gerencia10(x)
|
|
|
|
DEFINE x RECORD
|
|
tipo_cliente SMALLINT,
|
|
sec_cliente SMALLINT,
|
|
nombre CHAR(30),
|
|
status_t CHAR(1),
|
|
tipo_negocio SMALLINT,
|
|
descripcion CHAR(30),
|
|
nombre_pro LIKE vetb00020.nombre_provincia,
|
|
cantidad2 DECIMAL(14,2),
|
|
cantidad1 DECIMAL(14,2),
|
|
posicion INTEGER,
|
|
devolucion1 DECIMAL(12,2),
|
|
devolucion2 DECIMAL(12,2),
|
|
codigo CHAR(6)
|
|
END RECORD
|
|
|
|
DEFINE j ARRAY[5000] OF RECORD
|
|
codigo CHAR(7),
|
|
nombre CHAR(30),
|
|
provincia LIKE vetb00020.nombre_provincia,
|
|
status_t CHAR(1),
|
|
descripcion CHAR(30),
|
|
cantidad1 DECIMAL(14,2),
|
|
cantidad2 DECIMAL(14,2),
|
|
posicion1 INTEGER,
|
|
posicion2 INTEGER,
|
|
limite LIKE vetb00004.limite_credito,
|
|
porc1 DECIMAL(12,2),
|
|
porc2 DECIMAL(12,2)
|
|
END RECORD
|
|
|
|
DEFINE mes11,cuenta SMALLINT
|
|
DEFINE nom_mes1 CHAR(15)
|
|
DEFINE descrip,descrip1 CHAR(30)
|
|
DEFINE nombre_sal CHAR(20),
|
|
limite LIKE vetb00004.limite_credito,
|
|
hora CHAR(5)
|
|
|
|
OUTPUT
|
|
LEFT MARGIN 2
|
|
TOP MARGIN 1
|
|
ORDER BY x.cantidad2 DESC,x.codigo
|
|
|
|
FORMAT
|
|
PAGE HEADER
|
|
LET hora = time
|
|
PRINT COLUMN 1, letras.comp_on,letras.negrillas_on
|
|
PRINT COLUMN 1, "geprrp010",
|
|
COLUMN 22, "R A Y . O . V A C D O M I N I C A N A, S. A.",
|
|
COLUMN 83, "Pag. ", pageno using "###"
|
|
PRINT COLUMN 22, " Sistema de Informacion Gerencial",
|
|
COLUMN 83, today using "dd/mm/yyyy"
|
|
PRINT COLUMN 12, "Ranking de Ventas Comparativas Ano Anterior Mayor A ",
|
|
cantidad1 USING "#,###,###.##",
|
|
COLUMN 86, hora
|
|
PRINT COLUMN 22, " M A Y O R I S T A S "
|
|
|
|
PRINT COLUMN 1, "ACUMULADO AL MES DE ",nom_mes CLIPPED
|
|
PRINT COLUMN 1, "----------------------------------------------------",
|
|
"------------------------------------------------",
|
|
"---------------------------------"
|
|
PRINT COLUMN 2, "Posicion",
|
|
COLUMN 68, "Monto",
|
|
COLUMN 90, "Limite",
|
|
COLUMN 105,"Tipo de",
|
|
COLUMN 120, "%",
|
|
COLUMN 130, "%"
|
|
|
|
PRINT COLUMN 1, ano1 USING "&&&&",
|
|
COLUMN 6, ano1-1 USING "&&&&",
|
|
COLUMN 12, "Cliente",
|
|
COLUMN 63, ano1 USING "&&&&",
|
|
COLUMN 78, ano1-1 USING "&&&&",
|
|
COLUMN 85, "Status",
|
|
COLUMN 90, "Credito",
|
|
COLUMN 105, "Negocio",
|
|
COLUMN 120, "Particip.",
|
|
COLUMN 130, "Particip."
|
|
PRINT COLUMN 1, "----------------------------------------------------",
|
|
"------------------------------------------------",
|
|
"---------------------------------"
|
|
PRINT COLUMN 1, letras.negrillas_off
|
|
|
|
ON EVERY ROW
|
|
IF idx1 IS NULL THEN
|
|
LET idx1 = 0
|
|
END IF
|
|
SELECT a.limite_credito INTO limite FROM vetb00004 a
|
|
WHERE a.tipo_cliente = x.tipo_cliente AND
|
|
a.sec_cliente = x.sec_cliente
|
|
|
|
LET idx1 = idx1 + 1
|
|
LET idx = x.posicion
|
|
LET j[idx].codigo = x.codigo
|
|
LET j[idx].nombre = x.nombre
|
|
LET j[idx].provincia = x.nombre_pro
|
|
LET j[idx].status_t = x.status_t
|
|
LET J[idx].descripcion= x.descripcion
|
|
LET j[idx].cantidad1 = x.cantidad1
|
|
LET j[idx].cantidad2 = x.cantidad2
|
|
LET j[idx].limite = limite
|
|
LET j[idx].porc1 = (x.cantidad2 / ventas_totales1) * 100
|
|
LET j[idx].porc2 = (x.cantidad1 / ventas_totales2) * 100
|
|
IF x.cantidad1 = 0 THEN
|
|
LET j[idx].posicion1 = 0
|
|
ELSE
|
|
LET j[idx].posicion1 = idx1
|
|
END IF
|
|
LET j[idx].posicion2 = x.posicion
|
|
|
|
ON LAST ROW
|
|
FOR idx = 1 TO idx1
|
|
IF j[idx].posicion1 != 0 THEN
|
|
LET cuenta = cuenta + 1
|
|
END IF
|
|
PRINT COLUMN 1, j[idx].posicion2 USING "##&",
|
|
COLUMN 6, j[idx].posicion1 USING "##&",
|
|
COLUMN 15, j[idx].codigo," ",j[idx].nombre CLIPPED,
|
|
COLUMN 54, j[idx].provincia,
|
|
COLUMN 87, j[idx].cantidad2 USING "###,###,###.##",
|
|
COLUMN 109, j[idx].cantidad1 USING "###,###,###.##",
|
|
COLUMN 125, j[idx].status_t,
|
|
COLUMN 128, j[idx].limite USING "###,###,###.##",
|
|
COLUMN 144, j[idx].descripcion CLIPPED,
|
|
COLUMN 166, j[idx].porc1 USING "###.##",
|
|
COLUMN 174, j[idx].porc2 USING "###.##"
|
|
END FOR
|
|
|
|
PRINT COLUMN 87, "--------------",
|
|
COLUMN 109, "--------------"
|
|
PRINT COLUMN 30, "TOTAL VENTAS...."," ",
|
|
COLUMN 87, SUM(x.cantidad2) USING "###,###,###.##",
|
|
COLUMN 109, SUM(x.cantidad1) USING "###,###,###.##"
|
|
PRINT COLUMN 1, letras.comp_off,letras.negrillas_off
|
|
PRINT COLUMN 1, "Total Clientes =>" ,cuenta USING "##,###"
|
|
|
|
PRINT COLUMN 1, "--------------------------------------------"
|
|
PRINT COLUMN 1, "Total Ventas ano ", ano1 USING "<<<<"," ",ventas_totales1 USING "###,###,###.##"
|
|
PRINT COLUMN 1, "Total Ventas ano ", ano1-1 USING "<<<<"," ",ventas_totales2 USING "###,###,###.##"
|
|
|
|
END REPORT
|