public RemoteBudgetItem(string id, BudgetItemType type, string label, int amountBudgeted)
 {
     Id             = id;
     Type           = type;
     Label          = label;
     AmountBudgeted = amountBudgeted;
 }
        public async Task <BudgetItemViewModel> GetBudgetItemVM(int itemId, BudgetItemType itemType)
        {
            BudgetItemViewModel vm = new BudgetItemViewModel(this.dbFilePath);
            await vm.LoadVMAsync(itemId, itemType);

            return(vm);
        }
예제 #3
0
        //Method for getting the right Sql command according to the user selected budget item(general expense, debt saving)
        private MySqlCommand getCorrectSqlCommand(BudgetItemType itemType, String startDate, String endDate)
        {
            MySqlCommand getTotalItemValueCommand = null;
            QueryData    paramContainer           = new QueryData.Builder(userID).addStartDate(startDate).addEndDate(endDate).build();

            switch (itemType)
            {
            //CHANGE(FROM EXPENSE TO GENERAL EXPENSE)!!!
            case BudgetItemType.GENERAL_EXPENSE:
                getTotalItemValueCommand = SQLCommandBuilder.getMultipleMonthsCommand(sqlStatementGetTotalExpenses, paramContainer);
                break;

            case BudgetItemType.DEBT:
                getTotalItemValueCommand = SQLCommandBuilder.getMultipleMonthsCommand(sqlStatementGetTotalDebts, paramContainer);
                break;

            case BudgetItemType.SAVING:
                getTotalItemValueCommand = SQLCommandBuilder.getMultipleMonthsCommand(sqlStatementGetTotalSavings, paramContainer);
                break;

            default:
                break;
            }

            return(getTotalItemValueCommand);
        }
예제 #4
0
        public int getPercentageLimitForItem(BudgetItemType itemType)
        {
            //Gets the budget plan data
            DataTable budgetPlanDataTable = getBudgetPlanData();

            //Sets the default value for the percentage limit
            int percentageLimit = 1;

            //Checks if the specified item type is a general expense, debt or saving and sets the percentage limit accordingly (if the percentage limit retrieved from the DB is null the default value of 1 is set)
            switch (itemType)
            {
            //CHANGE(FROM EXPENSE TO GENERAL EXPENSE)!!!
            case BudgetItemType.GENERAL_EXPENSE:
                percentageLimit = budgetPlanDataTable.Rows[0].ItemArray[1] != DBNull.Value ? Convert.ToInt32(budgetPlanDataTable.Rows[0].ItemArray[1]) : 1;
                break;

            case BudgetItemType.DEBT:
                percentageLimit = budgetPlanDataTable.Rows[0].ItemArray[2] != DBNull.Value ? Convert.ToInt32(budgetPlanDataTable.Rows[0].ItemArray[2]) : 1;
                break;

            case BudgetItemType.SAVING:
                percentageLimit = budgetPlanDataTable.Rows[0].ItemArray[3] != DBNull.Value ? Convert.ToInt32(budgetPlanDataTable.Rows[0].ItemArray[3]) : 1;
                break;

            default:
                break;
            }

            return(percentageLimit);
        }
예제 #5
0
        //Method that gets the total value of the selected element for the specified month
        private int getTotalValueForSelectedElement(BudgetItemType itemType, String sqlStatement, QueryData paramContainer)
        {
            int totalValue = 0;

            //Getting the correct SQL comand for the selected element
            MySqlCommand command = getCommand(itemType, sqlStatement, paramContainer);

            if (command == null)
            {
                return(-1);
            }

            //Getting the data based on the previously created command
            DataTable resultDataTable = DBConnectionManager.getData(command);

            //Checking if the DataTable contains data and if so converting the value to int
            if (resultDataTable != null && resultDataTable.Rows.Count == 1)
            {
                Object result = resultDataTable.Rows[0].ItemArray[0];
                totalValue = result != DBNull.Value ? Convert.ToInt32(result) : 0;

                return(totalValue);
            }

            return(-1);
        }
