def Post_contact_ajax():
    c = Cust_details()
    msg = ""
    status = 0
    valid = True
    if request.method == "POST":
        print('in post')
        # fetching data from form..
        data = {
            'contact_number': request.values.get('contact_number'),
            'name': request.values.get('name'),
        }

        if data.get('name'):
            print(data.get('name'))
        else:
            valid = False
            msg = "Please Enter the Name"

        #ceating object for model class..

        if valid:
            #calling insert method using that object..
            output = c.insert_cust(data)
            if output:
                msg = "Successfully Saved !"
                results = c.get_cust()
                html = render_template('customer_index_ajax.html',
                                       cust_data=results)
                status = 1
            else:
                msg = "failed"
                status = 0

        return jsonify({'message': msg, 'status': status, 'html': html})
def Post_Edit_contact(id):
    print("Inside in contoller Post Edit")
    print(id)
    id = int(id)
    if request.method == "POST":
        print('in post Edit')

        # fetching data from form..
        data = {
            'contact_number': request.form['contact_number'],
            'name': request.form['name'],
            'interest': request.form['interest'],
            'plan': request.form['plan'],
        }

        #ceating object for model class..
        c = Cust_details()

        #calling insert method using that object..
        output = c.update_cust(id, data)
    # return all rows as a JSON array of objects
    # json_data = json.dumps([dict(r) for r in output])
    # results = json_data.json()
    # response = json.dumps(output)
    # print('Return data to Android ..')
    flash('Successfully Updated ! ')
    return redirect(url_for('cust.Custindex'))
def contact_index_ajax():
    c = Cust_details()
    msg = ""
    status = 1
    results = c.get_cust()
    html = render_template('customer_index_ajax.html', cust_data=results)

    return jsonify({'message': msg, 'status': status, 'html': html})
def Delete_contact(id):
    print("Inside in contoller delete")
    print(id)
    id = int(id)
    # contact_id = request.args.get('contact_id')
    # print(contact_id)
    c = Cust_details()
    output = c.delete_cust(id)
    print(output)
    flash('Customer Number' + ' ' + str(id) + ' ' + 'is Deleted ! ')
    return redirect(url_for('cust.Custindex'))
def Custindex():
    print('ín Index')
    c = Cust_details()
    output = c.get_cust()
    print(output)
    # return all rows as a JSON array of objects
    # json_data = json.dumps([dict(r) for r in output])
    # print('Return data to Android ..')
    # print(json_data)
    # return json_data
    # print(output.json())
    # return output.json()
    return render_template('customer_index.html', cust_data=output)
def Post_contact_normal():
    if request.method == "POST":
        print('in post')
        # fetching data from form..
        data = {
            'contact_number': request.form['contact_number'],
            'name': request.form['name'],
        }

        #ceating object for model class..
        c = Cust_details()

        #calling insert method using that object..
        output = c.insert_cust(data)

        if output:
            flash('Successfully Saved ! ')
            return redirect(url_for('cust.Custindex'))
def Edit_contact(id):
    print("Inside in contoller Edit")
    print(id)
    id = int(id)
    c = Cust_details()
    output = c.edit_cust(id)
    print(output)
    # data_ = [dict(r) for r in output]
    print(output.name)
    # return all rows as a JSON array of objects
    # json_data = json.dumps([dict(r) for r in output])
    # print('Printing for results data to sent edit html file Boss ')
    # # results = json_data
    # print(json_data)
    # data  = json.loads(json_data)
    # contact_list = data[0]
    # print (contact_list)
    # print('Return data to Android ..')
    return render_template('edit_contact.html', result=output, id=id)
def Post_contact():
    # if request.method == "POST":
    print('in post')

    # fetching data from form..
    data = {
        'contact_number': request.values.get('contact_number'),
        'name': request.values.get('name'),
        'interest': request.values.get('interest'),
        'plan': request.values.get('plan'),
        'societies': request.values.get('check')
    }

    #ceating object for model class..
    c = Cust_details()

    #calling insert method using that object..
    output = c.insert_cust(data)

    if output:
        flash('Successfully Saved ! ')
        return redirect(url_for('cust.Custindex'))