artfully_ose 1.2.0 → 1.3.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (577) hide show
  1. checksums.yaml +5 -13
  2. data/app/assets/images/actions/open.png +0 -0
  3. data/app/assets/images/actions/pledge.png +0 -0
  4. data/app/assets/images/actions/pledge.psd +0 -0
  5. data/app/assets/images/glyphish/gray/cancel.png +0 -0
  6. data/app/assets/images/loading_gray.gif +0 -0
  7. data/app/assets/javascripts/application.js +30 -4
  8. data/app/assets/javascripts/baseball_card.js.coffee +235 -0
  9. data/app/assets/javascripts/boxoffice.js +12 -49
  10. data/app/assets/javascripts/contributions.js +264 -0
  11. data/app/assets/javascripts/custom/advanced_searches.js +142 -0
  12. data/app/assets/javascripts/custom/endless-scroll.js +1 -1
  13. data/app/assets/javascripts/custom/job-monitor.js +73 -0
  14. data/app/assets/javascripts/custom/kits-config.js +0 -2
  15. data/app/assets/javascripts/custom/mailchimp.js +14 -0
  16. data/app/assets/javascripts/custom/people.js +31 -2
  17. data/app/assets/javascripts/custom/person-finder.js +34 -0
  18. data/app/assets/javascripts/custom/searches.js +12 -0
  19. data/app/assets/javascripts/custom/user-finder.js +111 -0
  20. data/app/assets/javascripts/households.js +12 -5
  21. data/app/assets/javascripts/ical.js +138 -0
  22. data/app/assets/javascripts/jquery-lib/jquery.timeago.js +221 -0
  23. data/app/assets/javascripts/locationselector.js +1 -1
  24. data/app/assets/javascripts/memberships.js +24 -0
  25. data/app/assets/javascripts/relationships.js +10 -0
  26. data/app/assets/javascripts/search.js +22 -0
  27. data/app/assets/javascripts/store/sliding-wizard.js +2 -2
  28. data/app/assets/javascripts/store/store.js +51 -6
  29. data/app/assets/javascripts/tags.js +44 -0
  30. data/app/assets/stylesheets/application.sass +331 -32
  31. data/app/assets/stylesheets/bootstrap-overrides.css +24 -9
  32. data/app/assets/stylesheets/boxoffice.css.scss +0 -4
  33. data/app/assets/stylesheets/sass/_campaigns.sass +43 -0
  34. data/app/assets/stylesheets/sass/_tags.sass +10 -1
  35. data/app/assets/stylesheets/sass/fa-color.css.scss +13 -0
  36. data/app/assets/stylesheets/sass/store.sass +7 -7
  37. data/app/concerns/cart_finder.rb +10 -0
  38. data/app/concerns/oh_noes.rb +1 -1
  39. data/app/controllers/actions_controller.rb +5 -5
  40. data/app/controllers/addresses_controller.rb +1 -1
  41. data/app/controllers/advanced_search_segments_controller.rb +97 -0
  42. data/app/controllers/advanced_searches_controller.rb +118 -0
  43. data/app/controllers/appeals_controller.rb +63 -0
  44. data/app/controllers/artfully_ose_controller.rb +20 -2
  45. data/app/controllers/campaigns_controller.rb +90 -0
  46. data/app/controllers/charts_controller.rb +8 -2
  47. data/app/controllers/console_sales_controller.rb +21 -23
  48. data/app/controllers/contributions_controller.rb +74 -43
  49. data/app/controllers/converts_controller.rb +21 -0
  50. data/app/controllers/delete_ticket_types_controller.rb +35 -0
  51. data/app/controllers/events_pass_types_controller.rb +10 -2
  52. data/app/controllers/export_controller.rb +4 -4
  53. data/app/controllers/households_controller.rb +63 -15
  54. data/app/controllers/imports_controller.rb +13 -10
  55. data/app/controllers/job_monitors_controller.rb +9 -0
  56. data/app/controllers/members/people_controller.rb +7 -5
  57. data/app/controllers/members/sessions_controller.rb +1 -0
  58. data/app/controllers/membership_comps_controller.rb +5 -20
  59. data/app/controllers/memberships_controller.rb +2 -2
  60. data/app/controllers/merges_controller.rb +7 -6
  61. data/app/controllers/mobile/users_controller.rb +18 -6
  62. data/app/controllers/notes_controller.rb +5 -1
  63. data/app/controllers/orders_controller.rb +30 -13
  64. data/app/controllers/organizations_controller.rb +8 -0
  65. data/app/controllers/passes_kits_controller.rb +2 -4
  66. data/app/controllers/people_controller.rb +105 -17
  67. data/app/controllers/pledges_controller.rb +64 -0
  68. data/app/controllers/preview_rows_controller.rb +29 -0
  69. data/app/controllers/regular_donation_kits_controller.rb +11 -6
  70. data/app/controllers/sales_controller.rb +72 -40
  71. data/app/controllers/searches_controller.rb +37 -6
  72. data/app/controllers/segments_controller.rb +33 -2
  73. data/app/controllers/settlements_controller.rb +13 -7
  74. data/app/controllers/shows_controller.rb +58 -24
  75. data/app/controllers/statements_controller.rb +2 -2
  76. data/app/controllers/store/checkouts_controller.rb +43 -26
  77. data/app/controllers/store/donations_controller.rb +27 -11
  78. data/app/controllers/store/memberships_controller.rb +37 -4
  79. data/app/controllers/store/orders_controller.rb +26 -10
  80. data/app/controllers/store/passes_controller.rb +30 -3
  81. data/app/controllers/tags_controller.rb +42 -0
  82. data/app/controllers/ticket_types_controller.rb +9 -2
  83. data/app/controllers/tickets_controller.rb +6 -4
  84. data/app/controllers/unacknowledged_gifts_controller.rb +45 -0
  85. data/app/controllers/user_memberships_controller.rb +47 -8
  86. data/app/helpers/advanced_searches_helper.rb +252 -0
  87. data/app/helpers/artfully_ose_helper.rb +33 -4
  88. data/app/helpers/checkouts_helper.rb +16 -0
  89. data/app/helpers/mailchimp_lists_for_search_helper.rb +21 -0
  90. data/app/helpers/orders_helper.rb +11 -0
  91. data/app/helpers/people_helper.rb +28 -1
  92. data/app/helpers/relationships_helper.rb +6 -0
  93. data/app/helpers/sales_helper.rb +3 -1
  94. data/app/helpers/searches_helper.rb +3 -1
  95. data/app/helpers/segments_helper.rb +3 -0
  96. data/app/mailers/order_mailer.rb +8 -1
  97. data/app/mailers/producer_mailer.rb +39 -0
  98. data/app/mailers/reports_mailer.rb +6 -1
  99. data/app/models/ability.rb +15 -8
  100. data/app/models/action.rb +33 -4
  101. data/app/models/actions/change_action.rb +3 -1
  102. data/app/models/actions/comp_action.rb +3 -1
  103. data/app/models/actions/convert_action.rb +19 -0
  104. data/app/models/actions/do_action.rb +3 -1
  105. data/app/models/actions/exchange_action.rb +3 -1
  106. data/app/models/actions/get_action.rb +3 -1
  107. data/app/models/actions/give_action.rb +8 -2
  108. data/app/models/actions/go_action.rb +3 -1
  109. data/app/models/actions/hear_action.rb +15 -1
  110. data/app/models/actions/join_action.rb +3 -1
  111. data/app/models/actions/mailchimp_hear_action.rb +17 -0
  112. data/app/models/actions/pledge_action.rb +19 -0
  113. data/app/models/actions/refund_action.rb +3 -1
  114. data/app/models/actions/say_action.rb +3 -1
  115. data/app/models/actions/system_action.rb +17 -0
  116. data/app/models/address.rb +76 -31
  117. data/app/models/advanced_search.rb +434 -0
  118. data/app/models/advanced_search_segment.rb +12 -0
  119. data/app/models/appeal.rb +106 -0
  120. data/app/models/box_office.rb +1 -1
  121. data/app/models/budget_restriction.rb +9 -0
  122. data/app/models/campaign.rb +141 -0
  123. data/app/models/cart.rb +39 -4
  124. data/app/models/chart.rb +2 -2
  125. data/app/models/checkout.rb +54 -10
  126. data/app/models/comp.rb +7 -5
  127. data/app/models/company.rb +2 -0
  128. data/app/models/console_sale.rb +26 -0
  129. data/app/models/contribution.rb +327 -62
  130. data/app/models/convert.rb +62 -0
  131. data/app/models/daily_membership_report.rb +1 -1
  132. data/app/models/database_views/item_view.rb +91 -49
  133. data/app/models/discount.rb +1 -1
  134. data/app/models/discounts/discount_type.rb +2 -1
  135. data/app/models/donation.rb +27 -2
  136. data/app/models/donation_search.rb +188 -10
  137. data/app/models/door_list.rb +39 -2
  138. data/app/models/event.rb +31 -15
  139. data/app/models/ext.rb +3 -3
  140. data/app/models/ext/delayed_indexing.rb +41 -1
  141. data/app/models/ext/integrations.rb +6 -0
  142. data/app/models/forwarding_job_monitor.rb +2 -0
  143. data/app/models/household.rb +1 -1
  144. data/app/models/import.rb +39 -8
  145. data/app/models/imports/donations_import.rb +110 -19
  146. data/app/models/imports/events_import.rb +3 -2
  147. data/app/models/imports/mappings.rb +991 -0
  148. data/app/models/imports/memberships_import.rb +218 -20
  149. data/app/models/imports/people_import.rb +9 -1
  150. data/app/models/imports/rollback.rb +9 -0
  151. data/app/models/imports/validations.rb +7 -0
  152. data/app/models/individual.rb +3 -1
  153. data/app/models/item.rb +55 -17
  154. data/app/models/job/acknowledge_job.rb +23 -0
  155. data/app/models/job/checkout_processor.rb +1 -1
  156. data/app/models/job/convert_order_processor.rb +14 -0
  157. data/app/models/job/daily_email_report_job.rb +1 -12
  158. data/app/models/job/destroy_show_job.rb +1 -6
  159. data/app/models/job/destroy_tag_job.rb +18 -0
  160. data/app/models/job/door_list_generator_job.rb +33 -0
  161. data/app/models/job/door_list_mailer_job.rb +15 -0
  162. data/app/models/job/email_organization_sales_report_job.rb +32 -0
  163. data/app/models/job/expire_ticket_job.rb +19 -2
  164. data/app/models/job/export_people_job.rb +47 -0
  165. data/app/models/job/export_settlements_job.rb +24 -0
  166. data/app/models/job/geocode_address_job.rb +2 -7
  167. data/app/models/job/mailchimp_sync_job.rb +61 -3
  168. data/app/models/job/merge_job.rb +19 -0
  169. data/app/models/job/order_export_job.rb +36 -0
  170. data/app/models/job/order_mailer_job.rb +1 -2
  171. data/app/models/job/order_processor.rb +17 -6
  172. data/app/models/job/person_lifetime_value_job.rb +1 -0
  173. data/app/models/job/search_export_job.rb +33 -0
  174. data/app/models/job/suggest_households_by_address_job.rb +29 -0
  175. data/app/models/job/suggest_households_by_spouse_job.rb +22 -0
  176. data/app/models/job_monitor.rb +14 -0
  177. data/app/models/kit.rb +35 -8
  178. data/app/models/kits/campaigns_kit.rb +27 -0
  179. data/app/models/kits/mailchimp_kit.rb +548 -124
  180. data/app/models/kits/membership_kit.rb +14 -6
  181. data/app/models/kits/passes_kit.rb +14 -6
  182. data/app/models/kits/regular_donation_kit.rb +29 -2
  183. data/app/models/{relationships_kit.rb → kits/relationships_kit.rb} +3 -7
  184. data/app/models/kits/scannable_tickets_kit.rb +0 -5
  185. data/app/models/kits/sponsored_donation_kit.rb +2 -12
  186. data/app/models/kits/ticketing_kit.rb +9 -1
  187. data/app/models/linking_job_monitor.rb +2 -0
  188. data/app/models/list_grouping.rb +10 -0
  189. data/app/models/member.rb +35 -23
  190. data/app/models/member_number_generator.rb +2 -0
  191. data/app/models/membership.rb +23 -14
  192. data/app/models/membership_change.rb +17 -1
  193. data/app/models/membership_comp.rb +48 -23
  194. data/app/models/membership_comp_job.rb +7 -0
  195. data/app/models/membership_type.rb +13 -7
  196. data/app/models/monitorable.rb +19 -0
  197. data/app/models/note.rb +10 -1
  198. data/app/models/order.rb +170 -21
  199. data/app/models/order_handler.rb +13 -2
  200. data/app/models/orders/convert_order.rb +11 -0
  201. data/app/models/organization.rb +87 -9
  202. data/app/models/parsed_row.rb +142 -67
  203. data/app/models/pass.rb +13 -7
  204. data/app/models/pass_type.rb +17 -4
  205. data/app/models/passes_report.rb +6 -3
  206. data/app/models/payment.rb +16 -6
  207. data/app/models/payments/cash_payment.rb +1 -0
  208. data/app/models/payments/check_payment.rb +1 -5
  209. data/app/models/payments/comp_payment.rb +0 -1
  210. data/app/models/payments/credit_card_payment.rb +2 -7
  211. data/app/models/permission.rb +28 -0
  212. data/app/models/person.rb +503 -94
  213. data/app/models/phone.rb +3 -0
  214. data/app/models/redis_manager.rb +39 -0
  215. data/app/models/relationship.rb +31 -4
  216. data/app/models/relationship_builder.rb +0 -3
  217. data/app/models/rolling_membership_type.rb +5 -1
  218. data/app/models/s3_coordinator.rb +21 -0
  219. data/app/models/sale.rb +7 -4
  220. data/app/models/scheduled_pledge_payment.rb +69 -0
  221. data/app/models/search.rb +236 -24
  222. data/app/models/section.rb +6 -4
  223. data/app/models/show.rb +21 -12
  224. data/app/models/show_validator.rb +45 -0
  225. data/app/models/soft_credit.rb +126 -0
  226. data/app/models/subscribed_list.rb +52 -0
  227. data/app/models/suggested_household.rb +8 -2
  228. data/app/models/ticket.rb +35 -10
  229. data/app/models/ticket/locker.rb +25 -0
  230. data/app/models/ticket_summary.rb +1 -1
  231. data/app/models/ticket_type.rb +14 -2
  232. data/app/models/user.rb +42 -3
  233. data/app/models/user_membership.rb +57 -3
  234. data/app/models/valuation/lifetime_donations.rb +2 -2
  235. data/app/models/valuation/lifetime_pledges.rb +35 -0
  236. data/app/models/valuation/lifetime_value.rb +5 -1
  237. data/app/models/valuation_query.rb +109 -0
  238. data/app/models/venue.rb +8 -0
  239. data/app/views/actions/_action.html.haml +1 -1
  240. data/app/views/actions/_form.html.haml +2 -2
  241. data/app/views/actions/give/_show.html.haml +1 -1
  242. data/app/views/actions/pledge/_show.html.haml +8 -0
  243. data/app/views/actions/shared/_show.html.haml +1 -1
  244. data/app/views/addresses/_address.html.haml +3 -1
  245. data/app/views/advanced_search_segments/_advanced_searches_results.html.haml +15 -0
  246. data/app/views/advanced_search_segments/index.html.haml +18 -0
  247. data/app/views/advanced_search_segments/show.html.haml +46 -0
  248. data/app/views/advanced_searches/_form.html.haml +61 -0
  249. data/app/views/advanced_searches/_hit.html.haml +10 -0
  250. data/app/views/advanced_searches/_household.html.haml +7 -0
  251. data/app/views/advanced_searches/_new_condition.html.haml +3 -0
  252. data/app/views/advanced_searches/_people_count.html.erb +3 -0
  253. data/app/views/advanced_searches/_people_list.html.haml +5 -0
  254. data/app/views/advanced_searches/filters/_action.html.haml +12 -0
  255. data/app/views/advanced_searches/filters/_birthday.html.haml +9 -0
  256. data/app/views/advanced_searches/filters/_discount_code.html.haml +7 -0
  257. data/app/views/advanced_searches/filters/_donated.html.haml +17 -0
  258. data/app/views/advanced_searches/filters/_email.html.haml +7 -0
  259. data/app/views/advanced_searches/filters/_has_purchased_for.html.haml +9 -0
  260. data/app/views/advanced_searches/filters/_keyword.html.haml +9 -0
  261. data/app/views/advanced_searches/filters/_lifetime_value.html.haml +13 -0
  262. data/app/views/advanced_searches/filters/_limit_results.html.haml +7 -0
  263. data/app/views/advanced_searches/filters/_location.html.haml +11 -0
  264. data/app/views/advanced_searches/filters/_mailchimp_group.html.haml +8 -0
  265. data/app/views/advanced_searches/filters/_mailchimp_list.html.haml +8 -0
  266. data/app/views/advanced_searches/filters/_membership_ended.html.haml +9 -0
  267. data/app/views/advanced_searches/filters/_membership_started.html.haml +9 -0
  268. data/app/views/advanced_searches/filters/_membership_status.html.haml +8 -0
  269. data/app/views/advanced_searches/filters/_membership_type.html.haml +8 -0
  270. data/app/views/advanced_searches/filters/_orders.html.haml +10 -0
  271. data/app/views/advanced_searches/filters/_pass_type.html.haml +9 -0
  272. data/app/views/advanced_searches/filters/_relationships.html.haml +8 -0
  273. data/app/views/advanced_searches/filters/_segment.html.haml +8 -0
  274. data/app/views/advanced_searches/filters/_tagging.html.haml +9 -0
  275. data/app/views/advanced_searches/new.html.haml +12 -0
  276. data/app/views/advanced_searches/show.html.haml +107 -0
  277. data/app/views/advanced_searches/shows_for_org.html.haml +1 -0
  278. data/app/views/advanced_searches/ticket_types_for_org.html.haml +1 -0
  279. data/app/views/advanced_searches/update.js.erb +9 -0
  280. data/app/views/appeals/_form.html.haml +113 -0
  281. data/app/views/appeals/_header.html.haml +6 -0
  282. data/app/views/appeals/_heard_action.html.haml +16 -0
  283. data/app/views/appeals/edit.html.haml +8 -0
  284. data/app/views/appeals/new.html.haml +6 -0
  285. data/app/views/campaigns/_campaign_donations.html.haml +19 -0
  286. data/app/views/campaigns/_campaign_stats.html.haml +28 -0
  287. data/app/views/campaigns/_form.html.haml +48 -0
  288. data/app/views/campaigns/_header.html.haml +6 -0
  289. data/app/views/campaigns/edit.html.haml +6 -0
  290. data/app/views/campaigns/index.html.haml +33 -0
  291. data/app/views/campaigns/new.html.haml +6 -0
  292. data/app/views/campaigns/show.html.haml +132 -0
  293. data/app/views/console_sales/_cart.html.haml +3 -2
  294. data/app/views/console_sales/_payment.html.haml +14 -1
  295. data/app/views/console_sales/new.html.haml +11 -6
  296. data/app/views/contributions/_form.html.haml +139 -37
  297. data/app/views/contributions/_header.html.haml +5 -0
  298. data/app/views/contributions/_match_eligible.html.haml +24 -0
  299. data/app/views/contributions/_pledge_payment.html.haml +22 -0
  300. data/app/views/contributions/_search.html.haml +30 -0
  301. data/app/views/contributions/_soft_credit.html.haml +25 -0
  302. data/app/views/contributions/edit.html.haml +5 -8
  303. data/app/views/contributions/find_person.html.haml +16 -15
  304. data/app/views/contributions/index.html.haml +61 -24
  305. data/app/views/contributions/new.html.haml +5 -5
  306. data/app/views/converts/_grouped_form.html.haml +11 -0
  307. data/app/views/converts/new.html.haml +35 -0
  308. data/app/views/delete_ticket_types/_cannot_destroy_modal.html.haml +11 -0
  309. data/app/views/delete_ticket_types/_cannot_destroy_modal.rb +0 -0
  310. data/app/views/delete_ticket_types/_confirm_destroy_modal.html.haml +13 -0
  311. data/app/views/delete_ticket_types/show.html.haml +4 -0
  312. data/app/views/discounts/_form.html.haml +1 -1
  313. data/app/views/events/_day_date_show.html.haml +4 -2
  314. data/app/views/events/_glance.html.haml +12 -12
  315. data/app/views/events/_header.html.haml +1 -1
  316. data/app/views/events/_list.html.haml +1 -1
  317. data/app/views/events/_menu.html.haml +26 -21
  318. data/app/views/events/_section_fields.html.haml +1 -1
  319. data/app/views/events/_tax_deductible_message.html.haml +3 -0
  320. data/app/views/events/_ticket_type_fields.html.haml +13 -3
  321. data/app/views/events/index.html.haml +2 -1
  322. data/app/views/events/messages.html.haml +12 -10
  323. data/app/views/events/show.html.haml +6 -6
  324. data/app/views/events/temp_discount_form.html.haml +1 -1
  325. data/app/views/events_pass_types/_form.html.haml +1 -1
  326. data/app/views/events_pass_types/new.html.haml +1 -2
  327. data/app/views/households/_edit_modal.html.haml +9 -4
  328. data/app/views/households/_form.html.haml +6 -1
  329. data/app/views/households/_header.html.haml +9 -18
  330. data/app/views/households/confirm.html.haml +43 -0
  331. data/app/views/households/new.html.haml +3 -1
  332. data/app/views/households/show.html.haml +2 -1
  333. data/app/views/households/suggested.html.haml +10 -27
  334. data/app/views/imports/_export_links.html.haml +2 -2
  335. data/app/views/imports/donations/_new.html.haml +49 -6
  336. data/app/views/imports/donations/_pending.html.haml +69 -22
  337. data/app/views/imports/donations/_preview.html.haml +23 -0
  338. data/app/views/imports/events/_new.html.haml +8 -8
  339. data/app/views/imports/index.html.haml +26 -21
  340. data/app/views/imports/memberships/_approved.html.haml +16 -0
  341. data/app/views/imports/memberships/_caching.html.haml +17 -0
  342. data/app/views/imports/memberships/_failed.html.haml +5 -0
  343. data/app/views/imports/memberships/_imported.html.haml +45 -0
  344. data/app/views/imports/memberships/_importing.html.haml +20 -0
  345. data/app/views/imports/memberships/_invalid.html.haml +5 -0
  346. data/app/views/imports/memberships/_new.html.haml +155 -0
  347. data/app/views/imports/memberships/_pending.html.haml +85 -0
  348. data/app/views/imports/memberships/_preview_rows.html.haml +38 -0
  349. data/app/views/imports/people/_new.html.haml +81 -15
  350. data/app/views/imports/shared/_inspect_modal.html.haml +10 -1
  351. data/app/views/imports/shared/_new_sidebar.html.haml +12 -0
  352. data/app/views/imports/show.html.haml +0 -3
  353. data/app/views/index/_action.html.haml +4 -3
  354. data/app/views/index/_recent_activity.html.haml +14 -7
  355. data/app/views/index/dashboard.html.haml +27 -14
  356. data/app/views/job_monitors/_job_monitor_show.html.haml +34 -0
  357. data/app/views/job_monitors/_linking_job_monitor_show.html.haml +31 -0
  358. data/app/views/job_monitors/show.html.haml +1 -0
  359. data/app/views/layouts/_google_analytics.html.haml +9 -11
  360. data/app/views/layouts/_menu.html.haml +5 -3
  361. data/app/views/layouts/application.html.haml +12 -4
  362. data/app/views/layouts/devise_layout.html.haml +1 -1
  363. data/app/views/layouts/storefront.html.haml +7 -10
  364. data/app/views/members/index/index.html.haml +82 -4
  365. data/app/views/members/mailer/_invitation_body.html.haml +2 -2
  366. data/app/views/members/passwords/new.html.haml +13 -0
  367. data/app/views/members/sessions/new.html.haml +1 -1
  368. data/app/views/membership_comps/confirm.html.haml +10 -8
  369. data/app/views/membership_comps/create.html.haml +1 -3
  370. data/app/views/membership_kits/edit.html.haml +6 -0
  371. data/app/views/membership_types/_form.html.haml +1 -1
  372. data/app/views/membership_types/index.html.haml +11 -3
  373. data/app/views/memberships/index.html.haml +122 -109
  374. data/app/views/merges/find_person.html.haml +5 -3
  375. data/app/views/merges/new.html.haml +13 -4
  376. data/app/views/notes/_note.html.haml +3 -3
  377. data/app/views/order_mailer/confirmation_for.html.haml +1 -0
  378. data/app/views/order_mailer/confirmation_for.text.haml +1 -0
  379. data/app/views/orders/_assignable_donations.html.haml +25 -0
  380. data/app/views/orders/_assignable_pledges.html.haml +26 -0
  381. data/app/views/orders/_item_table.haml +20 -8
  382. data/app/views/orders/_order_sidebar.html.haml +37 -7
  383. data/app/views/orders/membership.html.haml +2 -2
  384. data/app/views/orders/passes.html.haml +4 -4
  385. data/app/views/orders/sales.html.haml +5 -5
  386. data/app/views/orders/show.html.haml +26 -7
  387. data/app/views/organizations/_form.html.haml +0 -5
  388. data/app/views/pass_types/index.html.haml +13 -5
  389. data/app/views/passes/index.html.haml +50 -39
  390. data/app/views/passes_kits/edit.html.haml +6 -0
  391. data/app/views/passes_reports/index.html.haml +1 -1
  392. data/app/views/pdfs/member.html.haml +1 -1
  393. data/app/views/pdfs/member_card_generator/blanks_usa_idc6.html.haml +1 -1
  394. data/app/views/pdfs/order.html.haml +5 -3
  395. data/app/views/people/_address_fields.html.haml +40 -0
  396. data/app/views/people/_convert_to_company_modal.html.haml +3 -0
  397. data/app/views/people/_edit_modal.html.haml +121 -38
  398. data/app/views/people/_form.html.haml +8 -14
  399. data/app/views/people/_header.html.haml +11 -16
  400. data/app/views/people/_list.html.haml +3 -9
  401. data/app/views/people/_mailchimp_group.html.haml +3 -0
  402. data/app/views/people/_phone_fields.html.haml +1 -1
  403. data/app/views/people/_relationship_fields.html.haml +10 -5
  404. data/app/views/people/_work_with_menu.html.haml +14 -8
  405. data/app/views/people/index.html.haml +10 -9
  406. data/app/views/people/new.html.haml +18 -4
  407. data/app/views/people/pledges.html.haml +13 -0
  408. data/app/views/people/show.html.haml +96 -45
  409. data/app/views/pledges/_none_scheduled_payment_table.html.haml +17 -0
  410. data/app/views/pledges/_receive_pledge.html.haml +87 -0
  411. data/app/views/pledges/_scheduled_payments_table.html.haml +18 -0
  412. data/app/views/pledges/index.html.haml +47 -0
  413. data/app/views/preview_rows/index.html.haml +1 -0
  414. data/app/views/producer_mailer/donation_notification.html.haml +9 -0
  415. data/app/views/producer_mailer/donation_notification.text.erb +8 -0
  416. data/app/views/producer_mailer/door_list_notification.html.haml +10 -0
  417. data/app/views/producer_mailer/door_list_notification.text.erb +6 -0
  418. data/app/views/producer_mailer/mailchimp_kit_initial_sync_notification.html.haml +2 -2
  419. data/app/views/regular_donation_kits/edit.html.haml +29 -1
  420. data/app/views/relationships/index.html.haml +1 -1
  421. data/app/views/sales/_boxoffice.html.haml +15 -5
  422. data/app/views/sales/_doorlist.html.haml +2 -2
  423. data/app/views/sales/new.html.haml +2 -2
  424. data/app/views/searches/_company.html.haml +7 -0
  425. data/app/views/searches/_form.html.haml +75 -8
  426. data/app/views/searches/_household.html.haml +2 -2
  427. data/app/views/searches/_individual.html.haml +7 -0
  428. data/app/views/searches/show.html.haml +59 -23
  429. data/app/views/segments/index.html.haml +1 -1
  430. data/app/views/segments/show.html.haml +36 -1
  431. data/app/views/shared/_baseball_card.html.haml +40 -0
  432. data/app/views/shared/_tags.html.haml +10 -8
  433. data/app/views/shows/_empty_ticket_table.html.haml +12 -0
  434. data/app/views/shows/_sections_table.html.haml +78 -69
  435. data/app/views/shows/_ticket_table.html.haml +10 -7
  436. data/app/views/shows/index.html.haml +95 -85
  437. data/app/views/statements/_shows.html.haml +1 -1
  438. data/app/views/store/checkouts/_event_information.html.haml +89 -0
  439. data/app/views/store/checkouts/_shopping_cart_display.haml +8 -0
  440. data/app/views/store/checkouts/_thanks.html.haml +40 -0
  441. data/app/views/store/checkouts/create.html.haml +1 -0
  442. data/app/views/store/checkouts/shopping_cart_display/_discounts.haml +8 -0
  443. data/app/views/store/checkouts/shopping_cart_display/_donations.haml +15 -0
  444. data/app/views/store/checkouts/{_membership_info.html.haml → shopping_cart_display/_membership_info.html.haml} +0 -0
  445. data/app/views/store/checkouts/shopping_cart_display/_memberships.haml +8 -0
  446. data/app/views/store/checkouts/shopping_cart_display/_passes.haml +9 -0
  447. data/app/views/store/checkouts/shopping_cart_display/_tickets.haml +10 -0
  448. data/app/views/store/checkouts/shopping_cart_display/_total.haml +10 -0
  449. data/app/views/store/donations/index.html.haml +4 -0
  450. data/app/views/store/events/_contact_info.html.haml +8 -0
  451. data/app/views/store/events/_venue.html.haml +14 -7
  452. data/app/views/store/events/calendar.html.haml +2 -9
  453. data/app/views/store/events/show.html.haml +2 -9
  454. data/app/views/store/events/single_show.html.haml +3 -3
  455. data/app/views/store/memberships/index.html.haml +3 -3
  456. data/app/views/store/orders/blank.html.erb +34 -0
  457. data/app/views/store/orders/show.html.haml +15 -6
  458. data/app/views/store/passes/index.html.haml +3 -3
  459. data/app/views/store/shared/_small_donate_form.html.haml +21 -18
  460. data/app/views/tags/_edit_modal.html.haml +16 -0
  461. data/app/views/tags/index.html.haml +23 -0
  462. data/app/views/unacknowledged_gifts/_heard_action.html.haml +10 -0
  463. data/app/views/unacknowledged_gifts/index.html.haml +76 -0
  464. data/app/views/user_memberships/_list.html.haml +147 -24
  465. data/config/initializers/delayed_job_config.rb +10 -1
  466. data/config/routes.rb +85 -9
  467. data/db/migrate/20140422193345_add_email_copy_to_pass_type.rb +1 -1
  468. data/db/migrate/20140616045851_add_birthdate_to_search.rb +7 -0
  469. data/db/migrate/20140623131025_create_campaigns.rb +27 -0
  470. data/db/migrate/20140627120214_create_appeals.rb +28 -0
  471. data/db/migrate/20140630151406_add_deleted_at_to_campaigns.rb +9 -0
  472. data/db/migrate/20140701124100_add_segment_id_and_notes_to_appeals.rb +12 -0
  473. data/db/migrate/20140702115815_add_campaign_id_and_appeal_id_to_donations.rb +14 -0
  474. data/db/migrate/20140702121928_add_materials_to_appeals.rb +11 -0
  475. data/db/migrate/20140702150521_add_deleted_at_to_appeals.rb +9 -0
  476. data/db/migrate/20140709151816_add_campaign_id_and_appeal_id_to_orders.rb +14 -0
  477. data/db/migrate/20140723133850_remove_campaign_id_and_apeal_id_from_orders.rb +11 -0
  478. data/db/migrate/20140723134923_add_commitment_date_to_donations.rb +6 -0
  479. data/db/migrate/20140730141515_add_match_eligible_to_donations.rb +15 -0
  480. data/db/migrate/20140818141140_create_soft_credits.rb +12 -0
  481. data/db/migrate/20140903140113_add_pledge_to_donations.rb +9 -0
  482. data/db/migrate/20140904183953_add_destroyed_at_to_relationships.rb +7 -0
  483. data/db/migrate/20140905080503_create_scheduled_pledge_payments.rb +16 -0
  484. data/db/migrate/20140909150251_add_org_to_suggested_household.rb +7 -0
  485. data/db/migrate/20141007114614_add_order_id_to_donations.rb +15 -0
  486. data/db/migrate/20141021134013_add_lifetime_pledges_to_people.rb +5 -0
  487. data/db/migrate/20141027191307_default_overwrite_member_addresses_to_false.rb +5 -0
  488. data/db/migrate/20141031193839_update_relations.rb +9 -0
  489. data/db/migrate/20141126183258_add_mailchimp_status_fields_to_people.rb +6 -0
  490. data/db/migrate/20141126184811_add_processing_at_to_ticket.rb +5 -0
  491. data/db/migrate/20141127135743_add_import_to_campaigns.rb +6 -0
  492. data/db/migrate/20141128143944_add_fiscal_year_to_donations.rb +5 -0
  493. data/db/migrate/20141128151407_remove_fiscal_year_from_scheduled_pledge_payments.rb +3 -0
  494. data/db/migrate/20141204164400_add_more_indexes_to_actions.rb +7 -0
  495. data/db/migrate/20141204171612_add_indexes_to_charts.rb +12 -0
  496. data/db/migrate/20141204172658_add_hide_on_recent_activity_to_actions.rb +5 -0
  497. data/db/migrate/20141204173004_add_indexes_to_ept.rb +9 -0
  498. data/db/migrate/20141204211933_remove_membership_counts_from_members.rb +13 -0
  499. data/db/migrate/20141205202030_create_subscribed_lists.rb +19 -0
  500. data/db/migrate/20141208225228_add_mailchimp_lists_to_searches.rb +5 -0
  501. data/db/migrate/20141210162329_add_bounced_to_subscribed_lists.rb +5 -0
  502. data/db/migrate/20141211165307_add_external_reference_to_actions.rb +5 -0
  503. data/db/migrate/20141212172119_add_not_mailchimp_lists_to_searches.rb +5 -0
  504. data/db/migrate/20141229204605_normalize_states_in_addresses.rb +11 -0
  505. data/db/migrate/20150113091344_add_fiscal_to_organizations.rb +11 -0
  506. data/db/migrate/20150113091434_create_budget_restrictions.rb +14 -0
  507. data/db/migrate/20150113091503_add_budget_restriction_to_campaigns.rb +14 -0
  508. data/db/migrate/20150129091354_add_campaign_to_searches.rb +13 -0
  509. data/db/migrate/20150203174456_create_list_groupings.rb +12 -0
  510. data/db/migrate/20150203222451_add_groupings_to_searches.rb +6 -0
  511. data/db/migrate/20150219153827_add_roles_to_user_memberships.rb +13 -0
  512. data/db/migrate/20150223145657_add_daily_sales_to_user_membership.rb +13 -0
  513. data/db/migrate/20150318171857_create_advanced_searches.rb +16 -0
  514. data/db/migrate/20150319185940_add_org_id_index_to_orders.rb +5 -0
  515. data/db/migrate/20150325085516_add_received_amount_to_donations.rb +16 -0
  516. data/db/migrate/20150325173053_add_pass_index_to_tickets.rb +5 -0
  517. data/db/migrate/20150331084817_add_creator_id_to_orders.rb +11 -0
  518. data/db/migrate/20150406162656_index_tickets_on_action_id.rb +5 -0
  519. data/db/migrate/20150408123349_add_donor_instructions_to_orders.rb +9 -0
  520. data/db/migrate/20150408125600_add_index_to_imports.rb +5 -0
  521. data/db/migrate/20150414193419_add_index_to_phone.rb +5 -0
  522. data/db/migrate/20150414193646_add_index_to_taggings.rb +5 -0
  523. data/db/migrate/20150415113013_add_nickname_to_people.rb +11 -0
  524. data/db/migrate/20150420143707_add_indexes_to_donations.rb +7 -0
  525. data/db/migrate/20150421092302_add_kind_to_addresses.rb +11 -0
  526. data/db/migrate/20150513154513_add_name_to_advanced_search.rb +5 -0
  527. data/db/migrate/20150518131946_add_receive_donation_notification_to_user_memberships.rb +9 -0
  528. data/db/migrate/20150520182350_remove_name_from_advanced_search.rb +9 -0
  529. data/db/migrate/20150520202900_create_advanced_search_segments.rb +9 -0
  530. data/db/migrate/20150520210658_add_advanced_search_id_to_advanced_search_segment.rb +5 -0
  531. data/db/migrate/20150521183507_add_organization_id_to_advanced_search_segment.rb +5 -0
  532. data/db/migrate/20150602204548_add_index_on_deleted_at.rb +5 -0
  533. data/db/migrate/20150711143014_add_receive_door_list_to_user_memberships.rb +10 -0
  534. data/db/migrate/20150716000301_create_job_monitors_table.rb +12 -0
  535. data/db/migrate/20150807005404_re_refresh_show_stats.rb +8 -0
  536. data/db/migrate/20150810133417_convert_business_to_work.rb +5 -0
  537. data/db/migrate/20150812135205_update_notes_nulls.rb +9 -0
  538. data/db/migrate/20150813202745_index_household_id.rb +6 -0
  539. data/db/migrate/20150814075653_add_maiden_name_to_people.rb +9 -0
  540. data/db/migrate/20150911203530_normalize_countries_in_addresses.rb +11 -0
  541. data/db/migrate/20150922155253_add_advanced_search_segment_id_to_membership_types.rb +5 -0
  542. data/db/migrate/20150922155308_add_advanced_search_segment_id_to_pass_types.rb +5 -0
  543. data/db/migrate/20151006180702_add_deleted_at_to_ticket_types.rb +5 -0
  544. data/db/migrate/20151009175206_add_receipt_details_to_ticket_types.rb +5 -0
  545. data/db/migrate/20151112174723_index_list_groupings.rb +5 -0
  546. data/lib/artfully_ose/common_abilities.rb +80 -57
  547. data/lib/artfully_ose/version.rb +1 -1
  548. data/lib/tasks/artfully_ose.rake +46 -4
  549. data/spec/factories/action_factories.rb +2 -0
  550. data/spec/factories/address_factories.rb +2 -2
  551. data/spec/factories/advanced_search_factories.rb +45 -0
  552. data/spec/factories/advanced_search_segment_factories.rb +6 -0
  553. data/spec/factories/advanced_segment_factories.rb +6 -0
  554. data/spec/factories/campaign_factories.rb +20 -0
  555. data/spec/factories/cart_factories.rb +24 -0
  556. data/spec/factories/chart_factories.rb +4 -0
  557. data/spec/factories/event_factories.rb +6 -0
  558. data/spec/factories/item_factories.rb +23 -1
  559. data/spec/factories/kit_factories.rb +27 -3
  560. data/spec/factories/member_factories.rb +8 -1
  561. data/spec/factories/membership_factories.rb +12 -0
  562. data/spec/factories/membership_type_factories.rb +18 -0
  563. data/spec/factories/note_factories.rb +7 -0
  564. data/spec/factories/order_factories.rb +7 -0
  565. data/spec/factories/pass_factories.rb +6 -0
  566. data/spec/factories/payments_factories.rb +1 -1
  567. data/spec/factories/person_factories.rb +46 -4
  568. data/spec/factories/scheduled_pledge_payment_factories.rb +10 -0
  569. data/spec/factories/show_factories.rb +8 -3
  570. data/spec/factories/soft_credit_factories.rb +8 -0
  571. data/spec/factories/ticket_factories.rb +22 -9
  572. data/spec/factories/user_factories.rb +16 -8
  573. metadata +342 -59
  574. data/app/controllers/comps_controller.rb +0 -47
  575. data/app/models/household_suggester.rb +0 -58
  576. data/app/views/searches/_person.html.haml +0 -10
  577. data/app/views/store/checkouts/thanks.html.haml +0 -134
