def increase_quantity(value_tuple, quantity):
    """THis function decreases the quantity of the function whaen purchased"""
    try:

        p = str(value_tuple[3])
        check_quantity_formula = "SELECT quantity FROM inventory WHERE item_type = '" + value_tuple[
            0] + "'  and   gender  = '" + value_tuple[
                1] + "' and size  = '" + value_tuple[
                    2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                        4] + "' and brand = '" + value_tuple[5] + "'"
        mycursor.execute(check_quantity_formula)
        data = mycursor.fetchall()
        quantity_available = int(data[0][0])
        final_quantity = int(quantity_available) + int(quantity)
        f = "UPDATE inventory  SET quantity = '" + str(
            final_quantity
        ) + "' WHERE item_type = '" + value_tuple[
            0] + "'  and   gender  = '" + value_tuple[
                1] + "' and size  = '" + value_tuple[
                    2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                        4] + "' and brand = '" + value_tuple[5] + "'"
        mycursor.execute(f)
        mycon.commit()
        bf.hanprt("Quantity increased.")
    except:
        bf.hanprt("Sorry an error occured in decreasing the quantiy")
def process_o_input(scaned_set, o_input):
    """This functions processes the scanned set and returns the processes output or query"""
    try:
        if (scaned_set == (set(
            [r"add", r"stock(s)?", r"new"]))) or (scaned_set == (set(
                [r"add", r"stock(s)?"]))) or (scaned_set == (set([
                    r"add", r"item(s)?", r"new"
                ]))) or (scaned_set == (set([r"add", r"item(s)?"]))):

            odb.check_and_add_new_stocks(
                ask_entire_stock(bf.get_attribute(o_input)))

        elif ((scaned_set == (set([r"show", r"stock(s)?"]))) or
              (scaned_set == (set([r"display", r"stock(s)?"]))) or
              (scaned_set == (set([r"print(s)?", r"stock(s)?"])))) or (
                  (scaned_set == (set([r"show", r"item(s)?"]))) or
                  (scaned_set == (set([r"display", r"item(s)?"]))) or
                  (scaned_set == (set([r"print(s)?", r"item(s)?"])))):
            display_stocks(odb.show_stocks(bf.get_attribute(o_input)))
        elif ((scaned_set == (set([r"show", r"profile(s)?"])))
              or (scaned_set == (set([r"display", r"profile(s)?"])))
              or (scaned_set == (set([r"print(s)?", r"profile(s)?"])))
              or (scaned_set == (set([r"profile(s)?"])))):
            display_profile(odb.get_data_of_profile(which_profile(o_input)))

        else:
            cb.chat(o_input)

        return scaned_set
    except:
        bf.hanprt("Sorry an error occured in proccessing the input")
def give_small_size(value_tuple):
    try:
        global last_viewed_tuple
        global cur_item_tuple
        value_list = list(value_tuple)
        if value_list[2] == "s":
            bf.hanprt("Sorry we don't have any size smaller than S")
        else:    
            if value_tuple[2] == "xxxl":
                value_list[2] = "xxl"
            if value_tuple[2] == "xxl":
                value_list[2] = "xl"
            if value_tuple[2] == "xl":
                value_list[2] = "l"
            if value_tuple[2] == "l":
                value_list[2] = "m"
            if value_tuple[2] == "m":
                value_list[2] = "s"

            bf.random_pr_string(("No problem I will  give you a small size"
                                ,"No problem"
                                ,"Sure"
                                ,"This is smalller"
                                ,"I hope this will fit you"
                                ,"Try this size"))
           
            value_tuple_2 = tuple(value_list)
            last_viewed_tuple =  value_tuple_2
            cur_item_tuple =  value_tuple_2
            data_list = udb.items_available_to_buy(value_tuple_2)
            showcase_designs(data_list)
            #prev_item_tuple =  value_tuple_2
    except:
        bf.hanprt("Sorry an error occured in getting you the small size")
def delete_empty_stock(value_tuple):
    """THis function deletes the empty stock when quantity becomes zero"""
    try:

        p = str(value_tuple[3])
        check_quantity_formula = "SELECT quantity FROM inventory WHERE item_type = '" + value_tuple[
            0] + "'  and   gender  = '" + value_tuple[
                1] + "' and size  = '" + value_tuple[
                    2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                        4] + "' and brand = '" + value_tuple[5] + "'"
        mycursor.execute(check_quantity_formula)
        data = mycursor.fetchall()
        quantity_available = int(data[0][0])
        #final_quantity = int(quantity_available) - int(quantity)
        if quantity_available == 0:
            #f = "UPDATE inventory  SET quantity = '"+ str(final_quantity) + "' WHERE item_type = '" + value_tuple[0]  + "'  and   gender  = '" + value_tuple[1]  + "' and size  = '" + value_tuple[2] + "'and prize = '" + p+ "' and colour = '" + value_tuple[4] + "' and brand = '" + value_tuple[5] + "'"
            f = "DELETE FROM inventory  WHERE item_type = '" + value_tuple[
                0] + "'  and   gender  = '" + value_tuple[
                    1] + "' and size  = '" + value_tuple[
                        2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                            4] + "' and brand = '" + value_tuple[5] + "'"
            mycursor.execute(f)
            mycon.commit()
    except:
        bf.hanprt("Sorry an error occured in deleting the empty stocks")
