//Fix for Drawer Change public void RemoveTransaction(Transaction transaction, string splitString) { if (transaction.Value > 0m) { char[] separators = { '(', ')' }; splitString = splitString.Replace(")", ""); string[] binGoalStrs = splitString.Split(separators); string[] temp = binGoalStrs[0].Split('-'); decimal value = Math.Round(transaction.Value * Convert.ToDecimal(temp[1])); decimal BinAmount = value; int goalID; decimal goalPerc; int index; decimal valTemp; if (String.Compare("", binGoalStrs[1]) != 0) { binGoalStrs[1] = binGoalStrs[1].Remove(0, 1); string[] goalStrs = binGoalStrs[1].Split('|'); for (int i = 0; i < goalStrs.Count(); ++i) { temp = goalStrs[i].Split('-'); goalID = Convert.ToInt32(temp[0]); goalPerc = Convert.ToDecimal(temp[1]); valTemp = Math.Round(value * goalPerc, 2); index = Goals.IndexOf(Goals.Where(x => x.ID == goalID).FirstOrDefault()); Goals[index].Value -= valTemp; BinAmount -= valTemp; } } Balance -= BinAmount; } else { if (transaction.DrawerExp) { Balance -= transaction.Value; int index = CurrDrawers.IndexOf(CurrDrawers.Where(x => x.ID == transaction.DrawerGoalID && x.Month == transaction.Date.Month && x.Year == transaction.Date.Year).FirstOrDefault()); if (index != -1) { CurrDrawers[index].RemoveExpense(transaction); } } else { int index = Goals.IndexOf(Goals.Where(x => x.ID == transaction.DrawerGoalID).FirstOrDefault()); if (index != -1) { Goals[index].RemoveExpense(transaction); } else { Balance -= transaction.Value; } } } }
//Fix for Drawer Change public void RemoveDrawer(string name, int year, int month) { int index = CurrDrawers.IndexOf(CurrDrawers.Where(x => string.Compare(x.Name, name) == 0 && x.Year == year && x.Month == month).FirstOrDefault()); if (index != -1) { Account.DeleteDrawer(CurrDrawers[index]); CurrDrawers.RemoveAt(index); } }
/* public void AddDrawerExpense(Expense exp) * { * Balance -= exp.Value; * int index = Drawers.IndexOf(Drawers.Where(x => string.Compare(x.Name, exp.Drawer) == 0).FirstOrDefault()); * if (index != -1) * { * Drawers[index].AddExpense(exp); * } * if(Balance < 0) * { * PullfromGoals(); * } * } * * public void AddGoalExpense(Expense exp) * { * int index = Goals.IndexOf(Goals.Where(x => string.Compare(x.Name, exp.Drawer) == 0).FirstOrDefault()); * if (index != -1) * { * Goals[index].AddExpense(exp); * } else * { * Balance -= exp.Value; * } * } * * public void RemoveDrawerExpense(Expense exp) * { * Balance += exp.Value; * int index = Drawers.IndexOf(Drawers.Where(x => string.Compare(x.Name, exp.Drawer) == 0).FirstOrDefault()); * if (index != -1) * { * Drawers[index].RemoveExpense(exp); * } * } * * public void RemoveGoalExpense(Expense exp) * { * * int index = Goals.IndexOf(Goals.Where(x => string.Compare(x.Name, exp.Drawer) == 0).FirstOrDefault()); * if (index != -1) * { * Goals[index].RemoveExpense(exp); * } else * { * Balance += exp.Value; * } * } */ //Fix for Drawer Change public string AddTransaction(Transaction transaction) { decimal value = 0; if (transaction.IncomeSplit) { value = Math.Round(transaction.Value * _percentage, 2); } else { value = transaction.Value; } if (value > 0m) { decimal totalAmount = 0; StringBuilder str = new StringBuilder(); Tuple <int[], decimal[], decimal[]> goalAndPerc = AddToGoals(value); str.Append("_" + ID + "-" + _percentage + "("); for (int i = 0; i < Goals.Count; ++i) { if (goalAndPerc.Item2[i] != 0) { str.Append("|" + goalAndPerc.Item1[i] + "-" + goalAndPerc.Item2[i]); totalAmount += goalAndPerc.Item3[i]; } } str.Append(")"); Balance += value - totalAmount; return(str.ToString()); } else { if (transaction.DrawerExp) { Balance += transaction.Value; int index = CurrDrawers.IndexOf(CurrDrawers.Where(x => String.Compare(x.Name, transaction.DrawerGoal) == 0 && x.Month == transaction.Date.Month && x.Year == transaction.Date.Year).FirstOrDefault()); if (index != -1) { CurrDrawers[index].AddExpense(transaction); transaction.DrawerGoalID = CurrDrawers[index].ID; } } else { int index = Goals.IndexOf(Goals.Where(x => String.Compare(x.Name, transaction.DrawerGoal) == 0).FirstOrDefault()); if (index != -1) { Goals[index].AddExpense(transaction); transaction.DrawerGoalID = Goals[index].ID; } else { Balance += transaction.Value; } } } return("_" + ID + "-" + Percentage + "()"); }