예제 #6
0
        private String getSelectedTableName(ComboBox comboBox)
        {
            if (comboBox == null)
            {
                return("");
            }

            BudgetItemType itemType = getSelectedBudgetItemType(comboBox);

            switch (itemType)
            {
            case BudgetItemType.INCOME:
                return("Incomes");

            case BudgetItemType.GENERAL_EXPENSE:
                return("General expenses");

            case BudgetItemType.SAVING_ACCOUNT_EXPENSE:
                return("Saving accounts expenses");

            case BudgetItemType.DEBT:
                return("Debts");

            case BudgetItemType.SAVING:
                return("Savings");

            case BudgetItemType.UNDEFINED:
                return("");

            default:
                return("");
            }
        }
        public async Task <ActionResult <BudgetItemType> > Put(int id, [FromBody] BudgetItemType model)
        {
            if (model is null)
            {
                return(BadRequestProblem(ModelIsRequiredMessage));
            }
            if (id == 0)
            {
                return(BadRequestProblem(RequestIdMustNotBeCeroMessage));
            }
            if (id != model.Id)
            {
                return(BadRequestProblem(RequestIdAndModelIdDontMatchMessage));
            }

            var entity = await _services.FindByIdAsync(id);

            if (entity is null)
            {
                return(NotFound());
            }

            UpdateEntity(model, entity);

            var result = await _services.UpdateAsync(entity);

            if (!result.IsValid)
            {
                return(ValidationErrorsProblem(result));
            }

            return(Ok(entity));
        }
예제 #8
0
        ////Method for retrieving the record date from the specified row of the DataGridView
        //private DateTime getDateFromRow(int rowIndex, int columnIndex) {
        //    if(dataGridViewTableDisplay == null || dataGridViewTableDisplay.Rows.Count < rowIndex || rowIndex == -1) {
        //        return DateTime.MinValue;
        //    }

        //    if (dataGridViewTableDisplay.Columns.Count - 1 < columnIndex || columnIndex == -1) {
        //        return DateTime.MinValue;
        //    }

        //    DataRow specifiedRow = ((DataTable)dataGridViewTableDisplay.DataSource).Rows[rowIndex];
        //    object rowDateObject = specifiedRow.ItemArray[columnIndex];
        //    DateTime rowDateValue = rowDateObject != DBNull.Value ? DateTime.Parse(Convert.ToString(rowDateObject)) : DateTime.MinValue;

        //    return rowDateValue;
        //}

        ////Method for retrieving the record value from the specified row of the DataGridView
        //private int getValueFromRow(int rowIndex, int columnIndex) {
        //    if (dataGridViewTableDisplay == null || dataGridViewTableDisplay.Rows.Count - 1 < rowIndex || rowIndex == -1) {
        //        return -1;
        //    }

        //    if (dataGridViewTableDisplay.Columns.Count - 1 < columnIndex || columnIndex == -1) {
        //        return -1;
        //    }

        //    DataRow specifiedRow = ((DataTable)dataGridViewTableDisplay.DataSource).Rows[rowIndex];
        //    object rowDateObject = specifiedRow.ItemArray[columnIndex];
        //    int recordValue = rowDateObject != DBNull.Value ? Convert.ToInt32(rowDateObject) : -1;

        //    return recordValue;

        //}

        //Method for retrieving the correct data column index for saving account expense/savings
        private int[] getColumnIndexList()
        {
            int[] columnIndexList = new int[2];

            int expectedValueColumnIndex = -1;
            int expectedDateColumnIndex  = -1;
            //The actual values for the expected column indexes are set based on the selected budget item type(because the layout of the displayed DataGridView for each of them is different)
            BudgetItemType selectedItemType = getSelectedBudgetItemType();

            if (selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE)
            {
                expectedValueColumnIndex = 3;
                expectedDateColumnIndex  = 4;
            }
            else if (selectedItemType == BudgetItemType.SAVING)
            {
                expectedValueColumnIndex = 2;
                expectedDateColumnIndex  = 3;
            }

            columnIndexList[0] = expectedValueColumnIndex;
            columnIndexList[1] = expectedDateColumnIndex;

            return(columnIndexList);
        }
 private void UpdateEntity(BudgetItemType model, BudgetItemType entity)
 {
     entity.BudgetClass = model.BudgetClass;
     entity.RowVersion  = model.RowVersion;
     entity.Name        = model.Name;
     entity.Notes       = model.Notes;
     entity.Order       = model.Order;
 }
예제 #10
0
        public void MapFromDomainEntity_NullContent_ReturnNull()
        {
            //Act
            var response = BudgetItemType.MapFromDomainEntity(null);

            //Assert
            Assert.IsNull(response);
        }
