{ ------------------------------------------------------------------ PROGRAMA : COPRMT012 OBJETIVO : Capturar, Modificar, Eliminar registros de la Tabla de Plan de Produccion PROGRAMADOR : Lic. Abner Montalvo Z. FECHA REALIZACION : Septiembre 19, 1992. ------------------------------------------------------------------ } GLOBALS "coprgb000.4gl" DEFINE cantidad_meses SMALLINT, fecha_inicial DATE, mes_proceso SMALLINT, nombre_mes CHAR(10), respuesta CHAR(1), rango_p CHAR(4), dia2 INTEGER, dia1 INTEGER, mes2 INTEGER, mes1 INTEGER, ano1 INTEGER, fecha1 CHAR(10), fecha2 CHAR(10), fecha3 CHAR(6), cod_n_ant SMALLINT, cod_grupo_ant SMALLINT, cod_tipo_ant SMALLINT, cod_sec_ant SMALLINT, fecha_ant DATE, cancelar CHAR(1), mes_final SMALLINT, dia_inicial SMALLINT, mes_ant SMALLINT, total_reg SMALLINT, uso_formula CHAR(1), status_reg CHAR(1) FUNCTION coprmt012() WHENEVER ERROR CONTINUE CLEAR SCREEN OPTIONS FORM LINE 9, ERROR LINE 23, COMMENT LINE 21 OPEN FORM cofmmt012 FROM "cofmmt012" DISPLAY FORM cofmmt012 CALL pantalla() DISPLAY "coprmt012" AT 4,3 DISPLAY "Plan de Produccion" AT 6,31 MENU "OPCIONES" COMMAND "Adiciona/Modifica" " Adiciona/Modifica Plan Cancela Operacion" LET int_flag = FALSE CLEAR FORM CALL copcad012() COMMAND "Salir" "Retorna Menu Anterior" EXIT MENU END MENU END FUNCTION FUNCTION copcad012() LABEL inicio: INITIALIZE cantidad_meses, fecha_inicial, mes_proceso, nombre_mes, respuesta, dia2, dia1, mes1, mes2, ano1, fecha1, fecha2, rango_p, ant_art.cod_n, ant_art.cod_grupo, ant_art.cod_tipo, ant_art.cod_sec, modifica, cod_n_ant, cod_grupo_ant, cod_tipo_ant, cod_sec_ant, fecha_ant, cancelar, mes_ant, total_reg TO NULL LET modifica = "N" CALL inicializa_arreglo() CALL inicializa_arreglo1() LABEL modificar: INPUT BY NAME cantidad_meses,fecha_inicial,ant_art.cod_n, ant_art.cod_grupo,ant_art.cod_tipo,ant_art.cod_sec WITHOUT DEFAULTS ON KEY (CONTROL-W) CASE WHEN INFIELD (cod_n) CALL busca_pt() IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) NEXT FIELD cod_n END IF IF NOT int_flag THEN DISPLAY ant_art.cod_n TO cod_n DISPLAY ant_art.cod_grupo TO cod_grupo DISPLAY ant_art.cod_tipo TO cod_tipo DISPLAY ant_art.cod_sec TO cod_sec DISPLAY descrip1 TO descrip_esp EXIT INPUT END IF LET int_flag = FALSE WHEN INFIELD (cod_grupo) CALL busca_pt() IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) NEXT FIELD cod_grupo END IF IF NOT int_flag THEN DISPLAY ant_art.cod_n TO cod_n DISPLAY ant_art.cod_grupo TO cod_grupo DISPLAY ant_art.cod_tipo TO cod_tipo DISPLAY ant_art.cod_sec TO cod_sec DISPLAY descrip1 TO descrip_esp EXIT INPUT END IF LET int_flag = FALSE WHEN INFIELD (cod_tipo) CALL busca_pt() IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) NEXT FIELD cod_tipo END IF IF NOT int_flag THEN DISPLAY ant_art.cod_n TO cod_n DISPLAY ant_art.cod_grupo TO cod_grupo DISPLAY ant_art.cod_tipo TO cod_tipo DISPLAY ant_art.cod_sec TO cod_sec DISPLAY descrip1 TO descrip_esp EXIT INPUT END IF LET int_flag = FALSE WHEN INFIELD (cod_sec) CALL busca_pt() IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) NEXT FIELD cod_sec END IF IF NOT int_flag THEN DISPLAY ant_art.cod_n TO cod_n DISPLAY ant_art.cod_grupo TO cod_grupo DISPLAY ant_art.cod_tipo TO cod_tipo DISPLAY ant_art.cod_sec TO cod_sec DISPLAY descrip1 TO descrip_esp EXIT INPUT END IF LET int_flag = FALSE END CASE BEFORE FIELD cantidad_meses IF modifica = "S" THEN NEXT FIELD fecha_inicial END IF AFTER FIELD cantidad_meses IF cantidad_meses IS NULL OR cantidad_meses = 0 THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD cantidad_meses END IF AFTER FIELD fecha_inicial IF fecha_inicial IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD fecha_inicial END IF IF modifica = "S" THEN IF fecha_inicial < fecha_ant THEN LET numero_msg = 51 CALL msg(numero_msg) NEXT FIELD fecha_inicial END IF CALL mes_indicador() END IF LET dia1 = DAY(fecha_inicial) USING "&&" LET mes1 = MONTH(fecha_inicial) USING "&&" LET ano1 = YEAR(fecha_inicial) LET mes_proceso = mes1 IF dia1 > 15 THEN LET mes_proceso = mes_proceso + 1 IF mes_proceso > 12 THEN LET mes_proceso = 1 END IF END IF AFTER FIELD cod_sec IF ant_art.cod_n IS NULL AND ant_art.cod_grupo IS NULL AND ant_art.cod_tipo IS NULL AND ant_art.cod_sec IS NULL THEN LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD cod_n ELSE SELECT a.descrip_esp INTO descrip1 FROM intb00001 a,iptb00002 b WHERE a.cod_n=ant_art.cod_n AND a.cod_grupo=ant_art.cod_grupo AND a.cod_tipo=ant_art.cod_tipo AND a.cod_sec=ant_art.cod_sec AND a.cod_n=b.cod_n AND a.cod_grupo=b.cod_grupo AND a.cod_tipo= b.cod_tipo AND a.cod_sec = b.cod_sec AND b.status_t IS NULL IF status >= 0 THEN IF status = NOTFOUND THEN LET numero_msg = 26 CALL msg(numero_msg) NEXT FIELD cod_n ELSE DISPLAY descrip1 TO descrip_esp END IF ELSE CALL integridad() IF bandera = 1 THEN LET bandera = 0 RETURN END IF END IF END IF LET uso_formula = null LET status_reg = null SELECT a.uso, a.status_t INTO uso_formula, status_reg FROM catb00002 a, catb00001 b WHERE b.cod_n_pt = ant_art.cod_n and b.cod_grupo_pt = ant_art.cod_grupo and b.cod_tipo_pt = ant_art.cod_tipo and b.cod_sec_pt = ant_art.cod_sec and a.num_formula = b.num_formula IF STATUS = NOTFOUND THEN LET numero_msg = 120 CALL msg(numero_msg) NEXT FIELD cod_n END IF IF status_reg = "E" THEN LET numero_msg = 121 CALL msg(numero_msg) NEXT FIELD cod_n END IF IF uso_formula = "N" THEN LET numero_msg = 122 CALL msg(numero_msg) NEXT FIELD cod_n END IF AFTER INPUT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) RETURN END IF LET uso_formula = null LET status_reg = null SELECT a.uso, a.status_t INTO uso_formula, status_reg FROM catb00002 a, catb00001 b WHERE b.cod_n_pt = ant_art.cod_n and b.cod_grupo_pt = ant_art.cod_grupo and b.cod_tipo_pt = ant_art.cod_tipo and b.cod_sec_pt = ant_art.cod_sec and a.num_formula = b.num_formula IF STATUS = NOTFOUND THEN LET numero_msg = 120 CALL msg(numero_msg) NEXT FIELD cod_n END IF IF status_reg = "E" THEN LET numero_msg = 121 CALL msg(numero_msg) NEXT FIELD cod_n END IF IF uso_formula = "N" THEN LET numero_msg = 122 CALL msg(numero_msg) NEXT FIELD cod_n END IF EXIT INPUT END INPUT LET mes_final = MONTH(fecha_inicial) FOR idx = 1 to cantidad_meses LET mes_final = mes_final + 1 IF mes_final > 12 THEN LET mes_final = 1 END IF END FOR IF dia1 > 15 THEN LET mes_final = mes_final + 1 IF mes_final > 12 THEN LET mes_final = 1 END IF END IF LET rango_p = MONTH(fecha_inicial) USING "&&", mes_final USING "&&" LET fecha3 = fecha_inicial USING "ddmmyy" LET total_reg = null SELECT count(*) INTO total_reg FROM cotb00026 WHERE rango_plan = rango_p AND cod_n = ant_art.cod_n AND cod_grupo = ant_art.cod_grupo AND cod_tipo = ant_art.cod_tipo AND cod_sec = ant_art.cod_sec AND fecha_ini = fecha3 AND status_t is NULL IF status >= 0 THEN IF status = notfound THEN LET numero_msg = 12 CALL msg(numero_msg) END IF ELSE CALL integridad() IF bandera = 1 THEN LET bandera = 0 RETURN END IF END IF IF total_reg = 0 OR total_reg IS NULL THEN LET fecha_ant = null LET cod_n_ant = null LET cod_grupo_ant = null LET cod_tipo_ant = null LET cod_sec_ant = null GO TO calcula END IF IF modifica = "S" THEN IF fecha_ant != fecha_inicial OR cod_n_ant != ant_art.cod_n OR cod_grupo_ant != ant_art.cod_grupo OR cod_tipo_ant != ant_art.cod_tipo OR cod_sec_ant != ant_art.cod_sec THEN IF total_reg IS NOT NULL THEN LET numero_msg = 50 CALL msg(numero_msg) GO TO modificar END IF END IF END IF IF modifica = "N" THEN CALL acepta_respuesta() END IF IF modifica = "N" THEN IF respuesta = "S" or respuesta = "s" THEN LET fecha_ant = fecha_inicial LET cod_n_ant = ant_art.cod_n LET cod_grupo_ant = ant_art.cod_grupo LET cod_tipo_ant = ant_art.cod_tipo LET cod_sec_ant = ant_art.cod_sec CALL desplega_arreglo() LET modifica = "S" GO TO modificar ELSE CLEAR FORM LET modifica = "N" GO TO inicio END IF END IF LABEL calcula: CALL inicializa_arreglo() FOR idx = 1 TO cantidad_meses IF mes1 = 2 THEN IF dia1 > 28 THEN LET dia2 = dia1 LET dia1 = 28 END IF END IF IF idx > 1 THEN LET arr_plan_prod[idx].fecha_ini = dia1+1 USING "&&","/", mes1 USING "&&","/", ano1 USING "####" ELSE LET arr_plan_prod[idx].fecha_ini = dia1 USING "&&","/", mes1 USING "&&","/", ano1 USING "####" END IF IF mes1 = 2 THEN IF dia2 > 28 THEN LET dia1 = dia2 LET dia2 = 0 END IF END IF SELECT descrip INTO nombre_mes FROM mestable WHERE mes = mes_proceso IF status >= 0 THEN IF status = notfound THEN LET numero_msg = 12 CALL msg(numero_msg) END IF ELSE CALL integridad() IF bandera = 1 THEN LET bandera = 0 END IF END IF LET arr_plan_prod[idx].mes = nombre_mes IF modifica = "S" THEN IF arr1_plan_prod[mes_ant].fecha_ini[4,5] = mes1 THEN LET arr_plan_prod[idx].cantidad = arr1_plan_prod[mes_ant].cantidad LET mes_ant = mes_ant + 1 END IF ELSE LET arr_plan_prod[idx].cantidad = NULL END IF LET mes1 = mes1 + 1 IF mes1 > 12 THEN LET mes1 = 1 LET ano1 = ano1 + 1 END IF LET mes_proceso = mes_proceso + 1 IF mes_proceso > 12 THEN LET mes_proceso = 1 END IF IF mes1 = 2 THEN IF dia1 > 28 THEN LET dia2 = dia1 LET dia1 = 28 END IF END IF LET arr_plan_prod[idx].fecha_fin = dia1 USING "&&","/", mes1 USING "&&","/", ano1 USING "####" IF mes1 = 2 THEN IF dia2 > 28 THEN LET dia1 = dia2 LET dia2 = 0 END IF END IF END FOR IF dia1 > 15 THEN LET mes2 = mes1 LET mes1 = mes1 + 1 IF mes1 > 12 THEN LET mes1 = 1 END IF END IF LET rango_p = MONTH(fecha_inicial) USING "&&", mes1 USING "&&" IF dia1 > 15 THEN LET mes1 = mes2 END IF CALL set_count(idx - 1) LABEL arreglo: INPUT ARRAY arr_plan_prod WITHOUT DEFAULTS FROM sc_plan_prod.* AFTER ROW LET fila = scr_line() LET curr = arr_curr() AFTER FIELD cantidad LET curr = arr_curr() IF curr = cantidad_meses THEN EXIT INPUT END IF AFTER INPUT IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) RETURN END IF END INPUT PROMPT "Datos Correctos ? " FOR respuesta IF respuesta = "s" OR respuesta = "S" THEN DELETE FROM cotb00026 where rango_plan = rango_p and cod_n = ant_art.cod_n and cod_grupo = ant_art.cod_grupo and cod_tipo = ant_art.cod_tipo and cod_sec = ant_art.cod_sec FOR idx = 1 to cantidad_meses IF arr_plan_prod[idx].cantidad IS NOT NULL THEN LET fecha1 = arr_plan_prod[idx].fecha_ini[1,6], arr_plan_prod[idx].fecha_ini[9,10] LET fecha2 = arr_plan_prod[idx].fecha_fin[1,6], arr_plan_prod[idx].fecha_fin[9,10] INSERT INTO cotb00026 VALUES (rango_p,fecha1,ant_art.cod_n,ant_art.cod_grupo, ant_art.cod_tipo,ant_art.cod_sec,fecha2, arr_plan_prod[idx].cantidad,null,user,current, null, null) IF status < 0 THEN CALL integridad() IF bandera = 1 THEN LET bandera = 0 END IF END IF END IF END FOR IF fecha_ant = fecha_inicial AND cod_n_ant = ant_art.cod_n AND cod_grupo_ant = ant_art.cod_grupo AND cod_tipo_ant = ant_art.cod_tipo AND cod_sec_ant = ant_art.cod_sec THEN LET numero_msg = 13 CALL msg(numero_msg) ELSE LET numero_msg = 1 CALL msg(numero_msg) END IF CALL inicializa_arreglo() CALL inicializa_arreglo1() ELSE GO TO arreglo END IF END FUNCTION FUNCTION desplega_arreglo() # Esta funcion desplega los datos del plan existente en la pantalla LET selec = "SELECT fecha_ini, fecha_fin, cantidad ", "FROM cotb00026 ", "WHERE cod_n = ? AND cod_grupo = ? AND cod_tipo = ? AND cod_sec = ? AND ", " rango_plan = ? AND status_t is null ORDER BY 1 " PREPARE busca FROM selec DECLARE proceso CURSOR FOR busca OPEN proceso USING ant_art.cod_n, ant_art.cod_grupo, ant_art.cod_tipo, ant_art.cod_sec, rango_p LET idx = 1 WHILE status != NOTFOUND FETCH proceso INTO arr1_plan_prod[idx].fecha_ini, arr1_plan_prod[idx].fecha_fin, arr1_plan_prod[idx].cantidad IF status = NOTFOUND THEN EXIT WHILE END IF LET scr_l = scr_line() LET arr1_plan_prod[idx].fecha_ini = arr1_plan_prod[idx].fecha_ini USING "&&/&&/&&" LET arr1_plan_prod[idx].fecha_fin = arr1_plan_prod[idx].fecha_fin USING "&&/&&/&&" LET mes1 = arr1_plan_prod[idx].fecha_ini[4,5] IF arr1_plan_prod[idx].fecha_ini[1,2] > "15" THEN LET mes1 = mes1 + 1 END IF SELECT descrip INTO arr1_plan_prod[idx].mes FROM mestable WHERE mes=mes1 IF status >= 0 THEN IF status = notfound THEN LET numero_msg = 12 IF int_flag THEN LET int_flag = FALSE EXIT WHILE END IF CALL msg(numero_msg) END IF ELSE CALL integridad() IF bandera = 1 THEN LET bandera = 0 END IF END IF IF idx <= 5 THEN DISPLAY arr1_plan_prod[idx].fecha_ini TO sc_plan_prod[idx].fecha_ini DISPLAY arr1_plan_prod[idx].fecha_fin TO sc_plan_prod[idx].fecha_fin DISPLAY arr1_plan_prod[idx].mes TO sc_plan_prod[idx].mes DISPLAY arr1_plan_prod[idx].cantidad TO sc_plan_prod[idx].cantidad END IF LET idx = idx + 1 END WHILE CALL set_count(idx - 1) RETURN END FUNCTION FUNCTION mes_indicador() # Busca el mes a partir del cual toma las cantidades y las despliega para evitar # que el usuario las digite. Esta funcion es validad solamente cuando la fecha # digitada es mayor o igual a la fecha que tenia el plan anteriormente. LET mes_ant = MONTH(fecha_inicial) USING "&&" FOR idx = 1 TO cantidad_meses IF arr1_plan_prod[idx].fecha_ini[4,5] = mes_ant THEN LET mes_ant = idx USING "&&" EXIT FOR END IF END FOR END FUNCTION FUNCTION acepta_respuesta() LET respuesta = null PROMPT "Plan Existe. Deseas Modificarlo ?" FOR respuesta END FUNCTION FUNCTION inicializa_arreglo() FOR idx = 1 TO 100 IF arr_plan_prod[idx].fecha_ini IS NULL THEN EXIT FOR END IF LET arr_plan_prod[idx].fecha_ini = NULL LET arr_plan_prod[idx].fecha_fin = NULL LET arr_plan_prod[idx].mes = NULL LET arr_plan_prod[idx].cantidad = NULL END FOR END FUNCTION FUNCTION inicializa_arreglo1() FOR idx = 1 TO 100 IF arr1_plan_prod[idx].fecha_ini IS NULL THEN EXIT FOR END IF LET arr1_plan_prod[idx].fecha_ini = NULL LET arr1_plan_prod[idx].fecha_fin = NULL LET arr1_plan_prod[idx].mes = NULL LET arr1_plan_prod[idx].cantidad = NULL END FOR END FUNCTION FUNCTION busca_pt() # Busca el codigo y descripcion de los productos terminados, segun el criterio # de seleccion. OPEN WINDOW busqueda AT 7,12 WITH FORM "cofmwd009" ATTRIBUTE (BORDER,FORM LINE FIRST + 2,COMMENT LINE LAST) LET int_flag = false CONSTRUCT criterio ON intb00001.descrip_esp FROM descrip_esp LET selec2 = "SELECT a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp", "FROM intb00001 a,iptb00002 b ", "WHERE a.cod_n = b.cod_n and a.cod_grupo = b.cod_grupo and ", " a.cod_tipo = b.cod_tipo and a.cod_sec = b.cod_sec and ", " a.status_t is null AND ",criterio clipped," ORDER BY 5 " IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) GO TO sale9 END IF PREPARE busca2 FROM selec2 IF status >= 0 THEN IF status = notfound THEN LET numero_msg = 12 CALL msg(numero_msg) END IF ELSE CALL integridad() IF bandera = 1 THEN LET bandera = 0 END IF END IF DECLARE johnn2 CURSOR FOR busca2 LET idx = 1 FOREACH johnn2 INTO busca_ma[idx].* IF int_flag THEN LET numero_msg = 2 CALL msg(numero_msg) EXIT FOREACH END IF LET busca_pt1[idx].codigo = busca_ma[idx].cod_n USING "&","-", busca_ma[idx].cod_grupo USING "&","-", busca_ma[idx].cod_tipo USING "&&","-", busca_ma[idx].cod_sec USING "&&&" LET busca_pt1[idx].descrip_esp = busca_ma[idx].descrip_esp LET idx = idx + 1 END FOREACH CALL SET_COUNT(idx-1) DISPLAY ARRAY busca_pt1 TO s_desp2.* LET curr1 = arr_curr() LET ant_art.cod_n = busca_pt1[curr1].codigo[1] LET ant_art.cod_grupo = busca_pt1[curr1].codigo[3] LET ant_art.cod_tipo = busca_pt1[curr1].codigo[5,6] LET ant_art.cod_sec = busca_pt1[curr1].codigo[8,10] LET descrip1 = busca_pt1[curr1].descrip_esp LABEL sale9: CLOSE WINDOW busqueda END FUNCTION