コード例 #1
0
 def wrapper_function(*args, **kwargs):
     try:
         api_key = request.headers["x-access-token"]
     except KeyError:
         return RESTException.raise_exception(RESTException.TOKEN_MISSING)
     try:
         decoded_token = jwt.decode(api_key, verify=False)
         expiry = decoded_token["expiry"]
         user_id = decoded_token["user_id"]
     except jwt.DecodeError:
         return RESTException.raise_exception(RESTException.INVALID_TOKEN)
     except KeyError:
         return RESTException.raise_exception(RESTException.INVALID_TOKEN)
     if time.time() > expiry:
         return RESTException.raise_exception(RESTException.TOKEN_EXPIRED)
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "select password from client_credential where id=%s limit 1",
             (user_id, ))
         result = cursor.fetchone()
         if result is None:
             return RESTException.raise_exception(
                 RESTException.INCORRECT_PASSWORD)
         password_hash = result["password"]
         try:
             jwt.decode(api_key, password_hash + RESTSecret.user_secret)
         except jwt.DecodeError:
             return RESTException.raise_exception(
                 RESTException.INVALID_TOKEN)
     finally:
         cursor.close()
         connection.close()
     return _function(*args, **kwargs)
コード例 #2
0
ファイル: mobile_verification.py プロジェクト: ai-being/ofs
def mobile_verfication():

    connection = get_connection()
    cursor = connection.cursor()
    try:
        cursor.execute("SELECT * from customer_login where id=%s and active=1",
                       (rights()))
        customer_details = cursor.fetchone()
        phone = customer_details['duplicate_mobile']

        otp = list(string.digits)
        otp.remove('0')
        otp_text = ""
        for i in range(0, 5):
            otp_text += random.choice(otp)
            # print(otp_text)
        if (send_sms(phone, "OTP: {}".format(otp_text))) == True:
            cursor.execute(
                "UPDATE customer_login set mobile_otp=%s where id=%s and active=1",
                (otp_text, rights()))
            connection.commit()
            return True
        else:
            return False
    except:
        return False
    finally:
        cursor.close()
        connection.close()
コード例 #3
0
 def wrapper_function(*args, **kwargs):
     if "inventory_token" not in session:
         return redirect("/contest")
     token = session["inventory_token"]
     try:
         decoded_token = jwt.decode(token, verify=False)
     except jwt.DecodeError:
         return redirect("/contest")
     admin_id = decoded_token["inventory_id"]
     expiry_time = decoded_token["expiry"]
     if time.time() > expiry_time:
         return redirect("/contest")
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "SELECT password from customer_login where customer_login.id=%s limit 1",
             (admin_id))
         result = cursor.fetchone()
         if result is None:
             return redirect("/contest")
         password_hash = result["password"]
     finally:
         cursor.close()
         connection.close()
     try:
         inventory_secret = "jeeva$kani*vichu&69_7#%%^"
         jwt.decode(token, key=password_hash + inventory_secret)
     except jwt.DecodeError:
         return redirect("/contest")
     return _function(*args, **kwargs)
コード例 #4
0
def rights():
    if ("inventory_token" not in session):
        return None
    else:
        token = session["inventory_token"]
        decoded_token = jwt.decode(token, verify=False)
        if ("inventory_id" not in decoded_token) | ("token_user"
                                                    not in decoded_token):
            return None
        print(decoded_token)
        admin_id = decoded_token["inventory_id"]
        token_user = decoded_token["token_user"]

        username_hash = token_user

        connection = get_connection()
        cursor = connection.cursor()
        cursor.execute(
            "SELECT id,username from customer_login where customer_login.id=%s",
            admin_id)
        right = cursor.fetchone()
        if right['username'] == username_hash:
            return admin_id
        else:
            return None
コード例 #5
0
 def post(self):
     decoded_token = jwt.decode(request.headers["x-access-token"],
                                verify=False)
     user_id = decoded_token["user_id"]
     name = request.json["name"]
     address = request.json["address"]
     website = request.json["website"]
     country_code = request.json["country_code"]
     phone = request.json["phone"]
     twitter = request.json["twitter"]
     facebook = request.json["facebook"]
     linkedin = request.json["linkedin"]
     instagram = request.json["instagram"]
     image = request.json["image"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "insert into organization value(null, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
             (user_id, name, address, website, country_code, phone, twitter,
              facebook, linkedin, instagram, image))
         connection.commit()
     finally:
         cursor.close()
         connection.close()
     return jsonify({"message": "Organization has been added!"})
