Files
MBS/PROYECTOS/otrodir - 21102021/fotos.4gl
T

299 lines
13 KiB
Plaintext

{
==============================================================
MODULO : fotos.4gl
FECHA : 09/02/2017
DESARROLLADO POR : ING. JUAN SOTO
}
IMPORT os
FUNCTION fotos(xcodn,xcodgrupo,xcodtipo,xcodsec,producto,xusuario)
DEFINE xcodn,xcodgrupo,xcodtipo,xcodsec SMALLINT,
producto VARCHAR(100),
xcantidad_minima,xtipo_material VARCHAR(30),
kdatos DYNAMIC ARRAY OF RECORD
kimagen BYTE,
bookmash VARCHAR(50),
tipos VARCHAR(50),
lado_1 DEC(8,2),
lado_2 DEC(8,2),
lado_3 DEC(8,2),
cantidad SMALLINT,
cantidad2 FLOAT,
disponible SMALLINT,
cantidadOrden SMALLINT,
xobservacion VARCHAR(200),
id_producto CHAR(25),
bodega INT,
seccion INT,
tramo INT,
codid INT,
borrar CHAR(2) ,
nombre_file VARCHAR(100)
END RECORD,
kimagen_dest,kimagen_dest2 STRING,
xusuario VARCHAR(50),
i SMALLINT,
TOemail,CCEmail,cuerpo_correo,
subject, procedimiento VARCHAR(200),
totalMedida DEC(12,5)
DEFINE dir_file_default,file_Save,s_tipo,d_tipos,mensaje,f_tipos,filepath,dir_file,opcion STRING
LET producto = xcodn USING "&&&&","-",xcodgrupo USING "&&&&","-",
xcodtipo USING "&&&&","-",xcodsec USING "&&&&"," ",producto CLIPPED
OPEN WINDOW w1 WITH FORM "ipfmwd015"
DISPLAY BY NAME producto
DECLARE busca_imagen CURSOR FOR
SELECT a.imagen,a.book,a.tipos,a.lado_1,a.lado_2,a.lado_3,a.cantidad,a.cantidad2,
a.observacion,a.id_producto, a.cod_bodega,a.cod_seccion,a.cod_tramo, a.rowid,
a.nombre_file FROM iptb00050 a
WHERE a.cod_n = xcodn AND
a.cod_grupo = xcodgrupo AND
a.cod_tipo =xcodtipo AND
a.cod_sec = xcodsec
LET kimagen_dest = "tmpfile.jpg"
LET kimagen_dest2="tmpfile2.jpg"
LET i=1
LET d_tipos="jpeg"
LET f_tipos="*.jpg *.png *.jpeg"
LET mensaje=%"Elige Documento"
LOCATE kdatos[i].kimagen IN MEMORY
LET totalMedida = 0
FOREACH busca_imagen INTO kdatos[i].kimagen,kdatos[i].bookmash,kdatos[i].tipos,kdatos[i].lado_1,
kdatos[i].lado_2,kdatos[i].lado_3,kdatos[i].cantidad,kdatos[i].cantidad2,
kdatos[i].xobservacion,kdatos[i].id_producto, kdatos[i].bodega, kdatos[i].seccion,kdatos[i].tramo, kdatos[i].codid,kdatos[i].nombre_file
LET kdatos[i].borrar='NO'
LET totalMedida = totalMedida + kdatos[i].cantidad2
LET i = i+1
LOCATE kdatos[i].kimagen IN MEMORY
END FOREACH
DISPLAY BY NAME totalMedida
CALL kdatos.deleteElement(i)
SELECT a.usuario FROM seg0003 a
WHERE a.usuario = xusuario AND
a.fotos_adicionales_inventario = "SI"
IF STATUS <> NOTFOUND THEN
DIALOG
INPUT BY NAME xtipo_material,xcantidad_minima
BEFORE INPUT
SELECT DISTINCT a.tipo_material,a.cantidad_minima INTO xtipo_material,xcantidad_minima
FROM iptb00052 a
WHERE a.cod_n =xcodn AND a.cod_grupo = xcodgrupo AND
a.cod_tipo = xcodtipo AND a.cod_sec = xcodsec
DISPLAY BY NAME xtipo_material,xcantidad_minima
END INPUT
INPUT ARRAY kdatos FROM sdatos.* ATTRIBUTE(WITHOUT DEFAULTS)
BEFORE ROW
LET i=arr_curr()
IF kdatos[i].kimagen IS NOT NULL THEN
CALL kdatos[i].kimagen.writeFile(kimagen_dest)
DISPLAY kimagen_dest TO presenta
END IF
LET kdatos[i].cantidad = 1
DISPLAY kdatos[i].cantidad TO sdatos[scr_line()].cantidad
CALL bodegas('1')
CALL cseccion(kdatos[i].bodega)
CALL ctramo(kdatos[i].bodega,kdatos[i].seccion)
AFTER FIELD bodega
# IF kdatos[i].cod_bodega IS NOT NULL THEN
CALL cseccion(kdatos[i].bodega)
# END IF
AFTER FIELD seccion
CALL ctramo(kdatos[i].bodega,kdatos[i].seccion)
ON ACTION eliminar
LET opcion = fgl_winquestion("ELIMINAR","ESTA SEGURO DE ELIMINAR ESTA IMAGEN?","NO","YES|NO","QUESTION",0)
IF opcion = "YES" THEN
DELETE FROM iptb00050 WHERE rowid = kdatos[arr_curr()].codid
CALL kdatos.deleteElement(arr_curr())
END IF
ON ACTION foto_down
IF kdatos[i].kimagen IS NOT NULL THEN
LET dir_file = "tmp\\",xusuario CLIPPED,
kimagen_dest CLIPPED
LET s_tipo = '*jpg *.png'
LET opcion = 'Archivo Imagen'
CALL kdatos[i].kimagen.writeFile(dir_file)
LET mensaje = 'Guardar archivo'
CALL ui.Interface.frontCall("standard","getenv", ["TEMP"], [filepath] )
LET filepath = filepath CLIPPED,"\\",kdatos[i].nombre_file CLIPPED
CALL ui.Interface.frontCall("standard","savefile", [dir_file,opcion,
s_tipo,mensaje], [filepath] )
CALL fgl_putfile(dir_file,filepath)
CALL ui.Interface.frontCall("standard","shellexec", [filepath],[opcion])
END IF
ON ACTION foto
LET i = arr_curr()
CALL ui.Interface.frontCall("standard","openfile", [dir_file,d_tipos,f_tipos,mensaje], [filepath] )
IF filepath IS NOT NULL THEN
IF downshift(os.Path.extension(filepath)) = "jpg" OR
downshift(os.Path.extension(filepath)) = "jpeg" OR
downshift(os.Path.extension(filepath)) = "png" THEN
LET dir_file = os.Path.basename(filepath)
LOCATE kdatos[i].kimagen IN MEMORY
LET dir_file = "tmp\\",dir_file CLIPPED
# CALL fgl_getfile(filepath,kimagen_dest2)
CALL fgl_getfile(filepath,dir_file)
CALL comprimeImagen(dir_file,' -resize 500x500 ')
CALL kdatos[i].kimagen.readfile(dir_file)
LET kdatos[i].nombre_file = os.Path.basename(dir_file)
DISPLAY filepath TO presenta
ELSE
CALL fgl_winmessage("ERROR","EL FILE DEBE SER JPG, JPEG, PNG","INFO")
END IF
END IF
AFTER FIELD cantidad
LET i = arr_curr()
LET kdatos[i].cantidad2= kdatos[i].lado_1 * kdatos[i].lado_2 * kdatos[i].cantidad
DISPLAY kdatos[i].cantidad2 TO sdatos[scr_line()].cantidad2
ON ACTION cancel
LET INT_FLAG = FALSE
CALL fgl_winmessage("INFO","OPERACION CANCELADA","INFO")
EXIT dialog
ON ACTION guardar
IF xcodgrupo IS NOT NULL THEN
SELECT DISTINCT a.cod_n FROM iptb00052 a
WHERE a.cod_n = xcodn AND a.cod_grupo=xcodgrupo AND a.cod_tipo = xcodtipo AND a.cod_sec = xcodsec
IF STATUS = NOTFOUND THEN
INSERT INTO iptb00052 (cod_n,cod_grupo,cod_tipo,cod_Sec,tipo_material,cantidad_minima,us_crea,fech_crea)
VALUES (xcodn,xcodgrupo,xcodtipo,xcodsec,xtipo_material,xcantidad_minima,xusuario,getdate())
ELSE
UPDATE iptb00052 SET tipo_material = xtipo_material,
cantidad_minima = xcantidad_minima,
us_mod = xusuario,
fech_mod = getdate()
WHERE cod_n = xcodn AND cod_grupo = xcodgrupo AND cod_tipo = xcodtipo AND cod_sec = xcodsec
END IF
END IF
WHENEVER ERROR CONTINUE
FOR i =1 TO kdatos.getLength()
# IF kdatos[i].kimagen IS NOT NULL THEN
LET kdatos[i].id_producto=kdatos[i].id_producto CLIPPED
IF kdatos[i].codid IS NOT NULL THEN
UPDATE iptb00050 SET imagen = kdatos[i].kimagen,
lado_1 = kdatos[i].lado_1,
lado_2 = kdatos[i].lado_2,
lado_3 = kdatos[i].lado_3,
cantidad = kdatos[i].cantidad,
cantidad2 = kdatos[i].cantidad2,
tipo_material=xtipo_material,
cantidad_minima = xcantidad_minima,
book = kdatos[i].bookmash,
tipos = kdatos[i].tipos,
observacion = kdatos[i].xobservacion,
id_producto = kdatos[i].id_producto ,
nombre_file = kdatos[i].nombre_file,
us_mod = xusuario,
fech_mod = getdate(),
cod_bodega=kdatos[i].bodega,
cod_seccion=kdatos[i].seccion,
cod_tramo = kdatos[i].tramo
WHERE ROWID = kdatos[i].codid
# IF STATUS < 0 THEN
# CALL fgl_Winmessage("ERROR",SQLCA.sqlerrd[2],"INFO")
# END IF
ELSE
SELECT DISTINCT a.id_producto FROM iptb00050 a
WHERE a.id_producto = kdatos[i].id_producto
IF STATUS <> NOTFOUND THEN
CALL fgl_winmessage("INFO",SFMT ("EXISTE UNA FOTO CON ESTE %1 MISMO ID ",kdatos[i].id_producto),"INFO")
NEXT FIELD id_producto
END IF
INSERT INTO iptb00050 (cod_n,cod_grupo,cod_tipo,cod_Sec,imagen,observacion,tipos,book,
lado_1,lado_2,lado_3,cantidad,
nombre_file,us_crea,fech_crea,id_producto,
cantidad2,cod_bodega,cod_seccion,cod_tramo)
VALUES (xcodn,xcodgrupo,xcodtipo,xcodsec,kdatos[I].kimagen,kdatos[i].xobservacion,
kdatos[i].tipos,kdatos[i].bookmash,kdatos[i].lado_1,kdatos[i].lado_2,kdatos[i].lado_3,
kdatos[i].cantidad, kdatos[i].nombre_file,xusuario,getdate(),kdatos[i].id_producto,
kdatos[i].cantidad2,kdatos[i].bodega,kdatos[i].seccion,kdatos[i].tramo)
FREE kdatos[i].kimagen
LET kdatos[i].codid = SQLCA.SQLERRD[2]
END IF
DISPLAY kdatos[i].codid TO sdatos[scr_line()].codid
# END IF
END FOR
CALL fgl_winmessage("ACTUALIZACION","ACTUALIZACION EXITOSA","INFO")
LET subject="ACTUALIZACION IMAGEN PRODUCTO"
LET cuerpo_correo = "EL ARTICULO ",producto CLIPPED, " FUE ACTUALIZADO CON UNA IMAGEN"
LET toemail ='vendedores@marmotech.com.do;jsoto@marmotech.com.do'
LET procedimiento = "{ call cc_avisadespacho(?,?,?,?) }" CLIPPED
# CALL envia_correo(TOemail,CCEmail,cuerpo_correo,
# subject, procedimiento )
END INPUT
END DIALOG
ELSE
DISPLAY ARRAY kdatos TO sdatos.*
BEFORE ROW
LET i=arr_curr()
IF kdatos[i].kimagen IS NOT NULL THEN
CALL kdatos[i].kimagen.writeFile(kimagen_dest)
DISPLAY kimagen_dest TO presenta
END IF
ON ACTION foto_down
IF kdatos[i].kimagen IS NOT NULL THEN
LET dir_file = "tmp\\",xusuario CLIPPED,
kimagen_dest CLIPPED
LET s_tipo = '*jpg *.png'
LET opcion = 'Archivo Imagen'
CALL kdatos[i].kimagen.writeFile(dir_file)
LET mensaje = 'Guardar archivo'
CALL ui.Interface.frontCall("standard","getenv", ["TEMP"], [filepath] )
LET filepath = filepath CLIPPED,"\\",kdatos[i].nombre_file CLIPPED
CALL ui.Interface.frontCall("standard","savefile", [dir_file,opcion,
s_tipo,mensaje], [filepath] )
CALL fgl_putfile(dir_file,filepath)
CALL comprimeImagen(filepath,' -resize 500x500 ')
CALL ui.Interface.frontCall("standard","shellexec", [filepath],[opcion])
END IF
AFTER DISPLAY
EXIT DISPLAY
END DISPLAY
END IF
CLOSE WINDOW w1
END FUNCTION