Skip to content
Browse files

Creazione di progetti ricorrenti scaduti

  • Loading branch information...
1 parent 627d9c3 commit 245842c56a7259f9337067e2398a8469022bb100 @tommyblue committed Aug 22, 2012
Showing with 7 additions and 1 deletion.
  1. +3 −1 app/controllers/recurring_slips_controller.rb
  2. +4 −0 app/models/recurring_slip.rb
View
4 app/controllers/recurring_slips_controller.rb
@@ -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"
View
4 app/models/recurring_slip.rb
@@ -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

0 comments on commit 245842c

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