コード例 #6
0
ファイル: signup.py プロジェクト: VISWESWARAN1998/sensible
 def post(self):
     phone = request.json["phone"]
     password = request.json["password"]
     name = request.json["name"]
     profile_picture = request.json["profile_picture"]
     currency_code = request.json["currency"]
     if not validate_phone_number(phone_number=phone):
         return SensibleException.raise_exception(SensibleException.INVALID_PHONE)
     if not is_valid_currency(currency=currency_code):
         return SensibleException.raise_exception(SensibleException.INVALID_CURRENCY_CODE)
     password = hash_password(password)
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id from user_credential where phone=%s limit 1", (phone, ))
         result = cursor.fetchone()
         if result:
             return SensibleException.raise_exception(SensibleException.PHONE_EXISTS)
         cursor.execute("insert into user_credential value(null, null, %s, %s, %s, %s, %s, 0)", (
             phone, password, name, currency_code, profile_picture
         ))
         user_id = cursor.lastrowid
         connection.commit()
         return jsonify(
             {
                 "message": "Account has been created!",
                 "user_id": user_id
             }
         )
     finally:
         cursor.close()
         connection.close()
コード例 #7
0
 def get(self):
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id, name, symbol from currency")
         result = cursor.fetchall()
         return jsonify({"currency_detail": result})
     finally:
         cursor.close()
         connection.close()
コード例 #8
0
ファイル: signup.py プロジェクト: ai-being/ofs
def signup_value(salt):
    name = request.form['name']
    mobilenumber = request.form['mobilenumber']
    email = request.form['email']
    username = request.form['username']
    password = request.form['pass']
    repeat_pass = request.form['repeat_pass']

    connection = get_connection()
    cursor = connection.cursor()
    try:
        if password == repeat_pass:
            cursor.execute(
                "SELECT * from customer_login where phone=%s and active=1",
                (mobilenumber))
            mobile_check = cursor.fetchone()

            cursor.execute(
                "SELECT * from customer_login where email=%s and active=1",
                (email))
            email_check = cursor.fetchone()
            if mobile_check == None:
                if email_check == None:
                    username_hash = user_encryption(username)

                    password_hash = password_encryption(password)

                    #=====================================================================================
                    # [0-----Flase]
                    # [1------True]
                    #=====================================================================================
                    cursor.execute(
                        "SELECT * from customer_login where username=%s and active=1",
                        (username_hash))
                    user_check = cursor.fetchone()

                    if user_check == None:
                        cursor.execute(
                            "INSERT into customer_login Value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                            (name, email, mobilenumber, username_hash,
                             password_hash, 0, 0, 0, 1, 0, 0, 0, 0))
                        connection.commit()
                        return 'Registered Successfully!'
                    else:
                        return 'Already username Registered'
                else:
                    return 'Already email Registered'
            else:
                return 'Already mobile number Registered'
        else:
            return 'password mismatch'
    finally:
        cursor.close()
        connection.close()
コード例 #9
0
 def mutate(root, info, tag_list):
     decoded_token = jwt.decode(request.headers["x-access-token"], verify=False)
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         for tag in tag_list:
             cursor.execute("delete from tag where id=%s and user_id=%s limit 1", (tag, user_id))
             connection.commit()
     finally:
         cursor.close()
         connection.close()
     return DeleteTag(response=200, message="Tags will be deleted if the ID belongs to the user.")
コード例 #10
0
 def get(self):
     decoded_token = jwt.decode(request.headers["x-access-token"],
                                verify=False)
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id from organization where user_id=%s",
                        (user_id, ))
         result = cursor.fetchall()
         return jsonify({"organization_list": result})
     finally:
         cursor.close()
         connection.close()