예제 #11
0
        public async Task <OperationResult> RemoveAsync(BudgetItemType entity)
        {
            _repository.Delete(entity);

            await _repository.SaveChangesAsync();

            return(SuccessfulOperation());
        }
예제 #12
0
        public static BudgetItemType CopyValuesFrom(this BudgetItemType target, BudgetItemType source)
        {
            target.Name        = source.Name;
            target.Order       = source.Order;
            target.BudgetClass = source.BudgetClass;
            target.Notes       = source.Notes;

            return(target);
        }
예제 #13
0
 public BudgetItem(string id,
                   string name,
                   decimal amount      = 0m,
                   BudgetItemType type = BudgetItemType.Expense)
 {
     Id     = id;
     Name   = name;
     Amount = amount;
     Type   = type;
 }
예제 #14
0
        public BudgetGroup(
            string name,
            BudgetItemType defaultItemType = BudgetItemType.Expense,
            List <BudgetItem> budgetItems  = null)
        {
            Name            = name;
            DefaultItemType = defaultItemType;

            BudgetItems.CollectionChanged += BudgetItemCollectionChanged;

            // Add any passed in budget items
            budgetItems?.ForEach(item => BudgetItems.Add(item));
        }
예제 #15
0
        public void Constructor_ValidProperty_ExpectAssignment()
        {
            string         name   = "test name";
            decimal        amount = 123.45m;
            BudgetItemType type   = BudgetItemType.Expense;

            BudgetItem budgetItem = new BudgetItem(name, type, amount);

            budgetItem.Should().NotBeNull();
            budgetItem.Name.Should().Be(name);
            budgetItem.Amount.Should().Be(amount);
            budgetItem.Type.Should().Be(type);
        }
예제 #16
0
        public BudgetGroup(string id,
                           string name,
                           BudgetItemType defaultItemType = BudgetItemType.Expense,
                           List <BudgetItem> budgetItems  = null)
        {
            Id              = id;
            Name            = name;
            DefaultItemType = defaultItemType;

            BudgetItems.CollectionChanged += BudgetItemCollectionChanged;

            budgetItems?.ForEach(item => BudgetItems.Add(item));
        }
예제 #17
0
        public static BudgetItemTypeDTO MapFromDatabaseEntity(BudgetItemType budgetItemType)
        {
            if (budgetItemType == null)
            {
                return(null);
            }

            return(new BudgetItemTypeDTO()
            {
                Id = budgetItemType.Id,
                Value = budgetItemType.Value,
                Position = budgetItemType.Position
            });
        }
예제 #18
0
        //Saving the new values of value and date columns when the saving account expenses data is shown in the DataGridView and one of these cells' content is modified
        private void dataGridViewTableDisplay_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            BudgetItemType selectedItemType = getSelectedBudgetItemType();

            if (selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE || selectedItemType == BudgetItemType.SAVING)
            {
                //Retrieving the column index of the modified cell(the new values are saved only if changes are performed to the value or date columns)
                int changedCellColumn = e.ColumnIndex;

                object changedCellValue = null;
                //CHANGE
                if ((selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE && changedCellColumn == 3) || (selectedItemType == BudgetItemType.SAVING && changedCellColumn == 2))
                {
                    changedCellValue      = dataGridViewTableDisplay.CurrentCell.Value;
                    newRecordValue        = changedCellValue != DBNull.Value ? Convert.ToInt32(changedCellValue) : -1;
                    hasChangedRecordValue = true;

                    changedRowIndex = dataGridViewTableDisplay.CurrentCell.RowIndex;
                    //CHANGE
                }
                else if ((selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE && changedCellColumn == 4) || (selectedItemType == BudgetItemType.SAVING && changedCellColumn == 3))
                {
                    changedCellValue     = dataGridViewTableDisplay.CurrentCell.Value;
                    newRecordDate        = changedCellValue != DBNull.Value ? DateTime.Parse(Convert.ToString(changedCellValue)) : DateTime.MinValue;
                    hasChangedRecordDate = true;

                    changedRowIndex = dataGridViewTableDisplay.CurrentCell.RowIndex;
                }

                //setRowsEditableProperty(dataGridViewTableDisplay, true, e.RowIndex);//Makes all the rows of the DataGridView non-editable except for the one containing the changed values
                //CHANGE-DGW MANAGEMENT
                gridViewManager.setRowsReadOnlyProperty(true, e.RowIndex);
            }

            DateTime temp;

            if ((monthRecordsCheckBox.Checked == true || yearRecordsCheckBox.Checked == true))
            {
                if (hasChangedRecordValue && newRecordValue <= 0)
                {
                    return;
                }
                else if (hasChangedRecordDate && !DateTime.TryParse(newRecordDate.ToString(), out temp))
                {
                    return;
                }

                submitButton.Enabled = true;
            }
        }
        internal async Task LoadVMAsync(int itemId, BudgetItemType itemType)
        {
            switch (itemType)
            {
            case BudgetItemType.Income:
                await LoadIncomeItemAsync(itemId);

                break;

            case BudgetItemType.Expense:
                await LoadExpenseItemAsync(itemId);

                break;
            }
        }
