Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Altered a exchanges and exchane_route to handle NULL values fir recon…
Browse files Browse the repository at this point in the history
…ciliations
  • Loading branch information
kaguillera committed Sep 21, 2016
1 parent 57180d6 commit 8ad9096
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
29 changes: 29 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Alter the enums to cater for missing data.
ALTER TYPE payment_net ADD VALUE 'unknown';
ALTER TYPE exchange_status ADD VALUE 'unknown';

-- Update the field status in the exchanges table from NULL to 'unknown'
UPDATE exchanges SET status = 'unknown' WHERE status IS NULL;

-- Alter the exchanges table to ensure that no more NULL values are entered
ALTER TABLE exchanges ALTER COLUMN status SET NOT NULL;

-- Insert records for ‘unknown’ (previously NULL in exchanges table
-- network in exchange_route table
INSERT INTO exchange_routes (participant, network, address, error)
(
SELECT DISTINCT participants.id, 'unknown'::payment_net, 'None', 'None'
FROM exchanges, participants
WHERE exchanges.participant = participants.username
AND route IS NULL
);

-- Update exchanges records with exchange_route ids pointing to ‘unknown’ network records for that participants
UPDATE exchanges
SET route = exchange_routes.id
FROM exchange_routes, participants
WHERE exchange_routes.participant = participants.id
AND participants.username = exchanges.participant;

-- Alter exchanges table and set route to not null
ALTER TABLE exchanges ALTER COLUMN route SET NOT NULL;
25 changes: 17 additions & 8 deletions www/dashboard/reconciliation.spt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def by_month():
month = str(month)[:7]
if month not in by_month.keys():
by_month[month] = { network: { 's_payin': 0, 'p_payin': 0, 'f_payin': 0, \
'total_payin': 0, 'payin_income': 0, \
'u_payin': 0, 'total_payin': 0, 'payin_income': 0, \
's_payout': 0, 'p_payout': 0, 'f_payout': 0,\
'total_payout': 0, 'payout_income': 0 } }
'u_payout': 0, 'total_payout': 0, 'payout_income': 0 } }
if network not in by_month[month].keys():
by_month[month][network] = { 's_payin': 0, 'p_payin': 0, 'f_payin': 0, \
'total_payin': 0, 'payin_income': 0, \
'u_payin': 0, 'total_payin': 0, 'payin_income': 0, \
's_payout': 0, 'p_payout': 0, 'f_payout': 0,\
'total_payout': 0, 'payout_income': 0 }
'u_payout': 0,'total_payout': 0, 'payout_income': 0 }
if status == 'succeeded':
by_month[month][network]['s_payin'] = payins
by_month[month][network]['s_payout'] = payouts
Expand All @@ -45,6 +45,9 @@ def by_month():
if status == 'failed':
by_month[month][network]['f_payin'] = payins
by_month[month][network]['f_payout'] = payouts
if status == 'unknown':
by_month[month][network]['u_payin'] = payins
by_month[month][network]['u_payout'] = payouts
by_month[month][network]['total_payin'] += payins
by_month[month][network]['total_payout'] += payouts

Expand All @@ -54,9 +57,9 @@ def by_month():

def by_month_csv(by_month):
output = [ ["Month", "Network", "Succeeded Payins", "Pending Payins",
"Failed Payins", "Total Payins", "Payin Fee Income",
"Succeeded Payouts", "Pending Payouts",
"Failed Payouts","Total Payouts", "Payout Fee Income"] ]
"Failed Payins", "Unknown Payin", "Total Payins", "Payin Fee Income",
"Succeeded Payouts", "Pending Payouts", "Failed Payouts",
"Unknown Payout", "Total Payouts", "Payout Fee Income"] ]
for month, recs in sorted(by_month.items()):
for network,transfers in recs.items():
row = []
Expand All @@ -65,11 +68,13 @@ def by_month_csv(by_month):
row.append( transfers['s_payin'] )
row.append( transfers['p_payin'] )
row.append( transfers['f_payin'] )
row.append( transfers['u_payin'] )
row.append( transfers['total_payin'] )
row.append( transfers['payin_income'] )
row.append( transfers['s_payout'] )
row.append( transfers['p_payout'] )
row.append( transfers['f_payout'] )
row.append( transfers['u_payout'] )
row.append( transfers['total_payout'] )
row.append( transfers['payout_income'] )
output.append(row)
Expand Down Expand Up @@ -131,12 +136,14 @@ by_month
<th>Succeeded</th>
<th>Pending</th>
<th>Failed</th>
<th>Unknown</th>
<th>Total</th>
<th>Fee Income</th>
<th>&nbsp;</th>
<th>Succeeded</th>
<th>Pending</th>
<th>Failed</th>
<th>Unknown</th>
<th>Total</th>
<th>Fee Income</th>
</tr>
Expand All @@ -146,17 +153,19 @@ by_month
<td>{{ fmt( transfers['s_payin'] ) }}</td>
<td>{{ fmt( transfers['p_payin'] ) }}</td>
<td>{{ fmt( transfers['f_payin'] ) }}</td>
<td>{{ fmt( transfers['u_payin'] ) }}</td>
<td>{{ fmt( transfers['total_payin'] ) }}</td>
<td>{{ fmt( transfers['payin_income'] ) }}</td>
<td>&nbsp;</td>
<td>{{ fmt( transfers['s_payout'] ) }}</td>
<td>{{ fmt( transfers['p_payout'] ) }}</td>
<td>{{ fmt( transfers['f_payout'] ) }}</td>
<td>{{ fmt( transfers['u_payout'] ) }}</td>
<td>{{ fmt( transfers['total_payout'] ) }}</td>
<td>{{ fmt( transfers['payout_income'] ) }}</td>
</tr>
{% endfor %}
<tr><td colspan="12"><hr></td></tr>
<tr><td colspan="14"><hr></td></tr>
</table>
{% endfor %}

Expand Down

0 comments on commit 8ad9096

Please sign in to comment.