【问题描述】
专业版收款单选择源单销售发票保存时提示:收款单中包含核销金额大于未核销金额的销售发票,不允许保存!
【原因分析】
原因:所选销售发票表头的已核销金额及未核销金额与发票的实际核销金额不符,系统判定单据不允许保存;
【解决方案】
可参考以下脚本执行处理:
update ICSale set FReceiveAmountFor = rp.ftotal
from ICSale icx inner join
(
select ics.FInterID,FBillNo,FReceiveAmountFor,isnull(ftotal,0) ftotal –,FReceiveAmountFor-ftotal ‘差异’
–ics.FInterID ‘发票内码’,FBillNo ‘发票编码’,FReceiveAmountFor ‘账面已收金额’,ftotal ‘实际发生收款金额’
from ICSale ics
left join (
Select FInterID,sum(FAmount) ftotal From (
Select e.FInterID as FInterID,isnull(e.FBillSettleAmountFor,0) as FAmount –‘收款单’
from t_RP_RBill t Inner Join t_RP_RBillEntry e On t.FBillID=e.FBillID
Left Join t_Currency c ON e.FBillCurrencyID=c.FCurrencyID
Inner Join t_Account a ON a.FAccountID=t.FAcctId
Where e.FClassID_SRC IN (1000000,1000002)
Union All
Select u.FInterID as FInterID,-1*isnull(e.FBillSettleAmountFor,0) as FAmount –‘退款单’
from t_RP_RBill t Inner Join t_RP_RBillEntry e On t.FBillID=e.FBillID
Inner Join t_RP_RBillEntry u On e.FEntryID_SRC=u.FEntryID
Left Join t_Currency c ON e.FBillCurrencyID=c.FCurrencyID
Inner Join t_Account a ON a.FAccountID=t.FAcctId
Where t.FReceiveTypeid =1009 and u.FClassID_SRC in (1000000,1000002)
Union All
select FContactID as FInterID,isnull(e.FCheckAmountFor,0) as FAmount –‘核销单’
from T_RP_CheckInfo t Inner Join T_RP_CheckInfoEntry e ON t.FInterID=e.FInterID
Inner Join t_Currency c ON e.FCurrencyID=c.FCurrencyID
Where ((t.FCheckType = 1 And e.FEntryType = 1) Or (t.FCheckType = 2 And e.FEntryType = 1) Or (t.FCheckType = 3 And e.FEntryType = 0) )
And FContactType IN (80,86)
Union All
Select v1.FInvoiceID as FInterID,isnull(e.FBillSettleAmountFor,0) as FAmount –‘收款单’
from t_RP_RBill t Inner Join t_RP_RBillEntry e On t.FBillID=e.FBillID
Left Join t_RP_CheckInfoEntry v1 on v1.FInterID=e.FInterID and v1.FNo=e.FEntryID_HXD_SRC
Left Join t_RP_CheckInfo v2 on v1.FInterID=v2.FInterID
Left Join t_Currency c ON e.FBillCurrencyID=c.FCurrencyID
Inner Join t_Account a ON a.FAccountID=t.FAcctId
Where e.FClassID_SRC = 1000092 and v1.FInvoiceType IN (80,86) And v2.FCheckType=4
Union All
Select v1.FInvoiceID as FInterID,-1*isnull(e.FBillSettleAmountFor,0) as FAmount –‘退款单’
from t_RP_RBill t Inner Join t_RP_RBillEntry e On t.FBillID=e.FBillID
Inner Join t_RP_RBillEntry u On e.FEntryID_SRC=u.FEntryID
Left Join t_RP_CheckInfoEntry v1 on v1.FInterID=u.FInterID and v1.FNo=u.FEntryID_HXD_SRC
Left Join t_RP_CheckInfo v2 on v1.FInterID=v2.FInterID
Left Join t_Currency c ON e.FBillCurrencyID=c.FCurrencyID
Inner Join t_Account a ON a.FAccountID=t.FAcctId
Where t.FReceiveTypeid =1009 AND u.FClassID_SRC=1000092 AND v1.FInvoiceType IN (80,86) And v2.FCheckType=4
Union All
select v1.FInvoiceID as FInterID,isnull(v1.FCheckAmountFor,0) as FAmount –‘核销单’
from T_RP_CheckInfo t Inner Join T_RP_CheckInfoEntry e ON t.FInterID=e.FInterID
Inner Join T_RP_CheckInfoEntry v1 on v1.FContactID=e.FInterID and v1.FHeIndex=e.FNo
Inner Join T_RP_CheckInfo v2 on v2.FInterID=v1.FInterID
Inner Join t_Currency c ON e.FCurrencyID=c.FCurrencyID
Where ((v2.FCheckType = 1 And v1.FEntryType = 1) Or (v2.FCheckType = 2 And v1.FEntryType = 1) Or (v2.FCheckType = 3 And v1.FEntryType = 0))
And v1.FInvoiceType IN (80,86) And v1.FContactType=1005 AND t.FCheckType=4
Union All
SELECT b.FInvoiceID as FInterID,isnull(b.FCheckAmountFor, 0) – isnull(b.FMeCheckAmountFor, 0) as FAmount –应收转应收(未核销金额不为0的)上面没有包含未核销金额
FROM T_RP_CheckInfo a LEFT JOIN
T_RP_CheckInfoEntry b ON a.FInterID = b.FInterID
WHERE a.FCheckType = 4 AND b.FInvoiceType IN (80,86) and isnull(b.FCheckAmountFor, 0) – isnull(b.FMeCheckAmountFor, 0) <> 0
) pp
group by FInterID) md on md.FInterId=ics.FInterID
where ics.FReceiveAmountFor-isnull(md.ftotal,0)<>0
) rp on rp.FInterId=icx.FInterId
where rp.FReceiveAmountFor-isnull(rp.ftotal,0)<>0 and icx.FSaleStyle<>100
go
update ICSale set FUnReceiveAmountFor = FInvoiceAmountFor – FReceiveAmountFor
go
【注意事项】
正式账套执行脚本前请先做好备份,建议待在测试账套中核实无误后再在正式账套中执行。