您的位置:首页 > 其它

实施财务模块时为会计科目添加合计

2010-12-01 15:34 381 查看
最近实施的一个项目客户的会计科目表行非常多,并且没有使用中国本地化开发的树状科目,因此需要把非末级科目的科目类型设置为“合计”,并指定合计的下级科目,一个个设置有些太浪费时间和人力了,这种工作又不方便让技术顾问搞开发,还是自己用SQL解决吧。下面的方法不是最优化的,因为用了很多临时表,只是方便一些。

1. 将 LedgerTable 和 LedgerTableInterval 表转出为Excel (LedgerTable 表一定要将RecId 列也引出)。

2. 把 LedgerTable 表中的三列(AccountNum,AccountName,RecId)引入SQL Server(其中AccountName 列只是供人参考用,不引也可以)。

3. 更新 LedgerTable 表,把非末级科目的“科目类型”设置为“合计”

//填写AccountNumCN 列,这步做的傻了点,倒是容易理解,懒得优化了,其实一条语句就行了。
alter table coa add level1 varchar(255) //一级科目
alter table coa add level2 varchar(255) //二级科目
alter table coa add level3 varchar(255) //三级科目
alter table coa add AccountNumCN varchar(255) //临时科目,和按中国习惯显示的科目一样

update coa set level1=LEFT(accountnum,4)
update coa set level2=substring(accountnum,5,2)
update coa set level3=substring(accountnum,7,2)

update coa set AccountNumCN=level1 where level2='00'
update coa set AccountNumCN=level1+level2 where level3='00' and level2<>'00'
update coa set AccountNumCN=level1+level2+level3 where level3<>'00'

//按照AccountNumCN 判断哪些是末级科目,如果是则填1,不是则填0
alter table coa add EndMark tinyint //标识是否末级科目
update coa set EndMark=0
go
update coa set EndMark=1 from coa as t where not exists (select * from coa where AccountNumCN like t.AccountNumCN + '%' and AccountNumCN<>t.AccountNumCN)
go

//基本数据可以了,然后就转到EXCEL里处理再引入AX。
4. 填写 LedgerTableInterval 表

alter table coa add FromNum varchar(255) //合计起科目
alter table coa add ToNum varchar(255) //合计终科目 update coa set FromNum=AccountNumCN+'01' where EndMark=0
update coa set ToNum=AccountNumCN+'99' where EndMark=0

update coa set FromNum=left(FromNum+'0000',8) where EndMark=0
update coa set ToNum=left(ToNum+'0000',8) where EndMark=0

select RecId,FromNum,ToNum from coa where endmark=0

//基本数据可以了,然后就转到EXCEL里处理再引入AX。

处理后的数据截图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: