Class: Backend::SubscriptionsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Class Method Summary collapse

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?

Class Method Details

.subscriptions_conditionsObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/backend/subscriptions_controller.rb', line 35

def self.subscriptions_conditions
  code = ''
  # COALESCE(#{Sale.table_name}.state NOT INsale_id, 0) NOT IN (SELECT id FROM #{Sale.table_name} WHERE state NOT IN ('invoice', 'order'))
  code << "conditions = ['1=1']\n"
  code << "unless params[:nature_id].to_i.zero?\n"
  code << "  conditions[0] += \" AND #{Subscription.table_name}.nature_id = ?\"\n"
  code << "  conditions << params[:nature_id].to_i\n"
  code << "end\n"
  code << "if params[:subscribed_on].to_s =~ /\A\d\d\d\d\-\d\d\-\d\d\z/.nil?\n"
  code << "  conditions[0] += \" AND ? BETWEEN #{Subscription.table_name}.started_on AND #{Subscription.table_name}.stopped_on\"\n"
  code << "  conditions << params[:subscribed_on]\n"
  code << "end\n"
  code << "conditions\n"
  code.c
end

Instance Method Details

#renewObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/backend/subscriptions_controller.rb', line 67

def renew
  @subscription = find_and_check
  unless @subscription.renewable?
    notify_error :subscription_is_not_renewable
    redirect_to params[:redirect] || { action: :show, id: @subscription.id }
    return
  end
  unless current_user.can?(:write, :sales)
    notify_error :access_denied
    redirect_to params[:redirect] || { action: :show, id: @subscription.id }
    return
  end
  redirect_to(@subscription.renew_attributes.merge(controller: :sales, action: :new))
end

#suspendObject


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

def suspend
  @subscription = find_and_check
  @subscription.suspend
  redirect_to params[:redirect] || { action: :show, id: @subscription.id }
end

#takeoverObject


88
89
90
91
92
# File 'app/controllers/backend/subscriptions_controller.rb', line 88

def takeover
  @subscription = find_and_check
  @subscription.takeover
  redirect_to params[:redirect] || { action: :show, id: @subscription.id }
end