Skip to content
Browse files

Merge branch 'master' into add_bpa_rate_info

  • Loading branch information...
2 parents 8e30804 + 311fe16 commit 29af645705aca210e1826b07e937be85bff4a6ff @keviniano keviniano committed Jun 20, 2012
Showing with 10 additions and 17 deletions.
  1. +3 −15 app/controllers/summaries_controller.rb
  2. +6 −1 app/models/summary.rb
  3. +1 −1 app/views/summaries/_summaries.html.erb
View
18 app/controllers/summaries_controller.rb
@@ -85,20 +85,8 @@ def bulk_update
if @query.conditions.first.empty?
flash[:alert] = "Cannot update without date range"
else
- for summary in Summary.current_versions.find(:all, :conditions=>@query.conditions)
- next if summary.complete
- updated += 1
- old_rows = summary.summary_rows.map &:clone
- summary.complete = true
- summary.save!
- prev = summary.previous
- for row in old_rows
- row.summary_id=prev.id
- row.save!
- end
- end
+ updated = Summary.current_versions.where(@query.conditions).data_entry_not_complete.update_all(:complete => true)
flash[:alert] = "Updated #{updated} records"
-
end
redirect_to :action => :index, :summary_query => params[:summary_query]
end
@@ -112,18 +100,18 @@ def show_update
def update
old_version = Summary.find(params[:summary][:id])
@summary = old_version.current_version
- prev = @summary.previous
@providers = Provider.with_summary_data.order(:name).all
@versions = @summary.versions.reverse
#gather up the old row objects
- old_rows = @summary.summary_rows.map &:clone if prev
+ old_rows = @summary.summary_rows.map &:clone
@summary.attributes = params[:summary]
if @summary.save
#this created a new prior version, to which we want to reassign the
#newly-created old-valued summary rows
+ prev = @summary.previous
if prev
for row in old_rows
row.summary_id=prev.id
View
7 app/models/summary.rb
@@ -23,7 +23,6 @@ def date_range(start_date, after_end_date)
TripAttrs = [:total_miles,:turn_downs,:unduplicated_riders,:driver_hours_paid,:driver_hours_volunteer,:escort_hours_volunteer]
- validates_uniqueness_of :allocation_id, :scope => :period_start, :message => "already in use in another summary for this month"
validates :allocation_id, :presence => true
validates :administrative_hours_volunteer, :numericality => true
validates :funds, :numericality => true
@@ -37,6 +36,9 @@ def date_range(start_date, after_end_date)
validates_size_of :vehicle_maint, :is => 0, :allow_nil => true, :if => Proc.new {|rec| rec.allocation.try(:vehicle_maint_data) == 'Prohibited'}, :wrong_length => "should be blank"
validate do |record|
+ if Summary.where("base_id <> COALESCE(?,0)",record.base_id).where(:period_start => record.period_start,:allocation_id => record.allocation_id).exists?
+ record.errors.add :allocation_id, "already in use in another summary for this month"
+ end
record.summary_rows.each do |row|
if record.allocation.try(:trip_collection_method) == 'summary_rows'
unless row.in_district_trips.is_a? Numeric
@@ -70,6 +72,7 @@ def date_range(start_date, after_end_date)
scope :valid_range, lambda{|start_date, end_date| where("summaries.valid_start <= ? and summaries.valid_end > ?",start_date,end_date) }
scope :data_entry_complete, where(:complete => true)
+ scope :data_entry_not_complete, where(:complete => false)
scope :for_date_range, lambda {|start_date, end_date| where("summaries.period_start >= ? AND summaries.period_start < ?", start_date, end_date) }
scope :for_allocation, lambda {|allocation| where(:allocation_id => allocation.id) }
@@ -112,4 +115,6 @@ def fix_period_end
self.period_end = self.period_start.next_month - 1.day
end
+
+
end
View
2 app/views/summaries/_summaries.html.erb
@@ -1,6 +1,6 @@
<h2 id="result-count"><%= @summaries.total_entries %> summaries found.</h2>
<% if @summaries.total_entries > 0 %>
- <%= link_to 'Mark All Complete', { :action => :bulk_update, :summary_query => params[:summary_query] }, :class=>'mark-complete' %>
+ <%= link_to 'Mark Data Entry Complete For All', { :action => :bulk_update, :summary_query => params[:summary_query] }, :class=>'mark-complete' %>
<div class="list-wrapper">
<table id="summary-results">
<thead>

0 comments on commit 29af645

Please sign in to comment.
Something went wrong with that request. Please try again.