def action_record_payment(request): # Process our payment form bill_id = None if request.method == 'POST': payment_form = PaymentForm(request.POST) bill_id = payment_form['bill_id'].value() try: if payment_form.is_valid(): payment = payment_form.save(created_by=request.user.username) messages.success(request, "Payment of $%s recorded." % payment.amount) except Exception as e: messages.error(request, str(e)) else: raise Exception("Must be a POST!") if 'next' in request.POST: return HttpResponseRedirect(request.POST.get('next')) if bill_id: return HttpResponseRedirect(reverse('staff:billing:bill', kwargs={'bill_id': bill_id})) return HttpResponseRedirect(reverse('staff:billing:bills'))
def pay_bills_form(self): from nadine.forms import PaymentForm return PaymentForm(initial={'username': self.user.username, 'amount': self.open_bills_amount})
def bill_view(request, bill_id): bill = get_object_or_404(UserBill, id=bill_id) if request.method == 'POST': if 'delete_payment_id' in request.POST: try: payment_id = request.POST.get('delete_payment_id') payment = Payment.objects.get(id=payment_id) payment.delete() messages.success(request, "Payment deleted.") except Exception as e: messages.error(request, str(e)) if 'mark_paid' in request.POST: bill.mark_paid = True bill.save() messages.success(request, "Bill marked as paid.") if 'close_bill' in request.POST: bill.close() messages.success(request, "Bill marked as closed.") if 'waive_day' in request.POST: day_id = request.POST.get('waive_day') day = CoworkingDay.objects.get(pk=day_id) day.mark_waived() bill.recalculate() messages.success(request, "Activity on %s waived and bill recalculated." % day.visit_date) if 'recalculate' in request.POST: bill.recalculate() messages.success(request, "Bill recalculated.") initial_data = { 'bill_id': bill.id, 'username': bill.user.username, 'payment_date': localtime(now()), 'amount': bill.total_owed, 'can_waive_days': bill.total_paid == 0, } payment_form = PaymentForm(initial=initial_data) # Calculate how past due this bill is overdue = (localtime(now()).date() - bill.due_date).days if overdue < 1: overdue = None # Count up all the resources on this bill resources = {} if bill.coworking_day_count > 0 or bill.coworking_day_allowance > 0: resources['days'] = { 'count': bill.coworking_day_count, 'billable': bill.coworking_day_billable_count, 'allowance': bill.coworking_day_allowance, 'overage': bill.coworking_day_overage, } if bill.desk_allowance: resources['desk'] = bill.desk_allowance if bill.mail_allowance: resources['mail'] = bill.mail_allowance if bill.key_allowance: resources['key'] = bill.key_allowance line_items = bill.line_items.all().order_by('id') context = { 'bill': bill, 'line_items': line_items, 'resources': resources, 'overdue': overdue, 'payment_form': payment_form, } return render(request, 'staff/billing/bill_view.html', context)