k3 生成备品出库单的触发器

create trigger [dbo].[ICStockBill_ProcessSOFreeQty1] ON [dbo].[ICStockBill]
	for insert,update
as
set nocount on
/******************************************************************************
 * TABLE NAME:    ICStockBill                                                 *
 * TRIGGER NAME:  ICStockBill_ProcessSOFreeQty1                               *              *
 * CREATED BY:                                                                *
 * CREATION DATE: 2007/08/01 17:04                                            *
 * DESCRIPTION:                                                               *
 ******************************************************************************/

if exists (select * from Inserted as i join Deleted as d on i.FInterID=d.FInterID join ICStockBillEntry as e on i.FInterID=e.FInterID
	where isnull(e.FEntrySelfB0158,0)<>0 and i.FTranType=21 and i.FCheckerID<>0 and isnull(d.FCheckerID,0)=0)
begin
                
	declare @id int, 
                @entry int
	declare @FROB int    --红蓝单标志


	exec GetICMaxNum 'ICStockBill', @id output

	if @@error<>0 or isnull(@id, -1)=-1
	begin
	
		if @@trancount > 0
		rollback
		return
	end
	insert ICStockBill (FBrNo, FInterID, FTranType, FOrgBillInterID, FDate, FBillNo, FExplanation, FDeptID, FEmpID, FSupplyID, 
		FFManagerID, FSManagerID, FBillerID, FCheckerID, FCheckDate, FSaleStyle, FROB, FUpStockWhenSave,
		FPOStyle, FPurposeID, FMarketingStyle, FFetchAdd, FRefType, FUse, FBillTypeID, FStatus)
	select i.FBrNo, @id, 29, i.FInterID, i.FDate, i.FBillNo+'B', '销售出库单'+rtrim(i.FBillNo)+'备品出库', i.FDeptID, i.FEmpID, i.FSupplyID, 
		i.FFManagerID, i.FSManagerID, i.FBillerID, i.FCheckerID, i.FCheckDate, i.FSaleStyle, i.FROB, i.FUpStockWhenSave,
		null, i.FPurposeID, i.FMarketingStyle, i.FFetchAdd, i.FRefType, i.FUse, 1000, 1
	        from Inserted as i 
                join Deleted as d on i.FInterID=d.FInterID 
	        where i.FTranType=21 and i.FCheckerID<>0 and isnull(d.FCheckerID,0)=0
          --状态由0变成1时,即审核时
if @@error<>0
	begin

		rollback
		return
	end
	
	declare @FBrNo int, @FItemID int, @FQty decimal(28,10), @FPrice decimal(28,10), @FAuxQty decimal(28,10), @FAuxPrice decimal(28,10), 
		@FBatchNo varchar(200),	@FNote varchar(255), @FUnitID int, @FDCSPID int, @FDCStockID int, @FKFDate datetime, @FKFPeriod int, @FAuxPropID int
	
	declare temp_cursor cursor for
	select e.FBrNo, e.FItemID, round(e.FEntrySelfB0158*u.FCoefficient, b.FQtyDecimal), e.FPrice, e.FEntrySelfB0158, e.FAuxPrice, 
		e.FBatchNo, e.FNote, e.FUnitID, e.FDCSPID, e.FDCStockID, e.FKFDate, e.FKFPeriod, e.FAuxPropID
	from ICStockBillEntry as e 
                join Inserted as i on e.FInterID=i.FInterID 
                join Deleted as d on i.FInterID=d.FInterID 
		join t_ICItemBase as b on e.FItemID=b.FItemID 
                join t_MeasureUnit as u on e.FUnitID=u.FItemID
	where e.FEntrySelfB0158<>0 and i.FTranType=21 and i.FCheckerID<>0 and isnull(d.FCheckerID,0)=0
        order by e.fentryid

          --状态由0变成1时,即审核时
	if @@error<>0
	begin
		rollback
		return
	end

	open temp_cursor
	fetch temp_cursor into @FBrNo, @FItemID, @FQty, @FPrice, @FAuxQty, @FAuxPrice, @FBatchNo, 
		@FNote, @FUnitID, @FDCSPID, @FDCStockID, @FKFDate, @FKFPeriod, @FAuxPropID

	select @entry = 0
	while(@@fetch_status = 0)
	begin
		select @entry = @entry + 1
                if @FQty>0 
                        select @FROB=1
                else
                        select @FROB=-1
		insert ICStockBillEntry (FBrNo, FInterID, FEntryID, FItemID, FQty, FPrice, FAuxQty, FAuxPrice, FAmount, 
			FBatchNo, FNote, FUnitID, FDCSPID, FDCStockID, FKFDate, FKFPeriod, FAuxPropID)
		values (@FBrNo, @id, @entry, @FItemID, @FQty, 0.01, @FAuxQty, 0, 0, 
			@FBatchNo, @FNote, @FUnitID, @FDCSPID, @FDCStockID, @FKFDate, @FKFPeriod, @FAuxPropID)
		if @@error<>0
		begin

			rollback
			return
		end
	
		fetch temp_cursor into @FBrNo, @FItemID, @FQty, @FPrice, @FAuxQty, @FAuxPrice, @FBatchNo, 
			@FNote, @FUnitID, @FDCSPID, @FDCStockID, @FKFDate, @FKFPeriod, @FAuxPropID
	end
