Able to enter a location with a time entry

This commit is contained in:
Bram Senders 2011-11-23 22:05:51 +01:00
parent d706e91e9d
commit b31cd03330
1 changed files with 20 additions and 0 deletions

View File

@ -214,6 +214,11 @@ module StopTime::Models
class Location < Base class Location < Base
has_many :time_entries has_many :time_entries
belongs_to :invoice belongs_to :invoice
# Returns whether the location is billed, i.e. included in an invoice.
def billed?
not invoice.nil?
end
end end
class StopTimeTables < V 1.0 # :nodoc: class StopTimeTables < V 1.0 # :nodoc:
@ -822,6 +827,9 @@ module StopTime::Controllers
@task_list = Task.all.reject { |t| t.billed? }.map do |t| @task_list = Task.all.reject { |t| t.billed? }.map do |t|
[t.id, t.name] [t.id, t.name]
end end
@location_list = Location.all.reject { |l| l.billed? }.map do |l|
[l.id, l.name]
end
@input["bill"] = true # Bill by default. @input["bill"] = true # Bill by default.
render :time_entries render :time_entries
end end
@ -832,6 +840,7 @@ module StopTime::Controllers
if @input.has_key? "enter" if @input.has_key? "enter"
@time_entry = TimeEntry.create( @time_entry = TimeEntry.create(
:task_id => @input.task, :task_id => @input.task,
:location_id => @input.location,
:date => @input.date, :date => @input.date,
:start => "#{@input.date} #{@input.start}", :start => "#{@input.date} #{@input.start}",
:end => "#{@input.date} #{@input.end}", :end => "#{@input.date} #{@input.end}",
@ -888,6 +897,7 @@ module StopTime::Controllers
@input = @time_entry.attributes @input = @time_entry.attributes
@input["customer"] = @time_entry.task.customer.id @input["customer"] = @time_entry.task.customer.id
@input["task"] = @time_entry.task.id @input["task"] = @time_entry.task.id
@input["location"] = @time_entry.location.id
@input["date"] = @time_entry.date.to_date @input["date"] = @time_entry.date.to_date
@input["start"] = @time_entry.start.to_formatted_s(:time_only) @input["start"] = @time_entry.start.to_formatted_s(:time_only)
@input["end"] = @time_entry.end.to_formatted_s(:time_only) @input["end"] = @time_entry.end.to_formatted_s(:time_only)
@ -920,6 +930,7 @@ module StopTime::Controllers
@time_entry.start = "#{@input["date"]} #{@input["start"]}" @time_entry.start = "#{@input["date"]} #{@input["start"]}"
@time_entry.end = "#{@input["date"]} #{@input["end"]}" @time_entry.end = "#{@input["date"]} #{@input["end"]}"
@time_entry.task = Task.find(@input.task) @time_entry.task = Task.find(@input.task)
@time_entry.location = Location.find(@input.location)
@time_entry.bill = @input.has_key? "bill" @time_entry.bill = @input.has_key? "bill"
@time_entry.save @time_entry.save
if @time_entry.invalid? if @time_entry.invalid?
@ -1222,6 +1233,7 @@ module StopTime::Views
h2 "Timeline" h2 "Timeline"
table.timeline do table.timeline do
col.task {} col.task {}
col.location {}
col.date {} col.date {}
col.start_time {} col.start_time {}
col.end_time {} col.end_time {}
@ -1230,6 +1242,7 @@ module StopTime::Views
col.flag {} col.flag {}
tr do tr do
th "Project/Task" th "Project/Task"
th "Location"
th "Date" th "Date"
th "Start time" th "Start time"
th "End time" th "End time"
@ -1240,6 +1253,7 @@ module StopTime::Views
form :action => R(Timeline), :method => :post do form :action => R(Timeline), :method => :post do
tr do tr do
td { _form_select("task", @task_list) } td { _form_select("task", @task_list) }
td { _form_select("location", @location_list) }
td { input :type => :text, :name => "date", td { input :type => :text, :name => "date",
:value => DateTime.now.to_date.to_formatted_s } :value => DateTime.now.to_date.to_formatted_s }
td { input :type => :text, :name => "start", td { input :type => :text, :name => "start",
@ -1258,6 +1272,12 @@ module StopTime::Views
tr do tr do
td { a entry.task.name, td { a entry.task.name,
:href => R(CustomersNTasksN, entry.customer.id, entry.task.id) } :href => R(CustomersNTasksN, entry.customer.id, entry.task.id) }
if entry.location
td { a entry.location.name,
:href => R(LocationsN, entry.location.id) }
else
td { "unspecified" }
end
td { a entry.date.to_date, td { a entry.date.to_date,
:href => R(TimelineN, entry.id) } :href => R(TimelineN, entry.id) }
td { entry.start.to_formatted_s(:time_only) } td { entry.start.to_formatted_s(:time_only) }