def calllogs(): current_user = g.user store_id = get_or_set_store_id() from application.forms.calllog import CalllogSearchForm search_form = CalllogSearchForm(request.args) search_form.sales_filter.choices = get_sales_selection(store_id) query = dict() if search_form.start_date.data and search_form.start_date.data != '': query['start_date'] = search_form.start_date.data if search_form.end_date.data and search_form.end_date.data != '': query['end_date'] = search_form.end_date.data if search_form.sales_filter.data not in ('None', 'all'): query['sales_filter'] = search_form.sales_filter.data if search_form.keywords.data: query['keywords'] = search_form.keywords.data sort_params = SortMixin.get_order_query(search_form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) calllogs = Calllog.find_all_by_query_params_in_store(store_id, **query) return render_template('calllogs/calllogs.html', selected_menu=CALL_LOG, form=search_form, calllogs=calllogs, back_endpoint=request.args.get('back_endpoint', None))
def campaigns(): current_user = g.user store_id = get_or_set_store_id() from application.forms.campaign import CampaignSearchForm form = CampaignSearchForm(request.args) type = form.type.data keywords = form.keywords.data days = None active = False if type == 'active-campaigns': days = 15 active = True query = { 'days': days, 'active': active, 'keywords': keywords, } sort_params = SortMixin.get_order_query(form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) campaigns = Campaign.find_all_by_store_in_recent_days_and_keywords( store_id, **query) return render_template('campaigns/campaigns.html', selected_menu=CAMPAIGN_MGMT, form=form, campaigns=campaigns, back_endpoint=request.args.get( 'back_endpoint', None))
def customers(): current_user = g.user store_id = get_or_set_store_id() from application.forms.customer import CustomerSearchForm search_form = CustomerSearchForm(request.args) search_form.intent_level_filter.choices = get_intent_level_selection( store_id) search_form.intent_car_ids_filter.choices = get_intent_car_ids_selection( store_id) search_form.last_instore_filter.choices = get_last_instore_selection( store_id) search_form.status_filter.choices = get_status_selection() search_form.sales_filter.choices = get_sales_selection(store_id) # build query query = dict() if search_form.intent_level_filter.data not in ('None', 'all'): query['intent_level'] = search_form.intent_level_filter.data if search_form.intent_car_ids_filter.data not in ('None', 'all'): query['intent_car_ids'] = search_form.intent_car_ids_filter.data if search_form.last_instore_filter.data not in ('None', 'all'): query['last_instore'] = search_form.last_instore_filter.data if search_form.status_filter.data not in ('None', 'all'): query['status'] = search_form.status_filter.data if search_form.keywords.data: query['keywords'] = search_form.keywords.data if search_form.sales_filter.data not in ('None', 'all'): query['sales_id'] = search_form.sales_filter.data if not current_user.has_role_in_current_store(USER_ROLE_STORE_MANAGER): query.pop('sales_id', None) # TODO: scope = current_user.getDataScope('customer', store_id) if scope: scope.pop('store_id', None) query.update(scope) sort_params = SortMixin.get_order_query(search_form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) customers_list = Customer.find_all_with_last_appt_by_query_params_in_store( store_id, **query) return render_template('customers/customers.html', selected_menu=CUSTOMER_MGMT, form=search_form, customers=customers_list, back_endpoint=request.args.get( 'back_endpoint', None))
def orders(): store_id = request.args.get('store_id', None) if not store_id: store_id = get_or_set_store_id() from application.forms.order import OrderSearchForm search_form = OrderSearchForm(request.args) search_form.ordered_car_ids_filter.choices = get_intent_car_ids_selection( store_id) search_form.sales_filter.choices = get_sales_selection(store_id) search_form.status_filter.choices = get_status_selection() # build query query = dict() if search_form.start_date.data and search_form.start_date.data != '': query['start_date'] = search_form.start_date.data if search_form.end_date.data and search_form.end_date.data != '': query['end_date'] = search_form.end_date.data if search_form.ordered_car_ids_filter.data not in ('None', 'all'): query['ordered_car_ids'] = search_form.ordered_car_ids_filter.data if search_form.sales_filter.data not in ('None', 'all'): query['sales_id'] = search_form.sales_filter.data if search_form.status_filter.data not in ('None', 'all'): query['status'] = search_form.status_filter.data if search_form.keywords.data: query['keywords'] = search_form.keywords.data if search_form.history.data: query['history'] = search_form.history.data sort_params = SortMixin.get_order_query(search_form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) cancel_form = OrderCancelForm() orders_list = Order.find_all_by_query_params_in_store(store_id, **query) return render_template('orders/orders.html', selected_menu=ORDERS_MGMT, form=search_form, orders=orders_list, cancel_form=cancel_form, back_endpoint=request.args.get( 'back_endpoint', None))
def leads(): current_user = g.user store_id = current_user.store_id from application.forms.lead import LeadSearchForm search_form = LeadSearchForm(request.args) query = dict() if search_form.start_date.data and search_form.start_date.data != '': query['start_date'] = search_form.start_date.data if search_form.end_date.data and search_form.end_date.data != '': query['end_date'] = search_form.end_date.data if search_form.on_file.data: query['on_file'] = search_form.on_file.data query.update(get_page_info(request)) rx = Reception.find_all_leads_by_query_params_in_store(store_id, **query) return render_template('leads/leads.html', selected_menu=LEADS_VIEW, form=search_form, leads=rx, back_endpoint=request.args.get('back_endpoint', None), today=datetime.date.today())
def receptions(): current_user = g.user store_id = get_or_set_store_id() from application.forms.reception import RxSearchForm search_form = RxSearchForm(request.args) search_form.type_filter.choices = get_type_selection() search_form.sales_filter.choices = get_sales_selection(store_id) search_form.status_filter.choices = get_status_selection() query = dict() if search_form.start_date.data and search_form.start_date.data != '': query['start_date'] = search_form.start_date.data if search_form.end_date.data and search_form.end_date.data != '': query['end_date'] = search_form.end_date.data if search_form.type_filter.data and search_form.type_filter.data not in ( 'None', 'all'): query['type_filter'] = search_form.type_filter.data if search_form.sales_filter.data not in ('None', 'all'): query['sales_filter'] = search_form.sales_filter.data if search_form.incomplete.data: query['incomplete'] = search_form.incomplete.data if search_form.status_filter.data not in ('None', 'all'): query['status'] = search_form.status_filter.data sort_params = SortMixin.get_order_query(search_form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) receptions = Reception.find_all_by_query_params_in_store(store_id, **query) return render_template('receptions/receptions.html', selected_menu=RX_VIEW, form=search_form, receptions=receptions, back_endpoint=request.args.get( 'back_endpoint', None), today=datetime.date.today())
def appts(): current_user = g.user store_id = get_or_set_store_id() from application.forms.appt import ApptSearchForm search_form = ApptSearchForm(request.args) search_form.type_filter.choices = get_type_selection() search_form.status_filter.choices = get_status_selection() search_form.sales_filter.choices = get_sales_selection(store_id) query = dict() if search_form.start_date.data and search_form.start_date.data != '': query['start_date'] = search_form.start_date.data if search_form.end_date.data and search_form.end_date.data != '': query['end_date'] = search_form.end_date.data if search_form.type_filter.data and search_form.type_filter.data not in ( 'None', 'all'): query['type_filter'] = search_form.type_filter.data if search_form.status_filter.data and search_form.status_filter.data not in ( 'None', 'all'): query['status'] = search_form.status_filter.data if search_form.sales_filter.data and search_form.sales_filter.data not in ( 'None', 'all'): query['sales_filter'] = search_form.sales_filter.data sort_params = SortMixin.get_order_query(search_form) if sort_params: query.update(sort_params) query.update(get_page_info(request)) appts = Appointment.find_all_by_query_params_in_store(store_id, **query) return render_template('appts/appts.html', selected_menu=APPTS_VIEW, form=search_form, back_endpoint=request.args.get( 'back_endpoint', None), appts=appts)
def get_store_orders(sid): status = request.args.get('status') confirmed = request.args.get('confirmed') return Order.find_all_in_status_by_store(sid, status, confirmed, **get_page_info(request))
def get_customers_of_sales(sales_id): return Customer.find_all_by_sales(sales_id, **get_page_info(request))
def get_all_store_customers(sid): status = request.args.get('status', None) return Customer.find_all_by_store_in_status(sid, status, **get_page_info(request))
def get_appointments_by_sales(sales_id): return Appointment.find_all_of_sales(sales_id, **get_page_info(request))
def get_active_campaigns(store_id): return Campaign.find_all_active_by_store(store_id, **get_page_info(request))