--批次模型
create table mxh
(
fifo_id int identity(1,1),
q decimal(13,4) default(0),
entry_q decimal(13,4) default(0)
)
insert into mxh(q,entry_q) values(10,10)
insert into mxh(q,entry_q) values(10,10)
insert into mxh(q,entry_q) values(10,10)
alter view v_mxh
as
select fifo_id,q,entry_q,(select sum(q) from mxh a where a.fifo_id>=b.fifo_id ) as enough_q
from mxh b
go
select * from v_mxh
select max(fifo_id),min(enough_q)
from v_mxh
where enough_q>=11
要把库存数调整为11则保留fifo_id为5,6的批次信息
下面的实际例子,当期批次有5个11000228商品
1、无损溢即将批次有5个调整为5个,等于不变批次,如下图
2、有溢出,分两种情况
2.1 、超过所有的批次数量的和即大于21 如下图
2.2、要调整的数量大于当前批次数量小于所有批次数量的和,即在5和21之间
2.3、数量小于5,即有损耗,如下图