144 lines
4.0 KiB
Plaintext
144 lines
4.0 KiB
Plaintext
create or replace procedure p_ppcl
|
|
(
|
|
p_tpbh kwjbxx.tpbh%type, --转入的托盘编号,
|
|
p_cpbh cpkcxx.cpbh%type, --转出的产品编号
|
|
p_lpxx cpkcxx.lpxx%type, --转出物料的批次信息
|
|
p_sl cpkcxx.sl%type, --转出的数量
|
|
p_boxno cpkcxx.boxno%type --转出物料的计划单号
|
|
) as
|
|
/**配盘处理
|
|
* 将一个空库位的库存转移到另外一个虚拟库位上
|
|
*这部分库位是出库拣选后转移到虚拟库存,库位为空
|
|
*dengbiao
|
|
*/
|
|
v_ckmc cpkcxx.ckmc%type;
|
|
v_kwbh cpkcxx.kwbh%type;
|
|
v_jldw cpkcxx.jldw%type;
|
|
v_kc_jlh cpkcxx.jlh%type;
|
|
v_lpxx cpkcxx.lpxx%type;
|
|
v_wzlb cpkcxx.wzlb%type;
|
|
v_cpbh cpkcxx.cpbh%type;
|
|
v_rksl cpkcxx.sl%type;
|
|
v_zlzt cpkcxx.zlzt%type;
|
|
v_cpmc cpkcxx.cpmc%type;
|
|
v_cpgg1 cpkcxx.cpgg1%type;
|
|
v_cpgg2 cpkcxx.cpgg2%type;
|
|
v_cpgg3 cpkcxx.cpgg3%type;
|
|
v_jhj cpkcxx.jhj%type;
|
|
v_rksj cpkcxx.rksj%type;
|
|
v_gydw cpkcxx.gydw%type;
|
|
v_djbz cprkd.bz%type;
|
|
v_boxno ckzl.boxno%type;
|
|
v_sclkc char(1); -- 是否删除零库存
|
|
v_gxcpcfkw sys_config.dqz%type; -- 是否更新存货档案信息记录的最近存放库位和当前存放库位
|
|
v_zc_kc_jlh cpkcxx.jlh%type; --转出库存记录号
|
|
v_txm cpkcxx.txm%type;
|
|
-- CREATE GLOBAL TEMPORARY TABLE admin_work_area
|
|
--(startdate DATE,
|
|
--enddate DATE,
|
|
--class CHAR(20))
|
|
--ON COMMIT DELETE ROWS;
|
|
|
|
cursor c_kcxx is
|
|
select jlh, ckmc, cpbh, lpxx, zlzt, sl, rksj, jldw, cpmc, cpgg1, cpgg2, cpgg3, jhj, wzlb, gydw, bz, boxno, txm
|
|
from cpkcxx
|
|
where cpbh = p_cpbh
|
|
and nvl(lpxx, ' ') = p_lpxx
|
|
and boxno = p_boxno
|
|
and kwbh is null;
|
|
|
|
begin
|
|
|
|
select max(dqz)
|
|
into v_sclkc
|
|
from sys_config
|
|
where id_pzx = 'delete_0_inventory';
|
|
select max(dqz)
|
|
into v_gxcpcfkw
|
|
from sys_config
|
|
where id_pzx = 'update_cpxx_cfkw';
|
|
|
|
select a.kwbh
|
|
into v_kwbh
|
|
from cpkcxx a
|
|
join kwjbxx b
|
|
on a.kwbh = b.kwbh
|
|
where tpbh = p_tpbh;
|
|
if v_kwbh is null
|
|
then
|
|
select max(kwbh)
|
|
into v_kwbh
|
|
from kwjbxx
|
|
where zsl = 0
|
|
and sfsd = 0
|
|
and qysx = 'P';
|
|
end if;
|
|
if v_kwbh is null
|
|
then
|
|
raise_application_error(-20010, '未找到虚拟库位');
|
|
return;
|
|
end if;
|
|
open c_kcxx;
|
|
loop
|
|
fetch c_kcxx
|
|
into v_zc_kc_jlh, v_ckmc, v_cpbh, v_lpxx, v_zlzt, v_rksl, v_rksj, v_jldw, v_cpmc, v_cpgg1, v_cpgg2, v_cpgg3, v_jhj, v_wzlb, v_gydw, v_djbz, v_boxno, v_txm;
|
|
exit when c_kcxx%notfound;
|
|
if v_rksl < p_sl
|
|
then
|
|
close c_kcxx;
|
|
raise_application_error(-20010, '产品' || v_cpbh || '库位' || v_kwbh ||
|
|
'原库存数量' || v_rksl || '小于转移数量' || p_sl);
|
|
end if;
|
|
|
|
select max(jlh)
|
|
into v_kc_jlh
|
|
from cpkcxx
|
|
where ckmc = v_ckmc
|
|
and kwbh = v_kwbh
|
|
and cpbh = v_cpbh
|
|
and nvl(lpxx, ' ') = nvl(v_lpxx, ' ')
|
|
and nvl(boxno, ' ') = nvl(v_boxno, ' ')
|
|
and nvl(txm, ' ') = nvl(v_txm, ' ');
|
|
--转入的增加
|
|
if v_kc_jlh is null
|
|
then
|
|
insert into cpkcxx
|
|
(jlh, ckmc, kwbh, cpbh, lpxx, sl, zlzt, rksj, jldw, cpmc, cpgg1, cpgg2, cpgg3, jhj, wzlb, gydw, bz, boxno, txm)
|
|
values
|
|
(cpkcxx_jlh.nextval, v_ckmc, v_kwbh, v_cpbh, v_lpxx, p_sl, v_zlzt, v_rksj, v_jldw, v_cpmc, v_cpgg1, v_cpgg2, v_cpgg3, v_jhj, v_wzlb, v_gydw, v_djbz, v_boxno, v_txm);
|
|
else
|
|
update cpkcxx set sl = sl + p_sl where jlh = v_kc_jlh;
|
|
end if;
|
|
|
|
--原库存减少
|
|
update cpkcxx set sl = sl - p_sl where jlh = v_zc_kc_jlh;
|
|
if p_sl - v_rksl = 0
|
|
then
|
|
delete cpkcxx
|
|
where sl = 0
|
|
and jlh = v_zc_kc_jlh;
|
|
end if;
|
|
|
|
--修改库位信息
|
|
update kwjbxx
|
|
set sjwzlx = v_zlzt, sfwzzl = 'M', tpbh = p_tpbh
|
|
where ckmc = v_ckmc
|
|
and kwbh = v_kwbh
|
|
and (sjwzlx <> v_zlzt or sjwzlx is null or sfwzzl is null or
|
|
zsl = 0 or sfwzzl <> 'M' or tpbh is null);
|
|
--修改库位上的总数量
|
|
update kwjbxx
|
|
set zsl =
|
|
(select nvl(sum(sl), 0) as sumsl
|
|
from cpkcxx
|
|
where ckmc = v_ckmc
|
|
and kwbh = v_kwbh)
|
|
where ckmc = v_ckmc
|
|
and kwbh = v_kwbh;
|
|
|
|
end loop;
|
|
close c_kcxx;
|
|
|
|
end;
|
|
/
|