@@ -18,40 +18,14 @@ def print
1818 def index
1919 setup_date_range_picker
2020
21- @donations = current_organization . donations
22- . includes ( :storage_location , :donation_site , :product_drive , :product_drive_participant , :manufacturer , line_items : [ :item ] )
23- . order ( created_at : :desc )
24- . class_filter ( filter_params )
25- . during ( helpers . selected_range )
26- @item_categories = current_organization . item_categories . pluck ( :name ) . uniq
27- @paginated_donations = @donations . page ( params [ :page ] )
28-
29- @product_drives = current_organization . product_drives . alphabetized
30- @product_drive_participants = current_organization . product_drive_participants . alphabetized
31-
32- # Are these going to be inefficient with large datasets?
33- # Using the @donations allows drilling down instead of always starting with the total dataset
34- @donations_quantity = @donations . collect ( &:total_quantity ) . sum
35- @paginated_donations_quantity = @paginated_donations . collect ( &:total_quantity ) . sum
36- @total_value_all_donations = total_value ( @donations )
37- @paginated_in_kind_value = total_value ( @paginated_donations )
38- @total_money_raised = total_money_raised ( @donations )
39- @storage_locations = @donations . filter_map { |donation | donation . storage_location if !donation . storage_location . discarded_at } . compact . uniq . sort
40- @selected_storage_location = filter_params [ :at_storage_location ]
41- @sources = @donations . collect ( &:source ) . uniq . sort
42- @selected_source = filter_params [ :by_source ]
43- @selected_item_category = filter_params [ :by_category ]
44- @donation_sites = @donations . collect ( &:donation_site ) . compact . uniq . sort_by { |site | site . name . downcase }
45- @selected_donation_site = filter_params [ :from_donation_site ]
46- @selected_product_drive = filter_params [ :by_product_drive ]
47- @selected_product_drive_participant = filter_params [ :by_product_drive_participant ]
48- @manufacturers = @donations . collect ( &:manufacturer ) . compact . uniq . sort
49- @selected_manufacturer = filter_params [ :from_manufacturer ]
21+ @donation_info = View ::Donations . from_params ( params : params , organization : current_organization , helpers : helpers )
5022
5123 respond_to do |format |
5224 format . html
5325 format . csv do
54- send_data Exports ::ExportDonationsCSVService . new ( donation_ids : @donations . map ( &:id ) , organization : current_organization ) . generate_csv , filename : "Donations-#{ Time . zone . today } .csv"
26+ send_data Exports ::ExportDonationsCSVService . new ( donation_ids : @donation_info . donations . map ( &:id ) ,
27+ organization : current_organization ) . generate_csv ,
28+ filename : "Donations-#{ Time . zone . today } .csv"
5529 end
5630 end
5731 end
@@ -81,7 +55,9 @@ def new
8155 def edit
8256 @donation = Donation . find ( params [ :id ] )
8357 @donation . line_items . build
84- @audit_performed_and_finalized = Audit . finalized_since? ( @donation , @donation . storage_location_id )
58+ @changes_disallowed = SnapshotEvent . intervening ( @donation ) . present?
59+ @audit_performed_and_finalized = Audit . finalized_since? ( @donation , @donation . storage_location_id ) &&
60+ !@changes_disallowed
8561
8662 load_form_collections
8763 end
@@ -117,7 +93,7 @@ def destroy
11793 if service . success?
11894 flash [ :notice ] = "Donation #{ params [ :id ] } has been removed!"
11995 else
120- flash [ :error ] = "Donation #{ params [ :id ] } failed to be removed because #{ service . error } "
96+ flash [ :error ] = service . error . message
12197 end
12298
12399 redirect_to donations_path
@@ -177,16 +153,4 @@ def compact_line_items
177153 params [ :donation ] [ :line_items_attributes ] . delete_if { |_row , data | data [ "quantity" ] . blank? && data [ "item_id" ] . blank? }
178154 params
179155 end
180-
181- def total_value ( donations )
182- total_value_all_donations = 0
183- donations . each do |donation |
184- total_value_all_donations += donation . value_per_itemizable
185- end
186- total_value_all_donations
187- end
188-
189- def total_money_raised ( donations )
190- donations . sum { |d | d . money_raised . to_i }
191- end
192156end
0 commit comments