127 lines
3.8 KiB
Plaintext
127 lines
3.8 KiB
Plaintext
create or replace procedure p_ckqr
|
|
(
|
|
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, --转出物料的计划单号
|
|
p_txm cpkcxx.txm%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_yksl 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;
|
|
|
|
cursor c_kcxx is
|
|
select jlh, a.ckmc as ckmc, a.kwbh as kwbh, cpbh, lpxx, a.zlzt as zlzt, sl, rksj, jldw, cpmc, cpgg1, cpgg2, cpgg3, jhj, wzlb, gydw, bz, boxno, txm
|
|
from cpkcxx a
|
|
join kwjbxx b
|
|
on a.ckmc = b.ckmc
|
|
and a.kwbh = b.kwbh
|
|
where cpbh = p_cpbh
|
|
and nvl(lpxx, ' ') = p_lpxx
|
|
and tpbh = p_tpbh;
|
|
|
|
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';
|
|
|
|
open c_kcxx;
|
|
loop
|
|
fetch c_kcxx
|
|
into v_zc_kc_jlh, v_ckmc, v_kwbh, v_cpbh, v_lpxx, v_zlzt, v_yksl, 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_kwbh is null
|
|
then
|
|
raise_application_error(-20010, '未找到库存');
|
|
return;
|
|
end if;
|
|
if v_yksl < p_sl
|
|
then
|
|
close c_kcxx;
|
|
raise_application_error(-20010, '产品' || v_cpbh || '库位' || v_kwbh ||
|
|
'原库存数量' || v_yksl || '小于转移数量' || p_sl);
|
|
end if;
|
|
|
|
select max(jlh)
|
|
into v_kc_jlh
|
|
from cpkcxx
|
|
where ckmc = v_ckmc
|
|
and kwbh is null
|
|
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, null, 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, p_boxno, p_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_yksl = 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;
|
|
/
|