Example #1
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    amex = []
    visamc = []
    ach = []
    settled_checks = []
    other_transactions = []
    totals = {'amex_total':0, 'visamc_total':0, 'ach_total':0, 'total':0}
    open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    try:
        api = PaymentAPI()

        if 'close_batch' in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        transactions = api.get_transactions(year, month, day)
        totals['total_count'] = len(transactions)

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)

        for t in transactions:
            # Pull the member and the amount they owe
            member = Member.objects.filter(user__username = t['username']).first()
            if member:
                t['member'] = member
                t['open_bill_amount'] = member.open_bill_amount()
                t['xero_invoices'] = open_xero_invoices.get(t['username'], [])
                for i in t['xero_invoices']:
                    if i['AmountDue'] != t['amount']:
                        t['xero_invoices'].remove(i)

            # Total up all the Settled transactions
            if t['transaction_type'] == "Sale" and t['status'] != "Declined" and t['status'] != "Error":
                totals['total'] = totals['total'] + t['amount']
                if t['card_type'] == "A":
                    amex.append(t)
                    totals['amex_total'] = totals['amex_total'] + t['amount']
                elif t['card_type'] == "V" or t['card_type'] == "M":
                    visamc.append(t)
                    totals['visamc_total'] = totals['visamc_total'] + t['amount']
                elif t['card_type'] == "ACH":
                    ach.append(t)
                    totals['ach_total'] = totals['ach_total'] + t['amount']

                # Presence of authorized transactions means this batch is still open
                if t['status'] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)


    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response('staff/charges.html', {'date': d, 'amex': amex, 'visamc': visamc, 'ach':ach, 'open_batch':open_batch,
                                                      'other_transactions': other_transactions, 'settled_checks':settled_checks, 'totals':totals,
                                                      'next_date': d + timedelta(days=1), 'previous_date': d - timedelta(days=1)}, context_instance=RequestContext(request))
Example #2
0
def xero_user(request, username):
    user = get_object_or_404(User, username=username)
    xero_api = XeroAPI()

    if request.method == 'POST':
        action = request.POST.get('action').lower()
        if action == "link":
            if 'xero_id' in request.POST:
                xero_id = request.POST.get('xero_id').strip()
                if len(xero_id) > 0:
                    try:
                        if len(xero_api.xero.contacts.get(xero_id)) == 1:
                            XeroContact.objects.create(user=user, xero_id=xero_id)
                    except Exception:
                        pass
        elif action == "sync" or action == "add":
            xero_api.sync_user_data(user)

    invoices = None
    repeating_invoices = None
    xero_contact_data = None
    xero_contact_search = None
    xero_contact = XeroContact.objects.filter(user=user).first()
    if not xero_contact:
        xero_contact_search = xero_api.find_contacts(user)
    else:
        invoices = xero_api.get_invoices(user)
        invoices.reverse()
        repeating_invoices = xero_api.get_repeating_invoices(user)
        xero_contact_data = xero_api.get_contact(user)
    return render_to_response('staff/xero.html', {'user': user, 'xero_contact': xero_contact, 'invoices': invoices, 'repeating_invoices':repeating_invoices,
        'xero_contact_data': xero_contact_data, 'xero_contact_search': xero_contact_search}, context_instance=RequestContext(request))
Example #3
0
def xero_user(request, username):
    user = get_object_or_404(User, username=username)
    xero_api = XeroAPI()

    if request.method == "POST":
        action = request.POST.get("action").lower()
        if action == "link":
            if "xero_id" in request.POST:
                xero_id = request.POST.get("xero_id").strip()
                if len(xero_id) > 0:
                    try:
                        if len(xero_api.xero.contacts.get(xero_id)) == 1:
                            XeroContact.objects.create(user=user, xero_id=xero_id)
                    except Exception:
                        pass
        elif action == "sync" or action == "add":
            xero_api.sync_user_data(user)

    invoices = None
    repeating_invoices = None
    xero_contact_data = None
    xero_contact_search = None
    xero_contact = XeroContact.objects.filter(user=user).first()
    if not xero_contact:
        xero_contact_search = xero_api.find_contacts(user)
    else:
        invoices = xero_api.get_invoices(user)
        invoices.reverse()
        repeating_invoices = xero_api.get_repeating_invoices(user)
        xero_contact_data = xero_api.get_contact(user)
    return render_to_response(
        "staff/xero.html",
        {
            "user": user,
            "xero_contact": xero_contact,
            "invoices": invoices,
            "repeating_invoices": repeating_invoices,
            "xero_contact_data": xero_contact_data,
            "xero_contact_search": xero_contact_search,
        },
        context_instance=RequestContext(request),
    )
