Files
MBS/WEBSERVICES/ordene.4gl
T

197 lines
6.5 KiB
Plaintext

IMPORT util
IMPORT com
IMPORT os
IMPORT security
SCHEMA mbs
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 kurl = "https://ws.marmotech.com.do/gas/ws/r/restserver"
# LET kurl = "http://192.168.40.9/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 orden RECORD
encabezado RECORD
num_oc,cotizacion_no,factura,tipo_cliente,sec_cliente,cond_pago,sec_vend INT,
nombre,direccion_linea1,direccion_linea2,ciudad,codigo_postal,pais_region,region_provincia,
telefono1,telefono2,correo_electronico,contacto VARCHAR(100),
orden_externa VARCHAR(30),
fecha_orden DATE,
metodo_pago,referencia STRING,
tipo_envio VARCHAR(100),
total_bruto,monto_descuento,sub_total,monto_itbis,total_neto,itbis,valor_envio FLOAT,
codigo_dgii,titulo_ncf,num_rnc VARCHAR(11),
ventas VARCHAR(1),
cod_zona VARCHAR(3),
conexion ,
usuario,clave STRING
END RECORD,
detalle DYNAMIC ARRAY OF RECORD
ultima_cotizacion,codid,cod_n,cod_grupo,cod_tipo,cod_sec INT,
precio,cantidad1,cantidad,descuento FLOAT,
titulo STRING
END RECORD
END RECORD
DEFINE respuesta RECORD
cod_msg INT,
descripcion STRING
END RECORD,
r_cmd t_sync_cmd
DEFINE cmd, res, msg,url STRING,
ret INT
LET orden.encabezado.factura = 0
LET orden.encabezado.tipo_cliente =25
LET orden.encabezado.sec_cliente =0
LET orden.encabezado.cond_pago =4
LET orden.encabezado.sec_vend =9
LET orden.encabezado.codigo_dgii ='B02'
LET orden.encabezado.titulo_ncf = 'CONSUMO'
LET orden.encabezado.nombre ="SUPERMERCADOS NACIONAL SIN RNC"
LET orden.encabezado.direccion_linea1 = "CALLE MANUEL EMILIO RICARD HERNANDEZ, ESQUINA MARION II"
LET orden.encabezado.direccion_linea2 = "VIEJO"
LET orden.encabezado.ciudad ="01"
LET orden.encabezado.codigo_postal ="000000"
LET orden.encabezado.pais_region = "DO"
LET orden.encabezado.region_provincia = "01"
LET orden.encabezado.telefono1 = "(809)620-2924"
LET orden.encabezado.telefono2 = "(829)847-3878"
LET orden.encabezado.correo_electronico = "jsoto@marmotech.com.do"
LET orden.encabezado.orden_externa = "2129"
LET orden.encabezado.fecha_orden = TODAY
LET orden.encabezado.metodo_pago = "PayPal"
LET orden.encabezado.tipo_envio = 'DCM SANTO DOMINGO'
LET orden.encabezado.total_bruto = 739.32
LET orden.encabezado.monto_descuento =0
LET orden.encabezado.sub_total =739.32
LET orden.encabezado.monto_itbis =133.07
LET orden.encabezado.total_neto =0
LET orden.encabezado.itbis =18
LET orden.encabezado.contacto = 'JHONNY SOTO'
LET orden.encabezado.referencia = 'FRENTE AL PARQUE DE ARROYO HONDO II'
LET orden.encabezado.num_rnc = 0
LET orden.encabezado.ventas = 0
LET orden.encabezado.cod_zona =0
LET orden.detalle[1].ultima_cotizacion =0
LET orden.detalle[1].codid =3684
LET orden.detalle[1].precio =433.59
LET orden.detalle[1].cantidad1 = 1
LET orden.detalle[1].cantidad =1
LET orden.detalle[1].descuento =0
LET orden.detalle[1].titulo = "GRIFERIA DELTA VERO P/LAV. 1H CR 553LF"
LET orden.detalle[2].ultima_cotizacion =0
LET orden.detalle[2].codid =3691
LET orden.detalle[2].precio =305.73
LET orden.detalle[2].cantidad1 = 1
LET orden.detalle[2].cantidad =1
LET orden.detalle[2].descuento =0
LET orden.detalle[2].titulo = "GRIFERIA DELTA COMPEL LAV.1H CR 761-DST"
LET orden.encabezado.conexion = 'NO ACTIVA'
LET orden.encabezado.usuario = 'conecta'
LET orden.encabezado.clave = 'conecta'
DISPLAY " URL ",xurl
LET r_cmd.oper = "orden_e"
LET r_cmd.data = util.JSON.stringify(orden) -- 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,respuesta)
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