public async Task <IncomeResponseModel> UpdateIncome(UpdateIncomeRequestModel model)
        {
            var updatedIncome = new Incomes
            {
                Id          = model.Id,
                UserId      = model.UserId,
                Amount      = model.Amount,
                Description = model.Description,
                IncomeDate  = model.IncomeDate,
                Remarks     = model.Remarks
            };
            await _incomeRepository.UpdateAsync(updatedIncome);

            var incomeResponseModel = new IncomeResponseModel
            {
                Id          = updatedIncome.Id,
                UserId      = updatedIncome.UserId,
                Amount      = updatedIncome.Amount,
                Description = updatedIncome.Description,
                IncomeDate  = updatedIncome.IncomeDate,
                Remarks     = updatedIncome.Remarks
            };

            return(incomeResponseModel);
        }
        public static int CreateBusiness(BusinessCreateViewModel model, string username)
        {
            int      result   = 0;
            DateTime current  = DateTime.Now;
            Entities entities = new Entities();

            //Create business
            Assets business = new Assets();

            business.AssetName   = model.Name;
            business.Value       = model.Value.Value;
            business.StartDate   = current;
            business.CreatedDate = current;
            business.CreatedBy   = Constants.Constants.USER;
            business.AssetType   = (int)Constants.Constants.ASSET_TYPE.BUSINESS;
            business.ObtainedBy  = (int)Constants.Constants.OBTAIN_BY.CREATE;
            business.Username    = username;

            if (model.Income.HasValue && model.Income.Value > 0)
            {
                //Create income
                Incomes income = new Incomes();
                income.Name        = "Thu nhập kinh doanh từ " + business.AssetName;
                income.Value       = model.Income.Value;
                income.IncomeDay   = 1;
                income.StartDate   = current;
                income.CreatedDate = current;
                income.CreatedBy   = Constants.Constants.USER;
                income.IncomeType  = (int)Constants.Constants.INCOME_TYPE.BUSINESS_INCOME;
                income.Username    = username;
                business.Incomes1.Add(income);
            }

            if (model.IsInDebt)
            {
                if (model.Liabilities != null && model.Liabilities.Liabilities.Count > 0)
                {
                    foreach (var liabilityViewModel in model.Liabilities.Liabilities)
                    {
                        Liabilities liability = new Liabilities();
                        liability.Name             = liabilityViewModel.Source;
                        liability.Value            = liabilityViewModel.Value.Value;
                        liability.InterestType     = liabilityViewModel.InterestType;
                        liability.InterestRate     = liabilityViewModel.InterestRate.Value;
                        liability.InterestRatePerX = liabilityViewModel.InterestRatePerX;
                        liability.StartDate        = liabilityViewModel.StartDate.Value;
                        liability.EndDate          = liabilityViewModel.EndDate.Value;
                        liability.LiabilityType    = (int)Constants.Constants.LIABILITY_TYPE.BUSINESS;
                        liability.CreatedDate      = current;
                        liability.CreatedBy        = Constants.Constants.USER;
                        liability.Username         = username;
                        business.Liabilities.Add(liability);
                    }
                }
            }

            entities.Assets.Add(business);
            result = entities.SaveChanges();
            return(result);
        }
        public void RegisterIncome(decimal value, string description)
        {
            var incomesTotal   = Incomes.Select(a => a.Value).Sum() + value;
            var currentBalance = incomesTotal - Expenses.Select(a => a.Value).Sum();

            RaiseEvent(new IncomeRegistered(value, description, currentBalance));
        }
示例#4
0
        public override void Calculate()
        {
            var holdingPeriodReturn = 0.00m;

            var index = 0;

            foreach (var period in Periods)
            {
                var periodFrom = period.DateFrom;
                var periodTo   = period.DateTo;

                var incomeForPeriod = Incomes.Where(i => i.Timestamp >= periodFrom && i.Timestamp <= periodTo)
                                      .Select(i => i.Amount)
                                      .Sum();

                var periodicReturn = CalculatePeriodicReturn(periodFrom, periodTo, incomeForPeriod);

                if (index == 0)
                {
                    holdingPeriodReturn = periodicReturn;
                }
                else
                {
                    holdingPeriodReturn = holdingPeriodReturn * (1 + periodicReturn);
                }
                index++;
            }

            CalculatedTime = DateTime.Now;
            Rate           = holdingPeriodReturn - 1;
        }
