fe 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +16 -36
  3. data/app/assets/javascripts/fe/admin.js +0 -1
  4. data/app/assets/javascripts/fe/fe.admin.js +40 -16
  5. data/app/assets/javascripts/fe/fe.common.js +48 -14
  6. data/app/assets/javascripts/fe/fe.public.js +1 -414
  7. data/app/assets/javascripts/fe/fe.public.nojquery.js +450 -0
  8. data/app/assets/javascripts/fe/jquery.validate.pack.js +3 -15
  9. data/app/assets/stylesheets/360front.css +0 -0
  10. data/app/assets/stylesheets/fe/fe.screen.css.scss.erb +69 -10
  11. data/app/controllers/fe/admin/elements_controller.rb +64 -48
  12. data/app/controllers/fe/admin/email_templates_controller.rb +2 -2
  13. data/app/controllers/fe/admin/question_pages_controller.rb +1 -1
  14. data/app/controllers/fe/admin/question_sheets_controller.rb +2 -103
  15. data/app/controllers/fe/concerns/admin/question_sheets_controller_concern.rb +112 -0
  16. data/app/controllers/fe/concerns/answer_pages_controller_concern.rb +2 -1
  17. data/app/controllers/fe/concerns/answer_sheets_controller_concern.rb +1 -1
  18. data/app/controllers/fe/concerns/application_controller_concern.rb +13 -0
  19. data/app/controllers/fe/reference_sheets_controller.rb +2 -0
  20. data/app/controllers/fe/references_controller.rb +1 -0
  21. data/app/helpers/fe/application_helper.rb +5 -0
  22. data/app/mailers/fe/notifier.rb +11 -4
  23. data/app/models/answer_sheet.rb +2 -0
  24. data/app/models/fe/application.rb +2 -1
  25. data/app/models/fe/concerns/answer_pages_presenter_concern.rb +10 -1
  26. data/app/models/fe/concerns/answer_sheet_concern.rb +38 -8
  27. data/app/models/fe/concerns/choice_field_concern.rb +17 -10
  28. data/app/models/fe/date_field.rb +1 -1
  29. data/app/models/fe/element.rb +105 -31
  30. data/app/models/fe/page.rb +52 -20
  31. data/app/models/fe/page_element.rb +6 -1
  32. data/app/models/fe/page_link.rb +6 -3
  33. data/app/models/fe/person.rb +11 -8
  34. data/app/models/fe/question.rb +2 -6
  35. data/app/models/fe/question_grid.rb +1 -1
  36. data/app/models/fe/question_grid_with_total.rb +15 -0
  37. data/app/models/fe/question_set.rb +1 -1
  38. data/app/models/fe/question_sheet.rb +15 -13
  39. data/app/models/fe/reference_question.rb +0 -10
  40. data/app/models/fe/reference_sheet.rb +17 -13
  41. data/app/models/staff.rb +2 -0
  42. data/app/validators/email_validator.rb +11 -0
  43. data/app/views/fe/admin/elements/create.js.erb +1 -0
  44. data/app/views/fe/admin/elements/drop.js.erb +1 -0
  45. data/app/views/fe/admin/elements/duplicate.js.erb +1 -0
  46. data/app/views/fe/admin/panels/_advanced_options.html.erb +9 -3
  47. data/app/views/fe/admin/panels/_common_fields.html.erb +19 -5
  48. data/app/views/fe/admin/panels/_page.html.erb +1 -1
  49. data/app/views/fe/admin/panels/_prop_choice_field.html.erb +20 -11
  50. data/app/views/fe/admin/panels/_prop_element.html.erb +2 -9
  51. data/app/views/fe/admin/panels/_prop_page.html.erb +8 -3
  52. data/app/views/fe/admin/panels/_prop_paragraph.html.erb +38 -24
  53. data/app/views/fe/admin/panels/_prop_section.html.erb +8 -2
  54. data/app/views/fe/admin/panels/_prop_sheet.html.erb +4 -1
  55. data/app/views/fe/admin/question_pages/_element.html.erb +11 -1
  56. data/app/views/fe/answer_pages/_answer_page.html.erb +9 -8
  57. data/app/views/fe/answer_pages/_element.html.erb +6 -7
  58. data/app/views/fe/answer_pages/_page_name.html.erb +1 -0
  59. data/app/views/fe/answer_pages/update.js.erb +3 -3
  60. data/app/views/fe/answer_sheets/_answer_sheet.html.erb +3 -3
  61. data/app/views/fe/answer_sheets/_element.html.erb +52 -34
  62. data/app/views/fe/answer_sheets/_incomplete.html.erb +1 -1
  63. data/app/views/fe/answer_sheets/_page_link.html.erb +2 -2
  64. data/app/views/fe/answer_sheets/_pages_list.html.erb +3 -3
  65. data/app/views/fe/answer_sheets/_submit_to.html.erb +1 -0
  66. data/app/views/fe/answer_sheets/edit.html.erb +14 -14
  67. data/app/views/fe/answer_sheets/incomplete.js.erb +3 -0
  68. data/app/views/fe/answer_sheets/index.html.erb +3 -3
  69. data/app/views/fe/answer_sheets/show.html.erb +1 -1
  70. data/app/views/fe/applications/_logout.html.erb +1 -0
  71. data/app/views/fe/applications/show.html.erb +1 -0
  72. data/app/views/fe/questions/fe/_acceptance.html.erb +3 -3
  73. data/app/views/fe/questions/fe/_attachment_field.html.erb +7 -3
  74. data/app/views/fe/questions/fe/_checkbox_field.html.erb +26 -24
  75. data/app/views/fe/questions/fe/_date_field.html.erb +1 -2
  76. data/app/views/fe/questions/fe/_date_field_mmyy.html.erb +2 -2
  77. data/app/views/fe/questions/fe/_drop_down_field.html.erb +3 -2
  78. data/app/views/fe/questions/fe/_paragraph.html.erb +1 -1
  79. data/app/views/fe/questions/fe/_question_grid.html.erb +14 -9
  80. data/app/views/fe/questions/fe/_question_grid_with_total.html.erb +21 -14
  81. data/app/views/fe/questions/fe/_questions.html.erb +2 -2
  82. data/app/views/fe/questions/fe/_radio_button_field.html.erb +12 -11
  83. data/app/views/fe/questions/fe/_rating.html.erb +9 -8
  84. data/app/views/fe/questions/fe/_reference_discipler.html.erb +1 -1
  85. data/app/views/fe/questions/fe/_reference_friend.html.erb +1 -1
  86. data/app/views/fe/questions/fe/_reference_parent.html.erb +1 -1
  87. data/app/views/fe/questions/fe/_reference_peer.html.erb +1 -1
  88. data/app/views/fe/questions/fe/_reference_question.html.erb +22 -15
  89. data/app/views/fe/questions/fe/_reference_roommate.html.erb +1 -1
  90. data/app/views/fe/questions/fe/_reference_spiritual.html.erb +1 -1
  91. data/app/views/fe/questions/fe/_reference_staff.html.erb +1 -1
  92. data/app/views/fe/questions/fe/_section.html.erb +1 -1
  93. data/app/views/fe/questions/fe/_text_area_field.html.erb +10 -3
  94. data/app/views/fe/questions/fe/_text_field.html.erb +1 -1
  95. data/app/views/fe/questions/fe/_yes_no_field.erb +3 -3
  96. data/app/views/fe/reference_pages/_reference.html.erb +11 -11
  97. data/app/views/fe/reference_pages/edit.html.erb +7 -7
  98. data/app/views/fe/reference_sheets/done.html.erb +2 -2
  99. data/app/views/fe/reference_sheets/not_found.html.erb +4 -4
  100. data/app/views/fe/references/edit.html.erb +6 -6
  101. data/app/views/fe/references/show.html.erb +7 -7
  102. data/app/views/fe/references/submit.js.erb +1 -1
  103. data/app/views/fe/submit_pages/_thankyou.html.erb +1 -1
  104. data/app/views/fe/submit_pages/edit.html.erb +9 -9
  105. data/app/views/layouts/fe/_error_messages_for.html.erb +7 -0
  106. data/app/views/layouts/fe/application.html.erb +1 -1
  107. data/config/routes.rb +0 -36
  108. data/db/migrate/20131003044250_create_reference_sheets.rb +1 -0
  109. data/db/migrate/20140623153424_create_fe_people.rb +1 -1
  110. data/db/migrate/20140624180246_create_fe_addresses.rb +1 -1
  111. data/db/migrate/20140624182216_create_fe_phone_numbers.rb +16 -0
  112. data/db/migrate/20140625160545_create_fe_users.rb +1 -1
  113. data/db/migrate/20150504221439_add_all_element_ids_to_pages.rb +5 -0
  114. data/db/migrate/20150713022326_add_locale_columns.rb +9 -0
  115. data/db/migrate/20150714220730_add_locale_to_answer_sheet.rb +5 -0
  116. data/db/migrate/20150928085325_change_pages_all_element_ids_to_text.rb +5 -0
  117. data/db/migrate/20150930191538_add_locale_to_reference_sheets.rb +5 -0
  118. data/lib/access_key_generator.rb +12 -0
  119. data/lib/distinct_distinct_patch.rb +20 -0
  120. data/lib/fe.rb +4 -0
  121. data/lib/fe/engine.rb +16 -4
  122. data/lib/fe/version.rb +1 -1
  123. data/spec/controllers/fe/admin/elements_controller_spec.rb +201 -1
  124. data/spec/controllers/fe/admin/email_templates_controller_spec.rb +26 -1
  125. data/spec/controllers/fe/admin/question_pages_controller_spec.rb +8 -1
  126. data/spec/controllers/fe/admin/question_sheets_controller_spec.rb +48 -1
  127. data/spec/controllers/fe/answer_pages_controller_spec.rb +73 -1
  128. data/spec/controllers/fe/answer_sheets_controller_spec.rb +80 -1
  129. data/spec/controllers/fe/reference_pages_controller.rb +4 -0
  130. data/spec/controllers/fe/references_controller_spec.rb +4 -0
  131. data/spec/controllers/fe/submit_pages_controller_spec.rb +4 -0
  132. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  133. data/spec/dummy/app/helpers/application_helper.rb +9 -0
  134. data/spec/dummy/app/models/application.rb +3 -0
  135. data/spec/dummy/app/models/person.rb +11 -0
  136. data/spec/dummy/app/models/user.rb +3 -0
  137. data/spec/dummy/config/application.rb +2 -1
  138. data/spec/dummy/config/database.yml +20 -17
  139. data/spec/dummy/config/environments/production.rb +1 -5
  140. data/spec/dummy/config/environments/test.rb +3 -1
  141. data/spec/dummy/config/initializers/fast_gettext.rb +5 -0
  142. data/spec/dummy/config/secrets.yml +2 -2
  143. data/spec/dummy/db/migrate/20141203214017_core.fe_engine.rb +92 -0
  144. data/spec/dummy/db/migrate/20141203214018_create_reference_sheets.fe_engine.rb +25 -0
  145. data/spec/dummy/db/migrate/20141203214019_add_element_and_answer_fields.fe_engine.rb +11 -0
  146. data/spec/dummy/db/migrate/20141203214020_create_email_templates.fe_engine.rb +18 -0
  147. data/spec/dummy/db/migrate/20141203214021_add_max_lengths.fe_engine.rb +9 -0
  148. data/spec/dummy/db/migrate/20141203214022_create_join_table.fe_engine.rb +12 -0
  149. data/spec/dummy/db/migrate/20141203214023_remove_question_id_from_element.fe_engine.rb +10 -0
  150. data/spec/dummy/db/migrate/20141203214024_create_fe_people.fe_engine.rb +13 -0
  151. data/spec/dummy/db/migrate/20141203214025_create_fe_addresses.fe_engine.rb +21 -0
  152. data/{db/migrate/20140624182216_create_create_fe_phone_numbers.rb → spec/dummy/db/migrate/20141203214026_create_create_fe_phone_numbers.fe_engine.rb} +1 -0
  153. data/spec/dummy/db/migrate/20141203214027_create_fe_users.fe_engine.rb +13 -0
  154. data/spec/dummy/db/migrate/20141203214028_add_conditional_type_to_elements.fe_engine.rb +6 -0
  155. data/spec/dummy/db/migrate/20141203214029_add_conditional_answer_to_elements.fe_engine.rb +6 -0
  156. data/spec/dummy/db/migrate/20141203214030_remove_short_value_column.fe_engine.rb +6 -0
  157. data/spec/dummy/db/migrate/20141203214031_move_conditional_ids_used_for_choice_field_to_their_own_column.fe_engine.rb +8 -0
  158. data/spec/dummy/db/migrate/20150123215803_create_users.rb +9 -0
  159. data/spec/dummy/db/migrate/20150504222619_add_all_element_ids_to_pages.fe_engine.rb +6 -0
  160. data/spec/dummy/db/migrate/20150930190001_create_fe_phone_numbers.fe_engine.rb +20 -0
  161. data/spec/dummy/db/migrate/20150930190002_add_locale_columns.fe_engine.rb +10 -0
  162. data/spec/dummy/db/migrate/20150930190003_add_locale_to_answer_sheet.fe_engine.rb +6 -0
  163. data/spec/dummy/db/migrate/20150930190004_change_pages_all_element_ids_to_text.fe_engine.rb +6 -0
  164. data/spec/dummy/db/migrate/20150930191756_add_locale_to_reference_sheets.fe_engine.rb +6 -0
  165. data/spec/dummy/db/schema.rb +50 -20
  166. data/spec/dummy/log/development.log +5 -0
  167. data/spec/factories/applications.rb +0 -1
  168. data/spec/factories/dummy_applications.rb +6 -0
  169. data/spec/factories/dummy_people.rb +6 -0
  170. data/spec/factories/dummy_users.rb +6 -0
  171. data/spec/factories/elements.rb +28 -3
  172. data/spec/factories/email_templates.rb +5 -0
  173. data/spec/factories/fe_email_templates.rb +9 -0
  174. data/spec/factories/fe_people.rb +0 -2
  175. data/spec/factories/fe_user.rb +6 -0
  176. data/spec/factories/question_sheet.rb +1 -1
  177. data/spec/factories/reference_sheets.rb +9 -0
  178. data/spec/mailers/fe/notifier_spec.rb +39 -0
  179. data/spec/models/fe/choice_field_spec.rb +20 -0
  180. data/spec/models/fe/element_spec.rb +185 -0
  181. data/spec/models/fe/page_spec.rb +112 -0
  182. data/spec/models/fe/question_sheet_spec.rb +106 -0
  183. data/spec/models/fe/reference_sheet_spec.rb +20 -0
  184. data/spec/rails_helper.rb +41 -13
  185. data/spec/support/choices.xml +6 -0
  186. metadata +136 -48
  187. data/app/assets/javascripts/fe/rails.extra.js +0 -6
  188. data/app/controllers/fe/applications_controller.rb +0 -183
  189. data/app/controllers/fe/payments_controller.rb +0 -184
  190. data/app/models/fe/payment.rb +0 -77
  191. data/app/models/fe/payment_question.rb +0 -22
  192. data/app/views/fe/admin/panels/_prop_payment_question.html.erb +0 -1
  193. data/app/views/fe/application/_logout.html.erb +0 -1
  194. data/app/views/fe/payment_pages/_credit.html.erb +0 -47
  195. data/app/views/fe/payment_pages/_mail.html.erb +0 -27
  196. data/app/views/fe/payment_pages/_payment.html.erb +0 -6
  197. data/app/views/fe/payment_pages/_staff.html.erb +0 -25
  198. data/app/views/fe/payment_pages/_staff_results.html.erb +0 -17
  199. data/app/views/fe/payment_pages/edit.html.erb +0 -75
  200. data/app/views/fe/payment_pages/staff_search.js.erb +0 -2
  201. data/app/views/fe/payments/_credit.html.erb +0 -47
  202. data/app/views/fe/payments/_errors.html.erb +0 -1
  203. data/app/views/fe/payments/_payment.html.erb +0 -13
  204. data/app/views/fe/payments/_staff.html.erb +0 -21
  205. data/app/views/fe/payments/_staff_results.html.erb +0 -18
  206. data/app/views/fe/payments/approve.js.erb +0 -3
  207. data/app/views/fe/payments/create.js.erb +0 -19
  208. data/app/views/fe/payments/destroy.js.erb +0 -7
  209. data/app/views/fe/payments/edit.html.erb +0 -56
  210. data/app/views/fe/payments/error.js.erb +0 -3
  211. data/app/views/fe/payments/no_access.html.erb +0 -7
  212. data/app/views/fe/payments/staff_search.js.erb +0 -1
  213. data/app/views/fe/payments/update.html.erb +0 -24
  214. data/app/views/fe/questions/fe/_payment_question.html.erb +0 -70
  215. data/db/migrate/20140828045339_create_payments.rb +0 -13
  216. data/spec/dummy/db/test.sqlite3 +0 -0
  217. data/spec/factories/payments.rb +0 -7
  218. data/spec/models/fe/payment_question_spec.rb +0 -65
