def refund_add(request, actor_pk): actor = get_object_or_404(Actor, pk=actor_pk) if not actor.refund_possible(): messages.error(request, _(u'Für %s liegen keine Informationen für eine Erstattung vor.' % actor)) return redirect('funds-memberlist') account = Account.objects.filter(type='GIRO').first() reason = _(u'Erstattungen\n\n\n\nIBAN: %s\nSWIFT-BIC: %s\n' % (actor.refund_iban, actor.refund_swift_bic)) entry_form_initial = { 'account': account, 'stakeholder': actor, 'reason': reason, 'actor': actor, } form = EntryForm(initial=entry_form_initial) c = { 'verbose_name': Entry.objects.model._meta.verbose_name_plural, 'url_list': 'funds-statement', 'form': form, 'parent_label': account.label, 'parent_pk': account.pk, 'map_area_category': get_map_area_category() } return render(request, 'funds/entry_form.html', get_context_funds(request, 'funds-entry-add', c))
def statement(request, account_pk): account = get_object_or_404(Account, pk=account_pk) entries_filtered = Entry.objects.filter(account=account) area = get_area_by_request(request) if area: entries_filtered = entries_filtered.filter(category__area=area) period = get_period_by_request(request) if period is None: entries = None total_start, total_end = 0, 0 else: entries = entries_filtered.filter(valuta__range=(period.start, period.end)).order_by('-valuta', '-pk') total_start = entries_filtered.filter(valuta__lte=period.start).aggregate(Sum('amount'))['amount__sum'] total_end = entries_filtered.filter(valuta__lte=period.end).aggregate(Sum('amount'))['amount__sum'] periods = Period.objects.all() areas = Area.objects.all() return render(request, 'funds/statement.html', get_context_funds(request, 'funds-statement', {'entries': entries, 'account': account, 'total_start': total_start, 'total_end': total_end, 'current_period': period, 'current_area': area, 'periods': periods, 'areas': areas}))
def report_project_list(request): projects = Project.objects.by_premiere() c = { 'projects': projects } return render(request, 'funds/report-project-list.html', get_context_funds(request, 'funds-report-project-list', c))
def memberlist(request): a = Actor.objects.all() p = Period.objects.all()[:5] if len(p) > 0: for actor in a: status = {} for period in p: status.update({period.pk: {'paid': False, 'amount': 0}}) status[period.pk] = actor.get_membership_fee_paid(period) actor.fee_status = status return render(request, 'funds/memberlist.html', get_context_funds(request, 'funds-memberlist', {'actors': a, 'periods': p}))
def create_cross_entry(request, account_pk): account = get_object_or_404(Account, pk=account_pk) if request.POST: form = CrossEntryForm(request.POST) if form.is_valid(): entry_from, entry_to = Entry.objects.create_cross_entry(actor=request.user.actor, account_from=form.cleaned_data['account_from'], account_to=form.cleaned_data['account_to'], reason=form.cleaned_data['reason'], amount=form.cleaned_data['amount'], valuta=form.cleaned_data['valuta']) messages.success(request, _(u'Die Umbuchung von <em>%s</em> nach <em>%s</em> wurde durchgeführt.' % ( entry_from.account, entry_to.account))) return redirect('funds-statement', account_pk=account_pk) else: form = CrossEntryForm(initial={'account_from': account}) return render(request, 'funds/create-cross-entry.html', get_context_funds(request, 'funds-entry-add-cross', {'account': account, 'form': form}))
def sepa_mandates(request): auto_open_modal = False if request.POST.get('delete', False): sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('delete')) if sepa_mandate.state is sepa_mandate.STATE_PENDING or sepa_mandate.keep_until() < datetime.now().date: message_object_deleted(request, sepa_mandate) sepa_mandate.delete() if request.POST.get('cancel', False): sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('cancel')) sepa_mandate.state = sepa_mandate.STATE_CANCELED sepa_mandate.save() message_object_updated(request, sepa_mandate) if 'sepa_activation' in request.POST: sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('sepa_activation'), state=SEPAMandate.STATE_PENDING) sepa_activate_form = SEPAMandateActivateForm(request.POST, instance=sepa_mandate) if sepa_activate_form.is_valid(): obj = sepa_activate_form.save() message_object_updated(request, obj) else: auto_open_modal = True else: sepa_activate_form = SEPAMandateActivateForm() sepa_mandate_all = SEPAMandate.objects.all() c = { 'view_title': SEPAMandate.objects.model._meta.verbose_name_plural, 'sepa_activate_form': sepa_activate_form, 'objects': sepa_mandate_all, 'auto_open_modal': auto_open_modal } return render(request, 'funds/sepa-mandate-list.html', get_context_funds(request, 'funds-sepa-mandates-list', c))
def report_project_detail(request, project_pk): period = get_period_by_request(request) project = get_object_or_404(Project, pk=project_pk) categories = Category.objects.all().order_by('area') current_entries = Entry.objects.filter(valuta__range=(period.start, period.end)).filter(project=project) entries_debit = current_entries.filter(amount__lt=0).values('category').annotate(sum=Sum('amount')) entries_credit = current_entries.filter(amount__gt=0).values('category').annotate(sum=Sum('amount')) entries_total = current_entries.values('category').annotate(sum=Sum('amount')) last_area = None result_set = { 'label': project.title, 'debit': 0, 'credit': 0, 'total': 0, 'areas': [] } for category in categories: if last_area != category.area_id: area_cnt = len(result_set['areas']) last_area = category.area_id result_set['areas'].append({ 'label': category.area.label, 'debit': 0, 'credit': 0, 'total': 0, 'categories': [] }) category_cnt = len(result_set['areas'][area_cnt]['categories']) result_set['areas'][area_cnt]['categories'].append({ 'label': category.label, 'debit': 0, 'credit': 0, 'total': 0 }) for ed in entries_debit: if ed['category'] == category.pk: result_set['areas'][area_cnt]['categories'][category_cnt]['debit'] += ed['sum'] result_set['areas'][area_cnt]['debit'] += ed['sum'] result_set['debit'] += ed['sum'] for ec in entries_credit: if ec['category'] == category.pk: result_set['areas'][area_cnt]['categories'][category_cnt]['credit'] += ec['sum'] result_set['areas'][area_cnt]['credit'] += ec['sum'] result_set['credit'] += ec['sum'] for et in entries_total: if et['category'] == category.pk: result_set['areas'][area_cnt]['categories'][category_cnt]['total'] += et['sum'] result_set['areas'][area_cnt]['total'] += et['sum'] result_set['total'] += et['sum'] c = { 'periods': Period.objects.all(), 'project': project, 'result_set': result_set } return render(request, 'funds/report-project-detail.html', get_context_funds(request, 'funds-report-project-detail', c))
def report_area(request): """ @TODO: performance? """ period = get_period_by_request(request) categories = Category.objects.all().order_by('area') current_entries = Entry.objects.filter(valuta__range=(period.start, period.end)) entries_debit = current_entries.filter(amount__lt=0).values('category').annotate(sum=Sum('amount')) entries_credit = current_entries.filter(amount__gt=0).values('category').annotate(sum=Sum('amount')) entries_total = current_entries.values('category').annotate(sum=Sum('amount')) result_set = [] last_area = None total = { 'credit': 0, 'debit': 0, 'total': 0 } for category in categories: if last_area != category.area_id: area_cnt = len(result_set) last_area = category.area_id result_set.append({ 'label': category.area.label, 'debit': 0, 'credit': 0, 'total': 0, 'categories': [] }) category_cnt = len(result_set[area_cnt]['categories']) result_set[area_cnt]['categories'].append({ 'label': category.label, 'debit': 0, 'credit': 0, 'total': 0 }) for ed in entries_debit: if ed['category'] == category.pk: result_set[area_cnt]['categories'][category_cnt]['debit'] += ed['sum'] result_set[area_cnt]['debit'] += ed['sum'] total['debit'] += ed['sum'] for ec in entries_credit: if ec['category'] == category.pk: result_set[area_cnt]['categories'][category_cnt]['credit'] += ec['sum'] result_set[area_cnt]['credit'] += ec['sum'] total['credit'] += ec['sum'] for et in entries_total: if et['category'] == category.pk: result_set[area_cnt]['categories'][category_cnt]['total'] += et['sum'] result_set[area_cnt]['total'] += et['sum'] total['total'] += et['sum'] c = { 'current_period': period, 'periods': Period.objects.all(), 'total': total, 'areas': result_set } return render(request, 'funds/report-area.html', get_context_funds(request, 'funds-report-area', c))
def dashboard(request): accounts = Account.objects.all() accounts_creditor = accounts.filter(is_creditor=True) return render(request, 'funds/dashboard.html', get_context_funds(request, 'funds-dashboard', {'accounts': accounts, 'accounts_creditor': accounts_creditor}))
def application_list(request): period = Period.objects.get_current() o = MembershipApplication.objects.all() return render(request, 'funds/membership-application.html', get_context_funds(request, 'funds-membership-application', {'objects': o, 'period': period}))