@@ -1,13 +1,15 @@
1
1
  class Pass < ActiveRecord::Base
2
2
  include Extendable
3
-
3
+
4
4
  belongs_to :pass_type
5
5
  belongs_to :person
6
6
  belongs_to :organization
7
7
  has_many :tickets
8
8
 
9
9
  before_save :adjust_ends_at
10
-
10
+ after_save { person.solr_index! if person }
11
+ after_destroy { person.solr_index! if person }
12
+
11
13
  EXPIRED_ERROR = "Sorry! This pass has expired."
12
14
  OUT_OF_TICKETS = "Sorry! There are no tickets remaning on this pass."
13
15
  OVER_EVENT_LIMIT = "Sorry! This pass has already been redeemed for this event."
@@ -31,7 +33,7 @@ class Pass < ActiveRecord::Base
31
33
  pass.starts_at = pass_type.starts_at
32
34
  pass.ends_at = pass_type.ends_at
33
35
  end
34
- end
36
+ end
35
37
 
36
38
  def adjust_ends_at
37
39
  self.ends_at = self.ends_at.end_of_day unless self.ends_at.blank?
@@ -66,7 +68,7 @@ class Pass < ActiveRecord::Base
66
68
 
67
69
  def expired?
68
70
  ends_at < Time.now
