use ufdata_999_2003
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'tr_salebill_vouchtype' AND type = 'TR')
DROP TRIGGER tr_salebill_vouchtype
GO
create trigger tr_salebill_vouchtype on salebillvouch
for insert,update,delete
as
--功能:开具销售发票时,要验证客户档案中的发票类型和要开具的发票类型是否相符,这样可以防止开票员开票错误
--描述系统发票带出来的发票类型,26代表增值发票,27代表普通发票
declare @vouchtype varchar(20)
--描述客户档案中的自定义项
declare @cusdefine varchar(20)
--先取出客户档案中
select @cusdefine=ccusdefine2 from inserted inner join customer on inserted.ccuscode=customer.ccuscode
--从生成的销售出库单号取得出库单时间,即发货单审核时间
select @vouchtype=cvouchtype from inserted
--如果发票类型和客户档案中的自定义项不相符,这里包含了客户自定义项档案为空的情况
if ((@cusdefine<>'增值') and (@vouchtype=26) )
begin
RAISERROR ('开票类型不相符,不能保存',16,1)
ROLLBACK TRANSACTION
end
if ( (@cusdefine<>'小额') and (@vouchtype=27)) -- and @cusdefine is not null))
begin
RAISERROR ('开票类型不相符,不能保存',16,1)
ROLLBACK TRANSACTION
end
go