JSOTO Adicion grupos ADMINISTRACION PERSONAL Y NOMINA
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
{
|
||||
FUNCION : requisiciondespacho()
|
||||
OBJETIVO : hacer la requisicion de despacho automatica
|
||||
FECHA : 27/08/2011
|
||||
DESARROLLADO POR : Ing. Juan Soto
|
||||
}
|
||||
SCHEMA smarmotech
|
||||
FUNCTION requisiciondespacho(xnum_oc,xtipo_cliente,xsec_cliente,xcondpago,xmonto,xfecha_oc,
|
||||
xsec_vend,pusuarios)
|
||||
|
||||
DEFINE xnum_oc INT,
|
||||
xfecha_oc DATE,
|
||||
xsec_vend,xkit INT,
|
||||
xnumreq,xtipo_cliente,xsec_cliente,pcotizacion INT,
|
||||
idx,xcondpago smallint,
|
||||
chmensaje,procedimiento,cuerpo_correo,subject STRING,
|
||||
vendedorEmail,nombre_vendedor CHAR(60),
|
||||
pusuarios CHAR(50),
|
||||
selec STRING,
|
||||
txtmensaje VARCHAR(200),
|
||||
pubicacion VARCHAR(170)
|
||||
|
||||
DEFINE arr_requisicion DYNAMIC ARRAY OF RECORD
|
||||
procesa CHAR(3),
|
||||
num_oc INT,
|
||||
fecha CHAR(10),
|
||||
cotizacion_no INT,
|
||||
tipo_cliente SMALLINT,
|
||||
sec_cliente INT,
|
||||
nombre CHAR(30),
|
||||
cantidad_1 DEC(12,5),
|
||||
cantidad DEC(12,5),
|
||||
area SMALLINT,
|
||||
cod_n SMALLINT,
|
||||
cod_grupo SMALLINT,
|
||||
cod_tipo SMALLINT,
|
||||
cod_sec SMALLINT,
|
||||
descripcion CHAR(30),
|
||||
unidad_med CHAR(3),
|
||||
cantidad_ord1 DEC(12,5),
|
||||
cantidad_ord DEC(12,5),
|
||||
cantidad_pendiente DEC(12,5),
|
||||
precio DEC(12,2),
|
||||
descuento DEC(12,2),
|
||||
descvalor DEC(12,2),
|
||||
valor DEC(12,2)
|
||||
END RECORD,
|
||||
pitbis,xmonto,monto_cotizacion DEC(12,2),
|
||||
estado_req varchar(30),
|
||||
cuenta smallint
|
||||
|
||||
SET CONNECTION "MSSQL"
|
||||
|
||||
LET monto_cotizacion = xmonto
|
||||
|
||||
SELECT b.nom1_emp || ' '||b.apell1_emp,a.email
|
||||
INTO nombre_vendedor,vendedorEmail
|
||||
FROM seg0000 a,adtb00003 b
|
||||
WHERE a.sec_vend = xsec_vend and
|
||||
a.sec_vend = b.num_emp
|
||||
|
||||
# PREPARE s FROM "SELECT @@IDENTITY"
|
||||
|
||||
SELECT a.num_req INTO xnumreq FROM cctb00019 a
|
||||
IF xnumreq IS NULL THEN
|
||||
LET xnumreq = 0
|
||||
END IF
|
||||
LET xnumreq = xnumreq + 1
|
||||
|
||||
BEGIN WORK
|
||||
UPDATE cctb00019 SET num_req = xnumreq,us_crea=pusuarios,fech_crea=getdate()
|
||||
# EXECUTE s INTO xnumreq
|
||||
|
||||
LET selec =
|
||||
"INSERT INTO cctb00034 (id_kit,cotizacion_no,num_oc,num_req,secuencia,area,cod_n,cod_grupo,cod_tipo,cod_sec,cantidad)",
|
||||
"SELECT a.id_kit,a.cotizacion_no,a.num_oc,'",xnumreq USING "<<<<<<","',a.secuencia,a.area,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,a.cantidad ",
|
||||
"FROM prtb00031 a ",
|
||||
" WHERE ",
|
||||
" a.num_oc ='", xnum_oc USING "<<<<<<","'"
|
||||
PREPARE xcctb34 FROM selec
|
||||
EXECUTE xcctb34
|
||||
|
||||
IF STATUS < 0 THEN
|
||||
ROLLBACK WORK
|
||||
CALL fgl_winmessage("ERROR",SQLCA.SQLCODE,"INFO")
|
||||
RETURN xnumreq,xmonto
|
||||
END IF
|
||||
|
||||
LET estado_req = 'NO AUTORIZADA'
|
||||
DECLARE insertaReq CURSOR FOR
|
||||
SELECT a.num_oc,a.cotizacion_no,b.secuencia,b.area,b.cod_n,b.cod_grupo,b.cod_tipo,
|
||||
b.cod_Sec,b.cantidad_1,b.cantidad,b.cantidad_1,b.cantidad,c.precio,
|
||||
c.porc_Desc,(c.precio*c.cantidad) * (c.porc_desc/100),a.tipo_cliente,a.sec_cliente,
|
||||
d.nombre_cliente,d.porc_itbi,c.id_kit,a.ubicacion,d.direccion_proyecto
|
||||
FROM prtb00012 a,prtb00023 b,vetb00051 c,vetb00050 d
|
||||
WHERE a.num_oc = b.num_oc and
|
||||
a.cotizacion_no = c.cotizacion_no and
|
||||
a.cotizacion_no = d.cotizacion_no and
|
||||
a.num_oc = xnum_oc and
|
||||
b.cod_n = c.cod_n and
|
||||
b.cod_grupo = c.cod_grupo and
|
||||
b.cod_tipo = c.cod_tipo and
|
||||
b.cod_sec = c.cod_sec AND
|
||||
b.area = c.area
|
||||
UNION
|
||||
SELECT a.num_oc,a.cotizacion_no,b.secuencia,b.area,b.cod_n,b.cod_grupo,b.cod_tipo,
|
||||
b.cod_Sec,b.cantidad_1,b.cantidad,b.cantidad_1,b.cantidad,c.precio,
|
||||
c.porc_Desc,(c.precio*c.cantidad) * (c.porc_desc/100),a.tipo_cliente,a.sec_cliente,
|
||||
d.nombre_cliente,d.porc_itbi,c.id_kit,a.ubicacion,d.direccion_proyecto
|
||||
FROM prtb00012 a,prtb00023 b,vetb00031 c,vetb00050 d
|
||||
WHERE a.num_oc = b.num_oc and
|
||||
a.cotizacion_no = c.cotizacion_no and
|
||||
a.cotizacion_no = d.cotizacion_no and
|
||||
a.num_oc = xnum_oc and
|
||||
b.cod_n = c.cod_n and
|
||||
b.cod_grupo = c.cod_grupo and
|
||||
b.cod_tipo = c.cod_tipo and
|
||||
b.cod_sec = c.cod_sec AND
|
||||
b.area = c.area
|
||||
|
||||
|
||||
LET idx = 1
|
||||
LET pcotizacion = 0
|
||||
LET xmonto = 0
|
||||
# DISPLAY " ESTOY EN ESTO ",xnum_oc
|
||||
FOREACH insertareq INTO arr_requisicion[idx].num_oc,
|
||||
arr_requisicion[idx].cotizacion_no,
|
||||
idx,
|
||||
arr_requisicion[idx].area,
|
||||
arr_requisicion[idx].cod_n,
|
||||
arr_requisicion[idx].cod_grupo,
|
||||
arr_requisicion[idx].cod_tipo,
|
||||
arr_requisicion[idx].cod_Sec,
|
||||
arr_requisicion[idx].cantidad_1,
|
||||
arr_requisicion[idx].cantidad,
|
||||
arr_requisicion[idx].cantidad_ord,
|
||||
arr_requisicion[idx].cantidad_ord1,
|
||||
arr_requisicion[idx].precio,
|
||||
arr_requisicion[idx].descuento,
|
||||
arr_requisicion[idx].descvalor,
|
||||
arr_requisicion[idx].tipo_cliente,
|
||||
arr_requisicion[idx].sec_cliente,
|
||||
arr_requisicion[idx].nombre,
|
||||
pitbis,xkit,
|
||||
pubicacion
|
||||
|
||||
#DISPLAY " VOY PARA LA 26, en el foreach cantidad ",arr_requisicion[idx].cantidad_ord
|
||||
IF arr_requisicion[idx].cantidad_ord IS NOT NULL THEN
|
||||
LET pcotizacion = arr_requisicion[idx].cotizacion_no
|
||||
IF arr_requisicion[idx].descvalor IS NULL THEN
|
||||
LET arr_requisicion[idx].descvalor=0
|
||||
END IF
|
||||
LET arr_requisicion[idx].valor = (arr_requisicion[idx].cantidad *arr_requisicion[idx].precio) -
|
||||
arr_requisicion[idx].descvalor
|
||||
LET arr_requisicion[idx].valor = arr_requisicion[idx].valor + (arr_requisicion[idx].valor * (pitbis/100))
|
||||
LET xmonto = arr_requisicion[idx].valor + xmonto
|
||||
INSERT INTO cctb00026 (num_req,num_oc,cotizacion_no,id,area,cod_n,cod_grupo,cod_tipo,cod_Sec,
|
||||
cantidad_ord1,cantidad_ord,cantidad_1,cantidad,precio,
|
||||
descuento,descvalor,valor,us_crea,fech_crea,estado,id_kit)
|
||||
VALUES (xnumreq,arr_requisicion[idx].num_oc,arr_requisicion[idx].cotizacion_no,
|
||||
idx,arr_requisicion[idx].area,arr_requisicion[idx].cod_n,arr_requisicion[idx].cod_grupo,
|
||||
arr_requisicion[idx].cod_tipo,arr_requisicion[idx].cod_Sec,
|
||||
arr_requisicion[idx].cantidad_ord1,arr_requisicion[idx].cantidad_ord,
|
||||
arr_requisicion[idx].cantidad_1,
|
||||
arr_requisicion[idx].cantidad,
|
||||
arr_requisicion[idx].precio,arr_requisicion[idx].descuento,
|
||||
arr_requisicion[idx].descvalor,
|
||||
arr_requisicion[idx].valor,SUSER_SNAME(),GETDATE(),estado_req,xkit)
|
||||
|
||||
IF STATUS < 0 THEN
|
||||
ROLLBACK WORK
|
||||
CALL fgl_winmessage("ERROR",SQLCA.SQLCODE,"INFO")
|
||||
RETURN xnumreq,xmonto
|
||||
|
||||
END IF
|
||||
|
||||
# EXECUTE xcctb34 USING xkit
|
||||
# IF STATUS < 0 THEN
|
||||
# ROLLBACK WORK
|
||||
# RETURN xnumreq,xmonto
|
||||
# END IF
|
||||
|
||||
END IF
|
||||
LET idx = idx +1
|
||||
END FOREACH
|
||||
|
||||
# CONTROL MONTO REQUISION
|
||||
{ IF xmonto > monto_cotizacion THEN
|
||||
# ROLLBACK WORK
|
||||
|
||||
LET xnumreq = 0
|
||||
LET xmonto=0
|
||||
RETURN xnumreq,xmonto
|
||||
END IF
|
||||
}
|
||||
IF pcotizacion IS NOT NULL THEN
|
||||
SELECT DISTINCT a.cotizacion_no FROM vetb00022 a WHERE a.cotizacion_no = pcotizacion
|
||||
IF STATUS <> NOTFOUND THEN
|
||||
LET selec =
|
||||
"INSERT INTO cctb00027 (num_req,etiqueta,num_oc,secuencia,area,cod_n,cod_grupo,cod_tipo,cod_sec, ",
|
||||
"Lado_1,lado_2,lado_3,cantidad,medida,cantidad_r,medida_r,us_crea,",
|
||||
"fech_crea)",
|
||||
" SELECT '",xnumreq,"',etiqueta,'",xnum_oc,"',secuencia,area,cod_n,cod_grupo,cod_tipo,cod_sec,lado_1,lado_2,lado_3,",
|
||||
"ISNULL(cantidad,0),medida,ISNULL(cantidad,0),medida,'",pusuarios CLIPPED,"',getdate() FROM vetb00022 WHERE cotizacion_no= ",
|
||||
pcotizacion USING "<<<<<<<<"
|
||||
|
||||
PREPARE comando FROM selec
|
||||
EXECUTE comando
|
||||
IF STATUS < 0 THEN
|
||||
ROLLBACK WORK
|
||||
CALL fgl_winmessage("ERROR",SQLCA.SQLCODE,"INFO")
|
||||
RETURN xnumreq,xmonto
|
||||
|
||||
END IF
|
||||
|
||||
END IF
|
||||
END IF
|
||||
INSERT INTO cctb00025 (num_req,fecha,sec_vend,sec_vend_aprobado,us_crea,fech_crea,
|
||||
estado,fecha_autorizacion,estado_despacho,monto_req)
|
||||
VALUES (xnumreq,today,xsec_vend,null,SUSER_NAME(),GETDATE(),estado_req,getdate(),
|
||||
"NO DESPACHADA",xmonto)
|
||||
IF STATUS < 0 THEN
|
||||
ROLLBACK WORK
|
||||
CALL fgl_winmessage("ERROR",SQLCA.SQLCODE,"INFO")
|
||||
RETURN xnumreq,xmonto
|
||||
|
||||
END IF
|
||||
COMMIT WORK
|
||||
|
||||
|
||||
IF xcondpago <> 4 and xcondpago<> 10 THEN
|
||||
CALL entramensaje(xnumreq,pcotizacion,"A",pusuarios)
|
||||
END IF
|
||||
IF xcondpago = 4 OR xcondpago = 10 THEN
|
||||
INSERT INTO cctb00029 (num_req,mensaje,us_crea,fech_crea) VALUES (xnumreq,pubicacion,pusuarios,getdate())
|
||||
END IF
|
||||
LET chmensaje = "NUMERO DE REQUISICION: ",xnumreq USING "<<<<<<"
|
||||
LET subject = "AVISO REQUISICION DESPACHO NO. ",xnumreq USING "&&&&&&"
|
||||
LET procedimiento = "{ call cc_avisadespacho(?,?,?,?) }" CLIPPED
|
||||
LET cuerpo_correo = "VENDEDOR : ",nombre_vendedor CLIPPED
|
||||
LET cuerpo_correo = cuerpo_correo CLIPPED," FECHA REQUISICION : ",xfecha_oc USING "DD/MM/YYYY"
|
||||
LET cuerpo_correo = cuerpo_correo CLIPPED," NUMERO DE ORDEN: ",xnum_oc USING "&&&&&&"
|
||||
LET cuerpo_correo = cuerpo_correo CLIPPED," CLIENTE: ",arr_requisicion[1].nombre
|
||||
|
||||
# CALL envia_correo('rantonio@marmotech.com.do;jsantelises@marmotech.com.do',vendedorEmail,cuerpo_correo,
|
||||
# subject, procedimiento )
|
||||
|
||||
# CALL fgl_Winmessage("INFORMACION",chmensaje,"STOP")
|
||||
RETURN xnumreq,xmonto
|
||||
END FUNCTION
|
||||
Reference in New Issue
Block a user