69
- end
71
+ end
70
72
 
71
73
  def refundable?
72
74
  true
@@ -80,6 +82,10 @@ class Pass < ActiveRecord::Base
80
82
  false
81
83
  end
82
84
 
85
+ def convertable?
86
+ false
87
+ end
88
+
83
89
  def self.new_pass_code(size=8)
84
90
  # Avoid confusable characters like 1/L/I and 0/O
85
91
  charset = %w{ 2 3 4 6 7 9 A C D E F G H J K M N P Q R T V W X Y Z}
@@ -163,11 +169,11 @@ class Pass < ActiveRecord::Base
163
169
  Rails.logger.debug ("PASSES Now only [#{tickets_remaining_on_pass}] tickets remaining on this pass")
164
170
  else
165
171
  Rails.logger.debug ("PASSES rejecting ticket [#{ticket.id}]")
166
- tickets_rejected << tickets
172
+ tickets_rejected << tickets
167
173
  end
168
174
  end
169
175
 
170
- if tickets_rejected.length > 0
176
+ if tickets_rejected.length > 0
171
177
  str = ""
172
178
  if tickets_applied.length == 0
173
179
  str += "There are no tickets"
@@ -194,4 +200,4 @@ class Pass < ActiveRecord::Base
194
200
 
195
201
 