@@ -1,6 +0,0 @@
1
- (function($) {
2
- // Enable sortable items
3
- $(function() {
4
- setUpJsHelpers();
5
- });
6
- })(jQuery);
@@ -1,183 +0,0 @@
1
- module Fe
2
- class ApplicationsController < ApplicationController
3
- append_before_filter :check_valid_user, :only => [:show, :collated_refs, :no_conf, :no_ref]
4
- append_before_filter :setup
5
- append_before_filter :set_title
6
-
7
- layout 'fe/application'
8
-
9
- # dashboard
10
- def index
11
- redirect_to :action => :show_default
12
- end
13
-
14
- def show_default
15
- @application = get_application
16
- setup_view
17
-
18
- render :template => 'fe/answer_sheets/edit'
19
- end
20
-
21
- # create app
22
- def create
23
- @question_sheet = Fe::QuestionSheet.find(params[:question_sheet_id])
24
- @application = @person.applications.build
25
-
26
- @application.save!
27
- @application.question_sheets << @question_sheet
28
- redirect_to fe_application_path(@application)
29
- end
30
-
31
- # edit an apply
32
- def edit
33
- @application = Application.find(params[:id]) unless @application
34
-
35
- if @application.applicant == current_user.person
36
- setup_view
37
-
38
- render :template => 'fe/answer_sheets/edit'
39
- else
40
- no_access
41
- end
42
-
43
- end
44
-
45
- def show
46
- @application = Application.find(params[:id]) unless @application
47
- @answer_sheets = @application.answer_sheets
48
- @show_conf = true
49
- @viewing = true
50
-
51
- if @answer_sheets.empty?
52
- render :action => :too_old
53
- #raise "No applicant sheets in sleeve '#{@application.sleeve.title}'."
54
- return
55
- end
56
- #render :layout => 'admin_application'
57
- end
58
-
59
- def no_ref
60
- @application = Application.find(params[:id]) unless @application
61
- @answer_sheets = [@application]
62
- @show_conf = true
63
-
64
- if @answer_sheets.empty?
65
- render :action => :too_old
66
- #raise "No applicant sheets in sleeve '#{@application.sleeve.title}'."
67
- return
68
- end
69
-
70
- #render :layout => 'admin_application', :template => 'fe/applys/show'
71
- render :template => 'fe/applys/show'
72
- end
73
-
74
- def no_conf
75
- @application = Application.find(params[:id]) unless @application
76
- @answer_sheets = [@application]
77
- @show_conf = false
78
-
79
- if @answer_sheets.empty?
80
- render :action => :too_old
81
- #raise "No applicant sheets in sleeve '#{@application.sleeve.title}'."
82
- return
83
- end
84
-
85
- #render :layout => 'admin_application', :template => 'fe/applys/show'
86
- render :template => 'fe/applys/show'
87
- end
88
-
89
- def collated_refs
90
- @application = Application.find(params[:id]) unless @application
91
- @answer_sheets = @application.references
92
-
93
- if @answer_sheets.empty?
94
- render :action => :too_old
95
- #raise "No applicant sheets in sleeve '#{@application.sleeve.title}'."
96
- return
97
- end
98
-
99
- @reference_question_sheet = Fe::QuestionSheet.find(2) #TODO: constant
100
-
101
- setup_reference("staff")
102
- setup_reference("discipler")
103
- setup_reference("roommate")
104
- setup_reference("friend")
105
-
106
- @show_conf = true
107
- end
108
-
109
- def setup_reference(type)
110
- ref = nil
111
- eval("ref = @" + type + "_reference = @application." + type + "_reference")
112
- raise type unless ref
113
- answer_sheet = ref
114
- question_sheet = answer_sheet.question_sheet
115
- if question_sheet
116
- elements = []
117
- question_sheet.pages.order(:number).each do |page|
118
- elements << page.elements.where("#{Fe::Element.table_name}.kind not in (?)", %w(Fe::Paragraph)).to_a
119
- end
120
- elements = elements.flatten
121
- elements.reject! {|e| e.is_confidential} if @show_conf == false
122
- eval("@" + type + "_elements = Fe::QuestionSet.new(elements, answer_sheet).elements")
123
- else
124
- eval("@" + type + "_elements = []")
125
- end
126
-
127
- end
128
-
129
- def no_access
130
- redirect_to '/'
131
- end
132
-
133
- protected
134
- def setup
135
- @person = get_person # current visitor_id
136
- end
137
-
138
- def get_year
139
- Application::YEAR
140
- end
141
-
142
- def get_person
143
- @person ||= current_person
144
- return nil unless @person
145
- @person.current_address = ::Fe::Address.new(:address_type =>'current') unless @person.current_address
146
- @person.emergency_address1 = ::Fe::Address.new(:address_type =>'emergency1') unless @person.emergency_address1
147
- @person.permanent_address = ::Fe::Address.new(:address_type =>'permanent') unless @person.permanent_address
148
- return @person
149
- end
150
-
151
- def get_application
152
- unless @application
153
- @person ||= get_person
154
- # if this is the user's first visit, we will need to create an apply
155
- if @person.application.nil?
156
- create_application
157
- @application.save!
158
- @person.application = @app
159
- else
160
- @application ||= @person.application
161
- end
162
- end
163
- @application
164
- end
165
-
166
- def create_application
167
- @application = Fe::Application.create :applicant_id => @person.id
168
- end
169
-
170
- def setup_view
171
- @answer_sheet = @application
172
- # edit the first page
173
- @presenter = Fe::AnswerPagesPresenter.new(self, @answer_sheet)
174
- @elements = @presenter.questions_for_page(:first).elements
175
- @page = @presenter.pages.first
176
- @presenter.active_page ||= @page
177
- end
178
-
179
- def set_title
180
- @title = "Form Engine"
181
- end
182
- end
183
- end
@@ -1,184 +0,0 @@
1
- # gather payment information from Applicant
2
- module Fe
3
- class PaymentsController < ApplicationController
4
- prepend_before_filter :ssm_login_required, :except => [:edit, :update]
5
- prepend_before_filter :cas_filter, :authentication_filter, :only => [:edit, :update]
6
- before_filter :setup, :except => [:edit, :update, :approve]
7
-
8
- # Allow applicant to edit payment
9
- # /applications/1/payment_page/edit
10
- # js: provide a partial to replace the answer_sheets page area
11
- def edit
12
- @payment = Fe::Payment.find(params[:id])
13
- @application = @payment.answer_sheet
14
- # if this isn't a staff payment they shouldn't be here for this staff person
15
- unless 'Staff' == @payment.payment_type && current_person.isStaff?
16
- render('no_access') and return
17
- end
18
- @payment.status = "Approved" # set the status so a default radio button will be selected
19
- end
20
-
21
- def create
22
- Fe::Payment.transaction do
23
- @payment = @application.payments.new(payment_params)
24
- if @application.payments.non_denied.length > 0
25
- @payment.errors.add(:base, "You have already submitted a payment for this application.")
26
- render :action => "error"
27
- else
28
- @payment.amount = Fe.cost
29
- @payment.status = 'Pending'
30
- if @payment.valid?
31
- case @payment.payment_type
32
- when "Credit Card"
33
- card_type = params[:payment][:card_type]
34
-
35
- creditcard = ActiveMerchant::Billing::CreditCard.new(
36
- :brand => card_type,
37
- :number => @payment.card_number,
38
- :month => @payment.expiration_month,
39
- :year => @payment.expiration_year,
40
- :verification_value => @payment.security_code,
41
- :first_name => @payment.first_name,
42
- :last_name => @payment.last_name
43
- )
44
-
45
- if creditcard.valid?
46
- response = GATEWAY.purchase(@payment.amount * 100, creditcard)
47
-
48
- if response.success?
49
- @payment.approve!
50
- # TODO: Send notification email
51
- else
52
- @payment.errors.add(:base, "Credit card transaction failed: #{response.message}")
53
- #Send email this way instead of raising error in order to still give an error message to user.
54
- # Fe::Notifier.notification('programmers@cojourners.com', # RECIPIENTS
55
- # "sp_error@uscm.org", # FROM
56
- # "Credit Card Error", # LIQUID TEMPLATE NAME
57
- # {'error' => "Credit card transaction failed: #{response.message} \n #{response.inspect} \n #{creditcard.inspect}"}).deliver
58
- end
59
- else
60
- @payment.errors.add(:card_number, "is invalid. Check the number and/or the expiration date.")
61
- end
62
- when "Mail"
63
- @payment.approve!
64
- when "Staff"
65
- @payment.save
66
- send_staff_payment_request(@payment)
67
- end
68
- end
69
- end
70
- end
71
- end
72
-
73
- def update
74
- @payment = Fe::Payment.includes({:application => :applicant}).find(params[:id])
75
- @application = @payment.answer_sheet
76
- @person = @application.applicant
77
- @payment.status = params[:payment][:status]
78
- staff_approval
79
- @payment.save!
80
- staff_payment_processed_email(@payment)
81
- @payment.answer_sheet.complete
82
- end
83
-
84
- def approve
85
- @payment = Fe::Payment.find(params[:id])
86
- @application = @payment.answer_sheet
87
- @payment.auth_code = si_user.user.person.account_no
88
- case @payment.payment_type
89
- when 'Staff'
90
- staff_approval
91
- staff_payment_processed_email(@payment)
92
- when 'Mail'
93
- Fe::Notifier.notification(@application.email, # RECIPIENTS
94
- Fe.from_email, # FROM
95
- "Check Received", # LIQUID TEMPLATE NAME
96
- {'name' => @application.applicant.informal_full_name}).deliver
97
- end
98
- @payment.approve!
99
- @payment.application.complete
100
- end
101
-
102
- # TODO this be moved to a decorotor or cru_lib as per Josh's instructions not to have Staff code in FE
103
- def staff_search
104
- #@payment = @application.payments.new(params[:payment].slice(:payment_type, :payment_account_no, :auth_code))
105
- @payment = @application.payments.new(staff_search_payment_params)
106
- if @payment.staff_first.to_s.strip.empty? || @payment.staff_last.to_s.strip.empty?
107
- render; return
108
- end
109
- @results = Staff.order('"lastName", "firstName"').where("(\"firstName\" like ? OR \"preferredName\" like ?) AND \"lastName\" like ? and \"removedFromPeopleSoft\" <> 'Y'", @payment.staff_first+'%', @payment.staff_first+'%', @payment.staff_last+'%')
110
- end
111
-
112
- def destroy
113
- @payment = @application.payments.find(params[:id])
114
- @payment.destroy
115
- end
116
-
117
- protected
118
-
119
- def setup
120
- if app_user && app_user.can_su_application?
121
- @answer_sheet = @application = Fe.answer_sheet_class.constantize.find(params[:application_id])
122
- else
123
- @answer_sheet = @application = current_person.applications.find(params[:application_id])
124
- end
125
- end
126
-
127
- def send_staff_payment_request(payment)
128
- @person = @application.applicant
129
- staff = Staff.find_by(accountNo: payment.payment_account_no)
130
- raise "Invalid staff payment request: " + payment.inspect if staff.nil?
131
- Fe::Notifier.notification(staff.email, # RECIPIENTS
132
- Fe.from_email, # FROM
133
- "Staff Payment Request", # LIQUID TEMPLATE NAME
134
- {'staff_full_name' => staff.informal_full_name, # HASH OF VALUES FOR REPLACEMENT IN LIQUID TEMPLATE
135
- 'applicant_full_name' => @person.informal_full_name,
136
- 'applicant_email' => @person.email,
137
- 'applicant_home_phone' => @person.current_address.home_phone,
138
- 'payment_request_url' => url_for(:action => :edit, :application_id => @application.id, :id => @payment.id)},
139
- {:format => :html}).deliver
140
- end
141
-
142
- def staff_approval
143
- @payment.auth_code = current_person.account_no
144
- if @payment.status == "Other Account"
145
- @payment.payment_account_no = params[:other_account]
146
- @payment.approve!
147
- end
148
- end
149
-
150
- def staff_payment_processed_email(payment)
151
- # Send appropriate email
152
- if payment.approved?
153
- # Send receipt to applicant
154
- Fe::Notifier.notification(@application.applicant.email, # RECIPIENTS
155
- Fe.from_email, # FROM
156
- "Applicant Staff Payment Receipt", # LIQUID TEMPLATE NAME
157
- {'applicant_full_name' => @application.applicant.informal_full_name}).deliver
158
- # Send notice to Tool Owner
159
- Fe::Notifier.notification(Fe.from_email, # RECIPIENTS - HARD CODED!
160
- Fe.from_email, # FROM
161
- "Tool Owner Payment Confirmation", # LIQUID TEMPLATE NAME
162
- {'payment_amount' => "$" + @payment.amount.to_s,
163
- 'payment_account_no' => @payment.payment_account_no,
164
- 'payment_auth_code' => @payment.auth_code,
165
- 'payment_id' => @payment.id}).deliver
166
- else
167
- # Sent notice to applicant that payment was declined
168
- Fe::Notifier.notification(@application.email, # RECIPIENTS
169
- Fe.from_email, # FROM
170
- "Payment Refusal", # LIQUID TEMPLATE NAME
171
- {'applicant_full_name' => @application.applicant.informal_full_name}).deliver
172
- end
173
- end
174
-
175
- def payment_params
176
- params.require(:payment).permit(:payment_type, :payment_account_no, :auth_code, :first_name, :last_name, :address,
177
- :city, :state, :zip, :card_number, :card_type, :expiration_month, :expiration_year, :security_code)
178
- end
179
-
180
- def staff_search_payment_params
181
- params.require(:payment).permit(:payment_type, :staff_first, :staff_last)
182
- end
183
- end
184
- end
@@ -1,77 +0,0 @@
1
- module Fe
2
- class Payment < ActiveRecord::Base
3
- self.table_name = self.table_name.sub('fe_', Fe.table_name_prefix)
4
-
5
- attr_accessor :first_name, :last_name, :address, :city, :state, :zip, :card_number,
6
- :expiration_month, :expiration_year, :security_code, :staff_first, :staff_last, :card_type
7
-
8
- belongs_to :application, class_name: Fe.answer_sheet_class
9
-
10
- scope :non_denied, -> { where("(status <> 'Denied' AND status <> 'Errored') OR status is null") }
11
-
12
- after_save :check_app_complete
13
-
14
- validate :credit_card_validation
15
- validate :staff_email_present_if_staff_payment
16
-
17
- def answer_sheet() application; end
18
-
19
- def credit_card_validation
20
- if credit?
21
- errors.add_on_empty([:first_name, :last_name, :address, :city, :state, :zip, :card_number,
22
- :expiration_month, :expiration_year, :security_code])
23
- errors.add(:card_number, "is invalid.") if get_card_type.nil?
24
- end
25
- end
26
-
27
- # TODO move all staff methods to decorators as per instructions from Josh
28
- def staff_email_present_if_staff_payment
29
- if staff? && !payment_account_no.include?('/') # Don't try to validate chart fields
30
- staff = Staff.find_by(accountNo: payment_account_no)
31
- unless staff
32
- errors.add(:base, "We couldn't find a staff member with that account number")
33
- return false
34
- end
35
-
36
- unless staff.email.present?
37
- errors.add(:base, "The staff member you've picked doesn't have an address on file for us to send the request to.")
38
- end
39
- end
40
- end
41
-
42
- def to_s
43
- "#{payment_type}: #{amount} on #{created_at}"
44
- end
45
-
46
- def check_app_complete
47
- if self.approved?
48
- self.answer_sheet.complete
49
- end
50
- end
51
-
52
- def credit?
53
- self.payment_type == 'Credit Card'
54
- end
55
-
56
- def staff?
57
- self.payment_type == 'Staff'
58
- end
59
-
60
- def approved?
61
- self.status == 'Approved'
62
- end
63
-
64
- def approve!
65
- self.status = 'Approved'
66
- self.auth_code ||= card_number[-4..-1] if card_number.present?
67
- self.save!
68
- end
69
-
70
- def get_card_type
71
- card = ActiveMerchant::Billing::CreditCard.new(:number => card_number)
72
- card.valid?
73
- card.brand
74
- end
75
- end
76
-
77
- end