Skip to content

Commit

Permalink
Creazione di progetti ricorrenti scaduti
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyblue committed Aug 22, 2012
1 parent 627d9c3 commit 245842c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/recurring_slips_controller.rb
Expand Up @@ -16,8 +16,10 @@ def create
schedule = IceCube::Schedule.new
schedule.add_recurrence_rule rule
@recurring_slip.schedule = schedule
@recurring_slip.start_date = Date.strptime(params[:schedule][:next], "%d/%m/%Y") unless params[:schedule][:next].empty?
next_occurrence = params[:schedule][:next].empty? ? nil : Date.strptime(params[:schedule][:next], "%d/%m/%Y")
@recurring_slip.start_date = next_occurrence if next_occurrence
if @recurring_slip.customer.user_id == current_user.id and @recurring_slip.save
@recurring_slip.force_next_occurrence(next_occurrence) if next_occurrence
redirect_to(recurring_slips_path, :notice => t('controllers.recurring_slips.create.success', :default => 'The recurring slip was successfully created.'))
else
render :action => "new"
Expand Down
4 changes: 4 additions & 0 deletions app/models/recurring_slip.rb
Expand Up @@ -17,6 +17,10 @@ class RecurringSlip < ActiveRecord::Base
self.next_occurrence = self.schedule.next_occurrence unless self.next_occurrence
end

def force_next_occurrence(next_occurrence)
self.update_attribute(:next_occurrence, next_occurrence)
end

def to_invoice?
self.next_occurrence and self.next_occurrence < Time.now
end
Expand Down

0 comments on commit 245842c

Please sign in to comment.