需求描述:
T1(V12.1)单据打印,希望在表头上显示经手人所属部门
解决办法:
借助触发器来实现,单据保存自动将经手人所属部门写入表头的自定义1
(以下两个触发器需要单独执行)
--增加/修改
Create Trigger [tr_Dept_name] on [MasterBilldft]
for insert,update
as
Declare @VouchID int, @Dept_name nvarchar(100)
set @VouchID=(Select s_ID from inserted)
set @Dept_name=(select u_name from department where s_id=(select dept_id from employee where s_id=(select emp_id from inserted )))
if exists(select * from billtitlecustomitemsdft where billid=@VouchID)
begin
update billtitlecustomitemsdft set item1=@dept_name where billid=@VouchID
end
else
begin
insert into billtitlecustomitemsdft (billid,item1) values (@VouchID,@Dept_name)
end
--删除
Create Trigger [tr_Del_Dept_name] on [MasterBilldft]
for delete
as
Declare @VouchID int
set @VouchID=(Select s_ID from deleted)
delete from billtitlecustomitemsdft where billid=@VouchID
执行完毕后,在单据设计中,将部门的公式设置为:部门:[主项数据."自定义1"]
然后打印预览查看效果: