Files

561 lines
18 KiB
Plaintext

{
-------------------------------------------------------------------------------
PROGRAMA : CCPRRP041
OBJETIVO : CREACION ARCHIVO ASCII DE LAS CUENTAS POR PAGAR
PROGRAMADOR : Juan F. Soto
FECHA REALIZACION : Junio 27, 1997
-------------------------------------------------------------------------------
}
GLOBALS "ccprgb000.4gl"
DEFINE tipo_venta CHAR(1)
DEFINE fecha_corte DATE
DEFINE ano1,mes1,idx_1, idx_2 SMALLINT
DEFINE selec1 CHAR(1000),
pcalle,pcasa,pbarrio,purbanizacion,psecuencia CHAR(20),
nom_zona,nom_prov CHAR(20),
err_val INTEGER
DEFINE doccli RECORD
tipo_cliente SMALLINT,
sec_cliente SMALLINT,
nombre CHAR(30),
aplica_a INTEGER,
pendiente DECIMAL(12,2),
num_rnc LIKE vetb00004.num_rnc,
zona_postal LIKE vetb00004.zona_postal,
cod_zona LIKE vetb00004.cod_zona,
cod_provincia LIKE vetb00004.cod_provincia,
limite_credito LIKE vetb00004.limite_credito,
fax LIKE vetb00004.fax,
telefono LIKE vetb00004.telefono,
fecha_factura DATE,
direccion CHAR(80),
cliente CHAR(7)
END RECORD
DEFINE tot_gen2 RECORD
total1 DECIMAL(10,2),
total2 DECIMAL(10,2),
total3 DECIMAL(10,2),
total4 DECIMAL(10,2),
total5 DECIMAL(10,2)
END RECORD
DEFINE valor_total DECIMAL(12,2)
FUNCTION ccprrp041()
# WHENEVER ERROR CONTINUE
OPTIONS
FORM LINE 8,
ERROR LINE 23,
COMMENT LINE 21
OPEN FORM ccfmrp041 FROM "ccfmrp041"
DISPLAY FORM ccfmrp041
CALL pantalla()
DISPLAY "ccprrp041" AT 4,3
DISPLAY "Proceso Generacion File ASCII" AT 6,29
LET tipo_papel = 1
CALL msgrp000(tipo_papel)
INPUT BY NAME tipo_venta,ano1,mes1
AFTER FIELD tipo_venta
IF tipo_venta is null THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD tipo_venta
END IF
IF tipo_venta = "1" OR tipo_venta = "2" THEN
DISPLAY BY NAME tipo_venta
ELSE
LET numero_msg = 7
CALL msg(numero_msg)
NEXT FIELD tipo_venta
END IF
AFTER FIELD ano1
IF ano1 is null THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD ano1
END IF
AFTER FIELD mes1
IF mes1 is null THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD mes1
END IF
SELECT a.fecha_corte INTO fecha_corte
FROM prdtable a
WHERE a.mes = mes1 AND
a.ano = ano1
AFTER INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
IF tipo_venta is null THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD tipo_venta
END IF
IF tipo_venta = "1" OR tipo_venta = "2" THEN
DISPLAY BY NAME tipo_venta
ELSE
LET numero_msg = 7
CALL msg(numero_msg)
NEXT FIELD tipo_venta
END IF
IF fecha_corte is null THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD fecha_corte
END IF
EXIT INPUT
END INPUT
# Busca pendiente de las facturas cuyas fechas de vencimiento son menores
# a la fecha de corte
DISPLAY " " AT 19,14
# Borra los datos anteriores de la tabla intermedia
DELETE FROM cctb00007
LET selec1 =
"SELECT a.tipo_cliente,a.sec_cliente,c.nombre,a.num_doc,a.valor+a.monto_desc, ",
" c.num_rnc,c.zona_postal,c.cod_zona,c.cod_provincia, ",
"c.limite_credito,c.fax,c.telefono,a.fecha_orig ",
"FROM cctb00001 a, vetb00004 c ",
"WHERE a.tipo_cliente=c.tipo_cliente AND a.sec_cliente = c.sec_cliente AND ",
" a.tipo_cliente = 12 AND a.sec_cliente < 9000 AND ",
" a.fecha_orig <= ? AND a.status_t is null and a.tipo_doc = 'DE' and ",
" a.num_doc = a.aplica_a "
PREPARE comando1 FROM selec1
DECLARE ft_pendiente1 CURSOR FOR comando1
OPEN ft_pendiente1 USING fecha_corte
LET selec3 =
"SELECT a.tipo_cliente,a.sec_cliente,c.nombre,a.aplica_a, ",
" SUM(a.valor+a.monto_desc), ",
" c.num_rnc,c.zona_postal,c.cod_zona,c.cod_provincia, ",
"c.limite_credito,c.fax,c.telefono ",
"FROM cctb00001 a, vetb00004 c ",
"WHERE a.tipo_cliente=c.tipo_cliente AND a.sec_cliente = c.sec_cliente AND ",
" a.tipo_cliente = 12 AND a.sec_cliente < 9000 AND ",
"a.fecha_orig <= ? AND a.status_t is null ",
"and a.tipo_doc not in ('DE','PC') ",
" GROUP BY 1,2,3,4,6,7,8,9,10,11,12 ",
" HAVING SUM(a.valor+a.monto_desc) <> 0"
DISPLAY "<< Buscando Informacion ... Espere Por Favor. >>" AT 19,14
ATTRIBUTE (REVERSE,BOLD)
PREPARE comando FROM selec3
DECLARE ft_pendiente CURSOR FOR comando
OPEN ft_pendiente USING fecha_corte
START REPORT reporte41 TO "saldo"
DISPLAY " " AT 19,14
DISPLAY "<< Reporte Generandose ... Por Favor Espere. >>"
AT 19,14 ATTRIBUTE (REVERSE)
WHILE status != NOTFOUND
FETCH ft_pendiente1 INTO doccli.*
IF status = NOTFOUND THEN
EXIT WHILE
END IF
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
LET doccli.cliente = doccli.tipo_cliente using "&&","-",
doccli.sec_cliente using "&&&&"
LET doccli.pendiente = doccli.pendiente * -1
DISPLAY doccli.aplica_a at 22,3
DISPLAY doccli.sec_cliente at 22,20
# Busca La Direccion Del Clinte
LET doccli.direccion = NULL
LET pcalle = NULL
LET pcasa = NULL
LET pbarrio= NULL
LET purbanizacion= NULL
SELECT a.calle,a.casa_num,a.barrio,a.urbanizacion,a.secuencia_visita
INTO pcalle,pcasa,pbarrio,purbanizacion,psecuencia
FROM vetb00005 a
WHERE a.tipo_cliente = doccli.tipo_cliente AND
a.sec_cliente = doccli.sec_cliente
LET doccli.direccion = pcalle CLIPPED," ",pcasa CLIPPED," ",pbarrio
# Busca La Ciudad
SELECT a.descrip INTO nom_zona
FROM vetb00008 a
WHERE a.cod_zona = doccli.cod_zona
SELECT a.nombre_provincia INTO nom_prov
FROM vetb00020 a
WHERE a.cod_provincia = doccli.cod_provincia
OUTPUT TO REPORT reporte41(doccli.*,tipo_venta,fecha_corte,valor_total)
END WHILE
LET status = 0
WHILE status != NOTFOUND
FETCH ft_pendiente INTO doccli.*
IF status = NOTFOUND THEN
EXIT WHILE
END IF
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
LET doccli.cliente = doccli.tipo_cliente USING "&&","-",
doccli.sec_cliente USING "&&&&"
DISPLAY doccli.aplica_a at 22,3
DISPLAY doccli.sec_cliente at 22,20
SELECT MIN(a.fecha_orig) INTO doccli.fecha_factura
FROM cctb00001 a
WHERE a.num_doc = doccli.aplica_a and
a.tipo_doc != "PG"
# Busca La Direccion Del Clinte
LET doccli.direccion = NULL
LET pcalle = NULL
LET pcasa = NULL
LET pbarrio= NULL
LET purbanizacion= NULL
SELECT a.calle,a.casa_num,a.barrio,a.urbanizacion,a.secuencia_visita
INTO pcalle,pcasa,pbarrio,purbanizacion,psecuencia
FROM vetb00005 a
WHERE a.tipo_cliente = doccli.tipo_cliente AND
a.sec_cliente = doccli.sec_cliente
LET doccli.direccion = pcalle CLIPPED," ",pcasa CLIPPED," ",pbarrio
OUTPUT TO REPORT reporte41(doccli.*,tipo_venta,fecha_corte,valor_total)
END WHILE
FINISH REPORT reporte41
DISPLAY BY NAME tot_gen2.*
PROMPT "<< ENTER >> PARA CONTINUAR" FOR opt
DISPLAY " " AT 19,14
ATTRIBUTE (REVERSE,BOLD)
DISPLAY "<< Creando Archivo ASCII... Espere Por Favor >> " AT 19,14
ATTRIBUTE (REVERSE,BOLD)
UNLOAD TO "cli.ld" SELECT *FROM cctb00007
LABEL vuelve:
PROMPT "ENTRE DISKETT EN LA UNIDAD..." FOR opt
DISPLAY "<< Formateando Diskett 3.5 144 MB.. Espere >> " AT 19,14
ATTRIBUTE (REVERSE,BOLD)
RUN "dosformat a:" RETURNING err_val
IF err_val > 0 THEN
DISPLAY " " AT 19,14
GOTO vuelve
END IF
LABEL vuelve1:
DISPLAY "<< Copiando Archivo ASCII a Diskett ... Espere>>" AT 19,14
RUN "doscp cli.ld a:"
IF err_val > 0 THEN
DISPLAY " " AT 19,14
PROMPT "ENTRE EL DISKETT EN LA UNIDAD. PRESIONE CUALQUIER TECLA" FOR
opt
GOTO vuelve1
END IF
CLEAR SCREEN
RUN "type C:\\archivo > %USPRINT%" END FUNCTION
REPORT reporte41(x,venta,corte,valor_gral)
DEFINE x RECORD
tipo_cliente SMALLINT,
sec_cliente SMALLINT,
nombre CHAR(30),
aplica_a INTEGER,
pendiente DECIMAL(12,2),
num_rnc LIKE vetb00004.num_rnc,
zona_postal LIKE vetb00004.zona_postal,
cod_zona LIKE vetb00004.cod_zona,
cod_provincia LIKE vetb00004.cod_provincia,
limite_credito LIKE vetb00004.limite_credito,
fax LIKE vetb00004.fax,
telefono LIKE vetb00004.telefono,
fecha_factura DATE,
direccion CHAR(80),
cliente CHAR(7)
END RECORD
DEFINE valor_gral DECIMAL(12,2)
DEFINE venta CHAR(1),
corte DATE
DEFINE doble_on CHAR(2)
DEFINE doble_off CHAR(2)
DEFINE negrillas_on CHAR(2)
DEFINE negrillas_off CHAR(2)
DEFINE comp_on CHAR(2)
DEFINE comp_off CHAR(2)
DEFINE doce CHAR(2)
DEFINE comprimido CHAR(3)
DEFINE normall CHAR(3)
DEFINE normal CHAR(2)
DEFINE hora CHAR(5)
DEFINE fecha_factura DATE
DEFINE tt90, tt120, tt149, tt180, tt30, tt60, total_saldo DECIMAL(12,2)
DEFINE t90,t120,t149,t180,t30, t45, t60, tm60, tsaldo DECIMAL(12,2)
DEFINE dias INTEGER ,
codigo CHAR(7)
OUTPUT
TOP MARGIN 0
LEFT MARGIN 0
BOTTOM MARGIN 2
ORDER BY x.cliente,x.aplica_a
FORMAT
PAGE HEADER
LET doble_on = ASCII 14
LET doble_off = ASCII 20
LET negrillas_on = ASCII 27, ASCII 69
LET negrillas_off = ASCII 27, ASCII 70
LET comp_on = ASCII 15
LET comp_off = ASCII 18
LET comprimido = ASCII 15
LET doce = ASCII 27, ASCII 77
LET normal = ASCII 27, ASCII 80
LET normall = ASCII 030
LET hora = time
LET lj = (123 - LENGTH(p_companias.nombre CLIPPED))/2
# PRINT COLUMN 1, doce ,negrillas_on
PRINT COLUMN 1, comprimido
PRINT COLUMN 1, "ccprrp041",
COLUMN lj, p_companias.nombre CLIPPED,
COLUMN 116, "Pag. ",pageno using "###"
PRINT COLUMN 46, "Sistema de Cuentas por Cobrar",
COLUMN 114, today using "dd/mm/yyyy"
PRINT COLUMN 44, "Saldos por Antiguedad al ",
corte using "dd/mm/yy",
COLUMN 119, hora
IF venta = "1" THEN
PRINT COLUMN 53, "Valores en RD$"
ELSE
PRINT COLUMN 53, "Valores en US$"
END IF
SKIP 1 LINES
PRINT COLUMN 1, "--------------------------------------------------",
"--------------------------------------------------",
"-----------------------"
PRINT COLUMN 2, "C l i e n t e",
COLUMN 46, "De 1 a 30",
COLUMN 66, "De 31 a 45",
COLUMN 82, "De 46 a 60",
COLUMN 99, "Mas de 60",
COLUMN 119, "Total"
PRINT COLUMN 1, "--------------------------------------------------",
"--------------------------------------------------",
"-----------------------"
# , negrillas_off
BEFORE GROUP OF x.cliente
LET descrip1 = x.nombre
LET t30 = 0
LET t60 = 0
LET t90 = 0
LET t120 = 0
LET t149 = 0
LET t180 = 0
IF descrip1 IS NULL THEN
LET descrip1 = "Cliente no Existe. Verifique."
END IF
PRINT COLUMN 1, " "
ON EVERY ROW
LET dias = corte - x.fecha_factura
IF total_saldo IS NULL THEN
LET total_saldo = 0
END IF
IF tsaldo IS NULL THEN
LET tsaldo = 0
END IF
IF dias >= 0 AND dias < 31 THEN
LET t30= t30 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
END IF
IF dias >= 31 AND dias <= 60 AND x.pendiente <> 0 THEN
LET t60 = t60 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
print x.aplica_a using "&&&&&&"," ",x.pendiente using "###,###.##",
" ",x.fecha_factura using "dd/mm/yy"
END IF
#### Imprime y acumula los valores correspondientes a pago realizados en
#### mas de 60 menor a 90 dias.
IF dias > 60 AND dias <= 90 THEN
LET t90 = t90 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
print x.aplica_a using "&&&&&&"," ",x.pendiente using "###,###.##",
" ",x.fecha_factura using "dd/mm/yy"
END IF
#### Imprime y acumula los valores correspondientes a pago realizados en
#### mas de 90 menor a 120 dias.
IF dias > 90 AND dias <= 120 THEN
LET t120 = t120 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
print x.aplica_a using "&&&&&&"," ",x.pendiente using "###,###.##",
" ",x.fecha_factura using "dd/mm/yy"
END IF
#### Imprime y acumula los valores correspondientes a pago realizados en
#### mas de 120 menor a 150 dias.
IF dias > 120 AND dias <= 150 THEN
LET t149 = t149 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
print x.aplica_a using "&&&&&&"," ",x.pendiente using "###,###.##",
" ",x.fecha_factura using "dd/mm/yy"
END IF
#### Imprime y acumula los valores correspondientes a pago realizados en
#### mas de 150 menor a 180 dias.
IF dias > 150 THEN
LET t180 = t180 + x.pendiente
LET total_saldo = total_saldo + x.pendiente
print x.aplica_a using "&&&&&&"," ",x.pendiente using "###,###.##",
" ",x.fecha_factura using "dd/mm/yy"
END IF
AFTER GROUP OF x.cliente
IF tt30 IS NULL THEN
LET tt30 = 0
END IF
IF tt60 IS NULL THEN
LET tt60 = 0
END IF
IF tt90 IS NULL THEN
LET tt90 = 0
END IF
IF tt120 IS NULL THEN
LET tt120 = 0
END IF
IF tt149 IS NULL THEN
LET tt149 = 0
END IF
IF tt180 IS NULL THEN
LET tt180 = 0
END IF
LET codigo = x.tipo_cliente USING "##","-",x.sec_cliente USING "&&&&"
CASE
WHEN t30 < 0
LET t60 = t60 + t30
LET t30 = 0
WHEN t60 < 0
LET t90 = t90 + t60
LET t60 = 0
WHEN t90 < 0
LET t120 = t120 + t90
LET t90 = 0
WHEN t120 < 0
LET t149 = t149 + t120
LET t120 = 0
WHEN t149 < 0
LET t180 = t180 + t149
LET t149 = 0
END CASE
INSERT INTO cctb00007 VALUES(corte,x.nombre,codigo,x.num_rnc,
x.zona_postal,x.direccion,
pbarrio,nom_prov,x.telefono,
x.limite_credito,t30,t60,t90,
t120,t149,t180)
LET tt30 = t30 + tt30
LET tt60 = t60 + tt60
LET tt90 = t90 + tt90
LET tt120 = t120 + tt120
LET tt149 = t149 + tt149
LET tt180 = t180 + tt180
ON LAST ROW
SKIP 1 LINE
PRINT
# COLUMN 1, negrillas_on,
COLUMN 23, "Totales -->",
COLUMN 41, tt30 using "(((,(((,(((.##)",
COLUMN 61, t45 using "(((,(((,(((.##)",
COLUMN 77, t60 using "(((,(((,(((.##)",
COLUMN 93, tm60 using "(((,(((,(((.##)",
COLUMN 109, tsaldo using "(((,(((,(((.##)"
# , negrillas_off
LET tot_gen2.total1 = 0
LET tot_gen2.total2 = 0
LET tot_gen2.total3 = 0
LET tot_gen2.total4 = 0
LET tot_gen2.total5 = 0
LET tot_gen2.total1 = tt30
LET tot_gen2.total2 = tt90
LET tot_gen2.total3 = tt60
LET tot_gen2.total4 = tt120+tt149+tt180
LET tot_gen2.total5 = total_saldo
LET t30 = 0
LET t45 = 0
LET t60 = 0
LET tm60 = 0
LET tsaldo = 0
PRINT normal
END REPORT