public ISubtotalResult SelectVoucherDetailsGrouped(IGroupedQuery query) => m_Db.SelectVoucherDetailsGrouped(query);
/// <inheritdoc /> public IEnumerable <Balance> SelectVoucherDetailsGrouped(IGroupedQuery query) { var level = query.Subtotal.Levels.Aggregate(SubtotalLevel.None, (total, l) => total | l); if (query.Subtotal.AggrType != AggregationType.None) { level |= query.Subtotal.AggrInterval; } if (query.Subtotal.EquivalentDate.HasValue) { level |= SubtotalLevel.Currency; } var preF = query.VoucherEmitQuery.VoucherQuery.Accept(new MongoDbNativeVoucher()); var chk = GetChk(query.VoucherEmitQuery); BsonDocument pprj; if (!level.HasFlag(SubtotalLevel.Day)) { pprj = ProjectDetails; } else if (!level.HasFlag(SubtotalLevel.Week)) { pprj = ProjectDate; } else if (level.HasFlag(SubtotalLevel.Year)) { pprj = ProjectYear; } else if (level.HasFlag(SubtotalLevel.Month)) { pprj = ProjectMonth; } else // if (level.HasFlag(SubtotalLevel.Week)) { pprj = ProjectWeek; } var prj = new BsonDocument(); if (level.HasFlag(SubtotalLevel.Day)) { prj["date"] = "$date"; } if (level.HasFlag(SubtotalLevel.User)) { prj["user"] = "******"; } if (level.HasFlag(SubtotalLevel.Currency)) { prj["currency"] = "$detail.currency"; } if (level.HasFlag(SubtotalLevel.Title)) { prj["title"] = "$detail.title"; } if (level.HasFlag(SubtotalLevel.SubTitle)) { prj["subtitle"] = "$detail.subtitle"; } if (level.HasFlag(SubtotalLevel.Content)) { prj["content"] = "$detail.content"; } if (level.HasFlag(SubtotalLevel.Remark)) { prj["remark"] = "$detail.remark"; } BsonDocument grp; if (query.Subtotal.GatherType == GatheringType.Count) { grp = new BsonDocument { ["_id"] = prj, ["count"] = new BsonDocument { ["$sum"] = 1 } } } ; else { grp = new BsonDocument { ["_id"] = prj, ["total"] = new BsonDocument { ["$sum"] = "$detail.fund" } } }; var fluent = m_Vouchers.Aggregate().Match(preF).Project(pprj).Unwind("detail").Match(chk).Group(grp); if (query.Subtotal.AggrType != AggregationType.ChangedDay && query.Subtotal.GatherType == GatheringType.NonZero) { fluent = fluent.Match(FilterNonZero); } return(fluent.ToEnumerable().Select(b => BsonSerializer.Deserialize <Balance>(b))); }