private Dictionary <TransactionMedium, double> GetPreviousEnding(TransactionReportParameter parameter) { Dictionary <TransactionMedium, double> previousEnding = new Dictionary <TransactionMedium, double>(); var report = this.db.TransactionReports.Where( x => x.ReportTimeType == parameter.ReportTimeType && x.TransactionReportType == parameter.TransactionReportType && x.AccountHeadId == parameter.AccountHeadId && x.Date < parameter.Date && x.ShopId == parameter.ReportShopId).OrderByDescending(x => x.Date).FirstOrDefault(); if (report != null) { previousEnding.Add(TransactionMedium.All, report.TotalEnding); previousEnding.Add(TransactionMedium.Cash, report.CashEnding); previousEnding.Add(TransactionMedium.Card, report.CardEnding); previousEnding.Add(TransactionMedium.Cheque, report.ChequeEnding); previousEnding.Add(TransactionMedium.Mobile, report.MobileEnding); previousEnding.Add(TransactionMedium.Other, report.OtherEnding); } else { previousEnding.Add(TransactionMedium.All, 0); previousEnding.Add(TransactionMedium.Cash, 0); previousEnding.Add(TransactionMedium.Card, 0); previousEnding.Add(TransactionMedium.Cheque, 0); previousEnding.Add(TransactionMedium.Mobile, 0); previousEnding.Add(TransactionMedium.Other, 0); } return(previousEnding); }
public override IEnumerable <M> CreateReportModels(List <T> models, ReportParameterBase p) { string defaultAccountHeadId = new Guid().ToString(); string defaultAccountHeadName = "All"; TransactionReportParameter previousParameter = new TransactionReportParameter( TransactionReportType.TransactionByAmount, defaultAccountHeadName, defaultAccountHeadId, null, p); var startingAll = this.GetPreviousEnding(previousParameter); var parameterAll = new TransactionReportParameter( TransactionReportType.TransactionByAmount, defaultAccountHeadName, defaultAccountHeadId, startingAll, p); var allReport = this.CreateReportModel(models, parameterAll); yield return(allReport); List <IGrouping <string, T> > transactionsByAccId = models.GroupBy(x => x.AccountHeadId).ToList(); foreach (var tById in transactionsByAccId) { var accId = tById.Key; if (tById.Any()) { var transaction = tById.First(); previousParameter.TransactionReportType = TransactionReportType.TransactionByAccountHead; previousParameter.AccountHeadId = accId; Dictionary <TransactionMedium, double> startingAmountsByAccount = GetPreviousEnding(previousParameter); var parameterByAccount = new TransactionReportParameter(TransactionReportType.TransactionByAccountHead, transaction.AccountHeadName, accId, startingAmountsByAccount, p); M transactionReport = this.CreateReportModel(tById.ToList(), parameterByAccount); yield return(transactionReport); } } }