263 lines
9.3 KiB
Plaintext
263 lines
9.3 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 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 factura RECORD
|
|
gral RECORD
|
|
cod_cia LIKE vetb00002.cod_cia, #DEJAR EN BLANCO
|
|
ventas LIKE vetb00002.ventas,
|
|
zona CHAR(3),
|
|
factura LIKE vetb00002.factura,
|
|
conduce LIKE vetb00002.conduce,
|
|
fecha_conduce DATE,
|
|
fecha_factura DATE,
|
|
tipo_cliente LIKE vetb00002.tipo_cliente,
|
|
sec_cliente LIKE vetb00002.sec_cliente,
|
|
nombre CHAR(30),
|
|
direccion CHAR(170),
|
|
ciudad CHAR(20),
|
|
prima_us LIKE vetb00002.prima_us,
|
|
porc_desc LIKE vetb00002.porc_desc,
|
|
cond_pago LIKE vetb00002.cond_pago, # AUTOMATICO
|
|
num_req INT, # AUTOMATICO
|
|
orden INT,
|
|
orden_externa STRING,
|
|
fecha_orden DATE,
|
|
porc_itbi LIKE vetb00002.porc_itbi,
|
|
sec_vend LIKE vetb00002.sec_vend,
|
|
nombre_vend CHAR(60),
|
|
cod_transp LIKE iptb00006.cod_transp,
|
|
sec_transp LIKE iptb00006.sec_transp,
|
|
cod_tarifa LIKE iptb00006.cod_tarifa,
|
|
nombre_tran CHAR(30),
|
|
fecha_embarque DATE,
|
|
placa_transp LIKE iptb00006.placa,
|
|
sub_total DECIMAL(12,2),
|
|
desc_valor DECIMAL(12,2),
|
|
itbis DECIMAL(12,2),
|
|
total_fact DECIMAL(12,2),
|
|
valor_envio FLOAT,
|
|
correo_electronico STRING,
|
|
metodo_pago STRING,
|
|
num_rnc,pais,telefono_casa,telefono_cel,strncf,codigo_dgii,usuario,clave,tipo_envio,referencia,contacto
|
|
STRING,
|
|
provincia INT,
|
|
contacto_obra,telefono_contacto_obra STRING
|
|
END RECORD,
|
|
detalle DYNAMIC ARRAY OF RECORD
|
|
area SMALLINT, #AUTOMATICO
|
|
cod_n SMALLINT,
|
|
cod_grupo SMALLINT,
|
|
cod_tipo SMALLINT,
|
|
cod_sec SMALLINT,
|
|
descrip_esp CHAR(50),
|
|
unidad_med CHAR(5),
|
|
cantidad1,
|
|
cantidad DEC(12,5),
|
|
precio LIKE vetb00003.precio,
|
|
cantidad_2 LIKE vetb00003.cantidad_2,
|
|
monto_fact DECIMAL(12,2),
|
|
cantidad_orden DEC(12,5),
|
|
facturada DEC(12,5),
|
|
pendiente DEC(12,5),
|
|
id_kit INT,
|
|
codid INT
|
|
END RECORD
|
|
|
|
END RECORD
|
|
DEFINE respuesta RECORD
|
|
cod_msg INT,
|
|
descripcion STRING,
|
|
ncf_string STRING
|
|
END RECORD,
|
|
|
|
r_cmd t_sync_cmd
|
|
|
|
DEFINE cmd, res, msg,url STRING,
|
|
ret INT
|
|
|
|
|
|
LET factura.gral.usuario = 'conecta'
|
|
LET factura.gral.clave = 'conecta'
|
|
|
|
LET factura.gral.codigo_dgii = 'B02'
|
|
LET factura.gral.zona = '1'
|
|
LET factura.gral.fecha_factura = TODAY
|
|
LET factura.gral.nombre = 'PRUEBA b02 FACTURA EXISTOSA SRL'
|
|
LET factura.gral.sec_cliente = 0
|
|
LET factura.gral.num_rnc ='130337391'
|
|
LET factura.gral.direccion ='CALLE TERCERA, RES. SOL CRECIENTE NO 16, CASA NO 6'
|
|
LET factura.gral.ciudad = 'SANTO DOMINGO'
|
|
LET factura.gral.valor_envio =100
|
|
LET factura.gral.prima_us = 1
|
|
LET factura.gral.porc_desc =0
|
|
LET factura.gral.cond_pago =4
|
|
LET factura.gral.orden_externa =1006
|
|
LET factura.gral.fecha_orden = '06/01/2021'
|
|
LET factura.gral.porc_itbi =18
|
|
LET factura.gral.sec_vend =9
|
|
LET factura.gral.fecha_embarque ='06/15/2021'
|
|
LET factura.gral.sub_total = 2050
|
|
LET factura.gral.desc_valor =0
|
|
LET factura.gral.itbis =369
|
|
LET factura.gral.total_fact =2419
|
|
LET factura.gral.correo_electronico = 'jsoto@marmotech.com.do'
|
|
LET factura.gral.metodo_pago = 'TARJETA DE CREDITO'
|
|
LET factura.gral.pais = 'RD'
|
|
LET factura.gral.provincia = '01'
|
|
LET factura.gral.zona = '01'
|
|
|
|
LET factura.gral.telefono_casa = '809-472-2924'
|
|
LET factura.gral.telefono_cel = '809-849-3878'
|
|
LET factura.gral.tipo_envio = 'DCM'
|
|
# DETALLE
|
|
LET factura.detalle[1].codid =12460
|
|
LET factura.detalle[1].area =1
|
|
#LET factura.detalle[1].cod_n =32
|
|
#LET factura.detalle[1].cod_grupo =824
|
|
#LET factura.detalle[1].cod_tipo =673
|
|
#LET factura.detalle[1].cod_sec =2502
|
|
LET factura.detalle[1].descrip_esp ='GRIFERIA VELLINO ECO P/LAVAMANOS 1H 662B'
|
|
LET factura.detalle[1].unidad_med = 'UD'
|
|
LET factura.detalle[1].cantidad =1
|
|
LET factura.detalle[1].precio =1000
|
|
LET factura.detalle[1].cantidad_2 =0
|
|
LET factura.detalle[1].monto_fact =1000
|
|
LET factura.detalle[1].cantidad_orden =1
|
|
|
|
LET factura.detalle[2].codid =14523
|
|
LET factura.detalle[2].area =1
|
|
#LET factura.detalle[2].cod_n =19
|
|
#LET factura.detalle[2].cod_grupo =824
|
|
#LET factura.detalle[2].cod_tipo =1657
|
|
#LET factura.detalle[2].cod_sec =4355
|
|
LET factura.detalle[2].descrip_esp ='LAVAMANO VELLINO 82055 C/PEDESTAL BLANCO '
|
|
LET factura.detalle[2].unidad_med = 'UD'
|
|
LET factura.detalle[2].cantidad =1
|
|
LET factura.detalle[2].precio =1050
|
|
LET factura.detalle[2].cantidad_2 =0
|
|
LET factura.detalle[2].monto_fact =1050
|
|
LET factura.detalle[2].cantidad_orden =1
|
|
|
|
DISPLAY " URL ",xurl
|
|
LET r_cmd.oper = "factura"
|
|
LET r_cmd.data = util.JSON.stringify(factura) -- 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,factura)
|
|
|
|
{ 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 |