CREATE OR REPLACE FUNCTION APPS.grn_qty_new (
p_shipment_header_id NUMBER,
p_shipment_line_id NUMBER,
p_transaction_type VARCHAR2
)
RETURN NUMBER
IS
v_qty NUMBER:=0;
v_qty_f NUMBER;
v_transaction_type VARCHAR2 (30);
v_transaction_id NUMBER;
v_count number;
v_routing_name varchar2(30);
c_qty number:=0;
ret_rcv_qty number:=0;
v_correct_qty number:=0;
v_rtv_qty number:=0;
CURSOR c1
IS
SELECT rt.*
FROM rcv_shipment_headers rsh,
rcv_shipment_lines rsl,
rcv_transactions rt
WHERE rsh.shipment_header_id = rsl.shipment_header_id
AND rsl.shipment_header_id = rt.shipment_header_id
AND rsl.shipment_line_id = rt.shipment_line_id
AND rsh.shipment_header_id =
p_shipment_header_id
--rsh.RECEIPT_NUM='5102140004389'
AND rt.shipment_line_id = p_shipment_line_id --61178
AND rt.transaction_type = p_transaction_type;
BEGIN
v_qty_f := 0;
FOR r1 IN c1
LOOP
begin
SELECT count(*)
into v_count
FROM rcv_transactions rt
WHERE rt.parent_transaction_id = r1.transaction_id;
exception
when no_data_found then
v_count:=0;
end;
if v_count>0then
FOR i IN (SELECT rt.transaction_type, rt.transaction_id,rt.QUANTITY
FROM rcv_transactions rt
WHERE rt.parent_transaction_id = r1.transaction_id)
LOOP
if i.transaction_type='RETURN TO RECEIVING'then
ret_rcv_qty:=ret_rcv_qty+(-1*i.QUANTITY);
elsif i.transaction_type='CORRECT' then
v_correct_qty:=v_correct_qty+i.QUANTITY;
elsif i.transaction_type='RETURN TO VENDOR' then
v_rtv_qty:=v_rtv_qty+(-1*i.QUANTITY);
end if;
end loop;
v_qty:=nvl(ret_rcv_qty,0)+nvl(v_correct_qty,0)+nvl(v_rtv_qty,0)+nvl(r1.QUANTITY,0);
elsif v_count=0 then
v_qty:=r1.QUANTITY;
end if;
v_qty_f := v_qty;--+r1.quantity;
END LOOP; --cursor c1 loop end
RETURN v_qty_f;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN (-1);
END;
/
p_shipment_header_id NUMBER,
p_shipment_line_id NUMBER,
p_transaction_type VARCHAR2
)
RETURN NUMBER
IS
v_qty NUMBER:=0;
v_qty_f NUMBER;
v_transaction_type VARCHAR2 (30);
v_transaction_id NUMBER;
v_count number;
v_routing_name varchar2(30);
c_qty number:=0;
ret_rcv_qty number:=0;
v_correct_qty number:=0;
v_rtv_qty number:=0;
CURSOR c1
IS
SELECT rt.*
FROM rcv_shipment_headers rsh,
rcv_shipment_lines rsl,
rcv_transactions rt
WHERE rsh.shipment_header_id = rsl.shipment_header_id
AND rsl.shipment_header_id = rt.shipment_header_id
AND rsl.shipment_line_id = rt.shipment_line_id
AND rsh.shipment_header_id =
p_shipment_header_id
--rsh.RECEIPT_NUM='5102140004389'
AND rt.shipment_line_id = p_shipment_line_id --61178
AND rt.transaction_type = p_transaction_type;
BEGIN
v_qty_f := 0;
FOR r1 IN c1
LOOP
begin
SELECT count(*)
into v_count
FROM rcv_transactions rt
WHERE rt.parent_transaction_id = r1.transaction_id;
exception
when no_data_found then
v_count:=0;
end;
if v_count>0then
FOR i IN (SELECT rt.transaction_type, rt.transaction_id,rt.QUANTITY
FROM rcv_transactions rt
WHERE rt.parent_transaction_id = r1.transaction_id)
LOOP
if i.transaction_type='RETURN TO RECEIVING'then
ret_rcv_qty:=ret_rcv_qty+(-1*i.QUANTITY);
elsif i.transaction_type='CORRECT' then
v_correct_qty:=v_correct_qty+i.QUANTITY;
elsif i.transaction_type='RETURN TO VENDOR' then
v_rtv_qty:=v_rtv_qty+(-1*i.QUANTITY);
end if;
end loop;
v_qty:=nvl(ret_rcv_qty,0)+nvl(v_correct_qty,0)+nvl(v_rtv_qty,0)+nvl(r1.QUANTITY,0);
elsif v_count=0 then
v_qty:=r1.QUANTITY;
end if;
v_qty_f := v_qty;--+r1.quantity;
END LOOP; --cursor c1 loop end
RETURN v_qty_f;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN (-1);
END;
/
No comments:
Post a Comment