1580 lines
74 KiB
Plaintext
1580 lines
74 KiB
Plaintext
IMPORT util
|
|
IMPORT os
|
|
|
|
DEFINE estado_rnc CHAR(50)
|
|
DEFINE ant_art RECORD
|
|
area SMALLINT,
|
|
cod_n SMALLINT,
|
|
cod_grupo SMALLINT,
|
|
cod_tipo SMALLINT,
|
|
cod_sec SMALLINT,
|
|
cantidad,precio DEC(12,2)
|
|
END RECORD,
|
|
verdad BOOLEAN,
|
|
i int
|
|
DEFINE p RECORD
|
|
cotizaciones RECORD
|
|
cotizacion_no INT,
|
|
fecha DATE,
|
|
ventas VARCHAR(1),
|
|
tipo_cliente SMALLINT,
|
|
sec_cliente INT,
|
|
nombre VARCHAR(100),
|
|
rnc VARCHAR(11),
|
|
nombre_proyecto VARCHAR(60),
|
|
direccion_proyecto VARCHAR(60),
|
|
direccion_cliente VARCHAR(80),
|
|
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),
|
|
contacto VARCHAR(100),
|
|
nombre_ciudad VARCHAR(60),
|
|
telefono_o VARCHAR(20),
|
|
telefono_r VARCHAR(20),
|
|
celular1 VARCHAR(20),
|
|
soporte VARCHAR(200),
|
|
instalador VARCHAR(200),
|
|
vendedor_aux VARCHAR(100),
|
|
sec_vend_aux INT,
|
|
cod_provincia SMALLINT,
|
|
nombre_vend VARCHAR(60),
|
|
porc_itbis DEC(8,2),
|
|
plazo_entrega VARCHAR(100),
|
|
comentario VARCHAR(100),
|
|
usuario VARCHAR(50),
|
|
clave VARCHAR(50),
|
|
etiqueta_cotizacion VARCHAR(60),
|
|
cod_zona SMALLINT,
|
|
codigo VARCHAR(10),
|
|
guiId STRING,
|
|
sincronizado BOOLEAN,
|
|
tipo_documento CHAR(10),
|
|
bodega INT,
|
|
titulo_bodega VARCHAR(100),
|
|
estado STRING
|
|
END RECORD,
|
|
detalles DYNAMIC ARRAY OF RECORD
|
|
secuencia INT,
|
|
area SMALLINT,
|
|
descripcion_area CHAR(50),
|
|
codid VARCHAR(25),
|
|
codigo VARCHAR(20),
|
|
cod_n SMALLINT,
|
|
cod_grupo SMALLINT,
|
|
cod_tipo SMALLINT,
|
|
cod_sec SMALLINT,
|
|
# descripcion VARCHAR(100),
|
|
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),
|
|
cantidad_reservada DEC(12,5),
|
|
fecha_inicio_reserva DATE,
|
|
fecha_vence_reserva DATE,
|
|
autorizada VARCHAR(10),
|
|
idkit INT,
|
|
disenoID VARCHAR(50)
|
|
|
|
END RECORD,
|
|
|
|
pprima,pitbis DEC(12,2),
|
|
puser,pfecha_crea VARCHAR(50)
|
|
END RECORD
|
|
|
|
TYPE t_sync_cmd RECORD
|
|
oper STRING,
|
|
data STRING
|
|
END RECORD
|
|
{FUNCTION gen_nombre_archivo(tip_sal)
|
|
|
|
DEFINE tip_sal,nom_arc STRING,
|
|
nro_rep INT
|
|
|
|
LET nro_rep=nro_rep+1
|
|
|
|
LET nom_arc="./ArchEnviados/rep_",fgl_getpid() USING "<<<<<<<<<&",
|
|
"-",nro_rep USING "<<<<<<<<<&",".",DOWNSHIFT(tip_sal)
|
|
|
|
RETURN nom_arc
|
|
|
|
END FUNCTION
|
|
}
|
|
DEFINE url_verification,estado STRING,
|
|
codigo_err INT
|
|
FUNCTION rep_cotizacion(s)
|
|
DEFINE nombreVendedor,selec,s,s_out,inserta,cliente_ant,cliente_act STRING,
|
|
emailcliente VARCHAR(100),
|
|
codigodgii,ppagaitbis VARCHAR(10),
|
|
pvalor_desc,tasaCambio,valorTope DEC(12,2),
|
|
secvend_ant,tipo_cliente_ant,sec_cliente_ant INT
|
|
|
|
DEFINE detalles DYNAMIC ARRAY OF RECORD
|
|
secuencia INT,
|
|
area SMALLINT,
|
|
descripcion_area CHAR(50),
|
|
codid VARCHAR(25),
|
|
codigo VARCHAR(20),
|
|
cod_n SMALLINT,
|
|
cod_grupo SMALLINT,
|
|
cod_tipo SMALLINT,
|
|
cod_sec SMALLINT,
|
|
# descripcion VARCHAR(100),
|
|
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),
|
|
cantidad_reservada DEC(12,5),
|
|
fecha_inicio_reserva DATE,
|
|
fecha_vence_reserva DATE,
|
|
autorizada VARCHAR(10),
|
|
idkit INT,
|
|
disenoID VARCHAR(50)
|
|
|
|
END RECORD
|
|
|
|
|
|
DEFINE cotizacion RECORD
|
|
cotizacion_no INT,
|
|
fecha DATE,
|
|
ventas VARCHAR(1),
|
|
tipo_cliente SMALLINT,
|
|
sec_cliente INT,
|
|
nombre VARCHAR(100),
|
|
rnc VARCHAR(11),
|
|
nombre_proyecto VARCHAR(60),
|
|
direccion_proyecto VARCHAR(60),
|
|
direccion_cliente VARCHAR(80),
|
|
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),
|
|
contacto VARCHAR(100),
|
|
nombre_ciudad VARCHAR(60),
|
|
telefono_o VARCHAR(20),
|
|
telefono_r VARCHAR(20),
|
|
celular1 VARCHAR(20),
|
|
soporte VARCHAR(200),
|
|
instalador VARCHAR(200),
|
|
vendedor_aux VARCHAR(100),
|
|
sec_vend_aux INT,
|
|
cod_provincia SMALLINT,
|
|
nombre_vend VARCHAR(60),
|
|
porc_itbis DEC(8,2),
|
|
plazo_entrega VARCHAR(100),
|
|
comentario VARCHAR(100),
|
|
usuario VARCHAR(50),
|
|
clave VARCHAR(50),
|
|
etiqueta_cotizacion VARCHAR(60),
|
|
cod_zona SMALLINT,
|
|
codigo VARCHAR(10),
|
|
guiId STRING,
|
|
sincronizado BOOLEAN ,
|
|
tipo_documento CHAR(10),
|
|
bodega INT,
|
|
titulo_bodega VARCHAR(100),
|
|
estado STRING
|
|
END RECORD,
|
|
imagen BYTE
|
|
|
|
DEFINE rep_out RECORD
|
|
generales RECORD
|
|
cotizcion_no INT,
|
|
contenido STRING,
|
|
nomb_arch STRING,
|
|
cod_msg SMALLINT,
|
|
mensaje_out,valorBruto,valorDescuento,valorItbis,valorNeto STRING
|
|
END RECORD,
|
|
detalles DYNAMIC ARRAY OF RECORD
|
|
codid,area,cod_n,cod_grupo,cod_tipo,cod_sec INT,
|
|
titulo STRING,
|
|
cantidad1,cantidad,valorBruto,valorDescuento,valorItbis,valorTotal DEC(12,2)
|
|
|
|
END RECORD
|
|
END RECORD ,
|
|
detalles_out DYNAMIC ARRAY OF RECORD
|
|
codid,area,cod_n,cod_grupo,cod_tipo,cod_sec INT,
|
|
titulo STRING,
|
|
cantidad1,cantidad,valorBruto,valorDescuento,valorItbis,valorTotal DEC(12,2)
|
|
END RECORD,
|
|
|
|
cantidad_reg,pcotizacion_no INT
|
|
|
|
DEFINE r RECORD
|
|
ERROR STRING
|
|
END RECORD,
|
|
xdescripcion VARCHAR(100)
|
|
|
|
DEFINE tip_sal,arc_sal STRING
|
|
DEFINE p_hand om.SaxDocumentHandler,
|
|
xdescuento CHAR(2),
|
|
xfechadesc DATE,
|
|
pporc_desc,porc_auth,porc_vend FLOAT
|
|
|
|
DEFINE
|
|
permitedesc BOOLEAN,
|
|
cantidad_unidades DEC(12,2),
|
|
factor DEC(12,5)
|
|
# WHENEVER ERROR CONTINUE
|
|
|
|
TRY
|
|
CALL util.JSON.parse(s, p)
|
|
|
|
CATCH
|
|
LET r.error = "FGL ERROR: ", err_get(status)
|
|
RETURN util.JSON.stringify(r)
|
|
END TRY
|
|
|
|
LET cotizacion.* = p.cotizaciones.*
|
|
|
|
LET valorTope = 250000
|
|
|
|
{ ESTA PARTE FUNCIONA PARA CUANDO DESEO BLOQUEAR EL WS
|
|
LET rep_out.generales.mensaje_out = 'DEBE REALIZAR ESTA OPCION VIA GENERO, ESTE SERVICIO ESTA DESACTIVADO'
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
RETURN s_out
|
|
}
|
|
DISPLAY "USUARIO: ",p.cotizaciones.usuario
|
|
# Sin esto el default WHENEVER ERROR STOP aborta el proceso ante cualquier
|
|
# error SQL y deja la conexion colgada -> proximo request: "conexion en uso".
|
|
WHENEVER ANY ERROR CONTINUE
|
|
|
|
CONNECT TO "smarmotech" USER p.cotizaciones.usuario USING p.cotizaciones.clave
|
|
IF STATUS < 0 THEN
|
|
# Recupera conexion "smarmotech" colgada de un request previo y reintenta.
|
|
DISCONNECT ALL
|
|
CONNECT TO "smarmotech" USER p.cotizaciones.usuario USING p.cotizaciones.clave
|
|
END IF
|
|
IF STATUS < 0 THEN
|
|
LET rep_out.generales.mensaje_out = 'ERROR EN USUARIO CONECTANDOSE A LA BASE DE DATOS'," ",err_get(status)
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
# VERIFICA DIRECCION
|
|
IF p.cotizaciones.direccion_cliente IS NULL OR LENGTH(p.cotizaciones.direccion_cliente) < 6 THEN
|
|
LET rep_out.generales.mensaje_out = 'DIRECCION DEL CLIENTE ESTA EN BLANCO o ES MUY CORTA'
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
# VERIFICA EMAIL
|
|
IF P.cotizaciones.email IS NULL THEN
|
|
LET rep_out.generales.mensaje_out = 'FAVOR DE COLOCAR EMAIL, ESTA EN BLANCO'
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
#VERIFICACION TIPO CLIENTE
|
|
IF P.cotizaciones.tipo_cliente=19 OR P.cotizaciones.tipo_cliente=18
|
|
THEN
|
|
LET rep_out.generales.mensaje_out = 'ESTE TIPO DE CLIENTE NO ES PERMITIDO EN EL CRM'
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
IF (p.cotizaciones.tipo_cliente <> 16 AND p.cotizaciones.sec_cliente <> 11140) THEN
|
|
CALL inicializar()
|
|
LET url_verification =p.cotizaciones.email CLIPPED
|
|
IF p.cotizaciones.sec_vend <> 1 THEN
|
|
CALL apiclient(url_verification) RETURNING estado,codigo_err
|
|
IF codigo_Err =400 THEN
|
|
LET rep_out.generales.mensaje_out = 'EMAIL CLIENTE ERRADO, NO PUEDE REALIZAR COTIZACION'
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
END IF
|
|
|
|
IF p.cotizaciones.cond_pago IS NULL OR p.cotizaciones.cond_pago=1000 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CONDICION EN BLANCO o NO TIENE CONDICION, NO PUEDES REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF p.cotizaciones.sec_vend IS NULL OR p.cotizaciones.sec_vend=0 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE EL CODIGO VENDEDOR EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
SELECT a.paga_itbis INTO ppagaitbis FROM vetb00060 a WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente
|
|
IF ppagaitbis ='S' THEN
|
|
IF p.cotizaciones.porc_itbis IS NULL OR p.cotizaciones.porc_itbis=0 THEN
|
|
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE EL ITBIS EN NULO, NO PUEDE HACER COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
#CONTROL PROVINCIA
|
|
IF p.cotizaciones.cod_provincia IS NULL OR p.cotizaciones.cod_provincia = 0 THEN
|
|
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE EL ID PROVINCIA EN CERO, NO PUEDE HACER COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
SELECT a.cod_provincia FROM vetb00020 a WHERE a.cod_provincia = p.cotizaciones.cod_provincia AND a.status_t IS NULL
|
|
IF STATUS = NOTFOUND THEN
|
|
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='PROVINCIA NO EXISTE EN BASE DE DATOS GENERO, FAVOR DE VERIFICAR'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
SELECT a.codigo FROM vetb00017 a WHERE a.codigo = p.cotizaciones.codigo
|
|
IF STATUS = NOTFOUND THEN
|
|
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='PAIS ',p.cotizaciones.codigo, ' NO EXISTE EN BASE DE DATOS GENERO, FAVOR DE VERIFICAR'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
#-----------------------------------------------------------------------------------------------------------
|
|
|
|
# CONTROL ZONA
|
|
IF p.cotizaciones.cod_zona IS NULL OR p.cotizaciones.cod_zona = 0 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE EL ID ZONA EN CERO, NO PUEDE HACER COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
SELECT DISTINCT a.cod_zona FROM vetb00009 a WHERE a.cod_zona = p.cotizaciones.cod_zona AND a.status_t IS NULL
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='ZONA NO EXISTEN EN BASE DE DATOS GENERO, NO PUEDE HACER COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
#BUSCA NOMBRE DEL CLIENTE
|
|
SELECT a.nombre INTO p.cotizaciones.nombre FROM vetb00004 a WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente AND
|
|
a.sec_cliente = p.cotizaciones.sec_cliente AND
|
|
a.status_t IS NULL
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CLIENTE NO EXISTE EN LA MAESTRA DE CLIENTES EN GENERO, NO PUEDE HACER COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
LET emailcliente = NULL
|
|
IF p.cotizaciones.tipo_cliente = 15 OR p.cotizaciones.tipo_cliente = 16 THEN
|
|
SELECT RTRIM(a.patente) INTO emailcliente FROM vetb00004 a WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente AND
|
|
a.sec_cliente = p.cotizaciones.sec_cliente
|
|
|
|
|
|
IF emailcliente IS NULL OR LENGTH(emailcliente) < 6 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CLIENTE NO TIENE EL EMAIL EN LA MAESTRA O NO ES VALIDO LA INFORMACION, FAVOR DE COLOCAR INFORMACION, COTIZACION NO PUEDE SER CREADA O MODIFICADA'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
|
|
#CONTROL NUMERO RNC CLIENTE
|
|
IF p.cotizaciones.rnc IS NULL THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='RNC CLIENTE EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF p.cotizaciones.tipo_cliente <> 0 THEN
|
|
SELECT a.prima INTO tasaCambio FROM vetb00019 a WHERE a.disponible='S'
|
|
LET valorTope = 250000
|
|
IF p.cotizaciones.ventas = 3 THEN
|
|
LET valorTope = valorTope / tasaCambio
|
|
END IF
|
|
|
|
LET selec =
|
|
"SELECT a.estado1 ",
|
|
"FROM DGII.dbo.empresas a ",
|
|
"WHERE a.rnc = ? "
|
|
|
|
PREPARE query2 FROM selec
|
|
|
|
----
|
|
|
|
SELECT UNIQUE a.codigo_dgii INTO codigodgii FROM vetb00060 a
|
|
WHERE a.tipo_cliente = P.cotizaciones.tipo_cliente AND
|
|
a.ncf = 'S' AND a.paga_itbis ="S"
|
|
|
|
IF STATUS <> NOTFOUND THEN
|
|
IF p.cotizaciones.rnc IS NULL THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='RNC CLIENTE EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
ELSE
|
|
# ESTA DECISION ES PARA LOS CLIENTES CREDITO FISCAL
|
|
IF codigodgii ='31' THEN
|
|
EXECUTE query2 INTO estado_rnc USING p.cotizaciones.rnc
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='RNC CLIENTE INVALIDO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF estado_rnc = 'ANULADO' OR estado_rnc = 'CESE TEMPORAL' OR estado_rnc = 'DADO DE BAJA' OR
|
|
estado_rnc = 'RECHAZADO' OR estado_rnc= 'RECHAZADO' OR estado_rnc = 'SUSPENDIDO' THEN
|
|
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='RNC CLIENTE ESTA SUSPENDIDO POR LA DGII'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
#-----------------------------------------------------
|
|
# ESTA DECISION ES PARA LOS CLIENTES CONSUMIDORES QUE PASEN DE 250,000
|
|
#-----------------------------------------------------
|
|
IF codigodgii ='32' AND p.cotizaciones.total_cotizacion > valorTope THEN
|
|
IF p.cotizaciones.tipo_documento <> 3 THEN # CLIENTES PASAPORTES NO CONTROLA
|
|
IF LENGTH(p.cotizaciones.rnc CLIPPED) <> 11 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='LONGITUD CEDULA INVALIDA'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
END IF
|
|
#-------------------------------------------------------------------------
|
|
END IF
|
|
END IF
|
|
END IF
|
|
#---------------------------------------------------------------------
|
|
|
|
LET inserta = " INSERT INTO vetb00031 (id_kit,cotizacion_no,cod_n,cod_grupo,cod_tipo,cod_Sec,cantidad,precio,
|
|
porc_Desc)
|
|
SELECT a.id_kit,?,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.cantidad,a.precio,a.porc_desc
|
|
FROM vetb00030 a WHERE a.id_kit = ?"
|
|
|
|
PREPARE comando FROM inserta
|
|
IF p.cotizaciones.tipo_cliente = 0 THEN
|
|
LET p.cotizaciones.tipo_cliente=NULL
|
|
LET p.cotizaciones.sec_cliente=null
|
|
END IF
|
|
|
|
----- CONTROLA QUE EL LUGAR DE ENTREGA NO ESTE EN BLANCO
|
|
IF p.cotizaciones.bodega IS NULL THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='LUGAR DE ENTREGA EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
----- COLOCA EL VENDEDOR QUE TIENE EL CLIENTE COMO EJECUTIVO------------------------
|
|
|
|
LET secvend_ant = p.cotizaciones.sec_vend
|
|
{
|
|
SELECT a.sec_vend FROM vetb00028 a WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente AND
|
|
a.sec_cliente = p.cotizaciones.sec_cliente AND
|
|
a.sec_vend = p.cotizaciones.sec_vend
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='VENDEDOR NO LE VENDE A ESTE CLIENTE'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
COMENTADA EN FECHA 11/09/2025
|
|
VAMOS A CONTROLAR QUE SI ESE VENDEDOR NO LE VENDE AL CLIENTE EN LA COTIZACION,
|
|
LA RECHACE.
|
|
|
|
IF p.cotizaciones.sec_vend IS NULL THEN
|
|
LET p.cotizaciones.sec_vend = secvend_ant
|
|
|
|
END IF}
|
|
---- NOMBRE VENDEDOR -----
|
|
SELECT RTRIM(a.nom1_emp) || ' '|| a.apell1_emp INTO nombreVendedor FROM adtb00003 a WHERE a.num_emp = p.cotizaciones.sec_vend
|
|
|
|
# VERIFICA VENDEDOR AUXILIAR
|
|
IF p.cotizaciones.vendedor_aux IS NOT NULL OR p.cotizaciones.vendedor_aux > 0 THEN
|
|
|
|
SELECT DISTINCT a.sec_vend_aux FROM vetb00050 a
|
|
WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente AND
|
|
a.sec_cliente = p.cotizaciones.sec_cliente AND
|
|
a.sec_vend_aux = p.cotizaciones.vendedor_aux
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='VENDEDOR AUXILIAR NO ESTA ASOCIADO A ESTE CLIENTE, CONSULTE EL EJECUTIVO ',nombreVendedor CLIPPED
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
END IF
|
|
|
|
# BUSCA PORCENTAJE DE DESCUENTO DEL VENDEDOR
|
|
SELECT a.descuento1 INTO porc_vend FROM seg0001 a WHERE a.usuario =p.cotizaciones.usuario
|
|
|
|
# CALCULA MONTOS COTIZACION
|
|
LET detalles = p.detalles
|
|
|
|
LET p.cotizaciones.total_bruto =0
|
|
LET p.cotizaciones.monto_desc =0
|
|
LET p.cotizaciones.monto_itbis =0
|
|
LET p.cotizaciones.total_cotizacion =0
|
|
|
|
LET rep_out.generales.valorBruto=0
|
|
LET rep_out.generales.valorDescuento =0
|
|
LET rep_out.generales.valorItbis =0
|
|
LET rep_out.generales.valorNeto =0
|
|
IF p.detalles.getLength() < 1 OR p.detalles.getLength() IS null THEN
|
|
IF p.cotizaciones.cotizacion_no =0 OR p.cotizaciones.cotizacion_no IS NULL THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
END IF
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='DETALLE COTIZACION ESTA LLEGANDO AL WS EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
# CONTROL CLIENTE - MONEDA
|
|
SELECT a.tipo_cliente FROM vetb00060 a WHERE a.ventas = p.cotizaciones.ventas AND
|
|
a.tipo_cliente = p.cotizaciones.tipo_cliente
|
|
IF STATUS = NOTFOUND THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COMBINACION CLIENTE/MONEDA NO ES PERMITIDO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
CALL calcula(detalles,p.cotizaciones.porc_itbis) RETURNING p.cotizaciones.total_bruto,p.cotizaciones.monto_desc,p.cotizaciones.monto_itbis,
|
|
p.cotizaciones.total_cotizacion,detalles_out
|
|
|
|
DISPLAY "ESTE FUE EL CALCULO 1: ",p.cotizaciones.total_bruto,p.cotizaciones.monto_desc,"-",p.cotizaciones.monto_itbis,
|
|
"-",p.cotizaciones.total_cotizacion
|
|
LET cotizacion.total_bruto = p.cotizaciones.total_bruto
|
|
LET cotizacion.monto_desc = p.cotizaciones.monto_desc
|
|
LET cotizacion.monto_itbis = p.cotizaciones.monto_itbis
|
|
LET cotizacion.total_cotizacion = p.cotizaciones.total_cotizacion
|
|
|
|
#BUSCA EL RNC QUE TIENE EL CLIENTE EN LA MAESTRA
|
|
SELECT a.num_rnc,a.nombre INTO p.cotizaciones.rnc,p.cotizaciones.nombre
|
|
FROM vetb00004 a
|
|
WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente AND
|
|
a.sec_cliente =p.cotizaciones.sec_cliente
|
|
|
|
IF p.cotizaciones.cotizacion_no =0 OR p.cotizaciones.cotizacion_no IS NULL THEN
|
|
|
|
------- ADICIONA CLIENTE------------------------------------------------------------------------------
|
|
SELECT a.cotizacion_no INTO pcotizacion_no FROM vetb00053 a
|
|
IF pcotizacion_no IS NULL THEN
|
|
LET pcotizacion_no = 0
|
|
END IF
|
|
LET pcotizacion_no = pcotizacion_no + 1
|
|
|
|
IF p.cotizaciones.estado IS NULL OR p.cotizaciones.estado = 'OPCION' THEN
|
|
LET p.cotizaciones.estado = 'PROPUESTA'
|
|
END IF
|
|
|
|
BEGIN WORK
|
|
UPDATE vetb00053 SET cotizacion_no =pcotizacion_no
|
|
LET p.cotizaciones.cotizacion_no=pcotizacion_no
|
|
|
|
LET rep_out.generales.cotizcion_no = pcotizacion_no
|
|
|
|
|
|
# CONTROL ITBIS
|
|
|
|
LET cantidad_reg=p.detalles.getLength()
|
|
IF p.detalles.getLength() = 0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION NO TIENE PRODUCTOS ASOCIADOS'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF cotizacion.total_cotizacion <= 0 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL MONTO DE LA COTIZACION ES 0 O NEGATIVO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
### COTIZACION MASTER
|
|
|
|
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,telefono_o,telefono_r,celular1,sec_vend_aux,contacto,
|
|
plazo_entrega,instalador,cod_zona,codigo,sincronizado,guiid,bodega,titulo_bodega,estado)
|
|
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,cotizacion.porc_itbis,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.cotizaciones.usuario,getdate(),cotizacion.cod_provincia,cotizacion.telefono_o,
|
|
cotizacion.telefono_r,cotizacion.celular1,cotizacion.sec_vend_aux,cotizacion.contacto,
|
|
cotizacion.plazo_entrega,cotizacion.instalador,cotizacion.cod_zona,cotizacion.codigo,cotizacion.sincronizado,cotizacion.guiId,cotizacion.bodega,cotizacion.titulo_bodega,
|
|
p.cotizaciones.estado)
|
|
|
|
IF STATUS < 0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ="ERROR ADICIONANDO MASTER COTIZACION ",err_get(status)
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
FOR i = 1 TO p.detalles.getLength()
|
|
IF p.detalles[i].area IS NOT NULL THEN
|
|
LET xdescripcion = NULL
|
|
SELECT a.descrip_esp,a.descuento_permitido,a.fecha_desc,a.porc_desc,b.factor_conv
|
|
INTO xdescripcion,xdescuento,xfechadesc,pporc_desc,factor
|
|
FROM iptb00002 a LEFT OUTER JOIN iptb00001 b ON a.cod_n = b.cod_n AND
|
|
a.cod_grupo = b.cod_grupo AND
|
|
a.cod_tipo = b.cod_tipo AND
|
|
a.cod_Sec = b.cod_sec
|
|
WHERE a.cod_n = p.detalles[i].cod_n AND
|
|
a.cod_grupo = p.detalles[i].cod_grupo AND
|
|
a.cod_tipo = p.detalles[i].cod_tipo AND
|
|
a.cod_sec = p.detalles[i].cod_sec AND
|
|
a.status_t IS NULL
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL CODIGO ',p.detalles[i].codigo CLIPPED,' NO EXISTE NO PUEDE HACER LA COTIZACION',STATUS
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
# VERIFICA QUE EL CODIGO ESTE DUPLICADO EN EL ARREGLO
|
|
CALL repite_codigo()
|
|
|
|
IF verdad THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL PRODUCTO ',p.detalles[i].codigo CLIPPED,' ESTA DUPLICADO EN LA CAPTURA DE DATOS, COLOQUE UN AREA DIFERENTE '
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
#VERIFICA QUE EL PRODUCTO TENGA PRECIOS EN LA BASE DE DATOS
|
|
DISPLAY "VERFICACION DE PRECIOS: ",xdescripcion CLIPPED
|
|
SELECT DISTINCT a.cod_n FROM vetb00025 a WHERE a.cod_n = p.detalles[i].cod_n AND
|
|
a.cod_grupo = p.detalles[i].cod_grupo AND
|
|
a.cod_tipo = p.detalles[i].cod_tipo AND
|
|
a.cod_sec = p.detalles[i].cod_sec AND
|
|
a.ventas = p.cotizaciones.ventas
|
|
IF STATUS = NOTFOUND THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ="PRODUCTO ",xdescripcion CLIPPED,
|
|
"NO TIENE PRECIO EN GENERO, NO ES POSIBLE COTIZARLO"
|
|
DISPLAY "VERFICACION DE PRECIOS, NO TIENE ADD: ",xdescripcion CLIPPED
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
IF p.detalles[I].secuencia IS null THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='SECUENCIA ITEM ESTA EN BLANCO, NO PUEDE REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
#RUTINA PARA CONTROL DEL DESCUENTO POR ITEMS
|
|
DISPLAY "PARAMETROS: ",p.detalles[i].cod_n,p.detalles[i].cod_grupo,p.detalles[i].cod_tipo,
|
|
p.detalles[i].cod_sec," desc ",p.detalles[i].porc_desc
|
|
|
|
DISPLAY "FECHA DESC: ",pporc_desc, " PERMITIDO: ",xdescuento
|
|
CALL autorizadescuento(P.detalles[i].porc_desc,P.detalles[i].cod_n,P.detalles[i].cod_grupo,
|
|
P.detalles[i].cod_tipo,P.detalles[i].cod_sec,porc_vend,xdescuento,
|
|
p.cotizaciones.usuario)
|
|
RETURNING permitedesc,rep_out.generales.mensaje_out
|
|
DISPLAY "MENSAJE AUTO DESC: ",rep_out.generales.mensaje_out
|
|
IF NOT permitedesc THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
#LET rep_out.generales.mensaje_out ='SECUENCIA ITEM ESTA EN BLANCO, NO PUEDE REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
IF p.detalles[I].cantidad=0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CANTIDAD ESTA EN CERO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF p.detalles[I].precio=0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='PRECIO ESTA EN CERO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
IF p.detalles[i].idkit=0 THEN
|
|
LET p.detalles[i].idkit=NULL
|
|
END IF
|
|
# LET detalle.* = p.detalles[i].*
|
|
#busca el FACTURA CONVERSION
|
|
SELECT ISNULL(a.factor_conv,1) INTO factor FROM iptb00001 a
|
|
WHERE a.cod_n = p.detalles[i].cod_n AND a.cod_grupo = p.detalles[i].cod_grupo
|
|
AND a.cod_tipo = p.detalles[i].cod_tipo AND a.cod_sec = p.detalles[i].cod_sec
|
|
|
|
LET p.detalles[i].cantidad1 = p.detalles[i].cantidad * factor USING "###,###.##"
|
|
# LET cantidad_unidades =p.detalles[i].cantidad1 / factor
|
|
|
|
# LET p.detalles[i].cantidad = cantidad_unidades
|
|
LET pvalor_desc = (p.detalles[i].cantidad1 * p.detalles[i].precio) * (p.detalles[i].porc_desc/100)
|
|
# disenoID es uniqueidentifier: un string vacio no convierte -> pasarlo a NULL.
|
|
IF p.detalles[i].disenoID IS NOT NULL
|
|
AND LENGTH(p.detalles[i].disenoID CLIPPED) = 0 THEN
|
|
LET p.detalles[i].disenoID = NULL
|
|
END IF
|
|
|
|
INSERT INTO vetb00051 (cod_cia,ventas,cotizacion_no,area,descripcion_area,
|
|
cod_n,cod_grupo,cod_tipo,cod_Sec,descripcion,
|
|
cantidad_1,cantidad,porc_desc,precio,us_crea,fech_crea,
|
|
cantidad_reservada,fecha_inicio_reserva,fecha_vence_reserva,
|
|
autorizada,secuencia,us_mod,id_kit,sincronizado,valor_desc,disenoID
|
|
)
|
|
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, xdescripcion,
|
|
p.detalles[i].cantidad,p.detalles[i].cantidad1,
|
|
p.detalles[i].porc_desc,p.detalles[i].precio,p.cotizaciones.usuario,getdate(),
|
|
p.detalles[i].cantidad_reservada,p.detalles[i].fecha_inicio_reserva,
|
|
p.detalles[i].fecha_vence_reserva,p.detalles[i].autorizada,
|
|
p.detalles[i].secuencia,cantidad_reg,
|
|
p.detalles[i].idkit,cotizacion.sincronizado,pvalor_desc,p.detalles[i].disenoID)
|
|
|
|
IF STATUS < 0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=SQLCA.sqlcode
|
|
LET rep_out.generales.mensaje_out ="ERROR ADICIONANDO DETALLE COTIZACION ",err_get(status)
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
# INSERTA TABLA COTIZACIONES KIT
|
|
IF p.detalles[i].idkit IS NOT NULL THEN
|
|
EXECUTE comando USING pcotizacion_no,p.detalles[i].idkit
|
|
END IF
|
|
# INSERTA TABLA LOG DETALLE COTIZACION
|
|
|
|
|
|
INSERT INTO detalles_cot_log (secuencia
|
|
,area
|
|
,descripcion_area
|
|
,codid
|
|
,codigo
|
|
,cod_n
|
|
,cod_grupo
|
|
,cod_tipo
|
|
,cod_sec
|
|
,cantidad
|
|
,cantidad1
|
|
,precio
|
|
,porc_desc
|
|
,itbis
|
|
,valor
|
|
,cantidad_reservada
|
|
,fecha_inicio_reserva
|
|
,fecha_vence_reserva
|
|
,autorizada
|
|
,idkit
|
|
,fecha
|
|
,cotizacion_no) VALUES (
|
|
p.detalles[i].secuencia ,p.detalles[i].area ,p.detalles[i].descripcion_area,
|
|
p.detalles[i].codid,p.detalles[i].codigo,p.detalles[i].cod_n,p.detalles[i].cod_grupo,
|
|
p.detalles[i].cod_tipo,p.detalles[i].cod_sec,p.detalles[i].cantidad,p.detalles[i].cantidad1,
|
|
p.detalles[i].precio,p.detalles[i].porc_desc,p.detalles[i].itbis,p.detalles[i].valor,
|
|
p.detalles[i].cantidad_reservada ,p.detalles[i].fecha_inicio_reserva,
|
|
p.detalles[i].fecha_vence_reserva,p.detalles[i].autorizada,p.detalles[i].idkit,getdate(),
|
|
p.cotizaciones.cotizacion_no )
|
|
END IF
|
|
|
|
END FOR
|
|
|
|
INSERT INTO cotizaciones_log VALUES (
|
|
p.cotizaciones.cotizacion_no,p.cotizaciones.fecha,p.cotizaciones.ventas,
|
|
p.cotizaciones.tipo_cliente,p.cotizaciones.sec_cliente,p.cotizaciones.nombre,
|
|
p.cotizaciones.rnc,p.cotizaciones.nombre_proyecto,p.cotizaciones.direccion_proyecto,
|
|
p.cotizaciones.direccion_cliente,p.cotizaciones.cond_pago,p.cotizaciones.descripcion,
|
|
p.cotizaciones.celular,p.cotizaciones.email,p.cotizaciones.sec_vend,p.cotizaciones.total_bruto,
|
|
p.cotizaciones.monto_desc,p.cotizaciones.monto_itbis,p.cotizaciones.total_cotizacion,
|
|
p.cotizaciones.contacto ,p.cotizaciones.nombre_ciudad , p.cotizaciones.telefono_o,p.cotizaciones.telefono_r,
|
|
p.cotizaciones.celular1,p.cotizaciones.soporte ,p.cotizaciones.instalador,p.cotizaciones.vendedor_aux,
|
|
p.cotizaciones.sec_vend_aux ,p.cotizaciones.cod_provincia,p.cotizaciones.nombre_vend,
|
|
p.cotizaciones.porc_itbis,p.cotizaciones.plazo_entrega,p.cotizaciones.comentario,
|
|
p.cotizaciones.usuario,p.cotizaciones.clave,p.cotizaciones.etiqueta_cotizacion,
|
|
GETDATE(),p.cotizaciones.bodega,p.cotizaciones.titulo_bodega)
|
|
COMMIT WORK
|
|
|
|
LET rep_out.generales.cod_msg=200
|
|
LET rep_out.generales.mensaje_out = 'ADICION EXITOSA PAR EL EJECUTIVO ',nombreVendedor CLIPPED, ' QUIEN LE VENDE A ESTE CLIENTE'
|
|
|
|
|
|
LET rep_out.generales.valorBruto = p.cotizaciones.total_bruto
|
|
LET rep_out.generales.valorDescuento = p.cotizaciones.monto_desc
|
|
LET rep_out.generales.valorItbis = p.cotizaciones.monto_itbis
|
|
LET rep_out.generales.valorNeto = p.cotizaciones.total_cotizacion
|
|
|
|
LET rep_out.detalles.* = detalles_out.*
|
|
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISPLAY "Valores: ",p.cotizaciones.total_bruto," ",p.cotizaciones.total_cotizacion
|
|
{ LET tip_sal = "PDF"
|
|
IF NOT fgl_report_loadCurrentSettings("veprmt049_mob.4rp") THEN
|
|
LET rep_out.generales.cod_msg = sqlca.sqlerrm
|
|
LET rep_out.generales.mensaje_out="ERROR:NO ENCONTRE EL 4RP FILE"
|
|
|
|
EXIT PROGRAM
|
|
END IF
|
|
|
|
|
|
LET arc_sal=gen_nombre_archivo(tip_sal)
|
|
|
|
CALL fgl_report_selectDevice(UPSHIFT(tip_sal))
|
|
CALL fgl_report_selectPreview(false)
|
|
CALL fgl_report_setOutputFileName(arc_sal)
|
|
|
|
LET p_hand=fgl_report_commitCurrentSettings()
|
|
|
|
IF p_hand IS NOT NULL THEN
|
|
START REPORT imprimeO TO XML HANDLER p_hand
|
|
LOCATE imagen IN MEMORY
|
|
|
|
FOR i = 1 TO p.detalles.getLength()
|
|
IF p.detalles[i].area IS NOT NULL THEN
|
|
LET detalle.area = p.detalles[i].area
|
|
LET detalle.cantidad = p.detalles[i].cantidad
|
|
LET detalle.cantidad1=p.detalles[i].cantidad1
|
|
|
|
LET detalle.cod_grupo=p.detalles[i].cod_grupo
|
|
LET detalle.cod_n=p.detalles[i].cod_n
|
|
LET detalle.cod_sec=p.detalles[i].cod_sec
|
|
LET detalle.cod_tipo=p.detalles[i].cod_tipo
|
|
|
|
LET detalle.descripcion_area=p.detalles[i].descripcion_area
|
|
LET detalle.precio = p.detalles[i].precio
|
|
LET detalle.porc_desc = p.detalles[i].porc_desc
|
|
LET detalle.valor = p.detalles[i].valor
|
|
|
|
SELECT a.descrip_esp, a.imagen INTO detalle.descripcion,imagen FROM iptb00002 a WHERE
|
|
a.cod_n = detalle.cod_n AND a.cod_grupo = detalle.cod_grupo AND
|
|
a.cod_tipo = detalle.cod_tipo AND a.cod_sec = detalle.cod_sec
|
|
IF imagen IS NULL OR LENGTH(imagen) < 4 THEN
|
|
CALL imagen.readFile("fotodefault.jpg")
|
|
DISPLAY "CARGUE DEFAULT"
|
|
UPDATE vetb00051 SET foto_producto = imagen
|
|
WHERE cotizacion_no = cotizacion.cotizacion_no
|
|
END IF
|
|
UPDATE vetb00051 SET descripcion = detalle.descripcion
|
|
WHERE cotizacion_no = cotizacion.cotizacion_no AND cod_n = detalle.cod_n AND
|
|
cod_Grupo = detalle.cod_grupo AND
|
|
cod_tipo = detalle.cod_tipo AND
|
|
cod_sec = detalle.cod_sec
|
|
OUTPUT TO REPORT imprimeO(cotizacion.*,detalle.*,imagen)
|
|
|
|
|
|
END IF
|
|
END FOR
|
|
FINISH REPORT imprimeO
|
|
END IF
|
|
|
|
IF os.Path.exists(arc_sal) THEN
|
|
CALL file_to_b64(arc_sal) RETURNING rep_out.generales.contenido
|
|
LET rep_out.generales.nomb_arch=os.path.basename(arc_sal)
|
|
LET rep_out.generales.cotizcion_no= pcotizacion_no
|
|
# DISPLAY "GRW file '",rep_out.generales.nomb_arch,"' sent."
|
|
ELSE
|
|
LET rep_out.generales.nomb_arch="Error generating the GRW report"
|
|
|
|
END IF
|
|
}
|
|
|
|
# DISPLAY "retorno: ",s_out
|
|
ELSE
|
|
----------------- MODIFICANDO LA COTIZACION -------------------------------------
|
|
DISPLAY "ESTE FUE EL CALCULO modifica1: ",p.cotizaciones.total_bruto,p.cotizaciones.monto_desc,"-",p.cotizaciones.monto_itbis,
|
|
"-",p.cotizaciones.total_cotizacion
|
|
|
|
# VERIFICA QUE LA COTIZACION NO TENGA ORDEN DE PEDIDOS
|
|
|
|
SELECT a.cotizacion_no FROM prtb00012 a WHERE a.cotizacion_no=p.cotizaciones.cotizacion_no AND
|
|
a.status_T IS NULL
|
|
IF STATUS <> NOTFOUND THEN
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE ORDEN, NO PUEDES MODIFICAR'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF p.cotizaciones.estado IS NULL OR p.cotizaciones.estado = 'OPCION' THEN
|
|
LET p.cotizaciones.estado = 'PROPUESTA'
|
|
END IF
|
|
IF p.cotizaciones.cond_pago IS NULL OR p.cotizaciones.cond_pago=1000 THEN
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CONDICION EN BLANCO o NO TIENE CONDICION, NO PUEDES REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
SELECT a.paga_itbis INTO ppagaitbis FROM vetb00060 a WHERE a.tipo_cliente = p.cotizaciones.tipo_cliente
|
|
IF ppagaitbis ='S' THEN
|
|
|
|
IF cotizacion.porc_itbis IS NULL THEN
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.mensaje_out = 'PORCIENTO ITBIS ESTA EN BLANCO, NO SE ACTUALIZO LA COTIZACION EN GENERO'
|
|
LET rep_out.generales.nomb_arch=' '
|
|
LET rep_out.generales.cod_msg = 400
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
END IF
|
|
|
|
#VERIFICA SI LA COTIZACION TIENE UN AVANCE APLICADO
|
|
SELECT DISTINCT a.tipo_cliente,a.sec_cliente
|
|
INTO tipo_cliente_ant,sec_cliente_ant FROM cctb00001 a
|
|
WHERE a.documento_ref = p.cotizaciones.cotizacion_no AND
|
|
a.tipo_Doc = 'AV' AND a.num_doc = a.aplica_a AND
|
|
a.status_t IS NULL
|
|
|
|
IF STATUS != NOTFOUND THEN
|
|
LET cliente_ant = tipo_cliente_ant USING "##","-",sec_cliente_ant USING "&&&&&&&&"
|
|
LET cliente_act = cotizacion.tipo_cliente USING "##","-",cotizacion.sec_cliente USING "&&&&&&&&"
|
|
IF cliente_ant <> cliente_act THEN
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='COTIZACION TIENE RECIBO AVANCE'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
END IF
|
|
# ACTUALIZA COTIZACION
|
|
|
|
BEGIN WORK
|
|
UPDATE vetb00050 SET (
|
|
ventas ,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 ,
|
|
cod_provincia,telefono_o,telefono_r,celular1,sec_vend_aux,contacto,
|
|
plazo_entrega,us_mod,fech_mod,instalador,cod_zona,codigo,bodega,titulo_bodega)
|
|
=
|
|
(cotizacion.ventas,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.cotizaciones.porc_itbis,
|
|
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,cotizacion.cod_provincia,cotizacion.telefono_o,
|
|
cotizacion.telefono_r,cotizacion.celular1,cotizacion.sec_vend_aux,cotizacion.contacto,
|
|
cotizacion.plazo_entrega,p.cotizaciones.usuario,getdate(),cotizacion.instalador,cotizacion.cod_zona,
|
|
cotizacion.codigo,cotizacion.bodega,cotizacion.titulo_bodega
|
|
)
|
|
WHERE cotizacion_no = p.cotizaciones.cotizacion_no
|
|
IF STATUS < 0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out = "ERROR ACTUALIZANDO COTIZACION MASTER ",err_get(status)
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
INSERT INTO cotizaciones_log VALUES (
|
|
p.cotizaciones.cotizacion_no,p.cotizaciones.fecha,p.cotizaciones.ventas,
|
|
p.cotizaciones.tipo_cliente,p.cotizaciones.sec_cliente,p.cotizaciones.nombre,
|
|
p.cotizaciones.rnc,p.cotizaciones.nombre_proyecto,p.cotizaciones.direccion_proyecto,
|
|
p.cotizaciones.direccion_cliente,p.cotizaciones.cond_pago,p.cotizaciones.descripcion,
|
|
p.cotizaciones.celular,p.cotizaciones.email,p.cotizaciones.sec_vend,p.cotizaciones.total_bruto,
|
|
p.cotizaciones.monto_desc,p.cotizaciones.monto_itbis,p.cotizaciones.total_cotizacion,
|
|
p.cotizaciones.contacto ,p.cotizaciones.nombre_ciudad , p.cotizaciones.telefono_o,p.cotizaciones.telefono_r,
|
|
p.cotizaciones.celular1,p.cotizaciones.soporte ,p.cotizaciones.instalador,p.cotizaciones.vendedor_aux,
|
|
p.cotizaciones.sec_vend_aux ,p.cotizaciones.cod_provincia,p.cotizaciones.nombre_vend,
|
|
p.cotizaciones.porc_itbis,p.cotizaciones.plazo_entrega,p.cotizaciones.comentario,
|
|
p.cotizaciones.usuario,p.cotizaciones.clave,p.cotizaciones.etiqueta_cotizacion,
|
|
GETDATE(),p.cotizaciones.bodega,p.cotizaciones.titulo_bodega)
|
|
|
|
DELETE FROM vetb00051 WHERE cotizacion_no =p.cotizaciones.cotizacion_no
|
|
DELETE FROM vetb00031 WHERE cotizacion_no =p.cotizaciones.cotizacion_no
|
|
FOR i = 1 TO p.detalles.getLength()
|
|
IF p.detalles[i].area IS NOT NULL THEN
|
|
LET xdescripcion = NULL
|
|
LET xdescuento = NULL
|
|
|
|
SELECT a.descrip_esp,a.descuento_permitido,a.fecha_desc,a.porc_desc
|
|
INTO xdescripcion,xdescuento,xfechadesc,pporc_desc
|
|
FROM iptb00002 a
|
|
WHERE a.cod_n = p.detalles[i].cod_n AND
|
|
a.cod_grupo = p.detalles[i].cod_grupo AND
|
|
a.cod_tipo = p.detalles[i].cod_tipo AND
|
|
a.cod_sec = p.detalles[i].cod_sec AND
|
|
a.status_t IS NULL
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL CODIGO ',p.detalles[i].codigo CLIPPED,' NO EXISTE NO PUEDE HACER LA COTIZACION ',STATUS
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
ELSE
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL AREA ESTA EN BLANCO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
|
|
# VERIFICA QUE EL CODIGO ESTE DUPLICADO EN EL ARREGLO
|
|
CALL repite_codigo()
|
|
|
|
IF verdad THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='EL PRODUCTO ',p.detalles[i].codigo CLIPPED,' ESTA DUPLICADO EN LA CAPTURA DE DATOS, COLOQUE UN AREA DIFERENTE '
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
#VERIFICA QUE EL PRODUCTO TENGA PRECIOS EN LA BASE DE DATOS
|
|
DISPLAY "VERFICACION DE PRECIOS: ",xdescripcion CLIPPED
|
|
SELECT DISTINCT a.cod_n FROM vetb00025 a WHERE a.cod_n = p.detalles[i].cod_n AND
|
|
a.cod_grupo = p.detalles[i].cod_grupo AND
|
|
a.cod_tipo = p.detalles[i].cod_tipo AND
|
|
a.cod_sec = p.detalles[i].cod_sec AND
|
|
a.ventas = p.cotizaciones.ventas
|
|
IF STATUS = NOTFOUND THEN
|
|
ROLLBACK WORK
|
|
DISPLAY "VERFICACION DE PRECIOS, NO ENCONTRO: ",xdescripcion CLIPPED
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ="PRODUCTO ",xdescripcion CLIPPED,
|
|
"NO TIENE PRECIO EN GENERO, NO ES POSIBLE COTIZARLO"
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
#RUTINA PARA CONTROL DEL DESCUENTO POR ITEMS
|
|
SELECT DISTINCT a.porc_desc INTO porc_auth FROM vetb00088 a WHERE a.cotizacion_no =pcotizacion_no AND
|
|
a.cod_n = p.detalles[i].cod_n AND
|
|
a.cod_grupo = p.detalles[i].cod_grupo AND
|
|
a.cod_tipo = p.detalles[i].cod_tipo AND
|
|
a.cod_sec = p.detalles[i].cod_sec AND
|
|
a.area =p.detalles[i].area
|
|
IF STATUS = NOTFOUND THEN
|
|
CALL autorizadescuento(P.detalles[i].porc_desc,P.detalles[i].cod_n,P.detalles[i].cod_grupo,
|
|
P.detalles[i].cod_tipo,P.detalles[i].cod_sec,porc_vend,xdescuento,
|
|
p.cotizaciones.usuario)
|
|
RETURNING permitedesc,rep_out.generales.mensaje_out
|
|
DISPLAY "MENSAJE AUTO DESC: ",rep_out.generales.mensaje_out
|
|
IF NOT permitedesc THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
#LET rep_out.generales.mensaje_out ='SECUENCIA ITEM ESTA EN BLANCO, NO PUEDE REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
|
|
END IF
|
|
END IF
|
|
#--------------------------------------------------------------------------------------------------------
|
|
IF p.detalles[I].secuencia IS null THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='SECUENCIA ITEM ESTA EN BLANCO, NO PUEDE REALIZAR COTIZACION'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
IF p.detalles[I].cantidad=0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='CANTIDAD ESTA EN CERO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
|
|
IF p.detalles[I].precio=0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out ='PRECIO ESTA EN CERO'
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
IF p.detalles[i].idkit=0 THEN
|
|
LET p.detalles[i].idkit=NULL
|
|
END IF
|
|
|
|
# BUSCA EL FACTOR DE CONVERSION
|
|
SELECT ISNULL(a.factor_conv,1) INTO factor FROM iptb00001 a
|
|
WHERE a.cod_n = p.detalles[i].cod_n AND a.cod_grupo = p.detalles[i].cod_grupo
|
|
AND a.cod_tipo = p.detalles[i].cod_tipo AND a.cod_sec = p.detalles[i].cod_sec
|
|
|
|
LET p.detalles[i].cantidad1 = p.detalles[i].cantidad * factor USING "###,###.##"
|
|
LET cantidad_unidades =p.detalles[i].cantidad1 / factor
|
|
LET p.detalles[i].cantidad = cantidad_unidades
|
|
|
|
LET pvalor_desc = (p.detalles[i].cantidad1 * p.detalles[i].precio) * (p.detalles[i].porc_desc/100)
|
|
# disenoID es uniqueidentifier: un string vacio no convierte -> pasarlo a NULL.
|
|
IF p.detalles[i].disenoID IS NOT NULL
|
|
AND LENGTH(p.detalles[i].disenoID CLIPPED) = 0 THEN
|
|
LET p.detalles[i].disenoID = NULL
|
|
END IF
|
|
INSERT INTO vetb00051 (cod_cia,ventas,cotizacion_no,area,descripcion_area,
|
|
cod_n,cod_grupo,cod_tipo,cod_Sec, descripcion,
|
|
cantidad_1,cantidad,porc_desc,precio,us_crea,fech_crea,
|
|
cantidad_reservada,fecha_inicio_reserva,fecha_vence_reserva,
|
|
autorizada,secuencia,valor_desc,disenoID
|
|
)
|
|
VALUES ('1',cotizacion.ventas,p.cotizaciones.cotizacion_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, xdescripcion,
|
|
p.detalles[i].cantidad,p.detalles[i].cantidad1,
|
|
p.detalles[i].porc_desc,p.detalles[i].precio,p.cotizaciones.usuario,getdate(),
|
|
p.detalles[i].cantidad_reservada,p.detalles[i].fecha_inicio_reserva,
|
|
p.detalles[i].fecha_vence_reserva,p.detalles[i].autorizada,
|
|
p.detalles[i].secuencia,pvalor_desc,p.detalles[i].disenoID)
|
|
|
|
IF STATUS < 0 THEN
|
|
ROLLBACK WORK
|
|
LET rep_out.generales.cotizcion_no = 0
|
|
LET rep_out.generales.contenido = 'VACIO'
|
|
LET rep_out.generales.nomb_arch='notiene.pdf'
|
|
LET rep_out.generales.cod_msg=400
|
|
LET rep_out.generales.mensaje_out = SQLCA.sqlerrm
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
DISCONNECT CURRENT
|
|
RETURN s_out
|
|
END IF
|
|
# INSERTA TABLA LOG DETALLE COTIZACION
|
|
|
|
INSERT INTO detalles_cot_log (secuencia
|
|
,area
|
|
,descripcion_area
|
|
,codid
|
|
,codigo
|
|
,cod_n
|
|
,cod_grupo
|
|
,cod_tipo
|
|
,cod_sec
|
|
,cantidad
|
|
,cantidad1
|
|
,precio
|
|
,porc_desc
|
|
,itbis
|
|
,valor
|
|
,cantidad_reservada
|
|
,fecha_inicio_reserva
|
|
,fecha_vence_reserva
|
|
,autorizada
|
|
,idkit
|
|
,fecha
|
|
,cotizacion_no) VALUES (
|
|
p.detalles[i].secuencia ,p.detalles[i].area ,p.detalles[i].descripcion_area,
|
|
p.detalles[i].codid,p.detalles[i].codigo,p.detalles[i].cod_n,p.detalles[i].cod_grupo,
|
|
p.detalles[i].cod_tipo,p.detalles[i].cod_sec,p.detalles[i].cantidad,p.detalles[i].cantidad1,
|
|
p.detalles[i].precio,p.detalles[i].porc_desc,p.detalles[i].itbis,p.detalles[i].valor,
|
|
p.detalles[i].cantidad_reservada ,p.detalles[i].fecha_inicio_reserva,
|
|
p.detalles[i].fecha_vence_reserva,p.detalles[i].autorizada,p.detalles[i].idkit,getdate(),
|
|
p.cotizaciones.cotizacion_no )
|
|
# INSERTA TABLA COTIZACIONES KIT
|
|
IF p.detalles[i].idkit IS NOT NULL THEN
|
|
EXECUTE comando USING pcotizacion_no,p.detalles[i].idkit
|
|
END IF
|
|
|
|
END FOR
|
|
COMMIT WORK
|
|
|
|
LET rep_out.generales.cotizcion_no=p.cotizaciones.cotizacion_no
|
|
LET rep_out.generales.cod_msg=200
|
|
LET rep_out.generales.mensaje_out = 'MODIFICACION EXITOSA, ',rep_out.generales.mensaje_out CLIPPED
|
|
|
|
LET rep_out.generales.valorBruto = p.cotizaciones.total_bruto
|
|
LET rep_out.generales.valorDescuento = p.cotizaciones.monto_desc
|
|
LET rep_out.generales.valorItbis = p.cotizaciones.monto_itbis
|
|
LET rep_out.generales.valorNeto = p.cotizaciones.total_cotizacion
|
|
|
|
LET rep_out.detalles.* = detalles_out.*
|
|
|
|
LET s_out=util.JSON.stringify(rep_out)
|
|
|
|
END IF
|
|
|
|
|
|
DISCONNECT CURRENT
|
|
|
|
|
|
RETURN s_out
|
|
END FUNCTION
|
|
|
|
REPORT imprimeO(y,z,ximagen)
|
|
DEFINE ximagen BYTE
|
|
DEFINE y 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,
|
|
sub_total DEC(12,2),
|
|
monto_desc DEC(12,2),
|
|
monto_itbis DEC(12,2),
|
|
total_cotizacion DEC(12,2),
|
|
|
|
contacto VARCHAR(60),
|
|
nombre_ciudad VARCHAR(60),
|
|
telefono_o VARCHAR(20),
|
|
telefono_r VARCHAR(20),
|
|
celular1 VARCHAR(20),
|
|
soporte VARCHAR(200),
|
|
instalador VARCHAR(200),
|
|
vendedor_aux VARCHAR(100),
|
|
sec_vend_aux INT,
|
|
cod_provincia SMALLINT,
|
|
nombre_vend VARCHAR(60),
|
|
porc_itbis DEC(8,2),
|
|
plazo_entrega VARCHAR(100),
|
|
comentario VARCHAR(100),
|
|
usuario VARCHAR(50),
|
|
clave VARCHAR(50),
|
|
etiqueta_cotizacion VARCHAR(60)
|
|
END RECORD,
|
|
z RECORD
|
|
area SMALLINT,
|
|
descripcion_area CHAR(50),
|
|
codid VARCHAR(25),
|
|
codigo VARCHAR(20),
|
|
cod_n SMALLINT,
|
|
cod_grupo SMALLINT,
|
|
cod_tipo SMALLINT,
|
|
cod_sec SMALLINT,
|
|
descripcion VARCHAR(100),
|
|
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)
|
|
END RECORD
|
|
,
|
|
xnombre_a CHAR(30),
|
|
xnombre_p CHAR(50),
|
|
xmedida CHAR(3),
|
|
xtotal_p,bruto,descuento,neto,total_area DEC(12,2),
|
|
pfecha,hora,etiqueta,etiqueta1,etiqueta2,etiqueta3,etiqueta4,etiqueta5 CHAR(100),
|
|
xorden INT,
|
|
p_companias RECORD
|
|
nombre CHAR(60),
|
|
direccion VARCHAR(80),
|
|
rnc VARCHAR(11),
|
|
telefono VARCHAR(20),
|
|
fax VARCHAR(20),
|
|
paginaweb VARCHAR(80),
|
|
telefono1 VARCHAR(20),
|
|
fax1 VARCHAR(20)
|
|
END RECORD,
|
|
nombre_vend VARCHAR(60),
|
|
psimbolo VARCHAR(4)
|
|
|
|
ORDER BY z.area,z.cod_n,z.cod_grupo,z.cod_tipo,z.cod_sec
|
|
FORMAT
|
|
FIRST PAGE HEADER
|
|
LET pfecha = TODAY USING "DD/MM/YYYY"
|
|
LET hora = TIME
|
|
LET etiqueta = "FORMA DE PAGO: "#,y.descrip
|
|
LET etiqueta3 = "PLAZO ENTREGA: "#,y.plazo_entrega
|
|
LET etiqueta4 = "COMENTARIO: "
|
|
LET etiqueta5 = "Entre la empresa ",p_companias.nombre CLIPPED," de una parte y de la otra parte:"
|
|
|
|
LET etiqueta1 = "Las variaciones en las tonalidades y vetas se entienden como parte de la naturaleza de las piedras naturales."
|
|
LET etiqueta2 = " No somos responsables en las tardanzas en la entrega cuando esten sujetas a especificaciones de medidas y/o terminaciones. "
|
|
|
|
SELECT a.simbolo INTO psimbolo FROM vetb00061 a WHERE a.ventas = y.ventas
|
|
SELECT ISNULL(a.nom1_emp,' ')||" "||ISNULL(a.apell1_emp,' ') INTO nombre_vend FROM adtb00003 a
|
|
WHERE a.num_emp = y.sec_vend
|
|
SELECT a.nombre,a.direccion,a.rnc,a.telefono,a.telefono1,a.fax,a.fax1,a.paginaweb
|
|
INTO p_companias.nombre,p_companias.direccion,p_companias.rnc,p_companias.telefono,
|
|
p_companias.telefono1,p_companias.fax,p_companias.fax1,p_companias.paginaweb
|
|
FROM companias a
|
|
|
|
BEFORE GROUP OF z.area
|
|
LET total_area = 0
|
|
|
|
ON EVERY ROW
|
|
# BUSCA ORDEN
|
|
LET xorden = null
|
|
#SELECT a.num_oc INTO xorden
|
|
#FROM prtb00012 a
|
|
#WHERE a.cotizacion_no = y.cotizacion_no AND a.status_t IS NULL
|
|
|
|
LET bruto = 0
|
|
LET descuento = 0
|
|
|
|
LET bruto = z.cantidad1 * z.precio
|
|
LET descuento = (z.cantidad1*z.precio*(z.porc_Desc/100))
|
|
LET xtotal_p = bruto - descuento
|
|
# LET y.sub_total = y.sub_total + y.monto_desc
|
|
LET xnombre_p = z.descripcion
|
|
LET xnombre_a = z.descripcion_area
|
|
PRINTX p_companias.*,y.*,z.*,bruto,descuento,neto,
|
|
etiqueta,etiqueta2,etiqueta3,etiqueta4,etiqueta5,
|
|
xnombre_a,xnombre_p,xmedida,xtotal_p,xorden,nombre_vend,psimbolo,ximagen
|
|
|
|
|
|
AFTER GROUP OF z.area
|
|
LET total_area = GROUP SUM(z.cantidad1*z.precio)
|
|
|
|
PRINTX total_area
|
|
|
|
END REPORT
|
|
|
|
FUNCTION repite_codigo()
|
|
DEFINE k INT
|
|
|
|
LET ant_art.area = p.detalles[i].area
|
|
LET ant_art.cod_n = p.detalles[i].cod_n
|
|
LET ant_art.cod_grupo = p.detalles[i].cod_grupo
|
|
LET ant_art.cod_tipo = p.detalles[i].cod_tipo
|
|
LET ant_art.cod_sec = p.detalles[i].cod_sec
|
|
LET ant_art.cantidad = p.detalles[i].cantidad
|
|
LET ant_art.precio = p.detalles[i].precio
|
|
|
|
LET verdad = FALSE
|
|
FOR k = 1 TO p.detalles.getLength()
|
|
IF k != i THEN
|
|
IF p.detalles[k].cod_n IS NOT NULL AND
|
|
p.detalles[k].cod_grupo IS NOT NULL AND
|
|
p.detalles[k].cod_tipo IS NOT NULL AND
|
|
p.detalles[k].cod_sec IS NOT NULL THEN
|
|
|
|
IF p.detalles[k].area = ant_art.area AND
|
|
p.detalles[k].cod_n = ant_art.cod_n AND
|
|
p.detalles[k].cod_grupo = ant_art.cod_grupo AND
|
|
p.detalles[k].cod_tipo = ant_art.cod_tipo AND
|
|
p.detalles[k].cod_sec = ant_art.cod_sec
|
|
|
|
THEN
|
|
|
|
LET verdad = TRUE
|
|
EXIT FOR
|
|
|
|
END IF
|
|
END IF
|
|
END IF
|
|
END FOR
|
|
|
|
# RETURN verdad
|
|
END FUNCTION |