コード例 #11
0
 def post(self):
     decoded_token = jwt.decode(request.headers["x-access-token"],
                                verify=False)
     category_id = request.json["category_id"]
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "delete from category where id=%s and customer_id=%s limit 1",
             (category_id, user_id))
         connection.commit()
     finally:
         cursor.close()
         connection.close()
     return jsonify({"message": "categories will be deleted!"})
コード例 #12
0
 def get(self):
     decoded_token = jwt.decode(request.headers["x-access-token"], verify=False)
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id, name, hex_colour from category where customer_id=%s", (user_id, ))
         result = cursor.fetchall()
         return jsonify(
             {
                 "category_list": result
             }
         )
     finally:
         cursor.close()
         connection.close()
コード例 #13
0
ファイル: add_contest.py プロジェクト: ai-being/ofs
def save_contest(rights,today,title,companyname,description,reward_amount,total_participate,entry_fee,com_startdate,com_enddate,parti_enddate,status_code):

    try:
        connection=get_connection()
        cursor=connection.cursor()

        try:
            cursor.execute("INSERT into contest_add value('null',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",(rights,today,title,companyname,description,reward_amount,total_participate,entry_fee,com_startdate,com_enddate,parti_enddate,status_code))
            connection.commit()
            return True
        except:
            return False

    finally:

        cursor.close()
        connection.close()
コード例 #14
0
 def get(self):
     decoded_token = jwt.decode(request.headers["x-access-token"],
                                verify=False)
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id from task where user_id=%s", (user_id, ))
         task_list = cursor.fetchall()
         cursor.execute(
             "select count(id) as not_completed from task where status!=2 and user_id=%s",
             (user_id, ))
         not_completed = cursor.fetchone()["not_completed"]
         return jsonify({
             "task_list": task_list,
             "not_completed": not_completed
         })
     finally:
         cursor.close()
         connection.close()
コード例 #15
0
 def post(self):
     phone = request.json["phone"]
     password = request.json["password"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id, password_hash from user_credential where phone=%s limit 1", (phone, ))
         result = cursor.fetchone()
         if result is None:
             return SensibleException.raise_exception(SensibleException.DATA_NOT_PRESENT)
         if not verify_password(password, result["password_hash"]):
             return SensibleException.raise_exception(SensibleException.INCORRECT_PASSWORD)
         _token = generate_token(result["id"], result["password_hash"])
         return jsonify(
             {
                 "message": _token
             }
         )
     finally:
         cursor.close()
         connection.close()
コード例 #16
0
 def mutate(root, info, tag_list):
     access_token = request.headers["x-access-token"]
     decoded_token = jwt.decode(access_token, verify=False)
     user_id = decoded_token["user_id"]
     try:
         connection = get_connection()
         cursor = connection.cursor()
         for tag in tag_list:
             tag_name = tag["tag_name"]
             cursor.execute(
                 "select id from tag where name=%s and user_id=%s limit 1",
                 (tag_name, user_id))
             result = cursor.fetchone()
             if result is None:
                 cursor.execute("insert into tag value(null, %s, %s)",
                                (user_id, tag_name))
                 connection.commit()
     finally:
         cursor.close()
         connection.close()
     return AddTag(response=200, message="Tags have been added!")
コード例 #17
0
 def post(self):
     email = request.json["email"]
     name = request.json["name"]
     password = request.json["pass"]
     password = hash_password(password=password)
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "select id from client_credential where email=%s limit 1",
             (email, ))
         if cursor.fetchone():
             return RESTException.raise_exception(
                 RESTException.EMAIL_EXISTS)
         cursor.execute(
             "insert into client_credential value(null, %s, %s, %s, 0)",
             (email, password, name))
         connection.commit()
         return jsonify({"message": "Account has been created!"})
     finally:
         cursor.close()
         connection.close()
コード例 #18
0
 def post(self):
     decoded_token = jwt.decode(request.headers["x-access-token"], verify=False)
     user_id = decoded_token["user_id"]
     category_name = request.json["category_name"]
     hex_color = request.json["hex_color"]
     hex_color = hex_color.strip()
     category_name = category_name.strip()
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute("select id from category where name=%s and customer_id=%s limit 1", (category_name, user_id))
         result = cursor.fetchone()
         if result is None:
             cursor.execute("insert into category value(null, %s, %s, %s)", (user_id, category_name, hex_color))
             connection.commit()
     finally:
         cursor.close()
         connection.close()
     return jsonify(
         {
             "message": "Category has been added!"
         }
     )
