Commit inicial: fuentes MBS ERP (Genero 6) + .gitignore + docs/SETUP_PC_MBS.md
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
IMPORT util
|
||||
FUNCTION cotizacion()
|
||||
DEFINE s STRING
|
||||
|
||||
DEFINE p RECORD
|
||||
cotizaciones DYNAMIC ARRAY OF RECORD
|
||||
cotizacion_no INT,
|
||||
fecha DATE,
|
||||
ventas VARCHAR(1),
|
||||
tipo_cliente SMALLINT,
|
||||
sec_cliente INT,
|
||||
nombre VARCHAR(80),
|
||||
rnc VARCHAR(11),
|
||||
nombre_proyecto VARCHAR(50),
|
||||
direccion_proyecto VARCHAR(50),
|
||||
direccion_cliente VARCHAR(50),
|
||||
cond_pago SMALLINT,
|
||||
descripcion VARCHAR(50),
|
||||
celular VARCHAR(15),
|
||||
email VARCHAR(60),
|
||||
sec_vend INT,
|
||||
total_bruto DEC(12,2),
|
||||
monto_desc DEC(12,2),
|
||||
monto_itbis DEC(12,2),
|
||||
total_cotizacion DEC(12,2),
|
||||
us_crea VARCHAR(50),
|
||||
us_mod VARCHAR(50),
|
||||
fech_crea DATETIME YEAR TO MINUTE,
|
||||
fech_mod DATETIME YEAR TO MINUTE
|
||||
END RECORD,
|
||||
detalles DYNAMIC ARRAY OF RECORD
|
||||
cotizacion_no INT,
|
||||
area SMALLINT,
|
||||
descripcion_area CHAR(50),
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
descripcion VARCHAR(80),
|
||||
cantidad DEC(12,5),
|
||||
cantidad1 DEC(12,5),
|
||||
precio DEC(12,2),
|
||||
porc_desc DEC(12,2),
|
||||
itbis DEC(12,2),
|
||||
valor DEC(12,2) ,
|
||||
codid INT,
|
||||
guiid STRING,
|
||||
sincronizado BOOLEAN
|
||||
END RECORD,
|
||||
pprima,pitbis DEC(12,2),
|
||||
puser,pfecha_crea VARCHAR(50)
|
||||
END RECORD ,
|
||||
pcotizacion_no INT
|
||||
|
||||
DEFINE cotizacion RECORD
|
||||
cotizacion_no INT,
|
||||
fecha DATE,
|
||||
ventas VARCHAR(1),
|
||||
tipo_cliente SMALLINT,
|
||||
sec_cliente INT,
|
||||
nombre VARCHAR(80),
|
||||
rnc VARCHAR(11),
|
||||
nombre_proyecto VARCHAR(50),
|
||||
direccion_proyecto VARCHAR(50),
|
||||
direccion_cliente VARCHAR(50),
|
||||
cond_pago SMALLINT,
|
||||
descripcion VARCHAR(50),
|
||||
celular VARCHAR(15),
|
||||
email VARCHAR(60),
|
||||
sec_vend INT,
|
||||
total_bruto DEC(12,2),
|
||||
monto_desc DEC(12,2),
|
||||
monto_itbis DEC(12,2),
|
||||
total_cotizacion DEC(12,2),
|
||||
us_crea VARCHAR(50),
|
||||
us_mod VARCHAR(50),
|
||||
fech_crea DATETIME YEAR TO MINUTE,
|
||||
fech_mod DATETIME YEAR TO MINUTE
|
||||
END RECORD
|
||||
DEFINE detalle RECORD
|
||||
cotizacion_no INT,
|
||||
area SMALLINT,
|
||||
descripcion_area CHAR(50),
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
descripcion VARCHAR(80),
|
||||
cantidad DEC(12,5),
|
||||
cantidad1 DEC(12,5),
|
||||
precio DEC(12,2),
|
||||
porc_desc DEC(12,2),
|
||||
itbis DEC(12,2),
|
||||
valor DEC(12,2) ,
|
||||
codid INT,
|
||||
guiid STRING,
|
||||
sincronizado BOOLEAN
|
||||
END RECORD
|
||||
|
||||
DEFINE r RECORD
|
||||
ERROR STRING
|
||||
--max_order_num LIKE orders.order_num,
|
||||
--max_customer_num LIKE customer.customer_num
|
||||
END RECORD
|
||||
DEFINE i INT
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(s, p)
|
||||
CATCH
|
||||
LET r.error = "FGL ERROR: ", err_get(status)
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
|
||||
SELECT a.cotizacion_no INTO pcotizacion_no FROM vetb00053 a
|
||||
LET pcotizacion_no = pcotizacion_no + 1
|
||||
|
||||
# BEGIN WORK
|
||||
|
||||
DECLARE cu21 CURSOR FOR INSERT INTO cotizacion_detalle (
|
||||
cotizacion_no_mob ,
|
||||
area ,
|
||||
descripcion_area ,
|
||||
cod_n ,
|
||||
cod_grupo ,
|
||||
cod_tipo ,
|
||||
cod_sec ,
|
||||
descripcion ,
|
||||
cantidad ,
|
||||
cantidad1 ,
|
||||
precio ,
|
||||
porc_desc ,
|
||||
itbis ,
|
||||
valor ,
|
||||
codid ,
|
||||
guiid,
|
||||
sincronizado
|
||||
)
|
||||
|
||||
VALUES(detalle.*)
|
||||
OPEN cu21
|
||||
|
||||
DECLARE cu20 CURSOR FOR INSERT INTO cotizacion ( cotizacion_no_mob ,
|
||||
fecha ,
|
||||
ventas ,
|
||||
tipo_cliente ,
|
||||
sec_cliente ,
|
||||
nombre ,
|
||||
rnc ,
|
||||
nombre_proyecto ,
|
||||
direccion_proyecto ,
|
||||
direccion_cliente ,
|
||||
cond_pago ,
|
||||
descripcion ,
|
||||
celular ,
|
||||
email ,
|
||||
sec_vend ,
|
||||
total_bruto ,
|
||||
monto_desc ,
|
||||
monto_itbis ,
|
||||
total_cotizacion ,
|
||||
us_crea ,
|
||||
us_mod ,
|
||||
fech_crea ,
|
||||
fech_mod
|
||||
)
|
||||
|
||||
VALUES(cotizacion.*)
|
||||
OPEN cu20
|
||||
FOR i = 1 TO p.cotizaciones.getLength()
|
||||
LET cotizacion.* = p.cotizaciones[i].*
|
||||
INSERT INTO vetb00050 ( cod_cia ,ventas ,cotizacion_no ,tipo_cliente ,sec_cliente ,nombre_cliente ,rnc ,
|
||||
nombre_proyecto, direccion_cliente, direccion_proyecto, email ,celular ,prima,porc_itbi,
|
||||
fecha , comentario ,cond_pago , sec_vend ,
|
||||
total_bruto,sub_total,monto_desc,monto_itbi,total_neto,
|
||||
us_crea,fech_crea,cod_provincia)
|
||||
VALUES
|
||||
("1",cotizacion.ventas,pcotizacion_no,cotizacion.tipo_cliente,cotizacion.sec_cliente,
|
||||
cotizacion.nombre,cotizacion.rnc,cotizacion.nombre_proyecto,cotizacion.direccion_cliente,
|
||||
cotizacion.direccion_proyecto,cotizacion.email,cotizacion.celular,P.pprima,P.pitbis,cotizacion.fecha,
|
||||
cotizacion.descripcion,cotizacion.cond_pago,cotizacion.sec_vend,cotizacion.total_bruto,
|
||||
cotizacion.total_bruto-cotizacion.monto_desc,cotizacion.monto_desc,cotizacion.monto_itbis,
|
||||
cotizacion.total_cotizacion, P.puser,p.pfecha_crea,"1")
|
||||
LET pcotizacion_no = pcotizacion_no + 1
|
||||
PUT cu20
|
||||
END FOR
|
||||
CLOSE cu20
|
||||
|
||||
FOR i = 1 TO p.detalles.getLength()
|
||||
IF p.detalles[i].cod_n IS NOT NULL THEN
|
||||
LET detalle.* = p.detalles[i].*
|
||||
INSERT INTO vetb00051
|
||||
(cod_cia,ventas,cotizacion_no,area,descripcion_area,cod_n,cod_grupo,cod_tipo,cod_Sec,descripcion,cantidad,cantidad_1,porc_desc,precio,guiid,sincronizado)
|
||||
VALUES ('1',cotizacion.ventas,pcotizacion_no,p.detalles[i].area,p.detalles[i].descripcion_area, p.detalles[i].cod_n,p.detalles[i].cod_grupo,
|
||||
p.detalles[i].cod_tipo,p.detalles[i].cod_sec,p.detalles[i].descripcion, p.detalles[i].cantidad,p.detalles[i].cantidad1,
|
||||
p.detalles[i].porc_desc,p.detalles[i].precio,p.detalles[i].guiid,p.detalles[i].sincronizado)
|
||||
|
||||
|
||||
PUT cu21
|
||||
END IF
|
||||
END FOR
|
||||
|
||||
|
||||
# COMMIT WORK
|
||||
CLOSE cu21
|
||||
|
||||
UPDATE cotizacion SET cotizacion_no = pcotizacion_no
|
||||
WHERE cotizacion_no_mob = cotizacion.cotizacion_no
|
||||
|
||||
UPDATE cotizacion_detalle SET cotizacion_no = pcotizacion_no
|
||||
WHERE cotizacion_no_mob = cotizacion.cotizacion_no
|
||||
|
||||
UPDATE vetb00053 SET cotizacion_no =pcotizacion_no
|
||||
|
||||
LET r.ERROR='INSERTE COTIZACION, VERIFIQUE SISTEMA DESKTOP'
|
||||
RETURN util.JSON.stringify(r)
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,102 @@
|
||||
{
|
||||
FUNCION : datosCocinas.4gl
|
||||
OBJETIVO : Publicar los datos para realizar estados de las cocinas modulares
|
||||
DESARROLLADO POR: ING. JUAN SOTO
|
||||
FECHA : Julio 20, 2026
|
||||
|
||||
}
|
||||
|
||||
IMPORT util
|
||||
|
||||
-- Tipos reutilizables para evitar duplicar la definición de campos
|
||||
TYPE t_datos RECORD
|
||||
ventasCantidad, cantidadInsumos DEC(12, 5),
|
||||
ventasVAlor, gastos, valorIsumos DEC(18, 2),
|
||||
cod_msg INT,
|
||||
descripcion STRING
|
||||
|
||||
END RECORD
|
||||
|
||||
FUNCTION datosCocina(data)
|
||||
DEFINE data STRING
|
||||
|
||||
DEFINE
|
||||
credenciales RECORD
|
||||
usuario VARCHAR(50),
|
||||
clave VARCHAR(50),
|
||||
fechaCorte DATE
|
||||
END RECORD,
|
||||
fecha1, fecha2 DATE
|
||||
|
||||
-- Registros temporales donde cae cada FETCH antes de copiarlo al arreglo
|
||||
DEFINE datos t_datos
|
||||
|
||||
CALL util.JSON.parse(data, credenciales)
|
||||
DISPLAY "USUARIO ", credenciales.usuario, " clave ", credenciales.clave
|
||||
|
||||
CONNECT TO "smarmotech" USER credenciales.usuario USING credenciales.clave
|
||||
IF STATUS < 0 THEN
|
||||
LET datos.cod_msg = 400
|
||||
LET datos.descripcion = "USUARIO NO VALIDO ", SQLCA.SQLERRM
|
||||
DISCONNECT CURRENT
|
||||
RETURN util.JSON.stringify(datos)
|
||||
END IF
|
||||
|
||||
SELECT a.fecha_inicio, a.fecha_corte
|
||||
INTO fecha1, fecha2
|
||||
FROM prdtable a
|
||||
WHERE a.ano = YEAR(credenciales.fechaCorte)
|
||||
AND a.mes = MONTH(credenciales.fechaCorte)
|
||||
|
||||
|
||||
-- VENTAS NETAS (bruto - descuento) * prima_us. Se agrega a nivel de encabezado
|
||||
-- (vetb00002) con EXISTS para no duplicar sub_total/monto_desc por cada linea de detalle.
|
||||
SELECT ISNULL(SUM(cantidadtrx),0), ISNULL(SUM(neto),0)
|
||||
INTO datos.ventasCantidad, datos.ventasVAlor
|
||||
FROM ventas_facturas
|
||||
WHERE ano = YEAR(credenciales.fechaCorte)
|
||||
AND numero_mes = MONTH(credenciales.fechaCorte)
|
||||
AND cod_n IN (52, 56, 40, 43) AND cod_grupo IN (1511,1500,668)
|
||||
|
||||
-- GASTOS del departamento de Ensamble Modulares (6118) = SUM(debito - credito)
|
||||
-- Solo cuentas de gasto: cuenta_no que inicia en '7'.
|
||||
SELECT ISNULL(SUM(a.debito - a.credito), 0)
|
||||
INTO datos.gastos
|
||||
FROM cgtb00004 a
|
||||
WHERE a.fecha BETWEEN fecha1 AND fecha2
|
||||
AND a.departamento = 6118
|
||||
AND a.cuenta_no LIKE '7%'
|
||||
AND a.tipo <> 3
|
||||
AND a.status_t IS NULL
|
||||
|
||||
-- CANTIDAD DE INSUMOS consumidos en el periodo (movimiento 86)
|
||||
SELECT ISNULL(SUM(a.cantidad_2 * - 1), 0)
|
||||
INTO datos.cantidadInsumos
|
||||
FROM iptb00006 a
|
||||
WHERE a.cod_mov = 86
|
||||
AND a.status_t IS NULL
|
||||
AND a.fecha BETWEEN fecha1 AND fecha2
|
||||
|
||||
-- VALOR DE INSUMOS: unidades del periodo * costo estandar (material+labor+gastos)
|
||||
-- tomado de iptb00004 (mes_fin=12 del ano de fecha2), no del costo del movimiento.
|
||||
SELECT ISNULL(
|
||||
SUM((a.cantidad_2 * - 1) * (b.material + b.labor + b.gastos)), 0)
|
||||
INTO datos.valorIsumos
|
||||
FROM iptb00006 a
|
||||
INNER
|
||||
JOIN iptb00004 b
|
||||
ON b.cod_n = a.cod_n
|
||||
AND b.cod_grupo = a.cod_grupo
|
||||
AND b.cod_tipo = a.cod_tipo
|
||||
AND b.cod_sec = a.cod_sec
|
||||
WHERE a.cod_mov = 86
|
||||
AND a.status_t IS NULL
|
||||
AND a.fecha BETWEEN fecha1 AND fecha2
|
||||
AND b.mes_fin = 12
|
||||
AND b.ano = YEAR(fecha2)
|
||||
|
||||
DISCONNECT CURRENT
|
||||
LET datos.cod_msg = 200
|
||||
LET datos.descripcion = 'OPERACION EXITOSA'
|
||||
RETURN util.JSON.stringify(datos)
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,147 @@
|
||||
IMPORT util
|
||||
IMPORT security
|
||||
|
||||
FUNCTION gestion_gastos(pdata)
|
||||
|
||||
DEFINE i SMALLINT
|
||||
DEFINE pdata STRING
|
||||
|
||||
DEFINE data RECORD
|
||||
generales RECORD
|
||||
usuario, clave VARCHAR(50)
|
||||
END RECORD,
|
||||
detalle DYNAMIC ARRAY OF RECORD
|
||||
tipo_gasto VARCHAR(100),
|
||||
fecha DATE,
|
||||
ncf STRING,
|
||||
rnc STRING,
|
||||
nombreproveedor VARCHAR(100),
|
||||
valor NUMERIC(18,2),
|
||||
itbis NUMERIC(18,2),
|
||||
documento BYTE,
|
||||
fech_crea DATE
|
||||
END RECORD,
|
||||
mensajes RECORD
|
||||
cod_msg INT,
|
||||
descripcion STRING
|
||||
END RECORD
|
||||
END RECORD
|
||||
|
||||
DEFINE raw_data RECORD
|
||||
generales RECORD
|
||||
usuario, clave VARCHAR(50)
|
||||
END RECORD,
|
||||
detalle DYNAMIC ARRAY OF RECORD
|
||||
tipo_gasto VARCHAR(100),
|
||||
fecha DATE,
|
||||
ncf STRING,
|
||||
rnc STRING,
|
||||
nombreproveedor VARCHAR(100),
|
||||
valor NUMERIC(18,2),
|
||||
itbis NUMERIC(18,2),
|
||||
documento STRING, -- base64 aquí
|
||||
fech_crea DATE
|
||||
END RECORD,
|
||||
mensajes RECORD
|
||||
cod_msg INT,
|
||||
descripcion STRING
|
||||
END RECORD
|
||||
END RECORD
|
||||
|
||||
DEFINE r_out RECORD
|
||||
orden INT,
|
||||
mensaje_out STRING,
|
||||
cod_msg INT
|
||||
END RECORD
|
||||
|
||||
DEFINE numemp INT, query STRING
|
||||
|
||||
DISPLAY "VERSION #", 8
|
||||
-- ? Parseamos el JSON en raw_data (con documento en base64 como STRING)
|
||||
CALL util.JSON.parse(pdata, raw_data)
|
||||
|
||||
DISPLAY 'usuario: ', raw_data.generales.usuario
|
||||
# DISPLAY 'clave: ', raw_data.generales.clave
|
||||
|
||||
CONNECT TO "marmotech" USER raw_data.generales.usuario USING raw_data.generales.clave
|
||||
IF STATUS < 0 THEN
|
||||
LET r_out.cod_msg = STATUS
|
||||
LET r_out.orden = 0
|
||||
LET r_out.mensaje_out = 'ERROR EN USUARIO CONECTANDOSE A LA BASE DE DATOS'
|
||||
DISCONNECT CURRENT
|
||||
RETURN util.JSON.stringify(r_out)
|
||||
END IF
|
||||
|
||||
--Convertir de raw_data a data (conversión de base64 incluida)
|
||||
FOR i = 1 TO raw_data.detalle.getLength()
|
||||
LET data.detalle[i].tipo_gasto = raw_data.detalle[i].tipo_gasto
|
||||
LET data.detalle[i].fecha = raw_data.detalle[i].fecha
|
||||
LET data.detalle[i].ncf = raw_data.detalle[i].ncf
|
||||
LET data.detalle[i].rnc = raw_data.detalle[i].rnc
|
||||
LET data.detalle[i].nombreproveedor = raw_data.detalle[i].nombreproveedor
|
||||
LET data.detalle[i].valor = raw_data.detalle[i].valor
|
||||
LET data.detalle[i].itbis = raw_data.detalle[i].itbis
|
||||
LET data.detalle[i].fech_crea = raw_data.detalle[i].fech_crea
|
||||
|
||||
IF raw_data.detalle[i].documento IS NOT NULL THEN
|
||||
LOCATE data.detalle[i].documento IN MEMORY
|
||||
CALL security.Base64.ToByte(raw_data.detalle[i].documento, data.detalle[i].documento)
|
||||
END IF
|
||||
END FOR
|
||||
|
||||
LET query = "SELECT num_emp FROM marmotech.dbo.seg0001 WHERE
|
||||
usuario = ? AND status_t IS NULL"
|
||||
|
||||
PREPARE buscaEmpleado FROM query
|
||||
EXECUTE buscaEmpleado INTO numemp USING raw_data.generales.usuario
|
||||
|
||||
IF data.detalle.getLength() > 0 THEN
|
||||
FOR i = 1 TO data.detalle.getLength()
|
||||
|
||||
# DISPLAY "Bytes cargados de registro: ", LENGTH(data.detalle[i].documento)
|
||||
|
||||
INSERT INTO cptb00014 (
|
||||
ficha_emp,
|
||||
tipo_gasto,
|
||||
fecha,
|
||||
rnc,
|
||||
nombreproveedor,
|
||||
ncf,
|
||||
itbis,
|
||||
valor,
|
||||
documento,
|
||||
fech_crea
|
||||
)
|
||||
VALUES (
|
||||
numemp,
|
||||
data.detalle[i].tipo_gasto,
|
||||
data.detalle[i].fecha,
|
||||
data.detalle[i].rnc,
|
||||
data.detalle[i].nombreproveedor,
|
||||
data.detalle[i].ncf,
|
||||
data.detalle[i].itbis,
|
||||
data.detalle[i].valor,
|
||||
data.detalle[i].documento,
|
||||
data.detalle[i].fech_crea
|
||||
)
|
||||
END FOR
|
||||
END IF
|
||||
|
||||
LET r_out.cod_msg = 13
|
||||
LET r_out.mensaje_out = 'SINCRONIZACION EXITOSA'
|
||||
DISCONNECT CURRENT
|
||||
RETURN util.JSON.stringify(r_out)
|
||||
|
||||
END FUNCTION
|
||||
{
|
||||
FUNCTION b64_to_file(str_64, f_sal)
|
||||
DEFINE str_64, f_sal, str_aux STRING
|
||||
|
||||
TRY
|
||||
CALL security.Base64.SaveBinary(f_sal, str_64)
|
||||
CATCH
|
||||
LET str_aux = "No pude convertir el file Base64: " || STATUS
|
||||
CALL fgl_winmessage("ERROR", str_aux, "stop")
|
||||
END TRY
|
||||
END FUNCTION
|
||||
}
|
||||
@@ -0,0 +1,919 @@
|
||||
# WARNING: Locale must be UTF-8!
|
||||
|
||||
IMPORT util
|
||||
IMPORT com
|
||||
IMPORT os
|
||||
|
||||
TYPE t_sync_cmd RECORD
|
||||
oper STRING,
|
||||
data STRING
|
||||
END RECORD
|
||||
|
||||
DEFINE r_cmd t_sync_cmd -- el comando recibido por el server
|
||||
|
||||
SCHEMA mbs
|
||||
|
||||
DEFINE start_time DATETIME YEAR TO SECOND
|
||||
DEFINE logs DYNAMIC ARRAY OF STRING
|
||||
DEFINE last_request, last_response STRING
|
||||
DEFINE
|
||||
last_date DATETIME YEAR TO SECOND,
|
||||
pcodn CHAR(4)
|
||||
CONSTANT dpy_verb = TRUE -- send messages to standard output
|
||||
CONSTANT log_verb = TRUE -- send messages to the errorlog
|
||||
|
||||
MAIN
|
||||
DEFINE tout, n, x INTEGER
|
||||
DEFINE d0 DATETIME YEAR TO SECOND
|
||||
|
||||
DEFINE url, msg STRING
|
||||
DEFINE method, version, headers STRING
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
|
||||
CALL startlog("err_sync_server.log")
|
||||
|
||||
CALL check_utf8() RETURNING x, msg
|
||||
IF x != 0 THEN
|
||||
DISPLAY "ERROR: ", msg
|
||||
EXIT PROGRAM 1
|
||||
END IF
|
||||
|
||||
CALL show_verb("Starting dbsync server: ...")
|
||||
|
||||
-- Normally, the port is set by the GAS for load balancing
|
||||
-- For standalone tests you can set FGLAPPSERVER environment variable
|
||||
CALL show_verb(
|
||||
"Listening on port : " || NVL(fgl_getenv("FGLAPPSERVER"), "GAS"))
|
||||
|
||||
CALL com.WebServiceEngine.Start()
|
||||
|
||||
LET start_time = CURRENT
|
||||
|
||||
--LET tout=-1 -- timeout: infinite wait
|
||||
--LET tout=5 -- timeout: 5 seconds
|
||||
LET tout = -1 -- timeout: 10 seconds
|
||||
IF tout = -1 THEN
|
||||
LET msg = "The dbsync server is listening (timeout = infinite wait)."
|
||||
ELSE
|
||||
LET msg =
|
||||
"The dbsync server is listening (timeout =",
|
||||
tout USING "-<<<<<<&",
|
||||
" seconds)."
|
||||
END IF
|
||||
CALL show_verb(msg)
|
||||
|
||||
LET n = 0
|
||||
# WHENEVER ERROR CONTINUE
|
||||
WHILE TRUE
|
||||
|
||||
IF int_flag <> 0 THEN
|
||||
LET int_flag = 0
|
||||
EXIT WHILE
|
||||
END IF
|
||||
|
||||
LET req = com.WebServiceEngine.getHTTPServiceRequest(tout)
|
||||
|
||||
IF req IS NULL THEN -- timeout
|
||||
CALL show_verb(
|
||||
SFMT("HTTP request timeout...: %1", CURRENT YEAR TO FRACTION))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET url = req.getURL()
|
||||
LET method = req.getMethod()
|
||||
DISPLAY "llega data: ", req
|
||||
DISPLAY "url ", url
|
||||
DISPLAY "metodo ", method
|
||||
|
||||
IF method != 'OPTIONS' THEN
|
||||
IF method IS NULL OR method != "POST" THEN
|
||||
IF method == "GET" THEN
|
||||
-- TODO: Send server status page back
|
||||
CALL req.sendTextResponse(
|
||||
200,
|
||||
NULL,
|
||||
"Welcome to dbsync server for MBS PRODUCCION...")
|
||||
ELSE
|
||||
CALL show_err(SFMT("Unexpected HTTP request: %1", method))
|
||||
CALL req.sendTextResponse(
|
||||
400, NULL, "Only POST requests supported")
|
||||
END IF
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
END IF
|
||||
IF method = 'OPTIONS' THEN
|
||||
CALL req.sendTextResponse(200, NULL, "Welcome")
|
||||
END IF
|
||||
LET version = req.getRequestVersion()
|
||||
IF version IS NULL OR version != "1.1" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request version: %1", version))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
LET headers = req.getRequestHeader("DBSync-Client")
|
||||
DISPLAY "header: DBSync-Clent=> ", headers
|
||||
IF headers IS NULL OR headers != "mbs" THEN
|
||||
CALL show_err(
|
||||
SFMT("Unexpected HTTP request header DBSync-Client: %1",
|
||||
headers))
|
||||
DISPLAY "HEADER: ", headers
|
||||
CALL req.sendTextResponse(
|
||||
400, NULL, "Bad request in Header DBSync-Client")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET headers = req.getRequestHeader("Content-Type")
|
||||
DISPLAY "content: ", headers
|
||||
IF headers IS NULL
|
||||
OR headers NOT MATCHES "dbsync/json*" THEN -- ;Charset=UTF-8
|
||||
CALL show_err(
|
||||
SFMT("Unexpected HTTP request header Content-Type: %1",
|
||||
headers))
|
||||
CALL req.sendTextResponse(
|
||||
400, NULL, "Bad request, in Header Content-Type")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
IF NOT (read_request(req)) THEN
|
||||
-- si el procesamiento del request da error vuelve al loop
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET n = n + 1
|
||||
|
||||
LET d0 = CURRENT
|
||||
|
||||
CALL show_verb(SFMT("oper [%1]: %2", d0, r_cmd.oper))
|
||||
--CALL show_verb( SFMT("data: %1", r_cmd.data) )
|
||||
DISPLAY "opera ", r_cmd.oper
|
||||
CASE r_cmd.oper
|
||||
WHEN "get_status"
|
||||
|
||||
CALL send_response(req, "SERVER OK")
|
||||
|
||||
WHEN "info"
|
||||
CALL send_response(req, info())
|
||||
WHEN "show_logs"
|
||||
CALL send_response(req, show_logs())
|
||||
WHEN "last_request"
|
||||
CALL send_response(req, last_request())
|
||||
WHEN "geoposicion"
|
||||
LET last_request = r_cmd.data
|
||||
WHEN "clientes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := clientes(r_cmd.data))
|
||||
WHEN "clientes_insert"
|
||||
LET last_response = clientes_insert(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clientes_contactos"
|
||||
LET last_response = contactos(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
|
||||
WHEN "monedas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := monedas())
|
||||
WHEN "envia_info"
|
||||
LET last_response = oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clientes_update"
|
||||
LET last_response = clientes_update(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clases"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := clases(r_cmd.data))
|
||||
WHEN "itbis"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := itbis_descuento())
|
||||
|
||||
WHEN "grupos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := grupos(r_cmd.data))
|
||||
WHEN "areas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := areas())
|
||||
WHEN "usuarios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := usuarios())
|
||||
|
||||
WHEN "tipos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := tipos(r_cmd.data))
|
||||
|
||||
WHEN "precios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := precios())
|
||||
|
||||
WHEN "tipo_negocios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := tipo_negocios())
|
||||
WHEN "condiciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := condiciones())
|
||||
|
||||
WHEN "medidas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := medidas())
|
||||
WHEN "productos_display"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := productos_display(r_cmd.data))
|
||||
WHEN "api_productos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := api_productos(r_cmd.data))
|
||||
WHEN "requisicion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := requisiciondespacho(r_cmd.data))
|
||||
|
||||
WHEN "envia_parametro_p"
|
||||
LET last_response = r_cmd.data
|
||||
LET pcodn = r_cmd.data CLIPPED
|
||||
# DISPLAY "data pcodn ",pcodn
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
|
||||
WHEN "productosconteo"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := productosconteo(last_request))
|
||||
WHEN "productos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := productos(last_request))
|
||||
WHEN "productostodos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := productostodos(last_request))
|
||||
WHEN "productosnoonline"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := productosnoonline(last_request))
|
||||
WHEN "oportunidades"
|
||||
LET last_request = oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "valida_avance"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := valida_avance(r_cmd.data))
|
||||
|
||||
WHEN "rnc"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
DISPLAY "rnc ", r_cmd.oper
|
||||
CALL send_response(req, last_response := rnc(r_cmd.data))
|
||||
WHEN "ip_movimientos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_movimientos(r_cmd.data))
|
||||
WHEN "cotizacion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := cotizacion())
|
||||
WHEN "rep_cotizacion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(
|
||||
req, last_response := rep_cotizacion(r_cmd.data))
|
||||
|
||||
WHEN "orden_insert"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := orden_insert(r_cmd.data))
|
||||
|
||||
WHEN "orden_anular"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := orden_anular(r_cmd.data))
|
||||
|
||||
WHEN "produccion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := produccion(r_cmd.data))
|
||||
|
||||
WHEN "gestion_gastos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := gestion_gastos(r_cmd.data))
|
||||
|
||||
WHEN "produccion_elimina"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := produccion_eliminar(r_cmd.data))
|
||||
|
||||
WHEN "producida"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := orden_cantidad(r_cmd.data))
|
||||
|
||||
WHEN "requisiciones_compra"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := requisiciones_compra(r_cmd.data))
|
||||
WHEN "requisicion_doc"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := requisicion_doc(r_cmd.data))
|
||||
|
||||
WHEN "requisiciones_compra_d"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := requisiciones_compra_d(r_cmd.data))
|
||||
|
||||
WHEN "ip_transportistas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := ip_transportistas())
|
||||
|
||||
WHEN "ip_bodegas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_bodegas(last_request))
|
||||
|
||||
WHEN "ordenes_agente"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ordenes_ia(last_request))
|
||||
|
||||
WHEN "ordenes_display"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ordenes_display(last_request))
|
||||
WHEN "orden_cliente"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ordenes_cliente(last_request))
|
||||
WHEN "orden_cocinas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ordenesCocinas(last_request))
|
||||
|
||||
WHEN "datos_cocinas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := datosCocina(last_request))
|
||||
|
||||
WHEN "respuesta_clientes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := respuesta_cliente(last_request))
|
||||
|
||||
WHEN "orden"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := orden(last_request))
|
||||
|
||||
WHEN "departamento"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := departamentos(last_request))
|
||||
WHEN "ip_existencia"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := existencia())
|
||||
WHEN "ip_secciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_secciones(last_request))
|
||||
WHEN "ip_secciones2"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_secciones2(last_request))
|
||||
WHEN "ip_filas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := ip_filas(last_request))
|
||||
WHEN "ip_filas2"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_filas2(last_request))
|
||||
WHEN "ip_posicion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_posicion(last_request))
|
||||
WHEN "ip_posicion2"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_posicion2(last_request))
|
||||
WHEN "ip_fechaConteo"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_fechaconteo(last_request))
|
||||
WHEN "ip_tramos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_tramos(last_request))
|
||||
WHEN "ip_tramos2"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := ip_tramos2(last_request))
|
||||
WHEN "ip_data_conteo"
|
||||
LET last_response = ip_descarga_conteo(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "ip_etiquetas"
|
||||
LET last_response = ip_etiquetas(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "ip_documentos"
|
||||
LET last_response = ip_documentos(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "factura"
|
||||
LET last_response = factura(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "orden_e"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := orden_e(r_cmd.data))
|
||||
WHEN "imp_factura"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := imprime_factura(r_cmd.data))
|
||||
|
||||
WHEN "v_usuarios"
|
||||
LET last_request = v_usuario(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_request)
|
||||
|
||||
WHEN "parametros_generales"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ", last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := parametros_generales())
|
||||
|
||||
WHEN "requisiciones"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ", last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response := requisiciones())
|
||||
|
||||
WHEN "empleados"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ", last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := empleados_data(last_request))
|
||||
WHEN "cedula"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := busca_emp(last_request))
|
||||
WHEN "pregunta"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := preguntas(last_request))
|
||||
|
||||
WHEN "respuesta"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := respuestas(last_request))
|
||||
WHEN "respuesta_laboral"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := respuesta_laboral(last_request))
|
||||
WHEN "respuesta_ref"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := respuestas_ref(last_request))
|
||||
WHEN "disponible"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(
|
||||
req, last_response := disponible_movil(r_cmd.data))
|
||||
OTHERWISE
|
||||
LET msg = "invalid operation: " || NVL(r_cmd.oper, " ")
|
||||
CALL show_err(msg)
|
||||
CALL req.sendTextResponse(404, NULL, msg)
|
||||
CONTINUE WHILE
|
||||
END CASE
|
||||
|
||||
LET logs[logs.getLength() + 1] =
|
||||
"n:", n USING "<<<<", " ", d0, ' "', r_cmd.oper, '" '
|
||||
|
||||
END WHILE
|
||||
|
||||
END MAIN
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Operacion "disponible" (app movil ConsultaDisponible).
|
||||
# Recibe JSON {credenciales,codid,cod_n..cod_sec,fecha}, resuelve el codigo por
|
||||
# iptb00016 (maestro productos terminados), llama disponibles() (lib funciones) y devuelve
|
||||
# JSON con existencia(m2) + pedidos de cliente abiertos(m2) + reservado/transito.
|
||||
# disponibles() devuelve 5 valores: cantidad_orden,conduce,transito,existencia,reservado
|
||||
#-------------------------------------------------------------------------------
|
||||
FUNCTION disponible_movil(pdata)
|
||||
DEFINE pdata STRING
|
||||
DEFINE p RECORD
|
||||
credenciales RECORD
|
||||
usuario STRING,
|
||||
clave STRING
|
||||
END RECORD,
|
||||
codid INTEGER,
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
fecha CHAR(10)
|
||||
END RECORD
|
||||
DEFINE r RECORD
|
||||
perror STRING,
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
descripcion VARCHAR(120),
|
||||
unidad_med VARCHAR(10),
|
||||
existencia DEC(12,5),
|
||||
ordenes DEC(12,5),
|
||||
reservado DEC(12,5),
|
||||
transito DEC(12,5),
|
||||
disponible DEC(12,5),
|
||||
fecha CHAR(10)
|
||||
END RECORD
|
||||
DEFINE q_orden, q_conduce, q_transito, q_exist, q_reserv DEC(12,5)
|
||||
|
||||
LET r.perror = "OK"
|
||||
LET r.descripcion = ""
|
||||
LET r.unidad_med = ""
|
||||
LET r.existencia = 0
|
||||
LET r.ordenes = 0
|
||||
LET r.reservado = 0
|
||||
LET r.transito = 0
|
||||
LET r.disponible = 0
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(pdata, p)
|
||||
CATCH
|
||||
LET r.perror = "ERROR_JSON"
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
# limpiar cualquier conexion "smarmotech" que quedara abierta de un request previo
|
||||
# (evita el -1802 "connection name in use" que tumbaba el server)
|
||||
WHENEVER ERROR CONTINUE
|
||||
DISCONNECT "smarmotech"
|
||||
WHENEVER ERROR STOP
|
||||
|
||||
# conectar con las credenciales del request (igual que orden.4gl y demas handlers)
|
||||
WHENEVER ERROR CONTINUE
|
||||
CONNECT TO "smarmotech" USER p.credenciales.usuario USING p.credenciales.clave
|
||||
WHENEVER ERROR STOP
|
||||
IF SQLCA.SQLCODE < 0 THEN
|
||||
LET r.perror = "NO_VALIDO"
|
||||
RETURN util.JSON.stringify(r)
|
||||
END IF
|
||||
|
||||
# a partir de aqui, pase lo que pase, SIEMPRE se desconecta al final
|
||||
TRY
|
||||
IF p.codid > 0 THEN
|
||||
SELECT cod_n, cod_grupo, cod_tipo, cod_sec, descrip_esp, unidad_med
|
||||
INTO p.cod_n, p.cod_grupo, p.cod_tipo, p.cod_sec, r.descripcion, r.unidad_med
|
||||
FROM iptb00002
|
||||
WHERE codid = p.codid AND status_t IS NULL
|
||||
ELSE
|
||||
SELECT descrip_esp, unidad_med
|
||||
INTO r.descripcion, r.unidad_med
|
||||
FROM iptb00002
|
||||
WHERE cod_n = p.cod_n AND cod_grupo = p.cod_grupo
|
||||
AND cod_tipo = p.cod_tipo AND cod_sec = p.cod_sec
|
||||
AND status_t IS NULL
|
||||
END IF
|
||||
|
||||
IF SQLCA.SQLCODE = NOTFOUND THEN
|
||||
LET r.perror = "NO_EXISTE"
|
||||
ELSE
|
||||
LET r.cod_n = p.cod_n
|
||||
LET r.cod_grupo = p.cod_grupo
|
||||
LET r.cod_tipo = p.cod_tipo
|
||||
LET r.cod_sec = p.cod_sec
|
||||
|
||||
CALL disponibles(p.cod_n, p.cod_grupo, p.cod_tipo, p.cod_sec, TODAY)
|
||||
RETURNING q_orden, q_conduce, q_transito, q_exist, q_reserv
|
||||
|
||||
LET r.existencia = q_exist
|
||||
LET r.ordenes = q_orden
|
||||
LET r.reservado = q_reserv
|
||||
LET r.transito = q_transito
|
||||
LET r.disponible = q_exist - (q_orden - q_conduce) - q_reserv
|
||||
LET r.fecha = TODAY USING "yyyy-mm-dd"
|
||||
END IF
|
||||
CATCH
|
||||
LET r.perror = SFMT("ERROR_SQL %1", SQLCA.SQLCODE)
|
||||
END TRY
|
||||
|
||||
# SIEMPRE liberar la conexion (por nombre), aunque haya habido error
|
||||
WHENEVER ERROR CONTINUE
|
||||
DISCONNECT "smarmotech"
|
||||
WHENEVER ERROR STOP
|
||||
|
||||
RETURN util.JSON.stringify(r)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION read_request(req)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE
|
||||
cmd STRING,
|
||||
p RECORD
|
||||
oper STRING,
|
||||
data RECORD
|
||||
usuario STRING,
|
||||
clave STRING,
|
||||
codigo STRING
|
||||
END RECORD
|
||||
END RECORD
|
||||
INITIALIZE r_cmd.* TO NULL
|
||||
|
||||
TRY
|
||||
CALL req.readTextRequest() RETURNING cmd
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(
|
||||
SFMT("Unexpected HTTP request read exception: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
#LET cmd='{"oper":"rnc","data":{"usuario":"crm_user","clave":"XMarmotech2019","tipo_Documento":1,"rnc":"130337391"}}'
|
||||
IF LENGTH(cmd) == 0 THEN
|
||||
-- la operacion va a estar vacia y va dar error por invalida
|
||||
RETURN TRUE
|
||||
END IF
|
||||
|
||||
TRY
|
||||
|
||||
CALL util.JSON.parse(cmd, r_cmd)
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("JSON parse error: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
|
||||
RETURN TRUE
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION send_response(req, res)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE res STRING
|
||||
# DISPLAY "response ",res
|
||||
IF res.getLength() > 50 THEN
|
||||
CALL show_verb(
|
||||
SFMT("Response [%1] -> Length: %2",
|
||||
CURRENT YEAR TO SECOND, LENGTH(res)))
|
||||
ELSE
|
||||
CALL show_verb(
|
||||
SFMT("Response [%1] -> %2.", CURRENT YEAR TO SECOND, res.trim()))
|
||||
END IF
|
||||
|
||||
CALL req.setResponseCharset("UTF-8")
|
||||
CALL req.setResponseHeader("dbsync-server", "result")
|
||||
CALL req.setResponseHeader("Content-Type", "dbsync/json")
|
||||
|
||||
CALL req.sendTextResponse(200, NULL, res)
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION check_utf8()
|
||||
IF ORD("€") == 8364 AND LENGTH("€") == 1 THEN
|
||||
RETURN 0, NULL
|
||||
ELSE
|
||||
RETURN -1,
|
||||
"Application locale must be UTF-8, with char length semantics"
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_verb(msg)
|
||||
DEFINE msg STRING
|
||||
IF dpy_verb THEN
|
||||
DISPLAY msg
|
||||
END IF
|
||||
# IF log_verb THEN
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
# END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_err(msg)
|
||||
DEFINE msg STRING
|
||||
DISPLAY "ERROR:", msg
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION info()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append(
|
||||
"<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append(
|
||||
"<h1>Servidor de sincronizacion para dispositivos moviles</h1>")
|
||||
CALL b.append("local time: " || CURRENT YEAR TO SECOND || "<br>")
|
||||
CALL b.append("uptime: " || CURRENT YEAR TO SECOND - start_time || "<br>")
|
||||
CALL b.append("<a href=logs>Logs</a><br>")
|
||||
CALL b.append("<a href=last_request>Last request</a><br>")
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_logs()
|
||||
DEFINE b base.StringBuffer
|
||||
DEFINE i INT
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append(
|
||||
"<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Logs</h1>")
|
||||
FOR i = 1 TO logs.getLength()
|
||||
CALL b.append(logs[i])
|
||||
CALL b.append("<br>")
|
||||
END FOR
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION last_request()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append(
|
||||
"<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Last Request</h1>")
|
||||
CALL b.append("Date:" || last_date)
|
||||
CALL b.append("<h2>Request:</h2>")
|
||||
IF last_request IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_request))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("<h2>Response:</h2>")
|
||||
IF last_response IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_response))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
{FUNCTION usuarios()
|
||||
DEFINE pusuarios DYNAMIC ARRAY OF RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD
|
||||
DEFINE pusuario RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD,
|
||||
i SMALLINT,
|
||||
selec STRING
|
||||
|
||||
LET selec ="SELECT a.email,' ',a.ocupacion,a.sec_vend,a.nombre,a.email
|
||||
FROM CRMindata.dbo.vendedores a"
|
||||
PREPARE comando FROM selec
|
||||
|
||||
DECLARE u1 CURSOR FOR comando
|
||||
LET i=0 FOREACH u1 INTO pusuario.* LET i=i+1 LET pusuarios[i].*=pusuario.*
|
||||
DISPLAY "SUBIENDO USUARIOS...."
|
||||
END FOREACH; FREE u1
|
||||
RETURN util.JSON.stringify(pusuarios)
|
||||
END FUNCTION
|
||||
}
|
||||
{
|
||||
FUNCTION geolocalizacion(s)
|
||||
DEFINE s STRING
|
||||
DEFINE file_out RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD
|
||||
DEFINE file_out_mov RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD,
|
||||
|
||||
|
||||
s_out STRING,
|
||||
archivo STRING,
|
||||
borrar INT
|
||||
|
||||
|
||||
DEFINE r RECORD
|
||||
ERROR STRING
|
||||
END RECORD
|
||||
|
||||
LOCATE file_out.i IN MEMORY
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(s, file_out)
|
||||
CATCH
|
||||
LET r.error = "FGL ERROR: ", err_get(status)
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
|
||||
IF os.Path.exists(file_out.nomb_arch) THEN
|
||||
CALL os.Path.delete(file_out.nomb_arch) RETURNING borrar
|
||||
END IF
|
||||
|
||||
CALL file_out.i.writeFile(file_out.nomb_arch)
|
||||
FREE file_out.i
|
||||
|
||||
|
||||
IF os.Path.size(file_out.nomb_arch)>0 THEN
|
||||
|
||||
CALL get_exif_latlong_bdl(file_out.nomb_arch) RETURNING file_out_mov.lat,file_out_mov.long
|
||||
DISPLAY "latitudes ", file_out_mov.lat," LONG ",file_out_mov.long
|
||||
ELSE
|
||||
LET file_out_mov.contenido="NO PUEDO GEOLOCALIZAR ESTA FOTO"
|
||||
END IF
|
||||
LET s_out = UTIL.JSON.stringify(file_out_mov)
|
||||
|
||||
RETURN s_out
|
||||
END FUNCTION
|
||||
}
|
||||
@@ -0,0 +1,557 @@
|
||||
# WARNING: Locale must be UTF-8!
|
||||
|
||||
IMPORT util
|
||||
IMPORT com
|
||||
IMPORT os
|
||||
|
||||
TYPE t_sync_cmd RECORD
|
||||
oper STRING,
|
||||
data STRING
|
||||
END RECORD
|
||||
|
||||
DEFINE r_cmd t_sync_cmd -- el comando recibido por el server
|
||||
|
||||
SCHEMA mbs
|
||||
|
||||
DEFINE start_time DATETIME YEAR TO SECOND
|
||||
DEFINE logs DYNAMIC ARRAY OF STRING
|
||||
DEFINE last_request, last_response STRING
|
||||
DEFINE last_date DATETIME YEAR TO SECOND,
|
||||
pcodn CHAR(4) ,
|
||||
cantidad_Datos,i INT
|
||||
|
||||
CONSTANT dpy_verb=TRUE -- send messages to standard output
|
||||
CONSTANT log_verb=TRUE -- send messages to the errorlog
|
||||
|
||||
MAIN
|
||||
DEFINE tout, n, x,quean,x1 INTEGER
|
||||
DEFINE d0 DATETIME YEAR TO SECOND
|
||||
|
||||
DEFINE url, msg STRING
|
||||
DEFINE method, version, headers STRING
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE procesa BOOLEAN
|
||||
CALL startlog("err_sync_server.log")
|
||||
|
||||
CALL check_utf8() RETURNING x, msg
|
||||
IF x != 0 THEN
|
||||
DISPLAY "ERROR: ", msg
|
||||
EXIT PROGRAM 1
|
||||
END IF
|
||||
OPEN WINDOW w1 WITH FORM "server" ATTRIBUTES(TEXT = "Test Rest Server", STYLE="naked")
|
||||
CALL show_verb("Starting dbsync server: ...")
|
||||
|
||||
-- Normally, the port is set by the GAS for load balancing
|
||||
-- For standalone tests you can set FGLAPPSERVER environment variable
|
||||
CALL show_verb("Listening on port : "|| NVL(fgl_getenv("FGLAPPSERVER"),"GAS"))
|
||||
|
||||
# CALL ARG_VAL(1) RETURNING usuarios
|
||||
# CALL ARG_VAL(2) RETURNING clave
|
||||
|
||||
# CALL show_verb(SFMT("Connecting to database '%1' as user '%2'","smarmotech",usuarios))
|
||||
# CONNECT TO "smarmotech_t" USER usuarios USING clave
|
||||
|
||||
CALL com.WebServiceEngine.Start()
|
||||
|
||||
LET start_time = CURRENT
|
||||
|
||||
--LET tout=-1 -- timeout: infinite wait
|
||||
--LET tout=5 -- timeout: 5 seconds
|
||||
LET tout=40 -- timeout: 10 seconds
|
||||
IF tout=-1 THEN
|
||||
LET msg="The dbsync server is listening (timeout = infinite wait)."
|
||||
ELSE
|
||||
LET msg="The dbsync server is listening (timeout =",tout USING "-<<<<<<&"," seconds)."
|
||||
END IF
|
||||
CALL show_verb(msg)
|
||||
|
||||
LET n=0
|
||||
WHENEVER ERROR CONTINUE
|
||||
WHILE TRUE
|
||||
|
||||
IF int_flag<>0 THEN
|
||||
LET int_flag=0
|
||||
EXIT WHILE
|
||||
END IF
|
||||
|
||||
LET req = com.WebServiceEngine.getHTTPServiceRequest(tout)
|
||||
|
||||
IF req IS NULL THEN -- timeout
|
||||
CALL show_verb( SFMT("HTTP request timeout...: %1", CURRENT YEAR TO FRACTION))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET url = req.getURL()
|
||||
LET method = req.getMethod()
|
||||
IF method IS NULL OR method != "POST" THEN
|
||||
IF method == "GET" THEN
|
||||
-- TODO: Send server status page back
|
||||
CALL req.sendTextResponse(200,NULL,"Welcome to dbsync server for MBS ...")
|
||||
ELSE
|
||||
CALL show_err(SFMT("Unexpected HTTP request: %1", method))
|
||||
CALL req.sendTextResponse(400,NULL,"Only POST requests supported")
|
||||
END IF
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
LET version = req.getRequestVersion()
|
||||
IF version IS NULL OR version != "1.1" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request version: %1", version))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET headers = req.getRequestHeader("DBSync-Client")
|
||||
IF headers IS NULL OR headers!= "mbs" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request header DBSync-Client: %1", headers))
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET headers = req.getRequestHeader("Content-Type")
|
||||
IF headers IS NULL OR headers NOT MATCHES "dbsync/json*" THEN -- ;Charset=UTF-8
|
||||
CALL show_err(SFMT("Unexpected HTTP request header Content-Type: %1", headers))
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
IF NOT(read_request(req)) THEN
|
||||
-- si el procesamiento del request da error vuelve al loop
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET n = n + 1
|
||||
|
||||
LET d0 = CURRENT
|
||||
|
||||
CALL show_verb( SFMT("oper [%1]: %2", d0, r_cmd.oper) )
|
||||
--CALL show_verb( SFMT("data: %1", r_cmd.data) )
|
||||
|
||||
CASE r_cmd.oper
|
||||
WHEN "get_status"
|
||||
CALL send_response(req, "SERVER OK")
|
||||
DISPLAY req TO msg
|
||||
WHEN "info"
|
||||
CALL send_response(req, info())
|
||||
DISPLAY req TO msg
|
||||
WHEN "show_logs"
|
||||
CALL send_response(req, show_logs())
|
||||
DISPLAY req TO msg
|
||||
WHEN "last_request"
|
||||
CALL send_response(req, last_request())
|
||||
DISPLAY req TO msg
|
||||
WHEN "geoposicion"
|
||||
LET last_request = r_cmd.data
|
||||
WHEN "clientes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=clientes())
|
||||
WHEN "clientes_insert"
|
||||
LET last_response=clientes_insert(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "monedas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=monedas())
|
||||
WHEN "envia_info"
|
||||
LET last_response=oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clientes_update"
|
||||
LET last_response=clientes_update(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clases"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=clases())
|
||||
WHEN "itbis"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=itbis_descuento())
|
||||
|
||||
WHEN "grupos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=grupos())
|
||||
WHEN "areas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=areas())
|
||||
WHEN "usuarios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=usuarios())
|
||||
|
||||
WHEN "tipos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=tipos())
|
||||
|
||||
WHEN "precios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=precios())
|
||||
|
||||
WHEN "tipo_negocios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=tipo_negocios())
|
||||
WHEN "condiciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=condiciones())
|
||||
|
||||
WHEN "medidas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=medidas())
|
||||
WHEN "productos_display"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=productos_display(r_cmd.data))
|
||||
WHEN "requisicion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=requisiciondespacho(r_cmd.data))
|
||||
|
||||
WHEN "envia_parametro_p"
|
||||
LET last_response=r_cmd.data
|
||||
LET pcodn = r_cmd.data CLIPPED
|
||||
# DISPLAY "data pcodn ",pcodn
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
|
||||
WHEN "repuestos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=productos("repuestos"))
|
||||
WHEN "materia_prima"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=productos("materia_prima"))
|
||||
WHEN "productos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
DISPLAY "data ",r_cmd.data
|
||||
CALL send_response(req, last_response:=productos("productos"))
|
||||
|
||||
WHEN "oportunidades"
|
||||
LET last_request = oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
|
||||
WHEN "gestion_gastos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=gestion_gastos(r_cmd.data))
|
||||
|
||||
WHEN "rnc"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=rnc(r_cmd.data))
|
||||
WHEN "ip_movimientos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_movimientos())
|
||||
WHEN "cotizacion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=cotizacion())
|
||||
WHEN "rep_cotizacion"
|
||||
# S1: Receive the sync request FROM the client
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
# S4: Sent back new records TO the client
|
||||
|
||||
CALL send_response(req, last_response:=rep_cotizacion(r_cmd.data))
|
||||
WHEN "ip_transportistas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_transportistas())
|
||||
|
||||
WHEN "ip_bodegas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_bodegas())
|
||||
WHEN "ip_existencia"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=existencia())
|
||||
WHEN "ip_secciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_secciones())
|
||||
WHEN "ip_fechaConteo"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_fechaconteo())
|
||||
WHEN "ip_tramos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_tramos())
|
||||
WHEN "ip_data_conteo"
|
||||
LET last_response = ip_descarga_conteo(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "ip_etiquetas"
|
||||
LET last_response = ip_etiquetas(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "v_usuarios"
|
||||
LET last_request = v_usuario(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req,last_request)
|
||||
|
||||
WHEN "parametros_generales"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ",last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=parametros_generales())
|
||||
|
||||
WHEN "requisiciones"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ",last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=requisiciones())
|
||||
WHEN "ip_ordenes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ordenes_display())
|
||||
OTHERWISE
|
||||
LET msg="invalid operation: " || NVL(r_cmd.oper," ")
|
||||
CALL show_err(msg)
|
||||
CALL req.sendTextResponse(404,NULL,msg)
|
||||
CONTINUE WHILE
|
||||
END CASE
|
||||
|
||||
LET logs[logs.getLength()+1] = "n:",n USING "<<<<", " ", d0, ' "', r_cmd.oper ,'" '
|
||||
|
||||
END WHILE
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION read_request(req)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE cmd STRING
|
||||
|
||||
INITIALIZE r_cmd.* TO NULL
|
||||
|
||||
TRY
|
||||
CALL req.readTextRequest() RETURNING cmd
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("Unexpected HTTP request read exception: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
|
||||
IF LENGTH(cmd) == 0 THEN
|
||||
-- la operacion va a estar vacia y va dar error por invalida
|
||||
RETURN TRUE
|
||||
END IF
|
||||
|
||||
TRY
|
||||
|
||||
CALL util.JSON.parse(cmd, r_cmd)
|
||||
# DISPLAY "ENVIO DATA ",cmd," ",r_cmd.data
|
||||
CATCH
|
||||
|
||||
|
||||
CALL show_err(SFMT("JSON parse error: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
|
||||
RETURN TRUE
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION send_response(req,res)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE res STRING
|
||||
IF res.getLength() > 50 THEN
|
||||
CALL show_verb( SFMT("Response [%1] -> Length: %2", CURRENT YEAR TO SECOND, LENGTH(res)) )
|
||||
ELSE
|
||||
CALL show_verb( SFMT("Response [%1] -> %2.", CURRENT YEAR TO SECOND, res.trim()) )
|
||||
END IF
|
||||
|
||||
CALL req.setResponseCharset("UTF-8")
|
||||
CALL req.setResponseHeader("dbsync-server","result")
|
||||
CALL req.setResponseHeader("Content-Type","dbsync/json")
|
||||
# DISPLAY res
|
||||
CALL req.sendTextResponse(200,NULL,res)
|
||||
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION check_utf8()
|
||||
IF ORD("€") == 8364 AND LENGTH("€") == 1 THEN
|
||||
RETURN 0, NULL
|
||||
ELSE
|
||||
RETURN -1, "Application locale must be UTF-8, with char length semantics"
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_verb(msg)
|
||||
DEFINE msg STRING
|
||||
IF dpy_verb THEN
|
||||
DISPLAY msg
|
||||
END IF
|
||||
IF log_verb THEN
|
||||
CALL errorlog(msg CLIPPED)
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_err(msg)
|
||||
DEFINE msg STRING
|
||||
DISPLAY "ERROR:",msg
|
||||
CALL errorlog(msg CLIPPED)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION info()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>Servidor de sincronizacion para dispositivos moviles</h1>")
|
||||
CALL b.append("local time: " || CURRENT YEAR TO SECOND || "<br>")
|
||||
CALL b.append("uptime: "|| CURRENT YEAR TO SECOND - start_time || "<br>")
|
||||
CALL b.append("<a href=logs>Logs</a><br>")
|
||||
CALL b.append("<a href=last_request>Last request</a><br>")
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_logs()
|
||||
DEFINE b base.StringBuffer
|
||||
DEFINE i INT
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Logs</h1>")
|
||||
FOR i = 1 TO logs.getLength()
|
||||
CALL b.append(logs[i])
|
||||
CALL b.append("<br>")
|
||||
END FOR
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION last_request()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Last Request</h1>")
|
||||
CALL b.append("Date:" || last_date)
|
||||
CALL b.append("<h2>Request:</h2>")
|
||||
IF last_request IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_request))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("<h2>Response:</h2>")
|
||||
IF last_response IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_response))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
{FUNCTION usuarios()
|
||||
DEFINE pusuarios DYNAMIC ARRAY OF RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD
|
||||
DEFINE pusuario RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD,
|
||||
i SMALLINT,
|
||||
selec STRING
|
||||
|
||||
LET selec ="SELECT a.email,' ',a.ocupacion,a.sec_vend,a.nombre,a.email
|
||||
FROM CRMindata.dbo.vendedores a"
|
||||
PREPARE comando FROM selec
|
||||
|
||||
DECLARE u1 CURSOR FOR comando
|
||||
LET i=0 FOREACH u1 INTO pusuario.* LET i=i+1 LET pusuarios[i].*=pusuario.*
|
||||
DISPLAY "SUBIENDO USUARIOS...."
|
||||
END FOREACH; FREE u1
|
||||
RETURN util.JSON.stringify(pusuarios)
|
||||
END FUNCTION
|
||||
}
|
||||
{
|
||||
FUNCTION geolocalizacion(s)
|
||||
DEFINE s STRING
|
||||
DEFINE file_out RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD
|
||||
DEFINE file_out_mov RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD,
|
||||
|
||||
|
||||
s_out STRING,
|
||||
archivo STRING,
|
||||
borrar INT
|
||||
|
||||
|
||||
DEFINE r RECORD
|
||||
ERROR STRING
|
||||
END RECORD
|
||||
|
||||
LOCATE file_out.i IN MEMORY
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(s, file_out)
|
||||
CATCH
|
||||
LET r.error = "FGL ERROR: ", err_get(status)
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
|
||||
IF os.Path.exists(file_out.nomb_arch) THEN
|
||||
CALL os.Path.delete(file_out.nomb_arch) RETURNING borrar
|
||||
END IF
|
||||
|
||||
CALL file_out.i.writeFile(file_out.nomb_arch)
|
||||
FREE file_out.i
|
||||
|
||||
|
||||
IF os.Path.size(file_out.nomb_arch)>0 THEN
|
||||
|
||||
CALL get_exif_latlong_bdl(file_out.nomb_arch) RETURNING file_out_mov.lat,file_out_mov.long
|
||||
DISPLAY "latitudes ", file_out_mov.lat," LONG ",file_out_mov.long
|
||||
ELSE
|
||||
LET file_out_mov.contenido="NO PUEDO GEOLOCALIZAR ESTA FOTO"
|
||||
END IF
|
||||
LET s_out = UTIL.JSON.stringify(file_out_mov)
|
||||
|
||||
RETURN s_out
|
||||
END FUNCTION
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
# WARNING: Locale must be UTF-8!
|
||||
|
||||
IMPORT util
|
||||
IMPORT com
|
||||
IMPORT os
|
||||
|
||||
TYPE t_sync_cmd RECORD
|
||||
oper STRING,
|
||||
data STRING
|
||||
END RECORD
|
||||
|
||||
DEFINE r_cmd t_sync_cmd -- el comando recibido por el server
|
||||
|
||||
#SCHEMA mbs
|
||||
|
||||
DEFINE start_time DATETIME YEAR TO SECOND
|
||||
DEFINE logs DYNAMIC ARRAY OF STRING
|
||||
DEFINE last_request, last_response STRING
|
||||
DEFINE last_date DATETIME YEAR TO SECOND,
|
||||
pcodn CHAR(4)
|
||||
CONSTANT dpy_verb=TRUE -- send messages to standard output
|
||||
CONSTANT log_verb=TRUE -- send messages to the errorlog
|
||||
|
||||
MAIN
|
||||
DEFINE tout, n, x INTEGER
|
||||
DEFINE d0 DATETIME YEAR TO SECOND
|
||||
|
||||
DEFINE url, msg STRING
|
||||
DEFINE method, version, headers STRING
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
|
||||
CALL startlog("err_sync_server.log")
|
||||
|
||||
CALL check_utf8() RETURNING x, msg
|
||||
IF x != 0 THEN
|
||||
DISPLAY "ERROR: ", msg
|
||||
EXIT PROGRAM 1
|
||||
END IF
|
||||
|
||||
CALL show_verb("Starting dbsync server: ...")
|
||||
|
||||
-- Normally, the port is set by the GAS for load balancing
|
||||
-- For standalone tests you can set FGLAPPSERVER environment variable
|
||||
CALL show_verb("Listening on port : "|| NVL(fgl_getenv("FGLAPPSERVER"),"GAS"))
|
||||
|
||||
CALL com.WebServiceEngine.Start()
|
||||
|
||||
LET start_time = CURRENT
|
||||
|
||||
--LET tout=-1 -- timeout: infinite wait
|
||||
--LET tout=5 -- timeout: 5 seconds
|
||||
LET tout=-1 -- timeout: 10 seconds
|
||||
IF tout=-1 THEN
|
||||
LET msg="The dbsync server is listening (timeout = infinite wait)."
|
||||
ELSE
|
||||
LET msg="The dbsync server is listening (timeout =",tout USING "-<<<<<<&"," seconds)."
|
||||
END IF
|
||||
CALL show_verb(msg)
|
||||
|
||||
LET n=0
|
||||
# WHENEVER ERROR CONTINUE
|
||||
WHILE TRUE
|
||||
|
||||
IF int_flag<>0 THEN
|
||||
LET int_flag=0
|
||||
EXIT WHILE
|
||||
END IF
|
||||
|
||||
LET req = com.WebServiceEngine.getHTTPServiceRequest(tout)
|
||||
|
||||
IF req IS NULL THEN -- timeout
|
||||
CALL show_verb( SFMT("HTTP request timeout...: %1", CURRENT YEAR TO FRACTION))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET url = req.getURL()
|
||||
LET method = req.getMethod()
|
||||
{ IF method = 'OPTIONS' THEN
|
||||
|
||||
CALL send_response(req,last_response)
|
||||
CALL show_err(SFMT("Unexpected HTTP request OPTIONS: %1", last_request))
|
||||
END IF
|
||||
}
|
||||
IF method IS NULL OR method != "POST" THEN
|
||||
IF method == "GET" THEN
|
||||
-- TODO: Send server status page back
|
||||
CALL req.sendTextResponse(200,NULL,"Welcome to dbsync server for MBS ...")
|
||||
ELSE
|
||||
|
||||
CALL show_err(SFMT("Unexpected HTTP request: %1", method))
|
||||
CALL req.sendTextResponse(400,NULL,"Only POST requests supported")
|
||||
END IF
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
LET version = req.getRequestVersion()
|
||||
IF version IS NULL OR version != "1.1" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request version: %1", version))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
LET headers = req.getRequestHeader("DBSync-Client")
|
||||
IF headers IS NULL OR headers!= "mbs" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request header DBSync-Client: %1", headers))
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
|
||||
LET headers = req.getRequestHeader("Content-Type")
|
||||
IF headers IS NULL OR headers NOT MATCHES "dbsync/json*" THEN -- ;Charset=UTF-8
|
||||
CALL show_err(SFMT("Unexpected HTTP request header Content-Type: %1", headers))
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
IF NOT(read_request(req)) THEN
|
||||
-- si el procesamiento del request da error vuelve al loop
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET n = n + 1
|
||||
|
||||
LET d0 = CURRENT
|
||||
|
||||
CALL show_verb( SFMT("oper [%1]: %2", d0, r_cmd.oper) )
|
||||
--CALL show_verb( SFMT("data: %1", r_cmd.data) )
|
||||
|
||||
CASE r_cmd.oper
|
||||
WHEN "get_status"
|
||||
|
||||
CALL send_response(req, "SERVER OK")
|
||||
|
||||
WHEN "info"
|
||||
CALL send_response(req, info())
|
||||
WHEN "show_logs"
|
||||
CALL send_response(req, show_logs())
|
||||
WHEN "last_request"
|
||||
CALL send_response(req, last_request())
|
||||
WHEN "geoposicion"
|
||||
LET last_request = r_cmd.data
|
||||
WHEN "clientes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=clientes())
|
||||
WHEN "clientes_insert"
|
||||
LET last_response=clientes_insert(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "monedas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=monedas())
|
||||
WHEN "envia_info"
|
||||
LET last_response=oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clientes_update"
|
||||
LET last_response=clientes_update(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "clases"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=clases())
|
||||
WHEN "itbis"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=itbis_descuento())
|
||||
|
||||
WHEN "grupos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=grupos())
|
||||
WHEN "areas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=areas())
|
||||
WHEN "usuarios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=usuarios())
|
||||
|
||||
WHEN "tipos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=tipos())
|
||||
|
||||
WHEN "precios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=precios())
|
||||
|
||||
WHEN "tipo_negocios"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=tipo_negocios())
|
||||
WHEN "condiciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=condiciones())
|
||||
|
||||
WHEN "medidas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=medidas())
|
||||
WHEN "productos_display"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=productos_display(r_cmd.data))
|
||||
WHEN "requisicion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=requisiciondespacho(r_cmd.data))
|
||||
|
||||
WHEN "envia_parametro_p"
|
||||
LET last_response=r_cmd.data
|
||||
LET pcodn = r_cmd.data CLIPPED
|
||||
# DISPLAY "data pcodn ",pcodn
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
|
||||
WHEN "repuestos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=productos("repuestos"))
|
||||
WHEN "materia_prima"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=productos("materia_prima"))
|
||||
WHEN "productos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=productos("productos"))
|
||||
|
||||
WHEN "oportunidades"
|
||||
LET last_request = oportunidades(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "valida_avance"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=valida_avance(r_cmd.data))
|
||||
|
||||
WHEN "rnc"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
DISPLAY "rnc ",r_cmd.oper
|
||||
CALL send_response(req, last_response:=rnc(r_cmd.data))
|
||||
|
||||
WHEN "gestion_gastos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=gestion_gastos(r_cmd.data))
|
||||
|
||||
|
||||
WHEN "ip_movimientos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_movimientos())
|
||||
WHEN "cotizacion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=cotizacion())
|
||||
WHEN "rep_cotizacion"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req, last_response:=rep_cotizacion(r_cmd.data))
|
||||
WHEN "orden_insert"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=orden_insert(r_cmd.data))
|
||||
|
||||
WHEN "ip_transportistas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_transportistas())
|
||||
|
||||
WHEN "ip_bodegas"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_bodegas())
|
||||
WHEN "ip_existencia"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=existencia())
|
||||
WHEN "ip_secciones"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_secciones())
|
||||
WHEN "ip_fechaConteo"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_fechaconteo())
|
||||
WHEN "ip_tramos"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ip_tramos())
|
||||
WHEN "ip_data_conteo"
|
||||
LET last_response = ip_descarga_conteo(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "ip_etiquetas"
|
||||
LET last_response = ip_etiquetas(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response)
|
||||
WHEN "v_usuarios"
|
||||
LET last_request = v_usuario(r_cmd.data)
|
||||
LET last_date = CURRENT
|
||||
|
||||
CALL send_response(req,last_request)
|
||||
|
||||
WHEN "parametros_generales"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ",last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=parametros_generales())
|
||||
|
||||
WHEN "requisiciones"
|
||||
LET last_request = r_cmd.data
|
||||
DISPLAY "last re ",last_request
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=requisiciones())
|
||||
WHEN "ip_ordenes"
|
||||
LET last_request = r_cmd.data
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=ordenes_display())
|
||||
OTHERWISE
|
||||
LET msg="invalid operation: " || NVL(r_cmd.oper," ")
|
||||
CALL show_err(msg)
|
||||
CALL req.sendTextResponse(404,NULL,msg)
|
||||
CONTINUE WHILE
|
||||
END CASE
|
||||
|
||||
LET logs[logs.getLength()+1] = "n:",n USING "<<<<", " ", d0, ' "', r_cmd.oper ,'" '
|
||||
|
||||
END WHILE
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION read_request(req)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE cmd STRING,
|
||||
p RECORD
|
||||
oper STRING,
|
||||
data RECORD
|
||||
usuario STRING,
|
||||
clave STRING,
|
||||
codigo STRING
|
||||
END RECORD
|
||||
END RECORD
|
||||
INITIALIZE r_cmd.* TO NULL
|
||||
|
||||
TRY
|
||||
CALL req.readTextRequest() RETURNING cmd
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("Unexpected HTTP request read exception: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
#LET cmd='{"oper": "productos_display","data": { "usuario": "CRM_user", "clave": "XMarmotech2019", "codigo": "196681781079"}}'
|
||||
IF LENGTH(cmd) == 0 THEN
|
||||
-- la operacion va a estar vacia y va dar error por invalida
|
||||
RETURN TRUE
|
||||
END IF
|
||||
#DISPLAY "EL CMD ",cmd
|
||||
TRY
|
||||
|
||||
CALL util.JSON.parse(cmd, r_cmd)
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("JSON parse error: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
|
||||
RETURN TRUE
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION send_response(req,res)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE res STRING
|
||||
IF res.getLength() > 50 THEN
|
||||
CALL show_verb( SFMT("Response [%1] -> Length: %2", CURRENT YEAR TO SECOND, LENGTH(res)) )
|
||||
ELSE
|
||||
CALL show_verb( SFMT("Response [%1] -> %2.", CURRENT YEAR TO SECOND, res.trim()) )
|
||||
END IF
|
||||
|
||||
CALL req.setResponseCharset("UTF-8")
|
||||
CALL req.setResponseHeader("dbsync-server","result")
|
||||
CALL req.setResponseHeader("Content-Type","dbsync/json")
|
||||
CALL req.setResponseHeader("Access-Control-Allow-Origin", "*")
|
||||
CALL req.setResponseHeader("Access-Control-Allow-Methods","GET, OPTIONS, HEAD, PUT, POST")
|
||||
CALL req.setResponseHeader("Access-Control-Allow-Headers","Content-Type")
|
||||
# DISPLAY res
|
||||
CALL req.sendTextResponse(200,NULL,res)
|
||||
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION check_utf8()
|
||||
IF ORD("€") == 8364 AND LENGTH("€") == 1 THEN
|
||||
RETURN 0, NULL
|
||||
ELSE
|
||||
RETURN -1, "Application locale must be UTF-8, with char length semantics"
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_verb(msg)
|
||||
DEFINE msg STRING
|
||||
IF dpy_verb THEN
|
||||
DISPLAY msg
|
||||
END IF
|
||||
# IF log_verb THEN
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
# END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_err(msg)
|
||||
DEFINE msg STRING
|
||||
DISPLAY "ERROR:",msg
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION info()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>Servidor de sincronizacion para dispositivos moviles</h1>")
|
||||
CALL b.append("local time: " || CURRENT YEAR TO SECOND || "<br>")
|
||||
CALL b.append("uptime: "|| CURRENT YEAR TO SECOND - start_time || "<br>")
|
||||
CALL b.append("<a href=logs>Logs</a><br>")
|
||||
CALL b.append("<a href=last_request>Last request</a><br>")
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_logs()
|
||||
DEFINE b base.StringBuffer
|
||||
DEFINE i INT
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Logs</h1>")
|
||||
FOR i = 1 TO logs.getLength()
|
||||
CALL b.append(logs[i])
|
||||
CALL b.append("<br>")
|
||||
END FOR
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION last_request()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Last Request</h1>")
|
||||
CALL b.append("Date:" || last_date)
|
||||
CALL b.append("<h2>Request:</h2>")
|
||||
IF last_request IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_request))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("<h2>Response:</h2>")
|
||||
IF last_response IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_response))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
{FUNCTION usuarios()
|
||||
DEFINE pusuarios DYNAMIC ARRAY OF RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD
|
||||
DEFINE pusuario RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD,
|
||||
i SMALLINT,
|
||||
selec STRING
|
||||
|
||||
LET selec ="SELECT a.email,' ',a.ocupacion,a.sec_vend,a.nombre,a.email
|
||||
FROM CRMindata.dbo.vendedores a"
|
||||
PREPARE comando FROM selec
|
||||
|
||||
DECLARE u1 CURSOR FOR comando
|
||||
LET i=0 FOREACH u1 INTO pusuario.* LET i=i+1 LET pusuarios[i].*=pusuario.*
|
||||
DISPLAY "SUBIENDO USUARIOS...."
|
||||
END FOREACH; FREE u1
|
||||
RETURN util.JSON.stringify(pusuarios)
|
||||
END FUNCTION
|
||||
}
|
||||
{
|
||||
FUNCTION geolocalizacion(s)
|
||||
DEFINE s STRING
|
||||
DEFINE file_out RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD
|
||||
DEFINE file_out_mov RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD,
|
||||
|
||||
|
||||
s_out STRING,
|
||||
archivo STRING,
|
||||
borrar INT
|
||||
|
||||
|
||||
DEFINE r RECORD
|
||||
ERROR STRING
|
||||
END RECORD
|
||||
|
||||
LOCATE file_out.i IN MEMORY
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(s, file_out)
|
||||
CATCH
|
||||
LET r.error = "FGL ERROR: ", err_get(status)
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
|
||||
IF os.Path.exists(file_out.nomb_arch) THEN
|
||||
CALL os.Path.delete(file_out.nomb_arch) RETURNING borrar
|
||||
END IF
|
||||
|
||||
CALL file_out.i.writeFile(file_out.nomb_arch)
|
||||
FREE file_out.i
|
||||
|
||||
|
||||
IF os.Path.size(file_out.nomb_arch)>0 THEN
|
||||
|
||||
CALL get_exif_latlong_bdl(file_out.nomb_arch) RETURNING file_out_mov.lat,file_out_mov.long
|
||||
DISPLAY "latitudes ", file_out_mov.lat," LONG ",file_out_mov.long
|
||||
ELSE
|
||||
LET file_out_mov.contenido="NO PUEDO GEOLOCALIZAR ESTA FOTO"
|
||||
END IF
|
||||
LET s_out = UTIL.JSON.stringify(file_out_mov)
|
||||
|
||||
RETURN s_out
|
||||
END FUNCTION
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
# WARNING: Locale must be UTF-8!
|
||||
|
||||
IMPORT util
|
||||
IMPORT com
|
||||
IMPORT os
|
||||
|
||||
TYPE t_sync_cmd RECORD
|
||||
oper STRING,
|
||||
data STRING
|
||||
END RECORD
|
||||
|
||||
DEFINE r_cmd t_sync_cmd -- el comando recibido por el server
|
||||
|
||||
|
||||
|
||||
DEFINE start_time DATETIME YEAR TO SECOND
|
||||
DEFINE logs DYNAMIC ARRAY OF STRING
|
||||
DEFINE last_request, last_response STRING
|
||||
DEFINE last_date DATETIME YEAR TO SECOND,
|
||||
pcodn CHAR(4)
|
||||
CONSTANT dpy_verb=TRUE -- send messages to standard output
|
||||
CONSTANT log_verb=TRUE -- send messages to the errorlog
|
||||
|
||||
MAIN
|
||||
DEFINE tout, n, x INTEGER
|
||||
DEFINE d0 DATETIME YEAR TO SECOND
|
||||
|
||||
DEFINE url, msg STRING
|
||||
DEFINE method, version, headers STRING
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
|
||||
CALL startlog("err_sync_server.log")
|
||||
|
||||
CALL check_utf8() RETURNING x, msg
|
||||
IF x != 0 THEN
|
||||
DISPLAY "ERROR: ", msg
|
||||
EXIT PROGRAM 1
|
||||
END IF
|
||||
|
||||
CALL show_verb("Starting dbsync server: ...")
|
||||
|
||||
-- Normally, the port is set by the GAS for load balancing
|
||||
-- For standalone tests you can set FGLAPPSERVER environment variable
|
||||
CALL show_verb("Listening on port : "|| NVL(fgl_getenv("FGLAPPSERVER"),"GAS"))
|
||||
|
||||
CALL com.WebServiceEngine.Start()
|
||||
|
||||
LET start_time = CURRENT
|
||||
|
||||
--LET tout=-1 -- timeout: infinite wait
|
||||
--LET tout=5 -- timeout: 5 seconds
|
||||
LET tout=-1 -- timeout: 10 seconds
|
||||
IF tout=-1 THEN
|
||||
LET msg="The dbsync server is listening (timeout = infinite wait)."
|
||||
ELSE
|
||||
LET msg="The dbsync server is listening (timeout =",tout USING "-<<<<<<&"," seconds)."
|
||||
END IF
|
||||
CALL show_verb(msg)
|
||||
|
||||
LET n=0
|
||||
# WHENEVER ERROR CONTINUE
|
||||
WHILE TRUE
|
||||
|
||||
IF int_flag<>0 THEN
|
||||
LET int_flag=0
|
||||
EXIT WHILE
|
||||
END IF
|
||||
|
||||
LET req = com.WebServiceEngine.getHTTPServiceRequest(tout)
|
||||
|
||||
IF req IS NULL THEN -- timeout
|
||||
CALL show_verb( SFMT("HTTP request timeout...: %1", CURRENT YEAR TO FRACTION))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET url = req.getURL()
|
||||
LET method = req.getMethod()
|
||||
DISPLAY "url ",url
|
||||
DISPLAY "metodo ", method
|
||||
|
||||
IF method != 'OPTIONS' THEN
|
||||
IF method IS NULL OR method != "POST" THEN
|
||||
IF method == "GET" THEN
|
||||
-- TODO: Send server status page back
|
||||
CALL req.sendTextResponse(200,NULL,"Welcome to dbsync server for MBS ...")
|
||||
ELSE
|
||||
CALL show_err(SFMT("Unexpected HTTP request: %1", method))
|
||||
CALL req.sendTextResponse(400,NULL,"Only POST requests supported")
|
||||
END IF
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
END IF
|
||||
IF method = 'OPTIONS' THEN
|
||||
CALL req.sendTextResponse(200,NULL,"Welcome")
|
||||
END IF
|
||||
LET version = req.getRequestVersion()
|
||||
IF version IS NULL OR version != "1.1" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request version: %1", version))
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
LET headers = req.getRequestHeader("DBSync-Client")
|
||||
DISPLAY "header: DBSync-Clent=> ",headers
|
||||
IF headers IS NULL OR headers!= "mbs" THEN
|
||||
CALL show_err(SFMT("Unexpected HTTP request header DBSync-Client: %1", headers))
|
||||
DISPLAY "HEADER: ",headers
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request in Header DBSync-Client")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
|
||||
LET headers = req.getRequestHeader("Content-Type")
|
||||
DISPLAY "content: ",headers
|
||||
IF headers IS NULL OR headers NOT MATCHES "dbsync/json*" THEN -- ;Charset=UTF-8
|
||||
CALL show_err(SFMT("Unexpected HTTP request header Content-Type: %1", headers))
|
||||
CALL req.sendTextResponse(400,NULL,"Bad request, in Header Content-Type")
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
IF NOT(read_request(req)) THEN
|
||||
-- si el procesamiento del request da error vuelve al loop
|
||||
CONTINUE WHILE
|
||||
END IF
|
||||
|
||||
LET n = n + 1
|
||||
|
||||
LET d0 = CURRENT
|
||||
|
||||
CALL show_verb( SFMT("oper [%1]: %2", d0, r_cmd.oper) )
|
||||
--CALL show_verb( SFMT("data: %1", r_cmd.data) )
|
||||
DISPLAY "opera ",r_cmd.oper
|
||||
CASE r_cmd.oper
|
||||
WHEN "get_status"
|
||||
|
||||
CALL send_response(req, "SERVER OK")
|
||||
|
||||
WHEN "info"
|
||||
CALL send_response(req, info())
|
||||
WHEN "show_logs"
|
||||
CALL send_response(req, show_logs())
|
||||
WHEN "respuesta"
|
||||
LET last_request = r_cmd.data
|
||||
|
||||
LET last_date = CURRENT
|
||||
CALL send_response(req, last_response:=respuestas(last_request))
|
||||
|
||||
OTHERWISE
|
||||
LET msg="invalid operation: " || NVL(r_cmd.oper," ")
|
||||
CALL show_err(msg)
|
||||
CALL req.sendTextResponse(404,NULL,msg)
|
||||
CONTINUE WHILE
|
||||
END CASE
|
||||
|
||||
LET logs[logs.getLength()+1] = "n:",n USING "<<<<", " ", d0, ' "', r_cmd.oper ,'" '
|
||||
|
||||
END WHILE
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION read_request(req)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE cmd STRING,
|
||||
p RECORD
|
||||
oper STRING,
|
||||
data RECORD
|
||||
usuario STRING,
|
||||
clave STRING,
|
||||
codigo STRING
|
||||
END RECORD
|
||||
END RECORD
|
||||
INITIALIZE r_cmd.* TO NULL
|
||||
# DISPLAY "request text: ",req.readTextRequest()
|
||||
TRY
|
||||
CALL req.readTextRequest() RETURNING cmd
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("Unexpected HTTP request read exception: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
#LET cmd='{"oper":"rnc","data":{"usuario":"crm_user","clave":"XMarmotech2019","tipo_Documento":1,"rnc":"130337391"}}'
|
||||
IF LENGTH(cmd) == 0 THEN
|
||||
-- la operacion va a estar vacia y va dar error por invalida
|
||||
RETURN TRUE
|
||||
END IF
|
||||
|
||||
TRY
|
||||
|
||||
CALL util.JSON.parse(cmd, r_cmd)
|
||||
|
||||
CATCH
|
||||
|
||||
CALL show_err(SFMT("JSON parse error: %1", STATUS))
|
||||
RETURN FALSE
|
||||
END TRY
|
||||
|
||||
RETURN TRUE
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION send_response(req,res)
|
||||
|
||||
DEFINE req com.HTTPServiceRequest
|
||||
DEFINE res STRING
|
||||
# DISPLAY "response ",res
|
||||
IF res.getLength() > 50 THEN
|
||||
CALL show_verb( SFMT("Response [%1] -> Length: %2", CURRENT YEAR TO SECOND, LENGTH(res)) )
|
||||
ELSE
|
||||
CALL show_verb( SFMT("Response [%1] -> %2.", CURRENT YEAR TO SECOND, res.trim()) )
|
||||
END IF
|
||||
|
||||
CALL req.setResponseCharset("UTF-8")
|
||||
CALL req.setResponseHeader("dbsync-server","result")
|
||||
CALL req.setResponseHeader("Content-Type","dbsync/json")
|
||||
|
||||
CALL req.sendTextResponse(200,NULL,res)
|
||||
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION check_utf8()
|
||||
IF ORD("€") == 8364 AND LENGTH("€") == 1 THEN
|
||||
RETURN 0, NULL
|
||||
ELSE
|
||||
RETURN -1, "Application locale must be UTF-8, with char length semantics"
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_verb(msg)
|
||||
DEFINE msg STRING
|
||||
IF dpy_verb THEN
|
||||
DISPLAY msg
|
||||
END IF
|
||||
# IF log_verb THEN
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
# END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_err(msg)
|
||||
DEFINE msg STRING
|
||||
DISPLAY "ERROR:",msg
|
||||
# CALL errorlog(msg CLIPPED)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION info()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>Servidor de sincronizacion para dispositivos moviles</h1>")
|
||||
CALL b.append("local time: " || CURRENT YEAR TO SECOND || "<br>")
|
||||
CALL b.append("uptime: "|| CURRENT YEAR TO SECOND - start_time || "<br>")
|
||||
CALL b.append("<a href=logs>Logs</a><br>")
|
||||
CALL b.append("<a href=last_request>Last request</a><br>")
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION show_logs()
|
||||
DEFINE b base.StringBuffer
|
||||
DEFINE i INT
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Logs</h1>")
|
||||
FOR i = 1 TO logs.getLength()
|
||||
CALL b.append(logs[i])
|
||||
CALL b.append("<br>")
|
||||
END FOR
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION last_request()
|
||||
DEFINE b base.StringBuffer
|
||||
LET b = base.StringBuffer.create()
|
||||
CALL b.append("<html><body>")
|
||||
CALL b.append("<a href='/'>[top]<a href=logs>[logs]</a><a href=last_request>[last request]</a>")
|
||||
CALL b.append("<h1>JSON Sync: Last Request</h1>")
|
||||
CALL b.append("Date:" || last_date)
|
||||
CALL b.append("<h2>Request:</h2>")
|
||||
IF last_request IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_request))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("<h2>Response:</h2>")
|
||||
IF last_response IS NOT NULL THEN
|
||||
CALL b.append("<pre>")
|
||||
CALL b.append(util.JSON.format(last_response))
|
||||
CALL b.append("</pre>")
|
||||
END IF
|
||||
CALL b.append("</body></html>")
|
||||
RETURN b.toString()
|
||||
END FUNCTION
|
||||
|
||||
{FUNCTION usuarios()
|
||||
DEFINE pusuarios DYNAMIC ARRAY OF RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD
|
||||
DEFINE pusuario RECORD
|
||||
usuarios VARCHAR(50),
|
||||
password VARCHAR(50),
|
||||
ocupacion VARCHAR(100),
|
||||
sec_vend INT,
|
||||
nombre VARCHAR(30),
|
||||
email VARCHAR(50)
|
||||
END RECORD,
|
||||
i SMALLINT,
|
||||
selec STRING
|
||||
|
||||
LET selec ="SELECT a.email,' ',a.ocupacion,a.sec_vend,a.nombre,a.email
|
||||
FROM CRMindata.dbo.vendedores a"
|
||||
PREPARE comando FROM selec
|
||||
|
||||
DECLARE u1 CURSOR FOR comando
|
||||
LET i=0 FOREACH u1 INTO pusuario.* LET i=i+1 LET pusuarios[i].*=pusuario.*
|
||||
DISPLAY "SUBIENDO USUARIOS...."
|
||||
END FOREACH; FREE u1
|
||||
RETURN util.JSON.stringify(pusuarios)
|
||||
END FUNCTION
|
||||
}
|
||||
{
|
||||
FUNCTION geolocalizacion(s)
|
||||
DEFINE s STRING
|
||||
DEFINE file_out RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD
|
||||
DEFINE file_out_mov RECORD
|
||||
contenido STRING,
|
||||
nomb_arch STRING,
|
||||
lat FLOAT,
|
||||
long FLOAT,
|
||||
i BYTE,
|
||||
file_ext STRING
|
||||
END RECORD,
|
||||
|
||||
|
||||
s_out STRING,
|
||||
archivo STRING,
|
||||
borrar INT
|
||||
|
||||
|
||||
DEFINE r RECORD
|
||||
ERROR STRING
|
||||
END RECORD
|
||||
|
||||
LOCATE file_out.i IN MEMORY
|
||||
|
||||
TRY
|
||||
CALL util.JSON.parse(s, file_out)
|
||||
CATCH
|
||||
LET r.error = "FGL ERROR: ", err_get(status)
|
||||
RETURN util.JSON.stringify(r)
|
||||
END TRY
|
||||
|
||||
|
||||
IF os.Path.exists(file_out.nomb_arch) THEN
|
||||
CALL os.Path.delete(file_out.nomb_arch) RETURNING borrar
|
||||
END IF
|
||||
|
||||
CALL file_out.i.writeFile(file_out.nomb_arch)
|
||||
FREE file_out.i
|
||||
|
||||
|
||||
IF os.Path.size(file_out.nomb_arch)>0 THEN
|
||||
|
||||
CALL get_exif_latlong_bdl(file_out.nomb_arch) RETURNING file_out_mov.lat,file_out_mov.long
|
||||
DISPLAY "latitudes ", file_out_mov.lat," LONG ",file_out_mov.long
|
||||
ELSE
|
||||
LET file_out_mov.contenido="NO PUEDO GEOLOCALIZAR ESTA FOTO"
|
||||
END IF
|
||||
LET s_out = UTIL.JSON.stringify(file_out_mov)
|
||||
|
||||
RETURN s_out
|
||||
END FUNCTION
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
IMPORT COM
|
||||
IMPORT XML
|
||||
IMPORT FGL WSHelper
|
||||
|
||||
PRIVATE CONSTANT C_BASEURL = "/ws/r/qa-test/MyService/"
|
||||
PRIVATE CONSTANT C_X_FOURJS_ENVIRONEMENT_ = "X-FourJs-Environment-"
|
||||
PRIVATE CONSTANT C_GENERO_INTERNAL_DELEGATE = "_GENERO_INTERNAL_DELEGATE_"
|
||||
|
||||
MAIN
|
||||
DEFINE req com.HttpServiceRequest
|
||||
DEFINE methd STRING
|
||||
DEFINE url STRING
|
||||
DEFINE path STRING
|
||||
DEFINE ind INTEGER
|
||||
DEFINE operation STRING
|
||||
|
||||
CALL com.WebServiceEngine.Start()
|
||||
|
||||
WHILE TRUE
|
||||
TRY
|
||||
LET req = com.WebServiceEngine.GetHttpServiceRequest(-1)
|
||||
IF req IS NULL THEN
|
||||
EXIT WHILE
|
||||
ELSE
|
||||
LET url = req.getUrl()
|
||||
LET methd = req.getMethod()
|
||||
LET path = req.getUrlPath()
|
||||
DISPLAY "Incoming request: ",methd," path=",path
|
||||
LET ind = path.getIndexOf(C_BASEURL,1)
|
||||
IF ind<1 THEN
|
||||
CALL req.sendResponse(400,"Invalid request")
|
||||
ELSE
|
||||
# Dispatch request based on operation name (ex : /ws/r/qa-test/MyService/operation1)
|
||||
LET operation = path.subString(ind+C_BASEURL.getLength(),path.getLength())
|
||||
CALL DispatchService(req,operation)
|
||||
END IF
|
||||
DISPLAY "Response sent"
|
||||
END IF
|
||||
CATCH
|
||||
EXIT WHILE
|
||||
END TRY
|
||||
END WHILE
|
||||
END MAIN
|
||||
|
||||
FUNCTION DispatchService(req,operation)
|
||||
DEFINE req com.HttpServiceRequest
|
||||
DEFINE operation STRING
|
||||
DEFINE ind INTEGER
|
||||
LET ind = operation.getIndexOf("/",1)
|
||||
IF ind>0 THEN
|
||||
CALL req.sendResponse(400,"invalid operation")
|
||||
ELSE
|
||||
CASE operation
|
||||
WHEN "Delegate" # Handle a dispatcher delegate service
|
||||
CALL DelegateWA(req)
|
||||
WHEN "producto"
|
||||
CALL productos_display(req)
|
||||
OTHERWISE
|
||||
CALL req.sendResponse(400,"unknown service '"||operation||"'.");
|
||||
END CASE
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
#
|
||||
# Delegate WA service
|
||||
# If browser URL doesn't contain 'ByPass' in query string then return a 404 error,
|
||||
# otherwise start GWC application
|
||||
#
|
||||
FUNCTION DelegateWA(req)
|
||||
DEFINE req com.HttpServiceRequest
|
||||
DEFINE q WSHelper.WSQueryType
|
||||
DEFINE url STRING
|
||||
DEFINE ind INTEGER
|
||||
DEFINE ByPass BOOLEAN
|
||||
|
||||
# Decode Delegate query
|
||||
CALL req.getURLQuery(q)
|
||||
IF q.getLength()==0 THEN
|
||||
CALL req.sendResponse(400,"no query string")
|
||||
RETURN
|
||||
ELSE
|
||||
IF q[1].name=="url" THEN
|
||||
LET url = q[1].value
|
||||
CALL q.deleteElement(1)
|
||||
# Valid delegate request with original URL as key parameter
|
||||
ELSE
|
||||
CALL req.sendResponse(400,"no valid delegate request")
|
||||
RETURN
|
||||
END IF
|
||||
END IF
|
||||
# Process Delegate request
|
||||
LET ByPass = FALSE
|
||||
# Check if user-agent query string has a ByPass string ?
|
||||
FOR ind=1 TO q.getLength()
|
||||
IF q[ind].name="ByPass" THEN
|
||||
LET ByPass = TRUE
|
||||
END IF
|
||||
END FOR
|
||||
IF NOT ByPass THEN
|
||||
# return error
|
||||
CALL req.sendResponse(404,"ByPass is missing")
|
||||
ELSE
|
||||
# Set parameter for the web client application via environment variable: ACCESS=OK
|
||||
CALL req.setResponseHeader(C_X_FOURJS_ENVIRONEMENT_||"ACCESS","OK")
|
||||
# Start application with HTTP code 307
|
||||
CALL req.sendResponse(307,C_GENERO_INTERNAL_DELEGATE)
|
||||
END IF
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,109 @@
|
||||
IMPORT util
|
||||
|
||||
DEFINE url STRING
|
||||
|
||||
TYPE t_sync_cmd RECORD
|
||||
oper STRING,
|
||||
data STRING
|
||||
END RECORD
|
||||
|
||||
MAIN
|
||||
|
||||
CALL startlog("err_client_test.log")
|
||||
|
||||
LET url="http://localhost:8097"
|
||||
|
||||
IF test_connection()==0 THEN
|
||||
DISPLAY "CONNECTION OK"
|
||||
CALL envia_foto("../prueba.jpg")
|
||||
END IF
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION test_connection()
|
||||
|
||||
DEFINE msg STRING
|
||||
DEFINE ret INTEGER
|
||||
DEFINE cmd STRING
|
||||
DEFINE r_cmd t_sync_cmd
|
||||
|
||||
LET r_cmd.oper = "get_status"
|
||||
LET r_cmd.data = ""
|
||||
|
||||
LET cmd = util.JSON.stringify(r_cmd)
|
||||
|
||||
CALL sync_send_command(url, cmd) RETURNING ret, msg
|
||||
|
||||
IF ret == 0 THEN
|
||||
CALL fgl_winmessage("Respuesta",msg,"information")
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection %1 failed",r_cmd.oper),"\n",url,"\n",msg
|
||||
CALL show_sync_err(msg)
|
||||
LET ret=-3
|
||||
END IF
|
||||
|
||||
RETURN ret
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION envia_foto(imagen)
|
||||
DEFINE imagen STRING
|
||||
|
||||
DEFINE t RECORD
|
||||
poportunidades RECORD
|
||||
tema varchar(100) ,
|
||||
direccion varchar(100) ,
|
||||
telefono varchar(20) ,
|
||||
# email VARCHAR(50),
|
||||
email_usuario varchar(50) ,
|
||||
email_asignada varchar(50),
|
||||
lat float ,
|
||||
long float
|
||||
# crm varchar(2)
|
||||
|
||||
END RECORD,
|
||||
imagenes RECORD
|
||||
imagen BYTE
|
||||
END RECORD
|
||||
END RECORD
|
||||
|
||||
DEFINE cmd, res, msg STRING
|
||||
DEFINE ret INTEGER
|
||||
DEFINE r_cmd t_sync_cmd
|
||||
|
||||
-- preparacion de datos para enviar al sever
|
||||
|
||||
LOCATE t.imagenes.imagen IN MEMORY
|
||||
CALL t.imagenes.imagen.readFile(imagen)
|
||||
|
||||
|
||||
LET t.poportunidades.tema="PRUEBA"
|
||||
LET t.poportunidades.direccion=""
|
||||
LET t.poportunidades.email_usuario=""
|
||||
LET t.poportunidades.email_asignada=""
|
||||
LET t.poportunidades.lat = 0
|
||||
LET t.poportunidades.long= 0
|
||||
|
||||
-- envio de datos al sever
|
||||
|
||||
LET r_cmd.oper = "envia_info"
|
||||
LET r_cmd.data = util.JSON.stringify(t) -- 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 fgl_Winmessage("Respuesta",res,"information")
|
||||
--TRY
|
||||
--CALL util.JSON.parse(res,t)
|
||||
--CALL fgl_Winmessage("INFO","ENVIO EXITOSO","information")
|
||||
--CATCH
|
||||
--CALL show_sync_err(SFMT("JSON parse error: %1", STATUS))
|
||||
--END TRY
|
||||
ELSE
|
||||
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n",url,"\n",res
|
||||
CALL show_sync_err(msg)
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,46 @@
|
||||
OPTIONS SHORT CIRCUIT
|
||||
IMPORT com
|
||||
|
||||
#
|
||||
## 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
|
||||
|
||||
DISPLAY "sync_send_command -> url=",url
|
||||
|
||||
TRY
|
||||
LET http_req = com.HTTPRequest.Create(url)
|
||||
CALL http_req.setConnectionTimeout(10)
|
||||
CALL http_req.setTimeout(20)
|
||||
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
|
||||
@@ -0,0 +1,300 @@
|
||||
{
|
||||
Esta funcion se utiliza para desplegar mensajes de los reportes de
|
||||
los sistemas de Ray-O-Vac Dominicana.
|
||||
|
||||
Realizada por JUAN SOTO
|
||||
FECHA : 13/7/2009
|
||||
}
|
||||
|
||||
FUNCTION msgrp000(tipo_papel)
|
||||
DEFINE tipo_papel SMALLINT,
|
||||
longitud CHAR(11),
|
||||
linea_papel CHAR(50)
|
||||
|
||||
CASE
|
||||
WHEN tipo_papel = 1
|
||||
LET longitud = " 9 1/2 x 11"
|
||||
WHEN tipo_papel = 2
|
||||
LET longitud = "14 7/8 x 11"
|
||||
END CASE
|
||||
|
||||
LET linea_papel = "Coloque papel ",longitud," en la impresora."
|
||||
DISPLAY linea_papel
|
||||
AT 15,14
|
||||
DISPLAY "Asegurese de que la impresora este encendida."
|
||||
AT 16,14
|
||||
DISPLAY "<Esc> Ejecuta impresion <Delete> Cancela impresion"
|
||||
AT 18,14
|
||||
|
||||
END FUNCTION
|
||||
|
||||
|
||||
|
||||
FUNCTION defecto(usuarios,clave,impresor)
|
||||
|
||||
DEFINE impresor,idx SMALLINT,
|
||||
|
||||
negrillas_on,
|
||||
|
||||
negrillas_off,
|
||||
|
||||
doble_on,
|
||||
|
||||
doble_off,
|
||||
|
||||
doce,
|
||||
|
||||
comp_on,
|
||||
|
||||
comp_off,
|
||||
|
||||
normal CHAR(6),
|
||||
|
||||
archivo CHAR(80),
|
||||
|
||||
lpnum INTEGER,
|
||||
|
||||
imprime CHAR(150),
|
||||
|
||||
prt RECORD
|
||||
prtcodigo SMALLINT,
|
||||
nombre VARCHAR(60),
|
||||
lpprog VARCHAR(150),
|
||||
lppipe VARCHAR(20),
|
||||
puerto VARCHAR(80)
|
||||
END RECORD,
|
||||
usuarios,clave CHAR(80),copia CHAR(100)
|
||||
|
||||
|
||||
SELECT a.codigo,a.nombre,a.lpprog,a.lppipe,a.puerto INTO prt.* FROM prttb00001 a
|
||||
|
||||
WHERE a.codigo = impresor
|
||||
|
||||
|
||||
|
||||
CASE
|
||||
|
||||
WHEN prt.prtcodigo = 1
|
||||
|
||||
LET doble_on = ASCII 14
|
||||
|
||||
LET doble_off = ASCII 18
|
||||
|
||||
LET negrillas_on = ASCII 27, ASCII 69
|
||||
|
||||
LET negrillas_off = ASCII 27, ASCII 70
|
||||
|
||||
LET comp_on = ASCII 15
|
||||
|
||||
LET comp_off = ASCII 18
|
||||
|
||||
LET doce = ASCII 27,ASCII 77
|
||||
|
||||
LET normal = ASCII 27,ASCII 80
|
||||
|
||||
EXIT CASE
|
||||
|
||||
WHEN prt.prtcodigo = 2 {Printer Central. Contabilidad}
|
||||
|
||||
LET doble_on = ASCII 001
|
||||
|
||||
LET doble_off = ASCII 002
|
||||
|
||||
LET negrillas_on = ASCII 027, ASCII 098
|
||||
|
||||
LET negrillas_off = ASCII 027, ASCII 099
|
||||
|
||||
LET comp_on = ASCII 031
|
||||
|
||||
LET comp_off = ASCII 029
|
||||
|
||||
LET doce = ASCII 030
|
||||
|
||||
LET normal = ASCII 029
|
||||
|
||||
EXIT CASE
|
||||
|
||||
WHEN impresor = 3
|
||||
|
||||
LET doble_on = ASCII 14
|
||||
|
||||
LET doble_off = ASCII 18
|
||||
|
||||
LET negrillas_on = ASCII 27, ASCII 69
|
||||
|
||||
LET negrillas_off = ASCII 27, ASCII 70
|
||||
|
||||
LET comp_on = ASCII 15
|
||||
|
||||
LET comp_off = ASCII 18
|
||||
|
||||
LET doce = ASCII 27,ASCII 77
|
||||
|
||||
LET normal = ASCII 27,ASCII 80
|
||||
|
||||
EXIT CASE
|
||||
|
||||
END CASE
|
||||
|
||||
|
||||
|
||||
# BUSCA EL NUMERO DE IMPRESION A SEGUIR
|
||||
|
||||
SELECT MAX(ult_imp) INTO lpnum
|
||||
|
||||
FROM prttb00002
|
||||
|
||||
|
||||
|
||||
IF lpnum IS NULL THEN
|
||||
|
||||
LET lpnum = 1
|
||||
|
||||
END IF
|
||||
|
||||
LET lpnum = lpnum + 1
|
||||
|
||||
LET archivo = FGL_GETENV("FGLSPOOL"),"\\",lpnum USING "<<<<<<<<<<"
|
||||
|
||||
LET imprime = prt.lpprog CLIPPED," ",archivo CLIPPED," ",
|
||||
prt.lppipe," ",prt.puerto
|
||||
|
||||
LET copia = prt.lppipe," ",prt.puerto
|
||||
|
||||
|
||||
{ UPDATE prttb00002 set ult_imp = lpnum + 1,
|
||||
|
||||
usuario = suser_sname()}
|
||||
|
||||
INSERT INTO prttb00002 (ult_imp,usuario)VALUES (lpnum,usuarios)
|
||||
|
||||
|
||||
|
||||
RETURN imprime,negrillas_on,negrillas_off,doble_on,doble_off,
|
||||
comp_on,comp_off,doce,normal,archivo,copia
|
||||
|
||||
END FUNCTION
|
||||
|
||||
|
||||
|
||||
FUNCTION ElijeImpresion(parametro)
|
||||
|
||||
|
||||
|
||||
DEFINE parametro CHAR(2),
|
||||
|
||||
orden,destino CHAR(1)
|
||||
|
||||
DEFINE letras RECORD
|
||||
|
||||
negrillas_on CHAR(6),
|
||||
|
||||
negrillas_off CHAR(6),
|
||||
|
||||
doble_on CHAR(6),
|
||||
|
||||
doble_off CHAR(6),
|
||||
|
||||
comp_on CHAR(6),
|
||||
|
||||
comp_off CHAR(6),
|
||||
|
||||
doce CHAR(6),
|
||||
|
||||
normal CHAR(6)
|
||||
|
||||
END RECORD
|
||||
|
||||
|
||||
OPEN WINDOW wopcion AT 10,5 WITH FORM "msgfmwd001" ATTRIBUTE
|
||||
|
||||
(BORDER,FORM LINE FIRST + 1)
|
||||
|
||||
CASE
|
||||
|
||||
WHEN parametro = "OD"
|
||||
|
||||
INPUT BY NAME orden,destino
|
||||
|
||||
EXIT CASE
|
||||
|
||||
WHEN parametro = "D"
|
||||
|
||||
INPUT BY NAME destino
|
||||
|
||||
EXIT CASE
|
||||
|
||||
END CASE
|
||||
|
||||
IF destino = "P" THEN
|
||||
|
||||
INITIALIZE letras.* TO NULL
|
||||
|
||||
END IF
|
||||
|
||||
|
||||
|
||||
CLOSE WINDOW wopcion
|
||||
|
||||
RETURN orden,destino,letras.*
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION fdestino(p_destino,p_archivo,p_imprime)
|
||||
|
||||
DEFINE p_destino CHAR(1),
|
||||
|
||||
p_imprime,ejecuta CHAR(80),
|
||||
|
||||
p_archivo CHAR(80)
|
||||
|
||||
|
||||
CASE
|
||||
|
||||
WHEN p_destino = "I"
|
||||
|
||||
DISPLAY P_IMPRIME AT 18,2
|
||||
|
||||
RUN p_imprime
|
||||
|
||||
EXIT CASE
|
||||
|
||||
WHEN p_destino = "P"
|
||||
|
||||
LET ejecuta = FGL_GETENV("EDITOR")," ",p_archivo CLIPPED
|
||||
|
||||
RUN ejecuta
|
||||
|
||||
EXIT CASE
|
||||
|
||||
END CASE
|
||||
|
||||
END FUNCTION
|
||||
|
||||
|
||||
FUNCTION configureOutput(tipo_file)
|
||||
DEFINE tipo_file CHAR(3)
|
||||
IF NOT fgl_report_loadCurrentSettings(NULL) THEN
|
||||
RETURN NULL
|
||||
END IF
|
||||
# CALL fgl_report_selectLogicalPageMapping("multipage")
|
||||
# CALL fgl_report_configureMultipageOutput(2, 4, TRUE)
|
||||
CALL fgl_report_setPageMargins("0.5cm","0.5cm","0.5cm","0.5cm")
|
||||
--CALL fgl_report_selectDevice("XLS")
|
||||
# CALL fgl_report_selectDevice(getPreviewDevice())
|
||||
# CALL fgl_report_configureCompatibilityOutput(1,'Franklin Gothic Heavy',false,'existencia',NULL,NULL)
|
||||
CALL fgl_report_selectDevice(tipo_file)
|
||||
CALL fgl_report_selectPreview(TRUE)
|
||||
RETURN fgl_report_commitCurrentSettings()
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION getPreviewDevice()
|
||||
DEFINE fename String
|
||||
CALL ui.interface.frontcall("standard", "feinfo", ["fename"],[fename])
|
||||
IF fename == "Genero Desktop Client" THEN
|
||||
RETURN "SVG"
|
||||
ELSE
|
||||
RETURN "PDF"
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
IMPORT util
|
||||
IMPORT com
|
||||
IMPORT os
|
||||
IMPORT security
|
||||
|
||||
#
|
||||
## 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(120)
|
||||
CALL http_req.setTimeout(120)
|
||||
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
|
||||
Reference in New Issue
Block a user