Beispiel #1
0
        private void PickerTypeStatsChanged(object sender, EventArgs e)
        {
            try
            {
                if (!(sender is Picker pk))
                {
                    return;
                }
                currentFequencyUsedToCalculate = HelperShuffle.ParseEnum <FrequencyOfIncomeExpenses>(pk.Items[pk.SelectedIndex]);
                CalculateTotals(currentFequencyUsedToCalculate);

                var fre = pk.Items[pk.SelectedIndex];
                if (fre == "Annually")
                {
                    CurrentViewModel.BreakDownText = "(per Year)";
                    return;
                }


                CurrentViewModel.BreakDownText = $"(per {pk.Items[pk.SelectedIndex].Trim(new char[] { 'l', 'y' })})";
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        private void CalculateTotals(FrequencyOfIncomeExpenses typeOfCalculationToPerform = FrequencyOfIncomeExpenses.Weekly)
        {
            try
            {
                CurrentViewModel.TotalIncome      = 0;
                CurrentViewModel.WeeklyCosts      = 0;
                CurrentViewModel.MonthlyCosts     = 0;
                CurrentViewModel.AnnualCosts      = 0;
                CurrentViewModel.FortnightlyCosts = 0;



                //*****calculate everything for weekly then set at the end
                foreach (var item in CurrentViewModel.BudgetDataEntry)
                {
                    //get all the incomes
                    if (item.IncomeOrExpense)
                    {
                        switch (item.Frequency)
                        {
                        case FrequencyOfIncomeExpenses.Weekly:
                            CurrentViewModel.TotalIncome += item.Amount;
                            break;

                        case FrequencyOfIncomeExpenses.Fortnightly:
                            CurrentViewModel.TotalIncome += item.Amount * 26 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Monthly:
                            CurrentViewModel.TotalIncome += item.Amount * 12 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Annually:
                            CurrentViewModel.TotalIncome += item.Amount / 52;
                            break;

                        default:
                            CurrentViewModel.TotalIncome += item.Amount;
                            break;
                        }
                    }
                    else
                    {
                        switch (item.Frequency)
                        {
                        case FrequencyOfIncomeExpenses.Weekly:
                            CurrentViewModel.WeeklyCosts += item.Amount;
                            break;

                        case FrequencyOfIncomeExpenses.Fortnightly:
                            CurrentViewModel.FortnightlyCosts += item.Amount / 2;
                            break;

                        case FrequencyOfIncomeExpenses.Monthly:
                            CurrentViewModel.MonthlyCosts += item.Amount * 12 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Annually:
                            CurrentViewModel.AnnualCosts += item.Amount / 52;
                            break;

                        default:
                            CurrentViewModel.WeeklyCosts += item.Amount;
                            break;
                        }
                    }
                }

                switch (typeOfCalculationToPerform)
                {
                case FrequencyOfIncomeExpenses.Weekly:
                    break;

                case FrequencyOfIncomeExpenses.Fortnightly:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52 / 26;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52 / 26;
                    CurrentViewModel.FortnightlyCosts = (CurrentViewModel.FortnightlyCosts * 52) / 26;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 2;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 2;
                    break;

                case FrequencyOfIncomeExpenses.Monthly:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52 / 12;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52 / 12;
                    CurrentViewModel.FortnightlyCosts = (CurrentViewModel.FortnightlyCosts * 52) / 12;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 52 / 12;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 52 / 12;
                    break;

                case FrequencyOfIncomeExpenses.Annually:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52;
                    CurrentViewModel.FortnightlyCosts = CurrentViewModel.FortnightlyCosts * 52;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 52;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 52;
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        private void CalculateTotals(FrequencyOfIncomeExpenses typeOfCalculationToPerform = FrequencyOfIncomeExpenses.Weekly)
        {
            try
            {
                CurrentViewModel.TotalIncome      = 0;
                CurrentViewModel.WeeklyCosts      = 0;
                CurrentViewModel.MonthlyCosts     = 0;
                CurrentViewModel.AnnualCosts      = 0;
                CurrentViewModel.FortnightlyCosts = 0;



                //*****calculate everything for weekly then set at the end
                foreach (var item in CurrentViewModel.BudgetDataEntry)
                {
                    //get all the incomes
                    if (item.IncomeOrExpense)
                    {
                        switch (item.Frequency)
                        {
                        case FrequencyOfIncomeExpenses.Weekly:
                            CurrentViewModel.TotalIncome += item.Amount;
                            break;

                        case FrequencyOfIncomeExpenses.Fortnightly:
                            CurrentViewModel.TotalIncome += item.Amount * 26 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Monthly:
                            CurrentViewModel.TotalIncome += item.Amount * 12 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Annually:
                            CurrentViewModel.TotalIncome += item.Amount / 52;
                            break;

                        default:
                            CurrentViewModel.TotalIncome += item.Amount;
                            break;
                        }
                    }
                    else
                    {
                        switch (item.Frequency)
                        {
                        case FrequencyOfIncomeExpenses.Weekly:
                            CurrentViewModel.WeeklyCosts += item.Amount;
                            break;

                        case FrequencyOfIncomeExpenses.Fortnightly:
                            CurrentViewModel.FortnightlyCosts += item.Amount / 2;
                            break;

                        case FrequencyOfIncomeExpenses.Monthly:
                            CurrentViewModel.MonthlyCosts += item.Amount * 12 / 52;
                            break;

                        case FrequencyOfIncomeExpenses.Annually:
                            CurrentViewModel.AnnualCosts += item.Amount / 52;
                            break;

                        default:
                            CurrentViewModel.WeeklyCosts += item.Amount;
                            break;
                        }
                    }
                }

                switch (typeOfCalculationToPerform)
                {
                case FrequencyOfIncomeExpenses.Weekly:
                    break;

                case FrequencyOfIncomeExpenses.Fortnightly:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52 / 26;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52 / 26;
                    CurrentViewModel.FortnightlyCosts = (CurrentViewModel.FortnightlyCosts * 52) / 26;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 2;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 2;
                    break;

                case FrequencyOfIncomeExpenses.Monthly:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52 / 12;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52 / 12;
                    CurrentViewModel.FortnightlyCosts = (CurrentViewModel.FortnightlyCosts * 52) / 12;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 52 / 12;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 52 / 12;
                    break;

                case FrequencyOfIncomeExpenses.Annually:
                    CurrentViewModel.TotalIncome      = CurrentViewModel.TotalIncome * 52;
                    CurrentViewModel.FortnightlyCosts = CurrentViewModel.FortnightlyCosts * 52;
                    CurrentViewModel.WeeklyCosts      = CurrentViewModel.WeeklyCosts * 52;
                    CurrentViewModel.MonthlyCosts     = CurrentViewModel.MonthlyCosts * 52;
                    CurrentViewModel.AnnualCosts      = CurrentViewModel.AnnualCosts * 52;
                    break;

                default:
                    break;
                }


                var totalIncome = CurrentViewModel.TotalIncome;

                var totalCosts = CurrentViewModel.WeeklyCosts + CurrentViewModel.FortnightlyCosts +
                                 CurrentViewModel.MonthlyCosts + CurrentViewModel.AnnualCosts;
                var dt = new ObservableCollection <ChartDataModel>();
                if (totalIncome > totalCosts)
                {
                    //calculate the percentage of total costs based on income
                    //var wk = (CurrentViewModel.WeeklyCosts / CurrentViewModel.TotalIncome) * 100;
                    //var ft = (CurrentViewModel.FortnightlyCosts / CurrentViewModel.TotalIncome) * 100;
                    //var mth = (CurrentViewModel.MonthlyCosts / CurrentViewModel.TotalIncome) * 100;
                    //var yr = (CurrentViewModel.AnnualCosts / CurrentViewModel.TotalIncome) * 100;
                    var wk       = CurrentViewModel.WeeklyCosts;
                    var ft       = CurrentViewModel.FortnightlyCosts;
                    var mth      = CurrentViewModel.MonthlyCosts;
                    var yr       = CurrentViewModel.AnnualCosts;
                    var leftOver = totalIncome - (wk + ft + mth + yr);


                    dt = new ObservableCollection <ChartDataModel>
                    {
                        new ChartDataModel(FrequencyOfIncomeExpenses.Weekly.ToString(), wk),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Fortnightly.ToString(), ft),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Monthly.ToString(), mth),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Annually.ToString(), yr),
                        new ChartDataModel("Remaining", leftOver)
                    };

                    CurrentViewModel.Data.Replace(dt);
                }
                else
                {
                    //calculate the percentage of costs based on the total

                    var wk  = (CurrentViewModel.WeeklyCosts / totalCosts) * 100;
                    var ft  = (CurrentViewModel.FortnightlyCosts / totalCosts) * 100;
                    var mth = (CurrentViewModel.MonthlyCosts / totalCosts) * 100;
                    var yr  = (CurrentViewModel.AnnualCosts / totalCosts) * 100;
                    dt = new ObservableCollection <ChartDataModel>
                    {
                        new ChartDataModel(FrequencyOfIncomeExpenses.Weekly.ToString(), wk),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Fortnightly.ToString(), ft),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Monthly.ToString(), mth),
                        new ChartDataModel(FrequencyOfIncomeExpenses.Annually.ToString(), yr)
                    };
                    CurrentViewModel.Data.Replace(dt);
                }



                //dt = new ObservableCollection<ChartDataModel>
                //{
                //    new ChartDataModel(FrequencyOfIncomeExpenses.Weekly.ToString(), CurrentViewModel.WeeklyCosts),
                //    new ChartDataModel(FrequencyOfIncomeExpenses.Fortnightly.ToString(), CurrentViewModel.FortnightlyCosts),
                //    new ChartDataModel(FrequencyOfIncomeExpenses.Monthly.ToString(), CurrentViewModel.MonthlyCosts),
                //    new ChartDataModel(FrequencyOfIncomeExpenses.Annually.ToString(), CurrentViewModel.AnnualCosts)
                //};

                //CurrentViewModel.Data.Replace(dt);
                //CurrentViewModel.Data
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }