USE [420923_2013]
GO
/****** Object: StoredProcedure [dbo].[Pro_MzCheck] Script Date: 01/29/2013 10:46:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Pro_MzCheck]
@Flag varchar(1), /*类别1一级审核;2二级审核;3转入历史库;4一级审核退单;5二级审核退单;6历史数据退单;7删除*/
@BillCode varchar(12),
@BillNo int
AS
begin
declare @Count int;
declare @v_CoopMedCode varchar(12); /**/
declare @v_CheckFee numeric(8,2); /**/
declare @Sql varchar(5000)
--一级审核
if @Flag = '1'
update o_CbMzBxDj set CheckerCode1=b.CheckerCode1,CheckerName1=b.CheckerName1,CheckDate1=getdate(),CheckOneFee=b.CheckOneFee,CheckRemark1=b.CheckRemark1
from o_CbMzBxDj a,#O_CheckOne_Mz b
where a.OrgCode=b.OrgCode and a.DiagNo=b.DiagNo and a.CoopMedCode=b.CoopMedCode and a.IDNo=b.IDNo;
--二级审核
if @Flag = '2'
begin
update o_CbMzBxDj set CheckerCode=b.CheckerCode,CheckerName=b.CheckerName,CheckDate2=getdate(),CheckFee=b.CheckFee,CheckRemark2=b.CheckRemark2
from o_CbMzBxDj a,#O_CheckTwo_Mz b
where a.OrgCode=b.OrgCode and a.DiagNo=b.DiagNo and a.CoopMedCode=b.CoopMedCode and a.IDNo=b.IDNo;
end;
--转入历史库
if @Flag = '3'
begin
-- BEGIN TRANSACTION
set @Sql='
insert s_CbMzZdb(BillCode,BillNo,BillName,WriteDate,Fee,CanFreeFee,CheckFee1,CheckFee,CheckStatus,PrincipalName,DebitID)
select BillCode,BillNo,BillName,WriteDate,Fee,CanFreeFee,CheckFee1,CheckFee,CheckStatus,PrincipalName,null
from O_CbMzZdb where BillCode='''+@BillCode+''' and BillNo='+cast(@BillNo as varchar(4));
print @Sql
exec(@Sql)
set @Sql='
insert s_CbMzbxdj(OrgCode,CoopMedCode,IDNo,DiagNo,ExpenseKind,HospitalCode,HospitalName,PatientName,HouseHolder,
Sex,Age,AgeUnit,InDate,IllCode,IllName,TotalFee,CanFreeFee,FreeFee,DoctorName,InputerCode,InputerName,
InputDate,CheckerCode1,CheckerName1,CheckOneFee,CheckDate1,CheckRemark1,CheckerCode,CheckerName,
CheckFee,CheckDate2,CheckRemark2,Remark,InterfaceIn,BillCode,BillNo,AreaCode,MzFlag)
select OrgCode,CoopMedCode,IDNo,DiagNo,ExpenseKind,HospitalCode,HospitalName,PatientName,HouseHolder,
Sex,Age,AgeUnit,InDate,IllCode,IllName,TotalFee,CanFreeFee,FreeFee,DoctorName,InputerCode,InputerName,
InputDate,CheckerCode1,CheckerName1,CheckOneFee,CheckDate1,CheckRemark1,CheckerCode,CheckerName,
CheckFee,CheckDate2,CheckRemark2,Remark,InterfaceIn,BillCode,BillNo,AreaCode,MzFlag
from o_CbMzbxdj where BillCode='''+@BillCode+''' and BillNo='+cast(@BillNo as varchar(4));
print @Sql
exec(@Sql)
delete from O_CbMzbxdj where BillCode=@BillCode and BillNo=@BillNo;
delete from O_CbMzZdb where BillCode=@BillCode and BillNo=@BillNo;
/* COMMIT TRANSACTION;
IF (@@ERROR <> 0 )
BEGIN
RAISERROR('error',16,1 )
ROLLBACK TRANSACTION
END
*/
end;
--一级审核退单
if @Flag = '4'
begin
-- update o_CbMzBxDj set CheckerCode1=null,CheckerName1=null,CheckDate1=null,CheckOneFee=0,CheckRemark1=null
-- where BillCode=@BillCode and BillNo=@BillNo;
update O_CbMzZdb set CheckFee1=0,CheckStatus='9' where BillCode=@BillCode and BillNo=@BillNo;
end;
--二级审核退单
if @Flag = '5'
begin
-- update o_CbMzBxDj set CheckerCode1=null,CheckerName1=null,CheckDate1=null,CheckOneFee=0,CheckRemark1=null,
-- CheckerCode=null,CheckerName=null,CheckDate2=null,CheckFee=0,CheckRemark2=null
-- where BillCode=@BillCode and BillNo=@BillNo;
update O_CbMzZdb set CheckFee1=0,CheckFee=0,CheckStatus='9' where BillCode=@BillCode and BillNo=@BillNo;
end;
--历史数据退单
if @Flag = '6'
begin
BEGIN TRANSACTION
--插入O_CbMzZdb\O_CbMzbxdj
insert O_CbMzZdb(BillCode,BillNo,BillName,WriteDate,Fee,CanFreeFee,CheckFee1,CheckFee,CheckStatus,PrincipalName)
select BillCode,BillNo,BillName,WriteDate,Fee,CanFreeFee,CheckFee1,CheckFee,CheckStatus,PrincipalName
from s_CbMzZdb where BillCode=@BillCode and BillNo=@BillNo;
insert O_CbMzbxdj(OrgCode,CoopMedCode,IDNo,DiagNo,ExpenseKind,HospitalCode,HospitalName,PatientName,HouseHolder,
Sex,Age,AgeUnit,InDate,IllCode,IllName,TotalFee,CanFreeFee,FreeFee,DoctorName,InputerCode,InputerName,
InputDate,CheckerCode1,CheckerName1,CheckOneFee,CheckDate1,CheckRemark1,CheckerCode,CheckerName,
CheckFee,CheckDate2,CheckRemark2,Remark,InterfaceIn,BillCode,BillNo,AreaCode,MzFlag)
select OrgCode,CoopMedCode,IDNo,DiagNo,ExpenseKind,HospitalCode,HospitalName,PatientName,HouseHolder,
Sex,Age,AgeUnit,InDate,IllCode,IllName,TotalFee,CanFreeFee,FreeFee,DoctorName,InputerCode,InputerName,
InputDate,CheckerCode1,CheckerName1,CheckOneFee,CheckDate1,CheckRemark1,CheckerCode,CheckerName,
CheckFee,CheckDate2,CheckRemark2,Remark,InterfaceIn,BillCode,BillNo,AreaCode,MzFlag
from s_CbMzbxdj where BillCode=@BillCode and BillNo=@BillNo;
--删除s_CbMzbxdj\s_CbMzZdb
delete from s_CbMzbxdj where BillCode=@BillCode and BillNo=@BillNo;
delete from s_CbMzZdb where BillCode=@BillCode and BillNo=@BillNo;
--更新O_CbMzZdb\O_CbMzbxdj
-- update o_CbMzBxDj set CheckerCode1=null,CheckerName1=null,CheckDate1=null,CheckOneFee=0,CheckRemark1=null,
-- CheckerCode=null,CheckerName=null,CheckDate2=null,CheckFee=0,CheckRemark2=null
-- where BillCode=@BillCode and BillNo=@BillNo;
update O_CbMzZdb set CheckStatus='3' where BillCode=@BillCode and BillNo=@BillNo;
COMMIT TRANSACTION;
IF (@@ERROR <> 0 )
BEGIN
RAISERROR('error',16,1 )
ROLLBACK TRANSACTION
END
end;
--删除
if @Flag = '7'
begin
BEGIN TRAN
update p_cbnhzhxx set HomeAccount=HomeAccount+ ss.FreeFee
from p_cbnhzhxx a,(select b.coopmedcode,sum(b.FreeFee) as FreeFee
from p_cbnhzhxx a,o_CbMzBxDj b
where a.coopmedcode=b.coopmedcode and b.BillCode=@BillCode and b.BillNo=@BillNo
group by b.coopmedcode) ss
where a.coopmedcode=ss.coopmedcode
delete from O_CbMzbxdj where BillCode=@BillCode and BillNo=@BillNo;
delete from O_CbMzZdb where BillCode=@BillCode and BillNo=@BillNo;
COMMIT TRANSACTION;
IF (@@ERROR <> 0 )
BEGIN
RAISERROR('error',16,1 )
ROLLBACK TRANSACTION
END
end;
end