예제 #20
0
        public async Task <OperationResult <BudgetItemType> > UpdateAsync(BudgetItemType entity)
        {
            var result = await SaveValidator.ValidateAsync(entity);

            if (!result.IsValid)
            {
                return(FailedOperation(result));
            }

            _repository.Update(entity);

            await _repository.SaveChangesAsync();

            return(SuccessfulOperation(entity));
        }
예제 #21
0
        public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity()
        {
            //Arrange
            var budgetItemType = new BudgetItemType()
            {
                Id       = Guid.NewGuid(),
                Value    = "Original Order",
                Position = 0
            };
            var response = BudgetItemTypeDTO.MapFromDatabaseEntity(budgetItemType);

            Assert.IsNotNull(response);
            Assert.AreEqual(budgetItemType.Id, response.Id);
            Assert.AreEqual(budgetItemType.Value, response.Value);
            Assert.AreEqual(budgetItemType.Position, response.Position);
        }
        private static void SeedBudgetItemTypes(CapRedV2Context context)
        {
            if (context.BudgetItemTypes.Any())
            {
                return;
            }
            string[] budgetItemTypes = { "Original Order", "Pending Forecast", "Pending Change", "Change Order", "Budget Item" };

            for (int i = 0; i < budgetItemTypes.Length; i++)
            {
                var budgetItemType = new BudgetItemType {
                    Id = Guid.NewGuid(), Position = i, Value = budgetItemTypes[i]
                };
                context.BudgetItemTypes.Add(budgetItemType);
            }
        }
예제 #23
0
        public void Constructor_ValidParams_ExpectAssignment()
        {
            string            name        = "test group name";
            BudgetItemType    defaultType = BudgetItemType.Expense;
            List <BudgetItem> items       = new List <BudgetItem>()
            {
                new BudgetItem("test item 1"),
                new BudgetItem("test item 2", BudgetItemType.Debt, 12.34m)
            };

            var group = new BudgetGroup(name, defaultType, items);

            group.DefaultItemType.Should().Be(defaultType);
            group.Name.Should().Be(name);
            group.BudgetItems.Should().BeEquivalentTo(items);
            group.TotalAmount.Should().Be(items.Sum(x => x.Amount));
        }
예제 #24
0
        public async Task CreateBudgetItem(string budgetId, string groupId, BudgetItemType type, string label, decimal amount)
        {
            restClient.Timeout = -1;
            var request = new RestRequest($"budget/budgets/{budgetId}/items", Method.POST);

            request.AddHeader("Authorization", $"Bearer {accessControlManager.Jwt}");
            request.AddHeader("Cache-Control", "no-cache");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("type", type.ToString());
            request.AddParameter("label", label);
            request.AddParameter("amount", (int)(amount * 100));
            request.AddParameter("budget_group_id", $"urn:everydollar:budget:{budgetId}:group:{groupId}");
            IRestResponse response = await restClient.ExecuteAsync(request);

            if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Created)
            {
                throw new Exception($"Unexpected response from DeleteBudgetItem call: {response.StatusCode} - {response.Content}");
            }
        }
