def api_customer_foodTruckMenu(): if not hasattr(current_user, 'roles') or 'Customer' not in current_user.roles: return ErrorModel('No Privilege: Must be Customer').json() data = json.loads(request.args.get('data') or '{}') foodTruck = data.get('foodTruck') callProcedure('mn_view_foodTruck_menu', [foodTruck]) ret = select('mn_view_foodTruck_menu_result', '1 = 1', 'foodName, price')['data'] cleanDecimal(ret, 'price', 2) return SuccessModel(ret).json()
def api_customer_orderHistory(): if not hasattr(current_user, 'roles') or 'Customer' not in current_user.roles: return ErrorModel('No Privilege: Must be Customer').json() username = current_user.id callProcedure('cus_order_history', [username]) ret = select('cus_order_history_result', '1 = 1', '*')['data'] cleanDecimal(ret, 'orderTotal', 2) formatDate(ret, 'date') formatOrderID(ret, 'orderID') return SuccessModel(ret).json()
def api_customer_currentInformation(): if not hasattr(current_user, 'roles') or 'Customer' not in current_user.roles: return ErrorModel('No Privilege: Must be Customer').json() username = current_user.id ret = {} callProcedure('cus_current_information_basic', [username]) ret['basic'] = select('cus_current_information_basic_result', '1 = 1', '*')['data'] cleanDecimal(ret['basic'], 'balance', 2) callProcedure('cus_current_information_foodTruck', [username]) ret['foodTrucks'] = select('cus_current_information_foodTruck_result', '1 = 1', '*')['data'] return SuccessModel(ret).json()
def api_manager_summaryDetail(): if not hasattr(current_user, 'roles') or 'Manager' not in current_user.roles: return ErrorModel('No Privilege: Must be Manager').json() urlData = json.loads(request.args.get('data') or '{}') foodTruckName = urlData.get('foodTruckName') username = current_user.id callProcedure('mn_summary_detail', [username, foodTruckName]) ret = select('mn_summary_detail_result', '1 = 1', '*')['data'] cleanDecimal(ret, 'totalPurchase', 2) formatDate(ret, 'date') return SuccessModel(ret).json()
def api_manager_foodTruckSummary(): if not hasattr(current_user, 'roles') or 'Manager' not in current_user.roles: return ErrorModel('No Privilege: Must be Manager').json() urlData = json.loads(request.args.get('data') or '{}') username = current_user.id foodTruckName = urlData.get('foodTruckName') stationName = urlData.get('stationName') dateRange = urlData.get('dateRange') dateFrom = None dateTo = None if dateRange: dateFrom = dateRange.get('dateFrom') dateTo = dateRange.get('dateTo') sortBy = urlData.get('sortBy') asc = urlData.get('asc') if sortBy: if not (asc == True): asc = 'DESC' else: asc = 'ASC' else: asc = None ret = {} callProcedure( 'mn_filter_summary', [username, foodTruckName, stationName, dateFrom, dateTo, sortBy, asc]) ret['table'] = select('mn_filter_summary_result', '1 = 1', '*')['data'] cleanDecimal(ret['table'], 'totalRevenue', 2) callProcedure('mn_get_station', [username]) ret['stationList'] = select('mn_get_station_result', '1 = 1', '*')['data'] return SuccessModel(ret).json()
def api_admin_manageBuildingAndStation(): if not hasattr(current_user, 'roles') or 'Admin' not in current_user.roles: return ErrorModel('No Privilege: Must be Admin').json() data = json.loads(request.args.get('data') or '{}') buildingName = data.get('buildingName') buildingTag = data.get('buildingTag') stationName = data.get('stationName') capacity = data.get('capacity') low = None high = None if capacity: low = capacity.get('low') high = capacity.get('high') callProcedure('ad_filter_building_station', [buildingName, buildingTag, stationName, low, high]) ret = {} ret['table'] = select('ad_filter_building_station_result', '1 = 1', '*')['data'] ret['buildingList'] = select('Building', '1 = 1', 'buildingName')['data'] ret['stationList'] = select('Station', '1 = 1', 'stationName')['data'] cleanDecimal(ret['table'], 'capacity', 0) return SuccessModel(ret).json()