create or replace package body cuttoship_lots is

  procedure prod_run(p_w_day date) as
begin
delete cuttoship_lot;
commit;
prod_erp(p_w_day);
prod_szbgerp(p_w_day);
prod_shs(p_w_day);
prod_subedit;
prod_ins_rpt;
prod_update_0;
end; procedure prod_erp(p_w_day date) as
begin
--panel qty
for c in (select 'erp' as site,lotno,max(gen_date) w_day
from facd321
where gen_date>=trunc(p_w_day) and gen_date<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
end loop; --trf to sewing qty
for c in (select 'erp' as site,lotno,max(import_time) w_day
from facd512
where import_time>=trunc(p_w_day) and import_time<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
end loop; --output qty
for c in (select 'erp' as site,lotno,max(lrrq) w_day
from facd105
where lrrq>=trunc(p_w_day) and lrrq<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
end loop; --leftover garments
for c in (select 'erp' as site,lotno,max(lrrq) w_day
from facd550
where lrrq>=trunc(p_w_day) and lrrq<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
end loop; --reason qty
for c in (select 'erp' as site,lotno,max(lastupdate) w_day
from facd343
where lastupdate>=trunc(p_w_day) and lastupdate<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
end loop; --log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_erp',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_erp',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
end; procedure prod_szbgerp(p_w_day date) as
p_ck number;
begin
p_ck:=0;
--panel qty
for c in (select 'szbgerp' as site,lotno,max(gen_date) w_day
from facd321@szbgerp
where gen_date>=trunc(p_w_day) and gen_date<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --trf to sewing qty
for c in (select 'szbgerp' as site,lotno,max(import_time) w_day
from facd512@szbgerp
where import_time>=trunc(p_w_day) and import_time<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --output qty
for c in (select 'szbgerp' as site,lotno,max(lrrq) w_day
from facd105@szbgerp
where lrrq>=trunc(p_w_day) and lrrq<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --leftover garments
for c in (select 'szbgerp' as site,lotno,max(w_day) w_day
from facd340@szbgerp
where w_day>=trunc(p_w_day) and w_day<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --reason qty
for c in (select 'szbgerp' as site,lotno,max(lastupdate) w_day
from facd343@szbgerp
where lastupdate>=trunc(p_w_day) and lastupdate<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
end if;
--log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_szbgerp',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_szbgerp',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
end; procedure prod_shs(p_w_day date) as
p_ck number;
begin
p_ck:=0; --panel qty
for c in (select 'shs' as site,lotno,max(gen_date) w_day
from facd321@shs
where gen_date>=trunc(p_w_day) and gen_date<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if; --trf to sewing qty
for c in (select 'shs' as site,lotno,max(import_time) w_day
from facd512@shs
where import_time>=trunc(p_w_day) and import_time<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if; --output qty
for c in (select 'shs' as site,lotno,max(lrrq) w_day
from facd105@shs
where lrrq>=trunc(p_w_day) and lrrq<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if; --leftover garments
for c in (select 'shs' as site,lotno,max(w_day) w_day
from facd340@shs
where w_day>=trunc(p_w_day) and w_day<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if; --reason qty
for c in (select 'shs' as site,lotno,max(lastupdate) w_day
from facd343@shs
where lastupdate>=trunc(p_w_day) and lastupdate<trunc(p_w_day+1)
group by lotno) loop
insert into cuttoship_lot
values(c.site,c.lotno,c.w_day);
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
end if; --log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_shs',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_shs',
trunc(p_w_day),
SYSDATE,
get_OS('OS_USER'));
commit;
end; procedure prod_subedit as
maxday date;
p_ck number;
begin
--delete the smae lotno records
for c in (select site,lotno,day
from cuttoship_lot
where site='erp') loop
select count(0) into p_ck
from cuttoship_lot
where site='szbgerp' and lotno=c.lotno;
if p_ck>0 then
select day into maxday
from cuttoship_lot
where site='szbgerp' and lotno=c.lotno;
if maxday>c.day then
delete cuttoship_lot where site=c.site and lotno=c.lotno;
elsif maxday<c.day then
delete cuttoship_lot where site='szbgerp' and lotno=c.lotno;
end if;
end if;
commit;
end loop; for c in (select site,lotno,day
from cuttoship_lot
where site in('erp','szbgerp')) loop
select count(0) into p_ck
from cuttoship_lot
where site='shs' and lotno=c.lotno;
if p_ck>0 then
select day into maxday
from cuttoship_lot
where site='shs' and lotno=c.lotno;
if maxday>c.day then
delete cuttoship_lot where site=c.site and lotno=c.lotno;
elsif maxday<c.day then
delete cuttoship_lot where site='shs' and lotno=c.lotno;
end if;
end if;
commit;
end loop; --log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_subedit',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_subedit',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
end; procedure prod_ins_rpt as
begin
prod_ins_rpt_erp;
prod_ins_rpt_szbgerp;
prod_ins_rpt_shs;
prod_ins_rpt_protex;
end; procedure prod_ins_rpt_erp as
begin
--lot info
for c1 in (select t1.lotno,lot_status,clot,wrk_no,customer,styleno,rmk_qty
from facd101 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
) loop
update cuttoship set lotstatus=c1.lot_status, clot=c1.clot, workshop=c1.wrk_no,
customer=c1.customer, styleno=c1.styleno, vpoqty=c1.rmk_qty
where lotno=c1.lotno; if sql%notfound then
insert into cuttoship
(lotno, lotstatus, clot, workshop, customer, styleno, vpoqty)
values
(c1.lotno,c1.lot_status,c1.clot,c1.wrk_no,c1.customer,c1.styleno,c1.rmk_qty);
end if;
commit;
end loop;
--Mfg. Order Qty
for c2 in (select t1.lotno,sum(nvl(qty, 0)) mfgqty
from facd302 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
group by t1.lotno
) loop
update cuttoship
set mfgqty=c2.mfgqty
where lotno=c2.lotno;
commit;
end loop;
--Panel Qty
for c3 in (select t1.lotno,sum(nvl(qty, 0)) panelqty
from facd321 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
where gen_date is not null and nvl(isactive, '') = ''
group by t1.lotno
) loop
update cuttoship
set panelqty=c3.panelqty
where lotno=c3.lotno;
commit;
end loop;
--Trf to Sewing & Panel Received
for c4 in (select t1.lotno,sum(nvl(qty, 0)) trftosewingqty
from facd512 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
where op=''
group by t1.lotno
) loop
update cuttoship
set trftosewingqty=c4.trftosewingqty,panelreceived=c4.trftosewingqty
where lotno=c4.lotno;
commit;
end loop;
--Output Qty
for c5 in (select t1.lotno,sum(nvl(qty, 0)) outputqty
from facd105 t1
inner join facd102 t2 on t1.lotno=t2.lotno and t1.operno=t2.lineno
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t2.ch_po='FOF'
group by t1.lotno
) loop
update cuttoship
set outputqty=c5.outputqty
where lotno=c5.lotno;
commit;
end loop;
--Leftover Garments Stored in WH
--1.A Quality,2.B Quality
for c6 in (select A.lotno,(A.defect222-B.defect223) defectqty,A.deadqty
from
(select t1.lotno,sum(nvl(repqty,0)-nvl(rplqty,0)) defect222,sum(nvl(damqty, 0)) deadqty
from facd550 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
where operno=''
group by t1.lotno) A,
(select t1.lotno,sum(nvl(repqty,0)) defect223
from facd550 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t2 on t1.lotno=t2.lotno
where operno=''
group by t1.lotno) B
where A.lotno=B.lotno(+)
) loop
update cuttoship
set defectqty=c6.defectqty,deadqty=c6.deadqty
where lotno=c6.lotno;
commit;
end loop;
--reason qty
for c7 in (select distinct S.lotno,qwlqty,wlpzqty,zgpzqty,khyyqty,zlwtqty,ysqty
from
(SELECT t1.lotno from facd343 t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno)S,
(select t1.lotno,nvl(t1.qty,0) qwlqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='A')A,
(select t1.lotno,nvl(t1.qty,0) wlpzqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='B')B,
(select t1.lotno,nvl(t1.qty,0) zgpzqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='C')C,
(select t1.lotno,nvl(t1.qty,0) khyyqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='D')D,
(select t1.lotno,nvl(t1.qty,0) zlwtqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='E')E,
(select t1.lotno,nvl(t1.qty,0) ysqty
from facd343 t1
inner join facd343_rea t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='erp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='F')F
where S.lotno=A.lotno(+)
and S.lotno=B.lotno(+)
and S.lotno=C.lotno(+)
and S.lotno=D.lotno(+)
and S.lotno=E.lotno(+)
and S.lotno=F.lotno(+)
) loop
update cuttoship
set qwlqty=c7.qwlqty,wlpzqty=c7.wlpzqty,zgpzqty=c7.zgpzqty,khyyqty=c7.khyyqty,
zlwtqty=c7.zlwtqty,ysqty=c7.ysqty,
subqty=c7.qwlqty+c7.wlpzqty+c7.zgpzqty+c7.khyyqty+c7.zlwtqty+c7.ysqty
where lotno=c7.lotno;
commit;
end loop;
--log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_ins_rpt_erp',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_ins_rpt_erp',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
end; procedure prod_ins_rpt_szbgerp as
p_ck number;
begin
p_ck:=0; --lot info
for c1 in (select t1.lotno,lot_status,clot,wrk_no,customer,styleno,rmk_qty
from facd101@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t2 on t1.lotno=t2.lotno
) loop
update cuttoship set lotstatus=c1.lot_status, clot=c1.clot, workshop=c1.wrk_no,
customer=c1.customer, styleno=c1.styleno, vpoqty=c1.rmk_qty
where lotno=c1.lotno; if sql%notfound then
insert into cuttoship
(lotno, lotstatus, clot, workshop, customer, styleno, vpoqty)
values
(c1.lotno,c1.lot_status,c1.clot,c1.wrk_no,c1.customer,c1.styleno,c1.rmk_qty);
end if;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --Mfg. Order Qty
for c2 in (select t1.lotno,sum(nvl(qty, 0)) mfgqty
from facd302@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t2 on t1.lotno=t2.lotno
group by t1.lotno
) loop
update cuttoship
set mfgqty=c2.mfgqty
where lotno=c2.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --Panel Qty
for c3 in (select t1.lotno,sum(nvl(qty, 0)) panelqty
from facd321@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t2 on t1.lotno=t2.lotno
where gen_date is not null and nvl(isactive, '') = ''
group by t1.lotno
) loop
update cuttoship
set panelqty=c3.panelqty
where lotno=c3.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --Trf to Sewing & Panel Received
for c4 in (select t1.lotno,sum(nvl(qty, 0)) trftosewingqty
from facd512@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t2 on t1.lotno=t2.lotno
where op=''
group by t1.lotno
) loop
update cuttoship
set trftosewingqty=c4.trftosewingqty,panelreceived=c4.trftosewingqty
where lotno=c4.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --Output Qty
for c5 in (select t1.lotno,sum(nvl(qty, 0)) outputqty
from facd105@szbgerp t1
inner join facd102@szbgerp t2 on t1.lotno=t2.lotno and t1.operno=t2.lineno
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t2.ch_po='FOF'
group by t1.lotno
) loop
update cuttoship
set outputqty=c5.outputqty
where lotno=c5.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --Leftover Garments
--1.A Quality,2.B Quality
for c6 in (select t1.lotno, sum(nvl(defect, 0)) defectqty, sum(nvl(dead, 0)) deadqty
from facd340@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t2 on t1.lotno=t2.lotno
group by t1.lotno
) loop
update cuttoship
set defectqty=c6.defectqty,deadqty=c6.deadqty
where lotno=c6.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
p_ck:=0;
end if; --reason qty
for c7 in (select distinct S.lotno,qwlqty,wlpzqty,zgpzqty,khyyqty,zlwtqty,ysqty
from
(SELECT t1.lotno from facd343@szbgerp t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno)S,
(select t1.lotno,nvl(t1.qty,0) qwlqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='A')A,
(select t1.lotno,nvl(t1.qty,0) wlpzqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='B')B,
(select t1.lotno,nvl(t1.qty,0) zgpzqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='C')C,
(select t1.lotno,nvl(t1.qty,0) khyyqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='D')D,
(select t1.lotno,nvl(t1.qty,0) zlwtqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='E')E,
(select t1.lotno,nvl(t1.qty,0) ysqty
from facd343@szbgerp t1
inner join facd343_rea@szbgerp t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='szbgerp') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='F')F
where S.lotno=A.lotno(+)
and S.lotno=B.lotno(+)
and S.lotno=C.lotno(+)
and S.lotno=D.lotno(+)
and S.lotno=E.lotno(+)
and S.lotno=F.lotno(+)
) loop
update cuttoship
set qwlqty=c7.qwlqty,wlpzqty=c7.wlpzqty,zgpzqty=c7.zgpzqty,khyyqty=c7.khyyqty,
zlwtqty=c7.zlwtqty,ysqty=c7.ysqty,
subqty=c7.qwlqty+c7.wlpzqty+c7.zgpzqty+c7.khyyqty+c7.zlwtqty+c7.ysqty
where lotno=c7.lotno;
commit;
p_ck:=p_ck+1;
end loop;
/**/
--must have data before close database link!
if p_ck>0 then
dbms_session.close_database_link('szbgerp');
end if;
--log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_ins_rpt_szbgerp',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_ins_rpt_szbgerp',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
end; procedure prod_ins_rpt_shs as
p_ck number;
begin
p_ck:=0;
--lot info
for c1 in (select t1.lotno,lot_status,clot,wrk_no,customer,styleno,rmk_qty
from facd101@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t2 on t1.lotno=t2.lotno
) loop
update cuttoship set lotstatus=c1.lot_status, clot=c1.clot, workshop=c1.wrk_no,
customer=c1.customer, styleno=c1.styleno, vpoqty=c1.rmk_qty
where lotno=c1.lotno; if sql%notfound then
insert into cuttoship
(lotno, lotstatus, clot, workshop, customer, styleno, vpoqty)
values
(c1.lotno,c1.lot_status,c1.clot,c1.wrk_no,c1.customer,c1.styleno,c1.rmk_qty);
end if;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--Mfg. Order Qty
for c2 in (select t1.lotno,sum(nvl(qty, 0)) mfgqty
from facd302@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t2 on t1.lotno=t2.lotno
group by t1.lotno
) loop
update cuttoship
set mfgqty=c2.mfgqty
where lotno=c2.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--Panel Qty
for c3 in (select t1.lotno,sum(nvl(qty, 0)) panelqty
from facd321@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t2 on t1.lotno=t2.lotno
where gen_date is not null and nvl(isactive, '') = ''
group by t1.lotno
) loop
update cuttoship
set panelqty=c3.panelqty
where lotno=c3.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--Trf to Sewing & Panel Received
for c4 in (select t1.lotno,sum(nvl(qty, 0)) trftosewingqty
from facd512@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t2 on t1.lotno=t2.lotno
where op=''
group by t1.lotno
) loop
update cuttoship
set trftosewingqty=c4.trftosewingqty,panelreceived=c4.trftosewingqty
where lotno=c4.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--Output Qty
for c5 in (select t1.lotno,sum(nvl(qty, 0)) outputqty
from facd105@shs t1
inner join facd102@shs t2 on t1.lotno=t2.lotno and t1.operno=t2.lineno
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t2.ch_po='FOF'
group by t1.lotno
) loop
update cuttoship
set outputqty=c5.outputqty
where lotno=c5.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--Leftover Garments
--1.A Quality,2.B Quality
for c6 in (select t1.lotno, sum(nvl(defect, 0)) defectqty, sum(nvl(dead, 0)) deadqty
from facd340@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t2 on t1.lotno=t2.lotno
group by t1.lotno
) loop
update cuttoship
set defectqty=c6.defectqty,deadqty=c6.deadqty
where lotno=c6.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
p_ck:=0;
end if;
--reason qty
for c7 in (select distinct S.lotno,qwlqty,wlpzqty,zgpzqty,khyyqty,zlwtqty,ysqty
from
(SELECT t1.lotno from facd343@shs t1
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno)S,
(select t1.lotno,nvl(t1.qty,0) qwlqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='A')A,
(select t1.lotno,nvl(t1.qty,0) wlpzqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='B')B,
(select t1.lotno,nvl(t1.qty,0) zgpzqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='C')C,
(select t1.lotno,nvl(t1.qty,0) khyyqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='D')D,
(select t1.lotno,nvl(t1.qty,0) zlwtqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='E')E,
(select t1.lotno,nvl(t1.qty,0) ysqty
from facd343@shs t1
inner join facd343_rea@shs t2 on t1.reasoncode=t2.reasoncode
inner join (select distinct site,lotno
from cuttoship_lot
where site='shs') t3 on t1.lotno=t3.lotno
where t1.isconfirm='Y' and t1.reasoncode='F')F
where S.lotno=A.lotno(+)
and S.lotno=B.lotno(+)
and S.lotno=C.lotno(+)
and S.lotno=D.lotno(+)
and S.lotno=E.lotno(+)
and S.lotno=F.lotno(+)
) loop
update cuttoship
set qwlqty=c7.qwlqty,wlpzqty=c7.wlpzqty,zgpzqty=c7.zgpzqty,khyyqty=c7.khyyqty,
zlwtqty=c7.zlwtqty,ysqty=c7.ysqty,
subqty=c7.qwlqty+c7.wlpzqty+c7.zgpzqty+c7.khyyqty+c7.zlwtqty+c7.ysqty
where lotno=c7.lotno;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('shs');
end if;
--log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_ins_rpt_shs',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_ins_rpt_shs',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
end; procedure prod_ins_rpt_protex as
p_ck number;
begin
p_ck:=0;
--shipmentdate
for c1 in (select t2.cstord,max(t1.plcomn),to_date(cast(DT#5Y as nvarchar2(4))||'-'||cast(DT#5M as nvarchar2(2))||'-'||cast(DT#5D as nvarchar2(2))) shipmentdate
from proda201.ORFPLCA@db2gzbg t1
left join proda201.ORFPLFB@db2gzbg t2 on t1.plcomn=t2.plcomn
inner join (select distinct lotno from cuttoship_lot) t3 on t2.cstord=t3.lotno
group by t2.cstord,DT#5Y,DT#5M,DT#5D
) loop
update cuttoship
set shipmentdate=c1.shipmentdate
where lotno=c1.cstord;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('db2gzbg');
p_ck:=0;
end if;
--sample qty
/*
for c2 in (select t1.cstord,nvl(sum(qty),0) sampleqty
from proda201.orforbc@db2gzbg t1
inner join (select distinct lotno from cuttoship_lot) t2 on t1.cstord=t2.lotno
group by t1.cstord
) loop
update cuttoship
set sampleqty=c2.sampleqty
where lotno=c2.cstord;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('db2gzbg');
p_ck:=0;
end if;
*/
--shipped qty
for c3 in (select t1.cstord,nvl(sum(qtypck),0) shippedqty
from proda201.orfplfb@db2gzbg t1
inner join (select distinct lotno from cuttoship_lot) t2 on t1.cstord=t2.lotno
group by t1.cstord
) loop
update cuttoship
set shippedqty=c3.shippedqty
where lotno=c3.cstord;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('db2gzbg');
p_ck:=0;
end if;
--Leftover Garments Stored in WH
--1.A Quality,2.B Quality
for c4 in (select S.cstord,astq,bstq
from
(select t1.cstord
from proda201.fgfstka@db2gzbg t1
inner join (select distinct lotno from cuttoship_lot) t2 on t1.cstord=t2.lotno
) S,
(select t1.cstord,nvl(sum(stq),0) astq
from proda201.fgfstka@db2gzbg t1
inner join (select distinct lotno from cuttoship_lot) t2 on t1.cstord=t2.lotno
group by t1.cstord) A,
(select t1.cstord,nvl(sum(stq),0) bstq
from proda201.fgfstka@db2gzbg t1
inner join (select distinct lotno from cuttoship_lot) t2 on t1.cstord=t2.lotno
group by t1.cstord) B
where S.cstord=A.cstord(+)
and S.cstord=B.cstord(+)
) loop
update cuttoship
set astq=c4.astq,bstq=c4.bstq
where lotno=c4.cstord;
commit;
p_ck:=p_ck+1;
end loop;
if p_ck>0 then
dbms_session.close_database_link('db2gzbg');
end if;
--radio,balabce,variance
update cuttoship
set radio=decode(vpoqty,0,0,round(1-shippedqty/vpoqty,4)),
balance=panelreceived-sampleqty-shippedqty-astq-bstq,
variance=panelqty-sampleqty-shippedqty-astq-bstq;
commit;
--log
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Success',
'cuttoship_lots',
'prod_ins_rpt_protex',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
exception
when others then
insert into facd610
(op_type, info_type, prod_name, w_day, op_date, os_user)
values
('Failure',
'cuttoship_lots',
'prod_ins_rpt_protex',
trunc(sysdate),
sysdate,
get_OS('OS_USER'));
commit;
end; procedure prod_update_0 as
begin
update cuttoship set vpoqty=0 where vpoqty is null;
update cuttoship set mfgqty=0 where mfgqty is null;
update cuttoship set panelqty=0 where panelqty is null;
update cuttoship set trftosewingqty=0 where trftosewingqty is null;
update cuttoship set panelreceived=0 where panelreceived is null;
update cuttoship set sampleqty=0 where sampleqty is null;
update cuttoship set outputqty=0 where outputqty is null;
update cuttoship set defectqty=0 where defectqty is null;
update cuttoship set deadqty=0 where deadqty is null;
update cuttoship set shippedqty=0 where shippedqty is null;
update cuttoship set radio=0 where radio is null;
update cuttoship set balance=0 where balance is null;
update cuttoship set astq=0 where astq is null;
update cuttoship set bstq=0 where bstq is null;
update cuttoship set variance=0 where variance is null;
update cuttoship set qwlqty=0 where qwlqty is null;
update cuttoship set wlpzqty=0 where wlpzqty is null;
update cuttoship set zgpzqty=0 where zgpzqty is null;
update cuttoship set khyyqty=0 where khyyqty is null;
update cuttoship set zlwtqty=0 where zlwtqty is null;
update cuttoship set ysqty=0 where ysqty is null;
update cuttoship set subqty=0 where subqty is null;
commit;
end;
end cuttoship_lots;

Oracle 存储过程包的更多相关文章

  1. Oracle 存储过程包(Package、Package Body)

    初出茅庐,不知原来存储过程还可以写得如此复杂,而且还竟然可以调试! 好吧,得整理一下存储过程的一些语法,以备以后用到时可以查阅. 使用数据库:Oracle 数据库工具:PL/SQL Developer ...

  2. oracle 存储过程 包 【转】

    一.为什么要用存储过程? 如果在应用程序中经常需要执行特定的操作,可以基于这些操作简历一个特定的过程.通过使用过程可以简化客户端程序的开发和维护,而且还能提高客户端程序的运行性能. 二.过程的优点? ...

  3. Oracle存储过程中异常Exception的捕捉和处理

    Oracle存储过程中异常的捕捉和处理 CREATE OR REPLACE Procedure Proc_error_process ( v_IN in Varchar2, v_OUT Out Var ...

  4. Oracle 存储过程学习

    转自:http://blog.chinaunix.net/uid-20495387-id-174394.html http://www.cnblogs.com/rootq/articles/11000 ...

  5. Oracle 存储过程异常处理

    Oracle 存储过程异常处理 1.异常的优点    如果没有异常,在程序中,应当检查每个命令的成功还是失败,如  BEGIN  SELECT ...  -- check for ’no data f ...

  6. (转)oracle 存储过程 带游标作为OUT参数输出

    (转)oracle 存储过程 带游标作为OUT参数输出 存储过程返回OUT参数的游标 例子. 包中带过程 要自己定义一个type [cur_name] is ref cursor游标,返回的时候就直接 ...

  7. Oracle存储过程中异步调用的实际操作步骤

    本文标签:Oracle存储过程 我们都知道在Oracle数据库的实际应用的过程中,我们经常把相关的业务处理逻辑,放在Oracle存储过程中,客户端以通过ADO来进行相关的调用  .而有些相关的业务逻辑 ...

  8. oracle存储过程实例

    oracle存储过程实例 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的P ...

  9. oracle存储过程分页

    1.首先在oracle中建包体,用于游标返回当前数据记录集 CREATE OR REPLACE PACKAGE pkg_query AS TYPE cur_query IS REF CURSOR; E ...

随机推荐

  1. oracle行转列(连接字符串函数)

    方法一:wmsys.wm_concat(column) 介绍:其函数在Oracle 10g推出,在10g版本中,返回字符串类型,在11g版本中返回clob类型.括号里面的参数是列,而且可以是多个列的集 ...

  2. 黄聪:走进wordpress 详细说说template-loader.php

    再看template-laoder.php,这个文件总共只有45行.它的作用是基于访问的URL装载正确的模板. 文件第六行,也是第一条语句,如下: if ( defined('WP_USE_THEME ...

  3. Linux 2.6 内核实时性分析 (完善中...)

      经过一个月的学习,目前对linux 下驱动程序的编写有了入门的认识,现在需要着手实践,编写相关的驱动程序. 因为飞控系统对实时性有一定的要求,所以先打算学习linux 2.6 内核的实时性与任务调 ...

  4. (C# File) 文件操作

    Get Files from Directory [C#] This example shows how to get list of file names from a directory (inc ...

  5. C#学习笔记四: C#3.0自动属性&匿名属性及扩展方法

    前言 这一章算是看这本书最大的收获了, Lambda表达式让人用着屡试不爽, C#3.0可谓颠覆了我们的代码编写风格. 因为Lambda所需篇幅挺大, 所以先总结C#3.0智能编译器给我们带来的诸多好 ...

  6. JAVA 对象初始化的过程

    对象初始化的过程例:Student S    =    new Student();1.因为new Student()用到了Student类,所以会把它从硬盘上加载进入内存2.如果有static静态代 ...

  7. xcode 插件管理工具

    每次xcode 更新后之前安装的插件 都失效了!解决办法: 一.可以通过在原插件项目infoplist新增 新xcode的 DVTPlugInCompatibilityUUID 来使之支持新版xcod ...

  8. Good Sentences

    Wine in, truth out One is never too old to learn What is done can not be undone Time tries all thing ...

  9. Perl模块的安装方法

    1. 下载离线安装包 *.tar.gz的形式解包后,#perl Makefile.PL#make#make install 2. 在联网的情况下,通过CPAN安装# perl -MCPAN -e sh ...

  10. javascript delete方法

    学习delete可以参考下面两个博客,写的都很好,本文大部分参考与以下两个博客 http://www.cnblogs.com/windows7/archive/2010/03/28/1698387.h ...