def get_financial_results(event_id): """ Gathers information from the log files and returns the a dictionary containing the relevant payment information. This function was implemented as part of an ongoing process to improve the MIS clubs financial controls. :param event_id: The id of the event to be queried :return: A dictionary object containing information about the payments made at the event with event id <<event_id>> """ file_name = Logger.get_event_log_file(event_id) with open(file_name, "r") as log_file: contents = log_file.read() contents = contents.split('\n') try: while True: contents.remove('') except ValueError: pass total_payments = 0 dollars_collected = 0 previous_update = 0 uncollected_revenue = 0 shirt_sales = 0 for line in contents: if "payment made" in line.lower(): words = line.split(" ") try: sems_paid_for = int(words[4]) except ValueError: sems_paid_for = int(words[3]) if sems_paid_for == 1: dollars_collected += 15 previous_update = 15 elif sems_paid_for == 2: dollars_collected += 20 previous_update = 20 else: raise ValueError("Something went wrong reading the log File. Impossible number of semesters paid " "for, or number of semesters not logged.") total_payments += 1 elif line == "Payment above NOT collected": dollars_collected -= previous_update uncollected_revenue += previous_update result_set = {'revenue': {'num': total_payments, 'dues': dollars_collected, 'shirts': shirt_sales}, 'expenses': {'uncollected': uncollected_revenue}}
def create_ticket(event_id, net_id): """ Creates a ticket with the given event_id and net_id :param event_id: The event id for the new ticket :param net_id: The net_id for the new ticket :return: void """ connection = get_connection() cursor = connection.cursor() sql_string = "INSERT INTO Ticket VALUES("+str(event_id)+", '"+net_id+"')" try: cursor.execute(sql_string) Logger.write_to_log(Logger.get_event_log_file(), sql_string+"\n") except sqlite3.IntegrityError: # Maybe change these passes to log write. Not sure how to handle them. pass except sqlite3.DatabaseError: pass finally: connection.commit()
def submit_data(self, event=None): major = self.major_entry.get().strip() classification = self.classification_entry.get().strip() name = self.name_entry.get().strip() netid = self.net_id_entry.get().strip() for x in (major, classification, name, netid): if x == "": self.feedback_label.config(style="ErrorLabel.TLabel") self.feedback_label['text'] = 'Make sure there is an entry for every field.' return if self.dues.get() == "two": dues = 2 elif self.dues.get() == "one": dues = 1 else: dues = 0 data = MIS_Database_Functions.check_member(netid) if data is not None: if data['major'] != major: MIS_Database_Functions.set_major(netid, major) Logger.write_to_log(Logger.get_event_log_file(), "Major updated to %s for net id %s\n" % (major, netid)) if data['classification'] != classification: MIS_Database_Functions.set_classification(netid, classification) Logger.write_to_log(Logger.get_event_log_file(), "Classification updated to '%s' for net id '%s'\n" % (classification, netid)) if data['name'] != name: MIS_Database_Functions.set_name(netid, name) Logger.write_to_log(Logger.get_event_log_file(), "Name updated to %s for net id %s\n" % (name, netid)) if data['dues_paid'] != dues and dues > 0: MIS_Database_Functions.update_payment(netid, dues) Logger.write_to_log(Logger.get_event_log_file(), "Payment made for %s, %d semesters paid for\n" % (netid, dues)) if self.payment_made.get() == 0: Logger.write_to_log(Logger.get_event_log_file(), "Payment above NOT collected\n") else: MIS_Database_Functions.create_member(netid, name, major, classification, dues) Logger.write_to_log(Logger.get_event_log_file(), 'New Member: (%s, %s, %s, %s, %d)\n' % (netid, name, major, classification, dues)) if dues > 0: Logger.write_to_log(Logger.get_event_log_file(), "Payment made for %s semesters for net id %s\n" % (str(dues), netid)) if self.payment_made.get() == 0: Logger.write_to_log(Logger.get_event_log_file(), "Payment above NOT collected\n") event_id = MIS_Database_Functions.get_most_recent_event_id() # Weird edge case: when user accidentally presses trial button, may end up recording a trial meeting for a # a user who has already paid for the semester. Code is corrected to make sure the users payment information is # not affected, this just makes sure the logs don't falsely record a trial meeting. if data is None and dues == 0: Logger.write_to_log(Logger.get_event_log_file(), "Trial Meeting for %s\n" % netid) elif hasattr(data, 'dues_paid'): if data['dues_paid'] == 0: Logger.write_to_log(Logger.get_event_log_file(), "Trial Meeting for %s\n" % netid) MIS_Database_Functions.create_ticket(event_id, netid) Logger.write_to_log(Logger.get_event_log_file(), "\n\n") self.clear_all() self.feedback_label.config(style="SuccessLabel.TLabel") self.feedback_label['text'] = name.split(" ")[1] + " was checked in successfully!\n" \ "Welcome them to the meeting!"