总账-期末结账写下一期期初
金蝶云社区-云社区用户48fm8987
云社区用户48fm8987
1人赞赏了该文章 528次浏览 未经作者许可,禁止转载编辑于2016年08月17日 11:59:16

select FCompanyId,FAccountViewId,FCurrencyId,FAccountBankId,FPeriodId,
sum(ISNULL(FDebitAmount,0.00)) as FMonthDebitAmt,
sum(ISNULL(FCreditAmount,0.00)) as FMonthCreditAmt,
sum(ISNULL(FMonthStartAmt,0.00)) as FMonthStartAmt,
sum(ISNULL(FDebitAmount,0.00))-sum(ISNULL(FCreditAmount,0.00))+sum(ISNULL(FMonthStartAmt,0.00)) as FMonthBalance,
sum(ISNULL(FYearStartAmt,0.00)) as FYearStartAmt,
sum(ISNULL(FDebitAmount,0.00))+sum(ISNULL(FYearDebitAmt,0.00)) as FYearDebitAmt,
sum(ISNULL(FCreditAmount,0.00))+sum(ISNULL(FYearCreditAmt,0.00)) as FYearCreditAmt,
sum(ISNULL(FDebitAmount,0.00))-sum(ISNULL(FCreditAmount,0.00))+sum(ISNULL(FMonthStartAmt,0.00)) as FYearBalance,
0 as FDebitStartAmt,0 as FCreditStartAmt,FControlUnitID,0 AS FIsInit,
//以此标志位标识是否已结账,2表示未结账,3表示已结账
3 AS FIsBalanced,FType
FROM (SELECT FAccountBankId, fcurrencyid, fperiodid, faccountviewid,fcompanyid,
sum(ISNULL(FDebitAmount,0.00)) as FDebitAmount,
sum(ISNULL(FCreditAmount,0.00)) as FCreditAmount,
0 as FMonthBalance,0 as FMonthStartAmt,0 as FYearStartAmt,0 as FYearDebitAmt,0 as FYearCreditAmt,0 as FYearBalance,FType
from T_CAS_Journal
WHERE FCompanyId=?
AND FPeriodId=?
GROUP BY FAccountViewId, FCompanyId, FPeriodId, FCurrencyId, FAccountBankId, FType
union all
select FAccountBankId, fcurrencyid, fperiodid, faccountviewid,fcompanyid,0 as FDebitAmount,0 as FCreditAmount,
FMonthBalance,FMonthStartAmt,FYearStartAmt, FYearDebitAmt,FYearCreditAmt,FYearBalance,ftype
from T_CAS_JournalBalance
WHERE FCompanyId=?
AND FPeriodId=?
//不需要对对账单进行结账
AND FIsInit=0 and FType != 3
) summary group by faccountviewid, fcompanyid,fperiodid,fcurrencyid,FAccountBankId,ftype

您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!

请选择打赏金币数 *

10金币20金币30金币40金币50金币60金币
可用金币: 0