Skip to content

Commit

Permalink
Merge pull request #11 from DSACMS/mg-display-payments
Browse files Browse the repository at this point in the history
Query for payroll data and show message if it doesn’t exist
  • Loading branch information
allthesignals authored May 1, 2024
2 parents 2866701 + 6a612e5 commit 37548ca
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 33 deletions.
23 changes: 15 additions & 8 deletions app/controllers/cbv_flows_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CbvFlowsController < ApplicationController
USER_TOKEN_ENDPOINT = 'https://api-sandbox.argyle.com/v2/users';
ITEMS_ENDPOINT = 'https://api-sandbox.argyle.com/v2/items';
PAYSTUBS_ENDPOINT = 'https://api-sandbox.argyle.com/v2/paystubs?limit=2&account='
PAYSTUBS_ENDPOINT = 'https://api-sandbox.argyle.com/v2/paystubs?limit=2&user='

before_action :set_cbv_flow

Expand All @@ -14,11 +14,15 @@ def employer_search
end

def summary
@employer = summary_employer_params[:employer]
@payments = [
{ amount: 810, start: 'March 25', end: 'June 15', hours: 54, rate: 15 },
{ amount: 195, start: 'January 1', end: 'February 23', hours: 13, rate: 15 }
]
@payments = fetch_payroll.map do |payment|
{
amount: payment['net_pay'].to_i,
start: payment['paystub_period']['start_date'],
end: payment['paystub_period']['end_date'],
hours: payment['hours'],
rate: payment['rate']
}
end
end

def reset
Expand Down Expand Up @@ -73,7 +77,10 @@ def fetch_employers
parsed['results']
end

def summary_employer_params
params.permit(:employer)
def fetch_payroll
res = Net::HTTP.get(URI.parse("#{PAYSTUBS_ENDPOINT}#{@cbv_flow.argyle_user_id}"), {"Authorization" => "Basic #{ENV['ARGYLE_API_TOKEN']}"})
parsed = JSON.parse(res)

parsed['results']
end
end
11 changes: 8 additions & 3 deletions app/views/cbv_flows/employer_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<h2>Get payment info from your employer.</h2>

<form data-controller="cbv-flows" action="<%= next_path %>" method="get">
<%= form_with url: next_path, method: :post, data: { controller: "cbv-flows" } do |f| %>
<label class="usa-label" for="employer">Search for an employer</label>
<div class="usa-combo-box margin-bottom-3" data-action="input->cbv-flows#search">
<select class="usa-select" name="employer" id="employer" data-cbv-flows-target="options" data-action="change->cbv-flows#select">
Expand All @@ -18,5 +18,10 @@
</select>
<input type="hidden" name="user[account_id]" data-cbv-flows-target="userAccountId" />
</div>
<button data-action="click->cbv-flows#submit" class="usa-button usa-button--outline" disabled="disabled" type="submit" data-cbv-flows-target="continue">Continue</button>
</form>
<%= f.submit "Continue",
class: "usa-button usa-button--outline",
disabled: "disabled",
type: "submit",
data: { action: "click->cbv-flows#submit", 'cbv-flows-target': "continue" }
%>
<% end %>
49 changes: 27 additions & 22 deletions app/views/cbv_flows/summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<h2>Review payment information from <%= @employer %></h2>
<p>Below is payment information from <%= @employer %> for the past 90 days.</p>
<h2>Review payment information from your employer</h2>

<h3 class="site-preview-heading">Total Payments: $<%= @payments.reduce(0) { |sum, payment| sum + payment[:amount] } %></h3>
<div class="usa-accordion margin-bottom-4">
<% @payments.each_with_index do |payment, index| %>
<div class="usa-accordion__heading">
<button
type="button"
class="usa-accordion__button"
aria-expanded="false"
aria-controls="<%= index %>"
>
Payment of $<%= payment[:amount] %>, <%= payment[:start] %> to <%= payment[:end] %>
</button>
</div>
<div id="<%= index %>" class="usa-accordion__content usa-prose">
<p>
<%= payment[:hours] %> hours at $<%= payment[:rate] %> per hour.
</p>
</div>
<% end %>
</div>
<% if @payments.any? %>
<p>Below is payment information from your employer for the past 90 days.</p>
<h3 class="site-preview-heading">Total Payments: $<%= @payments.reduce(0) { |sum, payment| sum + payment[:amount] } %></h3>

<div class="usa-accordion margin-bottom-4">
<% @payments.each_with_index do |payment, index| %>
<div class="usa-accordion__heading">
<button
type="button"
class="usa-accordion__button"
aria-expanded="false"
aria-controls="<%= index %>"
>
Payment of $<%= payment[:amount] %>, <%= payment[:start] %> to <%= payment[:end] %>
</button>
</div>
<div id="<%= index %>" class="usa-accordion__content usa-prose">
<p>
<%= payment[:hours] %> hours at $<%= payment[:rate] %> per hour.
</p>
</div>
<% end %>
</div>
<% else %>
<h3 class="site-preview-heading">No payments found. Please refresh the page after a few minutes.</h3>
<% end %>

<button class="usa-button margin-top-3 usa-button--outline" type="button">Share payment information</button>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get '/entry' => 'cbv_flows#entry'
get '/employer_search' => 'cbv_flows#employer_search'
get '/argyle_link' => 'cbv_flows#argyle_link'
post '/summary' => 'cbv_flows#summary'
get '/summary' => 'cbv_flows#summary'

# Utility route to clear your session; useful during development
Expand Down
33 changes: 33 additions & 0 deletions spec/controllers/cbv_flows_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,41 @@ def stub_environment_variable(variable, value, &block)
render_views

let(:cbv_flow) { CbvFlow.create(case_number: "ABC1234", argyle_user_id: "abc-def-ghi") }
let(:argyle_mock_paystubs_response) do
{
results: [
{
id: '018f1bc6-fa6e-a553-85ba-35fd755caf3b',
name: 'ACME',
net_pay: "1000",
hours: "40",
rate: "25",
paystub_period: {
start_date: "2021-01-01",
end_date: "2021-01-15"
},
},
{
id: '018f1bc6-fa6e-a553-85ba-35fd755c1234',
name: 'ACME',
net_pay: "1000",
hours: "40",
rate: "25",
paystub_period: {
start_date: "2021-01-01",
end_date: "2021-01-15"
},
},
]
}
end

before do
session[:cbv_flow_id] = cbv_flow.id

allow(Net::HTTP).to receive(:get)
.with(URI("#{CbvFlowsController::PAYSTUBS_ENDPOINT}#{cbv_flow.argyle_user_id}"), anything)
.and_return(JSON.generate(argyle_mock_paystubs_response))
end

it "renders properly" do
Expand Down

0 comments on commit 37548ca

Please sign in to comment.