def addItem(hold_num): order = customerOrderDAO.select_by_hold_number(hold_num) listHeader = ("Hold Num:", "Customer Name:", "Date Made:", "Delivery Address:", "Phone#:", "Total Cost") print('{0:>5} {1:>23} {2:>12} {3:>25} {4:>20} {5:>20}'.format(*listHeader)) list = ( order.get_hold_num(), str(customerDAO.select_by_phone(order.get_phone_num()).get_lname()) + ", " + str(customerDAO.select_by_phone(order.get_phone_num()).get_fname()), order.get_date_made(), order.get_delivery_address(), order.get_phone_num(), order.get_total_cost()) print('{0:>5} {1:>26} {2:>12} {3:>25} {4:>20} {5:>20}'.format(*list)) print("") items = itemDAO.select_by_hold_num(hold_num) listHeader = ("NTD#:", "Quantity:", "Cost of Product:", "Carton Count:", "Piece count:") print('{0:>15} {1:>17} {2:>22} {3:>18} {4:>15}'.format(*listHeader)) for item in items: list = (item.get_ntd_num(), item.get_quantity(), item.get_total_cost(), calculateCartonCount(item.get_quantity(), item.get_ntd_num()), calculatePieceCount(item.get_quantity(), item.get_ntd_num())) print('{0:>15} {1:>17} {2:>22} {3:>18} {4:>15}'.format(*list)) print("") while True: print( "Enter the NTD# for the item you would like to add or press 1 to quit" ) ntd_num = input() if ntd_num == "1": break valid_ntd_num = verifyNTDNumAdd(ntd_num) if valid_ntd_num == False: print( "The NTD# you tried to search by is invalid, please try again") print("") else: item_list = itemDAO.select_by_hold_num(hold_num) found = False for item in item_list: if item.get_ntd_num() == ntd_num: print("Item is already in customer order") found = True if not found: item = Item() item.set_hold_num(hold_num) item.set_ntd_num(ntd_num) while True: print( "Enter desired quantity of product, if grout enter number of bags, if tile enter square footage" ) desired_quantity = input() if float(desired_quantity) > float( productDAO.select_by_ntd_num( ntd_num).get_amt_in_stock()): print("Not enough quantity in warehouse!") else: break item.set_quantity(desired_quantity) cost = float(item.get_quantity()) * float( productDAO.select_by_ntd_num( item.get_ntd_num()).get_cost_per_sf()) product = productDAO.select_by_ntd_num(ntd_num) newSquareFootage = float(product.get_amt_in_stock()) - float( item.get_quantity()) newCartonCount = int( float(newSquareFootage) / float(product.get_sf_per_carton())) newPieceCount = int((float(newSquareFootage) % float(product.get_sf_per_carton())) / float(product.get_size_of_product())) product.set_amt_in_stock(str(newSquareFootage)) product.set_carton_count(str(newCartonCount)) product.set_piece_count(str(newPieceCount)) productDAO.update(product) total_cost_of_item = float(cost) item.set_total_cost(str(cost)) item.set_hold_num(hold_num) itemDAO.insert_item(item) customerOrder = customerOrderDAO.select_by_hold_number( hold_num) customerOrder.set_total_cost( float(total_cost_of_item) + float(customerOrder.get_total_cost())) customerOrderDAO.update(customerOrder) break
def create_order(): print("Connecting to database...") customer_dao = CustomerDAO() customer_order_dao = CustomerOrderDAO() customer_order = CustomerOrder() product_dao = ProductDAO() item_dao = ItemDAO() employee_dao = EmployeeDAO() found = False list_of_employees = employee_dao.select_all() salesperson_num = 0 while not found: print("Enter in salesperson number") salesperson_num = input() for emp in list_of_employees: if emp.get_salesperson_num() == salesperson_num: found = True if not found: print("No employee with that salesperson number") print("Please enter customer phone number ") phone_num = input() customer = customer_dao.select_by_phone(str(phone_num)) customer_order.set_phone_num(customer.get_phone()) customer_order.set_salesperson_num(salesperson_num) print("Please enter today's date ") date = input() customer_order.set_date_made(date) hold_num = generate_hold_num() customer_order.set_hold_num(hold_num) print("Please enter description of where tile will be located ") customer_order.set_description(input()) print("Please enter delivery address") customer_order.set_delivery_address(input()) customer_order.set_total_cost( 0.00) #Initialize to 0 we will manipulate this after customer_order_dao.insert_customer_order(customer_order) list_of_products = product_dao.select_all() done = True total_cost = 0 while done: found = False item = Item() while not found: print("Enter product NTD number") ntd_num = input() for x in list_of_products: if x.get_ntd_num() == ntd_num: item.set_ntd_num(ntd_num) found = True if not found: print("Wrong NTD number") while True: print( "Enter desired quantity of product, if grout enter number of bags, if tile enter square footage" ) desired_quantity = input() if float(desired_quantity) > float( product_dao.select_by_ntd_num(ntd_num).get_amt_in_stock()): print("Not enough quantity in warehouse!") else: break item.set_quantity(desired_quantity) cost = float(item.get_quantity()) * float( product_dao.select_by_ntd_num( item.get_ntd_num()).get_cost_per_sf()) total_cost = float(total_cost) + float(cost) item.set_total_cost(str(cost)) item.set_hold_num(hold_num) item_dao.insert_item(item) product = product_dao.select_by_ntd_num(item.get_ntd_num()) newSquareFootage = float(product.get_amt_in_stock()) - float( item.get_quantity()) newCartonCount = int( float(newSquareFootage) / float(product.get_sf_per_carton())) newPieceCount = int( (float(newSquareFootage) % float(product.get_sf_per_carton())) / float(product.get_size_of_product())) product.set_amt_in_stock(str(newSquareFootage)) product.set_carton_count(str(newCartonCount)) product.set_piece_count(str(newPieceCount)) product_dao.update(product) print("Enter another product?\n" "Press 1 for yes\n" "Press 2 to complete the order") choice = input() if choice == "2": customerOrder = customer_order_dao.select_by_hold_number( customer_order.get_hold_num()) customerOrder.set_total_cost(total_cost) customer_order_dao.update(customerOrder) print("Customer's order hold number is " + str(hold_num)) done = False