def give_big_size(value_tuple):
    try:
        global last_viewed_tuple
        global cur_item_tuple
        value_list = list(value_tuple)
        if value_list[2] == "xxxl":
            bf.hanprt("Sorry we only have upto size XXXL")
        else:    
            if value_tuple[2] == "s":
                value_list[2] = "m"
            if value_tuple[2] == "m":
                value_list[2] = "l"
            if value_tuple[2] == "l":
                value_list[2] = "xl"
            if value_tuple[2] == "xl":
                value_list[2] = "xxl"
            if value_tuple[2] == "xxl":
                value_list[2] = "xxxl"

            bf.random_pr_string(("No problem I will give you a bigger size"
                                ,"No problem"
                                ,"Sure"
                                ,"This is bigger"
                                ,"I hope this will fit you"
                                ,"Try this size"))
           
            value_tuple_2 = tuple(value_list)
            last_viewed_tuple =  value_tuple_2
            cur_item_tuple =  value_tuple_2
            data_list = udb.items_available_to_buy(value_tuple_2)
            showcase_designs(data_list)
    except:
        bf.hanprt("Sorry an error occured in getting you the big size")
def ask_customer_name():
    """This function asks the customers name"""
    try:
        bf.hanprt("Whats the username?")
        c_name = bf.ask_input()
        return c_name
    except:
        bf.hanprt("Sorry an error occured in asking the customer name")
def buy_what(u_input):
    try:
        """This function scans the text and searches what you want to buy"""
        value_tuple = bf.get_attribute(u_input)

        return value_tuple
    except:
        bf.hanprt("Sorry an error occured in finding what to buy")
def clear_cart(username):
    try:
        """THis function deletes all the items in the cart"""
        f = "DELETE FROM " + str(username) + "_cart"
        mycursor.execute(f)
        mycon.commit()

    except:
        bf.hanprt("Sorry an error occured in clearing the cart")
def create_profile(username):
    try:
        """CREATING the user profile"""
        
        if(bool(udb.check_table(str(username)+"_profile"))):
            bf.random_pr_string(("Welcome again." , "We love to see your face... Welcome again"))
        else:

            udb.create_profile_table(username)
            pass#del
    except:
        bf.hanprt("Sorry an error occured in creating new profie")
def remove_from_cart(value_tuple, username):
    """This function removes item from cart
    f = "DELETE FROM "+ str(username)  + "_cart"
        mycursor.execute(f)
        mycon.commit()    """
    """
    #del_to_cart  = "DELETE FROM "+ username +"_cart (item_type , gender , size  , prize , colour , brand , quantity , amount) VALUES (%s ,%s , %s , %s , %s , %s , %s ,%s)"
    del_to_cart  = "DELETE FROM "+ username +"_cart (item_type , gender , size  , prize , colour , brand ) VALUES (%s ,%s , %s , %s , %s , %s """
    try:
        filter_0 = ""
        filter_1 = ""
        filter_2 = ""
        filter_3 = ""
        filter_4 = ""
        filter_5 = ""
        filter_6 = ""
        additional_statement = ""  #where clause
        if value_tuple[0] != "":
            filter_0 = "item_type = '" + value_tuple[0] + "' and "
        if value_tuple[1] != "":
            filter_1 = "gender = '" + value_tuple[1] + "' and "
        if value_tuple[2] != "":
            filter_2 = "size = '" + value_tuple[2] + "'  and "
        if value_tuple[3] != "":
            filter_3 = "prize = '" + value_tuple[3] + "'  and "
        if value_tuple[4] != "":
            filter_4 = "colour = '" + value_tuple[4] + "'  and "
        if value_tuple[5] != "":
            filter_5 = "brand = '" + value_tuple[5] + "'  and "
        if value_tuple[6] != "":
            filter_6 = "quantity = '" + value_tuple[6] + "'  and "

        if ((value_tuple[0] != "") or (value_tuple[1] != "")
                or (value_tuple[2] != "") or (value_tuple[3] != "")
                or (value_tuple[4] != "") or (value_tuple[5] != "")
                or (value_tuple[6] != "")):
            additional_statement = "WHERE "

        DISPLAYING_FORMULA = "DELETE FROM " + username + "_cart     " + additional_statement + filter_0 + filter_1 + filter_2 + filter_3 + filter_4 + filter_5 + filter_6
        d = DISPLAYING_FORMULA[0:-4]
        mycursor.execute(d)

        #mycursor.execute(del_to_cart , value_tuple)
        mycon.commit()
        bf.random_pr_string(
            ("Removed from cart", "Item deleted from cart",
             "Item removed to cart", "Removed", "Done", "Deleted"))

    except:
        bf.hanprt("Sorry an error occured in removing from cart from database")