예제 #25
0
        //Method for retrieving the total value for the item that the user wants to insert into the DB(for the period between the start and end date of the budget plan)
        public int getTotalValueForSelectedItem(BudgetItemType itemType, String startDate, String endDate)
        {
            MySqlCommand getSelectedItemTotalValueCommand = getCorrectSqlCommand(itemType, startDate, endDate);

            if (getSelectedItemTotalValueCommand == null)
            {
                return(-1);
            }

            DataTable itemTotalValueDataTable = DBConnectionManager.getData(getSelectedItemTotalValueCommand);

            if (itemTotalValueDataTable != null && itemTotalValueDataTable.Rows.Count == 1)
            {
                int totalItemValue = itemTotalValueDataTable.Rows[0].ItemArray[0] != DBNull.Value ? Convert.ToInt32(itemTotalValueDataTable.Rows[0].ItemArray[0]) : 0;

                return(totalItemValue);
            }

            return(-1);
        }
        public async Task <ActionResult <BudgetItemType> > Post([FromBody] BudgetItemType model)
        {
            if (model is null)
            {
                return(BadRequestProblem(ModelIsRequiredMessage));
            }
            if (model.Id != 0)
            {
                return(BadRequestProblem(ModelIdMustBeCeroMessage));
            }

            var result = await _services.AddAsync(model);

            if (!result.IsValid)
            {
                return(ValidationErrorsProblem(result));
            }

            return(Ok(model));
        }
예제 #27
0
        //Method for checking if adding the user input value to the total value of the selected item would result in exceeding the imposed limit
        public bool exceedsItemLimitValue(int userInputValue, int limitValue, BudgetItemType itemType, String startDate, String endDate)
        {
            //Converts the date strings into the format required by the MySqL database
            String sqlFormatStartDate = DateTime.Parse(startDate).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
            String sqlFormatEndDate   = DateTime.Parse(endDate).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);

            //Creates the command that will retrieve the the total value of the item (expense debt, saving) up to the current date
            MySqlCommand totalItemValueCommand   = getCorrectSqlCommand(itemType, sqlFormatStartDate, sqlFormatEndDate);
            DataTable    totalItemValueDataTable = DBConnectionManager.getData(totalItemValueCommand);

            //The default value for the total item value is set to 0 so that it does not affect the calculations in case there are no expense record for the current time interval
            int totalItemValue = 0;

            if (totalItemValueDataTable != null && totalItemValueDataTable.Rows.Count == 1)
            {
                totalItemValue = totalItemValueDataTable.Rows[0].ItemArray[0] != DBNull.Value ? Convert.ToInt32(totalItemValueDataTable.Rows[0].ItemArray[0]) : 0;
            }

            return(totalItemValue + userInputValue > limitValue);
        }
        public async Task CreateBudgetItem_ExpectSuccess()
        {
            var remoteBudgetCalls = new RemoteBudgetCalls(accessControlManager, restClient);
            await remoteBudgetCalls.CreateNewBudget();

            var budget = await remoteBudgetCalls.GetCurrentBudget();

            decimal        amount = 234.56m;
            string         label  = "totally unit testing";
            BudgetItemType type   = BudgetItemType.Income;
            await remoteBudgetCalls.CreateBudgetItem(budget.Id, budget.BudgetGroups[0].Id, type, label, amount);

            var updateBudget = await remoteBudgetCalls.GetCurrentBudget();

            var addedItem = updateBudget.BudgetGroups[0].BudgetItems.Where(i => i.Label == label).FirstOrDefault();

            addedItem.Should().NotBeNull();
            addedItem.Type.Should().Be(type);
            addedItem.AmountBudgeted.Should().Be((int)(amount * 100));
        }
예제 #29
0
        //Method that returns the correct SQL command according to the type of selected item
        private MySqlCommand getCommand(BudgetItemType itemType, String sqlStatement, QueryData paramContainer)
        {
            switch (itemType)
            {
            case BudgetItemType.INCOME:
                return(SQLCommandBuilder.getSingleMonthCommand(sqlStatement, paramContainer));

            //CHANGE!!!(from EXPENSE TO GENERAL_EXPENSE)
            case BudgetItemType.GENERAL_EXPENSE:
                return(SQLCommandBuilder.getSingleMonthCommand(sqlStatement, paramContainer));

            case BudgetItemType.DEBT:
                return(SQLCommandBuilder.getSingleMonthCommand(sqlStatement, paramContainer));

            case BudgetItemType.SAVING:
                return(SQLCommandBuilder.getSingleMonthCommand(sqlStatement, paramContainer));

            default:
                return(null);
            }
        }
예제 #30
0
 private OperationResult <BudgetItemType> SuccessfulOperation(BudgetItemType entity)
 {
     return(new OperationResult <BudgetItemType>(new ValidationResult(), entity));
 }