示例#5
0
    public void LoadAndRender()
    {
        if (!PlayerPrefs.HasKey("Incomes"))
        {
            return;
        }
        Incomes incomes = GameObject.FindGameObjectWithTag("MainControl").GetComponent <MainControl>().incomes;

        for (int i = 0; i < incomes.Titles.Count; i++)
        {
            string[] ids = incomes.Ids[i].Split(' ');
            string[] valuesOnEachPurse = incomes.ValuesOnEachPurse[i].Split(' ');

            int[]    idsInt  = new int[ids.Length];
            double[] valsInt = new double[valuesOnEachPurse.Length];

            for (var k = 0; k < ids.Length; k++)
            {
                idsInt[k]  = int.Parse(ids[k]);
                valsInt[k] = double.Parse(valuesOnEachPurse[k]);
            }

            Render(idsInt, valsInt, incomes.Titles[i], incomes.Values[i], incomes.Curencys[i], DateTime.Parse(incomes.CreateDates[i]), i);
        }
        StartCoroutine(UpdateContentHeight());
    }
示例#6
0
        void ExecuteLoadIncomesCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Incomes.Clear();
                var incomes = DataStore.Get(true).OrderByDescending(x => x.Date);
                foreach (var item in incomes)
                {
                    item.BackgroundColor = Color.FromRgb(104, 222, 45);
                    Incomes.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private void OnDeleteBudgetItemCommandExecute(object budgetItem)
        {
            bool?response = this.questionBox.Show(
                "Are you sure you want to delete this budget bucket?\nAnalysis may not work correctly if transactions are allocated to this bucket.",
                "Delete Budget Bucket");

            if (response == null || response.Value == false)
            {
                return;
            }

            Dirty = true;
            var expenseItem = budgetItem as Expense;

            if (expenseItem != null)
            {
                expenseItem.PropertyChanged        -= OnExpenseAmountPropertyChanged;
                expenseItem.Bucket.PropertyChanged -= OnExpenseAmountPropertyChanged;
                Expenses.Remove(expenseItem);
                return;
            }

            var incomeItem = budgetItem as Income;

            if (incomeItem != null)
            {
                incomeItem.PropertyChanged        -= OnIncomeAmountPropertyChanged;
                incomeItem.Bucket.PropertyChanged -= OnIncomeAmountPropertyChanged;
                Incomes.Remove(incomeItem);
            }
        }
示例#8
0
        internal virtual bool Validate(StringBuilder validationMessages)
        {
            var retval = true;

            retval &= Incomes.OfType <IModelValidate>().ToList().All(i => i.Validate(validationMessages));
            retval &= Expenses.OfType <IModelValidate>().ToList().All(e => e.Validate(validationMessages));

            if (Expenses.Any(e => e.Bucket.Code == SurplusBucket.SurplusCode))
            {
                validationMessages.AppendFormat(CultureInfo.CurrentCulture,
                                                "You can not use SURPLUS as an expense code.");
                retval = false;
            }

            IEnumerable <string> duplicates = Expenses
                                              .GroupBy(i => i.Bucket.Code)
                                              .Where(g => g.Count() > 1)
                                              .Select(g => g.Key);

            foreach (var duplicateCode in duplicates)
            {
                retval = false;
                validationMessages.AppendFormat(CultureInfo.CurrentCulture,
                                                "Expense {0} is listed multiple time, each bucket must have a different name.", duplicateCode);
            }

            return(retval);
        }
        public ActionResult EditIncome(Incomes incomes)
        {
            incomes.UserId = User.Identity.GetUserId();
            incomeRepository.UpdateIncome(incomes);

            return(RedirectToAction("Index"));
        }
        public static int CreateOtherAsset(OtherAssetCreateViewModel model, string username)
        {
            int      result   = 0;
            DateTime current  = DateTime.Now;
            Entities entities = new Entities();

            //Create otherAsset
            Assets otherAsset = new Assets();

            otherAsset.AssetName   = model.Name;
            otherAsset.Value       = model.Value.Value;
            otherAsset.StartDate   = current;
            otherAsset.CreatedDate = current;
            otherAsset.CreatedBy   = Constants.Constants.USER;
            otherAsset.AssetType   = (int)Constants.Constants.ASSET_TYPE.OTHERS;
            otherAsset.ObtainedBy  = (int)Constants.Constants.OBTAIN_BY.CREATE;
            otherAsset.Username    = username;

            Incomes income = new Incomes();

            income.Name        = "Thu nhập từ " + otherAsset.AssetName;
            income.Value       = model.Income.HasValue ? model.Income.Value : 0;
            income.IncomeDay   = 1;
            income.StartDate   = current;
            income.CreatedDate = current;
            income.CreatedBy   = Constants.Constants.USER;
            income.IncomeType  = (int)Constants.Constants.INCOME_TYPE.OTHER_ASSET_INCOME;
            income.Username    = username;
            otherAsset.Incomes1.Add(income);

            entities.Assets.Add(otherAsset);
            result = entities.SaveChanges();
            return(result);
        }
        public async Task <IActionResult> Put(int id, [FromBody] Incomes model)
        {
            try
            {
                var oldIncome = _incomeRepository.GetIncomes(id);
                if (oldIncome == null)
                {
                    return(NotFound($"Could not find a Income with an ID of: {id}"));
                }

                oldIncome.Date         = model.Date;
                oldIncome.AmountEarned = model.AmountEarned;
                oldIncome.Comment      = model.Comment ?? model.Comment;
                oldIncome.Incometype   = model.Incometype ?? model.Incometype;

                if (await _incomeRepository.SaveAllAsync())
                {
                    return(Ok(oldIncome));
                }
            }
            catch (Exception ex)
            {
            }

            return(BadRequest("Couldn't update Income"));
        }
        public async Task<AddIncomeResponseModel> AddIncome(AddIncomRequestModel addIncome)
        {

            var income = new Incomes()
            {
                UserId = addIncome.UserId,
                Amount = addIncome.Amount,
                Description = addIncome.Description,
                IncomeDate = addIncome.IncomeDate,
                Remarks = addIncome.Remarks

            };

            var createdincome = await _incomeRepository.AddAsync(income);


            // map user object to UserRegisterResponseModel object
            var createdIncomeResponse = new AddIncomeResponseModel
            {

                UserId = createdincome.UserId,
                Amount = createdincome.Amount,
                Description = createdincome.Description,
                IncomeDate = createdincome.IncomeDate,
                Remarks = createdincome.Remarks


            };

            return createdIncomeResponse;

        }
示例#13
0
        public void RegisterExpense(decimal value, string description)
        {
            var expensesTotal  = Expenses.Select(a => a.Value).Sum() + value;
            var currentBalance = Incomes.Select(a => a.Value).Sum() - expensesTotal;

            RaiseEvent(new ExpenseRegistered(Id, value, description, currentBalance));
        }
        private void LoadIncomes()
        {
            int minYear = Incomes.Select(income => income.Date.Year).Min();
            int maxYear = Incomes.Select(income => income.Date.Year).Max();

            for (int i = minYear; i <= maxYear; i++)
            {
                decimal yearIncome = 0;
                monthIncomes[i] = new List <IncomeModel>();
                for (int j = 1; j <= 12; j++)
                {
                    var month = Incomes
                                .Where(income => income.Date.Year == i && income.Date.Month == j)
                                .Select(income => income.Money)
                                .Sum();

                    monthIncomes[i].Add(new IncomeModel
                    {
                        Date   = j,
                        Income = month
                    });

                    yearIncome += month;
                }

                yearIncomes.Add(new IncomeModel
                {
                    Date   = i,
                    Income = yearIncome
                });
            }
        }
示例#15
0
        void ExecuteDeleteIncomeCommand(object item)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            Income itemAsIncome = (Income)item;

            try
            {
                var income = Incomes.FirstOrDefault(x => x.Id == itemAsIncome.Id);
                DataStore.Delete(income);
                Incomes.Remove(income);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        /// <summary>
        /// Добавить доход.
        /// </summary>
        /// <param name="spendingName">Название дохода.</param>
        /// <param name="amount">Объем дохода.</param>
        /// <param name="category">Категория дохода.</param>
        /// <param name="comment">Комментарий к доходу.</param>
        public void AddIncome(string incomeName, double amount, string category, string comment)
        {
            var income = new Income(incomeName, amount, category, comment);

            Incomes.Add(income);
            this.CurrentAccount.AccountBalance += amount;
            SaveData(income);
        }
示例#17
0
        /// <summary>
        /// Get an income by unique identifier
        /// </summary>
        /// <param name="id">Unique identifier</param>
        /// <returns>Income</returns>
        public static Incomes GetIncomeById(int id)
        {
            Entities entities = new Entities();
            DateTime current  = DateTime.Now;
            Incomes  result   = entities.Incomes.Where(x => x.Id == id).FirstOrDefault();

            return(result);
        }
示例#18
0
        public ActionResult DeleteConfirmed(int id)
        {
            Incomes incomes = db.Incomes.Find(id);

            db.Incomes.Remove(incomes);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#19
0
        private string CalculateBalance()
        {
            var income   = 0.00M;
            var expenses = 0.00M;

            Incomes.ForEach(x => income    += x.Value);
            Expenses.ForEach(x => expenses += x.Value);
            return((income - expenses).ToString());
        }
        public async Task<Incomes> UpdateIncome(IncomeUpdateRequestModel UpdateIncome)
        {

            var updateExpense = new Incomes { Id = UpdateIncome.Id, UserId = UpdateIncome.UserId, Amount = UpdateIncome.Amount, Description = UpdateIncome.Description, IncomeDate = UpdateIncome.IncomeDate, Remarks = UpdateIncome.Remarks };
            var exp = await _incomeRepository.UpdateAsync(updateExpense);
            var updatedIncome = new Incomes { Id = exp.Id, UserId = exp.UserId, Amount = exp.Amount, Description = exp.Description, IncomeDate = exp.IncomeDate, Remarks = exp.Remarks };
            return updatedIncome;
            
        }
        private bool CanExecuteShowPieCommand()
        {
            if (Expenses == null || Incomes == null || CurrentBudget == null)
            {
                return(false);
            }

            return(Expenses.Any() || Incomes.Any());
        }
示例#22
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     if (parameters.GetNavigationMode() == NavigationMode.Back)
     {
         if (Incomes != null && _incomesCount != Incomes.Count)
         {
             Incomes = new ObservableCollection <Income>(Incomes.OrderByDescending(income => income.Date));
         }
     }
 }
        private void OnAddNewIncomeExecute()
        {
            Dirty = true;
            var newIncome = new Income {
                Bucket = new IncomeBudgetBucket(string.Empty, string.Empty), Amount = 0
            };

            Incomes.Add(newIncome);
            newIncome.PropertyChanged += OnIncomeAmountPropertyChanged;
        }
        private void OnIncomeAmountPropertyChanged(object sender, EventArgs propertyChangedEventArgs)
        {
            if (!this.isLoadingBudgetModel && IncomeTotal != 0)
            {
                Dirty = true;
            }

            IncomeTotal = Incomes.Sum(x => x.Amount);
            Surplus     = IncomeTotal - ExpenseTotal;
        }
        public async Task <Incomes> AddIncome(IncomeRequestModel incomeRequestModel)
        {
            var income = new Incomes
            {
                UsersId     = incomeRequestModel.UserId,
                Amount      = incomeRequestModel.Amount.Value,
                Description = incomeRequestModel.Description
            };

            return(await _incomeRepository.AddAsync(income));
        }
        public void UpdateIncome(Incomes incomes)
        {
            var updateIncome = context.Incomes.Where(x => x.Id == incomes.Id).FirstOrDefault();

            updateIncome.Name   = incomes.Name;
            updateIncome.UserId = incomes.UserId;
            updateIncome.Value  = incomes.Value;
            updateIncome.Date   = incomes.Date;

            context.SaveChanges();
        }
示例#27
0
        public void AssertAutoFieldsData(Address address, Incomes income)
        {
            var eik    = this.Eik.GetAttribute("value");
            var region = this.EmployerDistrict.GetAttribute("value");
            var area   = this.EmployerMunicipality.GetAttribute("value");
            var zip    = this.EmployerZip.GetAttribute("value");

            Assert.IsTrue(eik == income.Eik);
            Assert.IsTrue(region == address.Region);
            Assert.IsTrue(area == address.Area);
            Assert.IsTrue(zip == address.Zip);
        }
示例#28
0
        public static int DeleteSalary(int id)
        {
            Entities entities = new Entities();
            DateTime current  = DateTime.Now;

            Incomes salary = entities.Incomes.Where(x => x.Id == id).FirstOrDefault();

            salary.DisabledDate = current;
            salary.DisabledBy   = Constants.Constants.USER;
            entities.Incomes.Attach(salary);
            entities.Entry(salary).State = System.Data.Entity.EntityState.Modified;
            return(entities.SaveChanges());
        }
示例#29
0
        public void AddTemplate(string type)
        {
            if (type == "incomes")
            {
                this.list.AddRange(Incomes.Template());
            }
            else
            {
                this.list.AddRange(Expenses.Template());
            }

            Console.WriteLine($"{type} budget success loaded!");
        }
示例#30
0
        public void Add(Income incomeName, double amount)
        {
            var cost = Incomes.Keys.FirstOrDefault(c => c.Name.Equals(incomeName));

            if (cost == null)
            {
                Incomes.Add(incomeName, amount);
            }
            else
            {
                Incomes[cost] += amount;
            }
        }