diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index 7bb2164..7c26e4b 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -27,6 +27,8 @@ class TimeEntry < ActiveRecord::Base
   belongs_to :author, :class_name => 'User'
   belongs_to :activity, :class_name => 'TimeEntryActivity'
 
+  attr_accessor :remaining_time_action, :remaining_time_hours
+
   acts_as_customizable
   acts_as_event(
     :title =>
@@ -51,6 +53,8 @@ class TimeEntry < ActiveRecord::Base
   validates_presence_of :issue_id, :if => lambda {Setting.timelog_required_fields.include?('issue_id')}
   validates_presence_of :comments, :if => lambda {Setting.timelog_required_fields.include?('comments')}
   validates_numericality_of :hours, :allow_nil => true, :message => :invalid
+  validates :remaining_time_action,  :inclusion => { :in => ['auto', 'set', 'nothing'] }, :allow_nil => true
+  validates :remaining_time_hours, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true, :message => :invalid}
   validates_length_of :comments, :maximum => 1024, :allow_nil => true
   validates :spent_on, :date => true
   before_validation :set_project_if_nil
@@ -58,6 +62,8 @@ class TimeEntry < ActiveRecord::Base
   before_validation :set_author_if_nil
   validate :validate_time_entry
 
+  after_save :update_issue_remaining_hours
+
   scope :visible, (lambda do |*args|
     joins(:project).
     where(TimeEntry.visible_condition(args.shift || User.current, *args))
@@ -76,7 +82,8 @@ class TimeEntry < ActiveRecord::Base
 
   safe_attributes 'user_id', 'hours', 'comments', 'project_id',
                   'issue_id', 'activity_id', 'spent_on',
-                  'custom_field_values', 'custom_fields'
+                  'custom_field_values', 'custom_fields',
+                  'remaining_time_action', 'remaining_time_hours'
 
   # Returns a SQL conditions string used to find all time entries visible by the specified user
   def self.visible_condition(user, options={})
@@ -179,6 +186,7 @@ class TimeEntry < ActiveRecord::Base
     end
     errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
     errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
+    errors.add :remaining_time_hours, :invalid if (remaining_time_action == 'set' && remaining_time_hours.blank?)
     if spent_on && spent_on_changed? && user
       errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today)
     end
@@ -223,6 +231,34 @@ class TimeEntry < ActiveRecord::Base
     editable_custom_field_values(user).map(&:custom_field).uniq
   end
 
+  def remaining_time_action
+    @remaining_time_action
+  end
+
+  def remaining_time_hours
+    @remaining_time_hours
+  end
+
+  def update_issue_remaining_hours
+    issue = self.issue
+    return unless issue
+
+    h = (remaining_time_hours.is_a?(String)) ? remaining_time_hours.to_hours : remaining_time_hours
+
+    case remaining_time_action
+    when "auto"
+      new_remaining_hours = issue.remaining_hours - self.hours unless issue.remaining_hours.nil?
+    when "set"
+      new_remaining_hours = h
+    when "nothing"
+      return
+    end
+
+    issue.init_journal(User.current)
+    issue.remaining_hours = new_remaining_hours
+    issue.save
+  end
+
   def visible_custom_field_values(user = nil)
     user ||= User.current
     custom_field_values.select do |value|
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 219122d..a3096ac 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -24,6 +24,9 @@
         <% @time_entry.editable_custom_field_values.each do |value| %>
           <p><%= custom_field_tag_with_label :time_entry, value %></p>
         <% end %>
+        <p id="issue_remaining_time">
+          <%= render :partial => 'timelog/remaining_time', :locals => { :issue => @issue } %>
+        </p>
         <% end %>
     </fieldset>
     <% end %>
diff --git a/app/views/timelog/_form.html.erb b/app/views/timelog/_form.html.erb
index 3a0543e..7c84a39 100644
--- a/app/views/timelog/_form.html.erb
+++ b/app/views/timelog/_form.html.erb
@@ -35,6 +35,9 @@
       <%= wikitoolbar_for "time_entry_custom_field_values_#{value.custom_field_id}", preview_issue_path(:project_id => @project) %>
     <% end %>
   <% end %>
+  <p id="issue_remaining_time">
+    <%= render :partial => 'remaining_time', :locals => { :issue => @time_entry.issue } %>
+  </p>
   <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
 </div>
 
