def saveExpence():

    """ It saves the expenses added in a form """

    date = request.form.get('date')
    store = request.form.get('store')
    total = request.form.get('sum')

    date_of_purchase = datetime.strptime(date,"%m/%d/%Y")

    Expence.addExpence(date=date_of_purchase, store=store, total=total, user=session['User'])  

    return redirect('/viewExpences')     
def getExpences():

    """ 
        It gets all the expenses by week and by store for the current month
        or for the past 2 or 3 months if the parameter 'month' is passed
    """

    month = request.args.get('month')

    current_month = datetime.today().strftime('%m')

    # print "MONTH PARAM", month, type(month),type(current_month)

    if not month:

        month = current_month

    else:

        month = int(current_month) - int(month)

    # print "MONTH", month
    if 'User' in session:
        
        expences = Expence.getExpencesGroupedByDate(session['User'], month)

        expences_by_store = Expence.getExpencesByStore(session['User'], month)

        data_expences = helpFunctions.setDisplayData(expences, expences_by_store)

        return jsonify(data_expences)

    else:

        flash = []
        flash = "You need to login"
        return render_template("error.html")