def process_u_input(scaned_set , u_input):
    """This functions processes the scanned set and returns the processes output or query"""
    try:    
        global cur_item_tuple
        global cur_item_list
        global prev_item_tuple
        global prev_item_list
        global last_viewed_tuple
        global last_viewed_list
        if (scaned_set == (set([r"item(s)?",r"buy(ing)?"]))) or (scaned_set ==(set([r"item(s)?",r"show"]))) or (scaned_set ==(set([r"like",r"see"]))) or (scaned_set ==(set([r"like",r"purcha(s|c)e"]))) or (scaned_set ==(set([r"want",r"see"]))) or (scaned_set ==(set([r"want",r"purcha(s|c)e"]))) or  (scaned_set ==(set([r"buy(ing)?"]))) or  (scaned_set ==(set([r"purcha(s|c)e"]))) or (scaned_set ==(set([r"want",r"buy(ing)?"]))) or (scaned_set ==(set([r"buy(ing)?"]))) or (scaned_set ==(set([r"want",r"purcha(s|c)e"])))  or (scaned_set == (set([r"item(s)?",r"purcha(s|c)e"]))) or (scaned_set ==(set([r"item(s)?",r"show"]))) or (scaned_set ==(set([r"like",r"see"]))) or (scaned_set ==(set([r"item(s)?",r"display"]))):
            
            cur_item_list = list(ask_items_to_buy(buy_what(u_input)))
            cur_item_tuple = tuple(cur_item_list)
            data_list = udb.items_available_to_buy(cur_item_tuple)
            showcase_designs(data_list)
            last_viewed_list = cur_item_list
            last_viewed_tuple = tuple(last_viewed_list)
            
            
        elif(scaned_set == (set([r"add",r"cart"]))):
            #global cur_item_tuple
            udb.add_to_cart(ask_item_to_add_to_cart(bf.merge_tuple_value(cur_item_tuple,buy_what(u_input))),username)
            prev_item_list = prev_item_list
            prev_item_tuple = cur_item_tuple
        elif(scaned_set == (set([r"show",r"cart"]))) or (scaned_set == (set([r"display",r"cart"]))) or (scaned_set == (set([r"what(s)?",r"cart"]))) or (scaned_set == (set([r"see",r"cart"]))) :
            """Print cart"""
            print_cart(udb.data_of_cart(username))
        elif(scaned_set == (set([r"bill(s|ing)?"]))) or (scaned_set == (set([r"bill(s|ing)?" ,r"show" ]))) or (scaned_set == (set([r"bill(s|ing)?" ,r"give" ]))) or (scaned_set == (set([r"bill(s|ing)?" ,r"display" ]))) :
            create_bill(username)
        elif(scaned_set == (set([r"big(ger)?" ,r"show" ]))) or (scaned_set == (set([r"big(ger)?" ,r"give" ]))) or (scaned_set == (set([r"big(ger)?" ,r"display" ]))) or  (scaned_set == (set([r"big(ger)?"])))  or (scaned_set == (set([r"increase(d)? (the )?size(s)?"]))) :
            give_big_size(last_viewed_tuple)
        elif(scaned_set == (set([r"small(er)?" ,r"show" ]))) or (scaned_set == (set([r"small(er)?" ,r"give" ]))) or (scaned_set == (set([r"small(er)?" ,r"display" ]))) or  (scaned_set == (set([r"small(er)?"])))  or (scaned_set == (set([r"decrease(d)? (the )?size(s)?"]))) :
            give_small_size(last_viewed_tuple)
        elif( scaned_set == (set([r"delete(s)?",r"cart"]))) or (scaned_set == (set([r"remove(s)?",r"cart"]))):
            #global cur_item_tuple
            udb.remove_from_cart(ask_item_to_del_to_cart(buy_what(u_input)),username)
            
            
            
            
        else:
            cb.chat(u_input)
            


        return scaned_set;
    except  :
    
        bf.hanprt("Sorry an error occured in processing the output")
def display_profile(item_list):
    """THis function displays the user profile"""
    try:
        if item_list != []:
            bf.random_pr_string(
                ("Your customer loves these", "History of the user",
                 "Profile ", "Showing the profile"))
            bf.nnprt("")
            #bf.line("_",130)
            bf.nnprt(bf.center_align("_", 149))
            #bf.nnprt("|___ITEM____|__GENDER__|__SIZE___|____PRIZE__|_COLOUR_|__BRAND_|__QUANTY_|___AMOUNT___|__PAYMENT_MOD__|__DATE_AND_TIME____|")
            bf.nnprt("|__" + bf.left_align("ITEM", 10).upper() + "|__" +
                     bf.left_align("gender", 7).upper() + "|__" +
                     bf.left_align("SIZE", 7).upper() + "|__" +
                     bf.left_align("PRIZE", 13).upper() + "|__" +
                     bf.left_align("COLOUR", 10).upper() + "|__" +
                     bf.left_align("BRAND", 15).upper() + "|__" +
                     bf.left_align("QUANTITY", 10).upper() + "|__" +
                     bf.left_align("AMOUNT", 13).upper() + "|__" +
                     bf.left_align("PAYMENT_MOD", 12).upper() + "|__" +
                     bf.left_align("DATE AND TIME", 20).upper() + "|")

            for i in item_list:

                p = str(i[3])
                q = str(i[6])
                a = str(i[7])
                d = str(i[9])
                #print(d)
                #bf.easy_center_align( q + "pcs. of " +  i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-")

                bf.nnprt("|__" + bf.left_align(i[0], 10).upper() + "|__" +
                         bf.left_align(i[1], 7).upper() + "|__" +
                         bf.left_align(i[2], 7).upper() + "|__Rs." +
                         bf.left_align(p, 10).upper() + "|__" +
                         bf.left_align(i[4], 10).upper() + "|__" +
                         bf.left_align(i[5], 15).upper() + "|__" +
                         bf.left_align(q, 10).upper() + "|__Rs." +
                         bf.left_align(a, 10).upper() + "|__" +
                         bf.left_align(i[8], 12).upper() + "|__" +
                         bf.left_align(d, 20).upper() + "|")
            #bf.line("_",130)
            bf.nnprt(bf.center_align("_", 149))
            bf.nnprt("")
        else:
            bf.hanprt("No History available")

    except:
        bf.easy_center_align("Sorry an error occured displaying the profile")
