应付账龄分析表和应付明细表余额不一致排查方向(数据库)原创
85人赞赏了该文章
404次浏览
编辑于2024年06月28日 15:25:05
问题:
截止同一时间点,应付款明细表和应付款账龄分析表原币余额不相等(过滤条件一致的情况下)
(本位币不相等可能受调汇的影响)
排查方向:
1. 是否存在单据已经被删除,但核销记录还在
--付款单 SELECT FID 核销序号,FENTRYID,FSRCBILLNO 单据编号,FTARGETBILLNO 目标单据编码,FCURWRITTENOFFAMOUNTFOR 本次核销金额 FROM T_AP_PAYMATCHLOGENTRY A WHERE FSOURCEFROMID='AP_PAYBILL' AND NOT EXISTS (SELECT 1 FROM T_AP_PAYBILL WHERE FID=A.FSRCBILLID) --应付单 SELECT FID 核销序号,FENTRYID,FSRCBILLNO 单据编号,FTARGETBILLNO 目标单据编码,FCURWRITTENOFFAMOUNTFOR 本次核销金额 FROM T_AP_PAYMATCHLOGENTRY A WHERE FSOURCEFROMID='AP_Payable' AND NOT EXISTS (SELECT 1 FROM T_AP_PAYABLE WHERE FID=A.FSRCBILLID) --付款退款单 SELECT FID 核销序号,FENTRYID,FSRCBILLNO 单据编号,FTARGETBILLNO 目标单据编码,FCURWRITTENOFFAMOUNTFOR 本次核销金额 FROM T_AP_PAYMATCHLOGENTRY A WHERE FSOURCEFROMID='AP_REFUNDBILL' AND NOT EXISTS (SELECT 1 FROM T_AP_REFUNDBILL WHERE FID=A.FSRCBILLID) --其他应付单 SELECT FID 核销序号,FENTRYID,FSRCBILLNO 单据编号,FTARGETBILLNO 目标单据编码,FCURWRITTENOFFAMOUNTFOR 本次核销金额 FROM T_AP_PAYMATCHLOGENTRY A WHERE FSOURCEFROMID='AP_OtherPayable' AND NOT EXISTS (SELECT 1 FROM T_AP_OTHERPAYABLE WHERE FID=A.FSRCBILLID) --应付核销单 SELECT FID 核销序号,FENTRYID,FSRCBILLNO 单据编号,FTARGETBILLNO 目标单据编码,FCURWRITTENOFFAMOUNTFOR 本次核销金额 FROM T_AP_PAYMATCHLOGENTRY A WHERE FSOURCEFROMID='AP_Match' AND NOT EXISTS (SELECT 1 FROM T_AP_MATCK WHERE FID=A.FSRCBILLID)
处理方案:将异常核销记录反核销(由于有行分录单据已经不存在了,所以点击反核销可能会没反应或报错单据已经不存在)
2. 排查是否存在同一笔核销记录中本次核销金额不一致的核销记录
SELECT FID 核销序号,SUM(FCURWRITTENOFFAMOUNTFOR) FROM ( SELECT A.FID,FSOURCEFROMID,FTARGETFROMID, CASE WHEN FSOURCEFROMID IN ('AP_Payable','AP_OtherPayable','AR_receivable','AR_OtherRecAble','AP_REFUNDBILL') OR FSOURCEFROMID='AP_Match' AND FTARGETFROMID='AP_PAYBILL' THEN FCURWRITTENOFFAMOUNTFOR WHEN FSOURCEFROMID IN ('AP_PAYBILL','AP_InnerPayClear') OR FSOURCEFROMID='AP_Match' AND FTARGETFROMID IN ('AP_Payable','AP_REFUNDBILL','AP_OtherPayable','AR_receivable','AR_OtherRecAble') THEN -FCURWRITTENOFFAMOUNTFOR ELSE FCURWRITTENOFFAMOUNTFOR END FCURWRITTENOFFAMOUNTFOR FROM T_AP_PAYMATCHLOGENTRY A INNER JOIN T_AP_PAYMATCHLOG B ON A.FID=B.FID WHERE FBILLMATCHLOGID=0 ) A GROUP BY FID HAVING SUM(FCURWRITTENOFFAMOUNTFOR )<>0
处理方案:将异常核销记录反核销
3. 是否存在明细金额和计划金额不一致的应付单
SELECT A.FBILLNO 单据编号,A.FALLAMOUNTFOR 单据头价税合计,B.FALLAMOUNTFOR 明细价税合计汇总,C.FPAYAMOUNTFOR 计划应付金额汇总 FROM T_AP_PAYABLE A LEFT JOIN (SELECT FID,SUM(FALLAMOUNTFOR) FALLAMOUNTFOR FROM T_AP_PAYABLEENTRY GROUP BY FID) B ON A.FID=B.FID LEFT JOIN (SELECT FID,SUM(FPAYAMOUNTFOR) FPAYAMOUNTFOR FROM T_AP_PAYABLEPLAN GROUP BY FID) C ON A.FID=C.FID WHERE A.FALLAMOUNTFOR<>B.FALLAMOUNTFOR OR A.FALLAMOUNTFOR<>C.FPAYAMOUNTFOR
处理方案:修复应付单计划金额
4. 是否存在同一笔核销记录中(非特殊核销)往来单位不一致的核销记录
SELECT T.FID 核销序号 FROM ( SELECT DISTINCT A.FID,A.FMASTERID FROM ( --SELECT A.FID 核销序号,A.FSRCBILLNO 单据编号,A.FTARGETBILLNO 目标单据编号,A.FCONTACTUNITTYPE 往来单位类型,A.FCONTACTUNIT 往来单位内码,A.FMASTERID,A.FSETTLEORGID 结算组织 SELECT A.FID,A.FENTRYID,A.FSRCBILLNO,A.FTARGETBILLNO,A.FCONTACTUNITTYPE,A.FCONTACTUNIT,V.FMASTERID,A.FSETTLEORGID FROM T_AP_PAYMATCHLOGENTRY A LEFT JOIN V_FIN_CONTACTTYPE V ON A.FCONTACTUNIT=V.FITEMID ) A LEFT JOIN T_AP_PAYMATCHLOG B ON A.FID=B.FID WHERE B.FMATCHMETHODID NOT IN (40,30,38) --核销方式不为转销/特殊核销/外部特殊核销 ) T GROUP BY T.FID HAVING COUNT(1)>1
处理方案:将异常核销记录反核销
自动核销记录反核销方法请参考:自动核销记录如何操作反核销?
赞 85
85人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读