コード例 #1
0
        public async Task <TransactionDetail> GetTransaction(int id)
        {
            var spec        = new TransactionWithCategoryAndVendorSpecification(id);
            var transaction = await _unitOfWork.Repository <TransactionDetail>().FindOneBySpecAsync(spec);

            return(transaction);
        }
コード例 #2
0
        public async Task <IReadOnlyList <TransactionDto> > GetTransactions(TransactionsFilter specParams)
        {
            var spec         = new TransactionWithCategoryAndVendorSpecification(specParams);
            var transactions = await _unitOfWork.Repository <TransactionDetail>()
                               .FindAllBySpecAsync <TransactionDto>(spec);

            return(transactions);
        }
コード例 #3
0
        public async Task <MonthlyBillDto> GenerateMonthlyBillAsync(int month, int year, bool simulated = true)
        {
            if (!simulated)
            {
                var billSpec            = new BillSpecification(month, year);
                var inmateBillsForMonth = await _unitOfWork.Repository <InmateBill>().FindAllBySpecAsync(billSpec);

                _unitOfWork.Repository <InmateBill>().RemoveMany(inmateBillsForMonth);

                var transactionsToDeleteSpec = new TransactionDetailSpecification(month, year, true);
                var transactionsToDelete     = await _unitOfWork.Repository <TransactionDetail>().FindAllBySpecAsync(transactionsToDeleteSpec);

                _unitOfWork.Repository <TransactionDetail>().RemoveMany(transactionsToDelete);

                await _unitOfWork.Complete();
            }

            var filter = new TransactionsFilter(month, year, false)
            {
                IsAutoGeneratedTxnsNeeded = false
            };
            var spec         = new TransactionWithCategoryAndVendorSpecification(filter);
            var transactions = await _unitOfWork.Repository <TransactionDetail>().FindAllBySpecAsync(spec);

            var transactionsGrouped = transactions.GroupBy(t => t.CategoryId);

            var categoricalSum = transactionsGrouped.ToDictionary(billCategory => billCategory.Key, billCategory => billCategory.Sum(b => b.Amount));

            var monthlyBill = new MonthlyBillDto(month, year);

            var categories = await _unitOfWork.Repository <Category>().FindAllAsync();



            var categoryWiseExpensesList = new List <CategoryWiseExpense>();

            decimal monthlyTotal = 0;

            var associatedVendorNamesList = new List <string> {
                VendorNames.Main, VendorNames.Others
            };

            var vendorSpec = new VendorSpecification(associatedVendorNamesList);

            var vendors = await _unitOfWork.Repository <Vendor>().FindAllBySpecAsync(vendorSpec);

            var mainAccount = vendors.FirstOrDefault(v => v.Name == VendorNames.Main);

            var othersAccount = vendors.FirstOrDefault(v => v.Name == VendorNames.Others);


            foreach (var category in categories)
            {
                var categoryWiseExpense = new CategoryWiseExpense
                {
                    CategoryId         = category.Id,
                    CategoryName       = category.Name,
                    TotalAmount        = category.ConsiderDefaultRate && category.DefaultRate != 0 ? category.DefaultRate : (categoricalSum.ContainsKey(category.Id)?categoricalSum[category.Id]:0),
                    TransactionDetails = transactions
                                         .Where(t => t.Category.Name == category.Name)
                                         .Select(t => new TransactionDetailDto()
                    {
                        TransactionDetailName = t.Name,
                        Amount = t.Amount
                    }).ToList()
                };

                if (categoryWiseExpense.TransactionDetails == null || categoryWiseExpense.TransactionDetails.Count == 0)
                {
                    if (!simulated && categoryWiseExpense.TotalAmount > 0)
                    {
                        var transaction = new TransactionDetail
                        {
                            Name            = categoryWiseExpense.CategoryName,
                            CategoryId      = category.Id,
                            PaidPartyId     = mainAccount.Id,
                            PaidToId        = othersAccount.Id,
                            Amount          = categoryWiseExpense.TotalAmount,
                            TransactionDate = new DateTime(year, month, 1),
                            IsExpense       = true,
                            IsAutoGenerated = true
                        };

                        await _transactionService.PostTransaction(transaction);
                    }

                    categoryWiseExpense.TransactionDetails = new List <TransactionDetailDto>
                    {
                        new TransactionDetailDto
                        {
                            TransactionDetailName = categoryWiseExpense.CategoryName,
                            Amount = categoryWiseExpense.TotalAmount
                        }
                    };
                }

                monthlyTotal += categoryWiseExpense.TotalAmount;

                if (category.Name != BillCategory.DEPOSIT.ToString() && category.Name != BillCategory.BILLPAYMENT.ToString())
                {
                    categoryWiseExpensesList.Add(categoryWiseExpense);
                }
            }

            monthlyBill.CategoryWiseExpenses = categoryWiseExpensesList;

            monthlyBill.SubTotal = monthlyTotal;

            return(monthlyBill);
        }
コード例 #4
0
        public async Task <int> GetTransactionsCount(TransactionsFilter specParams)
        {
            var spec = new TransactionWithCategoryAndVendorSpecification(specParams, true);

            return(await _unitOfWork.Repository <TransactionDetail>().GetCountForSpecAsync(spec));
        }