private BudgetData GetBudgetData(int budgetId, int year) { FinancialAccount account = FinancialAccount.FromIdentity(budgetId); double budget = -account.GetBudget(year); Int64 actualCents = account.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double actual = actualCents / 100.0; // Get suballocated FinancialAccounts accountTree = account.GetTree(); double budgetTotal = -accountTree.GetBudgetSum(year); Int64 deltaTotalCents = accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double deltaTotal = deltaTotalCents / 100.0; BudgetData result = new BudgetData(); result.AccountName = account.Name; if (budgetTotal > 0.0) { result.PercentActual = actual / budgetTotal * 100.0; result.PercentSuballocated = (budgetTotal - budget) / budgetTotal * 100.0; result.PercentSuballocatedUsed = (deltaTotal - actual) / budgetTotal * 100.0; } return(result); }
private BudgetData GetBudgetData (int budgetId, int year) { FinancialAccount account = FinancialAccount.FromIdentity(budgetId); double budget = -account.GetBudget(year); Int64 actualCents = account.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double actual = actualCents / 100.0; // Get suballocated FinancialAccounts accountTree = account.GetTree(); double budgetTotal = -accountTree.GetBudgetSum(year); Int64 deltaTotalCents = accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double deltaTotal = deltaTotalCents/100.0; BudgetData result = new BudgetData(); result.AccountName = account.Name; if (budgetTotal > 0.0) { result.PercentActual = actual / budgetTotal * 100.0; result.PercentSuballocated = (budgetTotal-budget)/budgetTotal*100.0; result.PercentSuballocatedUsed = (deltaTotal-actual)/budgetTotal*100.0; } return result; }
public async Task <DateTime> UploadData(BudgetData budgetData) { if (DropboxClient == null) { return(DateTime.MinValue); } DateTime cloudFileModifedDate = DateTime.MinValue; try { using (MemoryStream stream = new MemoryStream()) { Serializer.Serialize(stream, budgetData); await stream.FlushAsync(); var bytes = stream.GetBuffer(); using (var memoryStream = new MemoryStream(bytes, 0, (int)stream.Length)) { var metadata = await DropboxClient.Files.UploadAsync(DROPBOX_DATA_FILE_PATH, WriteMode.Overwrite.Instance, body : memoryStream); cloudFileModifedDate = metadata.ServerModified; onUploadFinished?.Invoke(); } } } catch (Exception exc) { var msg = exc.Message; } return(cloudFileModifedDate); }
public async Task <bool> Save(bool upload = true) { try { LogsManager.Instance.WriteLine("Save data"); ActualBudgetData = new BudgetData { Version = VERSION, TimeStamp = DateTime.Now, BudgetPlanned = new BudgetPlanned(budgetPlanned), Months = _months.Select(item => (BudgetMonth)item.Clone()).ToList(), IsSynchronized = false }; await _fileManager.Save(ActualBudgetData); if (upload) { _budgetSynchronizer.ShouldSave = true; } } catch (Exception exc) { LogsManager.Instance.WriteLine("Save data error: " + exc.InnerException != null ? exc.InnerException.Message : string.Empty); LogsManager.Instance.WriteLine(exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } return(true); }
private void UpdateOutput() { if (data == null) { municipalBudgetOutput.ShowAreas(false); municipalBudgetOutput.ShowMessage("No budget data available for " + siteBrowser.ActiveSite.Name); return; } if (budgetLayer.grids.Count == 0) { municipalBudgetOutput.ShowAreas(false); municipalBudgetOutput.ShowMessage("There are no active layers yet. Please select at least one layer in the Data Layer panel."); return; } if (budgetData == null) { budgetData = new BudgetData(budgetLayer.Grid.values, budgetLayer.Grid.valuesMask, budgetLayer.Divisors, data); } else { budgetData.Update(budgetLayer.Grid.values, budgetLayer.Grid.valuesMask, budgetLayer.Divisors, data); } municipalBudgetOutput.ShowAreas(true); municipalBudgetOutput.HideMessage(); municipalBudgetOutput.SetData(budgetData); }
private async Task SaveToFile(string filename, BudgetData saveData) { await Task.Factory.StartNew(() => { try { lock (lockFile) { var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var filePath = Path.Combine(documentsPath, filename); var fileMode = FileMode.Truncate; if (!File.Exists(filePath)) { fileMode = FileMode.CreateNew; } using (var file = new FileStream(filePath, fileMode)) { Serializer.Serialize <BudgetData>(file, saveData); } } } catch (Exception exc) { Microsoft.AppCenter.Crashes.Crashes.TrackError(exc); LogsManager.Instance.WriteLine(exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } }); }
public static void SaveBudget(BudgetData data) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/" + data.month + data.year + ".sbudget"; FileStream stream = new FileStream(path, FileMode.Create); formatter.Serialize(stream, data); stream.Close(); }
public ActionResult SaveBudget(BudgetData budgetPost) { var user = context.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); var SchemeName = PensionSetup.GetSchemeNameAsync(user.SponsorNumber); using (var conn = new ApplicationDbContext()) { var operationType = budgetPost.operationType; var budgetID = budgetPost.budgetID; var budgetName = budgetPost.budgetName; Budget budget; if (operationType == "NEW") { //SAVE try { budget = new Budget(); budget = Budgeting(budget, budgetPost); conn.Budget.Add(budget); conn.SaveChanges(); var resp = new { STATUS = "1", MESSAGE = "Member Budget has been saved successfully" }; return(Json(resp, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var resp = new { STATUS = "0", MESSAGE = "Member Budget could not be saved: " + ex.Message }; return(Json(resp, JsonRequestBehavior.AllowGet)); } } else if (operationType == "EDIT") { //UPDATE try { budget = conn.Budget.Where(b => b.Id == budgetID).FirstOrDefault(); budget = Budgeting(budget, budgetPost); conn.SaveChanges(); var resp = new { STATUS = "1", MESSAGE = "Member Budget updated successfully" }; return(Json(resp, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var resp = new { STATUS = "1", MESSAGE = "Member Budget could not be update: " + ex.Message }; return(Json(resp, JsonRequestBehavior.AllowGet)); } } else { var resp = new { STATUS = "0", MESSAGE = "Unknown Operation Type" }; return(Json(resp, JsonRequestBehavior.AllowGet)); } } }
public void SetData(BudgetData budgetData) { bool updateGUI = budgetData == null; this.budgetData = budgetData; UpdateData(); if (updateGUI) { GuiUtils.RebuildLayout(container); } }
public BudgetData GetBudgetData(DateTime dateTime) { var budgetData = new BudgetData( repository.GetBudgetCalculations("earned", dateTime), repository.GetBudgetCalculations("spend", dateTime), repository.GetBudgetCalculations("planed", dateTime), repository.GetBudgetCalculations("left", dateTime) ); return(budgetData); }
public async Task Save(BudgetData saveData) { var storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var sampleFile = await storageFolder.CreateFileAsync("budget.dat", Windows.Storage.CreationCollisionOption.ReplaceExisting); using (Stream writeStream = await sampleFile.OpenStreamForWriteAsync()) { Serializer.Serialize(writeStream, saveData); await writeStream.FlushAsync(); writeStream.Dispose(); } }
public ProductView(BudgetData data = null) { if (CurrentViewModel == null) { CurrentViewModel = new ProductViewModel(); } if (data != null) { CurrentViewModel.Data = data; } BindingContext = CurrentViewModel; InitializeComponent(); CurrentViewModel.IsBusy = true; }
// ReSharper disable InconsistentNaming protected void Page_Load(object sender, EventArgs e) // ReSharper restore InconsistentNaming { // Set the chart Type Chart.Type = ChartType.ComboHorizontal; // Turn 3D off. Chart.Use3D = false; // Change the shading mode Chart.ShadingEffectMode = ShadingEffectMode.Three; // Set a default transparency Chart.DefaultSeries.DefaultElement.Transparency = 00; // Set the x axis scale Chart.ChartArea.XAxis.Scale = Scale.Stacked; Chart.ChartArea.XAxis.Minimum = 0; Chart.ChartArea.XAxis.Label.Text = "Percent budget used"; // Set the y axis label Chart.ChartArea.YAxis.Label.Text = ""; // Set the directory where the images will be stored. Chart.TempDirectory = "temp"; // Set the chart size. Chart.Width = Int32.Parse(Request.QueryString["Width"]) - 20; Chart.Height = 80; BudgetData data = GetBudgetData(Int32.Parse(Request.QueryString["AccountId"]), Int32.Parse(Request.QueryString["Year"])); if (data.PercentActual + Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated) <= 100.0) { Chart.ChartArea.XAxis.Maximum = 100; } Chart.SeriesCollection.Add(GetBudgetDataGraphics(data)); Chart.LegendBox.Position = LegendBoxPosition.Top; Chart.LegendBox.Template = "%Icon %Name"; Chart.LegendBox.CornerSize = 0; Chart.Debug = false; Chart.Mentor = false; Chart.Background.Color = Color.FromArgb(0xFF, 0xF8, 0xE7, 0xFF); }
private void ComputeLinearRegression(IEnumerable <BudgetData> budget) { // Compute linear regression double x = 0; int count = budget.Count(); if (count == 0) { return; } List <Point> points = new List <Point>(); double sum = (from c in budget select c.Budgeted.Count).Sum(); double avg = sum / count; BudgetData first = budget.First(); BudgetData last = budget.Last(); foreach (BudgetData c in budget) { if ((c == last || c == last) && c.Budgeted.Count < (avg / 2)) { // skip the first column if we have enough data since it might be an incomplete year/month. continue; } // ignore projected columns in our calculation. if (!c.IsProjected) { points.Add(new Point(x++, (double)c.Actual)); } } double a, b; // y = a + b.x MathHelpers.LinearRegression(points, out a, out b); // create "Average" points that represent this line. x = 0; foreach (BudgetData c in budget) { double y = a + (b * x); c.Average = y; x++; } }
public async Task <BudgetData> GetActualBudget(int categoryId) { using (SqlConnection con = new SqlConnection(_connectionString)) { BudgetData budget = await con.QueryFirstOrDefaultAsync <BudgetData>( @"select BudgetId, CategoryId, Date2 = MAX(Date2), Amount from rm.tBudget WHERE BudgetId <> 0 and CategoryId = @CategoryId GROUP BY BudgetId, CategoryId, Date2, Amount ORDER BY Date2 DESC;", new { CategoryId = categoryId }); return(budget); } }
public Budget Budgeting(Budget budget, BudgetData budgetPost) { var user = context.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); var SchemeName = PensionSetup.GetSchemeNameAsync(user.SponsorNumber); budget.SchemeCode = SchemeName; budget.MemberNumber = user.MemberNumber; budget.BudgetName = budgetPost.budgetName; budget.IncomeNetTakeHome = budgetPost.netIncome; budget.IncomeSpouseNetTakeHome = budgetPost.spouseNetIncome; budget.IncomeOther = budgetPost.otherIncome; budget.HouseMorgageRentInstallments = budgetPost.mortgageRent; budget.HouseLevyWaterElectricity = budgetPost.ratesWaterElectricity; budget.HouseDstv = budgetPost.payTv; budget.HouseSecurity = budgetPost.security; budget.HouseDomesticStaff = budgetPost.staffCost; budget.HouseHomeInsurance = budgetPost.homeInsurance; budget.TransCarInstallments = budgetPost.publicTransport; budget.TransCarInsurance = budgetPost.carInsurance; budget.TransFuel = budgetPost.maintenanceFee; budget.TelHomeLine = budgetPost.homeLine; budget.TellCellPhone = budgetPost.cellularPhone; budget.TeldecimalernetSub = budgetPost.internetSubscription; budget.FinanceRetirementSavings = budgetPost.retirementSavings; budget.FinanceSavingsInvest = budgetPost.savingInvestment; budget.FinanceMedicalExpensed = budgetPost.medicalExpenses; budget.FinanceLifeAssurance = budgetPost.lifeAssurance; budget.FinancePersonalLoan = budgetPost.personalLoan; budget.FinanceCreditFund = budgetPost.creditCard; budget.EducationSchoolFees = budgetPost.schoolFees; budget.EducationUniformTextbooks = budgetPost.miscellaneousFee; budget.EducationOtherCosts = budgetPost.otherEducationCost; budget.ShoppingGroceries = budgetPost.groceries; budget.ShoppingClothing = budgetPost.clothing; budget.ShoppingAccountRepayments = budgetPost.accountRepayment; budget.ShoppingOtherCosts = budgetPost.otherShoppingCost; budget.EntertainmentSportRecreation = budgetPost.recreation; budget.EntertainmentLunches = budgetPost.diningOut; budget.EntertainmentOther = budgetPost.otherEntertainmentCost; budget.CreatedAt = DateTime.Now; return(budget); }
public static BudgetData LoadBudget(string filename) { string path = Application.persistentDataPath + "/" + filename + ".sbudget"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); BudgetData newData = formatter.Deserialize(stream) as BudgetData; stream.Close(); return(newData); } else { //Debug.LogError("File " + path + "does not exist and cannot be loaded"); return(null); } }
private void UpdateData(object sender, BudgetData data) { try { if (data == null) { LogsManager.Instance.WriteLine("Cloud UpdateData == null"); Task.Run(() => LoadAsync()); } else { lock (_updateLock) { _months.Clear(); if (data.Months != null) { _months = data.Months; foreach (var month in _months) { month.Setup(); } } if (data.BudgetPlanned != null) { budgetPlanned = data.BudgetPlanned; } } IsDataLoaded = true; BudgetDataChanged?.Invoke(true); Task.Factory.StartNew(async() => await Save(false)); } } catch (Exception exc) { LogsManager.Instance.WriteLine("SynchronizeData exception: " + exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } }
public async Task <Result <int> > CreateTransacBudget(int price, DateTime date, int categoryId, int roomieId) { BudgetData budget = await this.GetActualBudget(categoryId); int budgetId = budget.BudgetId; using (SqlConnection con = new SqlConnection(_connectionString)) { var p = new DynamicParameters(); p.Add("@Price", price); p.Add("@Date", date); p.Add("@BudgetId", budgetId); p.Add("@RoomieId", roomieId); p.Add("@TBudgetId", dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add("@Status", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); await con.ExecuteAsync("rm.sTransacBudgetCreate", p, commandType : CommandType.StoredProcedure); int status = p.Get <int>("@Status"); Debug.Assert(status == 0); return(Result.Success(Status.Created, p.Get <int>("@TBudgetId"))); } }
public BudgetData CreateBudgetData() { BudgetCatagory[] catagoriesToConvert = GetCatagories(); BudgetData budgetData = new BudgetData(); if (catagoriesToConvert != null) { foreach (BudgetCatagory catagory in catagoriesToConvert) { CatagoryData catagoryData = new CatagoryData(catagory); if (catagoryData != null) { catagoryDatas.Add(catagoryData); } else { Debug.LogError("No partdata found"); } } } else { Debug.LogError("Parts to conver is null"); } //catagoryDatas.Add(new CatagoryData()); if (catagoryDatas != null) { budgetData.catagories = catagoryDatas; } budgetData.income = System.Convert.ToDouble(budgetController.IncomeInputText.text); budgetData.month = budgetController.month; budgetData.year = budgetController.year; budgetData.notes = budgetController.NotesInputText.text; return(budgetData); }
private void LoadDataForCalender() { //Get all files at path //foreach file in folder get the month and year, if year matches selected year color the correct months based on files of that year List <Button> monthButtons = budgetController.monthButtons; foreach (Button button in monthButtons) { string loadfileString = null; string monthString = (monthButtons.IndexOf(button) + 1).ToString(); loadfileString = (monthString + budgetController.year.ToString()); BudgetData data = SaveLoadBudgetDatas.LoadBudget(loadfileString); if (data != null) { double actualExpences = 0; foreach (CatagoryData catData in data.catagories) { actualExpences += catData.actualExpenses; } if (actualExpences <= data.income) { button.image.color = budgetController.lowCalculationColor; } if (actualExpences > data.income) { button.image.color = budgetController.highCalculationColor; } } else { button.image.color = budgetController.defaultColor; } } }
void LineChart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DependencyObject d = e.OriginalSource as DependencyObject; if (e == null) { return; } while (d != null) { FrameworkElement f = d as FrameworkElement; if (f != null && f.DataContext != null) { BudgetData data = f.DataContext as BudgetData; if (data != null) { Selection = data; return; } } d = VisualTreeHelper.GetParent(d); } }
public async Task CheckLocalData() { try { //add new object for testing var kt = new BudgetData() { ProductName = "Test Product _" + DateTime.Now.ToString("F"), StoreOne = "Pak n Save", IsValid = true, FlagForFutureUse = true, Description = "Test Description.." }; await App.DataTable.InsertAsync(kt); // } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public void Compare() { if (rowLeftItem != null && rowRightItem != null) { System.Console.WriteLine("RESULT:" + rowRightItem.ItemName + rowLeftItem.ItemName); //GetComparisonResult(rowLeftItem.ItemValue, rowRightItem.BudgetValue, rowLeftItem.SelectionType); CurrentComparisonText = BudgetData .PreMadeComparsionResults[(rowLeftActiveIndex * BudgetData.GetCurrentComparedToSection() .ProposedItems.Count) + rowRightActiveIndex]; StateHasChanged(); } }
private SeriesCollection GetBudgetDataGraphics (BudgetData data) { // TODO: Add sub-accounts from tree SeriesCollection collection = new SeriesCollection(); Element element; if (data.PercentSuballocated > 0.0) { double subAllocatedFirstBar = Math.Min(data.PercentSuballocated, data.PercentSuballocatedUsed); Series seriesSuballocatedUsed = new Series(); element = new Element(); element.YValue = subAllocatedFirstBar; element.Color = Color.DarkBlue; element.Name = data.AccountName; seriesSuballocatedUsed.Name = "Suballocated Used"; seriesSuballocatedUsed.Elements.Add(element); collection.Add(seriesSuballocatedUsed); if (data.PercentSuballocated < data.PercentSuballocatedUsed) { // overrun Series seriesSuballocatedOverrun = new Series(); element = new Element(); element.YValue = data.PercentSuballocatedUsed - data.PercentSuballocated; element.Color = Color.DarkViolet; element.Name = data.AccountName; seriesSuballocatedOverrun.Name = "Suballocated Overrun"; seriesSuballocatedOverrun.Elements.Add(element); collection.Add(seriesSuballocatedOverrun); } else if (data.PercentSuballocatedUsed < data.PercentSuballocated) { // overrun Series seriesSuballocatedUnused = new Series(); element = new Element(); element.YValue = data.PercentSuballocated - data.PercentSuballocatedUsed; element.Color = Color.LightSkyBlue; element.Name = data.AccountName; seriesSuballocatedUnused.Name = "Suballocated Unused"; seriesSuballocatedUnused.Elements.Add(element); collection.Add(seriesSuballocatedUnused); } } if (data.PercentActual > 0.0) { Series seriesUsed = new Series(); element = new Element(); if (data.PercentActual + Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated) > 100.0) { element.YValue = 100.0 - (Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated)); } else { element.YValue = data.PercentActual; } element.Color = Color.DarkOrange; element.Name = data.AccountName; if (element.YValue > 0.0) { seriesUsed.Name = "Used"; seriesUsed.Elements.Add(element); collection.Add(seriesUsed); } } if (data.PercentActual + Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated) > 100.0 && data.PercentActual > 0.0) { Series seriesOverrun = new Series(); element = new Element(); if (Math.Max(data.PercentSuballocated,data.PercentSuballocatedUsed) > 100.0) { element.YValue = data.PercentActual; } else { element.YValue = (data.PercentActual + Math.Max(data.PercentSuballocated, data.PercentSuballocatedUsed) - 100.0); // 10 100 130 should be 10; 10 98 95 should be 8 } element.Color = Color.Red; element.Name = data.AccountName; seriesOverrun.Name = "Overrun"; seriesOverrun.Elements.Add(element); collection.Add(seriesOverrun); } return collection; }
public async Task <IActionResult> GetCurrentBudget(int categoryId) { BudgetData currentBudget = await _budgetGateway.GetCurrentBudget(categoryId); return(Ok(currentBudget)); }
public void SaveBudget() { BudgetData data = CreateBudgetData(); SaveLoadBudgetDatas.SaveBudget(data); }
private SeriesCollection GetBudgetDataGraphics(BudgetData data) { // TODO: Add sub-accounts from tree SeriesCollection collection = new SeriesCollection(); Element element; if (data.PercentSuballocated > 0.0) { double subAllocatedFirstBar = Math.Min(data.PercentSuballocated, data.PercentSuballocatedUsed); Series seriesSuballocatedUsed = new Series(); element = new Element(); element.YValue = subAllocatedFirstBar; element.Color = Color.DarkBlue; element.Name = data.AccountName; seriesSuballocatedUsed.Name = "Suballocated Used"; seriesSuballocatedUsed.Elements.Add(element); collection.Add(seriesSuballocatedUsed); if (data.PercentSuballocated < data.PercentSuballocatedUsed) { // overrun Series seriesSuballocatedOverrun = new Series(); element = new Element(); element.YValue = data.PercentSuballocatedUsed - data.PercentSuballocated; element.Color = Color.DarkViolet; element.Name = data.AccountName; seriesSuballocatedOverrun.Name = "Suballocated Overrun"; seriesSuballocatedOverrun.Elements.Add(element); collection.Add(seriesSuballocatedOverrun); } else if (data.PercentSuballocatedUsed < data.PercentSuballocated) { // overrun Series seriesSuballocatedUnused = new Series(); element = new Element(); element.YValue = data.PercentSuballocated - data.PercentSuballocatedUsed; element.Color = Color.LightSkyBlue; element.Name = data.AccountName; seriesSuballocatedUnused.Name = "Suballocated Unused"; seriesSuballocatedUnused.Elements.Add(element); collection.Add(seriesSuballocatedUnused); } } if (data.PercentActual > 0.0) { Series seriesUsed = new Series(); element = new Element(); if (data.PercentActual + Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated) > 100.0) { element.YValue = 100.0 - (Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated)); } else { element.YValue = data.PercentActual; } element.Color = Color.DarkOrange; element.Name = data.AccountName; if (element.YValue > 0.0) { seriesUsed.Name = "Used"; seriesUsed.Elements.Add(element); collection.Add(seriesUsed); } } if (data.PercentActual + Math.Max(data.PercentSuballocatedUsed, data.PercentSuballocated) > 100.0 && data.PercentActual > 0.0) { Series seriesOverrun = new Series(); element = new Element(); if (Math.Max(data.PercentSuballocated, data.PercentSuballocatedUsed) > 100.0) { element.YValue = data.PercentActual; } else { element.YValue = (data.PercentActual + Math.Max(data.PercentSuballocated, data.PercentSuballocatedUsed) - 100.0); // 10 100 130 should be 10; 10 98 95 should be 8 } element.Color = Color.Red; element.Name = data.AccountName; seriesOverrun.Name = "Overrun"; seriesOverrun.Elements.Add(element); collection.Add(seriesOverrun); } return(collection); }
public Task Save(BudgetData saveData) { return(SaveToFile(BudgetFilename, saveData)); }
private void OnDataDownloaded(object sender, BudgetData data) { DataDownloaded.Invoke(this, data); }
public void UpdateChart() { if (this.MyMoney == null || !this.IsVisible) { return; } BudgetReport report = new BudgetReport(null, this.money); ObservableCollection <BudgetData> list = new ObservableCollection <BudgetData>(); if (CategoryFilter == null) { Dictionary <string, BudgetData> totals = new Dictionary <string, BudgetData>(); decimal sum = 0; // for new average // then we need to do all categories and compute the totals. foreach (Category rc in money.Categories.GetRootCategories()) { if (rc.Type != CategoryType.Expense) { continue; } report.CategoryFilter = rc; foreach (BudgetData b in report.Compute()) { BudgetData total = null; if (!totals.TryGetValue(b.Name, out total)) { totals[b.Name] = b; } else { total.Merge(b); sum += (decimal)b.Average; } } } if (totals.Count > 0) { decimal average = sum / totals.Count; foreach (BudgetData data in totals.Values) { data.Average = (double)average; } } ComputeLinearRegression(totals.Values); list = new ObservableCollection <BudgetData>(from b in totals.Values orderby b.BudgetDate ascending select b); } else { report.CategoryFilter = this.CategoryFilter; IEnumerable <BudgetData> result = report.Compute(); ComputeLinearRegression(result); // Now update the observable collection. list = new ObservableCollection <BudgetData>(from b in result orderby b.BudgetDate ascending select b); } // compute cumulative totals. double budgetTotal = 0; double actualTotal = 0; foreach (BudgetData d in list) { budgetTotal += d.Budget; actualTotal += d.Actual; d.BudgetCumulative = budgetTotal; d.ActualCumulative = actualTotal; } try { BudgetSeries.ItemsSource = list; ActualSeries.ItemsSource = list; AverageSeries.ItemsSource = list; BudgetCumulativeSeries.ItemsSource = list; ActualCumulativeSeries.ItemsSource = list; LineChart.InvalidateArrange(); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } }
public void LoadBudget(int month) { //clear existing data foreach (BudgetCatagory catagory in budgetController.budgetCatagories) { Destroy(catagory.transform.gameObject); } budgetController.budgetCatagories.Clear(); budgetController.IncomeInputText.text = ""; budgetController.NotesInputText.text = ""; budgetController.actualExpenseCalculationText.text = ""; budgetController.actualExpenseCalculationText.color = budgetController.defaultTextColor; budgetController.savingsCalculationText.text = ""; budgetController.savingsCalculationText.color = budgetController.defaultTextColor; budgetController.plannedExpenseCalculationText.text = ""; budgetController.plannedExpenseCalculationText.color = budgetController.defaultTextColor; string loadfileString = null; string monthString = month.ToString(); loadfileString = (monthString + budgetController.year.ToString()); BudgetData data = SaveLoadBudgetDatas.LoadBudget(loadfileString); if (data != null) { ClearBudget(); budgetController.month = data.month; budgetController.year = data.year; budgetController.IncomeInputText.text = System.Convert.ToString(data.income); //load notes budgetController.NotesInputText.text = data.notes; //create catagories from data foreach (CatagoryData catagoryData in data.catagories) { GameObject catagoryOBJ = budgetController.AddCatagory(); BudgetCatagory catagory = catagoryOBJ.GetComponent <BudgetCatagory>(); catagory.catagoryNameInput.text = catagoryData.catagoryName; catagory.catagoryPlannedExpense.text = catagoryData.plannedExpense.ToString(); catagory.plannedExpense = catagoryData.plannedExpense; catagory.catagoryActualExpense.text = catagoryData.actualExpenses.ToString(); catagory.actualExpense = catagoryData.actualExpenses; } } else { ClearBudget(); } }