196
202
  end
197
- end
203
+ end
@@ -2,11 +2,16 @@ class PassType < ActiveRecord::Base
2
2
  include Ext::Integrations::ServiceFee
3
3
  include OhNoes::Destroy
4
4
  extend ::ArtfullyOseHelper
5
-
5
+
6
6
  belongs_to :organization
7
+ belongs_to :advanced_search_segment
7
8
  has_many :passes
8
9
 
9
- attr_accessible :name, :description, :hide_fee, :thanks_copy, :email_copy, :sales_start_at, :sales_end_at,
10
+ after_save { organization.people.each {|p| p.solr_index! } if organization && organization.people }
11
+ after_destroy { organization.people.each {|p| p.solr_index! } if organization && organization.people }
12
+ after_create :create_list_segment
13
+
14
+ attr_accessible :name, :description, :hide_fee, :thanks_copy, :email_copy, :sales_start_at, :sales_end_at,
10
15
  :on_sale, :price, :tickets_allowed, :starts_at, :ends_at
11
16
 
12
17
  validates :name, :description, :price, :tickets_allowed, :starts_at, :ends_at, :presence => true
@@ -31,7 +36,7 @@ class PassType < ActiveRecord::Base
31
36
  sales_start_at
32
37
  sales_end_at
33
38
  end