コード例 #19
0
def paymentdetail_add(billdate, today, customername, invoice_no, details,
                      status1, status2, notes, deposit_to, bill_type, balance,
                      fine, grand_total, activeno, activeyes):

    try:
        connection = get_connection()
        cursor = connection.cursor()

        paid = float(grand_total) - float(balance)
        print(paid)
        if float(paid) != 0:

            print('pass')

            cursor.execute(
                "INSERT into payment_details value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (billdate, customername, invoice_no, grand_total, status1,
                 grand_total, paid, balance, fine, activeyes, bill_type))

            cursor.execute(
                "INSERT into payment_records value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,null,%s,%s)",
                (billdate, today, customername, invoice_no, details, status1,
                 details, details, notes, deposit_to, paid, activeno,
                 bill_type))
            connection.commit()

        else:
            cursor.execute(
                "INSERT into payment_details value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (billdate, customername, invoice_no, grand_total, status1,
                 grand_total, paid, balance, fine, activeno, bill_type))

            # cursor.execute("INSERT into payment_records value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,null,%s,%s)",(billdate,today,customername,invoice_no,details,status1,details,details,notes,deposit_to,paid,activeno,bill_type))
            connection.commit()
    finally:
        cursor.close()
        connection.close()
コード例 #20
0
ファイル: add_task.py プロジェクト: VISWESWARAN1998/sensible
 def post(self):
     decoded_token = jwt.decode(request.headers["x-access-token"],
                                verify=False)
     user_id = decoded_token["user_id"]
     name = request.json["name"]
     category_id = request.json["category_id"]
     due_date = request.json["due_date"]
     due_time = request.json["due_time"]
     status = request.json["status"]
     try:
         opportunity_id = request.json["opportunity"]
     except KeyError:
         opportunity_id = None
     try:
         connection = get_connection()
         cursor = connection.cursor()
         cursor.execute(
             "select name from category where id=%s and customer_id=%s limit 1",
             (category_id, user_id))
         result = cursor.fetchone()
         if result is None:
             return SensibleException.raise_exception(
                 SensibleException.DATA_NOT_PRESENT)
         if opportunity_id:
             cursor.execute(
                 "insert into task value(null, %s, %s, %s, %s, %s, null, null, %s, %s)",
                 (user_id, name, category_id, due_date, due_time,
                  opportunity_id, status))
         else:
             cursor.execute(
                 "insert into task value(null, %s, %s, %s, %s, %s, null, null, null, %s)",
                 (user_id, name, category_id, due_date, due_time, status))
         connection.commit()
         return jsonify({"message": "Task has been added!"})
     finally:
         cursor.close()
         connection.close()
