コード例 #1
0
 def withdraw(self, amount):
     """
     Withdraw function to withdraw money from account
     """
     if int(amount) <= 0:
         # Validation rule: Amount is negative
         print(
             'Invalid amount. Please enter positive values.\nTransaction aborted!'
         )
     elif int(amount) > self.max_transaction_amount:
         # Validation rule: Amount is more than maximum set by the customer
         print(
             'Amount entered is more than the maximum.\nTransaction aborted!'
         )
     elif int(amount) > self.balance:
         # Validation rule: Amount is more than current balance
         print('Amount entered is more than balance.\nTransaction aborted!')
     else:
         self.balance -= int(amount)
         # Add withdrawal transaction to transactions log
         global_transactions.append(
             Transaction(self.customer.customer_id, self.account_number,
                         get_current_date(), get_current_time(),
                         self.get_branch_code(), amount,
                         str(int(self.balance) + int(amount)),
                         str(self.balance),
                         f'{str(amount)} withdrawn successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer.customer_id}.\nYou have withdrawn '
             f'{str(amount)} from Account #{self.account_number}\nClosing Balance: INR{self.balance}',
             self.customer.phone_number)
コード例 #2
0
 def modify_account(self):
     """
     Modify function to modify an object of Account class
     """
     modify_account_list = ['1. Modify Maximum Transaction Amount']
     for i in modify_account_list:
         print('\t' + i)
     print()
     ch = input('Command: ')
     if ch == '1':
         while True:
             try:
                 self.max_transaction_amount = int(
                     input('New Maximum Transaction Amount: '))
                 break
             except ValueError:
                 print('\nInvalid Value\n')
         global_transactions.append(
             Transaction(
                 self.customer.customer_id, self.account_number,
                 get_current_date(), get_current_time(),
                 self.get_branch_code(), 0, self.balance, self.balance,
                 'Maximum Transaction Amount modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer.customer_id}\nYour Account Number '
             f'{self.account_number}.\nYour account has been modified successfully.',
             self.customer.phone_number)
コード例 #3
0
 def delete_customer(self):
     """
     Delete function to delete an object of Customer class
     """
     # Add deletion of customer to transactions log
     global_transactions.append(
         Transaction(self.customer_id, 'NA', get_current_date(),
                     get_current_time(), 'NA', 'NA', 'NA', 'NA',
                     f'Customer {self.customer_id} deleted successfully!'))
     # Delete individual accounts
     for i in self.active_accounts:
         self.active_accounts[i].delete_account(False)
     self.active_accounts.clear()
     print('Customer deleted successfully!')
     send_message(
         f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id} has been deleted.\nSorry to see you go!',
         self.phone_number)
コード例 #4
0
 def input_customer(self):
     """
     Input function to take values from the user and assign it to an object of Customer class
     """
     self.first_name = input('First Name: ')
     self.last_name = input('Last Name: ')
     self.address.input_address()
     while True:
         self.phone_number = input(
             'Phone Number (+<Country Code><Phone Number>): ')
         if validate_phone(self.phone_number):
             otp = generate_otp(self.phone_number)
             flag = False
             while not flag:
                 otp_input = input(f'OTP sent on {self.phone_number}: ')
                 if str(otp_input) == str(otp):
                     flag = True
             if flag:
                 break
         else:
             print(
                 '\nInvalid Phone Number. Phone Numbers should follow +<Country Code><Phone Number>\n'
             )
     while True:
         self.email = input('Email: ')
         if validate_email(self.email):
             break
         else:
             print('\nInvalid Email ID\n')
     self.customer_id = utility.global_customer_id
     utility.global_customer_id = str(int(utility.global_customer_id) + 1)
     utility.global_customer_id = '0' * (
         4 - len(utility.global_customer_id)) + utility.global_customer_id
     global_customer_map[self.customer_id] = self
     # Add creation of customer to transactions log
     global_transactions.append(
         Transaction(self.customer_id, 'NA', get_current_date(),
                     get_current_time(), 'NA', 'NA', 'NA', 'NA',
                     f'Customer {self.customer_id} created successfully!'))
     print(
         f'Customer created successfully! Customer ID: {self.customer_id}')
     send_message(
         f'Greetings from Bank XXX!\nWelcome {self.first_name} {self.last_name}!\nYour Customer ID '
         f'{self.customer_id}.', self.phone_number)
コード例 #5
0
 def delete_account(self, pop_from_list):
     """
     Delete function to delete an object of Account class
     """
     # Add deletion of account to transactions log
     global_transactions.append(
         Transaction(
             self.customer.customer_id, self.account_number,
             get_current_date(), get_current_time(), self.get_branch_code(),
             'NA', self.balance, 0,
             f'Account {self.account_number} deleted successfully!'))
     self.customer.active_accounts_number -= 1
     if pop_from_list:
         self.customer.active_accounts.pop(self.account_number)
     print(
         f'Account {str(self.account_number)} deleted successfully! Closing Balance: INR{str(self.balance)}'
     )
     send_message(
         f'Greetings from Bank XXX!\nYour Customer ID {self.customer.customer_id}\nYour Account Number '
         f'{self.account_number}.\nYour account has been deleted successfully.',
         self.customer.phone_number)
コード例 #6
0
 def input_account(self):
     """
     Input function to take values from the user and assign it to an object of Account class
     """
     while True:
         ch = input('Existing customer? (Y/N): ')
         # For existing customers, adds a new account to the customer.active_accounts dictionary
         if ch.upper() == 'Y':
             existing_customer_id = input('Existing Customer ID: ')
             if existing_customer_id in global_customer_map:
                 print(
                     f'Customer found. Adding account to customer ID #{existing_customer_id}'
                 )
                 self.customer = global_customer_map[existing_customer_id]
                 self.customer.active_accounts_number += 1
                 break
             else:
                 print(
                     'Customer ID does not exist. Recheck ID or register as a new customer.'
                 )
         elif ch.upper() == 'N':
             # For new customers, creates a new customer then adds a new account to the customer.active_accounts
             # dictionary
             self.customer = Customer(
                 '', '', Address('', '', '', '', '', '', '', ''), '', '', 0,
                 '', {})
             self.customer.input_customer()
             self.customer.active_accounts_number += 1
             break
     while True:
         try:
             self.max_transaction_amount = int(
                 input('Maximum Transaction Amount: '))
             break
         except ValueError:
             print('\nInvalid Value\n')
     while True:
         try:
             self.balance = int(input('Initial Balance: '))
             break
         except ValueError:
             print('\nInvalid Value\n')
     while True:
         branch_code = input('Branch Code: ')
         if branch_code in global_branches:
             break
         else:
             print('\nInvalid Branch Code\n')
     self.account_number = str(self.customer.customer_id + branch_code +
                               str("%02d" %
                                   self.customer.active_accounts_number))
     self.customer.active_accounts[self.account_number] = self
     print(
         f'Account created successfully! Account ID: {self.account_number}')
     # Add creation of account to transactions log
     global_transactions.append(
         Transaction(
             self.customer.customer_id, self.account_number,
             get_current_date(), get_current_time(), self.get_branch_code(),
             'NA', 0, self.balance,
             f'Account {self.account_number} created successfully!'))
     send_message(
         f'Greetings from Bank XXX!\nYour Customer ID {self.customer.customer_id}\nYour Account Number '
         f'{self.account_number}.\nBalance INR{self.balance}\nYour account has been created successfully.',
         self.customer.phone_number)
コード例 #7
0
 def modify_customer(self):
     """
     Modify function to modify an object of Customer class
     """
     modify_customer_list = [
         '1. First Name', '2. Last Name', '3. Address', '4. Phone Number',
         '5. Email'
     ]
     print('\n\tWhich parameter do you want to modify?')
     for i in modify_customer_list:
         print('\t' + i)
     print()
     ch = input('Command: ')
     if ch == '1':
         self.first_name = input('New First Name: ')
         global_transactions.append(
             Transaction(self.customer_id, 'NA', get_current_date(),
                         get_current_time(), 'NA', 'NA', 'NA', 'NA',
                         'First name modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id}.\nYour account has been modified '
             f'successfully.', self.phone_number)
     elif ch == '2':
         self.last_name = input('New Last Name: ')
         global_transactions.append(
             Transaction(self.customer_id, 'NA', get_current_date(),
                         get_current_time(), 'NA', 'NA', 'NA', 'NA',
                         'Last name modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id}.\nYour account has been modified '
             f'successfully.', self.phone_number)
     elif ch == '3':
         self.address.modify_address()
         global_transactions.append(
             Transaction(self.customer_id, 'NA', get_current_date(),
                         get_current_time(), 'NA', 'NA', 'NA', 'NA',
                         'Address modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id}.\nYour account has been modified '
             f'successfully.', self.phone_number)
     elif ch == '4':
         while True:
             self.phone_number = input(
                 'New Phone Number (+<Country Code><Phone Number>): ')
             if validate_phone(self.phone_number):
                 otp = generate_otp(self.phone_number)
                 flag = False
                 while not flag:
                     otp_input = input(f'OTP sent on {self.phone_number}: ')
                     if str(otp_input) == str(otp):
                         flag = True
                 if flag:
                     break
             else:
                 print(
                     '\nInvalid Phone Number. Phone Numbers should follow +<Country Code><Phone Number>\n'
                 )
         global_transactions.append(
             Transaction(self.customer_id, 'NA', get_current_date(),
                         get_current_time(), 'NA', 'NA', 'NA', 'NA',
                         'Phone number modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id}.\nYour account has been modified '
             f'successfully.', self.phone_number)
     elif ch == '5':
         while True:
             self.email = input('Email: ')
             if validate_email(self.email):
                 break
             else:
                 print('\nInvalid Email ID\n')
         global_transactions.append(
             Transaction(self.customer_id, 'NA', get_current_date(),
                         get_current_time(), 'NA', 'NA', 'NA', 'NA',
                         'Email modified successfully!'))
         send_message(
             f'Greetings from Bank XXX!\nYour Customer ID {self.customer_id}.\nYour account has been modified '
             f'successfully.', self.phone_number)
     else:
         print('Invalid entry!')