34
-
39
+
35
40
  def sold
36
41
  self.passes.select{ |p| p.person_id.present? }
37
42
  end
@@ -43,4 +48,12 @@ class PassType < ActiveRecord::Base
43
48
  def destroyable?
44
49
  self.passes.empty?
45
50
  end
46
- end
51
+
52
+ def create_list_segment
53
+ search = AdvancedSearch.for_pass(self)
54
+ segment = AdvancedSearchSegment.create(:advanced_search_id => search.id, :organization_id => self.organization.id, :name => self.name)
55
+ self.advanced_search_segment = segment
56
+ self.save!
57
+ end
58
+
59
+ end
@@ -1,5 +1,5 @@
1
1
  class PassesReport
2
- attr_accessor :pass_type, :header, :start_date, :end_date, :rows, :counts
2
+ attr_accessor :pass_type, :header, :start_date, :end_date, :rows, :counts, :organization
3
3
  attr_accessor :tickets_sold, :passes_sold, :total_tickets, :tickets_remaining, :original_price, :discounted
4
4
  extend ::ArtfullyOseHelper
5
5
 
@@ -11,6 +11,7 @@ class PassesReport
11
11
  self.pass_type = pass_type
12
12
  self.start_date = start_date
13
13
  self.end_date = end_date
14
+ self.organization = organization
14
15
 
15
16
  @orders = find_orders
16
17
 
@@ -30,7 +31,7 @@ class PassesReport
30
31
  end
31
32
 
32
33
  def calculate_total_tickets
33
- @passes = Pass.owned
34
+ @passes = Pass.where(:organization_id => self.organization).owned
34
35
  if self.pass_type.present?
35
36
  @passes = @passes.where(:pass_type_id => self.pass_type.id)
36
37
  end
@@ -48,13 +49,15 @@ class PassesReport
48
49
  end
49
50
 
50
51
  @items = @items.joins(:order)
52
+ @items = @items.where('orders.organization_id = ?', self.organization.id)
51
53
  @items = @items.where('orders.created_at > ?',self.start_date) unless start_date.blank?
52
54
  @items = @items.where('orders.created_at < ?',self.end_date) unless end_date.blank?
53
55
  @items.count
54
56
  end
55
57
 
56
58
  def find_orders
57
- @orders = Order.includes(:person, :items => [:show => :event])
59
+ @orders = Order.where(:organization_id => self.organization)
60
+ .includes(:person, :items => [:show => :event])
58
61
  .joins(:items)
59
62
  .joins("INNER join passes ON items.pass_id = passes.id")
60
63
  .joins("INNER join pass_types ON passes.pass_type_id = pass_types.id")
@@ -6,6 +6,7 @@ class Payment
6
6
  include ActiveModel::Validations
7
7
 
8
8
  attr_accessor :amount, :user_agreement, :transaction_id
9
+ attr_accessor :benefactor
9
10
 
10
11
  #This is named customer as it analogizes the "customer" record on a remote payment
11
12
  # system (Braintree, for instance). It is just a Person object.
@@ -58,8 +59,21 @@ class Payment
58
59
  self.customer.first_name = params.fetch(:customer, {}).fetch(:first_name, "")
59
60
  self.customer.last_name = params.fetch(:customer, {}).fetch(:last_name, "")
60
61
  self.customer.email = params.fetch(:customer, {}).fetch(:email, "")
61
-
62
- self.customer.phones << Phone.new(:number => params.fetch(:customer, {}).fetch(:phone, "")) unless params[:customer].blank? || params[:customer][:phone].blank?
62
+
63
+ #
64
+ # Storefront and sales console use a different hash to get the phone number
65
+ #
66
+ if params[:customer].present? && params[:customer][:phone].present? # storefront
67
+ self.customer.phones << Phone.new(:number => params.fetch(:customer, {}).fetch(:phone, ""))
68
+ elsif params[:customer].present? && params[:customer][:phones_attributes].present? # sales console
69
+ self.customer.phones << Phone.new(:number => params.fetch(:customer, {}).fetch(:phones_attributes,[]).first.fetch(:number,''))
70
+ elsif params[:person].present? && params[:person][:phones_attributes].first[:number].present? # box office
71
+ self.customer.phones << Phone.new(:number => params.fetch(:person, {}).fetch(:phones_attributes,[]).first.fetch(:number,''))
72
+ end
73
+ end
74
+
75
+ def payment_phone_number
76
+ self.customer.phones.first.try(:number)
63
77
  end
64
78
 
65
79
  def build_address_from(params)
@@ -107,10 +121,6 @@ class Payment
107
121
  false
108
122
  end
109
123
 
110
- def payment_phone_number
111
- nil
112
- end
113
-
114
124
  def reduce_amount_by(amount_in_cents)
115
125
  self.amount= self.amount - amount_in_cents
116
126
  end
@@ -4,6 +4,7 @@ class CashPayment < Payment
4
4
 
5
5
  def initialize(params = {})
6
6
  self.customer ||= Person.new
7
+ self.benefactor = params[:benefactor]
7
8
  build_customer_from(params)
8
9
  build_address_from(params)
9
10
  end
@@ -6,6 +6,7 @@ class CheckPayment < ::Payment
6
6
  @amount = params[:amount]
7
7
  @check_number = params[:check].try(:[], :number)
8
8
  self.customer ||= Person.new
9
+ self.benefactor = params[:benefactor]
9
10
  build_customer_from(params)
10
11
  build_address_from(params)
11
12
  end
@@ -14,11 +15,6 @@ class CheckPayment < ::Payment
14
15
  false
15
16
  end
16
17
 
17
- def refund
18
- self.errors.add(:base, "Check orders cannot be refunded. Please return the tickets to inventory instead.")
19
- false
20
- end
21
-
22
18
  def requires_settlement?
23
19
  false
24
20
  end
@@ -2,7 +2,6 @@
2
2
  # Comping from producer screens doesn't use this class
3
3
  class CompPayment < Payment
4
4
  payment_method :comp
5
- attr_accessor :benefactor
6
5
 
7
6
  #benefactor is the user that is doing the comping (current_user)
8
7
  #person is the person record receiving the comp. It must have the id set
@@ -13,13 +13,9 @@ class CreditCardPayment < ::Payment
13
13
  def per_item_processing_charge
14
14
  lambda { |item| item.realized_price * 0.035 }
15
15
  end
16
-
17
- def payment_phone_number
18
- self.customer.phones.first.try(:number)
19
- end
20
16
 
21
17
  def build(params)
22
- [:amount, :user_agreement, :transaction_id].each do |field|
18
+ [:amount, :user_agreement, :transaction_id, :benefactor].each do |field|
23
19
  self.instance_variable_set("@#{field.to_s}", params[field])
24
20
  end
25
21
 
@@ -143,8 +139,7 @@ class CreditCardPayment < ::Payment
143
139
  attrs[:response] = response
144
140
  @gateway_transaction = GatewayTransaction.create(attrs)
145
141
  rescue Exception => e
146
- ::Exceptional.context(:gateway_transaction => @gateway_transaction)
147
- ::Exceptional.handle(e, "Failed to persist Gateway Transaction")
142
+ Airbrake.notify(e, :parameters => {:error_message => "Failed to persist Gateway Transaction"})
148
143
  end
149
144
  end
150
145
  end
@@ -0,0 +1,28 @@
1
+ class Permission
2
+ ORGANIZATION_ADMINISTRATOR = "Organization Administrator"
3
+ MANAGER = "Manager"
4
+ GENERAL_ASSOCIATE = "General Associate"
5
+ BOX_OFFICE_ASSOCIATE = "Box Office Associate"
6
+
7
+ def self.available_permissions
8
+ [ORGANIZATION_ADMINISTRATOR, MANAGER, GENERAL_ASSOCIATE, BOX_OFFICE_ASSOCIATE]
9
+ end
10
+
11
+ def self.available_permissions_for(organization)
12
+ organization.admin_limit_reached? ? Permission.available_permissions - [Permission::ORGANIZATION_ADMINISTRATOR] : self.available_permissions
13
+ end
14
+
15
+ def self.for(str)
16
+ return ORGANIZATION_ADMINISTRATOR if str == "Organization Administrator"
17
+ return MANAGER if str == "Manager"
18
+ return GENERAL_ASSOCIATE if str == "General Associate"
19
+ return BOX_OFFICE_ASSOCIATE if str == "Box Office Associate"
20
+ end
21
+
22
+ def self.database_column_for(permission)
23
+ return "organization_administrator" if (permission == ORGANIZATION_ADMINISTRATOR || permission == "organization_administrator")
24
+ return "manager" if (permission == MANAGER || permission == "manager")
25
+ return "general_associate" if (permission == GENERAL_ASSOCIATE || permission == "general_associate")
26
+ return "box_office_associate" if (permission == BOX_OFFICE_ASSOCIATE || permission == "box_office_associate")
27
+ end
28
+ end
@@ -4,18 +4,23 @@ class Person < ActiveRecord::Base
4
4
  include Valuation::LifetimeValue
5
5
  include Valuation::LifetimeTicketValue
6
6
  include Valuation::LifetimeDonations
7
+ include Valuation::LifetimePledges
7
8
  include Valuation::LifetimeMemberships
8
9
 
10
+ COMPANY_TYPE = [['Business'], ['Foundation'], ['Government'], ['Nonprofit'], ['Other']]
11
+
9
12
  handle_asynchronously :calculate_lifetime_memberships
10
13
  handle_asynchronously :calculate_lifetime_donations
14
+ handle_asynchronously :calculate_lifetime_pledges
11
15
  handle_asynchronously :calculate_lifetime_ticket_value
