Class: Backend::AffairsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/affairs_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Instance Method Details

#attachObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/backend/affairs_controller.rb', line 44

def attach
  return unless @affair = find_and_check
  if deal = begin
              params[:deal_type].camelcase.constantize.find_by(id: params[:deal_id])
            rescue
              nil
            end
    deal.deal_with! @affair
    # @affair.attach(deal)
    redirect_to params[:redirect] || { controller: deal.class.name.tableize, action: :show, id: deal.id }
  else
    notify_error(:cannot_find_deal_to_attach)
    redirect_to_best_page
  end
end

#detachObject


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/backend/affairs_controller.rb', line 60

def detach
  return unless @affair = find_and_check
  if deal = begin
              params[:deal_type].camelcase.constantize.find_by(id: params[:deal_id])
            rescue
              nil
            end
    deal.undeal! @affair
    # @affair.detach(deal)
    redirect_to params[:redirect] || { controller: deal.class.name.tableize, action: :show, id: deal.id }
  else
    notify_error(:cannot_find_deal_to_detach)
    redirect_to_best_page
  end
end

#detach_gapsObject


76
77
78
79
80
# File 'app/controllers/backend/affairs_controller.rb', line 76

def detach_gaps
  return unless @affair = find_and_check
  @affair.gaps.each { |g| g.undeal! @affair }
  redirect_to params[:redirect] || redirect_to_best_page
end

#finishObject


82
83
84
85
86
# File 'app/controllers/backend/affairs_controller.rb', line 82

def finish
  return unless @affair = find_and_check
  notify_error :cannot_finish_affair unless @affair.finish
  redirect_to_best_page
end

#selectObject


37
38
39
40
41
42
# File 'app/controllers/backend/affairs_controller.rb', line 37

def select
  return unless @affair = find_and_check
  @deal_model = params[:deal_type].camelcase.constantize
  @third = Entity.find_by(id: params[:third_id]) if params[:third_id]
  @third ||= @affair.third
end