Comments (14)
SELECT month,
(CASE WHEN network = 'balanced-cc' THEN payins ELSE NULL END) AS "Balanced Payins",
(CASE WHEN network = 'paypal' THEN payins ELSE NULL END) AS "Balanced Payins",
(CASE WHEN network = 'balanced-cc' THEN payouts ELSE NULL END) AS "Balanced Payouts",
(CASE WHEN network = 'paypal' THEN payouts ELSE NULL END) AS "Balanced Payouts", network
FROM ( 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
, network
FROM exchanges, exchange_routes
WHERE exchanges.route = exchange_routes.id
GROUP BY month, exchange_routes.network
ORDER BY month ASC
)
AS totals;
from finances.
Per IRL convo, here's a hack to get the list of payment networks dynamically:
select enumlabel from pg_enum where enumtypid =
(select typelem from pg_type where typname='_payment_net');
from finances.
So I was wondering about the structure of the table that we want to get. It would narrow how to get the data a little. Below are the options that I was considering.
Month | Network1 payins | Network1 payouts | Network2 payins | Network2 payouts | Total payins | Total Payouts |
---|---|---|---|---|---|---|
2016-02-02 | $5.00 | $4.000 | $1.00 | $5.00 | $4.000 | $1.00 |
OR
Month | Network | Payins | Payouts | Income |
---|---|---|---|---|
2016-02-02 | Network1 | $5.00 | $4.000 | $1.00 |
2016-02-02 | Network2 | $6.00 | $7.000 | $1.50 |
from finances.
@kaguillera Let's go for:
2012-06
Network | Succeeded | Failed | Pending | Total | Fee Income |
---|---|---|---|---|---|
balanced | 250.00 | 150.00 | 0.00 | 400.00 | 23.00 |
paypal | 150.00 | 50.00 | 5.00 | 205.00 | 15.00 |
from finances.
Actually, we want to diff this against our books programmatically ...
from finances.
Per IRL convo, let's aim for CSVs at endpoints like this:
https://gratipay.com/dashboard/reconciliation/2012-06.csv
With columns as above: network
, succeeded
, failed
, pending
, total
, fee_income
.
from finances.
"What about the payout part?"—@kaguillera
from finances.
Yeah, we'll need that. Let's focus on what we need for 2012-06 and 2012-07. We can evolve the export as we work through the rest of the months.
from finances.
SELECT suc_table.month,
suc_payins,
suc_payouts,
suc_income,
pend_payins,
pend_payouts,
pend_income,
fail_payins,
fail_payouts,
fail_income,
suc_payins + pend_payins AS Total_Payins,
suc_payouts + pend_payouts AS Total_Payouts,
suc_income + pend_income AS Total_Income
FROM ( SELECT date_trunc('month', "timestamp") AS month
, COALESCE( sum(case when amount > 0 then amount end), 0) as suc_payins
, COALESCE( -(sum(case when amount < 0 then amount end)), 0) as suc_payouts
, COALESCE( sum(fee), 0 ) as suc_income
, status
, network
FROM exchanges, exchange_routes
WHERE exchanges.route = exchange_routes.id
AND status = 'succeeded'
GROUP BY month, exchange_routes.network, status
ORDER BY month ASC
) AS suc_table,
( SELECT date_trunc('month', "timestamp") AS month
, COALESCE( sum(case when amount > 0 then amount end), 0) as pend_payins
, COALESCE( -(sum(case when amount < 0 then amount end)), 0) as pend_payouts
, COALESCE( sum(fee), 0 ) as pend_income
, status
, network
FROM exchanges, exchange_routes
WHERE exchanges.route = exchange_routes.id
AND status = 'pending'
GROUP BY month, exchange_routes.network, status
ORDER BY month ASC
) AS pend_table,
( SELECT date_trunc('month', "timestamp") AS month
, COALESCE( sum(case when amount > 0 then amount end), 0) as fail_payins
, COALESCE( -(sum(case when amount < 0 then amount end)), 0) as fail_payouts
, COALESCE( sum(fee), 0 ) as fail_income
, status
, network
FROM exchanges, exchange_routes
WHERE exchanges.route = exchange_routes.id
AND status = 'failed'
GROUP BY month, exchange_routes.network, status
ORDER BY month ASC
) AS fail_table
WHERE suc_table.month = fail_table.month and suc_table.month = pend_table.month;
from finances.
produces:
Month | suc_payins | suc_payouts | suc_income | pend_payins | pend_payouts | pend_income | fail_payins | fail_payouts | fail_income | total_payins | total_payouts | total_income |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2015-06-01 | 841.47 | 9789.95 | 212.64 | 7542.84 | 0 | 150.87 | 522.92 | 0 | 10.46 | 8384.31 | 9789.95 | 363.51 |
2015-06-01 | 841.47 | 9789.95 | 212.64 | 4090.21 | 0 | 81.81 | 522.92 | 0 | 10.46 | 4931.68 | 9789.95 | 294.45 |
2015-06-01 | 2873.20 | 7510.88 | 207.68 | 7542.84 | 0 | 150.87 | 522.92 | 0 | 10.46 | 10416.04 | 7510.88 | 358.55 |
2015-06-01 | 2873.20 | 7510.88 | 207.68 | 4090.21 | 0 | 81.81 | 522.92 | 0 | 10.46 | 6963.41 | 7510.88 | 289.49 |
Not exactly what we are looking for?!
from finances.
Since that approach seems to be beyond me at this time I am going to use following query
SELECT date_trunc('month', "timestamp") AS month
, COALESCE(sum(case when amount > 0 then amount end), 0) as payins
, COALESCE(-(sum(case when amount < 0 then amount end)), 0) as payouts
, sum(fee) as income
, status
, network
FROM exchanges, exchange_routes
WHERE exchanges.route = exchange_routes.id
GROUP BY month, network, status
ORDER BY month ASC;
which produces the following results
month | payins | payouts | income | status | network |
---|---|---|---|---|---|
2015-03-01 | 0 | -2129.94 | 42.60 | succeeded | balanced-cc |
2015-03-01 | 647.53 | 0 | 12.95 | failed | balanced-cc |
2015-04-01 | 3494.54 | 0 | 69.90 | failed | balanced-cc |
2015-04-01 | 0 | -2244.59 | 44.89 | succeeded | paypal |
2015-04-01 | 0 | -3041.29 | 60.82 | succeeded | balanced-cc |
2015-04-01 | 2847.20 | 0 | 56.95 | failed | paypal |
2015-05-01 | 0 | -3379.97 | 67.60 | succeeded | paypal |
2015-05-01 | 5045.79 | 0 | 100.92 | failed | paypal |
The programmatically produce the table show in (#21 (comment))
so here we go...
from finances.
@kaguillera Does gratipay/gratipay.com#3975 close this?
from finances.
Yes. !m @whit537
from finances.
!m @kaguillera
from finances.
Related Issues (20)
- use current activity instead of retained earnings HOT 1
- budget HOT 9
- make sure Xero is canceled HOT 2
- convert to GnuCash HOT 26
- extract Ally operations data HOT 27
- extract PNC data HOT 4
- extract Citizen's data HOT 1
- More statements HOT 6
- convert to Odoo HOT 3
- start a Django app HOT 30
- deploy the Django app HOT 9
- —
- Additional test cases to check balance with bank statements HOT 5
- Finish setting up books HOT 7
- Acquire old PayPal logs HOT 9
- Deploy a public bean-web instance or two HOT 1
- Year end clarification/correction HOT 4
- get escrow off the income statement
- move fee buffer off the income statement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from finances.