def check_table(table_name):
    try:
        """This function gets the name of all the tables available in the database"""
        #mycursor.execute("SELECT Distinct TABLE_NAME FROM information_schema.TABLES where table_schema = 'tableowner'")
        mycursor.execute(
            "SELECT * FROM information_schema.tables WHERE table_name = '" +
            table_name + "'")
        data = mycursor.fetchall()
        if data == []:
            b = 0
        else:
            b = 1
        return b
    except:
        bf.hanprt("Sorry an error occured in checking the table")
def add_to_cart(value_tuple, username):
    """This function - the items selected by the user to the cart"""

    try:
        if value_tuple == ():
            #bf.hanprt("Sorry you have not asked me of anything to buy")
            #bf.hanprt("Try saying like 'I want to buy'")
            pass
        else:

            value_tuple = (get_full_values_of_item(value_tuple))

            p = str(value_tuple[3])
            check_quantity_formula = "SELECT quantity FROM inventory WHERE item_type = '" + value_tuple[
                0] + "'  and   gender  = '" + value_tuple[
                    1] + "' and size  = '" + value_tuple[
                        2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                            4] + "' and brand = '" + value_tuple[5] + "'"
            mycursor.execute(check_quantity_formula)

            data = mycursor.fetchall()
            quantity_available = int(data[0][0])
            quantity_needed = int(value_tuple[6])
            if (quantity_needed <= quantity_available):

                final_list = []
                final_list.append(value_tuple[0])
                final_list.append(value_tuple[1])
                final_list.append(value_tuple[2])
                final_list.append(p)
                final_list.append(value_tuple[4])
                final_list.append(value_tuple[5])
                final_list.append(quantity_needed)
                amount = int(p) * int(quantity_needed)
                final_list.append(amount)
                final_tuple = tuple(final_list)

                INSERT_TO_cart = "INSERT INTO " + username + "_cart (item_type , gender , size  , prize , colour , brand , quantity , amount) VALUES (%s ,%s , %s , %s , %s , %s , %s ,%s)"
                mycursor.execute(INSERT_TO_cart, final_tuple)
                mycon.commit()
                bf.random_pr_string(("Added to cart", "New Item added",
                                     "Item added to cart", "Added", "Done"))
            else:
                bf.hanprt(
                    "Sorry , we don't have this much quantity available right now the maxinum quantity you can get is "
                    + str(quantity_available))
    except:
        bf.easy_center_align("Sorry an error occured in adding to cart")
def create_cart(username):
    """This function creates the table as cart"""
    #bf.nnprt("Shopping cart created")
    try:
        if (bool((check_table(str(username + "_cart"))))):
            bf.hanprt(
                "It seem you once visited here so starting with your old cart")
        else:

            formula = "CREATE TABLE " + username + "_cart (item_type VARCHAR(100) , gender CHAR(1) , size CHAR(4)  , prize DECIMAL , colour VARCHAR(20) , brand VARCHAR(100) , quantity INTEGER , amount DECIMAL )"

            mycursor.execute(formula)
            mycon.commit()
            bf.easy_center_align("New cart created")
    except:
        bf.easy_center_align(
            "Sorry an error occured.Please run the program again as your input is not valid for smooth functioning"
        )
def display_stocks(item_list):
    try:
        if item_list != []:
            bf.random_pr_string((
                "This is what we have",
                "We have these",
                "This is the stock",
                "Stock available with us",
                "Items we have",
                "Available stock",
            ))

            bf.line("_", 90)
            bf.center_align("_", 20)
            #bf.nnprt("|___ITEM____|__GENDER__|__SIZE___|____PRIZE__|_COLOUR_|__BRAND_|__QUANTY_|")
            bf.nnprt(("|__" + bf.left_align("ITEM", 10).upper() + "|__" +
                      bf.left_align("gender", 7).upper() + "|__" +
                      bf.left_align("SIZE", 7).upper() + "|__" +
                      bf.left_align("PRIZE", 10).upper() + "|__" +
                      bf.left_align("COLOUR", 10).upper() + "|__" +
                      bf.left_align("BRAND", 15).upper() + "|__" +
                      bf.left_align("QUANTITY", 10) + "|"))

            for i in item_list:

                p = str(i[3])
                q = str(i[6])
                #bf.easy_center_align( q + "pcs. of " +  i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-")

                bf.nnprt("|__" + bf.left_align(i[0], 10).upper() + "|__" +
                         bf.left_align(i[1], 7).upper() + "|__" +
                         bf.left_align(i[2], 7).upper() + "|__Rs." +
                         bf.left_align(p, 7).upper() + "|__" +
                         bf.left_align(i[4], 10).upper() + "|__" +
                         bf.left_align(i[5], 15).upper() + "|__" +
                         bf.left_align(q, 10).upper() + "|")
            bf.line("_", 90)
            bf.nnprt("")
        else:
            bf.hanprt("No Item available in the stocks")

    except:
        bf.easy_center_align(
            "Sorry an error occured in finding whats in the stock")
