Skip to content

Instantly share code, notes, and snippets.

@sahilsk
Created November 17, 2014 03:59
Show Gist options
  • Select an option

  • Save sahilsk/4b23cdfb7c3ffccf8456 to your computer and use it in GitHub Desktop.

Select an option

Save sahilsk/4b23cdfb7c3ffccf8456 to your computer and use it in GitHub Desktop.
Task.rb
# == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# date :date
# task :text
# tid :string(255)
# actual_time_taken :float
# billable_time_taken :float
# status :string(255)
# remark :text
# user_id :integer
# organization_id :integer
# created_at :datetime
# updated_at :datetime
# draft :boolean
#
class Task < ActiveRecord::Base
belongs_to :user
belongs_to :organization
attr_accessible :date, :organization_id, :task, :tid,
:status, :remark, :draft,
:total_act_hrs, :total_act_mins,
:total_bil_hrs, :total_bil_mins
validates :task, presence: true, length: { minimum: 10 }
validates :date, presence: true
validates :organization_id, presence: true
def total_act_hrs
return (actual_time_taken/60).to_i
end
def total_act_hrs=(hrs)
self.actual_time_taken = self.actual_time_taken.to_i + hrs.to_i * 60
end
def total_act_mins
return actual_time_taken%60
end
def total_act_mins=(mins)
self.actual_time_taken = self.actual_time_taken + mins.to_i
end
def total_bil_hrs
return (billable_time_taken/60).to_i
end
def total_bil_hrs=(hrs)
self.billable_time_taken = self.billable_time_taken.to_i + hrs.to_i * 60
end
def total_bil_mins
return billable_time_taken%60
end
def total_bil_mins=(mins)
self.billable_time_taken = self.billable_time_taken + mins.to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment