Fix for 1.4.x easily.
And modified to work in development mode.
Update version.
git clone でそのまま使えるように階層移動
rails3対応 詳細は出力されるようになったがレポートはまだでない

rails2 以前に使ったことないのでヌケモレあるかも
update version 0.5.0
詳細とレポートを rails3, jQuery 対応

ついでに予定ベースのレポートを予定実績ベースに変更

diff --git a/app/controllers/estimate_timelog_controller.rb b/app/controllers/estimate_timelog_controller.rb
index 729ade5..fdb3f89 100644
--- a/app/controllers/estimate_timelog_controller.rb
+++ b/app/controllers/estimate_timelog_controller.rb
@@ -211,28 +211,32 @@ class EstimateTimelogController < ApplicationController
       end

       sql  = "SELECT "
-      sql << "#{sql_select_all}, yotei.hours_est, jisseki.hours "
+      if params[:est_type] == '1'
+        sql << "#{sql_select_all}, sum(yotei.hours_est) hours_est, sum(yotei.hours) hours "
+      elsif params[:est_type] == '2'
+        sql << "#{sql_select_all}, yotei.hours_est hours_est, jisseki.hours "
+      end
       sql << "FROM   "
       sql << "(SELECT #{sql_select_yotei}, issues.id as issue_id, "
-      sql << "    '' as spent_on, SUM(estimated_hours) AS hours_est   "
+      sql << "    '' as spent_on, SUM(estimated_hours) AS hours_est, 0 AS hours   "
       sql << "    FROM issues  "
       sql << "    LEFT JOIN projects ON issues.project_id = projects.id   "
       sql << "      WHERE 1=1"
       sql << "      AND (%s) " % @project.project_condition(Setting.display_subprojects_issues?) if @project
       sql << "      AND (%s) " % Project.allowed_to_condition(User.current, :view_time_entries)
       if params[:est_type] == '1'
-        sql << "     AND (start_date <= '%s' )" % [ActiveRecord::Base.connection.quoted_date(@to.to_time)]
-        sql << "     AND (due_date   >= '%s' )" % [ActiveRecord::Base.connection.quoted_date(@from.to_time)]
+        sql << "     AND (start_date <= '%s')" % [ActiveRecord::Base.connection.quoted_date(@to.to_time)]
+        sql << "     AND (due_date   >= '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time)]
         sql << "     AND (issues.assigned_to_id = '%s')" % [User.current.id] if params[:my_type]
       end
-      sql << "    GROUP BY #{sql_group_by_yotei}, issues.id) yotei "
+      sql << "    GROUP BY #{sql_group_by_yotei}, issues.id"
       if params[:est_type] == '1'
-        sql << "LEFT  "
+        sql << " UNION ALL  "
       elsif params[:est_type] == '2'
-        sql << "RIGHT "
+        sql << ") yotei "
+        sql << "RIGHT JOIN ("
       end
-      sql << "JOIN "
-      sql << "(SELECT #{sql_select_jisseki}, issues.id as issue_id, '' as spent_on, SUM(hours) AS hours FROM time_entries  LEFT JOIN issues ON time_entries.issue_id = issues.id   "
+      sql << "SELECT #{sql_select_jisseki}, issues.id as issue_id, '' as spent_on, '' as hours_est, SUM(hours) AS hours FROM time_entries  LEFT JOIN issues ON time_entries.issue_id = issues.id   "
       sql << "    LEFT JOIN       projects ON issues.project_id = projects.id "
       sql << "      WHERE 1=1"
       sql << "      AND (%s) " % @project.project_condition(Setting.display_subprojects_issues?) if @project
@@ -241,12 +245,19 @@ class EstimateTimelogController < ApplicationController
         sql << "     AND (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
         sql << "     AND (time_entries.user_id = '%s')" % [User.current.id] if params[:my_type]
       end
-      sql << "    group by #{sql_group_by_jisseki}, issues.id) jisseki "
-      sql << "ON (yotei.issue_id=jisseki.issue_id)  "
-      sql << "WHERE yotei.hours_est > 0 OR jisseki.hours > 0 "
+      sql << "    group by #{sql_group_by_jisseki}, issues.id "
+      if params[:est_type] == '1'
+        sql << "    ) yotei "
+        sql << "WHERE yotei.hours_est > 0 OR yotei.hours > 0 "
+        sql << "group by #{sql_group_by_all}"
+      elsif params[:est_type] == '2'
+        sql << "    ) jisseki "
+        sql << "ON (yotei.issue_id=jisseki.issue_id)  "
+        sql << "WHERE yotei.hours_est > 0 OR jisseki.hours > 0 "
+      end

       @hours = ActiveRecord::Base.connection.select_all(sql)
-      @hours = @hours.map{|i| i['done_ratio'] = i['done_ratio']+'%' if i.has_key? 'done_ratio'; i}
+      @hours = @hours.map{|i| i['done_ratio'] = i['done_ratio'].to_s+'%' if i.has_key? 'done_ratio'; i}
       @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
       @total_hours_est = @hours.inject(0) {|s,k| s = s + k['hours_est'].to_f}

