def OnButtonRecordTransferButton(self, event): for a in self.user.accountList: if self.choiceFrom.GetStringSelection() == a.name: from_account = a if self.choiceTo.GetStringSelection() == a.name: to_account = a if self.choiceFrom.GetStringSelection() != '' and self.choiceTo.GetStringSelection() != '': if self.textCtrlTransferAmount.GetValue() != '': if self.choiceFrom.GetStringSelection() != self.choiceTo.GetStringSelection(): amount = 0.0 try: if '$' in self.textCtrlTransferAmount.GetValue(): amount = float(self.textCtrlTransferAmount.GetValue()[1:]) else: amount = float(self.textCtrlTransferAmount.GetValue()) if amount > from_account.balance: result = wx.MessageBox('This action will record an overdrawn balance for the account {0}. Do you want to continue?'.format(from_account.name), 'Insufficient funds!', wx.YES_NO | wx.CENTRE) if result == wx.YES: subresult = wx.MessageBox('You are recording a transfer of ${0} from {1} to {2}. Is this correct?'.format(self.textCtrlTransferAmount.GetValue(), self.choiceFrom.GetStringSelection(), self.choiceTo.GetStringSelection()), 'Record funds transfer?', wx.YES_NO | wx.CENTRE) if subresult == wx.YES: from_account.r.add_transaction(self.user, CBudgetP.transaction('account transfer', amount*-1, datetime.now(), '', 'to '+self.choiceTo.GetStringSelection(), 'transfer debit'), from_account) to_account.r.add_transaction(self.user, CBudgetP.transaction('account transfer', amount, datetime.now(), '', 'from '+self.choiceFrom.GetStringSelection(), 'transfer credit'), to_account) wx.MessageBox('Your transfer of ${0} from {1} to {2} has been recorded in the transaction register. You can view this activity in the Transaction window'.format(float(self.textCtrlTransferAmount.GetValue()), self.choiceFrom.GetStringSelection(), self.choiceTo.GetStringSelection()), 'Success', wx.OK | wx.CENTRE) init.save() self.set_backcolor_white([self.textCtrlTransferAmount]) self.choiceFrom.SetSelection(-1) self.choiceTo.SetSelection(-1) self.textCtrlTransferAmount.Clear() self.textCtrlBalance.Clear() self.textCtrlTotalBalance.Clear() self.textCtrlBalance.WriteText('$'+str(round(self.user.accountList[self.listBoxAccounts.GetSelection()].balance, 2))) self.pos_neg_amount_forecolor(round(self.user.accountList[self.listBoxAccounts.GetSelection()].balance, 2), self.textCtrlBalance) self.textCtrlTotalBalance.WriteText('$'+str(round(self.user.get_total_accounts_balance(), 2))) self.pos_neg_amount_forecolor_total(round(self.user.get_total_accounts_balance(), 2), self.textCtrlTotalBalance) else: subresult = wx.MessageBox('You are recording a transfer of ${0} from {1} to {2}. Is this correct?'.format(self.textCtrlTransferAmount.GetValue(), self.choiceFrom.GetStringSelection(), self.choiceTo.GetStringSelection()), 'Record funds transfer?', wx.YES_NO | wx.CENTRE) if subresult == wx.YES: from_account.r.add_transaction(self.user, CBudgetP.transaction('account transfer', amount*-1, datetime.now(), '', 'to '+self.choiceTo.GetStringSelection(), 'transfer debit'), from_account) to_account.r.add_transaction(self.user, CBudgetP.transaction('account transfer', amount, datetime.now(), '', 'from '+self.choiceFrom.GetStringSelection(), 'transfer credit'), to_account) wx.MessageBox('Your transfer of ${0} from {1} to {2} has been recorded in the transaction register. You can view this activity in the Transaction window'.format(float(self.textCtrlTransferAmount.GetValue()), self.choiceFrom.GetStringSelection(), self.choiceTo.GetStringSelection()), 'Success', wx.OK | wx.CENTRE) init.save() self.set_backcolor_white([self.textCtrlTransferAmount]) self.choiceFrom.SetSelection(-1) self.choiceTo.SetSelection(-1) self.textCtrlTransferAmount.Clear() self.textCtrlBalance.Clear() self.textCtrlTotalBalance.Clear() self.textCtrlBalance.WriteText('$'+str(round(self.user.accountList[self.listBoxAccounts.GetSelection()].balance, 2))) self.pos_neg_amount_forecolor(round(self.user.accountList[self.listBoxAccounts.GetSelection()].balance, 2), self.textCtrlBalance) self.textCtrlTotalBalance.WriteText('$'+str(round(self.user.get_total_accounts_balance(), 2))) self.pos_neg_amount_forecolor_total(round(self.user.get_total_accounts_balance(), 2), self.textCtrlTotalBalance) except ValueError: wx.MessageBox('The transfer amount you are entering has to be a number. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Transfer amount is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlTransferAmount) self.OnListBoxAccountsListbox(event) else: wx.MessageBox('You are trying to record a transfer from an account to itsself. Make sure the From and To accounts are different', 'Transfer to same account', wx.OK | wx.CENTRE) self.OnListBoxAccountsListbox(event) else: wx.MessageBox('You must enter a transfer amount to transfer funds', 'Enter an amount', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlTransferAmount) self.OnListBoxAccountsListbox(event) else: wx.MessageBox('You must select both from and to accounts in order to transfer funds', 'Select transfer accounts', wx.OK | wx.CENTRE)
def OnButtonAddAccountButton(self, event): if self.textCtrlAccountName.GetValue() == '' and self.textCtrlBalance.GetValue() == '' and self.choiceAccountType.GetSelection() == -1: wx.MessageBox(self.add_account_message, 'To add an account', wx.OK | wx.CENTRE) self.set_backcolor_green(self.textCtrlAccountName) elif self.textCtrlAccountName.GetValue() == '' and self.textCtrlBalance.GetValue() == '': wx.MessageBox('In order to add an account, it has to have a name. You can enter that below where it says \"Account Name\".', 'Account has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAccountName) elif self.textCtrlAccountName.GetValue() == '' and self.textCtrlBalance.GetValue() != '': wx.MessageBox('In order to add an account, it has to have a name. You can enter that below where it says \"Account Name\".', 'Account has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAccountName) self.set_backcolor_white([self.textCtrlBalance]) elif self.textCtrlAccountName.GetValue() != '' and self.textCtrlBalance.GetValue() == '': wx.MessageBox('In order to add an account, it has to have an balance. You can set the balance to $0 or even give it a negative balance if your account is overdrawn. You can enter that below where it says \"Balance\".', 'Account has no balance', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlBalance) self.set_backcolor_white([self.textCtrlAccountName]) elif self.textCtrlAccountName.GetValue() != '' and self.textCtrlBalance.GetValue() != '' and self.choiceAccountType.GetSelection() == -1: wx.MessageBox('In order to add an account, Cbudget needs to know if it\'s a Checking, Savings, or Credit Card account. You can select that below where it says \"Account Type\".', 'Account has no type', wx.OK | wx.CENTRE) self.set_backcolor_red(self.staticTextSelectAccountType) self.set_backcolor_white([self.textCtrlAccountName, self.textCtrlBalance]) elif self.choiceAccountType.GetSelection() == 2 and self.textCtrlCreditLimit.GetValue() == '': wx.MessageBox('In order to add a credit card account, it has to have a credit limit. You can enter that below where it says \"Credit Limit\".', 'Credit card account has no credit limit', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlCreditLimit) self.set_backcolor_white([self.textCtrlAccountName, self.textCtrlBalance]) else: self.set_backcolor_white([self.textCtrlAccountName, self.textCtrlBalance, self.textCtrlCreditLimit]) self.set_backcolor_grey(self.staticTextSelectAccountType) balance = 0.0 try: if '$' in self.textCtrlBalance.GetValue(): balance = float(self.textCtrlBalance.GetValue()[1:]) else: balance = float(self.textCtrlBalance.GetValue()) if self.textCtrlAccountName.GetValue() not in self.listBoxAccounts.GetStrings(): if self.choiceAccountType.GetStringSelection() == 'Checking': self.user.addCheckingAccount(self.textCtrlAccountName.GetValue(), 0.0, '', self.textCtrlBankName.GetValue(), self.choiceAccountType.GetStringSelection()) trans = CBudgetP.transaction(self.textCtrlAccountName.GetValue(), balance, datetime.now(), '', 'starting balance', 'account_creation') if len(self.user.accountList[-1].r.registerList) == 0: self.user.accountList[-1].r.add_transaction(self.user, trans, self.user.accountList[-1]) self.add_account(event) if self.choiceAccountType.GetStringSelection() == 'Savings': self.user.addSavingsAccount(self.textCtrlAccountName.GetValue(), 0.0, '', self.textCtrlBankName.GetValue(), self.choiceAccountType.GetStringSelection()) trans = CBudgetP.transaction(self.textCtrlAccountName.GetValue(), balance, datetime.now(), '', 'starting balance', 'account_creation') if len(self.user.accountList[-1].r.registerList) == 0: self.user.accountList[-1].r.add_transaction(self.user, trans, self.user.accountList[-1]) self.add_account(event) if self.choiceAccountType.GetStringSelection() == 'Credit Card': self.user.addCreditCardAccount(self.textCtrlAccountName.GetValue(), 0.0, '', self.textCtrlBankName.GetValue(),self.textCtrlInterestRate.GetValue(), float(self.textCtrlCreditLimit.GetValue()), self.choiceAccountType.GetStringSelection()) trans = CBudgetP.transaction(self.textCtrlAccountName.GetValue(), balance, datetime.now(), '', 'starting balance', 'account_creation') if len(self.user.accountList[-1].r.registerList) == 0: self.user.accountList[-1].r.add_transaction(self.user, trans, self.user.accountList[-1]) self.add_account(event) else: wx.MessageBox('Sorry, you can\'t add an account with that name. It\'s already in the list. To add another account, you\'ll need to change the name.', 'Duplicate account', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAccountName) except ValueError: wx.MessageBox('The balance you are entering has to be a number and can\'t be blank. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Balance is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlBalance) self.enable_ctrls(False)
def OnButtonEditTransactionButton(self, event): dt = self.datePickerCtrlDate.GetValue() date = datetime(dt.Year,dt.Month+1,dt.Day) amount = None try: if '$' in self.textCtrlAmount.GetValue(): amount = float(self.textCtrlAmount.GetValue()[1:]) trans = CBudgetP.transaction(self.textCtrlName.GetValue(), amount, date, self.textCtrlConf.GetValue(), self.textCtrlNote.GetValue(), self.choiceType.GetStringSelection()) if len(self.filtered_transactions) > 0 and (len(self.filtered_transactions) < len(self.account.r.registerList)): self.change_trans_type(self.filtered_transactions[self.selected_row].type, trans.type, trans) self.change_trans_type(self.account.r.registerList[self.account.r.registerList.index(self.filtered_transactions[self.selected_row])].type, trans.type, trans) self.account.r.edit_transaction(self.account.r.registerList, self.account.r.registerList.index(self.filtered_transactions[self.selected_row]), trans.name, trans.amount, trans.date, trans.conf, trans.note, trans.type) self.filtered_transactions[self.selected_row] = trans else: self.change_trans_type(self.rows[self.selected_row].type, trans.type, trans) self.change_trans_type(self.account.r.registerList[self.account.r.registerList.index(self.rows[self.selected_row])].type, trans.type, trans) self.account.r.edit_transaction(self.account.r.registerList, self.account.r.registerList.index(self.rows[self.selected_row]), trans.name, trans.amount, trans.date, trans.conf, trans.note, trans.type) self.rows[self.selected_row] = trans if self.account.name: self.user.set_current_account(self.account) init.save() self.set_backcolor_white([self.textCtrlAmount]) self.set_cell_values(self.selected_row,values=[trans.name,str(trans.amount),str(trans.date.date()),trans.conf,trans.note]) self.buttonEditTransaction.Enabled = False self.choiceType.SetSelection(-1) self.textCtrlName.Clear() self.textCtrlAmount.Clear() self.textCtrlConf.Clear() self.textCtrlNote.Clear() if len(self.filtered_transactions) == 0: self.filtered_transactions = self.account.r.registerList self.show_transaction_totals(self.filtered_transactions) date = datetime.now() self.datePickerCtrlDate.SetValue(wx.DateTimeFromDMY(date.day,date.month-1,date.year)) self.OnChoiceShowTransactionsChoice(event) except ValueError: wx.MessageBox('The amount you are entering has to be a number. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Amount is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount)
def OnChoiceSelectAccountChoice(self, event): for a in self.user.accountList: if a.name == self.choiceSelectAccount.GetStringSelection(): self.account = a self.buttonAddTransaction.Enabled = True elif self.choiceSelectAccount.GetStringSelection() == 'All': self.account = CBudgetP.account(None,None,None,None,None,self.user.get_all_transactions()) self.buttonAddTransaction.Enabled = False self.buttonEditTransaction.Enabled = False self.buttonRemoveTransaction.Enabled = False init.save() self.filtered_by_type = False self.choiceType.SetSelection(-1) self.checkBoxTypeFilter.SetValue(False) self.filtered_by_search = False self.searchCtrlSearchTransactions.Clear() self.filtered_by_date = False self.buttonDateFilter.Label = 'Apply' self.checkBoxTypeFilter.Label = 'Apply filter' self.show_grid(self.account.r.registerList) self.show_transaction_totals(self.account.r.registerList) self.enable_ctrls(True) self.set_forecolor_black([self.textCtrlAmount]) try: if self.user.s.show_last_transactions: self.show_last_transactions() except Exception as message: print '\n',str(message.__class__)+':',str(message),'\n'
def OnButtonAddToIncomesButton(self, event): success__fail = None c = CBudgetP.credit(self.user.creditList[self.listBoxCredits.GetSelection()].name, self.user.creditList[self.listBoxCredits.GetSelection()].amount, self.user.creditList[self.listBoxCredits.GetSelection()].date, self.user.creditList[self.listBoxCredits.GetSelection()].conf, self.user.creditList[self.listBoxCredits.GetSelection()].note) success_fail = self.user.creditList[self.listBoxCredits.GetSelection()].add_to_incomeList(self.user, c) if success_fail == 'success': self.user.s.credit_added = True init.save() wx.MessageBox('{0} has been added as a new income to your income list'.format(self.listBoxCredits.GetStringSelection()), 'Credit added', wx.OK | wx.CENTRE) self.OnButtonIncomesButton(event) if success_fail == 'fail': wx.MessageBox('You can only add a credit to the income list if you have 3 or more credits with the same name that were not all added on the same day', 'Need more credits!', wx.OK | wx.CENTRE)
def OnButtonAddCreditButton(self, event): if self.textCtrlCreditName.GetValue() == '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox(self.add_credit_message, 'To add an credit', wx.OK | wx.CENTRE) self.set_backcolor_green(self.textCtrlCreditName) elif self.textCtrlCreditName.GetValue() == '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox('In order to add a credit, it has to have a name. You can enter that below where it says \"Credit Name\".', 'Credit has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlCreditName) elif self.textCtrlCreditName.GetValue() == '' and self.textCtrlAmount.GetValue() != '': wx.MessageBox('In order to add a credit, it has to have a name. You can enter that below where it says \"Credit Name\".', 'Credit has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlCreditName) self.set_backcolor_white([self.textCtrlAmount]) elif self.textCtrlCreditName.GetValue() != '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox('In order to add a credit, it has to have an amount. You can enter that below where it says \"Amount\".', 'Credit has no amount', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount) self.set_backcolor_white([self.textCtrlCreditName]) else: self.set_backcolor_white([self.textCtrlCreditName, self.textCtrlAmount]) amount = 0.0 try: if '$' in self.textCtrlAmount.GetValue(): amount = float(self.textCtrlAmount.GetValue()[1:]) else: amount = float(self.textCtrlAmount.GetValue()) result = wx.MessageBox('These funds will be shown as being credited to your {0} account. Is this correct?'.format(self.user.get_current_account().name), 'Correct account?', wx.YES_NO | wx.CENTRE) if result == wx.YES: trans = CBudgetP.transaction(self.textCtrlCreditName.GetValue(), amount, datetime.now(), self.textCtrlConf.GetValue(), self.textCtrlNote.GetValue(), 'credit') self.user.addCredit(trans.name, trans.amount, trans.date, trans.conf, trans.note) self.c.run_first_time = False self.user.get_current_account().r.add_transaction(self.user, trans, self.user.get_current_account()) init.save() wx.MessageBox('The credit \"{0}\" has been to your credits list.'.format(trans.name), 'Credit added', wx.OK | wx.CENTRE) self.set_backcolor_white([self.textCtrlAmount]) self.listBoxCredits.Clear() self.listBoxCredits.InsertItems([c.name for c in self.user.creditList],0) self.buttonAddCredit.Enabled = False self.textCtrlCreditName.Clear() self.textCtrlAmount.Clear() self.textCtrlCreditName.SetFocus() else: wx.MessageBox('Please use Select Account to change the current account to the account you want these funds to be shown as credited to', 'Change account', wx.OK | wx.CENTRE) self.set_backcolor_red(self.staticTextSelectAccount) except ValueError: wx.MessageBox('The amount you are entering has to be a number and can\'t be blank. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Amount is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount)
def OnButtonAddTransactionButton(self, event): dt = self.datePickerCtrlDate.GetValue() date = datetime(dt.Year,dt.Month+1,dt.Day) if self.textCtrlName.GetValue() == '' and self.textCtrlAmount.GetValue() == '' and self.choiceType.GetSelection() == -1: wx.MessageBox(self.add_transaction_message, 'To add a transaction', wx.OK | wx.CENTRE) self.set_backcolor_green(self.textCtrlName) elif self.textCtrlName.GetValue() == '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox('In order to add a transaction, it has to have a name. You can enter that below where it says \"Name\".', 'Transaction has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlName) elif self.textCtrlName.GetValue() == '' and self.textCtrlAmount.GetValue() != '': wx.MessageBox('In order to add a transaction, it has to have a name. You can enter that below where it says \"Name\".', 'Transaction has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlName) self.set_backcolor_white([self.textCtrlAmount]) elif self.textCtrlName.GetValue() != '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox('In order to add a transaction, it has to have an amount. You can enter that below where it says \"Amount\".', 'Transaction has no amount', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount) self.set_backcolor_white([self.textCtrlName]) elif self.textCtrlName.GetValue() != '' and self.textCtrlAmount.GetValue() != '' and self.choiceType.GetSelection() == -1: wx.MessageBox('In order to add a transaction, it has to have a type (credit or debit). You can enter that below where it says \"Transaction type\".', 'Transaction has no type', wx.OK | wx.CENTRE) self.set_backcolor_red(self.staticTextType) self.set_backcolor_white([self.textCtrlName, self.textCtrlAmount]) else: self.set_backcolor_white([self.textCtrlName, self.textCtrlAmount]) self.set_backcolor_grey(self.staticTextType) amount = 0.0 try: if '$' in self.textCtrlAmount.GetValue(): amount = float(self.textCtrlAmount.GetValue()[1:]) else: amount = float(self.textCtrlAmount.GetValue()) trans = CBudgetP.transaction(self.textCtrlName.GetValue(), amount, date, self.textCtrlConf.GetValue(), self.textCtrlNote.GetValue(), self.choiceType.GetStringSelection()) if self.choiceType.GetStringSelection() == 'debit' and self.textCtrlAmount.GetValue() != '': trans.amount *= -1 if self.account.type == 'Credit Card': trans.amount *= -1 if self.account.type == 'Credit Card' and (trans.amount + self.account.balance > self.account.credit_limit): wx.MessageBox('This transaction will put your balance over your credit limit.', 'Warning!', wx.OK | wx.CENTRE) if self.account.type != 'Credit Card' and (trans.amount + self.account.balance < 0.0): result = wx.MessageBox('This action will record an overdrawn balance for the account {0}. Do you want to continue?'.format(self.account.name), 'Insufficient funds!', wx.YES_NO | wx.CENTRE) if result == wx.YES: self.add_transaction(trans) else: self.add_transaction(trans) self.OnChoiceShowTransactionsChoice(event) except ValueError: wx.MessageBox('The amount you are entering has to be a number. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Amount is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount)
def OnButtonAddToIncomesButton(self, event): success__fail = None c = CBudgetP.credit( self.user.creditList[self.listBoxCredits.GetSelection()].name, self.user.creditList[self.listBoxCredits.GetSelection()].amount, self.user.creditList[self.listBoxCredits.GetSelection()].date, self.user.creditList[self.listBoxCredits.GetSelection()].conf, self.user.creditList[self.listBoxCredits.GetSelection()].note) success_fail = self.user.creditList[ self.listBoxCredits.GetSelection()].add_to_incomeList( self.user, c) if success_fail == 'success': self.user.s.credit_added = True init.save() wx.MessageBox( '{0} has been added as a new income to your income list'. format(self.listBoxCredits.GetStringSelection()), 'Credit added', wx.OK | wx.CENTRE) self.OnButtonIncomesButton(event) if success_fail == 'fail': wx.MessageBox( 'You can only add a credit to the income list if you have 3 or more credits with the same name that were not all added on the same day', 'Need more credits!', wx.OK | wx.CENTRE)
#Boa:Frame:Expenses import wx import time import CBudgetP init = CBudgetP.initialize() from datetime import datetime import CBudgetP_Home import CBudgetP_Accounts import CBudgetP_Incomes import CBudgetP_Credits import CBudgetP_SavingsItems import CBudgetP_Budget import CBudgetP_ExpensesDue import CBudgetP_Transactions def create(parent): return Expenses(parent) [ wxID_EXPENSES, wxID_EXPENSESBUTTONACCOUNTS, wxID_EXPENSESBUTTONADDEXPENSE, wxID_EXPENSESBUTTONAVERAGE, wxID_EXPENSESBUTTONBUDGET, wxID_EXPENSESBUTTONCLOSE, wxID_EXPENSESBUTTONCREDITS, wxID_EXPENSESBUTTONEDITEXPENSE, wxID_EXPENSESBUTTONEXPENSESDUE,
def OnButtonRecordTransfersButton(self, event): pay_bills = 0.0 pay_bills_before_message = '' pay_bills_after_message = '' savings = 0.0 savings_before_message = '' savings_after_message = '' spending = 0.0 spending_before_message = '' spending_after_message = '' from_account = self.user.account_paid_into pay_bills_to_account = None savings_to_account = None spending_to_account = None if self.choicePayBills.GetSelection() != -1: pay_bills = float(self.textCtrlPayBills.GetValue()[1:]) for a in self.user.accountList: if a.name == self.choicePayBills.GetStringSelection(): pay_bills_to_account = a pay_bills_trans_from = CBudgetP.transaction('account transfer', pay_bills*-1, datetime.now(), 'budgeted amount', 'to '+pay_bills_to_account.name, 'transfer debit') pay_bills_trans_to = CBudgetP.transaction('account transfer', pay_bills, datetime.now(), 'budgeted amount', 'from '+from_account.name, 'transfer credit') pay_bills_before_message = '$'+str(pay_bills)+ ' will be transferred from '+from_account.name+' to '+pay_bills_to_account.name+':' pay_bills_after_message = '$'+str(pay_bills)+ ' was transferred from '+from_account.name+' to '+pay_bills_to_account.name+':' if self.choiceSavings.GetSelection() != -1: savings = float(self.textCtrlSavings.GetValue()[1:]) for a in self.user.accountList: if a.name == self.choiceSavings.GetStringSelection(): savings_to_account = a savings_trans_from = CBudgetP.transaction('account transfer', savings*-1, datetime.now(), 'budgeted amount', 'to '+savings_to_account.name, 'transfer debit') savings_trans_to = CBudgetP.transaction('account transfer', savings, datetime.now(), 'budgeted amount', 'from '+from_account.name, 'transfer credit') savings_before_message = '$'+str(savings)+ ' will be transferred from '+from_account.name+' to '+savings_to_account.name+':' savings_after_message = '$'+str(savings)+ ' was transferred from '+from_account.name+' to '+savings_to_account.name+':' if self.choiceSpending.GetSelection() != -1: spending = float(self.textCtrlSpending.GetValue()[1:]) for a in self.user.accountList: if a.name == self.choiceSpending.GetStringSelection(): spending_to_account = a spending_trans_from = CBudgetP.transaction('account transfer', spending*-1, datetime.now(), 'budgeted amount', 'to '+spending_to_account.name, 'transfer debit') spending_trans_to = CBudgetP.transaction('account transfer', spending, datetime.now(), 'budgeted amount', 'from '+from_account.name, 'transfer credit') spending_before_message = '$'+str(spending)+ ' will be transferred from '+from_account.name+' to '+spending_to_account.name+':' spending_after_message = '$'+str(spending)+ ' was transferred from '+from_account.name+' to '+spending_to_account.name+':' if self.choicePayBills.GetSelection() == -1 and self.choiceSavings.GetSelection() == -1 and self.choiceSpending.GetSelection() == -1: wx.MessageBox('You have not selected any accounts to record funds transfers to. You must select at least one account', 'No accounts selected', wx.OK | wx.CENTRE) if pay_bills_before_message != '' or savings_before_message != '' or spending_before_message != '': first_result = wx.MessageBox('You are about to record the following transfers: \n\n{0}\n{1}\n{2}\n\nIs this correct?'.format(pay_bills_before_message, savings_before_message, spending_before_message), 'Record transfers?', wx.YES_NO | wx.CENTRE) if first_result == wx.YES: if pay_bills_to_account and pay_bills_trans_from.amount != 0: from_account.r.add_transaction(self.user, pay_bills_trans_from, from_account) if savings_to_account and savings_trans_from.amount != 0: from_account.r.add_transaction(self.user, savings_trans_from, from_account) if spending_to_account and spending_trans_from.amount != 0: from_account.r.add_transaction(self.user, spending_trans_from, from_account) for a in self.user.accountList: if a.name == self.choicePayBills.GetStringSelection(): try: pay_bills_to_account.r.add_transaction(self.user, pay_bills_trans_to, pay_bills_to_account) except Exception as message: print message if a.name == self.choiceSavings.GetStringSelection(): try: savings_to_account.r.add_transaction(self.user, savings_trans_to, savings_to_account) except Exception as message: print message if a.name == self.choiceSpending.GetStringSelection(): try: spending_to_account.r.add_transaction(self.user, spending_trans_to, spending_to_account) except Exception as message: print message init.save() second_result = wx.MessageBox('You have recorded the following transfers: \n\n{0}\n{1}\n{2}\n\nNow that you have transferred funds, would you like to go to the Expenses Due window ' \ 'to see if there are any bills that need to be paid?'.format(pay_bills_after_message, savings_after_message, spending_after_message), 'Transfers recorded', wx.YES_NO | wx.CENTRE) if second_result == wx.YES: self.OnButtonExpensesDueButton(event) self.choicePayBills.SetSelection(-1) self.choiceSavings.SetSelection(-1) self.choiceSpending.SetSelection(-1) else: wx.MessageBox('Make sure you have selected the correct accounts for funds transfers to be recorded', 'Make corrections', wx.OK | wx.CENTRE)
#Boa:Frame:Budget import wx import CBudgetP import os import time init = CBudgetP.initialize() import CBudgetP_Home from datetime import datetime import CBudgetP_Accounts import CBudgetP_Incomes import CBudgetP_Credits import CBudgetP_Expenses import CBudgetP_SavingsItems import CBudgetP_ExpensesDue import CBudgetP_Transactions def create(parent): return Budget(parent) [wxID_BUDGET, wxID_BUDGETBUTTONACCOUNTS, wxID_BUDGETBUTTONCLOSE, wxID_BUDGETBUTTONCREDITS, wxID_BUDGETBUTTONEXPENSES, wxID_BUDGETBUTTONEXPENSESDUE, wxID_BUDGETBUTTONHOME, wxID_BUDGETBUTTONINCOMES, wxID_BUDGETBUTTONRECORDTRANSFERS, wxID_BUDGETBUTTONSAVINGSITEMS, wxID_BUDGETBUTTONTRANSACTIONS, wxID_BUDGETCHOICEPAYBILLS, wxID_BUDGETCHOICESAVINGS, wxID_BUDGETCHOICESPENDING, wxID_BUDGETLISTBOXINCOMES, wxID_BUDGETPANEL1, wxID_BUDGETSTATICTEXTDAILYALLOWANCE, wxID_BUDGETSTATICTEXTDEBTTOINCOMERATIO, wxID_BUDGETSTATICTEXTINCOMES, wxID_BUDGETSTATICTEXTLEFTOVER, wxID_BUDGETSTATICTEXTMONTHLYALLOWANCE, wxID_BUDGETSTATICTEXTMONTHLYSAVINGS, wxID_BUDGETSTATICTEXTSAVEAMOUNT, wxID_BUDGETSTATICTEXTSETASIDE,
def OnButtonAddCreditButton(self, event): if self.textCtrlCreditName.GetValue( ) == '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox(self.add_credit_message, 'To add an credit', wx.OK | wx.CENTRE) self.set_backcolor_green(self.textCtrlCreditName) elif self.textCtrlCreditName.GetValue( ) == '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox( 'In order to add a credit, it has to have a name. You can enter that below where it says \"Credit Name\".', 'Credit has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlCreditName) elif self.textCtrlCreditName.GetValue( ) == '' and self.textCtrlAmount.GetValue() != '': wx.MessageBox( 'In order to add a credit, it has to have a name. You can enter that below where it says \"Credit Name\".', 'Credit has no name', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlCreditName) self.set_backcolor_white([self.textCtrlAmount]) elif self.textCtrlCreditName.GetValue( ) != '' and self.textCtrlAmount.GetValue() == '': wx.MessageBox( 'In order to add a credit, it has to have an amount. You can enter that below where it says \"Amount\".', 'Credit has no amount', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount) self.set_backcolor_white([self.textCtrlCreditName]) else: self.set_backcolor_white( [self.textCtrlCreditName, self.textCtrlAmount]) amount = 0.0 try: if '$' in self.textCtrlAmount.GetValue(): amount = float(self.textCtrlAmount.GetValue()[1:]) else: amount = float(self.textCtrlAmount.GetValue()) result = wx.MessageBox( 'These funds will be shown as being credited to your {0} account. Is this correct?' .format(self.user.get_current_account().name), 'Correct account?', wx.YES_NO | wx.CENTRE) if result == wx.YES: trans = CBudgetP.transaction( self.textCtrlCreditName.GetValue(), amount, datetime.now(), self.textCtrlConf.GetValue(), self.textCtrlNote.GetValue(), 'credit') self.user.addCredit(trans.name, trans.amount, trans.date, trans.conf, trans.note) self.c.run_first_time = False self.user.get_current_account().r.add_transaction( self.user, trans, self.user.get_current_account()) init.save() wx.MessageBox( 'The credit \"{0}\" has been to your credits list.'. format(trans.name), 'Credit added', wx.OK | wx.CENTRE) self.set_backcolor_white([self.textCtrlAmount]) self.listBoxCredits.Clear() self.listBoxCredits.InsertItems( [c.name for c in self.user.creditList], 0) self.buttonAddCredit.Enabled = False self.textCtrlCreditName.Clear() self.textCtrlAmount.Clear() self.textCtrlCreditName.SetFocus() else: wx.MessageBox( 'Please use Select Account to change the current account to the account you want these funds to be shown as credited to', 'Change account', wx.OK | wx.CENTRE) self.set_backcolor_red(self.staticTextSelectAccount) except ValueError: wx.MessageBox( 'The amount you are entering has to be a number and can\'t be blank. You\'ve probably entered some letters, symbols, or a word. Make sure it\'s a number.', 'Amount is not a number', wx.OK | wx.CENTRE) self.set_backcolor_red(self.textCtrlAmount)