存储过程倒扣料时考虑是否最后一笔判断有缺陷。替代料倒扣建立增加一个选择项来决定先扣替代料/主料
建议改为增加一个系统参数来决定先扣替代料/主料 ,电子料行业一般会有主替优先使用顺序。
判断是否最后一笔入库时,建立改为如下脚本
Case When ( Case When opur_pur2.pur_qty_check = '0' Then opur_pur2.in_tempqty+ opur_pur2.in_qty + opur_pur2.scrab_tempqty+ opur_pur2.scrab_qty- opur_pur2.intl_tempqty- opur_pur2.intl_qty- opur_pur2.sheet_qty *(1-obas_part1.err_rate) Else opur_pur2.scm_in_tempqty+ opur_pur2.scm_in_qty+ opur_pur2.scm_scrab_tempqty+ opur_pur2.scm_scrab_qty- opur_pur2.scm_intl_tempqty- opur_pur2.scm_intl_qty- opur_pur2.scm_sheet_qty End) >=0 and not exists(select top 1 1 from oscm_accept_in2 ,oscm_accept_in1,obas_sheet_type where oscm_accept_in2.sheet_no=oscm_accept_in1.sheet_no and oscm_accept_in1.sheet_type=obas_sheet_type.sheet_type and obas_sheet_type.sheet_kind in ('SCM04','SCM06','SCM07','SCM09','SCM11','SCM12') and oscm_accept_in2.pur_lot=a.pur_lot and ((oscm_accept_in1.sheet_date>c.sheet_date) or (oscm_accept_in1.sheet_date=c.sheet_date and oscm_accept_in2.sheet_lot>a.sheet_lot)))--增加判断是否是最后一笔入库单 李顶立 Then '5' Else '0' End