コード例 #21
0
ファイル: signup.py プロジェクト: ai-being/ofs
def sign_update(salt):
    name = request.form['name']
    mobilenumber = request.form['mobilenumber']
    email = request.form['email']
    username = request.form['username']
    oldpass = request.form['oldpass']
    password = request.form['pass']
    repeat_pass = request.form['repeat_pass']
    connection = get_connection()
    cursor = connection.cursor()
    pass_change = request.form.get('pass_change')

    if pass_change == 'no':

        cursor.execute(
            "SELECT * from customer_login where id=%s and password=%s and active=1",
            (rights(), password_encryption(oldpass)))
        customer_details = cursor.fetchone()

        if customer_details == None:
            return 'wrong password'
        else:
            password = oldpass
            repeat_pass = oldpass
    try:
        if password == repeat_pass:

            cursor.execute(
                "SELECT * from customer_login where id=%s and active=1",
                (rights()))
            customer_details = cursor.fetchone()

            cursor.execute(
                "SELECT * from customer_login where phone=%s and active=1 and id!=%s",
                (mobilenumber, rights()))
            mobile_check = cursor.fetchone()

            cursor.execute(
                "SELECT * from customer_login where email=%s and active=1 and id!=%s",
                (email, rights()))
            email_check = cursor.fetchone()
            #===============================================================================================================================#
            #================================================================customer update============================================#
            if mobile_check == None:
                #================================================================email verification============================================#
                if email_check == None:

                    username_hash = user_encryption(username)

                    oldpassword_hash = password_encryption(oldpass)

                    password_hash = password_encryption(password)

                    #=====================================================================================
                    # [0-----Flase]
                    # [1------True]
                    #=====================================================================================
                    cursor.execute(
                        "SELECT * from customer_login where password=%s and active=1 and id=%s",
                        (oldpassword_hash, rights()))
                    pass_check = cursor.fetchone()
                    #================================================================password verification============================================#
                    if pass_check != None:
                        cursor.execute(
                            "SELECT * from customer_login where username=%s and active=1 and id!=%s",
                            (username_hash, rights()))
                        user_check = cursor.fetchone()
                        #================================================================username verification verification============================================#
                        if user_check == None:
                            #================================================================ verified customer check============================================#
                            if customer_details[
                                    'mobile_verfication'] == 1 | customer_details[
                                        'email_verification'] == 1:
                                #================================================================mobile nukber changing verification============================================#

                                cursor.execute(
                                    "UPDATE customer_login set name=%s,password=%s where id=%s and active=1",
                                    (name, password_hash, rights()))
                                connection.commit()
                                return 'Update Successfully!'
                            else:

                                cursor.execute(
                                    "UPDATE customer_login set name=%s,email=%s,phone=%s,password=%s where id=%s and active=1",
                                    (name, email, mobilenumber, password_hash,
                                     rights()))
                                connection.commit()

                                return 'Update Successfully!'
                        else:
                            return 'Already username Registered please change'
                    else:
                        return 'password Wrong'
                else:
                    return 'Already email Registered please change'
            else:
                return 'Already mobile number Registered please change'
        else:
            return 'password mismatch'
    finally:
        cursor.close()
        connection.close()
