Class: Tenant
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Tenant
- Includes:
- TenantBilling, TenantProcedures
- Defined in:
- app/models/tenant.rb
Constant Summary
Constants included from TenantProcedures
Constants included from TenantBilling
TenantBilling::BASE_FEE_PRICE_ID, TenantBilling::MANAGED_COMPANIES_PRICE_ID, TenantBilling::MANAGED_EMPLOYEES_PRICE_ID
Class Method Summary collapse
Instance Method Summary collapse
- #create_main_company(employer_cnsst_percentage: 0, employer_cnt_percentage: 0) ⇒ Object
- #create_placeholder_company(email:) ⇒ Object
-
#onboarded? ⇒ Boolean
validate :email_not_used_by_company_or_erp_user, on: :check_email_and_phone validate :phone_not_used_by_company_or_erp_user, on: :check_email_and_phone.
Methods included from TenantBilling
#billing_portal_url, #checkout_session_url, #due_invoices, #find_or_create_stripe_customer, #redirect_to_stripe_url, #should_checkout?, #should_manage?
Methods inherited from ApplicationRecord
define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection
Class Method Details
.has_companies(active: true) ⇒ Object
8 9 10 |
# File 'app/models/tenant.rb', line 8 def has_companies(active: true) joins(:companies).where(companies: { active: active }).distinct end |
Instance Method Details
#create_main_company(employer_cnsst_percentage: 0, employer_cnt_percentage: 0) ⇒ Object
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 |
# File 'app/models/tenant.rb', line 45 def create_main_company( employer_cnsst_percentage: 0, employer_cnt_percentage: 0 ) companies.new( company_code: SecureRandom.uuid, company_name_e: tenant_name, company_name_f: tenant_name, registered_in_country_id: country_id, address_line1: bill_to_address_line1, address_line2: bill_to_address_line2, city: bill_to_city, province_id: bill_to_province_id, postal_code: bill_to_postal_code, phone_no: bill_to_phone_no, fax_no: bill_to_fax_no, email: bill_to_email, ship_address_line1: deliver_to_address_line1, ship_address_line2: deliver_to_address_line2, ship_city: deliver_to_city, ship_province_id: deliver_to_province_id, ship_postal_code: deliver_to_postal_code, ship_phone_no: deliver_to_phone_no, ship_fax_no: deliver_to_fax_no, ship_email: deliver_to_email, duns_no: duns_no, employer_cnsst_percentage: employer_cnsst_percentage, employer_cnt_percentage: employer_cnt_percentage, active: true ).write_procedure end |
#create_placeholder_company(email:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/tenant.rb', line 34 def create_placeholder_company(email:) company = companies.new({ company_code: SecureRandom.uuid, active: true, email: email, ship_email: email }) company.write_procedure(validate: false) company end |
#onboarded? ⇒ Boolean
validate :email_not_used_by_company_or_erp_user, on: :check_email_and_phone validate :phone_not_used_by_company_or_erp_user, on: :check_email_and_phone
30 31 32 |
# File 'app/models/tenant.rb', line 30 def onboarded? tenant_name.present? end |