diff --git a/sql/branch.sql b/sql/branch.sql new file mode 100644 index 0000000000..cddf03caa3 --- /dev/null +++ b/sql/branch.sql @@ -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; diff --git a/www/dashboard/reconciliation.spt b/www/dashboard/reconciliation.spt index b8fb9a62fb..c122480a88 100644 --- a/www/dashboard/reconciliation.spt +++ b/www/dashboard/reconciliation.spt @@ -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 @@ -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 @@ -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 = [] @@ -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) @@ -131,12 +136,14 @@ by_month