def worker(loop, seconds, url): i = 1 total_erros = 0 dao = Dao() while(i <= loop): print('check => ', url, 'i => ', i) try: start = time.time() request = requests.get(url, timeout=CONFIG.get("REQUEST_TIMEOUT")) status_code = request.status_code except Exception as e: if CONFIG.get("SENTRY_URL") != "": sentry_sdk.init(CONFIG.get("SENTRY_URL")) sentry_sdk.capture_exception(e) status_code = CONFIG.get("REQUEST_DEFAULT_ERROR") total_erros += 1 if total_erros > CONFIG.get("NUMBER_ERRORS_SEND_MAIL"): if CONFIG.get("SENDMAIL"): mail = Mail(url, status_code) mail.send_mail() total_erros = 0 try: dao.insert(log_entity(url, status_code, (time.time() - start))) except Exception as e: if CONFIG.get("SENTRY_URL") != "": sentry_sdk.init(CONFIG.get("SENTRY_URL")) sentry_sdk.capture_exception(e) sentry_sdk.capture_exception(e) i += 1 time.sleep(seconds)
def __init__(self): self.dao = Dao().get_instance() # Part Order related vars self.order_uid = None self.parts = None self.vendor_name = None self.street = None self.city = None self.state = None self.postal_code = None self.phone_number = None # Assistant vars self.prev_orders = None self.vendor_info = None self.next_part_flag = False self.submit_part = None self.update_part_status_button = None self.variable_status = None self.order_number = None self.part_number = None self.update_order_button = None self.go_to_this_part = None self.part_number_drop_down = None # Single Part Add related self.insert_single_part_parent = set() self.single_part_vin = None self.single_part_cost = None self.single_part_desc = None self.single_part_part_no = None self.single_part_order_number = None
def __init__(self, window): self.dao = Dao().get_instance() self.records = None self.table = None self.message = None self.public_page_service = PublicPageService() self.main_screen = window self.public_screen = None self.v = None
def __init__(self, window, user): self.dao = Dao().get_instance() self.root = window self.v = None self.show_tab = True self.table = None self.view_vehicle_page = None self.message = None self.user = user self.loan = None self.pp_service = PublicPageService() self.is_loan = False
def __init__(self, window, usertype): self.dao = Dao().get_instance() self.root = window self.v = None self.show_tab = True self.table = None self.view_vehicle_page = None self.pp_service = PublicPageService() self.records = None self.public_screen = None self.usertype = usertype self.message = None
def __init__(self, window): self.dao = Dao().get_instance() self.seller_uid = None self.vehicle_type = None self.cost = None self.model_name = None self.model_year = None self.manu_id = None self.milage = None self.desc = None self.color = None self.message = None self.root = window self.buy_date = None self.condition = None
class LoginService: def __init__(self): self.dao = Dao().get_instance() def login(self, username, password): if self.authenticate_user(username, password): return True else: return False def authenticate_user(self,username,password): records = self.dao.check_if_valid_user(username,password) if len(records)==0: return False else: return True
class LookupParts: def __init__(self, window): self.root = window self.dao = Dao().get_instance() self.table = None self.message = None self.view_parts_page = None def list_vehicle_parts(self, filter_text, window): records = self.dao.get_all_vehicle_parts(filter_text) if len(records) > 0: if self.table is not None: self.table.sdem.destroy() self.table = TableSheet(records, ["Part Number", "Cost", "Description"], window) if self.message is not None: self.message.destroy() self.message = None else: if self.message is None: self.message = Label( self.view_parts_page, text="Sorry, it looks like we don’t have that in stock!", bg="#e2e8f0") self.message.pack() def show_vehicle_parts(self): public_screen = Toplevel(self.root) public_screen.title("Lookup Parts") public_screen.geometry("1300x1000") Label(public_screen, text="List of Parts", bg="#ADD8E6").pack() SearchBox(public_screen, command=self.list_vehicle_parts, command_arguments=(public_screen), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) self.view_parts_page = public_screen
class SellVehicleService: def __init__(self, window, user): self.dao = Dao().get_instance() self.root = window self.v = None self.show_tab = True self.table = None self.view_vehicle_page = None self.message = None self.user = user self.loan = None self.pp_service = PublicPageService() self.is_loan = False def show_vehicle_for_sale(self): public_screen = Toplevel(self.root) public_screen.title("View and Sale Vehicle") #public_screen.geometry("%sx%s" % (public_screen.winfo_reqwidth(), public_screen.winfo_reqheight())) public_screen.geometry("1300x1000") Label(public_screen, text="Total Number of Vehicles available for Sale", bg="#ADD8E6").pack() Label(public_screen, text=self.pp_service.vehicle_available_for_purchase()).pack() self.v = IntVar() filters = [("Vehicle Type", 1), ("Manufacturer", 2), ("Model year", 3), ("Color", 4), ("Keyword", 5), ("Vin", 6)] Label(public_screen, text="""Choose the filter to filter Vehicles""", justify=LEFT, padx=20).pack() for val, fil in enumerate(filters): Radiobutton(public_screen, text=fil[0], padx=20, justify=LEFT, variable=self.v, command=self.show_choice, value=val).pack() SearchBox(public_screen, command=self.list_public_vehicles, command_arguments=(public_screen), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) self.view_vehicle_page = public_screen def list_public_vehicles(self, filter_text, window): options = { 0: "get_vehicles_model_type", 1: "get_vehicles_manufacturer", 2: "get_vehicles_model_year", 3: "get_vehicle_color", 4: "get_vehicle_any_keyword", 5: "get_vehicle_vin" } records = getattr(self, options.get(self.v.get()))(filter_text) if len(records) > 0: if self.table is not None: self.table.sdem.destroy() self.table = TableSheet(records, [ "vin", "vehicle type", "model year", "model", "mileage", "price", "manufacturer", "color" ], window) self.table.sdem.bind("<Double-Button-1>", self.show_vehicle_sale_page) if self.message is not None: self.message.destroy() self.message = None else: if self.message is None: self.message = Label( self.view_vehicle_page, text="Sorry, it looks like we don’t have that in stock!", bg="#e2e8f0") self.message.pack() def show_vehicle_sale_page(self, event): add_vehicle = AddVehicleService(None) rows = self.table.sdem.get_selected_rows(get_cells=True) record = self.table.records[rows[0]] root = Tk() root.geometry("800x600") root.configure(background="#e2e8f0") root.title("Sell Vehicle") label1 = Label(root, text="Sell Vehicle:") label1.grid(row=1, column=0, ipadx="100") label2 = Label(root, text=str(record[0])) label2.grid(row=1, column=1) date = Label(root, text="Enter sale date (YYYY-MM-DD)", bg="#e2e8f0") date_entry = Entry(root) date.grid(row=2, column=0) date_entry.grid(row=2, column=1) customer = Label(root, text="Enter customer id", bg="#e2e8f0") customer_entry = Entry(root) customer.grid(row=3, column=0) customer_entry.grid(row=3, column=1) add_individual_customer = Button( root, text="lookup customer", fg="Black", bg="#ADD8E6", command=add_vehicle.lookup_customer_info) add_individual_customer.grid(row=4, column=0) add_loan = Button(root, text="Add Loan", fg="Black", bg="#ADD8E6", command=lambda window=root: self.add_loan(window)) add_loan.grid(row=4, column=1) new_record = (date_entry, customer_entry, record[0]) submit = Button( root, text="Make sale", fg="Black", bg="#ADD8E6", command=lambda m=new_record, p=root: self.make_vehicle_sale(m, p)) submit.grid(row=15, column=1) add_individual_customer.grid(row=4, column=0) root.mainloop() def add_loan(self, window): self.is_loan = True interest_rate = Label(window, text="Interest Rate (%)", bg="#e2e8f0") down_payment = Label(window, text="Down Payment ($)", bg="#e2e8f0") monthly_payment = Label(window, text="Monthly Payment ($)", bg="#e2e8f0") start_month = Label(window, text="Start Month (YYYY-MM)", bg="#e2e8f0") term = Label(window, text="Loan Term (in month)", bg="#e2e8f0") interest_rate.grid(row=8, column=0) down_payment.grid(row=9, column=0) monthly_payment.grid(row=10, column=0) start_month.grid(row=11, column=0) term.grid(row=12, column=0) interest_rate_val = Entry(window) down_payment_val = Entry(window) monthly_payment_val = Entry(window) start_month_val = Entry(window) term_val = Entry(window) interest_rate_val.grid(row=8, column=1, ipadx="100") down_payment_val.grid(row=9, column=1, ipadx="100") monthly_payment_val.grid(row=10, column=1, ipadx="100") start_month_val.grid(row=11, column=1, ipadx="100") term_val.grid(row=12, column=1, ipadx="100") self.loan = (term_val, interest_rate_val, down_payment_val, monthly_payment_val, start_month_val) def is_buy_date_less_than_sell_date(self, buy_date, sale_date): var = str(buy_date).split("-") sale_var = str(sale_date).split("-") return datetime(int(var[0]), int(var[1]), int(var[2])) < datetime( int(sale_var[0]), int(sale_var[1]), int(sale_var[2])) def make_vehicle_sale(self, record, window): record = list(record) record.append(self.user) record.append(self.dao.get_selling_price_of_vehicle(record[2])) record = tuple(record) input_sale_date = record[0].get() input_vin = record[2] buy_date_for_vin = self.dao.get_buy_date_for_vin(input_vin) if not self.is_buy_date_less_than_sell_date(buy_date_for_vin, input_sale_date): self.popup_window( "ERROR", "Input Sale Date Can't be less than Buy Date...") return self.dao.insert_into_sell(record) if self.is_loan: loan_record = [ record[2], self.user, int(self.loan[0].get()), float(self.loan[1].get()), float(self.loan[2].get()), float(self.loan[3].get()), self.loan[4].get() ] self.dao.insert_into_loan(loan_record) sell_vehicle_success_screen = Tk() sell_vehicle_success_screen.title("Success") sell_vehicle_success_screen.geometry("150x100") Label(sell_vehicle_success_screen, text="Vehicle Sold Successfully").pack() Button(sell_vehicle_success_screen, text="OK", command=lambda m=window, c=sell_vehicle_success_screen: self. destroy(m, c)).pack() def destroy(self, window, child): child.destroy() window.destroy() def show_choice(self): pass def get_vehicles_model_type(self, vehicle_type): return self.pp_service.list_vehicles_vehicle_type(vehicle_type) def get_vehicles_manufacturer(self, mfg_name): return self.pp_service.list_vehicle_mfg_name(mfg_name) def get_vehicles_model_year(self, model_year): return self.pp_service.list_vehicle_model_year(model_year) def get_vehicle_color(self, color): return self.pp_service.list_vehicle_color(color) def get_vehicle_any_keyword(self, keyword): return self.pp_service.list_vehicle_any_keyword(keyword) def get_vehicle_vin(self, vin): return self.pp_service.list_vehicle_vin(vin) def popup_window(self, title, message): global popup_win popup_win = Tk() popup_win.title(title) popup_win.geometry("250x100") Label(popup_win, text=message).pack() Button(popup_win, text="OK", command=self.delete_popup_window).pack() popup_win.mainloop() def delete_popup_window(self): popup_win.destroy()
def __init__(self): self.dao = Dao().get_instance()
def __init__(self, window): self.root = window self.dao = Dao().get_instance() self.table = None self.message = None self.view_parts_page = None
class Report: __instance = None def __init__(self, window): self.dao = Dao().get_instance() self.root = window def report_screen(self,title,records, header, rows=None): app = CustomizedSheet(records, header, title, rows=rows) app.mainloop() def seller_history_report(self): records = self.dao.seller_history_report() header = ['Name', 'Total Number of Vehicles Sold','Average Purchase Price','Average Number of Parts', 'Average Cost of Parts'] row=0 rows=[] for record in records: if record[3] >= 5 or record[4] >= 500: rows.append(row) row += 1 self.report_screen('Seller History Report', records, header, rows=rows) def average_time_in_inventory_report(self): records = self.dao.average_time_in_inventory_report() header = ['Vehicle Type', 'Average Days in Inventory'] self.report_screen('Average Time in Inventory Report', records, header) def price_per_condition_report(self): records = self.dao.price_per_condition_report() header = ['vehicle_type', 'Fair', 'Good', 'Very Good', 'Excellent'] self.report_screen('Price Per Condition Report', records, header) def parts_statistics_report(self): records = self.dao.parts_statistics_report() header = ['Vendor Name', 'Number of Parts', 'Total Cost of Parts'] self.report_screen('Parts Statistics Report', records, header) def monthly_loan_income_report(self): records = self.dao.monthly_loan_income_report() header = ['Start Month', 'Monthly Payment', 'Burdell share'] self.report_screen('Monthly Loan Income Report', records, header) def drilldown(self, text, public_screen): date_to_search = text.get() records = self.dao.monthly_Sales_report_drilldown(date_to_search) header = ['Name', 'Number of Vehicles Sold', 'Total Sales'] self.report_screen(' Monthly Sales Specific Report', records, header) def monthly_sales_report(self): records = self.dao.monthly_sales_report_summary() header = ['Date', 'Number of Vehicles Sold', 'Total Sales Income', 'Total Net Income'] public_screen = Toplevel(self.root) public_screen.geometry("1300x1000") table = Table(public_screen, ['Date', 'Number of Vehicles Sold', 'Total Sales Income', 'Total Net Income'], column_minwidths=[None, None, None, None]) table.pack(padx=50, pady=50) table.set_data(records) w = Label(public_screen, text="Enter Date (In YYYY-MM Format):") w.pack() text = StringVar() e = Entry(public_screen, textvariable=text) e.pack() showButton = Button(public_screen, text='Search', command=lambda: self.drilldown(text, public_screen)) showButton.pack()
class PublicPageService: def __init__(self): self.dao = Dao().get_instance() def list_vehicles(self): return self.dao.list_public_vehicles() def filter_vehicles(self, records): vin_sell_list = self.dao.get_vins_in_sell() vin_sell_list = list(vin_sell_list) filtered_records = [] for record in records: if record[ 0] not in vin_sell_list and self.dao.if_all_orders_completed( record[0]): filtered_records.append(record) new_records = [] for record in filtered_records: new_records.append(list(record)) for record in new_records: new_records[new_records.index( record)][5] = self.dao.get_selling_price_of_vehicle(record[0]) filtered_records = [] for record in new_records: filtered_records.append(tuple(record)) return filtered_records def list_vehicles_vehicle_type(self, vehicle_type): records = self.dao.list_vehicles_vehicle_type(vehicle_type) records = self.filter_vehicles(records) return records def list_vehicle_mfg_name(self, mfg_name): records = self.dao.list_vehicles_mfg_name(mfg_name) records = self.filter_vehicles(records) return records def list_vehicle_model_year(self, model_year): records = self.dao.list_vehicle_model_year(model_year) records = self.filter_vehicles(records) return records def list_vehicle_color(self, color): records = self.dao.list_vehicle_color(color) records = self.filter_vehicles(records) return records def list_vehicle_any_keyword(self, keyword): records = self.dao.list_vehicle_any_keyword(keyword) records = self.filter_vehicles(records) return records def vehicle_available_for_purchase(self): records = self.list_vehicles() records = self.filter_vehicles(records) return len(records) def list_vehicle_vin(self, vin): records = self.dao.list_vehicle_vin(vin) records = self.filter_vehicles(records) return records
class ViewVehicleService: def __init__(self, window, usertype): self.dao = Dao().get_instance() self.root = window self.v = None self.show_tab = True self.table = None self.view_vehicle_page = None self.pp_service = PublicPageService() self.records = None self.public_screen = None self.usertype = usertype self.message = None def show_clerk_view_vehicle_page(self): self.public_screen = Toplevel(self.root) self.public_screen.title("View Vehicles") self.public_screen.geometry("1300x1000") Label(self.public_screen, text="Total Number of Vehicles available for purchase", bg="#ADD8E6").pack() Label(self.public_screen, text=self.pp_service.vehicle_available_for_purchase()).pack() Label(self.public_screen, text="Total Number of Vehicles parts order pending", bg="#ADD8E6").pack() Label(self.public_screen, text=self.total_vehicles_part_pending()).pack() self.v = IntVar() filters = [ ("Vehicle Type", 1), ("Manufacturer", 2), ("Model year", 3), ("Color", 4), ("Keyword", 5), ("Vin", 6) ] Label(self.public_screen, text="""Choose the filter to filter Vehicles""", justify=LEFT, padx=20).pack() for val, fil in enumerate(filters): Radiobutton(self.public_screen, text=fil[0], padx=20, justify=LEFT, variable=self.v, command=self.show_choice, value=val).pack() SearchBox(self.public_screen, command=self.list_public_vehicles, command_arguments=(), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) self.view_vehicle_page = self.public_screen def get_parts_details_for_vehicle(self, vin): res = self.dao.get_parts_details_for_vehicle(vin) if len(res) == 0: return "No parts order placed for this Vehicle" orders = [entry[0] for entry in res] final_res = "" for order in list(set(orders)): order_str = order + ": \n" for entry in res: if order == entry[0]: part_str = "Part ID: " + entry[1] + " status: " + entry[2] + " Cost" + str( entry[3]) + "Part Desc: " + entry[4] + " Vendor: " + entry[5] + "\n" # print(part_str) order_str += part_str order_str += "\n" final_res += order_str return final_res def get_vehicle_sell_info(self, sell_info): part_str = "Sales Price: " + str(sell_info[0][0]) + " Sales Date: " + str(sell_info[0][1]) + \ " Sales Person Name" + str(sell_info[0][2]) + " Buyer Name: " + sell_info[0][3] +"\n" return part_str def show_manager_view_vehicle_page(self): self.public_screen = Toplevel(self.root) self.public_screen.title("View Vehicles") self.public_screen.geometry("1300x1000") Label(self.public_screen, text="Total Number of Vehicles available for purchase", bg="#ADD8E6").pack() Label(self.public_screen, text=self.pp_service.vehicle_available_for_purchase()).pack() Label(self.public_screen, text="Total Number of Vehicles parts order pending", bg="#ADD8E6").pack() Label(self.public_screen, text=self.total_vehicles_part_pending()).pack() self.v = IntVar() filters = [ ("Vehicle Type", 1), ("Manufacturer", 2), ("Model year", 3), ("Color", 4), ("Keyword", 5), ("Vin", 6), ("Sold Vehicles", 7), ("Unsold Vehicles", 8), ("All Vehicles", 9) ] Label(self.public_screen, text="""Choose the filter to filter Vehicles""", justify=LEFT, padx=20).pack() for val, fil in enumerate(filters): Radiobutton(self.public_screen, text=fil[0], padx=20, justify=LEFT, variable=self.v, command=self.show_choice, value=val).pack() SearchBox(self.public_screen, command=self.list_public_vehicles, command_arguments=(), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) self.view_vehicle_page = self.public_screen def show_vehicle_detail_page(self, event): rows = self.table.sdem.get_selected_rows(get_cells=True) record = self.table.records[rows[0]] root = Tk() root.geometry("1300x1000") root.configure(background="#e2e8f0") root.title("Vehicle Details") vin = Label(root, text="VIN:", bg="#e2e8f0") vin_dat = Label(root, text=record[0], bg="#e2e8f0") v_type = Label(root, text="Vehicle Type:", bg="#e2e8f0") v_type_dat = Label(root, text=record[1], bg="#e2e8f0") v_model_year = Label(root, text="Vehicle Model Year:", bg="#e2e8f0") v_model_year_dat = Label(root, text=record[2], bg="#e2e8f0") v_model = Label(root, text="Vehicle Model:", bg="#e2e8f0") v_model_dat = Label(root, text=record[3], bg="#e2e8f0") v_odometer = Label(root, text="Vehicle Odometer:", bg="#e2e8f0") v_odometer_dat = Label(root, text=record[4], bg="#e2e8f0") v_selling_price = Label(root, text="Selling Price:", bg="#e2e8f0") v_selling_price_dat = Label(root, text=record[5], bg="#e2e8f0") v_mfg = Label(root, text="Manufacturer:", bg="#e2e8f0") v_mfg_dat = Label(root, text=record[6], bg="#e2e8f0") v_color = Label(root, text="Color(s):", bg="#e2e8f0") v_color_dat = Label(root, text=record[7], bg="#e2e8f0") v_desc = Label(root, text="Description", bg="#e2e8f0") v_desc_dat = Label(root, text=self.dao.get_vehicle_description(record[0])[0], bg="#e2e8f0") v_cost = Label(root, text="Cost", bg="#e2e8f0") v_cost_dat = Label(root, text=self.dao.get_vehicle_cost(record[0])[0][0], bg="#e2e8f0") v_parts_cost = Label(root, text="Parts Cost", bg="#e2e8f0") v_parts_cost_dat = Label(root, text=self.dao.get_parts_cost(record[0]), bg="#e2e8f0") parts_details = Label(root, text="Vehicle Parts Details\n", bg="#e2e8f0",font = "Helvetica 10 bold") parts_details_dat = Label(root, text=self.get_parts_details_for_vehicle(record[0]), bg="#e2e8f0", font = "Helvetica 10 bold") vin.grid(row=1, column=0) vin_dat.grid(row=1, column=1) v_model_year.grid(row=3, column=0) v_model_year_dat.grid(row=3, column=1) v_type.grid(row=5, column=0) v_type_dat.grid(row=5, column=1) v_model.grid(row=7, column=0) v_model_dat.grid(row=7, column=1) v_odometer.grid(row=9, column=0) v_odometer_dat.grid(row=9, column=1) v_selling_price.grid(row=11, column=0) v_selling_price_dat.grid(row=11, column=1) v_mfg.grid(row=13, column=0) v_mfg_dat.grid(row=13, column=1) v_color.grid(row=15, column=0) v_color_dat.grid(row=15, column=1) v_desc.grid(row=17, column=0) v_desc_dat.grid(row=17, column=1) v_cost.grid(row=19, column=0) v_cost_dat.grid(row=19, column=1) v_parts_cost.grid(row=21, column=0) v_parts_cost_dat.grid(row=21, column=1) parts_details.grid(row=25, column=1) parts_details_dat.grid(row=28, column=1) root.mainloop() def show_vehicle_detail_page_manager(self, event): rows = self.table.sdem.get_selected_rows(get_cells=True) record = self.table.records[rows[0]] root = Tk() root.geometry("800x600") root.configure(background="#e2e8f0") root.title("##Vehicle Details##") vin = Label(root, text="VIN:", bg="#e2e8f0") vin_dat = Label(root, text=record[0], bg="#e2e8f0") v_type = Label(root, text="Vehicle Type:", bg="#e2e8f0") v_type_dat = Label(root, text=record[1], bg="#e2e8f0") v_model_year = Label(root, text="Vehicle Model Year:", bg="#e2e8f0") v_model_year_dat = Label(root, text=record[2], bg="#e2e8f0") v_model = Label(root, text="Vehicle Model:", bg="#e2e8f0") v_model_dat = Label(root, text=record[3], bg="#e2e8f0") v_odometer = Label(root, text="Vehicle Odometer:", bg="#e2e8f0") v_odometer_dat = Label(root, text=record[4], bg="#e2e8f0") v_selling_price = Label(root, text="Selling Price:", bg="#e2e8f0") v_selling_price_dat = Label(root, text=record[5], bg="#e2e8f0") v_mfg = Label(root, text="Manufacturer:", bg="#e2e8f0") v_mfg_dat = Label(root, text=record[6], bg="#e2e8f0") v_color = Label(root, text="Color(s):", bg="#e2e8f0") v_color_dat = Label(root, text=record[7], bg="#e2e8f0") v_desc = Label(root, text="Description", bg="#e2e8f0") v_desc_dat = Label(root, text=self.dao.get_vehicle_description(record[0])[0], bg="#e2e8f0") v_seller_Name = Label(root, text="Seller Name:", bg="#e2e8f0") v_Seller_Emailid = Label(root, text="Seller Email:", bg="#e2e8f0") Seller_info = self.dao.get_seller_info(record[0]) v_seller_name = Label(root, text=Seller_info[0][0], bg="#e2e8f0") v_seller_emailid = Label(root, text=Seller_info[0][1], bg="#e2e8f0") v_seller_Phone = Label(root, text="Seller Phone:", bg="#e2e8f0") v_seller_phone = Label(root, text=Seller_info[0][2], bg="#e2e8f0") v_seller_Street= Label(root, text="Seller Street:", bg="#e2e8f0") v_seller_street = Label(root, text=Seller_info[0][3], bg="#e2e8f0") v_seller_Postalcode = Label(root, text="Seller Postal Code:", bg="#e2e8f0") v_seller_postalcode = Label(root, text=Seller_info[0][4], bg="#e2e8f0") v_seller_City = Label(root, text="Seller City:", bg="#e2e8f0") v_seller_city = Label(root, text=Seller_info[0][5], bg="#e2e8f0") v_seller_State = Label(root, text="Seller State:", bg="#e2e8f0") v_seller_state = Label(root, text=Seller_info[0][6], bg="#e2e8f0") v_purchase_Price = Label(root, text="Purchase Price:", bg="#e2e8f0") v_purchase_price = Label(root, text=Seller_info[0][7], bg="#e2e8f0") v_purchase_Date = Label(root, text="Purchase Date:", bg="#e2e8f0") v_purchase_date = Label(root, text=Seller_info[0][8], bg="#e2e8f0") v_Buyer = Label(root, text="Buyer name:", bg="#e2e8f0") v_buyer = Label(root, text=Seller_info[0][9], bg="#e2e8f0") if(Seller_info[0][10] != 0): v_business_Title = Label(root, text="Business Title:", bg="#e2e8f0") v_business_title = Label(root, text=Seller_info[0][10], bg="#e2e8f0") Loan_details = self.dao.get_loan_details(record[0]) if (len(Loan_details) > 0): v_loan_Term = Label(root, text="Loan Term:", bg="#e2e8f0") v_loan_term = Label(root, text=Loan_details[0][3], bg="#e2e8f0") v_interest_Rate = Label(root, text="Interest Rate:", bg="#e2e8f0") v_interest_rate = Label(root, text=Loan_details[0][4], bg="#e2e8f0") v_down_Payment = Label(root, text="Down Payemnt:", bg="#e2e8f0") v_down_payment = Label(root, text=Loan_details[0][5], bg="#e2e8f0") v_month_Payment = Label(root, text="Month Payment:", bg="#e2e8f0") v_month_payment = Label(root, text=Loan_details[0][6], bg="#e2e8f0") v_start_Month = Label(root, text="Start Month:", bg="#e2e8f0") v_start_month = Label(root, text=Loan_details[0][7], bg="#e2e8f0") v_parts_cost = Label(root, text="Parts Cost", bg="#e2e8f0") v_parts_cost_dat = Label(root, text=self.dao.get_parts_cost(record[0]), bg="#e2e8f0") parts_details = Label(root, text="Vehicle Parts Details\n", bg="#e2e8f0", font="Helvetica 10 bold") parts_details_dat = Label(root, text=self.get_parts_details_for_vehicle(record[0]), bg="#e2e8f0", font="Helvetica 10 bold") sell_info = self.dao.get_sell_info(record[0]) if (len(sell_info) > 0): v_sell_Info = Label(root, text="Vehicle Sales Details\n", bg="#e2e8f0", font="Helvetica 10 bold") v_sell_info = Label(root, text=self.get_vehicle_sell_info(sell_info), bg="#e2e8f0", font="Helvetica 10 bold") vin.grid(row=1, column=0) vin_dat.grid(row=1, column=1) v_model_year.grid(row=3, column=0) v_model_year_dat.grid(row=3, column=1) v_type.grid(row=5, column=0) v_type_dat.grid(row=5, column=1) v_model.grid(row=7, column=0) v_model_dat.grid(row=7, column=1) v_odometer.grid(row=9, column=0) v_odometer_dat.grid(row=9, column=1) v_selling_price.grid(row=11, column=0) v_selling_price_dat.grid(row=11, column=1) v_mfg.grid(row=13, column=0) v_mfg_dat.grid(row=13, column=1) v_color.grid(row=15, column=0) v_color_dat.grid(row=15, column=1) v_desc.grid(row=17, column=0) v_desc_dat.grid(row=17, column=1) v_seller_Name.grid(row=18, column=0) v_seller_name.grid(row=18, column=1) v_Seller_Emailid.grid(row=19, column=0) v_seller_emailid.grid(row=19, column=1) v_seller_Phone.grid(row=20, column=0) v_seller_phone.grid(row=20, column=1) v_seller_Street.grid(row=21, column=0) v_seller_street.grid(row=21, column=1) v_seller_Postalcode.grid(row=22, column=0) v_seller_postalcode.grid(row=22, column=1) v_seller_City.grid(row=23, column=0) v_seller_city.grid(row=23, column=1) v_seller_State.grid(row=24, column=0) v_seller_state.grid(row=24, column=1) v_purchase_Price.grid(row=25, column=0) v_purchase_price.grid(row=25, column=1) v_purchase_Date.grid(row=26, column=0) v_purchase_date.grid(row=26, column=1) v_Buyer.grid(row=27, column=0) v_buyer.grid(row=27, column=1) if (Seller_info[0][10] != 0): v_business_Title.grid(row=28, column=0) v_business_title.grid(row=28, column=1) if (len(Loan_details) > 0): v_loan_Term.grid(row=29, column=0) v_loan_term.grid(row=29, column=1) v_interest_Rate.grid(row=30, column=0) v_interest_rate.grid(row=30, column=1) v_down_Payment.grid(row=31, column=0) v_down_payment.grid(row=31, column=1) v_month_Payment.grid(row=32, column=0) v_month_payment.grid(row=32, column=1) v_start_Month.grid(row=33, column=0) v_start_month.grid(row=33, column=1) v_parts_cost.grid(row=34, column=0) v_parts_cost_dat.grid(row=34, column=1) parts_details.grid(row=35, column=0) parts_details_dat.grid(row=35, column=1) if (len(sell_info) > 0): v_sell_Info.grid(row=36, column=0) v_sell_info.grid(row=36, column=1) root.mainloop() def list_public_vehicles(self, filter_text, arguments): options = {0: "get_vehicles_model_type", 1: "get_vehicles_manufacturer", 2: "get_vehicles_model_year", 3: "get_vehicle_color", 4: "get_vehicle_any_keyword", 5: "get_vehicle_vin", 6: "get_vehicle_sold", 7: "get_vehicle_unsold", 8: "get_vehicle_all"} self.records = getattr(self, options.get(self.v.get()))(filter_text) if len(self.records) > 0: if self.table is not None: self.table.sdem.destroy() self.table = TableSheet(self.records, ["vin", "vehicle type", "model year", "model", "Odometer", "sales price", "manufacturer", "color"], self.public_screen) if self.usertype == const.CLERK: self.table.sdem.bind("<Double-Button-1>", self.show_vehicle_detail_page) if self.usertype == const.MANAGER or self.usertype == const.BURDELL: self.table.sdem.bind("<Double-Button-1>", self.show_vehicle_detail_page_manager) if self.message is not None: self.message.destroy() self.message = None else: if self.message is None: self.message = Label(self.public_screen, text="Sorry, it looks like we don’t have that in stock!", bg="white") self.message.pack() def show_choice(self): pass def get_vehicles_model_type(self, vehicle_type): records = self.dao.list_vehicles_vehicle_type(vehicle_type) records = self.filter_clerk_view_vehicle(records) return records def get_vehicles_manufacturer(self, mfg_name): records = self.dao.list_vehicles_mfg_name(mfg_name) records = self.filter_clerk_view_vehicle(records) return records def get_vehicles_model_year(self, model_year): records = self.dao.list_vehicle_model_year(model_year) records = self.filter_clerk_view_vehicle(records) return records def get_vehicle_color(self, color): records = self.dao.list_vehicle_color(color) records = self.filter_clerk_view_vehicle(records) return records def get_vehicle_any_keyword(self, keyword): records = self.dao.list_vehicle_any_keyword(keyword) records = self.filter_clerk_view_vehicle(records) return records def get_vehicle_vin(self, vin): records = self.dao.list_vehicle_vin(vin) records = self.filter_clerk_view_vehicle(records) return records def get_vehicle_sold(self, text): return self.dao.list_vehicle_sold() def get_vehicle_unsold(self, text): return self.dao.list_vehicle_unsold() def get_vehicle_all(self, text): return self.dao.list_vehicle_all() def total_vehicles_part_pending(self): records = self.dao.list_public_vehicles() new_records = [] for record in records: if self.dao.if_any_orders_pending(record[0]): new_records.append(record) return len(new_records) def filter_clerk_view_vehicle(self, records): vin_sell_list = self.dao.get_vins_in_sell() vin_sell_list = list(vin_sell_list) filtered_records = [] for record in records: if record[0] not in vin_sell_list: filtered_records.append(record) temp = [] for record in filtered_records: temp.append(list(record)) for record in temp: temp[temp.index(record)][5] = self.dao.get_selling_price_of_vehicle(record[0]) filtered_records = [] for record in temp: filtered_records.append(tuple(record)) return filtered_records def get_parts_details_for_vehicle(self, vin): res = self.dao.get_parts_details_for_vehicle(vin) if len(res) == 0: return "No parts order placed for this Vehicle" orders = [entry[0] for entry in res] final_res = "" for order in list(set(orders)): order_str = order + ": \n" for entry in res: if order == entry[0]: part_str = "Part ID: " + entry[1] + " status: " + entry[2] + " Cost" + str( entry[3]) + "Part Desc: " + entry[4] + " Vendor: " + entry[5] + "\n" order_str += part_str order_str += "\n" final_res += order_str return final_res
def __init__(self, window): self.dao = Dao().get_instance() self.root = window
def __init__(self, main_screen): self.dao = Dao().get_instance() self.main_screen = main_screen self.utype = None self.username = None
class PartOrderService: def __init__(self): self.dao = Dao().get_instance() # Part Order related vars self.order_uid = None self.parts = None self.vendor_name = None self.street = None self.city = None self.state = None self.postal_code = None self.phone_number = None # Assistant vars self.prev_orders = None self.vendor_info = None self.next_part_flag = False self.submit_part = None self.update_part_status_button = None self.variable_status = None self.order_number = None self.part_number = None self.update_order_button = None self.go_to_this_part = None self.part_number_drop_down = None # Single Part Add related self.insert_single_part_parent = set() self.single_part_vin = None self.single_part_cost = None self.single_part_desc = None self.single_part_part_no = None self.single_part_order_number = None def show_part_order_form(self): # create a GUI window root = Tk() # set the background colour of GUI window root.configure(background='#e2e8f0') # set the title of GUI window root.title("Part Order Form") # set the configuration of GUI window root.geometry("1200x" "800") # create a Form label heading1 = Label(root, text="Update Status for Parts Ordered", bg="#33A2FF", width=30) heading2 = Label(root, text="Place New Order", bg="#33A2FF", width=30) heading3 = Label(root, text="Latest Order IDs for Vehicle Related to You...", bg="#33A2FF", width=100) heading4 = Label(root, text="Vendor Info Assistant", bg="#33A2FF", width=100) # create a Name label self.order_uid = Label(root, text="Order UID", bg="#e2e8f0") self.parts = Label(root, text="Number of Parts", bg="#e2e8f0") self.vendor_name = Label(root, text="Vendor Name", bg="#e2e8f0") self.street = Label(root, text="Vendor Address Street", bg="#e2e8f0") self.city = Label(root, text="Vendor Address City", bg="#e2e8f0") self.state = Label(root, text="Vendor Address State", bg="#e2e8f0") self.postal_code = Label(root, text="Vendor Address Pincode", bg="#e2e8f0") self.phone_number = Label(root, text="Phone Number", bg="#e2e8f0") # Assistant Info vendors = self.dao.get_vendor_names() vendors = [ vendor[0].ljust(15, ' ') + " " + vendor[1] + ", " + vendor[2] + ", " + vendor[3] + ", " + str(vendor[4]) + ", " + str(vendor[5]) for vendor in vendors ] vendors = ("\n").join([i for i in vendors]) self.vendor_info = Label(root, text=vendors, bg="#e2e8f0") prev_orders = self.dao.get_previous_part_orders_by_user() user_specific_ordr_uids = set() order_uids = list(set([entry[1] for entry in prev_orders])) associated_vehicle_with_user = self.dao.get_vehicle_list_for_curr_user( ) if len(associated_vehicle_with_user) == 0: self.prev_orders = Label(root, text="No related Vehicles for this user", bg="#e2e8f0") else: associated_vehicle_with_user = list( set([entry[0] for entry in associated_vehicle_with_user])) for vin in associated_vehicle_with_user: for order in order_uids: if vin in order: user_specific_ordr_uids.add(order) user_specific_ordr_uids = list(user_specific_ordr_uids) for i in range(len(user_specific_ordr_uids)): if i % 5 == 0 and i != 0: user_specific_ordr_uids[i] = " \n" user_specific_ordr_uids = (", ").join( list(user_specific_ordr_uids)) self.prev_orders = Label(root, text=user_specific_ordr_uids, bg="#e2e8f0", font='Helvetica 6 bold') # grid method is used for placing # the widgets at respective positions # in table like structure. heading1.grid(row=0, column=1, sticky=W) heading2.grid(row=6, column=1, sticky=W) heading3.grid(row=0, column=4) heading4.grid(row=6, column=4) self.order_uid.grid(row=1, column=0) #Label(root, text="", bg="#e2e8f0").grid(row=5, column=0) self.parts.grid(row=7, column=0) self.vendor_name.grid(row=8, column=0) self.street.grid(row=9, column=0) self.city.grid(row=10, column=0) self.state.grid(row=11, column=0) self.postal_code.grid(row=12, column=0) self.phone_number.grid(row=13, column=0) Label(root, text=" ", bg="#e2e8f0").grid(column=3) # Assistant Info self.prev_orders.grid(row=1, column=4) self.vendor_info.grid(row=7, column=4) # create a text entry box # for typing the information self.order_uid = Entry(root, width=1) self.parts = Entry(root, width=3) self.vendor_name = Entry(root, width=3) self.street = Entry(root, width=3) self.city = Entry(root, width=3) self.state = Entry(root, width=3) self.postal_code = Entry(root, width=3) self.phone_number = Entry(root, width=3) # grid method is used for placing # the widgets at respective positions # in table like structure. self.order_uid.grid(row=1, column=1, ipadx="100", sticky=W) self.parts.grid(row=7, column=1, ipadx="100", sticky=W) self.vendor_name.grid(row=8, column=1, ipadx="100", sticky=W) self.street.grid(row=9, column=1, ipadx="100", sticky=W) self.city.grid(row=10, column=1, ipadx="100", sticky=W) self.state.grid(row=11, column=1, ipadx="100", sticky=W) self.postal_code.grid(row=12, column=1, ipadx="100", sticky=W) self.phone_number.grid(row=13, column=1, ipadx="100", sticky=W) # create a Submit Button and place into the root window self.update_order_button = Button(root, text="Update Part Status", fg="Black", bg="#FF8A33", command=self.show_parts_for_order) self.update_order_button.grid(row=3, column=1) submit = Button(root, text="Order & Add Parts", fg="Black", bg="#FF8A33", command=self.add_parts) submit.grid(row=14, column=1) root.mainloop() def add_parts(self): """ Method which calls single part_form in a loop == number """ valid_input = True if not (self.vendor_name.get()): self.popup_window("Error", "Enter All the Required Attributes") valid_input = False if valid_input: all_vendors = self.dao.get_all_vendor_names() if str(self.vendor_name.get()) in all_vendors: pass else: vendor_details = (str(self.vendor_name.get()), str(self.street.get()), str(self.city.get()), str(self.state.get()), int(str(self.postal_code.get())), int(str(self.phone_number.get()))) self.dao.insert_vendor(vendor_details) part_num = int(self.parts.get()) for i in range(part_num): self.part_form(i + 1, part_num) part_form.destroy() def part_form(self, num, tot_num): global part_form part_form = Tk() # set the background colour of GUI window part_form.configure(background='#e2e8f0') # set the title of GUI window part_form.title("Single Part Order Form") # set the configuration of GUI window part_form.geometry("1000x200") Label(part_form, text="VIN").grid(row=0, column=0) Label(part_form, text="Cost").grid(row=0, column=1) Label(part_form, text="Description").grid(row=0, column=2) Label(part_form, text="Part Number").grid(row=0, column=3) Label( part_form, text= "(Note: Do not enter Cost and Description if Part ID exists in Lookup Parts)" ).grid(row=2, column=1) self.single_part_vin = Entry(part_form, text="") self.single_part_vin.grid(row=1, column=0) self.single_part_cost = Entry(part_form, text="") self.single_part_cost.grid(row=1, column=1) self.single_part_desc = Entry(part_form, text="") self.single_part_desc.grid(row=1, column=2) self.single_part_part_no = Entry(part_form, text="") self.single_part_part_no.grid(row=1, column=3) self.submit_part = Button(part_form, text="Add Part to Order", fg="Black", bg="#ADD8E6", command=self.update_part_order_parent) self.submit_part.grid(row=1, column=4) indicator = Button(part_form, text="Part" + str(num) + " of " + str(tot_num), fg="Black", bg="light blue") indicator.grid(row=2, column=4) indicator.configure(state='disabled') part_form.mainloop() def get_order_id(self, vin): for ordr_id in self.insert_single_part_parent: if vin in ordr_id: return ordr_id res = self.dao.get_latest_order_ids_for_vin(vin) if len(res) == 0: return vin + "-001" else: vin = res[0][0] vin_ordr_list = [entry[1] for entry in res] vin_ordr_list = list(set(vin_ordr_list)) order_subsc = max([int(i.split("-")[1]) for i in vin_ordr_list]) + 1 order_subsc = ('{:03d}'.format(order_subsc)) id = vin + "-" + str(order_subsc) return id def update_part_order_parent(self): """Calls DB Inserts for Part, PartOrder and Contains""" if not (self.single_part_vin.get() and self.single_part_part_no.get()): self.popup_window("Error", "Please Enter All the Required Attributes") self.next_part_flag = True self.submit_part.configure(state='disabled') existing_part_ids = [entry[0] for entry in self.dao.get_part_ids()] if str(self.single_part_part_no.get()) in existing_part_ids: entry = self.dao.get_part_details_for_part( str(self.single_part_part_no.get())) self.single_part_desc = entry[0] self.single_part_cost = entry[1] else: part_tmp = (str(self.single_part_part_no.get()), str(self.single_part_cost.get()), str(self.single_part_desc.get())) self.dao.insert_part(part_tmp) self.single_part_order_number = self.get_order_id( str(self.single_part_vin.get())) order_tmp = (str(self.single_part_vin.get()), str(self.vendor_name.get()), None, self.single_part_order_number) contains_tmp = (self.single_part_order_number, str(self.single_part_part_no.get()), "ordered") if not self.single_part_order_number in list( self.insert_single_part_parent): self.insert_single_part_parent.add(self.single_part_order_number) self.dao.insert_part_order(order_tmp) self.dao.insert_contains(contains_tmp) part_form.quit() def show_parts_for_order(self): """ This method is auxilary UI method to specify paricular Part from previously mentioned OrderID """ show_parts_for_order_form = Tk() show_parts_for_order_form.configure(background='#e2e8f0') # set the title of GUI window show_parts_for_order_form.title("Select Part For Entered Order") # set the configuration of GUI window show_parts_for_order_form.geometry("400x100") Label(show_parts_for_order_form, text="Select Part").grid(row=1, column=2) self.order_number = str(self.order_uid.get()) PART_OPTIONS = self.dao.get_parts_associated_with_order( self.order_number) PART_OPTIONS = [entry[0] for entry in PART_OPTIONS] self.part_number_drop_down = StringVar(show_parts_for_order_form) self.part_number_drop_down.set(PART_OPTIONS[0]) # default value OptionMenu(show_parts_for_order_form, self.part_number_drop_down, *PART_OPTIONS).grid(row=3, column=2) self.go_to_this_part = Button(show_parts_for_order_form, text="GO TO THIS PART", fg="Black", bg="Red", command=self.update_part_status) self.go_to_this_part.grid(row=4, column=2) def update_part_status(self): """ This is UI related method to show Update Part Status Form """ self.part_number = str(self.part_number_drop_down.get()) entry = self.dao.get_part_info( (self.order_number, self.part_number))[0] update_part_form = Tk() update_part_form.configure(background='#e2e8f0') update_part_form.title("Part Status Update Form") update_part_form.geometry("400x100") Label(update_part_form, text="VIN").grid(row=0, column=0) Label(update_part_form, text="Cost").grid(row=0, column=1) Label(update_part_form, text="Description").grid(row=0, column=2) Label(update_part_form, text="Status").grid(row=0, column=3) curr_status = entry[-1] if curr_status == "ordered": OPTIONS = ["ordered", "received", "installed"] elif curr_status == "received": OPTIONS = ["received", "installed"] else: OPTIONS = ["installed"] self.variable_status = StringVar(update_part_form) self.variable_status.set(OPTIONS[0]) # default value OptionMenu(update_part_form, self.variable_status, *OPTIONS).grid(row=1, column=3) part_vin, part_cost, part_desc = entry[0], entry[1], entry[2] Label(update_part_form, text=part_vin).grid(row=1, column=0) Label(update_part_form, text=part_cost).grid(row=1, column=1) Label(update_part_form, text=part_desc).grid(row=1, column=2) self.update_part_status_button = Button(update_part_form, text="Update Status", fg="Black", bg="#ADD8E6", command=self.update_part) self.update_part_status_button.grid(row=1, column=4) if curr_status == "installed": self.update_part_status_button.configure(state="disabled") update_part_form.mainloop() def update_part(self): """ This updates the status of Particular Part calls DAO method """ status = str(self.variable_status.get()) self.dao.update_part_status(status, self.order_number, self.part_number) self.update_part_status_button.configure(state="disabled") def insert(self): self.next_part_flag = True self.submit_part.configure(state='disabled') part_form.quit() return def popup_window(self, title, message): global popup_win popup_win = Tk() popup_win.title(title) popup_win.geometry("200x100") Label(popup_win, text=message).pack() Button(popup_win, text="OK", command=self.delete_popup_window).pack() popup_win.mainloop() def delete_popup_window(self): popup_win.destroy()
class AddVehicleService: def __init__(self, window): self.dao = Dao().get_instance() self.seller_uid = None self.vehicle_type = None self.cost = None self.model_name = None self.model_year = None self.manu_id = None self.milage = None self.desc = None self.color = None self.message = None self.root = window self.buy_date = None self.condition = None def is_valid_buy_date(self, buy_date): var = buy_date.split("-") today_var = datetime.today().strftime('%Y-%m-%d').split("-") return datetime(int(var[0]), int(var[1]), int(var[2])) > datetime(int(today_var[0]), int(today_var[1]), int(today_var[2])) def insert(self, root): #TODO: Error handling is to be provided here #TODO: Some provision to close the window automatically after Sumbit button is pressed #TODO: handle error cases where some of the fileds are if int(self.model_year.get()) > datetime.today().year: self.popup_window("DATE ERROR", "Model Year should be less than current year") return if self.is_valid_buy_date(str(self.buy_date.get())): self.popup_window("DATE ERROR", "Purchase Date must be today or any day before today .....") return vehicle_val = (self.vin.get(), self.vehicle_type.get(), float(self.cost.get()), self.model_name.get(), int(self.model_year.get()), int(self.manu_id.get()), int(self.milage.get()), self.desc.get()) self.dao.insert_vehicle(vehicle_val) buy_val = (self.vin.get(), self.seller_uid.get(), const.CURRENT_USER, float(self.cost.get()), self.buy_date.get(), self.condition.get()) self.dao.insert_buy(buy_val) color_list = str(self.color.get()).split(",") for color in color_list: vehicle_color_val = (str(self.vin.get()), color) #self.dao.insert_vehicle_color(self.vin.get(), self.color.get()) self.dao.insert_vehicle_color(vehicle_color_val) root.destroy() def insert_individual_customer(self, screen): cust_id = self.dao.count_all_customers() customer = (str(cust_id+1),self.email.get(),self.phone_number.get(),self.street.get(), self.postal_code.get(),self.city.get(),self.state.get()) individual = (str(cust_id+1), self.dln.get(),self.first_name.get(),self.last_name.get()) self.dao.insert_individual_customer(customer,individual) screen.destroy() def insert_business_customer(self, screen, record): cust_id = self.dao.count_all_customers() customer = (str(cust_id + 1), record[0].get(), record[1].get(), record[2].get(), record[3].get(), record[4].get(), record[5].get()) business = (str(cust_id + 1), record[6].get(), record[7].get(), record[8].get(),record[9].get(), record[10].get()) self.dao.insert_business_customer(customer,business) screen.destroy() def list_customers(self,filter_text,arguments): if self.v.get()==0: columns = ["Customer id", "Tax Id","Business Name","Contact First Name","Contact Last Name","Contact Title"] records = self.dao.list_customers_taxId(filter_text) else: columns = ["Customer Id","Driver License Number","First Name","Last Name"] records = self.dao.list_customers_license(filter_text) if len(records)>0: TableSheet(records,columns,arguments[0]) if self.message is not None: self.message.destroy() self.message = None else: if self.message is None: self.message = Label(arguments[0],text="No customer found") self.message.pack() def add_business_customer(self): root = Tk() root.configure(background='white') root.title("Add Customer Form") root.geometry("500x350") heading = Label(root, text="Add Business Customer", bg="white") tax_id_no = Label(root, text="Tax Id number", bg="white") email = Label(root, text="email", bg="white") business_name = Label(root, text="business name", bg="white") contact_person_first_name = Label(root, text="CP first name ", bg="white") contact_person_last_name = Label(root, text="CP last name ", bg="white") phone_number = Label(root, text="phone number", bg="white") street = Label(root, text="street", bg="white") city = Label(root, text="city", bg="white") state = Label(root, text="state", bg="white") postal_code = Label(root, text="postal code", bg="white") cp_title = Label(root, text="contact person Title", bg="white") heading.grid(row=0, column=1) tax_id_no.grid(row=1, column=0) email.grid(row=2, column=0) business_name.grid(row=3, column=0) contact_person_first_name.grid(row=4, column=0) contact_person_last_name.grid(row=5,column=0) phone_number.grid(row=6, column=0) street.grid(row=7, column=0) city.grid(row=8, column=0) state.grid(row=9, column=0) postal_code.grid(row=10, column=0) cp_title.grid(row=11, column=0) # text entry box tax_id_no = Entry(root) email = Entry(root) business_name = Entry(root) contact_person_first_name = Entry(root) contact_person_last_name = Entry(root) phone_number = Entry(root) street = Entry(root) city = Entry(root) state = Entry(root) postal_code = Entry(root) cp_title = Entry(root) # grid for inputs tax_id_no.grid(row=1, column=1, ipadx="100") email.grid(row=2, column=1, ipadx="100") business_name.grid(row=3, column=1, ipadx="100") contact_person_first_name.grid(row=4, column=1, ipadx="100") contact_person_last_name.grid(row=5, column=1, ipadx="100") phone_number.grid(row=6, column=1, ipadx="100") street.grid(row=7, column=1, ipadx="100") city.grid(row=8, column=1, ipadx="100") state.grid(row=9, column=1, ipadx="100") postal_code.grid(row=10, column=1, ipadx="100") cp_title.grid(row=11, column=1, ipadx="100") record = (email,phone_number,street,postal_code,city,state,tax_id_no,business_name,contact_person_first_name,contact_person_last_name,cp_title) # create a Submit Button and place into the root window submit = Button(root, text="Submit", fg="Black", bg="Red", command=lambda m=root,r=record:self.insert_business_customer(m,r)) submit.grid(row=13, column=1) def add_individual_customer(self): root = Tk() root.configure(background='white') root.title("Add Customer Form") root.geometry("500x350") heading = Label(root, text="Add Individual Customer", bg="white") self.dln = Label(root, text="driver license number", bg="white") self.email = Label(root, text="email", bg="white") self.first_name = Label(root, text="firstname", bg="white") self.last_name = Label(root, text="lastname", bg="white") self.phone_number = Label(root, text="phone number", bg="white") self.street = Label(root, text="street", bg="white") self.city = Label(root, text="city", bg="white") self.state = Label(root, text="state", bg="white") self.postal_code = Label(root, text="postal code", bg="white") heading.grid(row=0, column=1) self.dln.grid(row=1, column=0) self.email.grid(row=2, column=0) self.first_name.grid(row=3, column=0) self.last_name.grid(row=4, column=0) self.phone_number.grid(row=5, column=0) self.street.grid(row=6, column=0) self.city.grid(row=7, column=0) self.state.grid(row=8, column=0) self.postal_code.grid(row=9, column=0) # text entry box self.dln = Entry(root) self.email = Entry(root) self.first_name = Entry(root) self.last_name = Entry(root) self.phone_number = Entry(root) self.street = Entry(root) self.city = Entry(root) self.state = Entry(root) self.postal_code = Entry(root) # grid for inputs self.dln.grid(row=1, column=1, ipadx="100") self.email.grid(row=2, column=1, ipadx="100") self.first_name.grid(row=3, column=1, ipadx="100") self.last_name.grid(row=4, column=1, ipadx="100") self.phone_number.grid(row=5, column=1, ipadx="100") self.street.grid(row=6, column=1, ipadx="100") self.city.grid(row=7, column=1, ipadx="100") self.state.grid(row=8, column=1, ipadx="100") self.postal_code.grid(row=9, column=1, ipadx="100") # create a Submit Button and place into the root window submit = Button(root, text="Submit", fg="Black", bg="Red", command=lambda m=root:self.insert_individual_customer(m)) submit.grid(row=11, column=1) def lookup_customer_info(self): root = Toplevel() root.configure(background='white') root.title("lookup or add customer") root.geometry("500x350") add_individual_customer = Button(root, text="Add Individual Customer", fg="Black", bg="Red", command=self.add_individual_customer) add_individual_customer.pack() add_business_customer = Button(root, text="Add Business Customer", fg="Black", bg="Red", command=self.add_business_customer) add_business_customer.pack() Label(root, text="""Choose the customer type to search on""", justify=LEFT, padx=20).pack() self.v = IntVar() filters = [ ("Business Customer", 1), ("Individual Customer", 2)] for val, fil in enumerate(filters): Radiobutton(root, text=fil[0], padx=20, justify=LEFT, variable=self.v, command=self.show_choice, value=val).pack() SearchBox(root, command = self.list_customers, command_arguments=(root,), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) def show_choice(self): pass def show_add_vehicle_form(self): root = Tk() root.configure(background='#e2e8f0') root.title("Add Vehicle") root.geometry("500x400") heading = Label(root, text="Add Vehicle Form", bg="#e2e8f0") self.seller_uid = Label(root, text="Seller UID", bg="#e2e8f0") self.vin = Label(root, text="VIN", bg="#e2e8f0") self.vehicle_type = Label(root, text="Vehicle Type", bg="#e2e8f0") self.cost = Label(root, text="Cost", bg="#e2e8f0") self.model_name = Label(root, text="Model Name", bg="#e2e8f0") self.model_year = Label(root, text="Model Year", bg="#e2e8f0") self.manu_id = Label(root, text="Manufacturer ID", bg="#e2e8f0") self.milage = Label(root, text="Odometer", bg="#e2e8f0") self.color = Label(root, text="Color(s)", bg="#e2e8f0") self.desc = Label(root, text="Description", bg="#e2e8f0") self.condition = Label(root, text="Vehicle Condition", bg="#e2e8f0") self.buy_date = Label(root, text="Buy Date", bg="#e2e8f0") #grid heading.grid(row=0, column=1) self.seller_uid.grid(row=1, column=0) self.vin.grid(row=2, column=0) self.vehicle_type.grid(row=3, column=0) self.cost.grid(row=4, column=0) self.model_name.grid(row=5, column=0) self.model_year.grid(row=6, column=0) self.manu_id.grid(row=7, column=0) self.milage.grid(row=8, column=0) self.color.grid(row=9, column=0) self.desc.grid(row=10, column=0) self.condition.grid(row=11, column=0) self.buy_date.grid(row=12, column=0) #text entry box self.seller_uid = Entry(root) self.vin = Entry(root) self.vehicle_type = Entry(root) self.cost = Entry(root) self.model_name = Entry(root) self.model_year = Entry(root) self.manu_id = Entry(root) self.milage = Entry(root) self.color = Entry(root) self.desc = Entry(root) self.condition = Entry(root) self.buy_date = Entry(root) #grid for inputs self.seller_uid.grid(row=1, column=1, ipadx="100") self.vin.grid(row=2, column=1, ipadx="100") self.vehicle_type.grid(row=3, column=1, ipadx="100") self.cost.grid(row=4, column=1, ipadx="100") self.model_name.grid(row=5, column=1, ipadx="100") self.model_year.grid(row=6, column=1, ipadx="100") self.manu_id.grid(row=7, column=1, ipadx="100") self.milage.grid(row=8, column=1, ipadx="100") self.color.grid(row=9, column=1, ipadx="100") self.desc.grid(row=10, column=1, ipadx="100") self.condition.grid(row=11, column=1, ipadx="100") self.buy_date.grid(row=12, column=1, ipadx="100") # create a Submit Button and place into the root window submit = Button(root, text="Submit", fg="Black", bg="#ADD8E6", command=lambda w=root: self.insert(root)) submit.grid(row=14, column=1) lookup_customer = Button(root, text="Search Customer", fg="Black", bg="#ADD8E6", command=self.lookup_customer_info) lookup_customer.grid(row=15, column=1) # start the GUI root.mainloop() def popup_window(self, title, message): global popup_win popup_win = Tk() popup_win.title(title) popup_win.geometry("250x100") Label(popup_win, text=message).pack() Button(popup_win, text="OK", command=self.delete_popup_window).pack() popup_win.mainloop() def delete_popup_window(self): popup_win.destroy()
class PublicPage: def __init__(self, window): self.dao = Dao().get_instance() self.records = None self.table = None self.message = None self.public_page_service = PublicPageService() self.main_screen = window self.public_screen = None self.v = None def get_vehicles_model_type(self, vehicle_type, pp_service): return pp_service.list_vehicles_vehicle_type(vehicle_type) def get_vehicles_manufacturer(self,mfg_name, pp_service): return pp_service.list_vehicle_mfg_name(mfg_name) def get_vehicles_model_year(self,model_year, pp_service): return pp_service.list_vehicle_model_year(model_year) def get_vehicle_color(self, color, pp_service): return pp_service.list_vehicle_color(color) def get_vehicle_any_keyword(self, keyword, pp_service): return pp_service.list_vehicle_any_keyword(keyword) def list_public_vehicles(self, filter_text, arguments): options = {0: "get_vehicles_model_type", 1: "get_vehicles_manufacturer", 2: "get_vehicles_model_year", 3: "get_vehicle_color", 4: "get_vehicle_any_keyword" } public_page_service = PublicPageService() self.records = getattr(self, options.get(self.v.get()))(filter_text, public_page_service) if len(self.records) > 0: if self.table is not None: self.table.sdem.destroy() self.table = TableSheet(self.records, ["vin", "vehicle type", "model year", "model", "Odometer", "selling price", "manufacturer", "color"], self.public_screen) self.table.sdem.bind("<Double-Button-1>", self.show_vehicle_detail_page) if self.message is not None: self.message.destroy() self.message = None else: if self.message is None: self.message = Label(self.public_screen, text="Sorry, it looks like we don’t have that in stock!", bg="white") self.message.pack() def show_vehicle_detail_page(self, event): rows = self.table.sdem.get_selected_rows(get_cells=True) record = self.table.records[rows[0]] root = Tk() root.geometry("800x600") root.configure(background="#e2e8f0") root.title("##Vehicle Details##") vin = Label(root, text="VIN:",bg="#e2e8f0") vin_dat = Label(root, text=record[0],bg="#e2e8f0") v_type = Label(root, text="Vehicle Type:",bg="#e2e8f0") v_type_dat = Label(root, text=record[1],bg="#e2e8f0") v_model_year = Label(root, text="Vehicle Model Year:", bg="#e2e8f0") v_model_year_dat = Label(root, text=record[2], bg="#e2e8f0") v_model = Label(root, text="Vehicle Model:", bg="#e2e8f0") v_model_dat = Label(root, text=record[3], bg="#e2e8f0") v_odometer = Label(root, text="Vehicle Odometer:", bg="#e2e8f0") v_odometer_dat = Label(root, text=record[4], bg="#e2e8f0") v_selling_price = Label(root, text="Selling Price:", bg="#e2e8f0") v_selling_price_dat = Label(root, text=record[5], bg="#e2e8f0") v_mfg = Label(root, text="Manufacturer:", bg="#e2e8f0") v_mfg_dat = Label(root, text=record[6] ,bg="#e2e8f0") v_color = Label(root, text="Color(s):", bg="#e2e8f0") v_color_dat = Label(root, text=record[7], bg="#e2e8f0") v_desc = Label(root, text="Description", bg="#e2e8f0") v_desc_dat = Label(root, text=self.dao.get_vehicle_description(record[0])[0], bg="#e2e8f0") vin.grid(row=1,column=0) vin_dat.grid(row=1, column = 1) v_model_year.grid(row=3,column=0) v_model_year_dat.grid(row=3,column=1) v_type.grid(row=5,column=0) v_type_dat.grid(row=5,column=1) v_model.grid(row=7,column=0) v_model_dat.grid(row=7,column=1) v_odometer.grid(row=9,column=0) v_odometer_dat.grid(row=9,column=1) v_selling_price.grid(row=11,column=0) v_selling_price_dat.grid(row=11,column=1) v_mfg.grid(row=13,column=0) v_mfg_dat.grid(row=13,column=1) v_color.grid(row=15,column=0) v_color_dat.grid(row=15,column=1) v_desc.grid(row=17,column=0) v_desc_dat.grid(row=17,column=1) root.mainloop() def show_public_page(self): self.public_screen = Toplevel(self.main_screen) self.public_screen.title("Public Page") self.public_screen.geometry("600x500") Label(self.public_screen, text="Total Number of cars available for purchase", bg="white").pack() public_page_service = PublicPageService() Label(self.public_screen, text=public_page_service.vehicle_available_for_purchase()).pack() self.v = IntVar() filters = [ ("Vehicle Type", 1), ("Manufacturer", 2), ("Model year", 3), ("Color", 4), ("Keyword", 5) ] Label(self.public_screen, text="""Choose the filter to filter Vehicles""", justify=LEFT, padx=20).pack() for val, fil in enumerate(filters): Radiobutton(self.public_screen, text=fil[0], padx=20, justify=LEFT, variable=self.v, command=self.show_choice, value=val).pack() SearchBox(self.public_screen, command=self.list_public_vehicles, command_arguments=(), placeholder="Type and press enter", entry_highlightthickness=0).pack(pady=6, padx=3) Label(self.public_screen, text="*Double click on row number to view respective vehicle details", justify=LEFT, padx=20).pack() def show_choice(self): pass
class DashboardService: def __init__(self, main_screen): self.dao = Dao().get_instance() self.main_screen = main_screen self.utype = None self.username = None def show_dashboard(self, uname, passwd): dashboard_menu = [] self.username = uname utype = self.dao.get_user_type(uname, passwd) self.utype = utype[0][0] if self.utype == const.CLERK: #TODO: Add Vehicle has to have search or add customer options dashboard_menu = ["Add Vehicle", "View Vehicles", "Place/Update Part Order", "Lookup Parts"] elif self.utype == const.SALESPERSON: dashboard_menu = ["View and Sell Vehicle"] elif self.utype == const.MANAGER: dashboard_menu = ["View Vehicle", "Seller History Report", "Average Time in Inverntory Report", "Price Per Condition Report", "Parts Statistics Report", "Monthly Loan Income Report", "Monthly Sales Report"] elif self.utype == const.BURDELL: dashboard_menu = ["Add Vehicle", "View Vehicle", "Place/Update Part Order", "View Vehicle and Update Sales Info", "Seller History Report", "Average Time in Inverntory Report", "Price Per Condition Report", "Parts Statistics Report", "Monthly Loan Income Report", "Monthly Sales Report" ] dashboard_title = "Dashboard for {0}, you are welcome {1}".format(self.utype, uname) self.generic_dashboard(dashboard_title, dashboard_menu) def populateMethod(self, method, window): if method == "Add Vehicle": add_vehicle_obj = AddVehicleService(self.main_screen) add_vehicle_obj.show_add_vehicle_form() if method == "Place/Update Part Order": part_order_obj = PartOrderService() part_order_obj.show_part_order_form() if method == "View Vehicles" and self.utype == const.CLERK: view_vehicle_service = ViewVehicleService(self.main_screen, self.utype) view_vehicle_service.show_clerk_view_vehicle_page() if method == "View and Sell Vehicle" and self.utype == const.SALESPERSON: sell_vehicle = SellVehicleService(self.main_screen,self.username) sell_vehicle.show_vehicle_for_sale() if method == "View Vehicle and Update Sales Info" and self.utype == const.BURDELL: sell_vehicle = SellVehicleService(self.main_screen, self.username) sell_vehicle.show_vehicle_for_sale() if method == "View Vehicle": view_vehicle_service = ViewVehicleService(self.main_screen, self.utype) view_vehicle_service.show_manager_view_vehicle_page() if method == "Lookup Parts": lookup_parts = LookupParts(self.main_screen) lookup_parts.show_vehicle_parts() if method == "Seller History Report": Report(self.main_screen).seller_history_report() if method == "Average Time in Inverntory Report": Report(self.main_screen).average_time_in_inventory_report() if method == "Price Per Condition Report": Report(self.main_screen).price_per_condition_report() if method == "Monthly Loan Income Report": Report(self.main_screen).monthly_loan_income_report() if method == "Parts Statistics Report": Report(self.main_screen).parts_statistics_report() if method == "Monthly Sales Report": report = Report(self.main_screen) report.monthly_sales_report() def generic_dashboard(self, title, dashboard_menu): window = Tk() window.geometry("500x350") window.configure(background="#e2e8f0") window.title(title) for method in dashboard_menu: button = Button(window, text=method, command=lambda m=method,w=window: self.populateMethod(m,window), bg="#ADD8E6", width=200) button.pack() window.mainloop()