def update_user_bank_account(user_selected_bank_account): statement = "UPDATE BANKACCOUNT SET Name = ?, Amount = ?, Description = ?, Account_ID = ?, User_ID = ? WHERE Account_ID = ?" cursor().execute(statement, ( user_selected_bank_account.Name, user_selected_bank_account.Amount, user_selected_bank_account.Description, user_selected_bank_account.Account_ID, user_selected_bank_account.User_ID, user_selected_bank_account.Account_ID, )) commit()
def commit_incomestatement(self): """ This method is used to input a new IncomeStatement into the database. ... Parameters ---------- self : IncomeStatement Object A fully created/populated income statement object """ statement = "INSERT INTO INCOMESTATEMENT (Date, Amount, UnBudgeted, Description, User_ID) VALUES (?, ?, ?, ?, ?)" cursor().execute(statement, (self.Date, self.Amount, self.UnBudgeted, self.Description, self.User_ID)) commit()
def commit_bank_accout(self): """ This method is used to input a new BankAccount into the database. ... Parameters ---------- self : BankAccount Object A fully created/populated BankAccount Object """ statement = "INSERT INTO BANKACCOUNT (Name, Amount, Description, User_ID) VALUES (?, ?, ?, ?)" cursor().execute( statement, (self.Name, self.Amount, self.Description, self.User_ID)) commit()
def commit_user(self): """ This method is used to input a new User into the database. Parameters ---------- self : IncomeStatement Object A fully created/populated User object """ statement = "INSERT INTO USER (Username, First_Name, Last_Name, Password) VALUES (?, ?, ?, ?)" cursor().execute(statement, ( self.Username, self.First_Name, self.Last_Name, self.Password, )) commit()
def get_users_statements(user): """ This method is used to retreive all of the IncomeStatement IDs from the database for a particular user and then returns a list of IncomeStatement objects that belong to the user ... Parameters ---------- user: User Object This is a user object mainly used to get the User_ID from the user ... Returns ------- income_statements : List of IncomeStatement Objects this is returned if the database call was successful in finding any IncomeStatements for the User_ID provided --or-- 0 : int This is returned if no data was able to be found or if something went wrong """ #SQL statement for the database call statement = "SELECT * FROM INCOMESTATEMENT WHERE User_ID = ?" #Call to the database rows = cursor().execute(statement, (user.User_ID, )).fetchall() #Checking to see if data was returned from the database. If it is the data will be parsed and returned in a list #of IncomeStatement objects. If nothing is found 0 is returned if rows: income_statements = [] for x in rows: temp_IncomeStatement = IncomeStatement(Date=x[0], Amount=x[1], UnBudgeted=x[2], Description=x[3], IncomeStatement_ID=x[4], User_ID=x[5]) income_statements.append(temp_IncomeStatement) return income_statements else: return 0
def get_users_bank_accounts(user): """ This method is used to retreive all of the BankAccount IDs from the database for a particular user and then returns a list of BankAccount objects that belong to the user ... Parameters ---------- user: User Object This is a user object mainly used to get the User_ID from the user ... Returns ------- bank_account : List of BankAccount Objects this is returned if the database call was successful in finding any BankAccounts for the User_ID provided --or-- 0 : int This is returned if no data was able to be found or if something went wrong """ #SQL statement for the database call statement = "SELECT * FROM BANKACCOUNT WHERE User_ID = ?" #Call to the database rows = cursor().execute(statement, (user.User_ID, )).fetchall() #Checking to see if data was returned from the database. If it is the data will be parsed and returned in a list #of BankAccount objects. If nothing is found 0 is returned if rows: bank_account = [] for x in rows: temp_bank_account = BankAccount(Name=x[0], Amount=x[1], Description=x[2], Account_ID=x[3], User_ID=x[4]) bank_account.append(temp_bank_account) return bank_account else: return 0
def fetch(**KWARGS): """ This method is used to fetch Users objects from the database. Parameters ---------- Username : str A string representing the username the user selects. This is not case sensative as it is put into all upper case when being put into the database First_Name : str A string representing the first name of the user. This is not case sensative as it is all capitolized when being put into the database. User_ID : int A unique ID used to identify the user in the database. This is the primary key of the user. Password : str This string is the users password. The password is hashed by bcrypt before being put in so it is not stored in plain text. It will require Bcrypt to compare the entered password and stored password at login. """ elements = [] db_fetch = User.db_fetch for k, v in KWARGS.items(): db_fetch += "\"{}\"=?".format(k) elements.append(v) temp_SQL_data = cursor().execute(db_fetch, (elements)).fetchone() if temp_SQL_data: return User(Username=temp_SQL_data[0], First_Name=temp_SQL_data[1], Last_Name=temp_SQL_data[2], User_ID=temp_SQL_data[4], Password=temp_SQL_data[3]) else: return "User Not Found"
def fetch(**KWARGS): """ This method is used to fetch Budget objects from the database. It will mainly be used with the User_ID being what is searched on or the Budget_ID. It can accept any of the parameters from the Budget class though for searching functionality. ... Parameters ---------- Name : str This variable stores the name given to the budget by the user Amount : float This variables stores the amount given to the budget by the user UnSpent : float The amount that has not been spent from the budget Description : str Description given to the budget by the user IncomeStatement_ID : int Foreign Key to the owning IncomeStatement Budget_ID : int Primary Key to indentify the budget object User_ID : int Foreign Key to the owning User ... Returns ------- temp_budget_object: Budget Object This is returned if the fetch was successful in finding the requested object in the database --or-- 0 : int This is returned if the object was not found in the database """ #I have no idea what this stuff does, it was written by a classmate for # another class project we worked on together elements = [] db_fetch = Budget.db_fetch for k,v in KWARGS.items(): db_fetch += "\"{}\"=?".format(k) elements.append(v) #Pulling data from database for an Income Statement temp_SQL_data = cursor().execute(db_fetch, (elements)).fetchone() #If something was able to be found it will return an IncomeStatement object if temp_SQL_data: temp_bank_account_object = Budget(Name = temp_SQL_data[0], Amount = temp_SQL_data[1], UnSpent = temp_SQL_data[2], Description = temp_SQL_data[3], IncomeStatement_ID = temp_SQL_data[4], Budget_ID = temp_SQL_data[5], User_ID = temp_SQL_data[6]) return temp_bank_account_object #If nothing was found a 0 will be returned else: return 0
def get_users_budgets(user, income_statement_id = None): """ This method is used to retreive all of the Budgets from the database for a particular user and then returns a list of Budget objects that belong to the user ... Parameters ---------- user: User Object This is a user object mainly used to get the User_ID from the user ... Returns ------- budget_object : List of BankAccount Objects this is returned if the database call was successful in finding any BankAccounts for the User_ID provided --or-- 0 : int This is returned if no data was able to be found or if something went wrong """ if income_statement_id == None: #SQL statement for the database call statement = "SELECT * FROM BUDGET WHERE User_ID = ?" #Call to the database rows = cursor().execute(statement, (user.User_ID,)).fetchall() #Checking to see if data was returned from the database. If it is the data will be parsed and returned in a list #of Budget objects. If nothing is found 0 is returned if rows: budget_objects = [] for x in rows: temp_budget = Budget(Name = x[0], Amount = x[1], UnSpent = x[2], Description = x[3], IncomeStatement_ID = x[4], Budget_ID = x[5], User_ID = x[6]) budget_objects.append(temp_budget) return budget_objects else: return 0 elif income_statement_id: #SQL statement for the database call statement = "SELECT * FROM BUDGET WHERE IncomeStatement_ID = ?" #Call to the database rows = cursor().execute(statement, (income_statement_id,)).fetchall() #Checking to see if data was returned from the database. If it is the data will be parsed and returned in a list #of Budget objects. If nothing is found 0 is returned if rows: budget_objects = [] for x in rows: temp_budget = Budget(Name = x[0], Amount = x[1], UnSpent = x[2], Description = x[3], IncomeStatement_ID = x[4], Budget_ID = x[5], User_ID = x[6]) budget_objects.append(temp_budget) return budget_objects else: return 0
def fetch(**KWARGS): """ This method is used to fetch IncomeStatement objects from the database. In all reality this method requires the User_ID to be passed in to work well. But to be safe and to cover all of the options I may need to look up different types of look ups. ... Parameters ---------- Date : str a date time object formated as a string to store in the data base Amount : float A float used to store the initial amount of the income statement Description : str The user inputed description of the income statement IncomeStatement_ID : int the unique identifier and primary key of the income statement UnBudgeted : float the amount of money in the income statement that has not been put towards a budget User_ID : int The unique identifier of the user that owns the income statement ... Returns ------- temp_income_statement_object: IncomeStatement Object This is returned if the fetch was successful in finding the requested object in the database --or-- 0 : int This is returned if the object was not found in the database """ #I have no idea what this stuff does, it was written by a classmate for # another class project we worked on together elements = [] db_fetch = IncomeStatement.db_fetch for k, v in KWARGS.items(): db_fetch += "\"{}\"=?".format(k) elements.append(v) #Pulling data from database for an Income Statement temp_SQL_data = cursor().execute(db_fetch, (elements)).fetchone() #If something was able to be found it will return an IncomeStatement object if temp_SQL_data: temp_income_statement_object = IncomeStatement( Date=temp_SQL_data[0], Amount=temp_SQL_data[1], UnBudgeted=temp_SQL_data[2], Description=temp_SQL_data[3], IncomeStatement_ID=temp_SQL_data[4], User_ID=temp_SQL_data[5]) return temp_income_statement_object #If nothing was found a 0 will be returned else: return 0
def edit_incomestatement_instance(user_selected_statement): user_still_editing_selected_income_statement = True while user_still_editing_selected_income_statement: #Printing the Income Statement the user is editng print( "\n-----------------------\n|Income Statement Info|\n-----------------------" ) print("\n\nDate: " + str(user_statements[user_selected_statement].Date)) print( "Description: " + str(user_statements[user_selected_statement].Description)) print("Amount: $" + str(user_statements[user_selected_statement].Amount)) user_edit_choice = input( "\nPlease enter the number of what you would like to enter: \n\n1)Date\n2)Description\n3)Amount\n4)Done Editing\n\nYour Input: " ) while user_edit_choice == "": user_edit_choice = input( "\nPlease enter one of the valid options: \n\n1)Date\n2)Description\n3)Amount\n4)Done Editing\n\nYour Input: " ) user_edit_choice = int(user_edit_choice) if user_edit_choice == 4: try: user_still_editing_selected_income_statement = False statement = "UPDATE INCOMESTATEMENT SET Date = ?, Amount = ?, Description = ?, IncomeStatement_ID = ?, UnBudgeted = ?, User_ID = ? WHERE IncomeStatement_ID = ?" cursor().execute(statement, ( user_statements[user_selected_statement].Date, user_statements[user_selected_statement].Amount, user_statements[user_selected_statement]. Description, user_statements[user_selected_statement]. IncomeStatement_ID, user_statements[user_selected_statement]. UnBudgeted, user_statements[user_selected_statement].User_ID, user_statements[user_selected_statement]. IncomeStatement_ID, )) commit() #TODO : When the user edits an IncomeStatement, all of the budgets associated with the income statement have to be edited as well so money that doesn't # exist for the user is not sitting inside of budgets except Exception as e: print( "\n\nUnable to commit that to the database, try again!\nIf this continues try retarting the app." ) logging.exception("Unable to made update to database") elif user_edit_choice == 1: #Asking the user for their input for the date of their income print( "\n----------------------------------------------------------\n" ) date = input( "\nPlease input the new date you received the income (Please use the MM/DD/YYYY format): " ) gooddate = False #Trying to turn the date the user put in into a date time object #If it works then GoodDate is set to True and the program won't fall into the while #loop below for checking user dataBud try: date = datetime.datetime.strptime(date, '%m/%d/%Y') gooddate = True #This is just here so the try command doesn't yell at me except Exception as e: logging.exception("Date format not correct") pass #If the date entered by the user wasn't able to be put into a date time object this loop will run #It will run the same code above but will keep running until the object is able to be created #by the users input while gooddate == False: print( "\n----------------------------------------------------------\n" ) date = input( "\nPlease input the date using the correct formatting (Please use the MM/DD/YYYY format)\n\nInput: " ) try: date = datetime.datetime.strptime(date, '%m/%d/%Y') gooddate = True except: logging.exception("Date format not correct") pass user_statements[user_selected_statement].Date = date elif user_edit_choice == 2: #Asking the user to input a description for their paycheck. This is one of the key ways that users will use determine what the paycheck is # print("\n----------------------------------------------------------\n") description = input( "\nPlease enter a short description of the income.\nThis, along with the date, will be how you have to recognize the income statement. Please be descriptive.\n\nInput:" ) while description == "": print( "\n----------------------------------------------------------\n" ) description = input( "\nPlease enter something, an empty input is not allowed.\nThis, along with the date, will be how you have to recognize the income statement. Please be descriptive.\n\nInput:" ) user_statements[ user_selected_statement].Description = description elif user_edit_choice == 3: #Asking the user to enter in the money amount of their income statement print( "\n----------------------------------------------------------\n" ) amount = input( "\nPlease input the amount of the income (Please use standard money input)\n\nInput: $" ) goodmoney = False #This will try to format the input into the ##.## format. If it can not format it into a two decimal format then it will fail #and will run the accept statement bwloe try: amount = "{:.2f}".format(float(amount)) goodmoney = True change_income = True #This will only run if the amount the user input wasn't able to be formated correctly except Exception as e: logging.exception("Money format not correct") #This loop will run until the input of the user is able to be formated correctly for storage while goodmoney == False: print( "\n----------------------------------------------------------\n" ) amount = input( "\nThat format didn't work, please try again (Please use standard money input without commas)\n\nInput: $" ) try: amount = "{:.2f}".format(float(amount)) goodmoney = True change_income = True except Exception as e: logging.exception("Money format not correct") print(e) user_statements[user_selected_statement].Amount = amount user_statements[ user_selected_statement].UnBudgeted = amount
def fetch(**KWARGS): """ This method is used to fetch BankAccount objects from the database. It will mainly be used with the User_ID being what is searched on or the BankAccount_ID. It can accept any of the parameters from the BankAccount class though for searching functionality. ... Parameters ---------- Name : str This variable holds a user entered value to describe and identify the name of the bank account Description : str This variables holds a user entered value to describe and identify their bank account Amount : float This variable holds the the amount of money inside of the bank account Account_ID : int This is a unique value given by the database to identify the account. This is the primary key of the object User_ID : int This is the unique value of the user that the account belongs to ... Returns ------- temp_bank_account_object: BankAccount Object This is returned if the fetch was successful in finding the requested object in the database --or-- 0 : int This is returned if the object was not found in the database """ #I have no idea what this stuff does, it was written by a classmate for # another class project we worked on together elements = [] db_fetch = BankAccount.db_fetch for k, v in KWARGS.items(): db_fetch += "\"{}\"=?".format(k) elements.append(v) #Pulling data from database for an Income Statement temp_SQL_data = cursor().execute(db_fetch, (elements)).fetchone() #If something was able to be found it will return an IncomeStatement object if temp_SQL_data: temp_bank_account_object = temp_bank_account = BankAccount( Name=temp_SQL_data[0], Amount=temp_SQL_data[1], Description=temp_SQL_data[2], Account_ID=temp_SQL_data[3], User_ID=temp_SQL_data[4]) return temp_bank_account_object #If nothing was found a 0 will be returned else: return 0