This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Import and Export functionality for pension funds
- Loading branch information
1 parent
23ab3c4
commit 29f912c
Showing
13 changed files
with
328 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
//= require bootstrap-sprockets | ||
//= require ./translations | ||
//= require ./pension_funds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$(document).ready(function(e) { | ||
$(document).on('click', '.pf-export-btn', function(e) { | ||
var country_code = $('#pf-country-code').val(); | ||
if (country_code != '') { | ||
location.href = '/pension_funds/export?country_code=' + country_code; | ||
} else { | ||
alert('Select a country to continue ...'); | ||
return false; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class PensionFundsJsonImporter | ||
attr_reader :country_code, :file, :errors | ||
|
||
def initialize(file, country_code) | ||
@file = file | ||
@country_code = country_code | ||
@errors = [] | ||
end | ||
|
||
def import | ||
return false unless valid? | ||
|
||
begin | ||
funds = JSON.parse(File.read(file.tempfile)) | ||
funds.each do |f| | ||
record = PensionFund.find_or_initialize_by(uuid: f['uuid']) | ||
record.fund = f['fund'] | ||
record.name = f['name'] | ||
record.email = f['email'] | ||
record.country_code = country_code | ||
@errors << record.errors.full_messages.to_sentence unless record.save | ||
end | ||
rescue StandardError => e | ||
@errors << e.message | ||
end | ||
@errors.empty? | ||
end | ||
|
||
def valid? | ||
@errors << 'Select a country' unless country_code.present? | ||
@errors << 'Select a JSON file to continue' unless file.present? | ||
@errors.empty? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
= render 'shared/sidebar', action: :index, resource: :pension_funds | ||
|
||
.edit-block | ||
h1.edit-block__title= t('pension_funds.upload.title') | ||
= form_with url: upload_pension_funds_path, method: 'post' do |form| | ||
.row | ||
.col-md-3 | ||
= form.select :country_code, options_for_select(sorted_countries_list, params[:country_code]), {include_blank: '-- Select Country --'}, class: 'form-control' | ||
.col-md-5 | ||
= form.file_field :json_file, class: 'form-control' | ||
.col-md-1 | ||
= form.button 'Upload', class: 'btn btn-info' | ||
|
||
br | ||
.row | ||
.col-md-12 | ||
table.table-bordered.table-striped.table | ||
thead | ||
tr | ||
th # | ||
th = t('pension_funds.upload.error_message') | ||
ody | ||
- @json_importer.try(:errors).to_a.each_with_index do |error, index| | ||
tr | ||
td = (index += 1) | ||
td = error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[ | ||
{ | ||
"country_code":"AU", | ||
"uuid":"1be3fff55b0f4534a4e25145117acb0b", | ||
"fund":"New Fund name2", | ||
"name":"New user2", | ||
"email":"newuser2@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"aabbadb539c945b89760b3584e4b6c1d", | ||
"fund":"New Fund name", | ||
"name":"New user", | ||
"email":"newuser@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"86d505bb81fb4b5bb957656a0f5e0525", | ||
"fund":"Test Fund", | ||
"name":"Test user One", | ||
"email":"test@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"519717276b524297b50d7975b5353bf4", | ||
"fund":"Energy Industries Superannuation Scheme Pty Ltd.", | ||
"name":"Alexander", | ||
"email":"alex.hutchison@eisuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"0a8d57637517485dac8e6d7ac72946f2", | ||
"fund":"Christian Super Pty. Limited", | ||
"name":"Peter", | ||
"email":"pmurphy@christiansuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"bc77a2784f1546ffad3aba26a02434fa", | ||
"fund":"Care Super", | ||
"name":"Xinting", | ||
"email":"xjia@caresuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"e3a0ef44156d4e7f80747e1e484efb6d", | ||
"fund":"BUSS (Queensland) Proprietary Limited", | ||
"name":"Bob", | ||
"email":"blette@bussq.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"fcc44635784343ae93fbbd34111b3b22", | ||
"fund":"BOC Gases Superannuation Fund", | ||
"name":"Kathy", | ||
"email":"kathy.hocker@boc.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"45959225972945aa8e3c7901b2150881", | ||
"fund":"Australian Catholic Superannuation and Retirement Fund", | ||
"name":"Greg", | ||
"email":"greg.cantor@catholicsuper.com.au" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[ | ||
{ | ||
"country_code":"AU", | ||
"uuid":"1be3fff55b0f4534a4e25145117acb0b", | ||
"fund":"New Fund name2", | ||
"name":"New user2", | ||
"email":"newuser2@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"aabbadb539c945b89760b3584e4b6c1d", | ||
"fund":"New Fund name", | ||
"name":"New user", | ||
"email":"newuser@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"86d505bb81fb4b5bb957656a0f5e0525", | ||
"fund":"Test Fund", | ||
"name":"Test user One", | ||
"email":"test@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"519717276b524297b50d7975b5353bf4", | ||
"fund":"Energy Industries Superannuation Scheme Pty Ltd.", | ||
"name":"Alexander", | ||
"email":"alex.hutchison@eisuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"0a8d57637517485dac8e6d7ac72946f2", | ||
"fund":"Christian Super Pty. Limited", | ||
"name":"Peter", | ||
"email":"pmurphy@christiansuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"bc77a2784f1546ffad3aba26a02434fa", | ||
"fund":"Care Super", | ||
"name":"Xinting", | ||
"email":"xjia@caresuper.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"e3a0ef44156d4e7f80747e1e484efb6d", | ||
"fund":"BUSS (Queensland) Proprietary Limited", | ||
"name":"Bob", | ||
"email":"blette@bussq.com.au" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"fcc44635784343ae93fbbd34111b3b22", | ||
"fund":"BOC Gases Superannuation Fund", | ||
"name":"Kathy", | ||
"email":"kathy.hocker@boc.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"uuid":"45959225972945aa8e3c7901b2150881", | ||
"fund":"Sample Fund", | ||
"name":"Watson", | ||
"email":"watson@example.com" | ||
}, | ||
{ | ||
"country_code":"AU", | ||
"fund":"Example fund", | ||
"name":"Sample One", | ||
"email":"watson100@example.com" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.