12
16
  handle_asynchronously :calculate_lifetime_value
13
17
 
14
18
  attr_accessor :skip_sync_to_mailchimp, :skip_commit
15
19
  attr_accessible :type, :email, :salutation, :dummy, :title, :company_name,
16
20
  :website, :twitter_handle, :linked_in_url, :facebook_url, :subtype,
17
- :first_name, :middle_name, :last_name, :suffix, :birth_day, :birth_month, :birth_year
18
- attr_accessible :address_attributes, :phones_attributes, :relationships_attributes
21
+ :first_name, :middle_name, :last_name, :suffix, :birth_day, :birth_month, :birth_year,
22
+ :nickname, :listing_name, :maiden_name
23
+ attr_accessible :addresses_attributes, :phones_attributes, :relationships_attributes
19
24
 
20
25
  attr_accessible :subscribed_lists, :do_not_email, :do_not_call, :skip_sync_to_mailchimp
21
26
  attr_accessible :organization_id
@@ -30,12 +35,31 @@ class Person < ActiveRecord::Base
30
35
  has_many :notes
31
36
  has_many :orders
32
37
  has_many :tickets, :foreign_key => 'buyer_id'
33
- has_one :address, :validate => false
38
+ has_many :addresses, :order => 'is_primary DESC'
39
+ has_many :soft_credits
40
+ has_many :scheduled_pledge_payments
34
41
  has_one :member
35
42
  has_many :memberships, :through => :member
36
43
  has_many :passes
37
44
 
38
- has_many :relationships, :foreign_key => :person_id, :class_name => 'Relationship'
45
+ has_many :relationships, :foreign_key => :person_id, :class_name => 'Relationship', :dependent => :destroy
46
+
47
+ has_many :subscribed_lists
48
+ def address
49
+ if self.new_record?
50
+ (addresses.select { |address| address.is_primary}).try(:first)
51
+ else
52
+ addresses.where(:is_primary => true).try(:first)
53
+ end
54
+ end
55
+
56
+ def address=(value)
57
+ addresses << value unless value.nil?
58
+ end
59
+
60
+ def primary_address
61
+ addresses.select{ |a| a.is_primary? }.try(:first)
62
+ end
39
63
 
40
64
  def self.individuals
41
65
  where(:type => 'Individual')
@@ -63,15 +87,21 @@ class Person < ActiveRecord::Base
63
87
  end
64
88
 
65
89
  accepts_nested_attributes_for :relationships, :allow_destroy => true
66
- accepts_nested_attributes_for :address, :allow_destroy => false
90
+ accepts_nested_attributes_for :addresses, :reject_if => :reject_address?, :allow_destroy => true
67
91
  accepts_nested_attributes_for :phones, :reject_if => lambda { |p| p[:number].blank? }, :allow_destroy => true
68
92
 
69
93
  default_scope where(:deleted_at => nil)
70
- before_save :check_do_not_email
94
+
71
95
  after_validation :validate_naming_details
72
- before_validation :default_to_individual
96
+ before_validation :validate_addresses
97
+ before_validation :default_subtype
98
+
73
99
  after_update :sync_update_to_mailchimp, :except => :create
74
- serialize :subscribed_lists, Array
100
+ after_update { ActionFeed.for(self.organization_id).rebuild_later }
101
+
102
+ serialize :old_subscribed_lists, Array
103
+ serialize :opted_out_lists, Array
104
+
75
105
  validates_presence_of :organization_id, :type, :subtype
76
106
  validates_numericality_of :birth_day, :birth_month, :birth_year, :allow_nil => true
77
107
  validates_inclusion_of :birth_day, :in => 1..31, :allow_nil => true
@@ -81,6 +111,10 @@ class Person < ActiveRecord::Base
81
111
  validates :email, :uniqueness => { :scope => [:organization_id, :deleted_at], :message => " %{value} has already been taken." }, :allow_blank => true
82
112
  validate :birth_month_and_day
83
113
 
114
+ def reject_address?(a)
115
+ a[:address1].blank? && a[:address2].blank? && a[:city].blank? && a[:state].blank? && a[:zip].blank?
116
+ end
117
+
84
118
  def dupe_code
85
119
  "#{first_name} | #{last_name} | #{email}"
86
120
  end
@@ -117,7 +151,11 @@ class Person < ActiveRecord::Base
117
151
  # Tickets are a special case
118
152
  #
119
153
  def self.mergables
120
- [:actions, :phones, :notes, :orders, :memberships, :passes]
154
+ [:actions, :phones, :notes, :orders, :soft_credits, :scheduled_pledge_payments, :passes, :subscribed_lists]
155
+ end
156
+
157
+ def self.loser_attributes_update_if_winner_not_present
158
+ ["company_name", "nickname", "listing_name", "maiden_name", "title", "salutation", "middle_name", "suffix", "twitter_handle", "facebook_url", "linked_in_url", "website", "birth_day", "birth_month", "birth_year", "email"]
121
159
  end
122
160
 
123
161
  def has_something?
@@ -141,33 +179,181 @@ class Person < ActiveRecord::Base
141
179
  end
142
180
 
143
181
  searchable do
144
- text :first_name, :middle_name, :last_name, :email, :company_name, :title
182
+ text :first_name
183
+ text :last_name
184
+ text :email
185
+ text :company_name
186
+ text :title
187
+ text :nickname
188
+ text :listing_name
189
+ text :maiden_name
190
+
191
+ text :full_name do
192
+ self.to_s
193
+ end
145
194
 
146
195
  text :member_number do
147
196
  member.member_number unless member.nil?
148
197
  end
149
198
 
150
- text :address do
151
- address.to_s unless address.nil?
199
+ text :phone_numbers do
200
+ phones.map {|phone| phone.number.gsub(/[^a-zA-Z0-9]/, "") }.join(" ")
201
+ end
202
+
203
+ text :clean_first_name do
204
+ first_name.gsub(/[^a-zA-Z0-9]/, '') unless first_name.nil?
205
+ end
206
+
207
+ text :clean_middle_name do
208
+ middle_name.gsub(/[^a-zA-Z0-9]/, '') unless middle_name.nil?
152
209
  end
210
+
211
+ text :clean_last_name do
212
+ last_name.gsub(/[^a-zA-Z0-9]/, '') unless last_name.nil?
213
+ end
214
+
215
+ text :clean_full_name do
216
+ self.to_s.gsub(/[^a-zA-Z0-9]/, '')
217
+ end
218
+
219
+ # text :address do
220
+ # address.to_s unless address.nil?
221
+ # end
153
222
 
154
223
  text :tags do
155
224
  taggings.map{ |tagging| tagging.tag.name }
156
225
  end
157
226
 
227
+ string :tag_list, multiple: true, stored: true do
228
+ tag_list.to_a
229
+ end
230
+
158
231
  text :notes do
159
232
  notes.map{ |note| note.text }.join(" ")
160
233
  end
161
234
 
162
- string :first_name, :last_name, :email, :company_name, :title
235
+ boolean :deleted do
236
+ deleted_at.present?
237
+ end
238
+
239
+ integer :id, :stored => true
240
+ string :first_name, :stored => true
241
+ string :last_name, :stored => true
242
+ string :email, :stored => true do
243
+ self.email.blank? ? nil : self.email
244
+ end
245
+ string :company_name, :stored => true
246
+ string :title
247
+ string :type, :stored => true
248
+ string :subtype
249
+
163
250
  string :organization_id do
164
- organization.id
251
+ organization_id
165
252
  end
166
253
 
167
254
  string :member_number do
168
255
  member.member_number unless member.nil?
169
256
  end
170
257
 
258
+ integer :birth_day
259
+ integer :birth_month
260
+ integer :birth_year
261
+ integer :lifetime_value
262
+
263
+ string :sort_name do
264
+ if type == "Individual"
265
+ "#{last_name} #{first_name}".downcase
266
+ elsif type == "Company"
267
+ company_name.try(:downcase)
268
+ end
269
+ end
270
+
271
+ text :city do
272
+ addresses.pluck(:city).join(' ')
273
+ end
274
+
275
+ string :state, multiple: true do
276
+ addresses.pluck(:state)
277
+ end
278
+
279
+ string :zip, multiple: true do
280
+ addresses.pluck(:zip)
281
+ end
282
+
283
+ string :country, multiple: true do
284
+ addresses.pluck(:country)
285
+ end
286
+
287
+ integer :discount_ids, multiple: true do
288
+ discount_codes = orders.map {|o| o.items.map(&:discount_id) }.flatten.compact.uniq
289
+ discount_codes.empty? ? nil : discount_codes
290
+ end
291
+
292
+ integer :event_ids, multiple: true do
293
+ event_ids = tickets.map {|t| t.show.event_id }.compact.uniq
294
+ event_ids.empty? ? nil : event_ids
295
+ end
296
+
297
+ date :donation_dates, multiple: true do
298
+ orders.map {|o| o.created_at if o.items.any? {|i| i.product_type == 'Donation'} }.compact
299
+ end
300
+
301
+ integer :relation_ids, multiple: true do
302
+ relationships.map(&:relation_id)
303
+ end
304
+
305
+ integer :membership_types, multiple: true do
306
+ memberships.any? ? memberships.map(&:membership_type_id) : nil
307
+ end
308
+
309
+ date :memberships_start_at, multiple: true do
310
+ memberships.any? ? memberships.map(&:starts_at) : nil
311
+ end
312
+
313
+ date :memberships_end_at, multiple: true do
314
+ memberships.any? ? memberships.map(&:ends_at) : nil
315
+ end
316
+
317
+ string :membership_status do
318
+ if member
319
+ if member.state == Member::CURRENT
320
+ 'Current'
321
+ elsif member.state == Member::LAPSED
322
+ 'Lapsed'
323
+ elsif member.state == Member::PAST
324
+ 'Past'
325
+ else
326
+ 'None'
327
+ end
328
+ else
329
+ 'None'
330
+ end
331
+ end
332
+
333
+ string :mailchimp_list_ids, multiple: true do
334
+ list_ids = subscribed_lists.pluck(:list_id)
335
+ list_ids.empty? ? nil : list_ids
336
+ end
337
+
338
+ string :mailchimp_groups, multiple: true do
339
+ group_tuples = []
340
+ lists = subscribed_lists.includes(:groupings)
341
+ lists.each do |list|
342
+ list.groupings.each do |grouping|
343
+ group_tuples << "#{grouping.mailchimp_id}|#{grouping.group}"
344
+ end
345
+ end
346
+ group_tuples
347
+ end
348
+
349
+ integer :household_id
350
+
351
+ integer :pass_type_ids, multiple: true do
352
+ passes.map(&:pass_type_id)
353
+ end
354
+
355
+ integer :id, stored: true
356
+
171
357
  end
172
358
  include Ext::DelayedIndexing
173
359
 
@@ -178,22 +364,29 @@ class Person < ActiveRecord::Base
178
364
  middle_name