diff --git a/app/views/timelog/_remaining_time.html.erb b/app/views/timelog/_remaining_time.html.erb
new file mode 100644
index 0000000..493d7e0
--- /dev/null
+++ b/app/views/timelog/_remaining_time.html.erb
@@ -0,0 +1,42 @@
+<% return if (!issue) || (!issue.safe_attribute? 'remaining_hours') %>
+
+<label for=""><%= l(:label_issue_remaining_hours) %></label>
+<span class="check_box_group">
+  <% if @time_entry.new_record? %>
+    <label>
+      <%= radio_button 'time_entry', 'remaining_time_action', 'auto' %> <%= l(:label_remaining_time_action_auto) %>
+    </label>
+  <% end %>
+  <label class="hours">
+    <%= radio_button 'time_entry', 'remaining_time_action', "set" %> <%= l(:label_remaining_time_action_set) %>
+  </label>
+  <%= text_field 'time_entry', "remaining_time_hours", :size => "3", :disabled => true %> <%= l(:field_hours) %>
+  <label>
+  <%= radio_button 'time_entry', 'remaining_time_action', 'nothing' %> <%= l(:label_remaining_time_action_nothing) %>
+  </label>
+</span>
+
+<%= javascript_tag do %>
+$(document).ready(function(){
+  var block = $("p#issue_remaining_time");
+
+  if (block.find('#time_entry_remaining_time_action_set').is(':checked')) {
+    block.find('input#time_entry_remaining_time_hours').prop("disabled", false)
+  }
+
+  block.find("input[type=radio]").change(function(e){
+    block.find('input#time_entry_remaining_time_hours').prop("disabled", true)
+    if ($(e.target).val() === 'set') {
+      block.find('input#time_entry_remaining_time_hours').prop("disabled", false).focus()
+    }
+  })
+});
+
+<% unless params[:time_entry].present? %>
+  <% if @time_entry.new_record? %>
+    $('#time_entry_remaining_time_action_auto').prop('checked', true);
+  <% else %>
+    $('#time_entry_remaining_time_action_nothing').prop('checked', true);
+  <% end %>
+<% end %>
+<% end %>
diff --git a/app/views/timelog/new.js.erb b/app/views/timelog/new.js.erb
index 70b731e..4ded87f 100644
--- a/app/views/timelog/new.js.erb
+++ b/app/views/timelog/new.js.erb
@@ -1,2 +1,2 @@
-$('#time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), default_activity(@time_entry)) %>');
+$('#new_time_entry p#issue_remaining_time').html('<%= escape_javascript render :partial => "remaining_time", :locals => { :issue => @time_entry.issue } %>');
 $('#time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>');
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2b70319..0766f92 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1141,6 +1141,10 @@ en:
   label_default_query: Default query
   label_edited: Edited
   label_time_by_author: "%{time} by %{author}"
+  label_issue_remaining_hours: Issue remaining time
+  label_remaining_time_action_auto: Adjust automatically
+  label_remaining_time_action_set: Set to
+  label_remaining_time_action_nothing: Do not update remaining time
 
   button_login: Login
   button_submit: Submit
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index b8212c0..ac874a0 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -904,6 +904,7 @@ label.no-css {
   width:auto;
 }
 input#time_entry_comments { width: 90%;}
+p#issue_remaining_time label.hours { display: inline-block; }
 input#months { width: 46px; }
 
 .jstBlock .jstTabs, .jstBlock .wiki-preview { width: 99%; }
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index f3ef5cb..0c5dd6e 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -69,6 +69,8 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_select 'input[name=?][type=hidden]', 'issue_id'
     assert_select 'a[href=?]', '/issues/2', :text => /Feature request #2/
     assert_select 'select[name=?]', 'time_entry[project_id]', 0
+    assert_select 'input[type=radio][name=?]', 'time_entry[remaining_time_action]', 3
+    assert_select 'input[type=text][name=?]', 'time_entry[remaining_time_hours]', 1
   end
 
   def test_new_without_project_should_prefill_the_form
@@ -152,6 +154,19 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_select 'select[name=?]', 'time_entry[user_id]', 0
   end
 
+  def test_new_on_issue_with_remaining_time_disabled_should_not_show_the_update_issue_remaining_time_section
+    tracker = Tracker.find(2)
+    tracker.core_fields = tracker.core_fields - %w(remaining_hours)
+    tracker.save!
+
+    @request.session[:user_id] = 3
+    get :new, :issue_id => 2
+    assert_response :success
+    assert_template 'new'
+    assert_select 'input[type=radio][name=?]', 'time_entry[remaining_time_action]', 0
+    assert_select 'input[type=text][name=?]', 'time_entry[remaining_time_hours]', 0
+  end
+
   def test_post_new_as_js_should_update_activity_options
     @request.session[:user_id] = 3
     post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'}
