def select_receipt_for_report_by_month_year(request): month = request.split("|")[0] year = request.split("|")[1] info = [] try: for el in SQLS.db_fetch( "SELECT * " "FROM receipts " "WHERE MONTH(dateCreated) = %s " "AND YEAR(dateCreated) = %s " "AND transactionType = '%s' " "ORDER BY deptCode;" % (month, year, "CHARGE BACK") ): for ell in el: info.append(str(ell)) info.append("|") info.append("%") info.pop(-1) if info[-1] == "|": info.pop(-1) except: info.append("NA") SQLS.output_update_to_screen("Request for report by month and year . -> ") return info
def select_sales_information(): info = [] for el in SQLS.db_fetch("SELECT * FROM information WHERE idinformation = 0;"): for ell in el: info.append(str(ell)) info.append("|") info.pop(-1) SQLS.output_update_to_screen("Request for sales information. -> ") return info
def closing_by_id(request): info = [] id = request[2] cells = request[3].split("|") info.append(str(SQLS.db_update( "UPDATE closings SET startDate = '%s', endDate = '%s', " "calculatedAmount = %s, drawerAmount = %s, comments = '%s'" "WHERE idclosings = %s;" % (cells[0], cells[1], cells[2], cells[3], cells[4], id) ))) SQLS.output_update_to_screen("Edited closing : %s" % id ) return info
def select_department_information(): info = [] try: for el in SQLS.db_fetch("SELECT * FROM departmentInformation ORDER BY deptName;"): for ell in el: info.append(str(ell)) info.append("|") info.append("%") info.pop(-1) if info[-1] == "|": info.pop(-1) except: info.append("NA") SQLS.output_update_to_screen("Request for department list. -> ") return info
def select_inventory(): info = [] try: for el in SQLS.db_fetch("SELECT * FROM inventory WHERE quantity > 0 OR price = 0 ORDER BY itemName;"): for ell in el: info.append(str(ell)) info.append("|") info.append("%") info.pop(-1) if info[-1] == "|": info.pop(-1) except: info.append("NA") SQLS.output_update_to_screen("Request for inventory list. -> ") return info
def select_receipts_by_descriptor(range, switch): info = [] first_date = range.split("|")[0] second_date = range.split("|")[1] query = "" if switch == "1": query = ("SELECT * FROM receipts " "WHERE transactionType != 'CHARGE BACK' " "AND DATE(dateCreated) between DATE('%s') AND DATE('%s');" % (first_date, second_date)) if switch == "2": query = ("SELECT * FROM receipts " "WHERE transactionType = 'CHARGE BACK' " "AND DATE(dateCreated) between DATE('%s') AND DATE('%s');" % (first_date, second_date)) if switch == "3": query = ("SELECT * FROM receipts " "WHERE DATE(dateCreated) between DATE('%s') AND DATE('%s');" % (first_date, second_date)) try: for el in SQLS.db_fetch(query): for ell in el: info.append( str(ell).replace('\n', '')) info.append("|") info.append("%") info.pop(-1) if info[-1] == "|": info.pop(-1) except: info.append("NA") print info SQLS.output_update_to_screen("Request for receipts between %s , and %s -> " % (first_date, second_date)) return info
def delete_receipt_by_id(id): # Get items from receipt items_sold = "" try: items_sold = SQLS.db_fetch( "SELECT itemsSold FROM receipts WHERE receiptId = %s;" % id )[0][0] except: SQLS.output_update_to_screen("Unable to fetch items sold in receipt id : %s ." % id ) # Add their quantities back into inventory if items_sold != "": for el in items_sold.split(","): item_id = el.split("#")[0] quantity = int(el.split("#")[1]) # If the item isn't a general library item, update quantity if item_id != "94": current_item_quantity = int(SQLS.db_fetch("SELECT quantity FROM inventory WHERE inventoryId = %s;" % item_id)[0][0]) updated_quantity = current_item_quantity + quantity SQLS.db_update("UPDATE inventory SET quantity = %s WHERE inventoryId = %s;" % (updated_quantity, item_id)) else: # If it is a general lib item, set to 0 SQLS.db_update("UPDATE inventory SET quantity = %s WHERE inventoryId = 0;") # Delete receipt info = [] info.append(str(SQLS.db_update( "DELETE FROM receipts WHERE receiptId = %s;" % id ))) return info
def handle(self): reply = None # Receive data from client self.data = self.request.recv(settings.BLOCK).split("^") if self.data[0] in recognized_queries: reply = request_handler.request_handler(self.data) if self.data[0] not in recognized_queries: reply = "?" settings.output_update_to_screen("UNRECOGNIZED QUERY !") settings.output_update_to_screen(self.data) if reply is not None: self.request.send(reply) self.request.close()