179
365
  last_name
180
366
  suffix
367
+ nickname
368
+ listing_name
369
+ maiden_name
181
370
  title
182
371
  type
183
372
  subtype
184
373
  company_name
185
- address("Address 1") { |address| address && address.address1 }
186
- address("Address 2") { |address| address && address.address2 }
187
- address("City") { |address| address && address.city }
188
- address("State") { |address| address && address.state }
189
- address("Zip") { |address| address && address.zip }
190
- address("Country") { |address| address && address.country }
191
- phones("Phone1 type") { |phones| phones[0] && phones[0].kind }
192
- phones("Phone1 number") { |phones| phones[0] && phones[0].number }
193
- phones("Phone2 type") { |phones| phones[1] && phones[1].kind }
194
- phones("Phone2 number") { |phones| phones[1] && phones[1].number }
195
- phones("Phone3 type") { |phones| phones[2] && phones[2].kind }
196
- phones("Phone3 number") { |phones| phones[2] && phones[2].number }
374
+
375
+ ('A'..'C').each_with_index do |letter, i|
376
+ addresses("Address#{letter} Type") { |addresses| addresses[i] && addresses[i].kind }
377
+ addresses("Address#{letter} Address 1") { |addresses| addresses[i] && addresses[i].address1 }
378
+ addresses("Address#{letter} Address 2") { |addresses| addresses[i] && addresses[i].address2 }
379
+ addresses("Address#{letter} City") { |addresses| addresses[i] && addresses[i].city }
380
+ addresses("Address#{letter} State") { |addresses| addresses[i] && addresses[i].state }
381
+ addresses("Address#{letter} Zip") { |addresses| addresses[i] && addresses[i].zip }
382
+ addresses("Address#{letter} Country") { |addresses| addresses[i] && addresses[i].country }
383
+ end
384
+
385
+ (1..3).each do |i|
386
+ phones("Phone#{i} type") { |phones| phones[i-1] && phones[i-1].kind }
387
+ phones("Phone#{i} number") { |phones| phones[i-1] && phones[i-1].number }
388
+ end
389
+
197
390
  website
198
391
  twitter_handle
199
392
  facebook_url
@@ -216,51 +409,98 @@ class Person < ActiveRecord::Base
216
409
  end
217
410
 
218
411
  def self.merge(winner, loser)
219
- unless winner.organization == loser.organization
220
- raise "Trying to merge two people [#{winner.id}] [#{loser.id}] from different organizations [#{winner.organization.id}] [#{winner.organization.id}]"
221
- end
222
412
 
223
- unless winner.type == loser.type
224
- raise "Trying to merge two people [#{winner.id}] [#{loser.id}] with different types [#{winner.type}] [#{loser.type}]"
225
- end
413
+ ActiveRecord::Base.transaction do
414
+ unless winner.organization == loser.organization
415
+ raise "Trying to merge two people [#{winner.id}] [#{loser.id}] from different organizations [#{winner.organization.id}] [#{winner.organization.id}]"
416
+ end
226
417
 
227
- mergables.each do |mergable|
228
- loser.send(mergable).each do |m|
229
- m.person = winner
230
- m.save!
418
+ unless winner.type == loser.type
419
+ raise "Trying to merge two people [#{winner.id}] [#{loser.id}] with different types [#{winner.type}] [#{loser.type}]"
231
420
  end
232
- end
233
421
 
234
- loser.tickets.each do |ticket|
235
- ticket.update_column(:buyer_id, winner.id)
236
- end
422
+ mergables.each do |mergable|
423
+ klass = Kernel.const_get(mergable.to_s.classify)
424
+ klass.where(:person_id => loser.id).update_all(:person_id => winner.id)
425
+ end
237
426
 
238
- loser.tags.each do |t|
239
- winner.tag_list << t.name unless winner.tag_list.include? t.name
240
- end
427
+ loser.tickets.each do |ticket|
428
+ ticket.update_column(:buyer_id, winner.id)
429
+ end
241
430
 
242
- loser.relationships.each do |r|
243
- unless Relationship.where(:person_id => winner.id, :relation_id => r.relation.id, :other_id => r.other.id).first
244
- winner.relationships << r
431
+ loser.tags.each do |t|
432
+ winner.tag_list << t.name unless winner.tag_list.include? t.name
245
433
  end
434
+
435
+ loser.addresses.each do |address|
436
+ if winner.addresses.blank?
437
+ address.update_attributes(:person_id => winner.id)
438
+ elsif !winner.addresses.include?(address)
439
+ address.update_attributes(:person_id => winner.id, :is_primary => false)
440
+ end
441
+ end
442
+
443
+ # loser.relationships.each do |r|
444
+ # r.copy_to(winner) unless r.involves?(winner)
445
+ # end
446
+
447
+ loser_attributes_update_if_winner_not_present.each do |merge_attribute|
448
+ unless winner.send(merge_attribute).present?
449
+ if loser.send(merge_attribute).present?
450
+ value = loser.send(merge_attribute)
451
+ mergable_attribute = merge_attribute + '='
452
+ winner.send(mergable_attribute, value)
453
+ end
454
+ end
455
+ end
456
+
457
+ loser.relationships.each do |r|
458
+ r.copy_to(winner) unless r.involves?(winner)
459
+ end
460
+
461
+ loser.merge_member_for(winner)
462
+
463
+ winner.lifetime_value += loser.lifetime_value
464
+ winner.lifetime_donations += loser.lifetime_donations
465
+ winner.lifetime_ticket_value += loser.lifetime_ticket_value
466
+ winner.lifetime_memberships += loser.lifetime_memberships
467
+
468
+ winner.do_not_email = true if loser.do_not_email?
469
+ winner.do_not_call = true if loser.do_not_call?
470
+ new_lists = loser.subscribed_lists.map(&:list_id) - winner.subscribed_lists.map(&:list_id)
471
+ loser.destroy(with_prejudice: true)
472
+ winner.save!
473
+
474
+ mailchimp_kit = winner.organization.kits.mailchimp
475
+ MailchimpSyncJob.merged_person(mailchimp_kit, loser.email, winner.id, new_lists) if mailchimp_kit
476
+
477
+ return winner
246
478
  end
479
+ end
247
480
 
248
- winner.lifetime_value += loser.lifetime_value
249
- winner.lifetime_donations += loser.lifetime_donations
250
- winner.lifetime_ticket_value += loser.lifetime_ticket_value
251
- winner.lifetime_memberships += loser.lifetime_memberships
481
+ def merge_member_for(winner)
482
+ loser = self
483
+ winner_member = winner.member
484
+ loser_member = loser.member
252
485
 
253
- winner.do_not_email = true if loser.do_not_email?
254
- winner.do_not_call = true if loser.do_not_call?
255
- new_lists = loser.subscribed_lists - winner.subscribed_lists
256
- winner.subscribed_lists = winner.subscribed_lists.concat(loser.subscribed_lists).uniq
257
- winner.save!
258
- loser.destroy(with_prejudice: true)
486
+ # If the loser has no member, we're done
487
+ return if loser_member.nil?
259
488
 
260
- mailchimp_kit = winner.organization.kits.mailchimp
261
- MailchimpSyncJob.merged_person(mailchimp_kit, loser.email, winner.id, new_lists) if mailchimp_kit
489
+ if winner_member.nil?
490
+ # If the winner has no member, copy the winner's details into the loser's member
491
+ # in doing this, loser memberships automatically point to the member so they
492
+ # do not need to be transferred
493
+ loser_member.email = winner.email
494
+ loser_member.person_id = winner.id
495
+ loser_member.save!
496
+ else
497
+ # Update any Memberships from loser.member.id -> winner.member.id
498
+ Membership.where(:member_id => loser_member.id).update_all(:member_id => winner_member.id)
499
+
500
+ # Cleanup the loser's membership
501
+ loser_member.destroy
502
+ end
262
503
 
263
- return winner
264
504
  end
265
505
 
266
506
  #
@@ -272,7 +512,7 @@ class Person < ActiveRecord::Base
272
512
  # Addresses will be copied.
273
513
  # Phones will be ammended.
274
514
  # Tags will be ammended.
275
- # orders and tickets will not be copied.
515
+ # orders and tickets will not be copied.
276
516
  #
277
517
  def update_from_import(absorbee)
278
518
  ParsedRow.new([], []).person_attributes.keys.each do |key|
@@ -288,9 +528,12 @@ class Person < ActiveRecord::Base
288
528
  self.tag_list << t unless self.tag_list.include? t
289
529
  end
290
530
 
291
- if self.address.blank?
292
- self.address.try(:destroy)
293
- self.address = absorbee.address
531
+ self.addresses.each do |address|
532
+ address.try(:destroy)
533
+ end
534
+
535
+ absorbee.addresses.each do |address|
536
+ self.addresses << address unless address.blank?
294
537
  end
295
538
 
296
539
  absorbee.phones.each do |phone|
@@ -300,11 +543,6 @@ class Person < ActiveRecord::Base
300
543
  self
301
544
  end
302
545
 
303
- def self.find_by_email_and_organization(email, organization)
304
- return nil if email.blank?
305
- find(:first, :conditions => { :email => email, :organization_id => organization.id })
306
- end
307
-
308
546
  def self.find_by_organization(organization)
309
547
  find_by_organization_id(organization.id)
310
548
  end
@@ -373,9 +611,8 @@ class Person < ActiveRecord::Base
373
611
  return person if person
374
612
  end
375
613
 