Example #4
0
 def open_xero_invoices(self):
     from nadine.utils.xero_api import XeroAPI
     xero_api = XeroAPI()
     return xero_api.get_open_invoices(self.user)
Example #5
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    ach = []
    credit_cards = []
    settled_checks = []
    other_transactions = []
    totals = {'cc_total':0, 'ach_total':0, 'settled_checks':0, 'total':0}

    open_xero_invoices = {}
    try:
        open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    except Exception:
        # Xero not integrated
        pass

    try:
        api = PaymentAPI()

        if 'close_batch' in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)
        add_bills_and_invoices(settled_checks, open_xero_invoices)
        for t in settled_checks:
            totals['settled_checks'] = totals['settled_checks'] + t['amount']

        # Pull the transactions and suplement the information
        transactions = api.get_transactions(year, month, day)
        add_bills_and_invoices(transactions, open_xero_invoices)

        # Total up all the Settled transactions
        totals['total_count'] = len(transactions) + len(settled_checks)
        for t in transactions:
            if t['transaction_type'] == "Sale" and t['status'] != "Declined" and t['status'] != "Error":
                totals['total'] = totals['total'] + t['amount']
                if t['card_type'] == "ACH":
                    ach.append(t)
                    totals['ach_total'] = totals['ach_total'] + t['amount']
                else:
                    credit_cards.append(t)
                    totals['cc_total'] = totals['cc_total'] + t['amount']

                # Presence of authorized transactions means this batch is still open
                if t['status'] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    context = {
        'date': d,
        'ach':ach,
        'credit_cards': credit_cards,
        'open_batch':open_batch,
        'other_transactions': other_transactions,
        'settled_checks':settled_checks,
        'totals':totals,
        'previous_date': d - timedelta(days=1),
        'next_date': d + timedelta(days=1),
    }
    return render(request, 'staff/billing/charges.html', context)
Example #6
0
    def open_xero_invoices(self):
        from nadine.utils.xero_api import XeroAPI

        xero_api = XeroAPI()
        return xero_api.get_open_invoices(self.user)
Example #7
0
def usaepay_transactions(request, year, month, day):
    d = date(year=int(year), month=int(month), day=int(day))
    open_batch = False
    amex = []
    visamc = []
    ach = []
    settled_checks = []
    other_transactions = []
    totals = {"amex_total": 0, "visamc_total": 0, "ach_total": 0, "total": 0}
    open_xero_invoices = XeroAPI().get_open_invoices_by_user()
    try:
        api = PaymentAPI()

        if "close_batch" in request.GET:
            api.close_current_batch()
            messages.add_message(request, messages.INFO, "Current batch closed")

        transactions = api.get_transactions(year, month, day)
        totals["total_count"] = len(transactions)

        # Pull the settled checks seperately
        settled_checks = api.get_checks_settled_by_date(year, month, day)

        for t in transactions:
            # Pull the member and the amount they owe
            u = User.objects.filter(username=t["username"]).first()
            if u:
                # TODO - change to User
                t["member"] = u.profile
                t["open_bill_amount"] = u.profile.open_bill_amount()
                t["xero_invoices"] = open_xero_invoices.get(t["username"], [])
                for i in t["xero_invoices"]:
                    if i["AmountDue"] != t["amount"]:
                        t["xero_invoices"].remove(i)

            # Total up all the Settled transactions
            if t["transaction_type"] == "Sale" and t["status"] != "Declined" and t["status"] != "Error":
                totals["total"] = totals["total"] + t["amount"]
                if t["card_type"] == "A":
                    amex.append(t)
                    totals["amex_total"] = totals["amex_total"] + t["amount"]
                elif t["card_type"] == "V" or t["card_type"] == "M":
                    visamc.append(t)
                    totals["visamc_total"] = totals["visamc_total"] + t["amount"]
                elif t["card_type"] == "ACH":
                    ach.append(t)
                    totals["ach_total"] = totals["ach_total"] + t["amount"]

                # Presence of authorized transactions means this batch is still open
                if t["status"] == "Authorized":
                    open_batch = True
            else:
                other_transactions.append(t)

    except Exception as e:
        messages.add_message(request, messages.ERROR, e)

    return render_to_response(
        "staff/charges.html",
        {
            "date": d,
            "amex": amex,
            "visamc": visamc,
            "ach": ach,
            "open_batch": open_batch,
            "other_transactions": other_transactions,
            "settled_checks": settled_checks,
            "totals": totals,
            "next_date": d + timedelta(days=1),
            "previous_date": d - timedelta(days=1),
        },
        context_instance=RequestContext(request),
    )