def overview(request): if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() income_list,income = detail_for_type(start, end,"INC") cogs_list,cogs = detail_for_type(start, end,"COGS") expense_list,expense = detail_for_type(start, end,"EXP") cogs_plus_expense = cogs + expense net = income - cogs_plus_expense return simple.direct_to_template(request, template='beancounter/overview.html', extra_context = { 'form': form, 'income_list': income_list, 'income': income, 'cogs_list': cogs_list, 'cogs': cogs, 'expense_list': expense_list, 'expense': expense, 'cogs_plus_expense': cogs_plus_expense, 'net': net, })
def overview(request): if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() income_list, income = detail_for_type(start, end, "INC") cogs_list, cogs = detail_for_type(start, end, "COGS") expense_list, expense = detail_for_type(start, end, "EXP") cogs_plus_expense = cogs + expense net = income - cogs_plus_expense return simple.direct_to_template(request, template='beancounter/overview.html', extra_context={ 'form': form, 'income_list': income_list, 'income': income, 'cogs_list': cogs_list, 'cogs': cogs, 'expense_list': expense_list, 'expense': expense, 'cogs_plus_expense': cogs_plus_expense, 'net': net, })
def income_vs_cost(request): """ Return a list of dictionaries containing COGS and related INC spending for the report time specified. """ if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() cogs_categories = Category.objects.filter(type__exact='COGS') totals = [] for cat in cogs_categories: if cat.income: #this should be in the query cogs_entries = Entry.objects.filter(date__gte=start, date__lt=end, category=cat) cogs_total = decimal.Decimal('0') #total for COGS category for e in cogs_entries: cogs_total += e.amount income_total = decimal.Decimal('0') income_entries = Entry.objects.filter(date__gte=start, date__lt=end, category=cat.income) #total for associated Income category for i in income_entries: income_total += i.amount totals.append({ 'cogs_category': cat.name, 'cogs_total': cogs_total, 'income_category': cat.income, 'income_total': income_total, 'balance': income_total - cogs_total, }) return simple.direct_to_template(request, template='beancounter/incomevscost.html', extra_context={ 'form':form, 'totals': totals, })
def income_vs_cost(request): """ Return a list of dictionaries containing COGS and related INC spending for the report time specified. """ if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() cogs_categories = Category.objects.filter(type__exact='COGS') totals = [] for cat in cogs_categories: if cat.income: #this should be in the query cogs_entries = Entry.objects.filter(date__gte=start, date__lt=end, category=cat) cogs_total = decimal.Decimal('0') #total for COGS category for e in cogs_entries: cogs_total += e.amount income_total = decimal.Decimal('0') income_entries = Entry.objects.filter(date__gte=start, date__lt=end, category=cat.income) #total for associated Income category for i in income_entries: income_total += i.amount totals.append({ 'cogs_category': cat.name, 'cogs_total': cogs_total, 'income_category': cat.income, 'income_total': income_total, 'balance': income_total - cogs_total, }) return simple.direct_to_template(request, template='beancounter/incomevscost.html', extra_context={ 'form': form, 'totals': totals, })
def moneyin_moneyout(request): """ Return a list of dictionaries containing COGS and related INC spending for the report time specified. """ if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() entries = Entry.objects.filter(date__gte=start, date__lt=end) income_dict = {} expense_dict = {} for e in entries: if e.category in ['EXP', 'COGS']: if expense_dict.has_key(e.name.name): expense_dict[e.name.name] += e.amount else: expense_dict[e.name.name] = e.amount elif e.category == 'INC': if income_dict.has_key(e.name.name): income_dict[e.name.name] += e.amount else: income_dict[e.name.name] = e.amount return simple.direct_to_template(request, template='beancounter/moneyin-moneyout.html', extra_context={ 'form':form, 'income': income_dict, 'expense': expense_dict, })
def moneyin_moneyout(request): """ Return a list of dictionaries containing COGS and related INC spending for the report time specified. """ if request.GET.has_key('month') and request.GET.has_key('year'): form = DateForm(request.GET) else: form = DateForm() start, end = form.get_date_range() entries = Entry.objects.filter(date__gte=start, date__lt=end) income_dict = {} expense_dict = {} for e in entries: if e.category in ['EXP', 'COGS']: if expense_dict.has_key(e.name.name): expense_dict[e.name.name] += e.amount else: expense_dict[e.name.name] = e.amount elif e.category == 'INC': if income_dict.has_key(e.name.name): income_dict[e.name.name] += e.amount else: income_dict[e.name.name] = e.amount return simple.direct_to_template( request, template='beancounter/moneyin-moneyout.html', extra_context={ 'form': form, 'income': income_dict, 'expense': expense_dict, })