376
- person = Person.find_by_email_and_organization(customer.email, organization)
377
-
378
- if person.nil?
614
+ person = Person.where(:email => customer.email, :organization_id => organization.id).first
615
+ if person.blank?
379
616
  params = {
380
617
  :first_name => customer.first_name,
381
618
  :last_name => customer.last_name,
@@ -402,20 +639,17 @@ class Person < ActiveRecord::Base
402
639
  end
403
640
  end
404
641
 
405
- # Needs a serious refactor
406
- def update_address(new_address, time_zone, user = nil, updated_by = nil)
642
+ def update_address(new_address)
407
643
  unless new_address.nil?
408
644
  new_address = Address.unhash(new_address)
409
- new_address.person = self
410
- @address = Address.find_or_create(id)
411
- if !@address.update_with_note(self, user, new_address, time_zone, updated_by)
412
- ::Rails.logger.error "Could not update address from payment"
413
- return false
645
+ new_address.is_primary = addresses.blank?
646
+ if addresses.blank? || !addresses.include?(new_address)
647
+ addresses << new_address
648
+ save
649
+ return true
414
650
  end
415
- self.address = @address
416
- save
417
651
  end
418
- true
652
+ return false
419
653
  end
420
654
 
421
655
  def phone_missing?(phone_number)
@@ -452,7 +686,7 @@ class Person < ActiveRecord::Base
452
686
  note
453
687
  end
454
688
 
455
- def create_subscribed_lists_notes!(user)
689
+ def update_and_note_subscriptions!(user, subscribed_list_ids, groupings, single_optin = false)
456
690
  if previous_changes["do_not_email"]
457
691
  new_note("#{user.email} changed do not email to #{do_not_email}",Time.now,user,organization.id)
458
692
  end
@@ -461,15 +695,24 @@ class Person < ActiveRecord::Base
461
695
  new_note("#{user.email} changed do not call to #{do_not_call}",Time.now,user,organization.id)
462
696
  end
463
697
 
464
- if previous_changes["subscribed_lists"]
698
+ if mailchimp_kit && subscribed_list_ids
699
+ if do_not_email
700
+ subscribed_list_ids = []
701
+ end
702
+
703
+ new_lists = subscribed_list_ids - subscribed_lists.map(&:list_id)
704
+ old_lists = subscribed_lists.map(&:list_id) - subscribed_list_ids
705
+
465
706
  mailchimp_kit.attached_lists.each do |list|
466
- old_lists = previous_changes["subscribed_lists"][0]
467
- if !old_lists.include?(list[:list_id]) && subscribed_lists.include?(list[:list_id])
707
+ if new_lists.include?(list[:list_id])
468
708
  new_note("#{user.email} changed subscription status of the MailChimp list #{list[:list_name]} to subscribed",Time.now,user,organization.id)
469
- elsif old_lists.include?(list[:list_id]) && !subscribed_lists.include?(list[:list_id])
709
+ elsif old_lists.include?(list[:list_id])
470
710
  new_note("#{user.email} changed subscription status of the MailChimp list #{list[:list_name]} to unsubscribed",Time.now,user,organization.id)
471
711
  end
472
712
  end
713
+
714
+ update_subscribed_lists(subscribed_list_ids, single_optin)
715
+ update_groupings(groupings)
473
716
  end
474
717
  end
475
718
 
@@ -487,9 +730,14 @@ class Person < ActiveRecord::Base
487
730
  end
488
731
  end
489
732
 
490
- def default_to_individual
491
- self.type ||= "Individual"
492
- self.subtype ||= "Individual"
733
+ def default_subtype
734
+ if self.type == 'Individual'
735
+ self.subtype ||= 'Individual'
736
+ end
737
+
738
+ if self.type == 'Company'
739
+ self.subtype ||= 'Other'
740
+ end
493
741
  end
494
742
 
495
743
  def validate_naming_details
@@ -500,6 +748,19 @@ class Person < ActiveRecord::Base
500
748
  first_name.present? || last_name.present? || email.present? || company_name.present?
501
749
  end
502
750
 
751
+ def validate_addresses
752
+ errors.add(:base, "A primary address is empty") unless addresses.empty? || non_empty_primary_address_available?
753
+ end
754
+
755
+ def non_empty_primary_address_available?
756
+ addresses.each do |address|
757
+ if address.is_primary?
758
+ return true
759
+ end
760
+ end
761
+ return false
762
+ end
763
+
503
764
  def send_pass_summary_email(passes)
504
765
  PassMailer.pass_info_for(self, self.organization.email,passes).deliver
505
766
  end
@@ -507,13 +768,161 @@ class Person < ActiveRecord::Base
507
768
  def any_current_passes?
508
769
  passes.not_expired.any?
509
770
  end
771
+
772
+ #
773
+ # encapsulate what happens to a person on people_controller#update
774
+ #
775
+ def update_person_attributes(params, updating_user)
776
+ success = self.update_attributes(params)
777
+
778
+ if success.eql?(true)
779
+ if self.member.present?
780
+ self.member.email = params['email'] if self.previous_changes.keys.include?('email')
781
+ self.member.save!
782
+ end
783
+
784
+ self.relationships.where(:inverse_id => nil).map(&:ensure_inverse)
785
+ end
786
+
787
+ success
788
+ end
789
+
790
+ def outstanding_pledges
791
+ orders.pledge.select { |o| !o.fully_paid? }
792
+ end
793
+
794
+ def scheduled_and_non_scheduled_pledges
795
+ not_received_scheduled_pledges = scheduled_pledge_payments.not_received.pluck(:order_id)
796
+ non_scheduled_pledges = []
797
+ outstanding_pledges.reject{|o| not_received_scheduled_pledges.include?(o.id)}.each_with_index do |o, index|
798
+ spp = ScheduledPledgePayment.new
799
+ spp.id = -(index + 1)
800
+ spp.order_id = o.id
801
+ spp.date = o.created_at.to_date
802
+ spp.amount = o.outstanding_amount.to_i / 100
803
+ non_scheduled_pledges << spp
804
+ end
805
+ non_scheduled_pledges + (scheduled_pledge_payments || [])
806
+ end
807
+
808
+ def subscribe_to_default_mailchimp_list!
809
+ return unless mailchimp_kit
810
+ subscribed_lists.create(:list_id => mailchimp_kit.default_list_id, :single_optin => true)
811
+ end
812
+
813
+ def opted_out_of_list?(list_id)
814
+ opted_out_lists.include?(list_id)
815
+ end
816
+
817
+ def subscribed_to_list?(list_id)
818
+ subscribed_list = subscribed_lists.where(:list_id => list_id).first
819
+ !subscribed_list.bounced? if subscribed_list
820
+ end
821
+
822
+ def in_group?(list_id, grouping_id, group_name)
823
+ subscribed_list = subscribed_lists.where(:list_id => list_id).first
824
+ subscribed_list.groupings.where(:mailchimp_id => grouping_id, :group => group_name).present? if subscribed_list
825
+ end
826
+
827
+ def confirmed_on_list?(list_id)
828
+ subscribed_list = subscribed_lists.where(:list_id => list_id).first
829
+ subscribed_list.confirmed? if subscribed_list
830
+ end
831
+
832
+ def unconfirmed_on_list?(list_id)
833
+ subscribed_list = subscribed_lists.where(:list_id => list_id).first
834
+ !subscribed_list.confirmed? if subscribed_list
835
+ end
836
+
837
+ def bounced_on_list?(list_id)
838
+ subscribed_list = subscribed_lists.where(:list_id => list_id).first
839
+ subscribed_list.bounced? if subscribed_list
840
+ end
841
+
842
+ def update_subscribed_lists(list_ids, single_optin)
843
+ # Remove lists that are unsubscribed
844
+ subscribed_lists.each do |subscribed_list|
845
+ next if list_ids.include?(subscribed_list.list_id)
846
+ subscribed_list.destroy
847
+ end
848
+
849
+ # subscribe to new lists
850
+ new_lists = list_ids - subscribed_lists.map(&:list_id)
851
+ new_lists.each do |list_id|
852
+ list = subscribed_lists.create(:list_id => list_id, :single_optin => single_optin)
853
+ if single_optin
854
+ list.update_attributes(:confirmed => true)
855
+ end
856
+ end
857
+ end
858
+
859
+ def update_groupings(groupings)
860
+ subscribed_lists.each do |subscribed_list|
861
+ subscribed_list.groupings.destroy_all
862
+ end
863
+
864
+ return unless groupings.present?
865
+
866
+ groupings.each do |list_id, groupings|
867
+ list = subscribed_lists.where(:list_id => list_id).first
868
+ attached_list = mailchimp_kit.attached_lists.detect { |list| list[:list_id] == list_id }
869
+ next unless list && attached_list
870
+ groupings.each do |grouping_id, groups|
871
+ grouping = attached_list.fetch(:groups, []).detect { |grouping| grouping["id"] == grouping_id.to_i }
872
+ next unless grouping
873
+ groups.each do |group|
874
+ list.groupings.create(:mailchimp_id => grouping_id, :name => grouping["name"], :group => group)
875
+ end
876
+ end
877
+ end
878
+
879
+ job = MailchimpSyncJob.new(mailchimp_kit, {
880
+ :type => "grouping_update",
881
+ :person_id => id,
882
+ })
883
+ Delayed::Job.enqueue(job, :queue => "mailchimp")
884
+ end
885
+
886
+ # Migrate object to a new STI class
887
+ # For example, individual.become_a!(Company) would convert the individual
888
+ # to a company and returns the new Company object with `type` already persisted.
889
+ def become_a!(klass)
890
+ klass = klass.constantize unless klass.is_a?(Class)
891
+ unless Person.descendants.include?(klass)
892
+ raise ArgumentError.new('That class is not a descendant of Person')
893
+ end
894
+ self.update_column(:type, klass.to_s)
895
+ self.solr_remove_from_index
896
+ klass.find(self.id)
897
+ end
510
898
 
511
899
  private
900
+ def check_list_bounce_status
901
+ return [] unless changes.has_key?("email")
902
+ bounced_lists = subscribed_lists.where(:bounced => true)
903
+ bounced_lists.each do |subscribed_list|
904
+ subscribed_list.bounced = false
905
+ subscribed_list.save
906
+ end
907
+ bounced_lists
908
+ end
909
+
512
910
  def sync_update_to_mailchimp
513
911
  return if skip_sync_to_mailchimp
514
912
  return unless mailchimp_changes? && mailchimp_kit
515
- job = MailchimpSyncJob.new(mailchimp_kit, :type => :person_update_to_mailchimp, :person_id => id, :person_changes => changes)
516
- Delayed::Job.enqueue(job, :queue => "mailchimp") if !mailchimp_kit.cancelled?
913
+
914
+ updated_bounced_lists = check_list_bounce_status
915
+
916
+ job = MailchimpSyncJob.new(mailchimp_kit, {
917
+ :type => :person_update_to_mailchimp,
918
+ :person_id => id,
919
+ :person_changes => changes,
920
+ :bounced_list_ids => updated_bounced_lists.map(&:id),
921
+ })
922
+
923
+ if !mailchimp_kit.cancelled?
924
+ Delayed::Job.enqueue(job, :queue => "mailchimp")
925
+ end
517
926
  end
518
927
 
519
928
  def mailchimp_kit
@@ -521,18 +930,18 @@ class Person < ActiveRecord::Base
521
930
  end
522
931
 
523
932
  def mailchimp_changes?
524
- ["first_name", "last_name", "email", "do_not_email", "subscribed_lists"].any? { |attr| changes.keys.include?(attr) }
933
+ ["first_name", "last_name", "email", "do_not_email"].any? { |attr| changes.keys.include?(attr) }
525
934
  end
526
935
 
527
936
  def check_do_not_email
528
937
  self.subscribed_lists = [] if do_not_email
529
938
  end
530
-
939
+
531
940
  def birth_month_and_day
532
941
  if self.birth_month.present? && self.birth_day.blank?
533
942
  errors.add(:birth_day, "cannot be blank.")
534
943
  end
535
-
944
+
536
945
  if self.birth_month.blank? && self.birth_day.present?
537
946
  errors.add(:birth_month, "cannot be blank.")
538
947
  end