Commit d1c68100 authored by pgole's avatar pgole

Updated sql for MRP RUN Sql changes req id: M16FSAV003


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@103555 ce508802-f39f-4f6c-b175-0d175dae99d5
parent f1096d71
......@@ -79,51 +79,54 @@ end;
---------------------------Function fn_get_avgpotency ------------------------------------------------------------------------
create or replace function fn_get_avgpotency(as_item_code in char, as_site_code in char ,quantity in number)
create or replace function fn_get_avgpotency (as_item_code in char, as_site_code in char ,quantity in number)
return char is
lc_item_potency number(14,3);
avg_potency number(14,3);
lc_potency number(14,3) := 0 ;
lc_potency_perc number(14,3);
cnt number;
begin
begin
select potency_perc into lc_potency_perc
from item
where item_code = as_item_code ;
begin
select potency_perc into lc_potency_perc
from item
where item_code = as_item_code and site_code = as_site_code ;
exception when others then
lc_potency := quantity;
end;
if lc_potency_perc > 0 then
exception when others then
begin
select COUNT(*) into cnt
from qc_order WHERE status = 'C' and item_potency > 0 and ROWNUM <= 3 order by status_date desc ;
lc_potency := quantity;
exception when others then
lc_potency := quantity;
end;
end;
if lc_potency_perc > 0 then
begin
begin
select sum(item_potency) into lc_item_potency
from qc_order WHERE status = 'C' and item_potency > 0 and ROWNUM <= 3 order by status_date desc ;
select COUNT(*) into cnt
from qc_order
WHERE site_code = as_site_code
and item_code = as_item_code
and status = 'C'
and item_potency > 0 and ROWNUM <= 3 order by status_date desc ;
exception when others then
lc_potency := quantity;
end;
exception when others then
lc_potency := quantity;
end;
begin
avg_potency := (lc_item_potency / cnt) ;
select sum(item_potency) into lc_item_potency
from qc_order
WHERE site_code = as_site_code
and item_code = as_item_code
and status = 'C'
and item_potency > 0 and ROWNUM <= 3 order by status_date desc ;
exception when others then
lc_potency := lc_potency_perc/avg_potency * quantity/100 + quantity;
lc_potency := quantity;
end if;
end;
avg_potency := (lc_item_potency / cnt) ;
lc_potency := quantity / avg_potency * 100 ;
return lc_potency;
end if;
return lc_potency;
end;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment