def posFilter(location): location = session['username'] + '/' + location rf = request.form for key in rf.keys(): data = key data_dic = json.loads(data) brand = data_dic['Brand'] city = data_dic['City'] product = data_dic['Product'] store = data_dic['Store'] country = data_dic['Country'] startdate = "-".join(data_dic['StartDate'].split('-')[::-1]) if startdate == '': startdate = 'All' enddate = "-".join(data_dic['EndDate'].split('-')[::-1]) if enddate == '': enddate = 'All' filteredData = Filtering.applyFilters(location, startdate, enddate, country, city, store, brand, product) return jsonify({ 'totalSales': KPIs.total_sales(filteredData, 1), 'salesPerStore': KPIs.sales_per_store(filteredData, 1), 'totalOnhandAmount': KPIs.total_onhand_amount(filteredData, 1), 'totalOnhandUnits': KPIs.total_onhand_units(filteredData, 1), 'averageInventoryAmount': KPIs.average_inventory_amount(filteredData, 1), 'distinctProductsSold': KPIs.ditinct_products_sold(filteredData, 1), 'outOfStock': KPIs.out_of_stock(filteredData, 1), 'totalsalesPerDay': json.loads(charts.totalsales_per_day(location)), 'totalsalesPerCountry': json.loads(charts.totalsales_per_country(location)), 'topProducts': json.loads(charts.top_products(location)), 'topBrands': json.loads(charts.top_brands(location)), 'totalsalesPerCity': json.loads(charts.totalsales_per_city(location)), 'totalsalesPerStore': json.loads(charts.totalsales_per_store(location)), 'salesPercentageForBrand': json.loads(charts.sales_percentage_for_brand(location)) })