Class: Backend::CampaignsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/campaigns_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

#closeObject


61
62
63
64
65
66
67
68
# File 'app/controllers/backend/campaigns_controller.rb', line 61

def close
  return unless (@campaign = find_and_check)
  activity = Activity.find(params[:activity_id])
  raise 'Cannot close used activity' if activity.productions.of_campaign(@campaign).any?
  activity_budget = activity.budgets.find_by(campaign: @campaign)
  activity_budget.destroy if activity_budget
  redirect_to params[:redirect] || { action: :show, id: @campaign.id }
end

#currentObject


70
71
72
73
74
75
76
# File 'app/controllers/backend/campaigns_controller.rb', line 70

def current
  if current_campaign.blank?
    @current_campaign = Campaign.find_or_create_by!(harvest_year: Date.current.year)
    current_user.current_campaign = @current_campaign
  end
  redirect_to backend_campaign_path(current_campaign)
end

#openObject

List of productions for one campaign list(:activity_productions, conditions: “campaign = Campaign.find(params)n['(started_on, stopped_on) OVERLAPS (?, ?)', campaign.started_on, campaign.stopped_on]”.c, order: { started_on: :desc }) do |t|

t.column :name, url: true
# t.column :product_nature, url: true
t.column :state
t.column :started_on
t.column :stopped_on

end


54
55
56
57
58
59
# File 'app/controllers/backend/campaigns_controller.rb', line 54

def open
  return unless (@campaign = find_and_check)
  activity = Activity.find(params[:activity_id])
  activity.budgets.find_or_create_by!(campaign: @campaign)
  redirect_to params[:redirect] || { action: :show, id: @campaign.id }
end