@@ -320,7 +331,7 @@ class EstimateTimelogController < ApplicationController
         sort_init 'start_date', 'desc'
         sort_update 'start_date' => 'start_date',
             'user' => 'user_id',
-            'activity' => 'activity_id',
+            # 'activity' => "#{TimeEntry.table_name}.activity_id",
             'project' => "#{Project.table_name}.name",
             'issue' => 'issue_id',
             'estimated_hours' => 'estimated_hours'
@@ -337,7 +348,7 @@ class EstimateTimelogController < ApplicationController
             cond << ["#{Issue.table_name}.assigned_to_id = ?", User.current.id]
         end

-        cond << ['(start_date <= ?) AND (due_date   >= ? ) ', @to, @from]
+        cond << ['(start_date <= ?) AND (due_date   >= ?) ', @to, @from]

         respond_to do |format|
             format.html {
@@ -468,10 +479,10 @@ private
     end

     @from, @to = @to, @from if @from && @to && @from > @to
-    @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
-    @to   ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
+    @from ||= (Issue.minimum(:start_date, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
+    @to   ||= (Issue.maximum(:due_date, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)

-    if params[:est_type] == '1' || params[:est_flg] == "true"
+    if params[:est_type] == '1' || params[:est_flg] == "true" || params[:est_flg] == nil
       @est_flg = true
     elsif params[:est_type] == '2' || params[:est_flg] == "false"
       @est_flg = false
diff --git a/app/helpers/estimate_timelog_helper.rb b/app/helpers/estimate_timelog_helper.rb
index b11a4df..77e967f 100644
--- a/app/helpers/estimate_timelog_helper.rb
+++ b/app/helpers/estimate_timelog_helper.rb
@@ -55,7 +55,7 @@ module EstimateTimelogHelper
   	if value.to_s.empty?
   		data.select {|row| row[criteria].blank? }
     else
-    	data.select {|row| row[criteria] == value}
+    	data.select {|row| row[criteria].to_s == value}
     end
   end

diff --git a/app/views/estimate_timelog/_date_range.html.erb b/app/views/estimate_timelog/_date_range.html.erb
index bd2f6d9..64c381b 100644
--- a/app/views/estimate_timelog/_date_range.html.erb
+++ b/app/views/estimate_timelog/_date_range.html.erb
@@ -1,10 +1,15 @@
 <%= link_to(l(:et_label_redminedefault), '/time_entries') if User.current.allowed_to?(:view_time_entries, nil, :global => true) %>
+<script type="text/javascript">
+  $("#qury_form > form").submit(function() {
+      alert('submit!!');
+  });
+</script>
 <fieldset id="date-range" class="collapsible">
 <legend onclick="toggleFieldset(this);"><%= l(:label_date_range) %></legend>
 <div>
 <p>
 <%= label_tag "period_type_list", l(:description_date_range_list), :class => "hidden-for-sighted" %>
-<%= radio_button_tag 'period_type', '1', !@free_period, :onclick => raw('Form.Element.disable("from");Form.Element.disable("to");Form.Element.enable("period");'), :id => "period_type_list"%>
+<%= radio_button_tag 'period_type', '1', !@free_period, :onclick => raw("$('#from', '#to').attr('disabled', true);$('#period').removeAttr('disabled');"), :id => "period_type_list"%>
 <%= select_tag 'period', options_for_period_select(params[:period]),
                          :onchange => 'this.form.submit();',
                          :onfocus => raw("$('period_type_1').checked = true;"),
@@ -12,7 +17,7 @@
 </p>
 <p>
 <%= label_tag "period_type_interval", l(:description_date_range_interval), :class => "hidden-for-sighted" %>
-<%= radio_button_tag 'period_type', '2', @free_period, :onclick => raw("Form.Element.enable('from');Form.Element.enable('to');Form.Element.disable('period');"), :id => "period_type_interval" %>
+<%= radio_button_tag 'period_type', '2', @free_period, :onclick => raw("$('#from', '#to').removeAttr('disabled'); $('#period').attr('disabled', true);"), :id => "period_type_interval" %>
 <span onclick="$('period_type_2').checked = true;">
 <%= raw l(:label_date_from_to,
         :start => ((label_tag "from", l(:description_date_from), :class => "hidden-for-sighted") +
@@ -48,7 +53,7 @@
 </fieldset>

 <p class="buttons">
-  <%= link_to l(:button_apply), '#', :onlick => raw("$('query_form').submit()"), :class => 'icon icon-checked' %>
+<%= link_to l(:button_apply), '#', :onclick => raw("$('query_form').submit(); alert('ok'); return false;"), :class => 'icon icon-checked' %>
   <%= link_to l(:button_clear), {:controller => controller_name, :action => controller.action_name, :project_id => @project, :issue_id => @issue}, :class => 'icon icon-reload' %>
 </p>

diff --git a/app/views/estimate_timelog/_report_criteria.html.erb b/app/views/estimate_timelog/_report_criteria.html.erb
index 3f1f436..eaead89 100644
--- a/app/views/estimate_timelog/_report_criteria.html.erb
+++ b/app/views/estimate_timelog/_report_criteria.html.erb
@@ -2,7 +2,7 @@
 <% hours_for_value = select_hours(hours, criterias[level], value) -%>
 <% next if hours_for_value.empty? -%>
 <tr class="<%= cycle('odd', 'even') %> <%= 'last-level' unless criterias.length > level+1 %>">
-    <%= '<td></td>' * level %>
+    <%= raw '<td></td>' * level %>
     <% tmp_value = format_criteria_value(criterias[level], value) %>
     <% check_value = tmp_value.to_s.scan(/#([0-9]*):/) %>
     <% if check_value.length > 0 %>
@@ -10,7 +10,7 @@
     <% else %>
     <td><%= h(format_criteria_value(criterias[level], value)) %></td>
     <% end %>
-    <%= '<td></td>' * (criterias.length - level - 1) -%>
+    <%= raw '<td></td>' * (criterias.length - level - 1) -%>
     <% total = 0 -%>
     <% total_est = 0 -%>
     <% sum_est = sum_hours_est(select_hours(hours_for_value, @columns, '')); total_est += sum_est -%>
diff --git a/app/views/estimate_timelog/details.html.erb b/app/views/estimate_timelog/details.html.erb
index 54a451b..f752719 100644
--- a/app/views/estimate_timelog/details.html.erb
+++ b/app/views/estimate_timelog/details.html.erb
@@ -6,7 +6,8 @@

 <h2><%= l(:label_spent_time) %></h2>

-<% form_tag( :url => {}, :html => {:method => :get, :id => 'query_form'}, :method => :get, :update => 'content', :remote=>true ) do %>
+<%# form_remote_tag( :url => {}, :html => {:method => :get, :id => 'query_form'}, :method => :get, :update => 'content', :remote=>true ) do %>
+  <%= form_tag({:action => 'details'}, {:id => 'query_form', :update => 'content', :method => 'post', :remote=>'false'}) do %>
 <%# TOOD: remove the project_id and issue_id hidden fields, that information is
 already in the URI %>
 <%= hidden_field_tag('project_id', params[:project_id]) if @project %>
diff --git a/app/views/estimate_timelog/report.html.erb b/app/views/estimate_timelog/report.html.erb
index 5db4dc6..e1701e7 100644
--- a/app/views/estimate_timelog/report.html.erb
+++ b/app/views/estimate_timelog/report.html.erb
@@ -6,8 +6,7 @@

 <h2><%= l(:label_spent_time) %></h2>

-<%# = form_tag(:url => {}, :html => {:method => :get, :id => 'query_form'}, :method => :get, :update => 'content', :remote=>true) do %>
-  <%= form_tag({:action => 'report'}, {:id => 'query_form', :update => 'content', :method => 'get', :remote=>'true'}) do %>
+<%= form_tag({:action => 'report'}, {:id => 'query_form', :method => 'get'}) do %>
   <% @criterias.each do |criteria| %>
     <%= hidden_field_tag 'criterias[]', criteria, :id => nil %>
   <% end %>
@@ -18,14 +17,12 @@

   <p>
   <%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@combobox_criterias.keys - @criterias ).collect{|k| [l(@available_criterias[k][:label]), k]}),
-                                                          :onchange => "this.form.onsubmit();",
+                                                          :onchange => "this.form.submit();",
                                                           :style => 'width: 200px',
                                                           :id => nil,
                                                           :disabled => (@criterias.length >= 3)) %>
      <%= link_to l(:button_clear), {:url => {:project_id => @project, :period_type => params[:period_type], :period => params[:period], :from => @from, :to => @to, :columns => @columns},
                                            :method => :get,
-                                           :update => 'content',
-                                           :remote => true
                                           }, :class => 'icon icon-reload' %></p>
   <%= l(:et_label_tmpl) %>:
     <%= select_tag(
@@ -38,7 +35,7 @@
               [l(:et_label_tmpl_4), '4']
             ]
         ),
-        :onchange => "this.form.onsubmit();"
+        :onchange => "this.form.submit();"
     ) %>
 <% end %>

@@ -77,7 +74,7 @@
 <%= render :partial => 'report_criteria', :locals => {:criterias => @criterias, :hours => @hours, :level => 0} %>
   <tr class="total">
   <td><%= l(:label_total) %></td>
-  <%= '<td></td>' * (@criterias.size - 1) %>
+  <%= raw '<td></td>' * (@criterias.size - 1) %>
   <% total_est = 0 -%>
   <% total = 0 -%>
     <% sum_est = sum_hours_est(select_hours(@hours, @columns, '')); total_est += sum_est -%>
update README
fix readme
Merge branch 'for-rails3'