{ ------------------------------------------------------------------------------- PROGRAMA : IPPRRP009 OBJETIVO : REPORTE EXISTENCIAS PROGRAMADOR : Juan Fco. Soto. FECHA REALIZACION : Febrero 1997 DIRECTOR PROYECTO : JOSE ALFREDO PAULINO ALEJO ------------------------------------------------------------------------------- } GLOBALS "ipprgb000.4gl" DEFINE noimprime CHAR(1),total_p dec(13,4), existencia_v DEC(12,3), existencia_negativa CHAR(2), costeo CHAR(10), grafico CHAR(2) MAIN DEFER INTERRUPT CALL ARG_VAL(1) RETURNING usuarios CALL ARG_VAL(2) RETURNING clave CALL ARG_VAL(3) RETURNING impresor CONNECT to "smarmotech" USER usuarios USING clave SELECT * INTO p_companias.* FROM companias CALL ipprrp09() END MAIN FUNCTION ipprrp09() DEFINE p_ano CHAR(4) DEFINE existe RECORD cod_cia LIKE iptb00002.cod_cia, descripcion CHAR(50), cod_n LIKE iptb00002.cod_n, cod_grupo LIKE iptb00002.cod_grupo, cod_tipo LIKE iptb00002.cod_tipo, cod_sec LIKE iptb00002.cod_sec, descrip_esp CHAR(45), descrip_ing CHAR(15), unidad_med CHAR(3), existe_act DECIMAL(12,3), existe_ant DEC(12,3), fecha DATE, codigo CHAR(25), total_c DECIMAL(12,2), total_a DEC(12,2), costo DECIMAL(12,5), costo_ant DEC(12,5) END RECORD DEFINE select_act STRING # WHENEVER ERROR CONTINUE OPTIONS FORM LINE 8, ERROR LINE 23, COMMENT LINE 21 OPEN FORM ipfmrp009 FROM "ipfmrp009" DISPLAY FORM ipfmrp009 LET tipo_papel = 1 CALL msgrp000(tipo_papel) INPUT BY NAME datos_cons.fech_in,datos_cons.fech_fi,noimprime,historico,servicios, existencia_negativa,grafico,costeo AFTER FIELD fech_in IF datos_cons.fech_in IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fech_in END IF AFTER FIELD fech_fi IF datos_cons.fech_fi IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fech_fi END IF AFTER INPUT END INPUT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) LET int_flag = false RETURN END IF LET p_ano = year(datos_cons.fech_fi) CONSTRUCT criterio ON a.cod_cia,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,d.bodega FROM cod_cia,cod_n,cod_grupo,cod_tipo,cod_sec,bodega BEFORE CONSTRUCT LET k1 = '1' CALL bodegas(k1) AFTER CONSTRUCT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) LET int_flag = FALSE RETURN END IF EXIT CONSTRUCT END CONSTRUCT IF historico = "N" THEN LET select_act = "SELECT a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, ", " a.descrip_ing, a.unidad_med, ISNULL(SUM(d.cantidad_2),0) ", "FROM iptb00002 a LEFT OUTER JOIN iptb00006 d ON ", " (a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND ", " a.cod_tipo = d.cod_tipo AND a.cod_sec = d.cod_sec),iptb00022 e ", " WHERE a.cod_cia = e.cod_cia AND a.status_t IS NULL AND ", " d.status_t IS NULL and (d.fecha <= ?) AND ", " a.control_existencia = 'SI' AND ",criterio CLIPPED, " GROUP BY a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, a.descrip_ing, a.unidad_med ", " ORDER BY a.cod_cia,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec " IF existencia_negativa ="SI" THEN LET select_act= "SELECT a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, ", " a.descrip_ing, a.unidad_med, ISNULL(SUM(d.cantidad_2),0) ", "FROM iptb00002 a LEFT OUTER JOIN iptb00006 d ON ", " (a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND ", " a.cod_tipo = d.cod_tipo AND a.cod_sec = d.cod_sec),iptb00022 e ", " WHERE a.cod_cia = e.cod_cia AND a.status_t IS NULL AND ", " d.status_t IS NULL and (d.fecha <= ?) AND ",criterio CLIPPED, " GROUP BY a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, a.descrip_ing, a.unidad_med ", " HAVING SUM(d.cantidad_2) <0 ", " ORDER BY a.cod_cia,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec " END IF ELSE LET select_act = "SELECT a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, ", " a.descrip_ing, a.unidad_med, SUM(d.cantidad_2) ", "FROM historicoMTECH.dbo.iptb00002 a, historicoMTECH.dbo.iptb00006 d,historicoMTECH.dbo.iptb00022 e ", "WHERE (a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND ", " a.cod_tipo = d.cod_tipo AND a.cod_sec = d.cod_sec) AND ", " a.cod_cia = e.cod_cia AND a.status_t IS NULL AND ", " d.status_t IS NULL and (d.fecha <= ?) AND ",criterio CLIPPED, " GROUP BY a.cod_cia,e.descripcion,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp, a.descrip_ing, a.unidad_med ", " ORDER BY a.cod_cia,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec " END IF DISPLAY "<< Estoy Buscando Los Balances Actuales >>" AT 19,14 ATTRIBUTE (REVERSE,BOLD) IF grafico = "SI" THEN CALL selectOutput() RETURNING r_output # IF r_output = 'XLSX' THEN # LET r_output="SVG" # END IF CALL configureOutput(r_output) RETURNING HANDLER START REPORT existencia TO XML HANDLER HANDLER ELSE CALL defecto(usuarios,clave,impresor) RETURNING imprime,negrilla_on,negrillas_of, doble_on,doble_off,comp_on,comp_off, doce,normal,archivo,copia START REPORT existencia TO archivo END IF PREPARE busca_act FROM select_act DECLARE busca_balan_act CURSOR FOR busca_act OPEN busca_balan_act USING datos_cons.fech_fi LET selec = "SELECT SUM(d.cantidad_2) FROM iptb00006 d", " WHERE d.status_t is null AND ", " (d.cod_n=? AND d.cod_grupo=? AND ", " d.cod_tipo = ? AND d.cod_sec = ?) and (d.fecha <= ?) " PREPARE cmdexiste FROM selec DISPLAY "<< Reporte Generandose ... Por Favor Espere. >>" AT 19,14 ATTRIBUTE (REVERSE) WHILE status != notfound FETCH busca_balan_act INTO existe.* IF status = notfound THEN EXIT WHILE END IF IF int_flag THEN LET int_flag = FALSE LET numero_msg = 2 CALL msg(numero_msg) RETURN END IF IF servicios = "N" THEN IF existe.cod_n = 12 OR existe.cod_n = 5 OR existe.cod_n = 25 THEN CONTINUE WHILE END IF END IF LET existe.costo = 0 LET existe.costo_ant=0 IF existencia_negativa = "NO" THEN IF noimprime = "S" AND existe.existe_act <= 0 THEN CONTINUE WHILE END IF END IF IF historico = "N" THEN LET existe.costo=0 SELECT MAX(d.material+d.labor+d.gastos) INTO existe.costo FROM iptb00004 d WHERE d.mes_fin=12 AND d.status_t is null AND d.ano = year(datos_cons.fech_fi) and d.cod_n=existe.cod_n AND d.cod_grupo=existe.cod_grupo AND d.cod_tipo = existe.cod_tipo AND d.cod_sec = existe.cod_sec IF existe.costo IS NULL THEN LET existe.costo=0 END IF LET existe.costo_ant=0 SELECT MAX(d.material+d.labor+d.gastos) INTO existe.costo_ant FROM iptb00004 d WHERE d.mes_fin=12 AND d.status_t is null AND d.ano = year(datos_cons.fech_in) and d.cod_n=existe.cod_n AND d.cod_grupo=existe.cod_grupo AND d.cod_tipo = existe.cod_tipo AND d.cod_sec = existe.cod_sec IF existe.costo_ant IS NULL THEN LET existe.costo_ant = 0 END IF ELSE LET selec = "SELECT MAX(d.material+d.labor+d.gastos) FROM historicoMTECH.dbo.iptb00004 d", " WHERE d.mes_fin=12 AND d.status_t is null AND ", " d.ano = ? and ", " d.cod_n=? AND d.cod_grupo=? AND ", " d.cod_tipo = ? AND d.cod_sec = ? " PREPARE cmdcosto FROM selec EXECUTE cmdcosto INTO existe.costo USING p_ano,existe.cod_n,existe.cod_grupo, existe.cod_tipo,existe.cod_sec END IF IF existe.costo IS NULL THEN LET existe.costo =0 END IF IF existe.costo_ant IS NULL THEN LET existe.costo_ant =0 END IF IF costeo <> "TODOS" THEN IF costeo = "SIN COSTO" AND existe.costo <> 0 THEN CONTINUE WHILE END IF END IF LET existencia_v = 0 LET existe.total_a = 0 LET existe.total_c = 0 EXECUTE cmdexiste INTO existencia_v USING existe.cod_n,existe.cod_grupo,existe.cod_tipo,existe.cod_sec, datos_cons.fech_in IF existencia_v IS NULL THEN LET existencia_v =0 END IF LET existe.existe_ant=existencia_v LET existe.total_a = existe.costo_ant*existencia_v LET existe.total_c = existe.existe_act * existe.costo LET existe.codigo = existe.cod_n using "&&&&",existe.cod_grupo using "&&&&", existe.cod_tipo using "&&&&",existe.cod_sec using "&&&&&&&" IF existe.total_a IS NULL THEN LET existe.total_a=0 END IF IF existe.total_c IS NULL THEN LET existe.total_c=0 END IF OUTPUT TO REPORT existencia(existe.*) END WHILE FINISH REPORT existencia IF grafico <> "SI" THEN LET cmd = NULL LET cmd ='copy ',archivo CLIPPED,' ', FGL_GETENV("FGLSPOOL")||"\\IPRP09.txt" RUN cmd CALL ui.Interface.frontCall("standard","getenv", ["FILEREPORTE"], [dcmd] ) LET cmd= FGL_GETENV("FGLSPOOL")||"\\IPRP09.txt" CALL fgl_putfile(cmd,dcmd) LET opt = fgl_winquestion("Atencion","Desea Imprimir Reporte?", "yes","yes|no","question",0) LET opt = UPSHIFT(opt) IF opt = "YES" THEN RUN imprime END IF END IF LET total_p = 0 END FUNCTION REPORT existencia(x) DEFINE x RECORD cod_cia LIKE iptb00002.cod_cia, descripcion CHAR(50), cod_n LIKE iptb00002.cod_n, cod_grupo LIKE iptb00002.cod_grupo, cod_tipo LIKE iptb00002.cod_tipo, cod_sec LIKE iptb00002.cod_sec, descrip_esp CHAR(45), descrip_ing CHAR(15), unidad_med CHAR(3), existe_act DECIMAL(12,3), existe_ant DEC(12,3), fecha DATE , codigo CHAR(7), total_c DECIMAL(12,2), total_a DEC(12,2), costo DECIMAL(12,5), costo_ant DEC(12,5) END RECORD, total_cia,total_gral,total_cia_ant,total_gral_ant DEC(12,2) DEFINE tt INTEGER 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(3) DEFINE hora CHAR(5) DEFINE l INTEGER OUTPUT LEFT MARGIN 0 RIGHT MARGIN 0 BOTTOM MARGIN 0 PAGE LENGTH 130 # ORDER BY x.cod_n,x.cod_grupo,x.cod_tipo,x.cod_sec FORMAT FIRST PAGE HEADER IF grafico <> "SI" THEN 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 doce = ASCII 030 END IF LET hora = time LET l = (130 - LENGTH(p_companias.nombre CLIPPED))/2 PRINT COLUMN 1, comp_on PRINT COLUMN 1, "ipprrp009", COLUMN l, p_companias.nombre CLIPPED, COLUMN 123, "Pag. ",pageno using "###" PRINT COLUMN 49, "Sistema de Inventario Productos ", COLUMN 123, today using "dd/mm/yyyy" PRINT COLUMN 49, " Existencia a Diferente Fechas", COLUMN 126, hora IF historico = 'N' THEN PRINT COLUMN 60, 'NO HISTORICO' ELSE PRINT COLUMN 64, 'HISTORICO' END IF IF existencia_negativa = "S" THEN PRINT COLUMN 60, "EXISTENCIA NEGATIVA" ELSE PRINT " " END IF SKIP 1 LINES PRINT COLUMN 1, "--------------------------------------------------", "--------------------------------------------------", "--------------------------------------------------", "-------" PRINT COLUMN 69, "Existencia", 5 spaces, "Existencia", 5 spaces, "Costo Std", 5 spaces, "Costo Std", 7 spaces, "Total", 15 spaces, "Total" PRINT COLUMN 1, "Codigo", COLUMN 21, "Descripcion", COLUMN 69, "Al ",datos_cons.fech_in using "dd/mm/yyyy", 2 spaces, "Al ", datos_cons.fech_fi using "dd/mm/yyyy", 5 spaces ,"Al ",datos_cons.fech_in USING "yyyy", 4 spaces ,"Al ",datos_cons.fech_fi USING "yyyy", 8 spaces, "Al ",datos_cons.fech_in using "yyyy", 15 spaces, "Al ",datos_cons.fech_fi USING "yyyy" PRINT COLUMN 1, "--------------------------------------------------", "--------------------------------------------------", "--------------------------------------------------", "-------" BEFORE GROUP OF x.cod_cia LET total_cia = 0 LET total_cia_ant =0 IF total_gral IS NULL THEN LET total_gral =0 LET total_gral_ant =0 END IF SKIP 1 LINE PRINT COLUMN 2," ORIGEN: ",x.descripcion SKIP 1 LINE ON EVERY ROW IF tt IS NULL THEN LET tt = 0 END IF IF total_p is null THEN LET total_p = 0 END IF LET total_p = x.total_c + total_p LET total_cia = x.total_c+ total_cia LET total_cia_ant = x.total_a + total_cia_ant LET descripcion = x.descrip_esp CLIPPED IF x.total_c <> 0 THEN LET tt = tt + 1 PRINT COLUMN 1, x.cod_n USING "&&&&","-",x.cod_grupo USING "&&&&","-", x.cod_tipo USING "&&&&","-",x.cod_sec USING "&&&&&&"," ", COLUMN 21, X.descrip_esp," ",x.unidad_med , COLUMN 48 , x.existe_ant USING "---,-&&.###", 2 spaces, x.existe_act USING "---,-&&.###", 2 spaces, x.costo_ant USING "###,###.####", 2 SPACES, x.costo USING "###,###.####", 2 spaces, x.total_a USING "-,---,---,-##.##", 2 spaces, x.total_c USING "-,---,---,-##.##" END IF AFTER GROUP OF x.cod_cia PRINT COLUMN 124, "-------------", 2 spaces, "--------------" PRINT COLUMN 121,total_cia_ant USING "----,---,-##.##", 2 spaces, total_cia USING "-,---,---,-##.##" LET total_gral = total_gral + total_cia LET total_gral_ant = total_cia_ant + total_gral_ant ON LAST ROW PRINT COLUMN 124, "-------------", 2 spaces, "--------------" PRINT COLUMN 122,total_gral_ant USING "####,###,###.##", 2 spaces, total_gral USING "###,###,###.##" SKIP 1 LINES PRINT COLUMN 1, "==================================================", "==================================================", "===============================================" PRINT COLUMN 4, "Total Registros Impresos =", tt USING "<<<<" PRINT comp_off END REPORT