end
insert ICInventory (FBrNo, FItemID, FBatchNo, FStockID, FStockPlaceID, FKFDate, FKFPeriod, FAuxPropID)
select r.FBrNo, r.FItemID, r.FBatchNo, r.FDCStockID, r.FDCSPID, r.FKFDate, r.FKFPeriod, r.FAuxPropID
from ICInventory as v 
     right join (select distinct e.FBrNo, e.FItemID, e.FBatchNo, e.FDCStockID, e.FDCSPID, 
		FKFDate=(case when e.FKFDate is null then '' else convert(char(10), e.FKFDate, 20) end), 
                e.FKFPeriod, e.FAuxPropID 
		from ICStockBillEntry as e 
                        join ICStockBill as s on e.FInterID=s.FInterID 
			join Inserted as i on s.FOrgBillInterID=i.FInterID 
                        join Deleted as d on i.FInterID=d.FInterID
		where s.FTranType=29 and s.FCheckerID<>0 and i.FTranType=21 and isnull(i.FCheckerID,0)<>isnull(d.FCheckerID,0))as r 
        on v.FItemID=r.FItemID and v.FBatchNo=r.FBatchNo and v.FStockID=r.FDCStockID and v.FStockPlaceID=r.FDCSPID and v.FKFDate=r.FKFDate 
           and v.FKFPeriod=r.FKFPeriod and v.FAuxPropID=r.FAuxPropID
     where v.FItemID is null

--更改库存
if @@error<>0
begin
	rollback
	return
end

update v set FQty = v.FQty - r.FQty
from ICInventory as v join
	(select e.FBrNo, e.FItemID, e.FBatchNo, e.FDCStockID, e.FDCSPID, 
		FKFDate=(case when e.FKFDate is null then '' else convert(char(10), e.FKFDate, 20) end), 
		e.FKFPeriod, e.FAuxPropID, FQty=sum(case when isnull(d.FCheckerID,0)=0 then e.FQty else -e.FQty end) 
		from ICStockBillEntry as e 
                     join ICStockBill as s on e.FInterID=s.FInterID 
		     join Inserted as i on s.FOrgBillInterID=i.FInterID 
                     join Deleted as d on i.FInterID=d.FInterID
		where s.FTranType=29 and s.FCheckerID<>0 and i.FTranType=21 and isnull(i.FCheckerID,0)<>isnull(d.FCheckerID,0)
		group by e.FBrNo, e.FItemID, e.FBatchNo, e.FDCStockID, e.FDCSPID, e.FKFDate, e.FKFPeriod, e.FAuxPropID) as r 
                on v.FItemID=r.FItemID and v.FBatchNo=r.FBatchNo and v.FStockID=r.FDCStockID 
		and v.FStockPlaceID=r.FDCSPID and v.FKFDate=r.FKFDate and v.FKFPeriod=r.FKFPeriod and v.FAuxPropID=r.FAuxPropID
