Files
MBS/PROYECTO/otrodir/busca_balances.4gl
T

103 lines
3.2 KiB
Plaintext

{
FUNCTION : busca_balance
PARAMETROS : ktipo (tipo_cliente), ksec (sec_cliente), corte(fecha_corte)
DESARROLLADO POR : Ing. Juan Soto
FECHA DESARROLLO : 21/05/2019
}
FUNCTION busca_balance(ktipo,ksec,corte)
DEFINE ktipo,ksec,dias INT,
xcorriente,x1a30,x31a60,x61a90,xmas90,xtotalSaldo DEC(12,2),
selec1 STRING,
corte DATE
DEFINE datos RECORD
num_doc INT,
monto FLOAT,
fecha_ven DATE
END RECORD
LET selec1 =
"SELECT a.num_doc,SUM(a.valor+a.monto_desc) ",
"FROM cctb00001 a ",
"WHERE ",
" (a.fecha_orig <='",corte USING "mm/dd/yyyy","') AND a.status_t is null and (a.tipo_doc in('AV') and ",
" a.num_doc = a.aplica_a) AND ",
" (a.tipo_cliente =", ktipo," AND a.sec_cliente = ",ksec,")",
" GROUP BY a.num_doc HAVING SUM(a.valor+a.monto_Desc) <>0"
PREPARE avances FROM selec1
DECLARE b_avances CURSOR FOR avances
LET xcorriente=0
LET x1a30=0
LET x31a60=0
LET x61a90=0
LET xmas90=0
LET xtotalSaldo=0
FOREACH b_avances INTO datos.*
LET datos.monto = datos.monto *-1
LET xmas90 = xmas90 + datos.monto
END FOREACH
LET selec1 ="SELECT a.aplica_a, ",
" SUM(a.valor+a.monto_desc) ",
"FROM cctb00001 a ",
"WHERE (a.tipo_cliente=",ktipo," AND a.sec_cliente =",ksec,") AND ",
" (a.fecha_orig <='",corte USING "mm/dd/yyyy","') AND a.status_t is null ",
"and a.tipo_doc not in ('AV','PC','AP') ",
" GROUP BY a.aplica_a HAVING SUM(a.valor + a.monto_desc) <> 0 "
PREPARE c_docs FROM selec1
DECLARE b_docs CURSOR FOR c_docs
FOREACH b_docs INTO datos.num_doc,datos.monto
# FECHA vencimiento
SELECT MAX(a.fecha_ven) INTO datos.fecha_ven
FROM cctb00001 a
WHERE a.num_doc = datos.num_doc and
a.tipo_doc not in ("PG" ,"PC","NC","ND","AV","AP") and
a.tipo_cliente = ktipo and a.sec_cliente = ksec and
a.status_t is NULL
IF datos.fecha_ven IS NULL THEN
LET datos.fecha_ven = '01/01/2001'
END IF
LET dias = corte - datos.fecha_ven
IF dias <= 0 THEN
LET xcorriente =xcorriente+ datos.monto
END IF
IF dias > 0 AND dias < 31 THEN
LET x1a30= x1a30 + datos.monto
END IF
IF dias >=31 AND dias < 61 THEN
LET x31a60=x31a60+ datos.monto
END IF
IF dias >= 61 AND dias <= 90 THEN
LET x61a90=x61a90+ datos.monto
END IF
IF dias > 90 THEN
LET xmas90= xmas90+datos.monto
END IF
END FOREACH
LET xtotalsaldo = xcorriente+ x1a30+x31a60 + x61a90 + xmas90
RETURN xcorriente,x1a30,x31a60,x61a90,xmas90,xtotalSaldo
END FUNCTION