Exemplo n.º 1
0
        public ActionResult OverAllReport(DateTime?month)
        {
            if (month == null)
            {
                month = DateTime.UtcNow;
            }
            ViewBag.month = month;

            var budgets                = budgetDac.Get().OrderBy(x => x.Name);
            var transactions           = transactionDac.Get(month.Value).ToList();
            var bringForwordThisMonths = bringForwardDac.Get(month.Value);

            transactions.InsertRange(0, bringForwordThisMonths.Select(b => new Transaction
            {
                IssueDate = new DateTime(month.Value.Year, month.Value.Month, 1),
                Title     = "ยอดยกมา",
                Amount    = b?.Amount ?? 0,
                BudgetId  = b.BudgetId,
            }));
            var response = new OverAllReport
            {
                Budgets = budgets.OrderBy(x => x.Name).Select(x => new OverAllReportDetail
                {
                    Budget       = x,
                    Transactions = transactions.Where(t => t.BudgetId == x.Id).OrderBy(x => x.IssueDate).ThenBy(x => x.Id).ToList(),
                }).ToList(),
            };

            return(View(response));
        }
Exemplo n.º 2
0
        private void CalculateBringForword(DateTime month, int budgetId)
        {
            var date1      = DateTime.UtcNow;
            var monthCount = ((date1.Year - month.Year) * 12) + date1.Month - month.Month;

            for (int i = 0; i < monthCount; i++)
            {
                var currentMonth = month.AddMonths(i);

                var bringForwordThisMonth = bringForwardDac.Get(currentMonth, budgetId);
                if (bringForwordThisMonth == null)
                {
                    bringForwordThisMonth = new BringForward
                    {
                        Month    = currentMonth,
                        BudgetId = budgetId,
                    };
                }
                var bringForwordNextMonth = bringForwardDac.Get(currentMonth.AddMonths(1), budgetId);
                if (bringForwordNextMonth == null)
                {
                    bringForwordNextMonth = new BringForward
                    {
                        Month    = currentMonth.AddMonths(1),
                        BudgetId = budgetId,
                    };
                }
                var transactions = transactionDac.Get(currentMonth, budgetId);

                var sumAmount = bringForwordThisMonth.Amount + transactions.Sum(x => x.Amount);
                bringForwordNextMonth.Amount = sumAmount;

                bringForwardDac.Upsert(bringForwordNextMonth);
            }
        }
        public IActionResult Index(DateTime?month, int budgetId = 1)
        {
            if (month == null)
            {
                month = DateTime.UtcNow;
            }
            ViewBag.month    = month;
            ViewBag.budgetId = budgetId;

            var budgets = budgetDac.Get().ToList();

            budgets.Add(new Budget
            {
                Id   = 0,
                Name = "ภาษี ณ ที่จ่าย",
            });
            ViewBag.budgets = budgets.OrderBy(x => x.Name);

            var partners     = partnerDac.Get();
            var transactions = budgetId switch
            {
                0 => transactionDac.GetTeackVat(month.Value).OrderBy(x => x.IssueDate).ThenBy(x => x.Id).Select(x => new Transaction
                {
                    Id        = x.Id,
                    IssueDate = x.IssueDate,
                    Title     = $"รับเงินภาษี ณ ที่จ่ายจาก {partners.FirstOrDefault(p => p.Id == x.PartnerId)?.Name}",
                    Amount    = x.VatInclude.Value,
                }).ToList(),
                _ => transactionDac.Get(month.Value, budgetId).OrderBy(x => x.IssueDate).ThenBy(x => x.Id).ToList(),
            };
            var bringForword = bringForwardDac.Get(month.Value, budgetId);

            if (bringForword != null)
            {
                transactions.Insert(0, new Transaction
                {
                    IssueDate = new DateTime(month.Value.Year, month.Value.Month, 1),
                    Title     = "ยอดยกมา",
                    Amount    = bringForword?.Amount ?? 0,
                    BudgetId  = bringForword.BudgetId,
                });
            }
            return(View(transactions));
        }