diff --git a/www/dashboard/reconciliation.spt b/www/dashboard/reconciliation.spt new file mode 100644 index 0000000000..0c437b20f2 --- /dev/null +++ b/www/dashboard/reconciliation.spt @@ -0,0 +1,112 @@ +import calendar +import datetime +from decimal import Decimal as D + +[---] +_by_month = website.db.all(""" + + SELECT date_trunc('month', "timestamp") as month + , sum(case when amount > 0 then amount end) as payins + , -(sum(case when amount < 0 then amount end)) as payouts + , sum(fee) as income + + FROM exchanges + GROUP BY month + ORDER BY month ASC + +""") +def by_month(): + balance = D(0) + for month, payins, payouts, income in _by_month: + balance = balance + payins - payouts + yield month, payins, payouts, balance, income +by_month = by_month() + +if user.ADMIN: + by_day = website.db.all(""" + SELECT date_trunc('day', timestamp)::date as day + , sum(case when amount > 0 then amount + fee else 0 end) as charge_amount + , sum(case when amount < 0 then -(amount - fee) else 0 end) as payout_amount + , sum(amount) as liability_delta + , sum(fee) as income + + FROM exchanges + GROUP BY day + ORDER BY day ASC; + """) + +fmt = lambda x: "{:,.2f}".format(x) +[---] text/html + + + Escrow Reconciliation Report + + + +

Reconciliation Reports

+

These reports are used as part of Gratipay's financial accounting + process.

+ +

Escrow and Income by Month

+ + + + + + + + + {% for month, payins, payouts, balance, fees in by_month %} + + + + + + + + {% endfor %} +
MonthPayins ($)Payouts ($)Balance ($)Fee Income ($)
{{ str(month)[:7] }}{{ fmt(payins) }}{{ fmt(payouts) }}{{ fmt(balance) }}{{ fmt(fees) }}
+ + {% if user.ADMIN %} +

By Day

+ + + + + + + + + {% for day, charge_amount, payout_amount, liability_delta, fee in by_day %} + + + + + + + + {% endfor %} +
DateCharge Amount ($)Payout Amount ($)Fee Income ($)Liability Δ ($)
{{ day }}{{ fmt(charge_amount) }}{{ fmt(payout_amount) }}{{ fmt(fee) }}{{ fmt(liability_delta) }}
+ {% endif %} + +