コード例 #22
0
def bill_insert(today, id):

    try:
        connection = get_connection()
        cursor = connection.cursor()

        rowcount = request.form['rowcount']

        invoice_no = request.form['invoice_no']
        billdate = request.form['billdate']
        due_date = request.form['duedate']
        customername = request.form['customername']
        customer_type = request.form['customer_type']
        address = request.form['address']
        shipaddress = request.form['shipaddress']
        gst = 'null'
        total = request.form['total']
        cgst = request.form['cgst']
        sgst = request.form['sgst']
        igst = request.form['igst']
        roundoff = request.form['roundoff']
        grand_total = request.form['grandtot']
        state = request.form['state']
        city = request.form['city']

        #===============payment function==========================

        balance = request.form['balance']
        paid = request.form['paid']
        fine = 0

        status1 = 'Payment Not Completed!'
        status2 = 'Payment Completed'

        bill_type = 'bill'
        details = 'cash'
        notes = 'none'
        deposit_to = 'cash'

        activeyes = 0
        activeno = 1

        #==============================================#
        #       active 0 == Not completed              #
        #       active 1 == paid                       #
        #==============================================#

        if customer_type != 'customer':
            cursor.execute(
                "INSERT into customer value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (today, customername, customername, "null", "null", address,
                 state, city, "null", "null", '0'))
            connection.commit()
            customername = cursor.lastrowid
            customer_type = 'customer'
        # print((invoice_no))
        # print((billdate))
        # print((due_date))
        # print((customername))
        # print((customer_type))
        # print((address))
        # print((shipaddress))
        # print((total))
        # print((cgst))
        # print((sgst))
        # print((igst))
        # print((roundoff))
        # print((grand_total))
        # print('pass1')
        if id == None:
            cursor.execute(
                "INSERT into bill value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (today, (invoice_no), billdate, due_date,
                 (customername), customer_type, (address), (shipaddress), gst,
                 (total), (cgst), (sgst), (igst), (roundoff),
                 (grand_total), state, city))
            customer_id = cursor.lastrowid
            connection.commit()

            if customer_type == 'customer':
                paymentdetail_add(billdate, today, customername, invoice_no,
                                  details, status1, status2, notes, deposit_to,
                                  bill_type, balance, fine, grand_total,
                                  activeno, activeyes)

            # ============================== paymenyt add ======================================

        else:

            # ==========================================================================================================================================================================================================================

            if customer_type == 'customer':

                customer_id = id

                cursor.execute(
                    "SELECT * from bill,payment_details where payment_details.type='bill' and payment_details.invoice_no=bill.invoice_no and payment_details.company_name=bill.companyname and bill.id =%s",
                    (id))
                bill_amount = cursor.fetchone()

                old_billamount = bill_amount['bill_amount']
                old_paid = bill_amount['paid_amount']

                amount_dif = float(grand_total) - float(old_billamount)
                paid_diff = float(paid) - float(old_paid)

                new_billamount = float(old_billamount) + amount_dif
                new_totalamount = float(
                    bill_amount['total_amount']) + amount_dif
                new_balance = float(
                    bill_amount['balance_amount']) + amount_dif - paid_diff

                new_paid = new_totalamount - new_balance

                if float(new_balance) == 0:
                    cursor.execute(
                        "UPDATE payment_details set bill_amount=%s,total_amount=%s,paid_amount=%s,balance_amount=%s,active_status=%s where id=%s",
                        (new_billamount, new_totalamount, new_paid,
                         new_balance, activeno,
                         bill_amount['payment_details.id']))
                    connection.commit()
                else:
                    cursor.execute(
                        "UPDATE payment_details set bill_amount=%s,total_amount=%s,paid_amount=%s,balance_amount=%s,active_status=%s where id=%s",
                        (new_billamount, new_totalamount, new_paid,
                         new_balance, activeyes,
                         bill_amount['payment_details.id']))
                    connection.commit()
            # ==========================================================================================================================================================================================================================
            cursor.execute(
                "UPDATE bill set date=%s,invoice_no=%s,bill=%s,due_date=%s,companyname=%s,customer_type=%s,address=%s,shipping=%s,gst=%s,total=%s,cgst=%s,sgst=%s,igst=%s,roundoff=%s,grand_total=%s,state=%s,city=%s where id=%s",
                (today, invoice_no, billdate, due_date, customername,
                 customer_type, address, shipaddress, gst, total, cgst, sgst,
                 igst, roundoff, grand_total, state, city, id))
            connection.commit()

            cursor.execute("SELECT * from bill where bill.id =%s", (id))
            invoice_number = cursor.fetchone()

            cursor.execute(
                "SELECT * from bill_info where bill_info.invoice_no =%s",
                (invoice_number['invoice_no']))
            item = cursor.fetchall()

            for i in item:

                qty = i['quantity']

                cursor.execute("SELECT * from product where product.id =%s",
                               (i['product_name']))
                oldstock = cursor.fetchone()

                newstock = float(oldstock['stock']) + float(qty)

                cursor.execute(
                    "UPDATE product set stock=%s where product.id=%s",
                    (newstock, i['product_name']))
                connection.commit()
            cursor.execute(
                "DELETE from bill_info where bill_info.invoice_no=%s",
                (invoice_number['invoice_no']))
            connection.commit()

        for i in range(0, int(rowcount)):

            try:

                code = request.form['productcode_' + str(i)]
                name = request.form['name_' + str(i)]
                mrp = 0
                qty = request.form['quantity_' + str(i)]
                value = request.form['value_' + str(i)]
                discount = request.form['dis_' + str(i)]
                after_dis = request.form['afterdis_' + str(i)]
                pretotal = request.form['prevalue_' + str(i)]
                gst = request.form['gst_' + str(i)]
                amount = request.form['amount_' + str(i)]
                unit = request.form['unit_' + str(i)]

                cursor.execute("SELECT * from product where id=%s", (name))
                item_name = cursor.fetchone()
                oldstock = item_name['stock']

                newstock = float(oldstock) - float(qty)

                cursor.execute("UPDATE product set stock=%s where id=%s",
                               (newstock, name))

                cursor.execute(
                    "INSERT into bill_info value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                    (today, invoice_no, billdate, 0, code, name, mrp, qty,
                     value, discount, after_dis, pretotal, gst, amount, unit))
                connection.commit()
            except:
                i += 1
        return customer_id
    finally:
        #print("ok")
        cursor.close()
        connection.close()
