public async Task <IDictionary <string, List <Expense> > > GetAsync(string planId, ExpenseFilter filter) { IGenericRepository <Plan> planRepository = _repositoryFactory.GetGenericRepository <Plan>(); Plan plan = await planRepository.GetByIdAsync(planId); ExpenseFilter expenseFilter = filter ?? new ExpenseFilter(); IEnumerable <Expense> expenses = plan.Expenses.Where(item => item.Amount > 0.0f); if (!string.IsNullOrWhiteSpace(expenseFilter.Category)) { expenses = expenses.Where(item => !string.IsNullOrWhiteSpace(item.Category) && string.Equals(item.Category.Trim().ToLower(), expenseFilter.Category.Trim().ToLower())); } if (expenseFilter.DateTo != null) { expenses = expenses.Where(item => item.Date != null && item.Date <= expenseFilter.DateTo); } if (expenseFilter.DateFrom != null) { expenses = expenses.Where(item => item.Date != null && item.Date >= expenseFilter.DateFrom); } Dictionary <string, List <Expense> > dict = expenses .GroupBy(x => x.Category, x => x) .ToDictionary(expense => expense.Key, expense => expense.ToList()); return(dict); }
public CashExpenseFilterView() { this.Build(); UoW = UnitOfWorkFactory.CreateWithoutRoot(); Filter = new ExpenseFilter(); ydateperiodPicker.Binding.AddBinding(Filter, x => x.StartDate, w => w.StartDate).InitializeFromSource(); ydateperiodPicker.Binding.AddBinding(Filter, x => x.EndDate, w => w.EndDate).InitializeFromSource(); ydateperiodPicker.PeriodChanged += (sender, e) => Refilter(); var employeeFactory = new EmployeeJournalFactory(); evmeEmployee.SetEntityAutocompleteSelectorFactory(employeeFactory.CreateWorkingEmployeeAutocompleteSelectorFactory()); evmeEmployee.Binding.AddBinding(Filter, x => x.Employee, w => w.Subject).InitializeFromSource(); evmeEmployee.ChangedByUser += (sender, e) => Refilter(); var expenseCategoryVM = new EntityCommonRepresentationModelConstructor <ExpenseCategory>(UoW) .AddColumn("Имя", x => x.Name).AddSearch(x => x.Name) .AddColumn("Тип документа", x => x.ExpenseDocumentType.GetEnumTitle()) .OrderBy(x => x.Name) .Finish(); entryExpenseCategory.RepresentationModel = expenseCategoryVM; entryExpenseCategory.Binding.AddBinding(Filter, x => x.ExpenseCategory, w => w.Subject).InitializeFromSource(); entryExpenseCategory.ChangedByUser += (sender, e) => Refilter(); }
public void FromExpenseTest() { Expense e = new Expense( 50f, DateTime.Today, "Walmart", new Card(), new HashSet <string> { "food", "hygene" }, "Bought groceries and handsoap"); ExpenseFilter f = new ExpenseFilter( name: "TestFilter", 50f, DateTime.Today, new HashSet <string> { "Walmart" }, new HashSet <string> { "food", "hygene" }); Assert.IsTrue(f.FunctionalEquals(ExpenseFilter.FromExpense("OtherFilter", e))); }
/// <summary> /// Search all the expenses that belongs to the user, which the token is tied to /// </summary> public async Task <IEnumerable <Expense> > GetExpensesAsync(ExpenseFilter filter) { var url = QueryStringUrl.GetUrl("/expense", filter.ToQueryStringDictionary()); return(await _httpClient.GetListAsync <expensereadables, expensereadablesExpense, Expense>(url, x => x.expense, Expense.FromNative)); }
/// <summary> /// Initializes a new instance of the <see cref="AddEditFilterDialog"/> class. /// Edit constructor. Constructs dialog in EditMode for existing filter. /// </summary> /// <param name="f">The expense data to edit.</param> public AddEditFilterDialog(ExpenseFilter f) { this.InitializeComponent(); this.ExpenseFilter = f; // Set title to Edit this.titleTextBox.Text = "Edit an Existing Filter"; // first disable everything. this.InitializeForm(); // Assign values to those of passed filter this.filterNameInputTextBox.Text = f.Name; this.filterNameInputTextBox.ReadOnly = true; // Cannot change the name, unique identifier. if (f.MinDate != DateTime.MinValue) { this.lowerBoundDateTimePicker.Value = f.MinDate; this.lowerBoundDateLabelButton.PerformClick(); } if (f.MaxDate != DateTime.MaxValue) { this.upperBoundDateTimePicker.Value = f.MaxDate; this.upperBoundDateLabelButton.PerformClick(); } if (f.Method != null) { // Assign purchase method. if (f.Method is Cash) { Cash c = f.Method as Cash; this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CASH; this.currencyInputComboBox.Text = c.Currency; } else if (f.Method is Card) { Card c = f.Method as Card; this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CARD; this.cardTypeInputComboBox.SelectedIndex = c.Debit ? 0 : 1; this.providerInputTextBox.Text = c.Provider; this.cardNumberMaskedTextBox.Text = c.Number.ToString(); this.cardNameInputTextBox.Text = c.Name; } else if (f.Method is DirectDeposit) { DirectDeposit d = f.Method as DirectDeposit; this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.DIRECT_DEPOSIT; this.accountTypeInputComboBox.SelectedIndex = d.Savings ? 0 : 1; this.bankNameInputTextBox.Text = d.BankName; this.accountNumberInputMaskedTextBox.Text = d.Number.ToString(); this.accountNameInputTextBox.Text = d.Name; } } if (f.MinValue != float.MinValue) { this.lowerBoundAmountInputTextBox.Text = f.MinValue.ToString(); this.lowerBoundAmountLabelButton.PerformClick(); } if (f.MaxValue != float.MaxValue) { this.upperBoundAmountInputTextBox.Text = f.MaxValue.ToString(); this.upperBoundAmountLabelButton.PerformClick(); } if (f.Place.Count > 0) { this.placesInputTextBox.Text = string.Join(", ", f.Place); this.placesLabelButton.PerformClick(); } if (f.Tag.Count > 0) { this.tagsInputTextBox.Text = string.Join(", ", f.Tag); this.tagsLabelButton.PerformClick(); } if (f.Keywords.Count > 0) { this.notesInputTextBox.Text = string.Join(", ", f.Keywords); this.keywordsLabelButton.PerformClick(); } }
private void ConfirmButton_Click(object sender, EventArgs e) { // wipe last attempt this.HideFormError(); // do data checks here. if (!this.InputsAreValid()) { return; } // if data checks pass assign all values to expense and pass back dialog ok result. string name; HashSet <string> places = new HashSet <string>(), tags = new HashSet <string>(), keywords = new HashSet <string>(); DateTime maxDate = DateTime.MaxValue, minDate = DateTime.MinValue; float maxValue = float.MaxValue, minValue = float.MinValue; PurchaseMethod p = null; name = this.filterNameInputTextBox.Text; if (this.lowerBoundDateTimePicker.Enabled) { minDate = this.lowerBoundDateTimePicker.Value; } if (this.upperBoundDateTimePicker.Enabled) { maxDate = this.upperBoundDateTimePicker.Value; } if (this.lowerBoundAmountInputTextBox.Enabled) { minValue = float.Parse(this.lowerBoundAmountInputTextBox.Text); } if (this.upperBoundAmountInputTextBox.Enabled) { maxValue = float.Parse(this.upperBoundAmountInputTextBox.Text); } if (this.placesInputTextBox.Enabled) { places = new HashSet <string>(from string place in this.placesInputTextBox.Text.Split(',') select place.Trim()); } if (this.tagsInputTextBox.Enabled) { tags = new HashSet <string>(from string tag in this.tagsInputTextBox.Text.Split(',') select tag.Trim()); } if (this.notesInputTextBox.Enabled) { keywords = new HashSet <string>(from string keyword in this.notesInputTextBox.Text.Split(',') select keyword.Trim()); } if (this.purchaseMethodSelectComboBox.Enabled) { switch ((EPurchaseMethodIndex)this.purchaseMethodSelectComboBox.SelectedIndex) { case EPurchaseMethodIndex.CASH: p = new Cash( this.currencyInputComboBox.Text); break; case EPurchaseMethodIndex.CARD: p = new Card( this.cardTypeInputComboBox.SelectedIndex == 0 ? true : false, this.providerInputTextBox.Text.Trim(), int.Parse(this.cardNumberMaskedTextBox.Text), this.cardNameInputTextBox.Text.Trim()); break; case EPurchaseMethodIndex.DIRECT_DEPOSIT: p = new DirectDeposit( this.accountTypeInputComboBox.SelectedIndex == 0 ? true : false, this.bankNameInputTextBox.Text.Trim(), int.Parse(this.accountNumberInputMaskedTextBox.Text), this.accountNameInputTextBox.Text.Trim()); break; default: Console.WriteLine("Error: unhandled purchase method passed"); throw new InvalidEnumArgumentException("Error: unhandled purchase method passed"); } } else { p = null; } if (this.ExpenseFilter == null) { this.ExpenseFilter = new ExpenseFilter( name, maxValue, minValue, maxDate, minDate, places, tags, keywords, p); } else { this.ExpenseFilter.MinValue = minValue; this.ExpenseFilter.MaxValue = maxValue; this.ExpenseFilter.MinDate = minDate; this.ExpenseFilter.MaxDate = maxDate; this.ExpenseFilter.Place = places; this.ExpenseFilter.Tag = tags; this.ExpenseFilter.Keywords = keywords; this.ExpenseFilter.Method = p; } // Set the ok result and close the form. this.DialogResult = DialogResult.OK; this.Close(); }
public static Task <IEnumerable <Expense> > GetExpensesAsync(this FreeAgentClient client, ExpenseFilter filterBy = ExpenseFilter.All, DateTime?fromDate = null, DateTime?toDate = null) { var view = filterBy.GetMemberValue(); return(client.GetOrCreateAsync(c => c.ExpenseList(client.Configuration.CurrentHeader, view, fromDate, toDate), r => r.Expenses)); }
public void UnionTest() { // case 1: Filters have no intersection. ExpenseFilter f1 = new ExpenseFilter( name: "TestFilter", 1000f, DateTime.Today.AddYears(5), new HashSet <string> { "Walmart" }, new HashSet <string> { "Groceries", "Food" }, new HashSet <string> { "ChexMix" }, new Card()); ExpenseFilter f2 = new ExpenseFilter( name: "TestFilter", -1000f, DateTime.Today.AddYears(-5), new HashSet <string> { "ToysRUs" }, new HashSet <string> { "Games" }, new HashSet <string> { "Mario" }, new Cash()); ExpenseFilter fSolution = new ExpenseFilter( name: "TestFilter", 1000f, -1000f, DateTime.Today.AddYears(5), DateTime.Today.AddYears(-5), new HashSet <string> { "Walmart", "ToysRUs" }, new HashSet <string> { "Groceries", "Games", "Food" }, new HashSet <string> { "ChexMix", "Mario" }); ExpenseFilter fUnion = ExpenseFilter.Union(f1, f2); Assert.IsTrue(fSolution.FunctionalEquals(fUnion)); // case 2: Filters have a intersection. f1 = new ExpenseFilter( name: "TestFilter", 1000f, -1000f, DateTime.Today.AddYears(5), DateTime.Today.AddYears(-5), new HashSet <string> { "Walmart" }, new HashSet <string> { "Groceries", "Food" }, new HashSet <string> { "ChexMix" }, new Card()); f2 = new ExpenseFilter( name: "TestFilter", 1500f, -500f, DateTime.Today.AddYears(7), DateTime.Today.AddYears(-2), new HashSet <string> { "ToysRUs" }, new HashSet <string> { "Games" }, new HashSet <string> { "Mario" }, new Card()); fSolution = new ExpenseFilter( name: "TestFilter", 1500f, -1000f, DateTime.Today.AddYears(7), DateTime.Today.AddYears(-5), new HashSet <string> { "Walmart", "ToysRUs" }, new HashSet <string> { "Groceries", "Games", "Food" }, new HashSet <string> { "ChexMix", "Mario" }, new Card()); fUnion = ExpenseFilter.Union(f1, f2); Assert.IsTrue(fSolution.FunctionalEquals(fUnion)); }
public void FindAllTest() { if (!this.dataAccessFactory.ExpenseTableExists) { // Create Table if it has not been created yet this.dataAccessFactory.CreateNewExpenseTable(); } // put expenses into database Expense e1 = new Expense( 50.00f, DateTime.Today, "Walmart", new Cash(), new HashSet <string> { "Food", "Hygene" }, "bought groceries and deoderant"); Expense e2 = new Expense( -150.00f, DateTime.Today.AddYears(5), "Safeway", new Card(), new HashSet <string> { "Food", "Hygene" }, "bought groceries and deoderant"); Expense e3 = new Expense( 1000.00f, DateTime.Today.AddYears(-5), "GameStop", new DirectDeposit(), new HashSet <string> { "Pay" }, "first paycheck from gamestop"); this.dataAccessFactory.InsertRecord(e1); this.dataAccessFactory.InsertRecord(e2); this.dataAccessFactory.InsertRecord(e3); // case: only one expense is returned anyways ExpenseFilter f = new ExpenseFilter( name: "TestFilter", place: new HashSet <string> { "GameStop" }); List <Expense> result = this.dataAccessFactory.FindAll(f); Assert.AreEqual(e3, result[0]); // case: nothing is returned f = new ExpenseFilter( name: "TestFilter", dateExact: DateTime.Today.AddDays(3)); result = this.dataAccessFactory.FindAll(f); Assert.AreEqual(0, result.Count); // case: multiple are returned so we need to make sure they are ordered correctly. f = new ExpenseFilter( name: "TestFilter", keywords: new HashSet <string> { "groceries" }); result = this.dataAccessFactory.FindAll(f); Assert.AreEqual(e1, result[0]); // Since both e1 and e2 match they should be sorted ascendingly by id, since e1 was inserted first it should have a lower id and thus be selected over e2 Assert.AreEqual(e2, result[1]); // Clean table of all entries for consecutive runs using (SqliteConnection db = new SqliteConnection(this.CreateConnectionString())) { db.Open(); using (SqliteCommand cmd = db.CreateCommand()) { cmd.CommandText = string.Format("DROP TABLE {0};", TABLENAME); cmd.ExecuteNonQuery(); } } }
public async Task <IActionResult> GetExpenses(string planId, [FromBody] ExpenseFilter filter) { IDictionary <string, List <Expense> > expenses = await _expenseService.GetAsync(planId, filter); return(Ok(expenses)); }