示例#1
0
        public ActionResult TrialBalance()
        {
            var allLogs    = _context.GetAllLogs().ToList();
            var viewModels = new List <TrialBalanceViewModel>();

            foreach (var transaction in allLogs)
            {
                var model = viewModels.FirstOrDefault(t => t.AccountCode == transaction.AccountCode);

                if (model == null)
                {
                    model = new TrialBalanceViewModel
                    {
                        AccountCode = transaction.AccountCode,
                        AcctName    = transaction.Name,
                        Category    = transaction.MainAccountCategory,
                        totalDebit  = transaction.Type == TransactionType.Debit ? transaction.Amount : 0,
                        totalCredit = transaction.Type == TransactionType.Credit ? transaction.Amount : 0
                    };
                    viewModels.Add(model);
                }
                else
                {
                    var amount = transaction.Amount;
                    if (transaction.Type == TransactionType.Debit)
                    {
                        model.totalDebit += amount;
                    }
                    else
                    {
                        model.totalCredit += amount;
                    }
                }
            }

            ViewBag.DebitTotal  = viewModels.Sum(c => c.totalDebit);
            ViewBag.CreditTotal = viewModels.Sum(c => c.totalCredit);


            return(View(viewModels));
        }
示例#2
0
        public IEnumerable <TransactionLog> GetAllLogs()
        {
            var values = _db.GetAllLogs();

            return(values);
        }