コード例 #23
0
def purchase_adds(id):
    try:

        connection = get_connection()
        cursor = connection.cursor()

        bill_no = request.form['bill_no']
        bill_date = request.form['bill_date']
        lr_no = request.form['lr_no']
        lr_date = request.form['lr_date']
        transpodate = request.form['ac_date']
        transport_name = request.form['transport_name']
        vendorname = request.form['vendorname']
        Narration = request.form['Narrations']

        total = request.form['total']
        cgst = request.form['cgst']
        sgst = request.form['sgst']
        igst = request.form['igst']
        INSURANCE = request.form['INSURANCE']
        inucgst = request.form['inucgst']
        inusgst = request.form['inusgst']
        roundoff = request.form['roundoff']
        gndtot = request.form['gndtot']

        rowcount = request.form['rowcount']
        print(rowcount)
        # print(id)

        #===============payment function==========================

        balance = request.form['balance']
        paid = request.form['paid']
        fine = 0

        status1 = 'Payment Not Completed!'
        status2 = 'Payment Completed'

        bill_type = 'purchase'
        details = 'cash'
        notes = 'none'
        deposit_to = 'cash'

        activeyes = 0
        activeno = 1

        customer_type = 'customer'

        #==============================================#
        #       active 0 == Not completed              #
        #       active 1 == paid                       #
        #==============================================#

        if int(id) == 0:
            cursor.execute(
                'INSERT INTO purchase_head value(null,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
                (bill_no, bill_date, transpodate, lr_no, lr_date,
                 transport_name, vendorname, Narration, total, cgst, sgst,
                 igst, INSURANCE, inucgst, inusgst, roundoff, gndtot))
            connection.commit()

            if customer_type == 'customer':
                paymentdetail_add(bill_date, bill_date, vendorname, bill_no,
                                  details, status1, status2, notes, deposit_to,
                                  bill_type, balance, fine, gndtot, activeno,
                                  activeyes)

        else:
            # ==========================================================================================================================================================================================================================

            if customer_type == 'customer':
                cursor.execute(
                    "SELECT * from purchase_head,payment_details where payment_details.type='purchase' and payment_details.invoice_no=purchase_head.bill_no and purchase_head.id =%s",
                    (id))
                bill_amount = cursor.fetchone()

                old_billamount = bill_amount['bill_amount']
                old_paid = bill_amount['paid_amount']

                amount_dif = float(gndtot) - float(old_billamount)
                paid_diff = float(paid) - float(old_paid)

                new_billamount = float(old_billamount) + amount_dif
                new_totalamount = float(
                    bill_amount['total_amount']) + amount_dif
                new_balance = float(
                    bill_amount['balance_amount']) + amount_dif - paid_diff

                new_paid = new_totalamount - new_balance

                if new_balance == 0:
                    cursor.execute(
                        "UPDATE payment_details set bill_amount=%s,total_amount=%s,paid_amount=%s,balance_amount=%s,active_status=%s where id=%s",
                        (new_billamount, new_totalamount, new_paid,
                         new_balance, activeno,
                         bill_amount['payment_details.id']))
                    connection.commit()
                else:
                    cursor.execute(
                        "UPDATE payment_details set bill_amount=%s,total_amount=%s,paid_amount=%s,balance_amount=%s,active_status=%s  where id=%s",
                        (new_billamount, new_totalamount, new_paid,
                         new_balance, activeyes,
                         bill_amount['payment_details.id']))
                    connection.commit()

            # ==========================================================================================================================================================================================================================
            cursor.execute(
                "UPDATE purchase_head set bill_no=%s,date=%s,ac=%s,lr_no=%s,lr_date=%s,transport_name=%s,suppiler_name=%s,Naration=%s,total=%s,cgst=%s,sgst=%s,igst=%s,insurance=%s,in_cgst=%s,in_sgst=%s,roundoff=%s,grand_total=%s where id=%s",
                (bill_no, bill_date, transpodate, lr_no, lr_date,
                 transport_name, vendorname, Narration, total, cgst, sgst,
                 igst, INSURANCE, inucgst, inusgst, roundoff, gndtot, id))
            connection.commit()

            cursor.execute("SELECT * from purchase_head where id=%s", (id))
            p_head = cursor.fetchone()

            cursor.execute("SELECT * from purchase_body where bill_no=%s",
                           (p_head['bill_no']))
            p_body = cursor.fetchall()

            for i in p_body:
                cursor.execute("SELECT * from product where id=%s",
                               (i['item']))
                product = cursor.fetchone()

                oldstock = float(product['stock'])

                newstock = oldstock - float(i['qty'])

                cursor.execute("UPDATE product set stock=%s where id=%s",
                               (newstock, product['id']))
                connection.commit()

            cursor.execute("DELETE from purchase_body where bill_no=%s",
                           (p_head['bill_no']))
            connection.commit()

        for i in range(0, int(rowcount)):
            print(i)
            try:
                productname = request.form['productname_' + str(i)]
                qty = request.form['quantity_' + str(i)]
                unit = request.form['unit_' + str(i)]
                value = request.form['value_' + str(i)]
                rate = request.form['rate_' + str(i)]
                gst = request.form['gst_' + str(i)]

                cursor.execute(
                    "INSERT INTO purchase_body value(null,%s, %s, %s, %s, %s,%s,%s)",
                    (bill_no, productname, qty, unit, rate, value, gst))
                connection.commit()

                cursor.execute("SELECT * from product where product.id=%s ",
                               (productname))
                product = cursor.fetchone()

                stock = int(int(product['stock'])) + int(qty)

                print(stock)
                cursor.execute(
                    "UPDATE product SET stock=%s where product.id=%s",
                    (stock, product['id']))
                connection.commit()
            except:
                print('wrong')
                i += 1

        return 'True'

    finally:
        #print("ok")
        cursor.close()
        connection.close()
