Beispiel #1
0
 public AddSpending(PeriodId periodId, Amount amount, Label label, Pair pair, SpendingCategory category)
 {
     PeriodId = periodId;
     Amount   = amount;
     Label    = label;
     Pair     = pair;
     Category = category;
 }
Beispiel #2
0
 public SpendingAdded(OperationId operationId, Amount amount, Label label, Pair pair, SpendingCategory category)
 {
     Pair        = pair;
     Label       = label;
     Amount      = amount;
     Category    = category;
     OperationId = operationId;
 }
Beispiel #3
0
        public OperationId AddSpending(Amount amount, Label label, Pair pair, SpendingCategory category)
        {
            var operationId = OperationId.From(State.GetNextOperationId());

            RaiseEvent(new SpendingAdded(operationId, amount, label, pair, category));
            RaiseBalanceChanged();
            return(operationId);
        }
 public ChangeSpending(PeriodId periodId, OperationId operationId, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     PeriodId = periodId;
     OperationId = operationId;
     Amount = amount;
     Label = label;
     Pair = pair;
     Category = category;
 }
Beispiel #5
0
 public IActionResult Create(SpendingCategory model)
 {
     if (ModelState.IsValid)
     {
         _SpendingCategory.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public async Task <IActionResult> AddSpending([FromBody] Spending input)
 {
     return(await SendCommandAsync(new AddSpending(
                                       PeriodId.From(input.PeriodId),
                                       Amount.From(input.Amount),
                                       Label.From(input.Label),
                                       Pair.From(input.Pair),
                                       SpendingCategory.From(input.Category))));
 }
Beispiel #7
0
        public void Should_Construct_SpendingCategory()
        {
            SpendingCategory spendingCategory = new SpendingCategory();

            _ = spendingCategory.SpendingCategoryId;
            _ = spendingCategory.NameAr;
            _ = spendingCategory.NameEn;

            spendingCategory.ShouldNotBeNull();
        }
Beispiel #8
0
        public void ShowByCategory(SpendingCategory category)
        {
            double total     = 0;
            var    spendings = _spendings.Where(s => s.Category == category).ToList();

            foreach (var spending in spendings)
            {
                total += spending.MoneyAmount;
            }

            ShowAll(spendings, total);
        }
Beispiel #9
0
 // GET: Accounts/Create
 public IActionResult Delete(int?Id)
 {
     if (Id == null)
     {
         return(NotFound());
     }
     else
     {
         SpendingCategory model = _SpendingCategory.GetSpendingCategory(Id);
         return(View(model));
     }
 }
Beispiel #10
0
        public static Spending Create()
        {
            Spending spending = new Spending();
            double   money;

            Console.WriteLine("Enter an amount of money.");
            while (!double.TryParse(Console.ReadLine(), out money) || !money.IsPositive())
            {
                Console.WriteLine("Wrong input. Please, try again.");
            }

            SpendingCategory category = (SpendingCategory)Spending.ChooseCategory();

            spending.Category    = category;
            spending.MoneyAmount = money;
            spending.Date        = DateTimeOffset.UtcNow;

            Logger.Log.Info("New spending was created");
            return(spending);
        }
Beispiel #11
0
        private static Period ChangeSpendingInfo(Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
        {
            var period = Some.Period(p => p.WithEvent(new SpendingAdded(OperationId.From(1), Amount.From(10), Label.From("test"), Pair.First, SpendingCategory.Advance)));

            MakeChanges(period, amount, label, pair, category);
            return(period);
        }
Beispiel #12
0
 private void ChangeOperation(OperationId operationId, Amount amount, Label label, Pair pair, SpendingCategory category)
 {
     ChangeOperation(operationId, amount, label, pair);
     if (State.CategoryNotEquals(operationId, category))
     {
         RaiseEvent(new SpendingCategoryChanged(operationId, category));
     }
 }
Beispiel #13
0
 public void ChangeSpending(OperationId operationId, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     ChangeOperation(operationId, amount, label, pair, category);
     if (UncommitedEventsHaveDifferentEventThatLabelChanged())
     {
         RaiseBalanceChanged();
     }
 }
Beispiel #14
0
 internal bool CategoryNotEquals(OperationId operationId, SpendingCategory category) => category != null && _periodOperations.CategoryNotEquals(operationId.Value, category.Value);
Beispiel #15
0
        /// <summary>
        /// Converts a SpendingCategory value to a corresponding string value
        /// </summary>
        /// <param name="enumValue">The SpendingCategory value to convert</param>
        /// <returns>The representative string value</returns>
        public static string ToValue(SpendingCategory enumValue)
        {
            switch (enumValue)
            {
            //only valid enum elements can be used
            //this is necessary to avoid errors
            case SpendingCategory.BILLS_AND_SERVICES:
            case SpendingCategory.CHARITY:
            case SpendingCategory.EATING_OUT:
            case SpendingCategory.ENTERTAINMENT:
            case SpendingCategory.EXPENSES:
            case SpendingCategory.FAMILY:
            case SpendingCategory.GAMBLING:
            case SpendingCategory.GENERAL:
            case SpendingCategory.GIFTS:
            case SpendingCategory.GROCERIES:
            case SpendingCategory.HOME:
            case SpendingCategory.INCOME:
            case SpendingCategory.SAVING:
            case SpendingCategory.SHOPPING:
            case SpendingCategory.HOLIDAYS:
            case SpendingCategory.PAYMENTS:
            case SpendingCategory.PETS:
            case SpendingCategory.TRANSPORT:
            case SpendingCategory.LIFESTYLE:
            case SpendingCategory.NONE:
            case SpendingCategory.REVENUE:
            case SpendingCategory.OTHER_INCOME:
            case SpendingCategory.CLIENT_REFUNDS:
            case SpendingCategory.INVENTORY:
            case SpendingCategory.STAFF:
            case SpendingCategory.TRAVEL:
            case SpendingCategory.WORKPLACE:
            case SpendingCategory.REPAIRS_AND_MAINTENANCE:
            case SpendingCategory.ADMIN:
            case SpendingCategory.MARKETING:
            case SpendingCategory.BUSINESS_ENTERTAINMENT:
            case SpendingCategory.INTEREST_PAYMENTS:
            case SpendingCategory.BANK_CHARGES:
            case SpendingCategory.OTHER:
            case SpendingCategory.FOOD_AND_DRINK:
            case SpendingCategory.EQUIPMENT:
            case SpendingCategory.PROFESSIONAL_SERVICES:
            case SpendingCategory.PHONE_AND_INTERNET:
            case SpendingCategory.VEHICLES:
            case SpendingCategory.DIRECTORS_WAGES:
            case SpendingCategory.VAT:
            case SpendingCategory.CORPORATION_TAX:
            case SpendingCategory.SELF_ASSESSMENT_TAX:
            case SpendingCategory.INVESTMENT_CAPITAL:
            case SpendingCategory.TRANSFERS:
            case SpendingCategory.LOAN_PRINCIPAL:
            case SpendingCategory.PERSONAL:
            case SpendingCategory.DIVIDENDS:
                return(StringValues[(int)enumValue]);

            //an invalid enum value was requested
            default:
                return(null);
            }
        }
Beispiel #16
0
        PositivityCategory Categorise(IDictionary <SpendingCategory, PositivityCategory> categories, SpendingCategory spendingCategory)
        {
            if (categories.TryGetValue(spendingCategory, out var positivityCategory))
            {
                return(positivityCategory);
            }

            return(PositivityCategory.Neutral);
        }
        public void UpdateOperation(PeriodId periodId, OperationId operationId, Amount amount = null, Label label = null, Pair pair = null, RecipeCategory recipeCategory = null, SpendingCategory spendingCategory = null)
        {
            if (!_operations.ContainsKey(periodId.Value))
            {
                return;
            }

            var operation = _operations[periodId.Value].FirstOrDefault(a => a.OperationId == operationId.Value);

            if (operation == null)
            {
                return;
            }

            if (amount != null)
            {
                operation.Amount = amount.Value;
            }
            if (label != null)
            {
                operation.Label = label.Value;
            }
            if (pair != null)
            {
                operation.Pair      = pair.GetUserName(_userProvider);
                operation.PairValue = pair.Value;
            }
            if (recipeCategory != null)
            {
                operation.Category      = recipeCategory.ToString();
                operation.CategoryValue = recipeCategory.Value;
            }
            if (spendingCategory != null)
            {
                operation.Category      = spendingCategory.ToString();
                operation.CategoryValue = spendingCategory.Value;
            }
        }
 public SpendingCategoryChanged(OperationId operationId, SpendingCategory category)
 {
     OperationId = operationId;
     Category    = category;
 }
Beispiel #19
0
 public void Add(SpendingCategory _SpendingCategory)
 {
     db.SpendingCategories.Add(_SpendingCategory);
     db.SaveChanges();
 }
Beispiel #20
0
 private static void MakeChanges(Period period, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     period.ChangeSpending(OperationId.From(1),
                           amount ?? Amount.From(10),
                           label ?? Label.From("test"),
                           pair ?? Pair.First,
                           category ?? SpendingCategory.Advance);
 }
Beispiel #21
0
        public SpendingCategory GetSpendingCategory(int?Id)
        {
            SpendingCategory dbEntity = db.SpendingCategories.Find(Id);

            return(dbEntity);
        }
        public async Task <ActionResult> Details(String id)
        {
            var model = new AccountDetailsViewModel();

            //Find all Transactions matching the account number (id)
            var ctList = db.CustomerTransactions
                         .Where(a => a.AccountNum == id)
                         .OrderBy(data => data.TransactionDate);

            //Return as a list
            model.CustomerTransactions = await ctList.ToListAsync();

            // create set of datapoints

            List <DataPoint> lineDataPoints = new List <DataPoint>();

            var startingBalance = db.CustomersAccounts
                                  .Where(a => a.AccountNum == id)
                                  .Select(a => a.Balance)
                                  .FirstOrDefault();
            var currBalance     = startingBalance;
            var tempDate        = new DateTime();
            var utcDate         = new DateTime(1969, 12, 31);
            var transCategories = db.TransactionCategories;
            List <TransactionWithCategory> transLookup = new List <TransactionWithCategory>();

            tempDate = model.CustomerTransactions[0].TransactionDate;

            foreach (var customerTransaction in model.CustomerTransactions)
            {
                SpendingCategory transCatEnum = (SpendingCategory)9;

                String transCat = "Credit";

                if (customerTransaction.TransactionType == TransactionTypeEnum.Debit)
                {
                    transCatEnum = db.TransactionCategories
                                   .Where(a => a.TransDescription == customerTransaction.Description)
                                   .Select(a => a.SpendingCategory)
                                   .FirstOrDefault();
                    transCat = Enum.GetName(typeof(SpendingCategory), transCatEnum);
                }

                TransactionWithCategory transCatEntry = new TransactionWithCategory();

                transCatEntry.TransactionID    = customerTransaction.TransactionID;
                transCatEntry.spendingCategory = transCat;
                transLookup.Add(transCatEntry);

                if (tempDate.Date != customerTransaction.TransactionDate.Date)
                {
                    lineDataPoints.Add(new DataPoint((tempDate.Subtract(utcDate).TotalMilliseconds), currBalance));
                    tempDate = customerTransaction.TransactionDate;
                }
                if (customerTransaction.TransactionType == TransactionTypeEnum.Credit)
                {
                    currBalance = currBalance + customerTransaction.Amount;
                }
                else if (customerTransaction.TransactionType == TransactionTypeEnum.Debit)
                {
                    currBalance = currBalance - customerTransaction.Amount;
                }
            }

            model.TransactionsWithCategories = transLookup;

            lineDataPoints.Add(new DataPoint((tempDate.Subtract(utcDate).TotalMilliseconds), currBalance));

            model.LineChartDataPoints = lineDataPoints;

            List <PieDataPoint> pieDataPoints = new List <PieDataPoint>();

            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Housing), 25.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Utilities), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Food), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Transportation), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Recreation), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Savings), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Personal), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Health), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Debt), 10.0));
            pieDataPoints.Add(new PieDataPoint(nameof(SpendingCategory.Other), 10.0));

            model.PieChartDataPoints = pieDataPoints;
            List <Decimal> amtByCat = new List <Decimal>();

            for (int i = 0; i < 10; i++)
            {
                amtByCat.Add(0);
            }

            // loop through transactions, update amount for each category
            foreach (var customerTransaction in model.CustomerTransactions)
            {
                SpendingCategory category = new SpendingCategory();

                if (customerTransaction.TransactionType == TransactionTypeEnum.Debit)
                {
                    category = transCategories
                               .Where(t => t.TransDescription == customerTransaction.Description)
                               .Select(t => t.SpendingCategory)
                               .FirstOrDefault();

                    int categoryInt = Convert.ToInt32(category);
                    amtByCat[categoryInt] += customerTransaction.Amount;
                }
            }

            // calcuate total spending
            decimal sum = amtByCat.Sum();

            // calculate spending percentage by category
            // add percentages to datapoints

            List <Double> percentByCat = new List <double>(10);

            for (int i = 0; i < 10; i++)
            {
                percentByCat.Add(0);
            }

            for (int i = 0; i < 10; i++)
            {
                percentByCat[i]    = Math.Round(((double)(amtByCat[i] / sum) * 100), 2);
                pieDataPoints[i].Y = percentByCat[i];
            }

            return(View(model));
        }