Commit inicial: fuentes MBS ERP (Genero 6) + .gitignore + docs/SETUP_PC_MBS.md
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
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"
|
||||
CALL chequea_req(kurl)
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION chequea_req(xurl)
|
||||
DEFINE xurl STRING
|
||||
|
||||
DEFINE generales RECORD
|
||||
usuario VARCHAR(50),
|
||||
clave VARCHAR(50),
|
||||
requisicion SMALLINT
|
||||
END RECORD
|
||||
DEFINE data RECORD
|
||||
detalle DYNAMIC ARRAY OF RECORD
|
||||
inventario STRING,
|
||||
codigo INT,
|
||||
producto STRING,
|
||||
cantidad FLOAT,
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
departamento VARCHAR(70),
|
||||
num_oc INT,
|
||||
num_req INT,
|
||||
fecha DATE,
|
||||
estado VARCHAR(20)
|
||||
END RECORD,
|
||||
|
||||
r_out RECORD
|
||||
mensaje_out STRING,
|
||||
cod_msg INT
|
||||
END RECORD
|
||||
END RECORD,
|
||||
i INT,
|
||||
msg,cmd,ret,res STRING
|
||||
DeFINE r_cmd t_sync_cmd
|
||||
LET generales.usuario ='JSOTO'
|
||||
LET generales.clave = 'lmmjvsd2014'
|
||||
LET generales.requisicion = 9013
|
||||
LET r_cmd.oper = "requisiciones_compra"
|
||||
LET r_cmd.data = util.JSON.stringify(generales) -- aca se convierte a string los datos de la operacion
|
||||
|
||||
LET cmd = util.JSON.stringify(r_cmd)
|
||||
DISPLAY cmd
|
||||
CALL sync_send_command(xurl, cmd) RETURNING ret, res
|
||||
|
||||
IF ret == 0 THEN
|
||||
CALL util.JSON.parse(res,data)
|
||||
|
||||
|
||||
# OPEN WINDOW w1 WITH FORM "reqcompra"
|
||||
# DISPLAY ARRAY data.detalle TO record1.*
|
||||
# CLOSE WINDOW w1
|
||||
# FOR i=1 TO data.detalle.getLength()
|
||||
# DISPLAY data.detalle[i].*
|
||||
# END FOR
|
||||
IF data.r_out.cod_msg > 0 THEN
|
||||
DISPLAY "ERR ",data.r_out.mensaje_out
|
||||
END IF
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",xurl
|
||||
CALL show_sync_err(msg)
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION valida_usuario(u,url)
|
||||
DEFINE u RECORD
|
||||
usuario VARCHAR(50),
|
||||
clave VARCHAR(20),
|
||||
sesion VARCHAR(10)
|
||||
END RECORD
|
||||
DEFINE r_cmd t_sync_cmd
|
||||
|
||||
DEFINE cmd, res, msg,url STRING,
|
||||
ret INT
|
||||
DEFINE r RECORD
|
||||
perror STRING,
|
||||
pbodega SMALLINT
|
||||
END RECORD
|
||||
LET r_cmd.oper = "v_usuarios"
|
||||
LET r_cmd.data = util.JSON.stringify(u) -- aca se convierte a string los datos de la operacion
|
||||
|
||||
LET cmd = util.JSON.stringify(r_cmd) -- aca se convierte a string el comando/operacion a enviar al server
|
||||
|
||||
CALL sync_send_command(url, cmd) RETURNING ret, res
|
||||
|
||||
IF ret == 0 THEN
|
||||
CALL util.JSON.parse(res,r)
|
||||
|
||||
IF r.perror = "VALIDO" THEN
|
||||
RETURN TRUE,r.pbodega
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url,"\n",res
|
||||
CALL show_sync_err(msg)
|
||||
RETURN FALSE,r.pbodega
|
||||
END IF
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url,"\n",res
|
||||
CALL show_sync_err(msg)
|
||||
RETURN FALSE,r.pbodega
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION chequea_rnc(url)
|
||||
DEFINE r_cmd t_sync_cmd
|
||||
DEFINE u CHAR(11),
|
||||
url,cmd,res,msg STRING,
|
||||
ret INT
|
||||
DEFINE r RECORD
|
||||
perror STRING,
|
||||
pbodega SMALLINT
|
||||
END RECORD
|
||||
DEFINE prnc RECORD
|
||||
nombre_cliente STRING,
|
||||
direccion STRING,
|
||||
existe INT
|
||||
END RECORD
|
||||
LET u ='130337391'
|
||||
LET r_cmd.oper = "rnc"
|
||||
LET r_cmd.data = util.JSON.stringify(u) -- aca se convierte a string los datos de la operacion
|
||||
LET cmd = util.JSON.stringify(r_cmd)
|
||||
CALL sync_send_command(url, cmd) RETURNING ret, res
|
||||
DISPLAY "ret ",ret
|
||||
IF ret == 0 THEN
|
||||
CALL util.JSON.parse(res,prnc)
|
||||
DISPLAY "datos ",prnc.nombre_cliente
|
||||
IF r.perror = "VALIDO" THEN
|
||||
RETURN TRUE,r.pbodega
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url,"\n",res
|
||||
CALL show_sync_err(msg)
|
||||
RETURN FALSE,r.pbodega
|
||||
END IF
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url,"\n",res
|
||||
CALL show_sync_err(msg)
|
||||
RETURN FALSE,r.pbodega
|
||||
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
|
||||
Reference in New Issue
Block a user