借贷不平衡可以从三个方面去考虑:

1、T_facard/t_fabalcard、t_faexpense/t_fabalexpense 表中的科目是否是最明细科目, T_facard/t_fabalcard 表中的fassetacctid/fdepracctid 是否是固定资产和累计折旧科目;

2、t_fadept 与t_faexpense、t_fabaldept 与t_fabalexpense 对应的部门是否一致;

3、t_fabaldept、t_fabalexpense 与t_fabalance 对应的金额是否一致。可以先去掉不需要生成凭证的参数,再计提折旧。金额不一致,一般是因为t_fabaldept、t_fabalexpense 表中对应的科目或核算项目不正确造成的。

判断卡片表中的固定资产/累计折旧科目是否是最明细科目:

select * from t_facard where fassetacctid not in (select faccountid from t_account where fdetail=1)

select * from t_facard where fdepracctid not in (select faccountid from t_account where fdetail=1)

–更新部门分配表与费用分配表中的部门一致性:

update a set a.fdeptid=b.fitemid from t_faexpense a join t_fadept b on a.falterid=b.falterid where b.fitemid<>a.fdeptid and b.frate=1

update a set a.fdeptid=b.fitemid from t_fabalexpense a join t_fabaldept

b on a.fbalid=b.fbalid

where b.fitemid<>a.fdeptid and b.frate=1

— 判断t_ fabalexpense 与t_fabalance 的金额一致性:

select * from t_fabalexpense where fbalid in (

select a.fbalid from t_fabalance a join

(select fbalid,sum(famount) famount from t_fabalexpense group by

fbalid) b on a.fbalid=b.fbalid and a.fdepr<>b.famount

where a.fbalid in (select fbalid from t_fabalance where fyear=???? and

fperiod=??))