diff --git a/config.yaml.example b/config.yaml.example index 53557af..8d5b841 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -3,6 +3,10 @@ # Time resolution in minutes #time_resolution: 1 +# Which date to use for new entries +# Supported values are: previous, today, none +#date_new_entry: today + # The default hourly rate #hourly_rate: 20.0 diff --git a/stoptime.rb b/stoptime.rb index 8dbef5b..3e02338 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -55,7 +55,7 @@ end module StopTime # The version of the application - VERSION = '1.16.1' + VERSION = '1.17.0' puts "Starting Stop… Camping Time! version #{VERSION}" # @return [Hash{String=>Object}] The parsed configuration. @@ -166,6 +166,7 @@ module StopTime::Models "invoice_template" => "invoice", "hourly_rate" => 20.0, "time_resolution" => 1, + "date_new_entry" => "today", "vat_rate" => 21.0 } # Creates a new configuration object and loads the configuation. @@ -888,6 +889,30 @@ module StopTime::Models end # StopTime::Models +# = The Stop… Camping Time! helpers +module StopTime::Helpers + + # Returns the date/time to use for new time entry defaults, or +nil+ if + # none is to be used. This method can use the last time entry (if any + # and if so configured). The result is based on the +date_new_entry+ + # configuration option. + # + # @param last_entry [DateTime] the last time entry to use if configured + # for "previous" + # @return [DateTime, nil] the date/time to be used for new entry defaults + def date_time_new_entry(last_entry = nil) + case @config["date_new_entry"] + when "previous" + TimeEntry.last.end + when "today" + DateTime.now + when "none" + nil + end + end + +end + # = The Stop… Camping Time! controllers module StopTime::Controllers @@ -1281,7 +1306,7 @@ module StopTime::Controllers tasks.each_key do |task| # Create a new (billed) task clone that contains the selected time # entries, leave the rest unbilled and associated with their task. - bill_task = task.dup # FIXME: depends on rails version! + bill_task = task.dup task.time_entries = task.time_entries - tasks[task] task.save bill_task.time_entries = tasks[task] @@ -1495,6 +1520,7 @@ module StopTime::Controllers .where("stoptime_tasks.invoice_id" => nil)\ .order("start DESC") end + @time_entries = @time_entries.where.not(task_id: nil) @time_entries.each do |te| @input["bill_#{te.id}"] = true if te.bill? end @@ -1550,9 +1576,11 @@ module StopTime::Controllers @task_list[t.customer.shortest_name] << [t.id, t.name] end @input["bill"] = true - @input["date"] = DateTime.now.to_date - @input["start"] = Time.now.to_formatted_s(:time_only) - + date_time_new = date_time_new_entry(TimeEntry.last) + if date_time_new + @input["date"] = date_time_new.to_date.to_formatted_s + @input["start"] = date_time_new.to_formatted_s(:time_only) + end @target = [Timeline] @button = "enter" render :time_entry_form @@ -1700,9 +1728,9 @@ module StopTime::Controllers # If we are editing the current info and it is already associated # with some invoices, create a new revision. @history_warn = true if @company != CompanyInfo.last - if @company == CompanyInfo.last and @company.invoices.length > 0 + if @company.id == CompanyInfo.last.id and @company.invoices.length > 0 old_company = @company - @company = old_company.clone # FIXME: depends on rails version! + @company = old_company.dup @company.original = old_company end @@ -1834,7 +1862,7 @@ module StopTime::Views elsif @active_tasks[customer].empty? p do em "No active projects/tasks found! " + - "Register time on one of these tasks: " + "Register time on one of these projects/tasks: " br @tasks[customer].each do |task| a task.name, href: R(CustomersNTasksN, customer.id, task.id) @@ -2919,7 +2947,7 @@ module StopTime::Views tbody do invoices.each do |invoice| due_class = invoice.past_due? ? "warning" : "" - due_class = "error" if invoice.way_past_due? + due_class = "danger" if invoice.way_past_due? tr(class: due_class) do td do a invoice.number, @@ -3123,6 +3151,7 @@ module StopTime::Views # @param [Customer, nil] task a task to show time entries for # @return [Mab::Mixin::Tag] the main menu def _time_entries(customer=nil, task=nil) + date_time_new = date_time_new_entry(@time_entries.first) form.form_inline action: R(Timeline), method: :post do table.table.table_condensed.table_striped.table_hover do thead do @@ -3156,11 +3185,11 @@ module StopTime::Views end td.col_md_1 do input.form_control type: :text, name: "date", - value: DateTime.now.to_date.to_formatted_s + value: date_time_new && date_time_new.to_date.to_formatted_s end td.col_md_1 do input.form_control type: :text, name: "start", - value: DateTime.now.to_time.to_formatted_s(:time_only) + value: date_time_new && date_time_new.to_formatted_s(:time_only) end td.col_md_1 do input.form_control type: :text, name: "end"