def print_cart(item_list):
    try:
        """This function prints the cart"""
        if item_list != []:
            bf.random_pr_string(("You have selected " ,
                                  "This is what you have selected" ,
                                  "Your cart contains" ,
                                  "Items you have added" ,))
            for i in item_list:
                
                p = str(i[3])
                q = str(i[6])
                a = str(i[7])
                
                bf.easy_center_align(q +"pcs of " + i[0] + "("+i[1].upper()+") of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-. Amount Rs." + a + "/-")
        else:
            bf.hanprt("Your cart is empty you have not added anything to your cart")
    except:
        bf.hanprt("Sorry an error occured in printing the cart")
def showcase_designs(item_list):
    try:
        if item_list != []:
            bf.random_pr_string(("Here are some beautiful designs for you" ,
                                  "You may like these designs" ,
                                  "I am sure you will love them" ,
                                  "Please have a look to them",
                                  "These designs are awesome" ,
                                  "Try these" ,))
            
            for i in item_list:
                
                p = str(i[3])
                
                bf.easy_center_align("A " + i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-")
        else:
            bf.hanprt("Sorry sir we don't have this item available at this moment")
    except:
        bf.hanprt("Sorry an error occured in showcasing what to buy")
def ask_items_to_buy(value_tuple):
    try:
        """This function ask the user for nessasary items to display"""
        
        value_list = list(value_tuple)
        if value_tuple[0] == "":
            
            value_list[0] = bf.ask_item_type()
            
        if value_tuple[1] == "":
            value_list[1] = bf.ask_gender()
            
        if value_tuple[2] == "":
            value_list[2] = bf.ask_size()

        value_tuple_2 = tuple(value_list)
        return value_tuple_2
    except:
        bf.hanprt("Sorry an error occured in asking items to buy")
def ask_items_to_remove_from_cart(value_tuple):
    try:
        """This function ask the user for removing from cart"""
        
        value_list = list(value_tuple)
        if value_tuple[0] == "":
            
            value_list[0] = bf.ask_item_type()
            
        if value_tuple[1] == "":
            value_list[1] = bf.ask_gender()
            
        if value_tuple[2] == "":
            value_list[2] = bf.ask_size()

        value_tuple_2 = tuple(value_list)
        return value_tuple_2
    except:
        bf.hanprt("Sorry an error occured in asking items to buy")
def which_profile(o_input):
    try:
        """This function scans th o_input for username"""
        s = (bf.scan_n(attribute_of_username_r, o_input))
        try:
            t = str(s.pop())
        except:
            t = ""
        if (re.match(r" user (\w+)", t)):
            username = t[6:-1]
        elif (re.match(r" username (\w+)", t)):
            username = t[10:-1]
        elif (re.match(r" customer (\w+)", t)):
            username = t[10:-1]
        else:
            username = ask_customer_name()
        return username
    except:
        bf.hanprt("Sorry an error occured in asking you which profile")
def get_data_of_profile(username):
    """THis function gets the data from profile of the user"""
    try:
        if check_table(username + "_profile"):

            DISPLAYING_FORMULA = "SELECT * FROM " + username + "_profile"

            mycursor.execute(DISPLAYING_FORMULA)

            data = mycursor.fetchall()
            # mycursor.commit()
            return data
        else:
            bf.hanprt("No such rercord of customer exists in the database")
            data = []
            return data

    except:
        bf.hanprt("Sorry an error occured in getting data of profile")
def add_to_profile(value_tuple, username, payment_mod):
    """
    bf.nnprt(value_tuple)
    bf.nnprt(username)
    bf.nnprt(payment_mod)"""
    try:
        #bf.nnprt(date)
        """Add the items to the profile"""
        #INSERTION_FORMULA  = "INSERT INTO "+username  +"_profile (item_type , gender , size  , prize , colour , brand , quantity ,amount ,  payment_mod , date ) VALUES('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}').format('"+str(value_tuple[0][0])+"','"+str(value_tuple[0][1])+"','"+str(value_tuple[0][2])+"','"+str(value_tuple[0][3])+"','"+str(value_tuple[0][4])+"','"+str(value_tuple[0][5])+"','"+str(value_tuple[0][6])+"','"+str(value_tuple[0][7])+"','"+str(payment_mod)+"','" + date+"')"
        INSERTION_FORMULA = "INSERT INTO " + username + "_profile (item_type , gender , size  , prize , colour , brand , quantity ,amount ,  payment_mod , date ) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        value_list = list(value_tuple)
        value_list.append(payment_mod)
        value_list.append(datetime.datetime.now())
        value_tuple_2 = tuple(value_list)

        mycursor.execute(INSERTION_FORMULA, value_tuple_2)
        mycon.commit()

    except:
        bf.hanprt("Sorry an error occured in adding to profile")
def start_as_owner():
    try:
        username = "******"
        bf.handler = "Auto K.B."

        bf.easy_center_align("Started as owner")

        bf.hanprt("Now you can start.")
        o_input = bf.ask_input()
        while (1):
            if ((o_input == "i am done") or (o_input == "exit")
                    or (o_input == "leave") or (o_input == "quit")):
                bf.hanprt("Thanks for visiting," + username)
                break
            display_o_output(
                process_o_input(bf.scan_r(o_kwd_act, o_input), o_input))

            o_input = bf.ask_input()
    except:
        bf.easy_center_align("Sorry an error occured in starting as owner")
        start_as_owner()
def start_as_user(u_name):
    try:
        global username
        username = u_name
        
        """Start as user/customer"""
        #user_name is the name of the user
        
        create_profile(username)
        udb.create_cart(username)
        Username = username[0].upper() + username[1:]
        bf.easy_center_align("Started as " + Username)
        bf.hanprt("Now you can ask me anything")
        bf.handler = "Staff"
        #the handler from basic function
       
        #try:
        
        u_input = bf.ask_input()
        while(1):
            if ((u_input == "i am done") or (u_input == "exit") or (u_input == "leave") or (u_input == "close")):
                bf.hanprt("Thanks for visiting ," + username)
                udb.delete_cart(username)
                break
            display_u_output(process_u_input(bf.scan_r(u_kwd_act , u_input),u_input))
            
            u_input = bf.ask_input()

    except:
        bf.hanprt("Sorry an error occured in starting as user")
        ask.username()
def check_and_add_new_stocks(value_tuple):
    try:
        """This function checks the table for a item and update its quantity if found else create a new one"""
        p = str(value_tuple[3])
        check_quantity_formula = "SELECT * FROM inventory WHERE item_type = '" + value_tuple[
            0] + "'  and   gender  = '" + value_tuple[
                1] + "' and size  = '" + value_tuple[
                    2] + "'and prize = '" + p + "' and colour = '" + value_tuple[
                        4] + "' and brand = '" + value_tuple[5] + "'"
        mycursor.execute(check_quantity_formula)
        data = mycursor.fetchall()
        if data == []:
            """Creating a new item"""
            add_entire_stock(value_tuple)
        else:

            bf.hanprt(
                "There is a same item already exisiting in the stocks so increasing its quantiy"
            )
            increase_quantity(value_tuple, value_tuple[6])
    except:
        bf.hanprt("Sorry an error occured in adding new stocks")
def ask_payment_mod():
    try:
    
        bf.hanprt("Which payment method will suit you")
        payment_mod = bf.ask_input()
        if( (re.search(r" cash "," " + payment_mod + " ")) or (re.search(r" card "," " + payment_mod + " "))  or (re.search(r" cheque "," " + payment_mod + " ")) or (re.search(r" e(-| )wallet "," " + payment_mod + " "))  ):
            if ( (re.search(r" boy(s)? "," " + payment_mod + " ")) ):
                payment_mod = "cash"
            elif ( (re.search(r" card "," " + payment_mod + " ")) ):
                payment_mod = "card"
            elif ((re.search(r" cheque "," " + payment_mod + " ")) ):
                payment_mod = "cheque"
            elif ((re.search(r" e(-| )wallet "," " + payment_mod + " ")) ):
                payment_mod = "ewallet"
            
            return payment_mod
        else:
            bf.hanprt("Invalid option , Please try again (cash/card/e-wallet/cheque)")
            
        return ask_payment_mod()
    except:
        bf.easy_center_align("Sorry an error occured.Please try again")
        ask_payment_mod()
def ask_item_to_del_to_cart(value_tuple):
    
    """Asks the entire item and stores the values to cart and asks the user for incomplete values if empty values is provided"""
    try:
        value_list = list(value_tuple)
        
    #"""if value_tuple == (): return value_tuple else:"""
            
        #if value_tuple == ("", "", "", "", "", "", ""):
            
           
             
        value_tuple_2 = tuple(value_list)
                
        data_list = udb.items_available_to_remove(value_tuple_2,username)  
        
            #if(len(data_list) > 1) or
        if len(data_list) > 1:
            if value_list[0] == "":
                value_list[0] = bf.ask_item_type()
         
            elif value_list[1] == "":
                value_list[1] = bf.ask_gender()

            elif value_list[2] == "":
                value_list[2] = bf.ask_size()

            elif value_list[4] == "":
                
                value_list[4] = bf.ask_colour()

            elif value_list[5] == "":
                value_list[5] = bf.ask_brand()
                
            elif value_list[3] == "":
                value_list[3] = str(bf.ask_prize())
            
            
                  
            
                
            #value_tuple_2 = tuple(value_list)    
            #ask_item_to_add_to_cart(value_tuple_2)
        elif len(data_list) == 0:
            bf.hanprt("No such item available")
            
            """elif len(data_list) == 1:
            bf.hanprt("clear_cart")
            udb.clear_cart(username)
            return ()"""
            return ()
            
        elif len(data_list) == 1:
            """if value_list[6] == "":
                value_list[6] = bf.ask_quantity()"""
            value_tuple_2 = tuple(value_list)
            return value_tuple_2
        else:
            pass
                
            
            #value_tuple_2 = tuple(value_list)    
            return value_tuple_2
        
        value_tuple_2 = value_list
        
        
        return ask_item_to_del_to_cart(value_tuple_2)
    except :
        
        bf.hanprt("Sorry an error occured in asking you what to add to cart")
Example #29
0
def chat(t):
    """This function chats with the user """
    if m(t, r"hi") or m(t, r"hello") or m(t, r"hey") or m(t, r"hello") or m(
            t, r"hlo") or m(t, r"hello"):
        bf.random_pr_string(
            ("Hey", "Hlo", "Hey..How are you?", "Hi..How are you?",
             "Hello..How can I help you? ", "Hi...What can i do for you?",
             "Hi..", "Nice to see you"))
    elif (m(t, r"how") and m(t, r"you(r)?")):
        bf.random_pr_string(
            ("I am fine...How are you?", "Fine", "I am fine...What about you?",
             "As usual...Fine", "I am nice", "Fine...Thanks for asking"))
    elif (m(t, r"what(')?(s)?") and m(t, r"name")) or (m(t, r"who")
                                                       and m(t, r"you(r)?")):
        bf.hanprt("Hey I am AutoKB...How can I help you?")
    elif ((m(t, r"what") and m(t, r"do")) or (m(t, r"help"))
          or m(t, r"command(s)?")):
        bf.hanprt("I am here to help you...I can help you in many ways")
        bf.hanprt("Try asking me to display items by saying 'I WANT TO BUY...")
        bf.hanprt("'ADD TO CART' to add to cart")
        bf.hanprt("'BILL' to start you billing")
        bf.hanprt("ADD TO CART' to add to cart")
        bf.hanprt("Ya its that simple'")
    elif (m(t, r"thank(s)?") or m(t, r"thank(-| )you")):
        bf.random_pr_string(("Welcome", "I am glad to hear that from you"))
    elif (m(t, r"shut up") or (m(t, r"close") and m(t, r"mouth"))):
        bf.hanprt("I am sorry if I offended you")
    elif (m(t, r"awesome") or m(t, r"fine") or m(t, r"good") or m(t, r"nice")
          or m(t, r"osm") or m(t, r"beauiful(l)?") or m(t, r"liked(d)?")
          or m(t, r"wonderful(l)?") or m(t, r"fantastic") or m(t, r"fabulous")
          or m(t, r"amazing") or m(t, r"lovely") or m(t, r"unique")
          or m(t, r"suberb") or m(t, r"super") or m(t, r"great(s| work)?")):
        bf.random_pr_string(
            ("Thanks", "Good", "Nice", "Huh", "Hmmm", "Glad to here"))
    elif (m(t, r"bye(e|ee|eee|eeee)?") or m(t, r"go")):
        bf.random_pr_string(("Bye...See you afterwards", "Bye...Bye...Bye...",
                             "See you later"))
    elif (m(t, r"you") and m(t, r"can")):
        bf.random_pr_string(
            ("No.I cannot", "Let me guess......No.", "What do you think?",
             "May be...", "But i will some day"))
    elif (m(t, r"aw(w|ww|www|wwww)?") or m(t, r"hm(m|mm|mmm|mmmm)?")):
        bf.random_pr_string(
            ("I literally hate it.", "Please don't say this again",
             "What do you think?", "May be...", "But i will some day"))
    elif (m(t, r"no") or m(t, r"never") or m(t, r"yes") or m(t, r"may be")):
        bf.random_pr_string(("Ok...", "Hmmm", "No Problem"))
    elif (m(t, r"available")):
        bf.hanprt("We have Items - Jeans,Shirts,T-shirts,Tops,Pants")
        bf.hanprt("We have Sizes - S to XXXL")
        bf.hanprt("For both Boys and Girls")
    elif (m(t, r"sorry")):
        bf.random_pr_string(
            ("Its ok..", "No problem", "Np", "I don't have any problem"))
    elif (m(t, r"o(o|oo|ooo|oooo)?k(kk|kkk|kkkk)?") or m(
            t,
            r"o(o|oo|ooo|oooo)?k(kk|kkk|kkkk)?a(aa|aaa|aaaa)?y(y|yy|yyy|yyyy)?"
    ) or m(t, r"k")) or m(t, r"oh(h|hh|hhh|hhhhh)?"):
        bf.random_pr_string(("Hmmm", "Ok", "Okay"))
    elif (m(t, r"so") and m(t, r"what(s)?")):
        bf.hanprt("You quess what")
    elif (m(t, r"what(s)?") or m(t, r"when(s)?") or m(t, r"where(s)?")
          or m(t, r"who(s|se)?")):
        bf.random_pr_string(
            ("Please you tell me....I am just a beta version",
             "Sorry i am new to this world...can't say anything", "No answer",
             "No guesses", "Sorry i don't know"))
    elif (m(t, r"favourite")):
        bf.hanprt("Sorry but algorithm don't let me choose something....")

    elif (m(t, r"who(s)?") and m(t, r"ma(de|ke)")):
        bf.hanprt("I master INFINITY made me")
    elif (m(t, r"when(s)?") and m(t, r"b(orn|irth)")):
        bf.hanprt("I was not born...I was an idea which is in front of you")
    elif m(t, r"foolish(s)?") or m(t, r"looser(s)?") or m(
            t, r"idiot(s)?") or m(t, r"stupid(s)?") or m(t, r"dumb(s)?"):
        bf.random_pr_string(("No.", "No you are.", "Same to you."))
    elif ((m(t, r"have") or (m(t, r"keep")))) and (((m(t, r"have")))) and ((
        (m(t, r"jean(s)?")) or (m(t, r"pant(s)?")) or (m(t, r"shirt(s)?")) or
        (m(t, r"t(-)?shirt(s)?")) or m(t, r"top(s)?"))) and (m(t, r"you(r)?")):
        bf.hanprt("Yes,We have this item available.")
        bf.hanprt("If you want to buy,ask me 'I WANT TO BUY...'")
    elif ((m(t, r"have") or
           (m(t, r"keep")))) and (((m(t, r"have")))) and (m(t, r"you(r)?")):
        bf.hanprt("Sorry , we don't have this item available.")
        bf.hanprt(
            "But we have jeans,pants,t-shirts,shirts and tops for girls.'")

    else:
        bf.random_pr_string(
            ("Sorry I cannot recorgnised your command",
             "Sorry please try to rephrase your command",
             "Please try to rephrase", "Sorry I did not understand",
             "Ask me again in another manner",
             "If you don't know the commands ask me for HELP"))
def create_bill(username):

    try:
        """This function creates the billl"""

        item_list = udb.data_of_cart(username)

        if item_list == []:
            bf.hanprt("I can't create you bill as your cart is empty.")
            bf.hanprt("Add something to your cart buy asking to 'add to cart'")
            
        else:
            
            file = username+"_bill"
            file = open(file +".txt", "w")
            
            payment_mod = ask_payment_mod()
            total_amount = 0

            bf.hanprt(bf.append_file("Bill of " + username ,file ))
            bf.hanprt(bf.append_file("Bill created" ,file ))
            bf.line("_",106)
            bf.nnprt(bf.append_file(("|"+bf.center_align("___" ,104)+"|"),file))
            
            bf.nnprt(bf.append_file(("|"+bf.center_align("PASSION AND PROFESSION" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("___" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("ESTIMATE" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("___" ,104)+"|"),file))
            
            
            bf.nnprt(bf.append_file("|"+bf.center_align(str("DATE_AND_TIME__"+str(datetime.datetime.now())),104) +"|",file))
            bf.nnprt(bf.append_file("|__"+ bf.left_align("ITEM" , 10).upper() + "|__"+bf.left_align("gender" , 7).upper() + "|__"+bf.left_align("SIZE" , 7).upper()+"|__"+bf.left_align("PRIZE" , 10).upper()+"|__"+bf.left_align("COLOUR", 10).upper()+"|__"+bf.left_align("BRAND" , 15).upper()+"|__"+bf.left_align("QUANTITY" , 10).upper()+"|__"+bf.left_align("AMOUNT" , 12).upper()+"|",file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("__" ,104)+"|"),file))
            now = datetime.datetime.now()
            date = now.strftime("%Y-%m-%d")
            
            
            
            for i in item_list:
                
                p = str(i[3])
                q = str(i[6])
                a = str(i[7])
                #bf.easy_center_align( q + "pcs. of " +  i[0] + " of brand " + i[5].upper() + " of size " +i[2].upper() + " of colour " + i[4].upper() + " of prize Rs." + p + "/-")
            
                bf.nnprt(bf.append_file("|__" + bf.left_align(i[0] , 10).upper() +"|__"+  bf.left_align(i[1]  , 7).upper() + "|__"+ bf.left_align(i[2] , 7).upper() + "|__Rs."+  bf.left_align(p , 7).upper() + "|__"+bf.left_align(i[4] , 10).upper()+ "|__" + bf.left_align(i[5] , 15).upper() +"|__"+ bf.left_align(q , 10).upper() + "|__Rs." + bf.left_align(a , 9).upper() + "|",file))
                total_amount += i[7]
                udb.decrease_quantity(i , q)
                
                udb.add_to_profile(i ,username,payment_mod)
                udb.delete_empty_stock(i)

            bf.nnprt(bf.append_file(("|"+bf.center_align("_" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("_" ,10))+bf.left_align(payment_mod , 10).upper() +bf.center_align("_" ,61)+"Rs."+ bf.left_align(a , 10).upper()+(bf.center_align("_" ,10)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("_" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("THANK YOU" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("HAVE A NICE DAY" ,104)+"|"),file))
            bf.nnprt(bf.append_file(("|"+bf.center_align("_" ,104)+"|"),file))
            file.close()
            udb.clear_cart(username)
            

    
    #create_bill(username)
    except:
        bf.hanprt("Sorry an error occured in creating the bill")