注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 CCNA教材推荐
 帮助

金蝶K3实现自动核算(物料单价)


2007-03-08 16:44:34
 标签:金蝶 K3   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://redking.blog.51cto.com/27212/19679
        原金蝶K3的存货核算都是手动核算,比较麻烦!HOHO!现编写SQL语句搞定自动核算!(想尽办法偷懒,HOHO!)
if exists (select * from sysobjects where name = 'icstockbill_jade01') drop trigger icstockbill_jade01
go
create trigger icstockbill_jade01 on icstockbill
for insert,update
as
declare @frob int,@finterid int,@ftrantype int,@fstatus int
select  @frob = frob,@finterid = finterid,@ftrantype = ftrantype,@fstatus = fstatus from inserted
--更新蓝字,未审核状态的 '销售出库单','领料单','委外出库单','其他出库单'的单价和金额
--更新步骤:物料的采购单价,以前月份的期末单价,以前月份的发出单价
if @frob = 1 and @fstatus = 0 and (@ftrantype = 21 or @ftrantype = 24 or @ftrantype = 28 or @ftrantype = 29)
    begin       
 --更新采购单价
     update a set fprice = isnull(b.forderprice,0),famount = isnull(b.forderprice,0) * fqty,fauxprice = isnull(b.forderprice,0)
     from icstockbillentry a ,t_icitem b where a.fitemid = b.fitemid and a.finterid = @finterid
 if @ftrantype = 24
     --更新以前月的平均单价
     update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice
     from icstockbillentry x,
     (select fstockid,fitemid,fyear * 100 + fperiod as fperiods,
     convert(decimal(18,2),case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end) as fprice
     from icinvbal
     where fsend <> 0 or fendqty <> 0) y,
     (select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal
     where fsend <> 0 or fendqty <> 0 
     group by fstockid,fitemid) z
     where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods
     and x.fscstockid = y.fstockid and x.fitemid = y.fitemid
 else
     --更新以前月的平均单价
     update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice
     from icstockbillentry x,
     (select fstockid,fitemid,fyear * 100 + fperiod as fperiods,
     convert(decimal(18,2),case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end) as fprice
     from icinvbal
     where fsend <> 0 or fendqty <> 0) y,
     (select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal
     where fsend <> 0 or fendqty <> 0 
     group by fstockid,fitemid) z
     where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods
     and x.fdcstockid = y.fstockid and x.fitemid = y.fitemid
    end

/*
alter table icstockbill disable trigger icstockbill_jade01
alter table icstockbill enable trigger icstockbill_jade01
*/
============================================

本文出自 “大唐网络” 博客,请务必保留此出处http://redking.blog.51cto.com/27212/19679


附件下载:
  自动核算(物料单价)




    文章评论
 
2007-03-10 13:00:55
好东西,支持`~~`!!

2007-08-15 22:52:59
select @frob = frob,@finterid = finterid,@ftrantype = ftrantype,@fstatus = fstatus from inserted
中的inserted表是从哪里来的?

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: