{ ------------------------------------------------------------------------------- PROGRAMA : CCPRRP007 OBJETIVO : Reportar el registro de ventas,itbis,devoluciones,etc en un rango de fecha determinado. PROGRAMADOR : Ing. Juan Soto FECHA REALIZACION : Mayo 19, 1993 MODIFICADO POR : Juan Soto PROCESO : Estaba sacando por cada devolucion una factra o sea que las facturas estaban duplicadas. FECHA MODIFICACION : Noviembre 18, 1993. ------------------------------------------------------------------------------- } GLOBALS "ccprgb000.4gl" ###### Definicion de variables usadas en el reporte # clientes_act - es para control del cliente que el reporte no busque las # notas de debito mas de una vez por cliente DEFINE cliente_act,cliente_ant CHAR(6) DEFINE enc CHAR(1) DEFINE vend,sec SMALLINT DEFINE tipo_venta CHAR(1) DEFINE fecha_ini,fecha_fin,fecha_corte DATE DEFINE idx_1, idx_2 SMALLINT DEFINE mes DATE DEFINE sele CHAR(500) ##### Registro Almacena la informacion seleccionada para la posterior impresion DEFINE prt_itbi RECORD ventas CHAR(1), nombre CHAR(30), fecha DATE, factura INTEGER, valor DECIMAL(12,2), descuento DECIMAL(12,2), itbi DECIMAL(12,2), porc_itbi DECIMAL(8,4), estatus CHAR(1), exentas DECIMAL(12,2), valor_doc DECIMAL(12,2), num_doc INTEGER, aplica_a INTEGER, fecha_orig DATE END RECORD # Record para la busqueda de las facturas que entran en el periodo # Especificado DEFINE facturas RECORD ventas CHAR(1), tipo_cliente SMALLINT, sec_cliente SMALLINT, nombre CHAR(30), fecha DATE, factura INTEGER, sub_total DECIMAL(12,2), monto_desc DECIMAL(12,2), monto_itbi DECIMAL(12,2), porc_itbi DECIMAL(8,4), estatus CHAR(1) END RECORD ##### Funcion para ejecutar la informacion a imprimir FUNCTION ccprrp007() # WHENEVER ERROR CONTINUE OPTIONS FORM LINE 8, ERROR LINE 23, COMMENT LINE 21 OPEN FORM ccfmrp007 FROM "ccfmrp007" DISPLAY FORM ccfmrp007 CALL pantalla() DISPLAY "ccprrp007" AT 4,3 DISPLAY "Registro de Ventas (ITBIS)" AT 6,27 LET tipo_papel = 2 CALL msgrp000(tipo_papel) LET fecha_ini = today LET fecha_fin = today ###### Entrada de valores para fines de busqueda en un rango de fecha INPUT BY NAME fecha_ini,fecha_fin WITHOUT DEFAULTS AFTER FIELD fecha_ini IF fecha_ini is null THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fecha_ini END IF AFTER FIELD fecha_fin IF fecha_fin is null THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fecha_fin END IF # Control para que la fecha final no sea menor que la inicial IF fecha_ini > fecha_fin THEN LET numero_msg = 86 CALL msg(numero_msg) NEXT FIELD fecha_ini END IF AFTER INPUT IF fecha_ini is null THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fecha_ini END IF IF fecha_fin is null THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fecha_fin END IF IF fecha_ini > fecha_fin THEN LET numero_msg = 86 CALL msg(numero_msg) NEXT FIELD fecha_ini END IF EXIT INPUT END INPUT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) LET int_flag = FALSE RETURN END IF ###### Creando el criterio de busqueda CONSTRUCT criterio ON a.tipo_cliente,a.sec_cliente FROM tipo_cliente,sec_cliente ##### Selecionando la informacion requerida de ventas. LET sele = "SELECT a.ventas,a.tipo_cliente,a.sec_cliente,b.nombre,", " a.fecha_factura,a.factura,a.sub_total,", " a.monto_desc,a.monto_itbi,a.porc_itbi,a.status_t ", " FROM vetb00002 a,vetb00004 b ", "WHERE ", " b.tipo_cliente = a.tipo_cliente and ", " b.sec_cliente = a.sec_cliente and ", " a.fecha_factura between ? and ? ", " ORDER BY 3 " DISPLAY "<< Buscando Informacion ... Espere Por Favor. >>" AT 19,14 ATTRIBUTE (REVERSE,BOLD) PREPARE busca_factura FROM sele DECLARE curr_fact SCROLL CURSOR FOR busca_factura OPEN curr_fact USING fecha_ini,fecha_fin ###### Enviando la informacion al printer del usuario START REPORT r_itbis TO "C:\\archivo" DISPLAY " " AT 19,14 DISPLAY "<< Reporte Generandose ... Por Favor Espere. >>" AT 19,14 ATTRIBUTE (REVERSE) LET cliente_ant = "1" LET idx_1 = 1 ###### Loop para enviar la inforacion a la rutina de impresion WHILE status != NOTFOUND FETCH curr_fact INTO facturas.* IF status = NOTFOUND THEN EXIT WHILE END IF # Verica que el usuario preciona la tecla de interrupcion del modulo IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) LET int_flag = false RETURN END IF LET prt_itbi.estatus = facturas.estatus # Valida la variable MES con 15 dias menos a la fecha final del reporte # para que asi poder buscar las notas de debito del mes anterior LET mes = fecha_fin - 15 #------------------------------------------------------------------------- # Validacion del record de impresion con el record de busqueda LET prt_itbi.ventas = facturas.ventas LET prt_itbi.nombre = facturas.nombre LET prt_itbi.fecha = facturas.fecha LET prt_itbi.factura = facturas.factura LET prt_itbi.valor = facturas.sub_total LET prt_itbi.descuento = facturas.monto_desc LET prt_itbi.itbi = facturas.monto_itbi LET prt_itbi.porc_itbi = facturas.porc_itbi # Compara si las ventas son de exportacion para grabar las que estan excentas IF facturas.ventas = "2" THEN LET prt_itbi.exentas = facturas.sub_total END IF # Variable alfa-numerica para tener el codigo del cliente en un solo campo y # poder utilizar las rupturas de control mas facil y # tambien para hacer el reporte mas rapido. Ejemplo si el cliente esta # consecutivo todo lo de ese cliente se busca para no repetir la misma busqueda LET cliente_act = facturas.tipo_cliente using "&&", facturas.sec_cliente using "&&&&" #------------------------------------------------------------------------------- # Busqueda de las notas de debito del mes anterior para imprimirlas LET enc = "N" IF cliente_act != cliente_ant THEN LET cliente_ant = facturas.tipo_cliente using "&&", facturas.sec_cliente using "&&&&" DECLARE notas CURSOR FOR SELECT num_doc,aplica_a,fecha_orig,valor FROM cctb00001 WHERE tipo_cliente = facturas.tipo_cliente and sec_cliente = facturas.sec_cliente and (tipo_doc = "AV" or tipo_doc = "NC") and month(fecha_orig) = month(mes) and year(fecha_orig) = year(mes) and status_t is null and valor > 0 FOREACH notas INTO prt_itbi.num_doc,prt_itbi.aplica_a,prt_itbi.fecha_orig, prt_itbi.valor_doc LET enc = "S" ###### Enviando la informacion a la funcion de reporte LET prt_itbi.estatus = facturas.estatus OUTPUT TO REPORT r_itbis(prt_itbi.*,fecha_ini,fecha_fin) END FOREACH END IF #------------------------------------------------------------------------- # Busqueda de las notas de debito del mes que se genere el reporte IF cliente_act != cliente_ant THEN LET cliente_ant = facturas.tipo_cliente using "&&", facturas.sec_cliente using "&&&&" DECLARE notas1 CURSOR FOR SELECT num_doc,aplica_a,fecha_orig,valor FROM cctb00001 WHERE tipo_cliente = facturas.tipo_cliente and sec_cliente = facturas.sec_cliente and (tipo_doc = "AV" or tipo_doc = "NC") and fecha_orig between fecha_ini and fecha_fin and status_t is null and valor > 0 FOREACH notas1 INTO prt_itbi.num_doc,prt_itbi.aplica_a,prt_itbi.fecha_orig, prt_itbi.valor_doc LET enc = "S" ###### Enviando la informacion a la funcion de reporte OUTPUT TO REPORT r_itbis(prt_itbi.*,fecha_ini,fecha_fin) END FOREACH #--------------------------------------------------------------------------- IF status = notfound THEN LET status = 0 END IF END IF IF enc = "N" THEN LET prt_itbi.num_doc = null LET prt_itbi.aplica_a = null LET prt_itbi.fecha_orig = null LET prt_itbi.valor_doc = null END IF IF enc = "N" THEN OUTPUT TO REPORT r_itbis(prt_itbi.*,fecha_ini,fecha_fin) END IF INITIALIZE prt_itbi.* TO NULL END WHILE FINISH REPORT r_itbis CLEAR SCREEN RUN "type C:\\archivo > %USPRINT%" END FUNCTION ##### Funcion del reporte, crea el formato de salida REPORT r_itbis(x,fecha_in,fecha_fi) ###### Definiendo las variables del reporte o salida DEFINE x RECORD ventas CHAR(1), nombre CHAR(30), fecha DATE, factura INTEGER, valor DECIMAL(12,2), descuento DECIMAL(12,2), itbi DECIMAL(12,2), porc_itbi DECIMAL(8,4), estatus CHAR(1), exentas DECIMAL(12,2), valor_doc DECIMAL(12,2), num_doc INTEGER, aplica_a INTEGER, fecha_orig DATE END RECORD DEFINE imprime CHAR(1) DEFINE fecha_in,fecha_fi DATE DEFINE tipo CHAR(2) DEFINE nombre_vend,apell_vend CHAR(30) DEFINE doble_on CHAR(3) DEFINE doble_off CHAR(3) DEFINE negrillas_on CHAR(6) DEFINE negrillas_off CHAR(6) DEFINE comp_on CHAR(3) DEFINE comp_off CHAR(3) DEFINE comprimido CHAR(3) DEFINE doce CHAR(3) DEFINE normal CHAR(3) DEFINE normall CHAR(3) DEFINE hora CHAR(5) DEFINE de1a30, de31a45, de46a60, masde60, total_saldo DECIMAL(12,2) DEFINE t30, t45, t60, tm60, tsaldo DECIMAL(12,2) DEFINE total_ventas,t_exentas,t_gravadas,t_itbi,t_devol,t_devol_i DECIMAL(12,2) DEFINE dias,cod_vend,sec_vend INTEGER OUTPUT TOP MARGIN 0 LEFT MARGIN 6 BOTTOM MARGIN 2 ##### Sorteando a la salida de la informacion ORDER BY x.factura ,x.nombre ##### Formateando la salida o condicionandola al tamano del papel o reporte FORMAT PAGE HEADER LET doble_on = ASCII 116 # LET doble_off = ASCII 20 LET negrillas_on = ASCII 027,ASCII 098 LET negrillas_off = ASCII 027,ASCII 099 # LET comp_on = ASCII 15 LET comp_off = ASCII 18 LET comprimido = ASCII 15 LET doce = ASCII 27, ASCII 77 LET normall = ASCII 030 LET normal = ASCII 27, ASCII 80 LET hora = time LET lj = (179 - LENGTH(p_companias.nombre CLIPPED))/2 # PRINT COLUMN 1, doce ,negrillas_on PRINT COLUMN 1, comprimido PRINT COLUMN 1, "ccprrp007", COLUMN lj, p_companias.nombre CLIPPED, COLUMN 172, "Pag. ", pageno using "###" PRINT COLUMN 75, "Sistema de Cuentas por Cobrar", COLUMN 170, today using "dd/mm/yyyy" PRINT COLUMN 73, "R E G I S T R O D E V E N T A S", COLUMN 175, hora PRINT COLUMN 78, fecha_in using "dd/mm/yy"," AL ", fecha_fi using "dd/mm/yy" SKIP 1 LINE PRINT COLUMN 1, "--------------------------------------------------", "--------------------------------------------------", "-------------------------------", "------------------------------------------------" PRINT COLUMN 138, "D E V O L U C I O N E S " PRINT COLUMN 43 , "FACTURA O ", COLUMN 82 , "V E N T A S", COLUMN 152, "N O T A S" PRINT COLUMN 6, "C l i e n t e", COLUMN 33, "FECHA", COLUMN 43, "COMPROVANTE", COLUMN 57, "TOTAL VENTAS", COLUMN 79, "EXENTAS", COLUMN 94, "GRAVADAS", COLUMN 104, "IMPORTE ITBIS |", COLUMN 120, "VALOR DEVOL.", COLUMN 136, "IMPORTE ITBIS", COLUMN 152, "DR/CR", COLUMN 161, "FACTURA NO.", COLUMN 174, "FECHA" PRINT COLUMN 1, "--------------------------------------------------", "--------------------------------------------------", "----------------------------------------", "---------------------------------------" # , negrillas_off IF total_ventas is null THEN LET total_ventas = 0 END IF IF t_exentas is null THEN LET t_exentas = 0 END IF IF t_gravadas is null THEN LET t_gravadas = 0 END IF IF t_itbi is null THEN LET t_itbi = 0 END IF IF t_devol is null THEN LET t_devol = 0 END IF IF t_devol_i is null THEN LET t_devol_i = 0 END IF BEFORE GROUP OF x.factura LET imprime = "S" ON EVERY ROW IF x.estatus = "E" THEN LET x.nombre = "---- NULA ----" LET x.valor = 0 LET x.descuento = 0 LET x.itbi = 0 LET x.exentas = 0 END IF IF x.ventas = "1" THEN LET tipo = "FT" ELSE LET tipo = "FE" END IF IF imprime = "S" THEN PRINT COLUMN 1, x.nombre, COLUMN 33, x.fecha using "dd/mm/yy", COLUMN 44, tipo,"-",x.factura using "&&&&&&", COLUMN 55, x.valor using "###,###,###.##", COLUMN 71, x.exentas using "###,###,###.##", COLUMN 88, x.valor - x.descuento using "###,###,###.##", COLUMN 104, x.itbi using "##,###,###.##"; END IF ##### Imprime el valor del documento sin el itbi PRINT COLUMN 117, x.valor_doc - (x.valor_doc *(x.porc_itbi/100)) using "###,###,###.##", ###### Imprime y calcula el itbi COLUMN 134, x.valor_doc*(x.porc_itbi/100) using "###,###,###.##", COLUMN 152, x.num_doc using "&&&&&&", COLUMN 164, x.aplica_a using "&&&&&", COLUMN 170, x.fecha_orig using "dd/mm/yy" IF imprime = "N" THEN LET x.valor = 0 LET x.descuento = 0 LET x.itbi = 0 LET x.exentas = 0 END IF LET imprime = "N" # Acumulacion Totales del reporte IF x.valor is null THEN LET x.valor = 0 END IF IF x.exentas is null THEN LET x.exentas = 0 END IF IF x.valor_doc is null THEN LET x.valor_doc = 0 END IF IF x.descuento is null THEN LET x.descuento = 0 END IF LET total_ventas = total_ventas + x.valor LET t_exentas = t_exentas + x.exentas LET t_gravadas = t_gravadas + (x.valor - x.descuento) LET t_itbi = t_itbi + x.itbi LET t_devol_i = t_devol_i + (x.valor_doc * (x.porc_itbi/100)) LET t_devol = t_devol + x.valor_doc ON LAST ROW ######### Imprimiendo los totales por columna PRINT negrillas_on PRINT COLUMN 24, "T O T A L M E S: ", COLUMN 55, total_ventas using "###,###,###.##", COLUMN 71, t_exentas using "###,###,###.##", COLUMN 88, t_gravadas - t_exentas using "###,###,###.##", COLUMN 104, t_itbi using "##,###,###.##", COLUMN 117, t_devol using "###,###,###.##", COLUMN 134, t_devol_i using "###,###,###.##" LET total_ventas = 0 LET t_exentas = 0 LET t_gravadas = 0 LET t_itbi = 0 LET t_devol_i = 0 LET t_devol = 0 PRINT negrillas_off END REPORT