224 lines
11 KiB
Plaintext
224 lines
11 KiB
Plaintext
{
|
|
PROGRAMA : veprmt040
|
|
OBJETIVO : AUTORIZACIONES DESCUENTOS
|
|
PROGRAMADOR : ING. JUAN FRANCISCO SOTO
|
|
FECHA DESARROLLO : 24/08/2015
|
|
|
|
|
|
}
|
|
SCHEMA decomarmol
|
|
GLOBALS
|
|
DEFINE pvetb88 RECORD LIKE vetb00088.*,
|
|
porc_desc DEC(8,2),
|
|
opt VARCHAR(3)
|
|
DEFINE usuarios,clave,nombre,nombre_v,descripcion VARCHAR(50),
|
|
impresor,ptipo SMALLINT,
|
|
pcotizacion,secCliente,psecvend,idx,s_idx INT,
|
|
|
|
pneto,subtotal,descuento,itbis,porc_itbis DEC(12,2),
|
|
pfecha DATE,
|
|
salida STRING,
|
|
chdescuento varchar(2)
|
|
|
|
DEFINE arr_items DYNAMIC ARRAY OF RECORD
|
|
area smallint,
|
|
cod_n smallint,
|
|
cod_grupo smallint,
|
|
cod_tipo smallint,
|
|
cod_sec smallint,
|
|
descripcion varchar(100),
|
|
cantidad dec(12,5),
|
|
precio dec(12,2),
|
|
valor dec(12,2),
|
|
porc_desc dec(12,2),
|
|
valor_desc dec(12,2),
|
|
costo dec(12,5),
|
|
valor_costo dec(12,5),
|
|
margen dec(12,2),
|
|
margen_porc dec(12,3),
|
|
descuento_aplicado dec(12,2)
|
|
END RECORD
|
|
END GLOBALS
|
|
MAIN
|
|
DEFER INTERRUPT
|
|
|
|
CALL ARG_VAL(1) RETURNING usuarios
|
|
CALL ARG_VAL(2) RETURNING clave
|
|
CALL ARG_VAL(4) RETURNING impresor
|
|
# CONNECT to "marmotech" AS "IFMX" USER usuarios USING clave
|
|
CONNECT TO "decomarmol" AS "MSSQL" USER usuarios USING clave
|
|
|
|
OPEN WINDOW vefmmt040 WITH FORM "vefmmt040"
|
|
DIALOG
|
|
INPUT BY NAME pcotizacion ATTRIBUTE(WITHOUT DEFAULTS)
|
|
AFTER FIELD pcotizacion
|
|
IF pcotizacion IS NOT NULL THEN
|
|
SET CONNECTION "MSSQL"
|
|
SELECT a.tipo_cliente,a.sec_cliente,a.nombre_cliente,
|
|
a.total_bruto,a.monto_desc,a.monto_itbi,a.total_neto,
|
|
a.sec_vend,CONVERT(CHAR(10), a.fecha,103),b.nom1_emp||' '||b.apell1_emp,
|
|
a.porc_itbi
|
|
INTO ptipo,seccliente,nombre,subtotal,descuento,itbis,pneto,
|
|
psecvend,pfecha,nombre_v,porc_itbis
|
|
FROM vetb00050 a,adtb00003 b
|
|
WHERE a.cotizacion_no =pcotizacion AND
|
|
a.sec_vend = b.num_emp
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
CALL fgl_winmessage("ERROR","COTIZACION NO EXISTE","INFO")
|
|
NEXT FIELD pcotizacion
|
|
END IF
|
|
|
|
DISPLAY BY NAME ptipo,seccliente,nombre,subtotal,descuento,itbis,pneto,
|
|
psecvend,pfecha,nombre_v
|
|
END IF
|
|
CALL arr_items.clear()
|
|
END INPUT
|
|
|
|
INPUT ARRAY arr_items FROM s_items.* ATTRIBUTE(WITHOUT DEFAULTS)
|
|
BEFORE INPUT
|
|
|
|
DECLARE busca_items CURSOR FOR
|
|
SELECT a.area,a.cod_n,a.cod_grupo,a.cod_tipo,a.cod_sec,b.descrip_esp,a.cantidad,a.precio,'0',
|
|
a.porc_desc,'0',c.material+c.gastos+c.labor,'0','0','0',d.porc_descuento
|
|
FROM vetb00051 a INNER JOIN iptb00002 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 LEFT OUTER JOIN
|
|
iptb00004 c ON 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
|
|
c.ano = YEAR(TODAY) AND c.mes_ini = '01' AND c.mes_fin ='12' LEFT OUTER JOIN
|
|
vetb00088 d ON a.cod_n = d.cod_n AND a.cod_grupo = d.cod_grupo AND a.cod_tipo = d.cod_tipo AND
|
|
a.cod_sec = d.cod_Sec AND a.cotizacion_no = d.cotizacion_no
|
|
|
|
WHERE a.cotizacion_no = pcotizacion
|
|
LET idx = 1
|
|
FOREACH busca_items INTO arr_items[idx].*
|
|
LET arr_items[idx].valor = arr_items[idx].cantidad*arr_items[idx].precio
|
|
LET arr_items[idx].valor_desc = arr_items[idx].valor*(arr_items[idx].porc_desc/100)
|
|
LET arr_items[idx].valor_costo = arr_items[idx].costo * arr_items[idx].cantidad
|
|
LET arr_items[idx].margen = (arr_items[idx].valor - arr_items[idx].valor_desc)-
|
|
arr_items[idx].valor_costo
|
|
|
|
IF arr_items[idx].valor_costo >0 THEN
|
|
LET arr_items[idx].margen_porc = ((arr_items[idx].precio - (arr_items[idx].costo *1.25))/
|
|
arr_items[idx].precio)*100
|
|
|
|
ELSE
|
|
LET arr_items[idx].margen_porc = 0
|
|
END IF
|
|
LET idx=idx + 1
|
|
END FOREACH
|
|
|
|
AFTER FIELD cod_Sec
|
|
LET idx = arr_curr()
|
|
LET s_idx = scr_line()
|
|
IF arr_items[idx].cod_Sec IS NOT NULL THEN
|
|
SELECT b.descrip_esp,b.descuento_permitido
|
|
INTO arr_items[idx].descripcion,chdescuento
|
|
FROM vetb00051 a,iptb00002 b
|
|
WHERE a.cotizacion_no = pcotizacion AND
|
|
a.cod_n = arr_items[idx].cod_n AND a.cod_grupo = arr_items[idx].cod_grupo AND
|
|
a.cod_tipo = arr_items[idx].cod_tipo AND a.cod_sec = arr_items[idx].cod_sec AND
|
|
a.area = arr_items[idx].area AND
|
|
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
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
CALL fgl_Winmessage("ERROR","CODIGO NO PERTENECE A COTIZACION","INFO")
|
|
NEXT FIELD cod_n
|
|
END IF
|
|
IF chdescuento = "NO" THEN
|
|
CALL fgl_winmessage("INFO","A ESTE PRODUCTO NO ES PERMITIDO COLOCAR DESCUENTO, PROCEDO A BORRAR DE LISTA","INFO")
|
|
CALL arr_items.deleteElement(idx)
|
|
END IF
|
|
DISPLAY arr_items[idx].descripcion TO s_items[s_idx].descripcion
|
|
END IF
|
|
|
|
ON ACTION ACTUALIZAR
|
|
LET opt = fgl_winquestion("INFO","ESTA SEGURO DE ACTUALIZAR?","NO","YES|NO","QUESTION",0)
|
|
IF opt = "YES" THEN
|
|
FOR idx = 1 TO arr_items.getLength()
|
|
IF arr_items[idx].descuento_aplicado IS NOT NULL THEN
|
|
SELECT a.cotizacion_no FROM vetb00088 a WHERE a.cotizacion_no = pcotizacion AND
|
|
a.area = arr_items[idx].area AND
|
|
a.cod_n = arr_items[idx].cod_n AND
|
|
a.cod_grupo = arr_items[idx].cod_grupo AND
|
|
a.cod_tipo = arr_items[idx].cod_tipo AND
|
|
a.cod_Sec = arr_items[idx].cod_sec
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
|
|
INSERT INTO vetb00088 (cotizacion_no,fecha_autorizacion,area,cod_n,cod_grupo,cod_tipo,cod_Sec,porc_descuento,costo,porc_desc,us_autoriza,autoriza)
|
|
VALUES (pcotizacion,getdate(),arr_items[idx].area,arr_items[idx].cod_n,arr_items[idx].cod_grupo,arr_items[idx].cod_tipo,arr_items[idx].cod_sec,
|
|
arr_items[idx].descuento_aplicado,arr_items[idx].costo, arr_items[idx].porc_desc,usuarios,'SI')
|
|
CALL registra_log()
|
|
CALL actualiza_cotizacion(arr_items[idx].descuento_aplicado,arr_items[idx].area,arr_items[idx].cod_n,arr_items[idx].cod_grupo,arr_items[idx].cod_tipo,arr_items[idx].cod_sec)
|
|
# SET CONNECTION "IFMX"
|
|
# CALL actualiza_cotizacion(arr_items[idx].descuento_aplicado,arr_items[idx].area,arr_items[idx].cod_n,arr_items[idx].cod_grupo,arr_items[idx].cod_tipo,arr_items[idx].cod_sec)
|
|
|
|
ELSE
|
|
UPDATE vetb00088 SET vetb00088.porc_descuento =arr_items[idx].descuento_aplicado,
|
|
vetb00088.fecha_autorizacion=getdate(),
|
|
us_autoriza = usuarios,
|
|
autoriza = 'SI'
|
|
WHERE cotizacion_no = pcotizacion AND
|
|
area = arr_items[idx].area AND
|
|
cod_n = arr_items[idx].cod_n AND
|
|
cod_grupo = arr_items[idx].cod_grupo AND
|
|
cod_tipo = arr_items[idx].cod_tipo AND
|
|
cod_sec = arr_items[idx].cod_sec
|
|
CALL registra_log()
|
|
CALL actualiza_cotizacion(arr_items[idx].descuento_aplicado,arr_items[idx].area,arr_items[idx].cod_n,arr_items[idx].cod_grupo,arr_items[idx].cod_tipo,arr_items[idx].cod_sec)
|
|
|
|
# SET CONNECTION "IFMX"
|
|
# CALL actualiza_cotizacion(arr_items[idx].descuento_aplicado,arr_items[idx].area,arr_items[idx].cod_n,arr_items[idx].cod_grupo,arr_items[idx].cod_tipo,arr_items[idx].cod_sec)
|
|
END IF
|
|
END IF
|
|
SET CONNECTION "MSSQL"
|
|
|
|
END FOR
|
|
CALL impresion(pcotizacion,'veprmt049.4rp','PDF',arr_items.getlength(),"COTIZACION") RETURNING salida
|
|
CALL msg(13)
|
|
END IF
|
|
NEXT FIELD pcotizacion
|
|
|
|
END INPUT
|
|
|
|
ON ACTION CANCEL
|
|
CALL fgl_winmessage("ERROR","OPERACION ABORTADA","INFO")
|
|
|
|
RETURN
|
|
|
|
END DIALOG
|
|
|
|
CLOSE WINDOW vefmmt040
|
|
|
|
END MAIN
|
|
FUNCTION actualiza_cotizacion(xporc_desc,xarea,codn,codgrupo,codtipo,codsec)
|
|
DEFINE total_bruto,xporc_desc DEC(12,2),
|
|
codn,codgrupo,codtipo,codsec,xarea INT
|
|
UPDATE vetb00051 SET porc_desc = xporc_Desc,
|
|
us_mod = usuarios,
|
|
fech_mod = getdate()
|
|
WHERE cotizacion_no = pcotizacion AND area = xarea AND
|
|
cod_n = codn AND cod_grupo = codgrupo AND
|
|
cod_tipo = codtipo AND cod_sec = codsec
|
|
|
|
SELECT SUM(a.cantidad*a.precio),SUM((a.cantidad*a.precio)*(a.porc_desc/100))
|
|
INTO total_bruto,descuento
|
|
FROM vetb00051 a
|
|
WHERE a.cotizacion_no = pcotizacion
|
|
LET subtotal = total_bruto - descuento
|
|
LET itbis = subtotal * (porc_itbis/100)
|
|
LET pneto = subtotal + itbis
|
|
UPDATE vetb00050 SET monto_desc = descuento,monto_itbi=itbis,sub_total = subtotal,total_neto = pneto,
|
|
us_mod = usuarios,fech_mod = getdate()
|
|
WHERE cotizacion_no = pcotizacion
|
|
|
|
END FUNCTION
|
|
FUNCTION registra_log()
|
|
SET CONNECTION "MSSQL"
|
|
|
|
INSERT INTO vetb00094 (cotizacion_no,fecha_registro,us_crea,area,cod_n,cod_grupo,cod_tipo,cod_sec,porc_desc)
|
|
VALUES (pcotizacion,getdate(),usuarios,pvetb88.area,pvetb88.cod_n,pvetb88.cod_grupo,pvetb88.cod_tipo,pvetb88.cod_sec,
|
|
porc_desc)
|
|
END FUNCTION |