Ejemplo n.º 1
0
def graph(request):
    graph = request.POST.get("graph", "members")
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end})
    starteo = timeo.strptime(start, "%Y-%m-%d")
    start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday)
    endeo = timeo.strptime(end, "%Y-%m-%d")
    end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday)

    days = [{'date': start_date + timedelta(days=i)} for i in range((end_date - start_date).days)]
    if graph == "members":
        title = "Members by Day"
        min_v, max_v, avg_v, days = graph_members(days)
    elif graph == "income":
        title = "Monthly Membership Income by Day"
        min_v, max_v, avg_v, days = graph_income(days)
    elif graph == "amv":
        title = "Average Monthly Value"
        min_v, max_v, avg_v, days = graph_members(days)
    elif graph == "churn":
        title = "Membership Churn"


    return render_to_response('staff/stats_graph.html', {'title':title, 'graph':graph,
        'days': days, 'date_range_form': date_range_form, 'start': start, 'end': end,
        'min': min_v, 'max': max_v, 'avg': avg_v
    }, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def graph(request):
    graph = request.POST.get("graph", "members")
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end})
    starteo = timeo.strptime(start, "%Y-%m-%d")
    start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday)
    endeo = timeo.strptime(end, "%Y-%m-%d")
    end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday)

    days = [{'date': start_date + timedelta(days=i)} for i in range((end_date - start_date).days)]
    if graph == "members":
        title = "Members by Day"
        min_v, max_v, avg_v, days = graph_members(days)
    elif graph == "income":
        title = "Monthly Membership Income by Day"
        min_v, max_v, avg_v, days = graph_income(days)
    elif graph == "amv":
        title = "Average Monthly Value"
        min_v, max_v, avg_v, days = graph_members(days)
    elif graph == "churn":
        title = "Membership Churn"

    context = {'title':title, 'graph':graph,
        'days': days, 'date_range_form': date_range_form, 'start': start, 'end': end,
        'min': min_v, 'max': max_v, 'avg': avg_v}
    return render(request, 'staff/stats/graph.html', context)
Ejemplo n.º 3
0
def transactions(request):
    page_message = None
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end})
    transactions = Transaction.objects.filter(transaction_date__range=(start, end)).order_by('-transaction_date')
    context = {"transactions": transactions, 'date_range_form': date_range_form, 'page_message': page_message}
    return render(request, 'staff/transactions.html', context)
Ejemplo n.º 4
0
def bill_list(request):
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end})
    starteo = timeo.strptime(start, "%Y-%m-%d")
    start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday)
    endeo = timeo.strptime(end, "%Y-%m-%d")
    end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday)
    bills = Bill.objects.filter(bill_date__range=(start_date, end_date), amount__gt=0).order_by('bill_date').reverse()
    total_amount = bills.aggregate(s=Sum('amount'))['s']
    return render_to_response('staff/bill_list.html', {'bills': bills, 'total_amount': total_amount, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date}, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def transactions(request):
    page_message = None
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({
        START_DATE_PARAM: start,
        END_DATE_PARAM: end
    })
    transactions = Transaction.objects.filter(
        transaction_date__range=(start, end)).order_by('-transaction_date')
    context = {
        "transactions": transactions,
        'date_range_form': date_range_form,
        'page_message': page_message
    }
    return render(request, 'staff/billing/transactions.html', context)
Ejemplo n.º 6
0
def history(request):
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end})
    logs = [log for log in Membership.objects.all()]
    end_date = timezone.now().date()
    if len(logs) > 0:
        start_date = logs[0].start_date
    else:
        start_date = end_date

    monthly_stats = [{'start_date': d, 'end_date': beginning_of_next_month(d) - timedelta(days=1)} for d in first_days_in_months(start_date, end_date)]
    for stat in monthly_stats:
        stat['monthly_total'] = Membership.objects.active_memberships(stat['end_date']).count()
        stat['started'] = Membership.objects.filter(start_date__range=(stat['start_date'], stat['end_date'])).count()
        stat['ended'] = Membership.objects.filter(end_date__range=(stat['start_date'], stat['end_date'])).count()
    monthly_stats.reverse()
    context = {'monthly_stats': monthly_stats,
               'date_range_form': date_range_form,
               'start': start,
               'end': end}
    return render(request, 'staff/stats/history.html', context)
Ejemplo n.º 7
0
def bill_list(request):
    start, end = date_range_from_request(request)
    date_range_form = DateRangeForm({
        START_DATE_PARAM: start,
        END_DATE_PARAM: end
    })
    starteo = timeo.strptime(start, "%Y-%m-%d")
    start_date = date(year=starteo.tm_year,
                      month=starteo.tm_mon,
                      day=starteo.tm_mday)
    endeo = timeo.strptime(end, "%Y-%m-%d")
    end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday)
    bills = Bill.objects.filter(bill_date__range=(start_date, end_date),
                                amount__gt=0).order_by('bill_date').reverse()
    total_amount = bills.aggregate(s=Sum('amount'))['s']
    context = {
        'bills': bills,
        'total_amount': total_amount,
        'date_range_form': date_range_form,
        'start_date': start_date,
        'end_date': end_date
    }
    return render(request, 'staff/billing/bill_list.html', context)