--更改库存
if @@error<>0
begin
	rollback
	return
end

update s set FCheckerID=0
from ICStockBill as s 
        join Inserted as i on s.FOrgBillInterID=i.FInterID 
        join Deleted as d on i.FInterID=d.FInterID
where s.FTranType=29 and s.FCheckerID<>0 and i.FTranType=21 and isnull(i.FCheckerID,0)=0 and d.FCheckerID<>0
--反审核
if @@error<>0
begin
	rollback
	return
end

delete s
from ICStockBill as s join Inserted as i on s.FOrgBillInterID=i.FInterID join Deleted as d on i.FInterID=d.FInterID
where s.FTranType=29 and i.FTranType=21 and isnull(i.FCheckerID,0)=0 and d.FCheckerID<>0
if @@error<>0
begin
	rollback
	return
end

set nocount off









 
CREATE trigger icstockbill_check --实现对物料据管控 on Icstockbill for insert as Declare @Ftrantype int --据类别定义/生产领料24/调拔41/销售出库21 Select @Ftrantype=Ftrantype from inserted --控制领料的领料日期不能小于生产任务的计划开工日期 倒扣物料只能车间仓库发料 if (@Ftrantype=24) begin declare @icmo varchar(20) declare @message varchar(200) declare @message0 varchar(200) declare @message00 varchar(200) declare @message000 varchar(200) declare @finterid240 int set @message='错误!领料日期不能小于生产任务计划开工日期,请与生管人员联系!错误号:' set @message0='生产领料发料仓库不正确,倒扣物料不能从 原料仓/半成品仓/成品仓 发料' set @message00='已完工生产任务不能跨月领料.请检查领料日期!' set @message000='生产领料必需关联源生产任务号,请重新录入据!' if exists ( select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid where t2.ficmointerid=0 ) begin RAISERROR(@message000,18,18) ROLLBACK end if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdateCast(year(max(t4.fdate)) as int(10))*100+Cast(month(max(t4.fdate)) as int(5)) ) begin RAISERROR(@message00,18,18) ROLLBACK end --更新领料上的销售订号 select @finterid240=finterid from inserted update t2 set t2.fentryselfb0445=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=24 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid240 return end --控制委外加工生产任务领料日期不对小于计划开工日期 if (@Ftrantype=28) begin declare @icmo3 varchar(20) declare @message3 varchar(200) set @message3='错误!委外加工发出日期不能小于对应委外加工生产任务计划开工日期,请与采购人员联系变更!错误号:' if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdate0 and t1.fdate0 and t1.fdate<t3.FPlanCommitDate set @message4=@message4+@icmo4 RAISERROR(@message4,18,18) ROLLBACK end ; --更新产品入库上的销售订号 select @finterid20=finterid from inserted update t2 set t2.fentryselfa0236=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=2 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid20 return end ---更新委外加工入销售订号 if (@Ftrantype=5) begin update t2 set t2.fentryselfa0548=t4.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid inner join seorder as t4 on t4.finterid=t3.forderinterid return end ---控制出全部出货的销售订所对应的采购订不能退料(红字外购入库) /*if (@Ftrantype=1) begin declare @message500 varchar(200) set @message500='已全部出货的销售订所对应的采购订不能退料!请检查您所退料的采购订号码是否正确!' if exists (select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join seorder as t3 on t3.fbillno=t2.fentryselfa0152 where t2.fqty<0 and t3.fclosed=1 ) begin RAISERROR(@message500,18,18) ROLLBACK end return end */
### 回答1: 金蝶K3生成凭证是指在金蝶K3财务软件中,通过编写开发代码来实现凭证的生成功能。凭证是财务会计中一个重要的概念,用于记录和反映企业经济业务活动的账务凭据。 金蝶K3生成凭证的开发工作主要包括以下几个方面: 1. 准备工作:首先需要明确凭证的生成规则和业务需求,分析业务流程,确定需要生成凭证的条件和生成方式。 2. 开发代码:根据准备工作中的需求,编写代码进行凭证的生成。开发人员可以使用金蝶K3的API(应用程序接口)来操作数据和实现业务逻辑,通过编写代码来自动化生成凭证。 3. 数据处理:在凭证生成过程中,需要对相关数据进行处理,例如根据业务规则计算科目余额、填充凭证各字段等。开发人员可以通过数据库查询和计算来获取所需数据,并将处理结果写入凭证中。 4. 测试和调试:开发完成后,需要进行测试和调试,确保凭证生成的代码逻辑正确,并能满足业务需求。测试过程中需进行多个业务场景的模拟,包括正常场景和异常场景,以验证代码的稳定性和准确性。 5. 上线调整:在凭证生成功能经过测试无误后,可以进行上线操作并应用到实际的生产环境中。在实际运行过程中,可能会遇到一些问题,需要根据实际情况进行调整和优化,以确保凭证生成的准确性和效率。 金蝶K3生成凭证开发是基于金蝶K3财务软件的核心功能,通过定制化开发来满足企业的特定需求,提高财务业务处理的效率和准确性。开发人员需要熟悉金蝶K3的API接口和相关的财务会计知识,具备编程和数据处理的能力,才能完成凭证生成功能的开发工作。 ### 回答2: 金蝶K3生成凭证开发是指对金蝶K3财务软件中的生成凭证功能进行自定义开发和定制。生成凭证是金蝶K3财务模块中非常重要的一项功能,它能够根据企业的财务流程和业务需求,自动生成相应的凭证。 在金蝶K3生成凭证开发过程中,我们需要根据客户的需求进行需求分析和功能设计,并与客户及相关部门进行充分的沟通和协商。通过理解客户的业务流程以及财务规则,在金蝶K3平台上进行二次开发,定制化生成凭证功能,以满足客户的特定需求。 实际开发中,我们会使用金蝶K3平台提供的相关接口和开发工具,通过编程的方式对生成凭证的逻辑进行编写和优化。我们会根据客户的要求进行字段的添加、修改和删除,增加一些必要的公式和规则,并进行数据验证和计算,确保生成凭证的准确性和完整性。 在开发完成后,我们还会进行相应的测试和调试工作,确保生成凭证的功能能够正常运行,并与金蝶K3财务模块的其他功能和模块进行协调和集成。同时,我们还会为客户提供相应的培训和技术支持,确保客户能够熟练使用和维护生成凭证的功能。 通过金蝶K3生成凭证开发,企业可以根据自身的需求和业务特点,对生成凭证功能进行个性化定制,提升财务处理的效率和准确性,满足企业的财务管理需求。 ### 回答3: 金蝶K3生成凭证是指通过金蝶K3财务管理软件来自动化生成公司的会计凭证。在金蝶K3中,凭证生成是一项重要的财务功能,能够将各种业务活动转化为会计凭证,并根据财务规则进行凭证的合理划分和生成。 金蝶K3生成凭证的开发需要进行以下步骤: 1. 需求分析:首先要明确系统需要支持的业务活动,包括业务流程、涉及的科目、金额计算等。根据需求分析,确定生成凭证的具体逻辑和功能要求。 2. 开发凭证模板:在金蝶K3中,可以根据需求自定义凭证模板。凭证模板包括凭证摘要、科目对应关系、金额计算公式等。开发人员可以根据需求设置凭证模板,确保生成的凭证符合会计要求。 3. 编写凭证生成程序:根据需求和凭证模板,开发人员需要编写凭证生成的程序逻辑。该程序逻辑需要包括根据业务活动生成凭证摘要、科目自动匹配、金额计算等。 4. 数据对接与调试:将凭证生成程序与公司现有的业务数据对接,确保凭证生成的准确性和一致性。在对接过程中,需要进行数据的测试和调试,确保生成的凭证数据正确无误。 5. 上线运行与优化:凭证生成程序上线后,需要进行运行监控和优化。通过定期检查凭证生成的准确性和效率,及时发现和处理问题,确保凭证生成的稳定性。 金蝶K3生成凭证的开发需要充分了解财务业务和会计规则,并严格按照需求进行开发和测试。凭证生成的自动化可以提高财务处理效率,减少错误率,为企业的财务管理提供有力支持。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值