GLOBALS "veprgb000.4gl" DEFINE arr_ofertas DYNAMIC ARRAY OF RECORD id int, cod_n smallint, cod_grupo smallint, cod_tipo smallint, cod_sec smallint, descripcion VARCHAR(100), unidad_med VARCHAR(4), porc_desc DEC(12,2), fecha_inicial DATETIME YEAR TO MINUTE, fecha_final DATETIME YEAR TO MINUTE END RECORD, datos_c RECORD documento INT, fecha DATE, descripcion_oferta VARCHAR(60), porc_desc1 DEC(12,2), fecha1 DATETIME YEAR TO MINUTE, fecha2 DATETIME YEAR TO MINUTE END RECORD DEFINE xus_crea,xus_mod VARCHAR(50), xfech_crea,xfech_mod DATETIME YEAR TO MINUTE, adiciona BOOLEAN, porc_Desc1 DEC(12,2), no_registros INT MAIN DEFER INTERRUPT CALL STARTLOG("veprmt023.log") CALL ARG_VAL(1) RETURNING usuarios CALL ARG_VAL(2) RETURNING clave CONNECT TO "decomarmol" AS "MSSQL" USER usuarios USING clave CALL veprmt023() END MAIN FUNCTION veprmt023() OPEN WINDOW w1 AT 1,1 WITH FORM "vefmmt023" MENU ON ACTION nuevo LET adiciona = TRUE CALL veprad23() ON ACTION modificar LET adiciona = FALSE CALL veprmf023() ON ACTION salir EXIT MENU END MENU CLOSE WINDOW w1 END FUNCTION FUNCTION veprad23() DIALOG ATTRIBUTES(UNBUFFERED, FIELD ORDER FORM) INPUT BY NAME datos_c.* BEFORE INPUT LET datos_c.fecha = TODAY DISPLAY BY NAME datos_c.fecha NEXT FIELD descripcion_oferta AFTER INPUT IF datos_c.fecha2 < datos_c.fecha1 THEN CALL fgl_winmessage("ERROR","FECHA FINAL NO PUEDE SER MENOR A LA INICIAL","INFO") NEXT FIELD fecha1 END IF END INPUT INPUT ARRAY arr_ofertas FROM sofertas.* ATTRIBUTE(WITHOUT DEFAULTS) AFTER FIELD cod_sec IF arr_ofertas[arr_curr()].cod_sec IS NOT NULL THEN CALL busca_producto(arr_ofertas[arr_curr()].cod_n,arr_ofertas[arr_curr()].cod_grupo, arr_ofertas[arr_curr()].cod_tipo,arr_ofertas[arr_curr()].cod_sec) RETURNING arr_ofertas[arr_curr()].descripcion DISPLAY arr_ofertas[arr_curr()].descripcion TO sofertas[scr_line()].descripcion END IF ON ACTION guardar IF fgl_winquestion("GUARDAR","ESTAS SEGURO DE GUARDAR ESTAS INFORMACIONES?","YES","YES|NO","QUESTION",0) THEN CALL actualiza() END IF ON ACTION copiar FOR idx = 1 TO arr_ofertas.getLength() LET arr_ofertas[idx].fecha_inicial=datos_c.fecha1 LET arr_ofertas[idx].fecha_final=datos_c.fecha2 LET arr_ofertas[idx].porc_desc=datos_c.porc_desc1 END FOR AFTER INPUT IF INT_FLAG THEN LET INT_FLAG = FALSE CALL msg(2) EXIT PROGRAM END IF END INPUT ON ACTION busca_productos CONSTRUCT criterio ON a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec FROM cod_n,cod_grupo,cod_tipo,cod_sec BEFORE CONSTRUCT CALL arr_ofertas.clear() END CONSTRUCT LET selec = "SELECT a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.descrip_esp,a.unidad_med FROM iptb00002 a WHERE a.status_t IS NULL and ", criterio CLIPPED PREPARE comando FROM selec DECLARE busca CURSOR FOR comando LET idx = 1 FOREACH busca INTO arr_ofertas[idx].cod_n,arr_ofertas[idx].cod_grupo,arr_ofertas[idx].cod_tipo,arr_ofertas[idx].cod_sec, arr_ofertas[idx].descripcion,arr_ofertas[idx].unidad_med LET arr_ofertas[idx].id=idx LET idx = idx + 1 END FOREACH LET no_registros=arr_ofertas.getLength() DISPLAY BY NAME no_registros ON ACTION CANCEL EXIT PROGRAM END DIALOG END FUNCTION FUNCTION veprmf023() CONSTRUCT BY NAME criterio on a.documento,a.fecha,a.descripcion_oferta ON ACTION CANCEL LET INT_FLAG = FALSE EXIT PROGRAM END CONSTRUCT LET selec = "SELECT a.documento,CONVERT(CHAR(10),a.fecha,103),a.descripcion_oferta,' ',' ',' ',a.us_crea,a.fech_crea ,a.us_mod,a.fech_mod FROM vetb00032 a ", " WHERE ",criterio CLIPPED PREPARE comando2 FROM selec DECLARE busca_c SCROLL CURSOR FOR comando2 OPEN busca_c FETCH FIRST busca_c INTO datos_c.*,xus_crea,xfech_crea,xus_mod,xfech_mod CALL desplega_info() MENU ON ACTION siguiente FETCH NEXT busca_c INTO datos_c.*,xus_crea,xfech_crea,xus_mod,xfech_mod CALL desplega_info() ON ACTION anterior FETCH previous busca_c INTO datos_c.*,xus_crea,xfech_crea,xus_mod,xfech_mod CALL desplega_info() ON ACTION primero FETCH FIRST busca_c INTO datos_c.*,xus_crea,xfech_crea,xus_mod,xfech_mod CALL desplega_info() ON ACTION ultimo FETCH LAST busca_c INTO datos_c.*,xus_crea,xfech_crea,xus_mod,xfech_mod CALL desplega_info() ON ACTION escoger INPUT BY NAME datos_c.* WITHOUT DEFAULTS BEFORE INPUT DISPLAY BY NAME datos_c.fecha NEXT FIELD descripcion_oferta AFTER INPUT IF datos_c.fecha2 < datos_c.fecha1 THEN CALL fgl_winmessage("ERROR","FECHA FINAL NO PUEDE SER MENOR A LA INICIAL","INFO") NEXT FIELD fecha1 END IF END INPUT INPUT ARRAY arr_ofertas FROM sofertas.* ATTRIBUTE(WITHOUT DEFAULTS) ON ACTION copiar FOR idx = 1 TO arr_ofertas.getLength() LET arr_ofertas[idx].fecha_inicial=datos_c.fecha1 LET arr_ofertas[idx].fecha_final=datos_c.fecha2 LET arr_ofertas[idx].porc_desc=datos_c.porc_desc1 END FOR AFTER FIELD cod_sec IF arr_ofertas[arr_curr()].cod_sec IS NOT NULL THEN CALL busca_producto(arr_ofertas[arr_curr()].cod_n,arr_ofertas[arr_curr()].cod_grupo, arr_ofertas[arr_curr()].cod_tipo,arr_ofertas[arr_curr()].cod_sec) RETURNING arr_ofertas[arr_curr()].descripcion DISPLAY arr_ofertas[arr_curr()].descripcion TO sofertas[scr_line()].descripcion END IF AFTER FIELD fecha_final IF arr_ofertas[arr_curr()].cod_sec IS NOT NULL THEN IF arr_ofertas[arr_curr()].fecha_final < arr_ofertas[arr_curr()].fecha_inicial THEN CALL fgl_winmessage("INFO","FECHA FINAL NO PUEDE SER MENOR A LA INCIAL","INFO") NEXT FIELD fecha_final END IF END IF END INPUT ON ACTION guardar IF fgl_winquestion("GUARDAR","ESTAS SEGURO DE GUARDAR ESTAS INFORMACIONES?","YES","YES|NO","QUESTION",0) THEN CALL actualiza() END IF ON ACTION salir EXIT MENU END MENU END FUNCTION FUNCTION actualiza() #BEGIN WORK IF adiciona THEN SELECT MAX(a.documento) INTO datos_c.documento FROM vetb00032 a IF datos_c.documento IS NULL THEN LET datos_c.documento = 0 END IF LET datos_c.documento = datos_c.documento+1 INSERT INTO vetb00032 (documento,fecha,descripcion_oferta,us_crea,fech_crea) VALUES (datos_c.documento,datos_c.fecha,datos_c.descripcion_oferta,usuarios,getdate()) ELSE DELETE FROM vetb00033 WHERE documento =datos_c.documento UPDATE vetb00032 SET descripcion_oferta = datos_c.descripcion_oferta, us_mod = usuarios, fech_mod = getdate() WHERE documento = datos_c.documento END IF FOR idx = 1 TO arr_ofertas.getLength() IF arr_ofertas[idx].cod_Sec IS NOT NULL THEN INSERT INTO vetb00033 (id,documento,cod_n,cod_grupo,cod_tipo,cod_sec,porc_desc,fecha_inicial,fecha_final) VALUES (arr_ofertas[idx].id,datos_c.documento,arr_ofertas[idx].cod_n,arr_ofertas[idx].cod_grupo,arr_ofertas[idx].cod_tipo, arr_ofertas[idx].cod_sec, arr_ofertas[idx].porc_desc,arr_ofertas[idx].fecha_inicial,arr_ofertas[idx].fecha_final) END IF END FOR #COMMIT WORK CALL fgl_winmessage("INFO","ACTUALIZACION EXITOSA","INFO") CALL arr_ofertas.clear() END FUNCTION FUNCTION busca_producto(xcodn,xcodgrupo,xcodtipo,xcodsec) DEFINE xcodn,xcodgrupo,xcodtipo,xcodsec SMALLINT, descripcion VARCHAR(100) SELECT a.descrip_esp INTO descripcion FROM iptb00002 a WHERE a.cod_n = xcodn AND a.cod_grupo = xcodgrupo AND a.cod_tipo = xcodtipo AND a.cod_sec = xcodsec AND a.status_t IS NULL RETURN descripcion END FUNCTION FUNCTION desplega_info() DISPLAY BY NAME datos_c.* DISPLAY xus_crea TO us_crea DISPLAY xus_mod TO us_mod DISPLAY xfech_crea TO fech_crea DISPLAY xfech_mod TO fech_mod DECLARE busca_c1 CURSOR FOR SELECT a.id,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,b.descrip_esp,b.unidad_med,a.porc_desc,a.fecha_inicial,a.fecha_final FROM vetb00033 a,iptb00002 b WHERE a.documento = datos_c.documento 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 LET idx = 1 FOREACH busca_c1 INTO arr_ofertas[idx].id, arr_ofertas[idx].cod_n,arr_ofertas[idx].cod_grupo,arr_ofertas[idx].cod_tipo,arr_ofertas[idx].cod_sec, arr_ofertas[idx].descripcion,arr_ofertas[idx].unidad_med,arr_ofertas[idx].porc_desc,arr_ofertas[idx].fecha_inicial, arr_ofertas[idx].fecha_final LET arr_ofertas[idx].id=idx LET idx = idx + 1 END FOREACH END FUNCTION