コード例 #24
0
ファイル: mobile_verification.py プロジェクト: ai-being/ofs
def otp_verification():
    otp = request.form["otp"]
    phone = request.form["phone"]

    connection = get_connection()
    cursor = connection.cursor()
    try:
        if int(otp) > 0:

            cursor.execute(
                "SELECT * from customer_login where id=%s and active=1",
                (rights()))
            customer_details = cursor.fetchone()

            if (customer_details['duplicate_mobile'] == phone) & (str(
                    customer_details['mobile_otp']) == otp):

                cursor.execute(
                    "UPDATE customer_login set mobile_verfication=1 ,mobile_otp=0,phone=%s where id=%s and active=1",
                    (phone, rights()))
                connection.commit()

                return True
            else:
                return 'wrong'
        else:
            return False
    except:
        False
    finally:
        cursor.close()
        connection.close()


# def email_verfication():

#     connection=get_connection()
#     cursor=connection.cursor()
#     try:
#         cursor.execute("SELECT * from customer_login where id=%s and active=1",(rights()))
#         customer_details=cursor.fetchone()
#         email=customer_details['duplicate_email']

#         otp = list(string.digits)
#         otp.remove('0')
#         otp_text = ""
#         for i in range(0, 5):
#             otp_text += random.choice(otp)
#             # print(otp_text)
#         if (gmail_otp.A.send_mail(email, 'OTP Verification', "OTP: {}".format(otp_text))) == True:
#             cursor.execute("UPDATE customer_login set email_otp=%s where id=%s and active=1",(otp_text,rights()))
#             connection.commit()
#             return True
#         else:
#             return False
#     except:
#         return False
#     finally:
#         cursor.close()
#         connection.close()

# def otp_email_verification():
#     otp = request.form["otp_email"]
#     email = request.form["email"]

#     connection=get_connection()
#     cursor=connection.cursor()
#     try:
#         if int(otp)>0:
#             print('pass')
#             cursor.execute("SELECT * from customer_login where id=%s and active=1",(rights()))
#             customer_details=cursor.fetchone()

#             if (customer_details['duplicate_email']== email) & (str(customer_details['email_otp'])==otp):
#                 print('paass')
#                 cursor.execute("UPDATE customer_login set email_verification=1 ,email_otp=0,email=%s where id=%s and active=1",(email,rights()))
#                 connection.commit()

#                 return True
#             else:
#                 return 'wrong'
#         else:
#             return False
#     except:
#         False
#     finally:
#         cursor.close()
#         connection.close()