Files
MBS/WEBSERVICES/testporddysplay.4gl
T

158 lines
4.5 KiB
Plaintext

IMPORT util
IMPORT com
IMPORT os
TYPE t_sync_cmd RECORD
oper STRING,
data STRING
END RECORD
MAIN
DEFINE k,kurl,kbodega STRING,
ktrue BOOLEAN
DEFINE ku RECORD
usuario VARCHAR(50),
clave VARCHAR(20),
sesion VARCHAR(10)
END RECORD
LET ku.usuario = 'jsoto'
LET ku.clave = 'lmmjvsd2014'
LET ku.sesion = 'ABRIR'
# LET kurl = "https://ws.marmotech.com.do/gas320/ws/r/restserver"
LET kurl = "https://ws.marmotech.com.do/gas320/ws/r/restserver"
CALL chequea_prod(kurl)
LET ku.usuario = 'jsoto'
LET ku.clave = 'lmmjvsd2014'
LET ku.sesion = 'CERRAR'
END MAIN
FUNCTION chequea_prod(xurl)
DEFINE xurl STRING
DEFINE producto RECORD
cod_cia SMALLINT ,
cod_n SMALLINT ,
cod_grupo SMALLINT ,
cod_tipo SMALLINT ,
cod_sec SMALLINT ,
descrip_esp varchar(180) ,
descrip_ing varchar(80) ,
unidad_med varchar(4) ,
nomenclatura char(50) ,
bodega SMALLINT ,
existencia DEC(12,5),
disponible DEC(12,5),
exist_max decimal(10, 2) ,
exist_min decimal(10, 2) ,
dia_llegada SMALLINT ,
control_existencia varchar(2) ,
control_itbis varchar(2) ,
codid INT ,
foto_producto STRING,
imagen BYTE,
porc_desc decimal(12, 2) ,
fecha_desc DATE ,
factor DEC(12,2),
referencia VARCHAR(25),
cod_msg SMALLINT,
mensaje_out STRING
END RECORD
DEFINE r_cmd t_sync_cmd
DEFINE u,cmd, res, msg,url,tmpfile STRING,
ret INT
DEFINE r RECORD
perror STRING,
pbodega SMALLINT
END RECORD
DEFINE data RECORD
usuario VARCHAR(50),
clave VARCHAR(50),
codigo VARCHAR(50)
END RECORD
# LOCATE arc_recibido IN MEMORY
LOCATE producto.imagen IN MEMORY
LET u ='196681781079'
LET data.codigo='2012012'
LET data.usuario = 'jsoto'
LET data.clave = 'lmmjvsd2014'
DISPLAY " URL ",xurl
LET r_cmd.oper = "productos_display"
LET r_cmd.data = util.JSON.stringify(data) -- aca se convierte a string los datos de la operacion
LET cmd = util.JSON.stringify(r_cmd)
CALL sync_send_command(xurl, cmd) RETURNING ret, res
DISPLAY "ret ",ret, "res ",res
IF ret == 0 THEN
CALL util.JSON.parse(res,producto)
IF producto.descrip_esp IS NOT NULL THEN
DISPLAY "datos ",producto.descrip_esp," ds ",producto.disponible
OPEN WINDOW w1 WITH FORM "testprodisp"
IF producto.imagen IS NOT NULL THEN
LET tmpfile = ".\\archrecibidos\\",os.Path.baseName(producto.foto_producto)
CALL producto.imagen.writeFile(tmpfile)
DISPLAY BY NAME tmpfile,producto.existencia
CALL fgl_winmessage("INFO","OK","INFO")
END IF
CLOSE WINDOW w1
ELSE
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url
CALL show_sync_err(msg)
END IF
ELSE
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url
CALL show_sync_err(msg)
END IF
END FUNCTION
#
## Communications library using com (http or https)
#
FUNCTION sync_send_command(url, cmd)
DEFINE url, cmd STRING
DEFINE result, tmp STRING
DEFINE http_req com.HTTPRequest
DEFINE http_resp com.HTTPResponse
TRY LET http_req = com.HTTPRequest.Create(url)
CALL http_req.setConnectionTimeout(40)
CALL http_req.setTimeout(40)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("DBSync-Client","mbs")
CALL http_req.setHeader("Content-Type","dbsync/json")
DISPLAY "request ",cmd
CALL http_req.doTextRequest(cmd)
LET http_resp=http_req.getResponse()
IF http_resp.getStatusCode() != 200 THEN
RETURN http_resp.getStatusCode(), http_resp.getStatusDescription()
END IF
LET tmp = http_resp.getStatusDescription()
IF (tmp == "OK" || tmp == "no error" ) THEN
RETURN -1, SFMT("HTTP request status description: %1 ",tmp)
END IF
LET result = http_resp.getTextResponse()
CATCH
RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM)
END TRY
RETURN 0, result
END FUNCTION
FUNCTION show_sync_err(msg)
DEFINE msg STRING
CALL fgl_winmessage(%"ERROR", msg, "exclamation")
END FUNCTION