-
Notifications
You must be signed in to change notification settings - Fork 57
/
financial_status_reports_controller.rb
187 lines (171 loc) · 5.44 KB
/
financial_status_reports_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# frozen_string_literal: true
require 'debts_api/v0/financial_status_report_service'
require 'debts_api/v0/fsr_rehydration_service'
module DebtsApi
module V0
class FinancialStatusReportsController < ApplicationController
service_tag 'financial-report'
before_action { authorize :debt, :access? }
rescue_from DebtsApi::V0::FinancialStatusReportService::FSRNotFoundInRedis, with: :render_not_found
def create
render json: service.submit_financial_status_report(fsr_form)
end
def download_pdf
send_data(
service.get_pdf,
type: 'application/pdf',
filename: 'VA Form 5655 - Submitted',
disposition: 'attachment'
)
end
def submissions
submissions = DebtsApi::V0::Form5655Submission.where(user_uuid: current_user.uuid)
render json: { 'submissions' => submissions.map { |sub| { 'id' => sub.id } } }
end
def rehydrate
submission_id = params[:submission_id]
DebtsApi::V0::FsrRehydrationService.attempt_rehydration(user_uuid: current_user.uuid, submission_id:)
render json: { result: 'FSR rehydrated' }
rescue ActiveRecord::RecordNotFound
render json: { error: "Form5655Submission record #{submission_id} not found." }, status: :not_found
rescue DebtsApi::V0::FsrRehydrationService::UserDoesNotOwnsubmission
render json: { error: "User #{current_user.uuid} does not own submission #{submission_id}" },
status: :unauthorized
rescue DebtsApi::V0::FsrRehydrationService::NoInProgressFormDataStored
render json: { error: "Form5655Submission record #{submission_id} missing InProgressForm data",
status: :not_found }
end
private
def render_not_found
render json: nil, status: :not_found
end
def full_name
%i[first middle last]
end
def address
%i[
addressline_one
addressline_two
addressline_three
city
state_or_province
zip_or_postal_code
country_name
]
end
def name_amount
%i[name amount]
end
# rubocop:disable Metrics/MethodLength
def fsr_form
params.permit(
streamlined: %i[
value
type
],
personal_identification: %i[fsr_reason ssn file_number],
personal_data: [
:telephone_number,
:email,
:date_of_birth,
:married,
{ ages_of_other_dependents: [],
veteran_full_name: full_name,
address:,
spouse_full_name: full_name,
employment_history: [
:veteran_or_spouse,
:occupation_name,
:from,
:to,
:present,
:employer_name,
{ employer_address: address }
] }
],
income: [
:veteran_or_spouse,
:monthly_gross_salary,
:total_deductions,
:net_take_home_pay,
:total_monthly_net_income,
{ deductions: [
:taxes,
:retirement,
:social_security,
{ other_deductions: name_amount }
],
other_income: name_amount }
],
expenses: [
:rent_or_mortgage,
:food,
:utilities,
:other_living_expenses,
:expenses_installment_contracts_and_other_debts,
:total_monthly_expenses,
{ other_living_expenses: name_amount }
],
discretionary_income: %i[
net_monthly_income_less_expenses
amount_can_be_paid_toward_debt
],
assets: [
:cash_in_bank,
:cash_on_hand,
:trailers_boats_campers,
:us_savings_bonds,
:stocks_and_other_bonds,
:real_estate_owned,
:total_assets,
{ automobiles: %i[make model year resale_value],
other_assets: name_amount }
],
installment_contracts_and_other_debts: [
:creditor_name,
:date_started,
:purpose,
:original_amount,
:unpaid_balance,
:amount_due_monthly,
:amount_past_due,
{ creditor_address: address }
],
total_of_installment_contracts_and_other_debts: %i[
original_amount
unpaid_balance
amount_due_monthly
amount_past_due
],
additional_data: [
:additional_comments,
{ bankruptcy: %i[
has_been_adjudicated_bankrupt
date_discharged
court_location
docket_number
] }
],
applicant_certifications: %i[
veteran_signature
],
selected_debts_and_copays: [
:current_ar,
:debt_type,
:deduction_code,
:p_h_amt_due,
:p_h_dfn_number,
:p_h_cerner_patient_id,
:resolution_comment,
:resolution_option,
{ station: [:facilit_y_num] }
]
).to_hash
end
# rubocop:enable Metrics/MethodLength
def service
DebtsApi::V0::FinancialStatusReportService.new(current_user)
end
end
end
end