/// <summary> /// 计算季度现金流信息 /// </summary> /// <param name="costList"></param> /// <param name="versionId"></param> /// <param name="season"></param> /// <param name="cashPure"></param> /// <param name="cashOut"></param> /// <param name="cashIn"></param> public void CalcSeasonCashFlowInfo(IEnumerable <BsonDocument> costList, string versionId, Season season, BsonDocument cashPure, BsonDocument cashOut, BsonDocument cashIn, BsonDocument cashAddup) { string SellDetail = "SellDetail"; List <BsonDocument> sellDetails = _ctx.FindAllByQuery(SellDetail, Query.EQ("versionId", versionId)).ToList();//销售信息 string RepayDetail = "RepayDetail"; List <BsonDocument> repayDetails = _ctx.FindAllByQuery(RepayDetail, Query.EQ("versionId", versionId)).ToList();//融资信息信息 string preKey = string.Empty; int index = 0; foreach (var seasonMonth in season.SeasonMonth) { string key = seasonMonth.key; var cost = costList.LeafNode().Sum(s => s.Decimal(key)); //成本支出 var sell = sellDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("salesVal")); var loan = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("loan")); //借款 var repayVal = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("repayVal")); //归还借款 var interest = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("interest")); //利息 //悲观 var mincost = costList.LeafNode().Sum(s => s.Decimal(key + "_min")); //成本支出 var minsell = sellDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("minSalesVal")); var minloan = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("minLoan")); //借款 var minrepayVal = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("minRepayVal")); //归还借款 var mininterest = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("minInterest")); //利息 //客观 var comcost = costList.LeafNode().Sum(s => s.Decimal(key + "_com")); //成本支出 var comsell = sellDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("comSalesVal")); var comloan = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("comLoan")); //借款 var comrepayVal = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("comRepayVal")); //归还借款 var cominterest = repayDetails.Where(s => isInSeason(seasonMonth.months, s.Date("date"))).Sum(s => s.Decimal("comInterest")); //利息 //净现金流 var tempTotal = sell + loan - repayVal - interest - cost; cashPure.Add(key, tempTotal.ToMoney()); var mintempTotal = minsell + minloan - minrepayVal - mininterest - mincost; cashPure.Add(key + "_min", mintempTotal.ToMoney()); var comtempTotal = comsell + comloan - comrepayVal - cominterest - comcost; cashPure.Add(key + "_com", comtempTotal.ToMoney()); //现金流出 var totalOut = -(repayVal + interest + cost); cashOut.Add(key, totalOut.ToMoney()); var mintotalOut = -(minrepayVal + mininterest + mincost); cashOut.Add(key + "_min", mintotalOut.ToMoney()); var comtotalOut = -(comrepayVal + cominterest + comcost); cashOut.Add(key + "_com", comtotalOut.ToMoney()); //现金流入 var totalIn = sell + loan; cashIn.Add(key, totalIn.ToMoney()); var mintotalIn = minsell + minloan; cashIn.Add(key + "_min", mintotalIn.ToMoney()); var comtotalIn = comsell + comloan; cashIn.Add(key + "_com", comtotalIn.ToMoney()); //累计现金流 var addup = cashAddup.Decimal(preKey) + cashPure.Decimal(key); cashAddup.Add(key, addup.ToMoney()); var minaddup = cashAddup.Decimal(preKey + "_min") + cashPure.Decimal(key + "_min"); cashAddup.Add(key + "_min", minaddup.ToMoney()); var comaddup = cashAddup.Decimal(preKey + "_com") + cashPure.Decimal(key + "_com"); cashAddup.Add(key + "_com", comaddup.ToMoney()); preKey = key; } }