Class: TenantsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TenantsController
- Defined in:
- app/controllers/tenants_controller.rb
Instance Method Summary collapse
- #billing_url ⇒ Object
- #create_or_update ⇒ Object
- #current ⇒ Object
- #index ⇒ Object
- #options ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from AuthentificationHelper
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#billing_url ⇒ Object
141 142 143 144 145 |
# File 'app/controllers/tenants_controller.rb', line 141 def billing_url render json: { url: current_tenant.billing_portal_url } end |
#create_or_update ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/tenants_controller.rb', line 34 def create_or_update tenant_id = params[:tenant_id] tenant_code = params[:tenant_code] || '' tenant_name = params[:tenant_name] duns_no = params[:duns_no] country_id = params[:country_id] bill_to_address_line1 = params[:bill_to_address_line1] bill_to_address_line2 = params[:bill_to_address_line2] bill_to_city = params[:bill_to_city] bill_to_province_id = params[:bill_to_province_id] bill_to_postal_code = params[:bill_to_postal_code] bill_to_phone_no = params[:bill_to_phone_no] bill_to_fax_no = params[:bill_to_fax_no] bill_to_email = params[:bill_to_email] deliver_to_address_line1 = params[:deliver_to_address_line1] deliver_to_address_line2 = params[:deliver_to_address_line2] deliver_to_city = params[:deliver_to_city] deliver_to_province_id = params[:deliver_to_province_id] deliver_to_postal_code = params[:deliver_to_postal_code] deliver_to_phone_no = params[:deliver_to_phone_no] deliver_to_fax_no = params[:deliver_to_fax_no] deliver_to_email = params[:deliver_to_email] website_url = params[:website_url] logo_path = params[:logo_path] gst_no = params[:gst_no] pst_no = params[:pst_no] tax_exemption_no = params[:tax_exemption_no] is_demo = params[:is_demo] is_master = params[:is_master] active = params[:active] user = params[:user] || 'Admin' result = Tenant.create_or_update_procedure( tenant_id: tenant_id, tenant_code: tenant_code, tenant_name: tenant_name, duns_no: duns_no, country_id: country_id, bill_to_address_line1: bill_to_address_line1, bill_to_address_line2: bill_to_address_line2, bill_to_city: bill_to_city, bill_to_province_id: bill_to_province_id, bill_to_postal_code: bill_to_postal_code, bill_to_phone_no: bill_to_phone_no, bill_to_fax_no: bill_to_fax_no, bill_to_email: bill_to_email, deliver_to_address_line1: deliver_to_address_line1, deliver_to_address_line2: deliver_to_address_line2, deliver_to_city: deliver_to_city, deliver_to_province_id: deliver_to_province_id, deliver_to_postal_code: deliver_to_postal_code, deliver_to_phone_no: deliver_to_phone_no, deliver_to_fax_no: deliver_to_fax_no, deliver_to_email: deliver_to_email, website_url: website_url, logo_path: logo_path, gst_no: gst_no, pst_no: pst_no, tax_exemption_no: tax_exemption_no, is_demo: is_demo, is_master: is_master, active: active, user: user ) render json: { message: 'Tenant inserted/updated successfully', redirect_to: "/app/settings/tenants/#{result['tenant_id']}/companies" } end |
#current ⇒ Object
135 136 137 138 139 |
# File 'app/controllers/tenants_controller.rb', line 135 def current render json: { tenant: current_tenant.as_json(include: %i[bill_to_province deliver_to_province]) } end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/tenants_controller.rb', line 7 def index display_length = params[:limit] || 10 search_value = params[:query] || '' display_start_from_page_no = params[:offset] || 1 order_by = params[:order_by] || 'tenant_id' order_direction = params[:order_direction] || 'DESC' grouping = "#{order_by} #{order_direction}" result = Tenant.where_procedure( display_length: display_length, search_value: search_value, display_start_from_page_no: display_start_from_page_no, grouping: grouping ) render json: { data: result[:data], metadata: result[:metadata] } end |
#options ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/tenants_controller.rb', line 102 def query = params[:query] || '' = Tenant .has_companies .select(:tenant_name, :tenant_id) .where('tenant_name LIKE :query', query: "%#{query}%") .order(:tenant_name) # .limit(10) render json: { data: } end |
#show ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/tenants_controller.rb', line 28 def show tenant_id = params[:id] result = Tenant.find_procedure(tenant_id) render json: result end |
#update ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/tenants_controller.rb', line 116 def update tenant = current_tenant tenant.assign_attributes(tenant_params) raise ActiveRecord::RecordInvalid.new(tenant) unless tenant.valid? tenant.save! render json: { message: I18n.t('messages.tenant_updated'), redirect_to: '/app/settings/account' } rescue ActiveRecord::RecordInvalid => e render json: { errors: e.record.errors, message: e.record.errors..join(', '), redirect_to: params[:form_url] }, status: :bad_request end |