@@ -172,6 +187,16 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_select 'a.user.active', :text => 'Redmine Admin'
   end
 
+  def test_get_should_not_show_the_adjust_automatically_option_in_issue_remaining_time_section
+    @request.session[:user_id] = 2
+    get :edit, :id => 2, :project_id => nil
+    assert_response :success
+    assert_template 'edit'
+    assert_select 'input[type=radio][name=?]', 'time_entry[remaining_time_action]', 2
+    assert_select 'input[type=text][name=?]', 'time_entry[remaining_time_hours]', 1
+    assert_select 'input[type=radio][id=?]', 'time_entry_remaining_time_action_auto]', 0
+  end
+
   def test_get_edit_with_an_existing_time_entry_with_inactive_activity
     te = TimeEntry.find(1)
     te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb
index 03d5c06..a7d7070 100644
--- a/test/integration/api_test/issues_test.rb
+++ b/test/integration/api_test/issues_test.rb
@@ -461,7 +461,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     parent.update_columns :estimated_hours => 2.0
     child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0, :remaining_hours => 1.0)
     TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
-                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id, :remaining_time_action => 'nothing')
     get '/issues/3.xml'
 
     assert_equal 'application/xml', response.media_type
@@ -515,7 +515,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     parent.update_columns :estimated_hours => 2.0
     child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0, :remaining_hours => 1.0)
     TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
-                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id, :remaining_time_action => 'nothing')
     get '/issues/3.json'
 
     assert_equal 'application/json', response.media_type
diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb
index 8722a86..a7ec7cf 100644
--- a/test/unit/time_entry_test.rb
+++ b/test/unit/time_entry_test.rb
@@ -297,4 +297,58 @@ class TimeEntryTest < ActiveSupport::TestCase
 
     assert_equal [2], time_entry.assignable_users.map(&:id)
   end
+
+  def test_time_entry_decrease_issue_remaining_time_with_logged_time
+    issue = Issue.find(1)
+    issue.update_attribute(:remaining_hours, 3)
+
+    te = TimeEntry.new(:spent_on => '2010-01-01', :hours => 1, :issue => issue,
+                        :user => User.find(1), :activity => TimeEntryActivity.first,
+                        :remaining_time_action => "auto")
+
+    assert te.save
+    assert_equal 2, issue.remaining_hours
+  end
+
+  def test_time_entry_set_issue_remaining_time
+    issue = Issue.find(1)
+    issue.update_attribute(:remaining_hours, 3)
+
+    te = TimeEntry.new(:spent_on => '2010-01-01', :hours => 1, :issue => issue,
+                        :user => User.find(1), :activity => TimeEntryActivity.first,
+                        :remaining_time_action => "set", :remaining_time_hours => 4)
+
+    assert te.save
+    assert_equal 4, issue.remaining_hours
+  end
+
+  def test_time_entry_do_not_update_issue_remaining_time
+    issue = Issue.find(1)
+    issue.update_attribute(:remaining_hours, 3)
+
+    te = TimeEntry.new(:spent_on => '2010-01-01', :hours => 1, :issue => issue,
+                        :user => User.find(1), :activity => TimeEntryActivity.first,
+                        :remaining_time_action => "nothing", :remaining_time_hours => 4)
+    assert te.save
+    assert_equal 3, issue.remaining_hours
+  end
+
+  def test_time_entry_do_not_decrease_issue_remaining_time_when_issue_remaining_time_is_nil
+    issue = Issue.find(1)
+    issue.update_attribute(:remaining_hours, '')
+
+    te = TimeEntry.new(:spent_on => '2010-01-01', :hours => 1, :issue => issue,
+                        :user => User.find(1), :activity => TimeEntryActivity.first,
+                        :remaining_time_action => "auto", :remaining_time_hours => 4)
+    assert te.save
+    assert_nil issue.remaining_hours
+  end
+
+  def test_validate_time_entry_remaining_time_action
+    te = TimeEntry.new(:spent_on => '2010-01-01', :hours => 1, :issue => Issue.find(1),
+                        :user => User.find(1), :activity => TimeEntryActivity.first,
+                        :remaining_time_action => "test", :remaining_time_hours => 'one')
+    assert !te.valid?
+    assert_equal 2, te.errors.count
+  end
 end
