Files
MBS/PROYECTO/ccdir/ccprmt006.4gl
T

687 lines
23 KiB
Plaintext

{
-------------------------------------------------------------------------------
PROGRAMA : CCPRMT006
OBJETIVO : Reclasificar las facturas que tiene saldo pendientes o a favor
PROGRAMADOR : Juan F. Soto
FECHA : Agosto 28, 1996
-------------------------------------------------------------------------------
}
GLOBALS
"ccprgb000.4gl"
DEFINE aplica_wd1 ARRAY[100] OF RECORD
numero INTEGER,
pendiente DECIMAL(12,2)
END RECORD
# Variable de Captura datos generales
DEFINE c_limpia RECORD
fecha_orig LIKE cctb00001.fecha_orig,
tipo_cliente LIKE cctb00001.tipo_cliente,
sec_cliente LIKE cctb00001.sec_cliente,
num_doc LIKE cctb00001.num_doc
END RECORD,
usuario CHAR(9),
fecha_crea LIKE cctb00001.fech_crea,
t_debito,t_credito,c_valor1,cuadre,c_valor DECIMAL(12,2),
eli CHAR(1)
# Variable de Captura Debitos y Creditos de Facturas
DEFINE arr_limpia ARRAY[100] OF RECORD
p_aplica_a LIKE cctb00001.aplica_a,
debito DECIMAL(12,2),
credito DECIMAL(12,2)
END RECORD
# Funcion Para Desplegar El Menu de Opciones
FUNCTION ccprmt006()
OPTIONS
ERROR LINE 24,
FORM LINE 8
CALL pantalla()
DISPLAY "Reclasificaion de Facturas" AT 6,15
OPEN FORM ccfmmt006 FROM "ccfmmt006"
DISPLAY FORM ccfmmt006
MENU "OPCION"
COMMAND "Adicionar" "<Esc> Adiciona Registro <Delete> Cancela Operacion"
LET int_flag = false
CALL ccprad06()
COMMAND "Consulta-modifica"
"<Esc> Busca Registro <Ctrl-c> Cancela Operacion"
LET int_flag = false
CALL ccprmf06()
COMMAND "Salir" "Retorna al menu anterior"
EXIT MENU
END MENU
END FUNCTION
# Funcion Para Agregar Registros a la tabla de transacciones de cxc
FUNCTION ccprad06()
CLEAR FORM
INITIALIZE c_limpia.* TO NULL
LET c_limpia.fecha_orig = TODAY
DISPLAY BY NAME c_limpia.fecha_orig
SELECT ult_recibo INTO c_limpia.num_doc
FROM cctb00003
WHERE tipo_doc = "RC"
IF c_limpia.num_doc IS NULL THEN
LET c_limpia.num_doc = 0
END IF
LET c_limpia.num_doc = c_limpia.num_doc + 1
INPUT BY NAME c_limpia.* WITHOUT DEFAULTS
ON KEY (CONTROL-W)
IF INFIELD(tipo_cliente) OR
INFIELD(sec_cliente) THEN
CALL consulta_clientes()
LET c_limpia.tipo_cliente = cliente_dir.tipo_cliente
LET c_limpia.sec_cliente = cliente_dir.sec_cliente
LET nom_cli = descrip1
DISPLAY BY NAME c_limpia.tipo_cliente,c_limpia.sec_cliente,
nom_cli
NEXT FIELD num_doc
END IF
AFTER FIELD fecha_orig
IF c_limpia.fecha_orig IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD fecha_orig
END IF
LET p_fechas = c_limpia.fecha_orig
CALL prd()
IF bandera = 1 THEN
LET bandera = 0
NEXT FIELD fecha_orig
END IF
BEFORE FIELD sec_cliente
DISPLAY BY NAME c_limpia.*
AFTER FIELD tipo_cliente
IF c_limpia.tipo_cliente IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD tipo_cliente
END IF
AFTER FIELD sec_cliente
IF c_limpia.sec_cliente IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD sec_cliente
END IF
SELECT nombre INTO nom_cli
FROM vetb00004
WHERE tipo_cliente = c_limpia.tipo_cliente AND
sec_cliente = c_limpia.sec_cliente AND
status_t is null
IF status = notfound THEN
LET numero_msg = 3
CALL msg(numero_msg)
NEXT FIELD tipo_cliente
END IF
DISPLAY BY NAME nom_cli
AFTER INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
SELECT UNIQUE @num_doc FROM cctb00001
WHERE @num_doc = c_limpia.num_doc AND
@tipo_doc = "RC" AND
status_t is null
IF STATUS != NOTFOUND THEN
LET numero_msg = 12
CALL msg(numero_msg)
NEXT FIELD fecha_orig
END IF
EXIT INPUT
END INPUT
FOR idx = 1 TO 7
LET arr_limpia[idx].p_aplica_a = null
LET arr_limpia[idx].debito = null
LET arr_limpia[idx].credito= null
DISPLAY arr_limpia[idx].p_aplica_a TO s_limpia[idx].p_aplica_a
DISPLAY arr_limpia[idx].debito TO s_limpia[idx].debito
DISPLAY arr_limpia[idx].credito TO s_limpia[idx].credito
END FOR
LABEL vuelve:
## AQUI SE INTRODUCEN LOS DATOS DEL ARREGLO
INPUT ARRAY arr_limpia WITHOUT DEFAULTS FROM s_limpia.*
## VENTANA PARA BUSCAR LOS DOCUMENTOS
ON KEY (CONTROL-W)
CASE
WHEN INFIELD (p_aplica_a)
CALL busca_facturas()
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
NEXT FIELD p_aplica_a
END IF
IF existe = "N" THEN
LET existe = "S"
NEXT FIELD p_aplica_a
END IF
IF arr_limpia[curr].debito < 0 THEN
LET arr_limpia[curr].debito = arr_limpia[curr].debito * -1
END IF
DISPLAY arr_limpia[curr].p_aplica_a to
s_limpia[scr_l].p_aplica_a
DISPLAY arr_limpia[curr].debito to
s_limpia[scr_l].debito
NEXT FIELD debito
END CASE
BEFORE ROW
LET curr = arr_curr()
LET scr_l = scr_line()
AFTER FIELD p_aplica_a
IF arr_limpia[curr].p_aplica_a IS NOT NULL THEN
# Controla que la factura pertenezca al cliente
SELECT UNIQUE a.num_doc FROM cctb00001 a
WHERE a.num_doc = arr_limpia[curr].p_aplica_a and
a.tipo_cliente = c_limpia.tipo_cliente AND
a.sec_cliente = c_limpia.sec_cliente AND
a.status_t is null
IF status = notfound THEN
LET numero_msg = 3
CALL msg(numero_msg)
NEXT FIELD p_aplica_a
END IF
SELECT SUM(a.valor+a.monto_desc) INTO valor_fac FROM cctb00001 a
WHERE a.aplica_a = arr_limpia[curr].p_aplica_a and
a.tipo_cliente = c_limpia.tipo_cliente AND
a.sec_cliente = c_limpia.sec_cliente AND
a.status_t is null
LET arr_limpia[curr].debito = valor_fac
DISPLAY arr_limpia[curr].debito TO s_limpia[scr_l].debito
END IF
AFTER ROW
LET t_debito = 0
LET t_credito = 0
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito is not null THEN
LET t_debito = t_debito + arr_limpia[idx].debito
END IF
IF arr_limpia[idx].credito is not null THEN
LET t_credito= t_credito + arr_limpia[idx].credito
END IF
END FOR
DISPLAY BY NAME t_debito,t_credito ATTRIBUTE(BOLD)
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
IF arr_limpia[idx].debito IS NULL AND
arr_limpia[idx].credito IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
LET arr_limpia[idx].p_aplica_a = null
DISPLAY arr_limpia[idx].p_aplica_a TO
s_limpia[scr_l].p_aplica_a
NEXT FIELD p_aplica_a
END IF
END IF
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
IF (arr_limpia[idx].debito IS NOT NULL AND
arr_limpia[idx].credito IS NOT NULL) THEN
LET numero_msg = 360
CALL msg(numero_msg)
NEXT FIELD p_aplica_a
END IF
END IF
END FOR
# Controla que el valor aplicado a las facturas no exceda el monto del recibo
END INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
# Chequea si la transaccion esta cuadrada
LET c_valor = 0
LET c_valor1 = 0
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito IS NULL THEN
LET arr_limpia[idx].debito = 0
END IF
IF arr_limpia[idx].credito IS NULL THEN
LET arr_limpia[idx].credito = 0
END IF
LET c_valor = c_valor + arr_limpia[idx].debito
LET c_valor1 = c_valor1 + arr_limpia[idx].credito
IF arr_limpia[idx].debito = 0 THEN
LET arr_limpia[idx].debito = NULL
END IF
IF arr_limpia[idx].credito = 0 THEN
LET arr_limpia[idx].credito = NULL
END IF
END FOR
LET cuadre = c_valor - c_valor1
IF cuadre != 0 THEN
LET numero_msg = 174
CALL msg(numero_msg)
GOTO vuelve
END IF
#-------------------------------------------------------------------------------
LET c_valor = 0
# Actualizacion de la tabla de cuentas por cobrar
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito IS NOT NULL OR
arr_limpia[idx].debito > 0 THEN
LET c_valor = arr_limpia[idx].debito
END IF
IF arr_limpia[idx].credito IS NOT NULL OR
arr_limpia[idx].credito > 0 THEN
LET c_valor = arr_limpia[idx].credito * -1
END IF
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
INSERT INTO cctb00001(num_doc,tipo_doc,tipo_cliente,sec_cliente,
fecha_orig,aplica_a,valor,status_t,us_crea,fech_crea,
monto_desc)
VALUES
(c_limpia.num_doc,"RC",c_limpia.tipo_cliente,
c_limpia.sec_cliente,c_limpia.fecha_orig,
arr_limpia[idx].p_aplica_a,c_valor,
null,user,current,0)
END IF
END FOR
SELECT ult_recibo FROM cctb00003
WHERE tipo_doc = "RC"
IF status = notfound THEN
INSERT INTO cctb00003 (ult_recibo,tipo_doc)
VALUES (c_limpia.num_doc,"RC")
END IF
UPDATE cctb00003 set ult_recibo = c_limpia.num_doc,
us_crea = user,
fech_crea = current
WHERE tipo_doc = "RC"
LET numero_msg = 1
CALL msg(numero_msg)
END FUNCTION
FUNCTION ccprmf06()
CLEAR FORM
CONSTRUCT BY NAME criterio ON tipo_cliente,sec_cliente,num_doc
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
LET selec = "SELECT fecha_orig,tipo_cliente,sec_cliente,num_doc,us_crea,",
"fech_crea ",
" FROM cctb00001 ",
"WHERE ",criterio clipped,
" AND tipo_doc = 'RC' ",
" AND status_t is null ",
" ORDER BY num_doc"
PREPARE comando FROM selec
DECLARE busca SCROLL CURSOR FOR comando
OPEN busca
FETCH FIRST busca INTO c_limpia.*,usuario,fecha_crea
IF status = notfound THEN
LET numero_msg = 3
CALL msg(numero_msg)
RETURN
END IF
CALL busca_cliente()
MENU "OPCION"
COMMAND "Siguiente" "Busca Siguiente Registro Cumpla Condicion"
FETCH NEXT busca INTO c_limpia.*,usuario,fecha_crea
IF STATUS = NOTFOUND THEN
LET numero_msg = 4
CALL msg(numero_msg)
END IF
CALL busca_cliente()
COMMAND "Anterior" "Busca Registro Anterior Cumpla Condicion"
FETCH PREVIOUS busca INTO c_limpia.*,usuario,fecha_crea
IF STATUS = NOTFOUND THEN
LET numero_msg = 5
CALL msg(numero_msg)
END IF
CALL busca_cliente()
COMMAND "Primero" "Busca Registro Anterior Cumpla Condicion"
FETCH FIRST busca INTO c_limpia.*,usuario,fecha_crea
LET numero_msg = 4
CALL msg(numero_msg)
CALL busca_cliente()
COMMAND "Ultimo" "Busca Registro Anterior Cumpla Condicion"
FETCH LAST busca INTO c_limpia.*,usuario,fecha_crea
LET numero_msg = 5
CALL msg(numero_msg)
CALL busca_cliente()
COMMAND "Escoger"
"<Esc> Actualiza Registro <Delete> Cancela Operacion"
INPUT BY NAME c_limpia.* WITHOUT DEFAULTS
ON KEY (CONTROL-W)
IF INFIELD(tipo_cliente) OR
INFIELD(sec_cliente) THEN
CALL consulta_clientes()
LET c_limpia.tipo_cliente = cliente_dir.tipo_cliente
LET c_limpia.sec_cliente = cliente_dir.sec_cliente
LET nom_cli = descrip1
DISPLAY BY NAME c_limpia.tipo_cliente,c_limpia.sec_cliente,
nom_cli
NEXT FIELD num_doc
END IF
AFTER FIELD fecha_orig
IF c_limpia.fecha_orig IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD fecha_orig
END IF
LET p_fechas = c_limpia.fecha_orig
CALL prd()
IF bandera = 1 THEN
LET bandera = 0
NEXT FIELD fecha_orig
END IF
BEFORE FIELD sec_cliente
DISPLAY BY NAME c_limpia.*
AFTER FIELD tipo_cliente
IF c_limpia.tipo_cliente IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD tipo_cliente
END IF
AFTER FIELD sec_cliente
IF c_limpia.sec_cliente IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
NEXT FIELD sec_cliente
END IF
SELECT nombre INTO nom_cli
FROM vetb00004
WHERE tipo_cliente = c_limpia.tipo_cliente AND
sec_cliente = c_limpia.sec_cliente AND
status_t is null
IF status = notfound THEN
LET numero_msg = 3
CALL msg(numero_msg)
NEXT FIELD tipo_cliente
END IF
DISPLAY BY NAME nom_cli
AFTER INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
EXIT INPUT
END INPUT
DECLARE busca_trx CURSOR FOR
SELECT a.aplica_a,a.valor FROM cctb00001 a
WHERE a.num_doc = c_limpia.num_doc and
a.tipo_doc = "RC" and
a.tipo_cliente = c_limpia.tipo_cliente and
a.sec_cliente = c_limpia.sec_cliente
LET idx = 1
FOREACH busca_trx INTO arr_limpia[idx].*
IF arr_limpia[idx].debito > 0 THEN
LET arr_limpia[idx].debito = arr_limpia[idx].debito
END IF
IF arr_limpia[idx].debito < 0 THEN
LET arr_limpia[idx].credito = arr_limpia[idx].debito * -1
LET arr_limpia[idx].debito = NULL
END IF
LET idx = idx + 1
END FOREACH
CALL set_count(idx - 1 )
LABEL vuelve:
INPUT ARRAY arr_limpia WITHOUT DEFAULTS FROM s_limpia.*
## VENTANA PARA BUSCAR LOS DOCUMENTOS
ON KEY (CONTROL-W)
CASE
WHEN INFIELD (p_aplica_a)
CALL busca_facturas()
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
NEXT FIELD p_aplica_a
END IF
IF existe = "N" THEN
LET existe = "S"
NEXT FIELD p_aplica_a
END IF
IF arr_limpia[curr].debito < 0 THEN
LET arr_limpia[curr].debito = arr_limpia[curr].debito * -1
END IF
DISPLAY arr_limpia[curr].p_aplica_a to
s_limpia[scr_l].p_aplica_a
DISPLAY arr_limpia[curr].debito to
s_limpia[scr_l].debito
NEXT FIELD debito
END CASE
BEFORE ROW
LET curr = arr_curr()
LET scr_l = scr_line()
AFTER FIELD p_aplica_a
IF arr_limpia[curr].p_aplica_a IS NOT NULL THEN
# Controla que la factura pertenezca al cliente
SELECT UNIQUE a.num_doc FROM cctb00001 a
WHERE a.num_doc = arr_limpia[curr].p_aplica_a and
a.tipo_cliente = c_limpia.tipo_cliente AND
a.sec_cliente = c_limpia.sec_cliente AND
a.status_t is null
IF status = notfound THEN
LET numero_msg = 3
CALL msg(numero_msg)
NEXT FIELD p_aplica_a
END IF
END IF
AFTER ROW
LET t_debito = 0
LET t_credito = 0
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito is not null THEN
LET t_debito = t_debito + arr_limpia[idx].debito
END IF
IF arr_limpia[idx].credito is not null THEN
LET t_credito= t_credito + arr_limpia[idx].credito
END IF
END FOR
DISPLAY BY NAME t_debito,t_credito ATTRIBUTE(BOLD)
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
IF arr_limpia[idx].debito IS NULL AND
arr_limpia[idx].credito IS NULL THEN
LET numero_msg = 16
CALL msg(numero_msg)
LET arr_limpia[idx].p_aplica_a = null
DISPLAY arr_limpia[idx].p_aplica_a TO
s_limpia[scr_l].p_aplica_a
NEXT FIELD p_aplica_a
END IF
END IF
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
IF (arr_limpia[idx].debito IS NOT NULL AND
arr_limpia[idx].credito IS NOT NULL) THEN
LET numero_msg = 360
CALL msg(numero_msg)
NEXT FIELD p_aplica_a
END IF
END IF
END FOR
END INPUT
IF int_flag THEN
LET numero_msg = 2
CALL msg(numero_msg)
LET int_flag = false
RETURN
END IF
# Chequea si la transaccion esta cuadrada
LET c_valor = 0
LET c_valor1 = 0
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito IS NULL THEN
LET arr_limpia[idx].debito = 0
END IF
IF arr_limpia[idx].credito IS NULL THEN
LET arr_limpia[idx].credito = 0
END IF
LET c_valor = c_valor + arr_limpia[idx].debito
LET c_valor1 = c_valor1 + arr_limpia[idx].credito
IF arr_limpia[idx].debito = 0 THEN
LET arr_limpia[idx].debito = NULL
END IF
IF arr_limpia[idx].credito = 0 THEN
LET arr_limpia[idx].credito = NULL
END IF
END FOR
LET cuadre = c_valor - c_valor1
IF cuadre != 0 THEN
LET numero_msg = 174
CALL msg(numero_msg)
GOTO vuelve
END IF
LET c_valor = 0
# Actualizacion de la tabla de cuentas por cobrar
DISPLAY "Actualizando Tablas... Espere Por Favor" AT 22,1
ATTRIBUTE (BOLD)
DELETE FROM cctb00001 WHERE num_doc = c_limpia.num_doc AND
tipo_doc = "RC"
FOR idx = 1 TO arr_count()
IF arr_limpia[idx].debito IS NOT NULL OR
arr_limpia[idx].debito > 0 THEN
LET c_valor = arr_limpia[idx].debito
END IF
IF arr_limpia[idx].credito IS NOT NULL OR
arr_limpia[idx].credito > 0 THEN
LET c_valor = arr_limpia[idx].credito * -1
END IF
IF arr_limpia[idx].p_aplica_a IS NOT NULL THEN
INSERT INTO cctb00001(num_doc,tipo_doc,tipo_cliente,
sec_cliente,
fecha_orig,aplica_a,valor,status_t,
us_crea,fech_crea,us_mod,fech_mod,
monto_desc)
VALUES
(c_limpia.num_doc,"RC",c_limpia.tipo_cliente,
c_limpia.sec_cliente,c_limpia.fecha_orig,
arr_limpia[idx].p_aplica_a,c_valor,null,
usuario,fecha_crea,user,current,0)
END IF
END FOR
DISPLAY " " AT 22,1
LET numero_msg = 13
CALL msg(numero_msg)
COMMAND KEY("L") "eLiminar"
"Elimina Logicamente Este Movimiento"
PROMPT "Esta Seguro de Eliminar Este Registro(S/N)?" FOR CHAR eli
LET eli = UPSHIFT(eli)
IF eli = "S" THEN
UPDATE cctb00001 SET status_t = "E",
us_mod = user,
fech_mod = current
WHERE num_doc = c_limpia.num_doc AND
tipo_doc = "RC"
END IF
COMMAND "Retornar" "Retorna Al menu Anterior"
EXIT MENU
END MENU
END FUNCTION
FUNCTION busca_cliente()
SELECT nombre INTO nom_cli
FROM vetb00004
WHERE tipo_cliente = c_limpia.tipo_cliente AND
sec_cliente = c_limpia.sec_cliente
DISPLAY BY NAME nom_cli,c_limpia.*
END FUNCTION
FUNCTION busca_facturas()
OPEN WINDOW busqueda1 AT 10,10 WITH FORM "ccfmwd003"
ATTRIBUTE (BORDER,FORM LINE FIRST + 1, comment line last)
DECLARE aplicar CURSOR FOR
SELECT a.aplica_a,SUM(a.valor+a.monto_desc) FROM cctb00001 a
WHERE a.tipo_cliente = c_limpia.tipo_cliente AND
a.sec_cliente = c_limpia.sec_cliente AND a.status_t is null
GROUP BY 1
HAVING SUM(a.valor+a.monto_desc) != 0
ORDER BY 1
LET existe = "N"
LET idx = 1
FOREACH aplicar INTO aplica_wd1[idx].numero,aplica_wd1[idx].pendiente
LET idx = idx + 1
END FOREACH
IF existe = "N" and idx = 1 THEN
LET numero_msg = 3
CALL msg(numero_msg)
GOTO salir
END IF
CALL set_count(idx-1)
DISPLAY ARRAY aplica_wd1 TO consart.*
LET curr1 = arr_curr()
IF int_flag THEN
GOTO salir
END IF
LET arr_limpia[curr].p_aplica_a = aplica_wd1[curr1].numero
LET arr_limpia[curr].debito = aplica_wd1[curr1].pendiente
LABEL salir:
CLOSE WINDOW busqueda1
END FUNCTION