200 lines
5.4 KiB
Plaintext
200 lines
5.4 KiB
Plaintext
IMPORT util
|
|
IMPORT com
|
|
IMPORT os
|
|
IMPORT security
|
|
|
|
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 = 'conecta'
|
|
LET ku.clave = 'conecta'
|
|
|
|
LET kurl = "https://ws.marmotech.com.do/gas/ws/r/restserver"
|
|
# LET kurl = "http://192.168.40.4/gas/ws/r/restserver"
|
|
CALL chequea_prod(kurl)
|
|
LET ku.usuario = 'conecta'
|
|
LET ku.clave = 'conecta'
|
|
|
|
END MAIN
|
|
|
|
FUNCTION chequea_prod(xurl)
|
|
DEFINE xurl STRING
|
|
|
|
|
|
DEFINE p RECORD
|
|
productos DYNAMIC ARRAY OF RECORD
|
|
codid INT,
|
|
cod_n INT,
|
|
cod_grupo INT,
|
|
cod_tipo INT,
|
|
cod_sec INT,
|
|
descripcion VARCHAR(100),
|
|
unidad_med VARCHAR(4),
|
|
titulo_esp STRING,
|
|
categoria_padre STRING,
|
|
categoria_us ,
|
|
marca STRING,
|
|
meta_data STRING,
|
|
precio_rd FLOAT,
|
|
precio_us FLOAT,
|
|
existencia FLOAT,
|
|
descripcion_larga_es,descripcion_larga_us TEXT,
|
|
internal_id_brand,wooc_id_brand,idcategoria_padre,sub_categoria,parentcode INT,
|
|
sub_categoria_2,
|
|
sub_categoria_3 STRING,
|
|
online VARCHAR(2),
|
|
factor_conv DEC(12,5),
|
|
contenido STRING,
|
|
ruta_file,codigo_ref STRING
|
|
END RECORD,
|
|
galerias DYNAMIC ARRAY OF RECORD
|
|
codid INT,
|
|
nombre_file STRING,
|
|
ruta_foto STRING
|
|
END RECORD,
|
|
relacionados DYNAMIC ARRAY OF RECORD
|
|
codid INT,
|
|
codid_relacionado INT,
|
|
cod_n,cod_grupo, cod_tipo,cod_sec INT,
|
|
descripcion STRING,
|
|
precio FLOAT
|
|
END RECORD,
|
|
sugeridos DYNAMIC ARRAY OF RECORD
|
|
codid INT,
|
|
codid_sugerido INT,
|
|
cod_n,cod_grupo, cod_tipo,cod_sec INT,
|
|
descripcion STRING,
|
|
precio FLOAT
|
|
END RECORD,
|
|
mensajes RECORD
|
|
cod_msg INT,
|
|
descripcion STRING
|
|
END RECORD
|
|
END RECORD,
|
|
|
|
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,clave VARCHAR(50),
|
|
fecha_actualiza STRING
|
|
END RECORD,
|
|
i int
|
|
|
|
|
|
LET data.usuario = 'conecta'
|
|
LET data.clave = 'conecta'
|
|
LET data.fecha_actualiza = '2022-03-16'
|
|
DISPLAY " URL ",xurl
|
|
LET r_cmd.oper = "productostodos"
|
|
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 "cmd", cmd,"ret ",ret," RES: ",RES
|
|
IF ret == 0 THEN
|
|
|
|
CALL util.JSON.parse(res,P)
|
|
|
|
{ OPEN WINDOW w1 WITH FORM "testprodisp_1"
|
|
FOR i = 1 TO p.productos.getLength()
|
|
|
|
IF p.contenido_file.contenido IS NOT NULL THEN
|
|
|
|
|
|
LET tmpfile = "tmpfoto.jpg"
|
|
|
|
CALL b64_to_file(p.contenido_file.contenido,tmpfile)
|
|
DISPLAY p.productos[i].descripcion,p.contenido_file.contenido
|
|
DISPLAY tmpfile TO record1[scr_line()].kimagen
|
|
|
|
END IF
|
|
|
|
END FOR
|
|
|
|
|
|
#CALL fgl_winmessage("INFO","VOY A CERRAR","INFO")
|
|
CLOSE WINDOW w1
|
|
}
|
|
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")
|
|
|
|
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
|
|
|
|
FUNCTION b64_to_file(str_b64,f_sal)
|
|
|
|
DEFINE f_sal,str_b64,str_aux STRING
|
|
|
|
TRY
|
|
CALL security.Base64.SaveBinary(f_sal,str_b64)
|
|
CATCH
|
|
DISPLAY " data ",str_b64
|
|
LET str_aux="Unable to convert Base64 String to file :",STATUS
|
|
CALL fgl_winmessage("Error",str_aux,"stop")
|
|
END TRY
|
|
END FUNCTION |