コード例 #1
0
        public static OtherExpenseListViewModel GetOtherExpenseByUser(string username)
        {
            Entities entities      = new Entities();
            var      otherExpenses = entities.Expenses.Where(x => x.Username.Equals(username) &&
                                                             x.ExpenseType == (int)Constants.Constants.EXPENSE_TYPE.OTHERS &&
                                                             !x.DisabledDate.HasValue).OrderBy(x => x.Name).ToList();
            OtherExpenseListViewModel result = new OtherExpenseListViewModel();

            foreach (var otherExpense in otherExpenses)
            {
                OtherExpenseViewModel viewModel = new OtherExpenseViewModel
                {
                    Id            = otherExpense.Id,
                    Source        = otherExpense.Name,
                    ExpenseDay    = otherExpense.ExpenseDay,
                    Expense       = otherExpense.Value,
                    AnnualExpense = otherExpense.Value * 12,
                    Note          = otherExpense.Note
                };

                result.Expenses.Add(viewModel);
            }

            result.TotalExpense       = result.Expenses.Sum(x => x.Expense.Value);
            result.TotalAnnualExpense = result.TotalExpense * 12;
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #2
0
        public static CarLiabilityListViewModel GetCarLiabilityByUser(string username)
        {
            Entities entities = new Entities();
            CarLiabilityListViewModel result = new CarLiabilityListViewModel();
            DateTime current     = DateTime.Now;
            var      liabilities = entities.Liabilities.Where(x => x.Username.Equals(username) &&
                                                              x.LiabilityType == (int)Constants.Constants.LIABILITY_TYPE.CAR &&
                                                              !x.DisabledDate.HasValue).OrderBy(x => x.Name);

            foreach (var liability in liabilities)
            {
                CarLiabilityViewModel viewModel = CreateViewModel(liability);
                result.Liabilities.Add(viewModel);
            }

            var lbts = result.Liabilities.Where(x => x.StartDate <= current && x.EndDate >= current);

            result.TotalOriginalValue   = lbts.Sum(x => x.LiabilityValue);
            result.TotalLiabilityValue  = lbts.Sum(x => x.Value.Value);
            result.TotalInterestPayment = lbts.Sum(x => x.MonthlyInterestPayment);
            result.TotalOriginalPayment = lbts.Sum(x => x.MonthlyOriginalPayment);
            result.TotalPayment         = lbts.Sum(x => x.TotalMonthlyPayment);
            result.TotalRemainedValue   = lbts.Sum(x => x.RemainedValue);
            result.TotalInterestRate    = result.TotalLiabilityValue > 0 ? lbts.Sum(x => x.OriginalInterestPayment) / result.TotalLiabilityValue * 12 : 0;
            result.IsInitialized        = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #3
0
        public static SalaryListViewModel GetSalaryByUser(string username)
        {
            Entities entities = new Entities();
            var      salaries = entities.Incomes.Where(x => x.Username.Equals(username) &&
                                                       x.IncomeType == (int)Constants.Constants.INCOME_TYPE.SALARY_INCOME &&
                                                       !x.DisabledDate.HasValue).OrderBy(x => x.Name).ToList();
            SalaryListViewModel result = new SalaryListViewModel();

            foreach (var salary in salaries)
            {
                SalaryViewModel viewModel = new SalaryViewModel
                {
                    Id           = salary.Id,
                    Source       = salary.Name,
                    IncomeDay    = salary.IncomeDay,
                    Income       = salary.Value,
                    AnnualIncome = salary.Value * 12,
                    Note         = salary.Note
                };

                result.Salaries.Add(viewModel);
            }

            result.TotalIncome       = result.Salaries.Sum(x => x.Income.Value);
            result.TotalAnnualIncome = result.TotalIncome * 12;
            result.IsInitialized     = UserQueries.IsCompleteInitialized(username);
            return(result);
        }
コード例 #4
0
        public static BusinessListViewModel GetBusinessByUser(string username)
        {
            Entities entities            = new Entities();
            BusinessListViewModel result = new BusinessListViewModel();
            DateTime current             = DateTime.Now;

            var businesss = entities.Assets.Include("Incomes").Include("Liabilities").Where(x => x.Username.Equals(username) &&
                                                                                            x.AssetType == (int)Constants.Constants.ASSET_TYPE.BUSINESS &&
                                                                                            !x.DisabledDate.HasValue);

            foreach (var business in businesss)
            {
                BusinessViewModel businessViewModel = new BusinessViewModel();
                businessViewModel.Id    = business.Id;
                businessViewModel.Name  = business.AssetName;
                businessViewModel.Value = business.Value;
                if (business.Incomes1.Where(x => !x.DisabledDate.HasValue).Any())
                {
                    businessViewModel.Income = business.Incomes1.FirstOrDefault().Value;
                }
                else
                {
                    businessViewModel.Income = 0;
                }
                businessViewModel.AnnualIncome = businessViewModel.Income * 12;
                businessViewModel.RentYield    = businessViewModel.Value > 0 ? businessViewModel.AnnualIncome / businessViewModel.Value : 0;

                foreach (var liability in business.Liabilities.Where(x => !x.DisabledDate.HasValue))
                {
                    BusinessLiabilityViewModel liabilityViewModel = BusinessLiabilityQueries.CreateViewModel(liability);
                    businessViewModel.Liabilities.Add(liabilityViewModel);
                }

                var liabilities = businessViewModel.Liabilities.Where(x => x.StartDate <= current && x.EndDate >= current);
                businessViewModel.TotalLiabilityValue  = liabilities.Select(x => x.Value.Value).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalOriginalPayment = liabilities.Select(x => x.MonthlyOriginalPayment).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalInterestPayment = liabilities.Select(x => x.MonthlyInterestPayment).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalMonthlyPayment  = liabilities.Select(x => x.TotalMonthlyPayment).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalPayment         = liabilities.Select(x => x.TotalPayment).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalRemainedValue   = liabilities.Select(x => x.RemainedValue).DefaultIfEmpty(0).Sum();
                businessViewModel.TotalInterestRate    = businessViewModel.TotalLiabilityValue > 0 ? liabilities.Select(x => x.OriginalInterestPayment).DefaultIfEmpty(0).Sum() / businessViewModel.TotalLiabilityValue * 12 : 0;
                businessViewModel.RowSpan = businessViewModel.Liabilities.Any() ? businessViewModel.Liabilities.Count() + 3 : 2;

                result.Businesses.Add(businessViewModel);
            }

            result.TotalValue         = result.Businesses.Select(x => x.Value).DefaultIfEmpty(0).Sum();
            result.TotalMonthlyIncome = result.Businesses.Select(x => x.Income).DefaultIfEmpty(0).Sum();
            result.TotalAnnualIncome  = result.TotalMonthlyIncome * 12;
            result.TotalRentYield     = result.TotalValue > 0 ? result.TotalAnnualIncome / result.TotalValue : 0;
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #5
0
        public static InsuranceListViewModel GetInsuranceByUser(string username)
        {
            Entities entities   = new Entities();
            var      insurances = entities.Assets.Include("Expenses").Where(x => x.Username.Equals(username) &&
                                                                            x.AssetType == (int)Constants.Constants.ASSET_TYPE.INSURANCE &&
                                                                            !x.DisabledDate.HasValue).OrderBy(x => x.AssetName).ToList();
            InsuranceListViewModel result = new InsuranceListViewModel();

            foreach (var insurance in insurances)
            {
                var expense = insurance.Expenses1.FirstOrDefault();
                InsuranceViewModel viewModel = new InsuranceViewModel
                {
                    Id            = insurance.Id,
                    Name          = insurance.AssetName,
                    Value         = insurance.Value,
                    StartDate     = insurance.StartDate.Value,
                    EndDate       = insurance.EndDate.Value,
                    PaymentPeriod = Helper.TimePeriodString(insurance.StartDate.Value, insurance.EndDate.Value),
                    Expense       = expense.Value,
                    AnnualExpense = expense.Value * 12,
                    Note          = insurance.Note
                };

                int paymentPeriod = Helper.CalculateTimePeriod(insurance.StartDate.Value, insurance.EndDate.Value);
                viewModel.TotalExpense = paymentPeriod * viewModel.Expense;
                viewModel.YieldRate    = viewModel.TotalExpense > 0 ? (viewModel.Value - viewModel.TotalExpense) / viewModel.TotalExpense : 0;
                int currentPeriod = Helper.CalculateTimePeriod(viewModel.StartDate, DateTime.Now);
                viewModel.RemainedValue = viewModel.TotalExpense - viewModel.Expense * currentPeriod;

                result.Insurances.Add(viewModel);
            }

            result.TotalValue         = result.Insurances.Sum(x => x.Value);
            result.TotalTotalExpense  = result.Insurances.Sum(x => x.TotalExpense);
            result.TotalExpense       = result.Insurances.Sum(x => x.Expense);
            result.TotalAnnualExpense = result.Insurances.Sum(x => x.AnnualExpense);
            result.TotalRemainedValue = result.Insurances.Sum(x => x.RemainedValue);
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #6
0
        public static AvailableMoneyCreateViewModel GetInitializedAvailableMoney(string username)
        {
            Entities entities = new Entities();
            AvailableMoneyCreateViewModel viewModel = new AvailableMoneyCreateViewModel();
            Users user = entities.Users.Where(x => x.Username.Equals(username)).FirstOrDefault();

            Assets availableMoney = entities.Assets.Where(x => x.Username.Equals(username) &&
                                                          x.AssetType == (int)Constants.Constants.ASSET_TYPE.AVAILABLE_MONEY &&
                                                          !x.DisabledDate.HasValue).OrderBy(x => x.CreatedDate).FirstOrDefault();

            if (availableMoney != null)
            {
                viewModel.Name           = "Tiền mặt có sẵn khởi tạo của " + user.FullName;
                viewModel.AvailableMoney = availableMoney.Value;
                viewModel.IsInitialized  = UserQueries.IsCompleteInitialized(username);
                return(viewModel);
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
        public static CreditCardLiabilityListViewModel GetCreditCardLiabilityByUser(string username)
        {
            Entities entities = new Entities();
            CreditCardLiabilityListViewModel result = new CreditCardLiabilityListViewModel();
            var liabilities = entities.Liabilities.Where(x => x.Username.Equals(username) &&
                                                         x.LiabilityType == (int)Constants.Constants.LIABILITY_TYPE.CREDIT_CARD &&
                                                         !x.DisabledDate.HasValue).OrderBy(x => x.Name);

            foreach (var liability in liabilities)
            {
                CreditCardLiabilityViewModel viewModel = CreateViewModel(liability);
                result.Liabilities.Add(viewModel);
            }

            result.TotalValue          = result.Liabilities.Sum(x => x.Value);
            result.TotalMonthlyPayment = result.Liabilities.Sum(x => x.MonthlyPayment);
            result.TotalAnnualPayment  = result.Liabilities.Sum(x => x.AnnualPayment);
            result.TotalInterestRate   = result.TotalAnnualPayment / result.TotalValue;
            result.IsInitialized       = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #8
0
        public static OtherAssetListViewModel GetOtherAssetByUser(string username)
        {
            Entities entities = new Entities();
            OtherAssetListViewModel result = new OtherAssetListViewModel();
            DateTime current = DateTime.Now;

            var otherAssets = entities.Assets.Include("Incomes").Include("Liabilities").Where(x => x.Username.Equals(username) &&
                                                                                              x.AssetType == (int)Constants.Constants.ASSET_TYPE.OTHERS &&
                                                                                              !x.DisabledDate.HasValue);

            foreach (var otherAsset in otherAssets)
            {
                OtherAssetViewModel otherAssetViewModel = new OtherAssetViewModel();
                otherAssetViewModel.Id    = otherAsset.Id;
                otherAssetViewModel.Name  = otherAsset.AssetName;
                otherAssetViewModel.Value = otherAsset.Value;
                if (otherAsset.Incomes1.Where(x => !x.DisabledDate.HasValue).Any())
                {
                    otherAssetViewModel.Income = otherAsset.Incomes1.FirstOrDefault().Value;
                }
                else
                {
                    otherAssetViewModel.Income = 0;
                }
                otherAssetViewModel.AnnualIncome = otherAssetViewModel.Income * 12;
                otherAssetViewModel.RentYield    = otherAssetViewModel.AnnualIncome / otherAssetViewModel.Value;

                result.Assets.Add(otherAssetViewModel);
            }

            result.TotalValue         = result.Assets.Select(x => x.Value).DefaultIfEmpty(0).Sum();
            result.TotalMonthlyIncome = result.Assets.Select(x => x.Income).DefaultIfEmpty(0).Sum();
            result.TotalAnnualIncome  = result.TotalMonthlyIncome * 12;
            result.TotalRentYield     = result.TotalMonthlyIncome / result.TotalValue;
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #9
0
        public static BankDepositListViewModel GetBankDepositByUser(string username)
        {
            Entities entities     = new Entities();
            var      bankDeposits = entities.Assets.Where(x => x.Username.Equals(username) &&
                                                          x.AssetType == (int)Constants.Constants.ASSET_TYPE.BANK_DEPOSIT &&
                                                          !x.DisabledDate.HasValue).OrderBy(x => x.AssetName).ToList();
            BankDepositListViewModel result = new BankDepositListViewModel();

            foreach (var bankDeposit in bankDeposits)
            {
                BankDepositViewModel viewModel = new BankDepositViewModel
                {
                    Id                = bankDeposit.Id,
                    Name              = bankDeposit.AssetName,
                    Value             = bankDeposit.Value,
                    StartDate         = bankDeposit.StartDate.Value,
                    EndDate           = bankDeposit.EndDate.Value,
                    Income            = bankDeposit.InterestRatePerX.Value == (int)Constants.Constants.INTEREST_RATE_PER.MONTH ? bankDeposit.Value * bankDeposit.InterestRate.Value / 100 : bankDeposit.Value * bankDeposit.InterestRate.Value / 1200,
                    InterestRate      = bankDeposit.InterestRate.Value / 100,
                    InterestRatePerX  = Helper.GetInterestTypePerX(bankDeposit.InterestRatePerX.Value),
                    InterestObtainWay = Helper.GetObtainWay(bankDeposit.ObtainedBy.Value),
                    PaymentPeriod     = Helper.CalculateTimePeriod(bankDeposit.StartDate.Value, bankDeposit.EndDate.Value),
                    Note              = bankDeposit.Note
                };
                viewModel.AnnualIncome = viewModel.Income * 12;
                result.BankDeposits.Add(viewModel);
            }

            result.TotalValue        = result.BankDeposits.Sum(x => x.Value);
            result.TotalIncome       = result.BankDeposits.Sum(x => x.Income);
            result.TotalAnnualIncome = result.BankDeposits.Sum(x => x.AnnualIncome);
            result.TotalInterestRate = result.TotalValue > 0 ? result.TotalAnnualIncome / result.TotalValue : 0;
            result.IsInitialized     = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #10
0
        public static StockListViewModel GetStockByUser(string username)
        {
            Entities           entities = new Entities();
            StockListViewModel result   = new StockListViewModel();
            DateTime           current  = DateTime.Now;

            var stocks = entities.Assets.Include("StockTransactions").Include("Liabilities").Where(x => x.Username.Equals(username) &&
                                                                                                   x.AssetType == (int)Constants.Constants.ASSET_TYPE.STOCK &&
                                                                                                   !x.DisabledDate.HasValue);

            foreach (var stock in stocks)
            {
                StockViewModel stockViewModel = new StockViewModel();
                stockViewModel.Id   = stock.Id;
                stockViewModel.Name = stock.AssetName;
                stockViewModel.Note = stock.Note;

                foreach (var transactions in stock.StockTransactions.Where(x => !x.DisabledDate.HasValue))
                {
                    StockTransactionViewModel transactionViewModel = StockQueries.CreateViewModel(transactions);
                    stockViewModel.Transactions.Transactions.Add(transactionViewModel);
                }

                var liabilities = stockViewModel.Transactions.Transactions.Select(x => x.Liabilities.Liabilities.Where(y => y.StartDate <= current && y.EndDate >= current));
                stockViewModel.TotalLiabilityValue          = liabilities.Sum(x => x.Sum(y => y.Value.HasValue ? y.Value.Value : 0));
                stockViewModel.TotalOriginalPayment         = liabilities.Sum(x => x.Sum(y => y.MonthlyOriginalPayment));
                stockViewModel.TotalInterestPayment         = liabilities.Sum(x => x.Sum(y => y.MonthlyInterestPayment));
                stockViewModel.TotalMonthlyPayment          = liabilities.Sum(x => x.Sum(y => y.TotalMonthlyPayment));
                stockViewModel.TotalPayment                 = liabilities.Sum(x => x.Sum(y => y.TotalPayment));
                stockViewModel.TotalRemainedValue           = liabilities.Sum(x => x.Sum(y => y.RemainedValue));
                stockViewModel.TotalOriginalInterestPayment = liabilities.Sum(x => x.Sum(y => y.OriginalInterestPayment));
                stockViewModel.TotalInterestRate            = stockViewModel.TotalLiabilityValue > 0 ? stockViewModel.TotalOriginalInterestPayment / stockViewModel.TotalLiabilityValue * 12 : 0;
                stockViewModel.RowSpan = stockViewModel.Transactions.Transactions.Any() ? stockViewModel.Transactions.Transactions.Count() + stockViewModel.Transactions.Transactions.Select(x => x.Liabilities.Liabilities).Count() + 4 : 4;

                if (stockViewModel.Transactions.Transactions.Any())
                {
                    stockViewModel.RowSpan = 4;
                    bool flag = false;
                    foreach (var transaction in stockViewModel.Transactions.Transactions)
                    {
                        if (transaction.Liabilities.Liabilities.Count() > 0)
                        {
                            if (flag == false)
                            {
                                flag = true;
                            }
                            stockViewModel.RowSpan += transaction.Liabilities.Liabilities.Count();
                        }
                    }
                    if (flag == true)
                    {
                        stockViewModel.RowSpan += 1;
                    }
                }
                else
                {
                    stockViewModel.RowSpan = 4;
                }

                result.Stocks.Add(stockViewModel);
            }

            result.TotalValue    = result.Stocks.Select(x => x.Transactions.Transactions).Sum(x => x.Sum(y => y.StockValue.Value));
            result.IsInitialized = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
コード例 #11
0
        // GET: OtherAsset
        public ActionResult Index()
        {
            bool result = UserQueries.IsCompleteInitialized(UserQueries.GetCurrentUsername());

            return(View(result));
        }