CREATE OR REPLACE PROCEDURE SP_YF_MZFYZDFPZSM ( PCFLSH0 in varchar2, PCZY000 in number, PFLAG00 in varchar2 default '0', PSFTSCW in varchar2 default '1' --0:不提示错误信息 1:提示 ) as Ecustom exception; ls_YPZSL0 YF_YZYPSQ.YPZSL0%type; ls_YPSYSL YF_YZYPSQ.YPZSL0%type; Verrmsg varchar2(200); ls_CFLSH0 YF_MZCF00.CFLSH0%type; LS_MZYBZSMCLCLFS varchar2(20); ls_YPZSL_MOD YF_YZYPSQ.YPZSL0%type; --小数部分 LS_YSMJL0 YF_CFZSMX.YPZSL0%type; ls_SFKSLY YF_MZCF00.SFKSLY%type; LS_SFQZDP BM_TYZD00.MC0000%type; --ls_BCCFH0 YF_MZCF00.CFLSH0%type; --ls_YFBMBH YF_MZCF00.YFBMBH%type; -- Person Date Comments -- dsm 2025.03.26 自动分配追溯码 create for YF-20250328-001 -- dsm 2025.03.31 ZSMZHL增加nvl处理 for YF-20250331-001 -- linshu 2025.03.31 5.0移植到9.0 for YF9-20250401-002 -- linshu 2025.04.30 增加入参PSFTSCW; for YF9-20250430-003 -- linshu 2025.05.13 增加了全量匹配; for MZPY9-20250421-001 -- linshu 2025.05.22 去掉参数YF_MZYBZSMCLCLFS判断; for YF9-20250522-008 -- linshu 2025.06.03 过滤掉自备药; for YF9-20250528-006 begin ls_CFLSH0:=PCFLSH0; /* select max(trim(MC0000)) into LS_MZYBZSMCLCLFS from BM_TYZD00 where BH0000='YF_MZYBZSMCLCLFS' and ZDMC00='医保追溯码配置'; if LS_MZYBZSMCLCLFS in('-1','1') and LS_MZYBZSMCLCLFS<>'0' then return; end if;*/ begin select MC0000 into LS_SFQZDP from BM_TYZD00 where BH0000='YF_ZSMSFQZDPP' and ZDMC00='医保追溯码配置' and YXBZ00 = '1'; exception when others then LS_SFQZDP := '0'; end; if PFLAG00='0' then select nvl(SFKSLY,'N') into ls_SFKSLY from YF_MZCF00 where CFLSH0 = PCFLSH0; for c_ckdyp in( select b.GHID00,b.YFBMBH,B.CFLSH0, a.YPNM00,a.YPMC00,a.CFID00,a.YPZSL0,a.ZHL000,a.YPZSL0*a.ZHL000 JLZSL0, nvl((select sum(YPZSL0) from YF_CFZSMX where CFLSH0=a.CFLSH0 and YPNM00=a.YPNM00 and FYTYBZ='0'),0) YSMSL0, nvl((select ZSMZHL from BM_YD0000 where YPNM00=a.YPNM00),0) ZSMZHL, nvl((select sum(YPZSL0) from YF_CFZSMX where CFLSH0=a.CFLSH0 and YPNM00=a.YPNM00 and SFCLBZ='1' and FYTYBZ='0'),0) CLZSL0 from YF_MZCFMX a,YF_MZCF00 b where a.CFLSH0=ls_CFLSH0 and a.CFLSH0=b.CFLSH0 and exists(select 1 from BM_YD0000 where YPNM00=a.YPNM00 and ( ZSCLBZ in('1','3') or ls_SFKSLY = 'Y')) and exists(select 1 from YK_YPZSM0 where YPNM00=a.ypnm00 ) and exists ( select 1 from BM_YD0000 where YPNM00 = A.YPNM00 and nvl(XSWZSM,0)<> '1') --2025.06.12去除销售端无码的分配 and exists(select 1 from YF_RKZSM0 where YFBMBH=b.YFBMBH and YPNM00=a.YPNM00 and SYJLSL>0) and A.SFZBY0 <> 'Y' ) loop if ( c_ckdyp.ZSMZHL is null ) and ( NVL(PSFTSCW,'1') <> '0' ) then Verrmsg := '拆零药品:【'||c_ckdyp.ypmc00||'】 未在药典表维护拆零转换率,拆零不能进行自动分配!'; raise Ecustom; end if; select nvl(sum(YPZSL0),0) into LS_YSMJL0 from YF_CFZSMX where YPQLPC = c_ckdyp.CFID00 and CFLSH0 = c_ckdyp.CFLSH0 and FYTYBZ <> '2'; if ls_SFKSLY = 'Y' or LS_SFQZDP = '1' then --科室领药 ls_YPZSL0 := c_ckdyp.JLZSL0 - LS_YSMJL0; else select mod(c_ckdyp.JLZSL0 - LS_YSMJL0,c_ckdyp.ZSMZHL) into ls_YPZSL_MOD from dual; ls_YPZSL0:=ls_YPZSL_MOD-c_ckdyp.CLZSL0; end if; if ls_YPZSL0>0 then for c_clyp in( select CLLSH0,ZSM000,SYJLSL from YF_RKZSM0 where YFBMBH=c_ckdyp.YFBMBH and YPNM00=c_ckdyp.YPNM00 and SYJLSL>0 AND ZT0000<>'3' order by CLLSH0 ) loop if ls_YPZSL0>0 then if c_clyp.SYJLSL0 ) and ( NVL(PSFTSCW,'1') <> '0' ) then --拆零库不够分配 Verrmsg:=c_ckdyp.YPMC00||'拆零库存不够分配,请先拆零入库'; raise Ecustom; end if; end loop; --elsif PFLAG00='1' then --退药 /* for c_ckdyp in(select TYZSL0,ZSM000,YPNM00,YPQLPC from YF_CFZSMX where CFLSH0=ls_BCCFH0 and SFCLBZ='1' and FYTYBZ in('0','1') and YPQLPC in (select CXCFID from YF_MZCFMX where CFLSH0=ls_CFLSH0) and nvl(TYZSL0,0)