@@ -26,6 +26,19 @@ class Company < ApplicationRecord
2626 self . const_set ( "ACCESS_ROLE_#{ access_role . upcase } " , access_role )
2727 end
2828
29+ ADMIN_CHECKLIST_ITEMS = [
30+ { key : "add_company_details" , title : "Add company details" , description : "Add your company name and basic information" } ,
31+ { key : "add_bank_account" , title : "Add bank account" , description : "Connect your bank account to enable payments" } ,
32+ { key : "invite_contractor" , title : "Invite a contractor" , description : "Add your first team member" } ,
33+ { key : "send_first_payment" , title : "Send your first payment" , description : "Process your first contractor payment" }
34+ ] . freeze
35+
36+ WORKER_CHECKLIST_ITEMS = [
37+ { key : "fill_tax_information" , title : "Fill tax information" , description : "Complete your tax details" } ,
38+ { key : "add_payout_information" , title : "Add payout information" , description : "Set up your payment method" } ,
39+ { key : "sign_contract" , title : "Sign contract" , description : "Review and sign your contractor agreement" }
40+ ] . freeze
41+
2942 has_many :company_administrators
3043 has_many :administrators , through : :company_administrators , source : :user
3144 has_many :company_lawyers
@@ -98,7 +111,6 @@ def active
98111 after_create_commit :create_balance!
99112 after_update_commit :update_convertible_implied_shares , if : :saved_change_to_fully_diluted_shares?
100113
101-
102114 accepts_nested_attributes_for :expense_categories
103115
104116 delegate :stripe_setup_intent , :bank_account_last_four , :microdeposit_verification_required? ,
@@ -135,7 +147,7 @@ def has_sufficient_balance?(usd_amount)
135147 account_balance >= ( is_trusted? ? 0 : usd_amount )
136148 end
137149
138- def pending_invoice_cash_amount_in_cents = invoices . pending . sum ( :cash_amount_in_cents )
150+ def pending_invoice_cash_amount_in_cents = invoices . alive . pending . sum ( :cash_amount_in_cents )
139151
140152 def create_stripe_setup_intent
141153 Stripe ::SetupIntent . create ( {
@@ -190,6 +202,28 @@ def json_flag?(flag)
190202 json_data &.dig ( "flags" ) &.include? ( flag )
191203 end
192204
205+ def checklist_items ( user )
206+ case user
207+ when CompanyAdministrator
208+ ADMIN_CHECKLIST_ITEMS . map do |item |
209+ item . merge ( completed : checklist_item_completed? ( item [ :key ] , user ) )
210+ end
211+ when CompanyWorker
212+ WORKER_CHECKLIST_ITEMS . map do |item |
213+ item . merge ( completed : checklist_item_completed? ( item [ :key ] , user ) )
214+ end
215+ else
216+ [ ]
217+ end
218+ end
219+
220+ def checklist_completion_percentage ( user )
221+ completed_count = checklist_items ( user ) . count { |item | item [ :completed ] }
222+ return 0 if checklist_items ( user ) . empty?
223+
224+ ( completed_count . to_f / checklist_items ( user ) . size * 100 ) . round
225+ end
226+
193227 private
194228 def update_convertible_implied_shares
195229 convertible_investments . each do |investment |
@@ -211,4 +245,25 @@ def fetch_or_create_stripe_customer_id!
211245 update! ( stripe_customer_id : stripe_customer . id )
212246 stripe_customer_id
213247 end
248+
249+ def checklist_item_completed? ( key , user )
250+ case key
251+ when "add_company_details"
252+ name . present?
253+ when "add_bank_account"
254+ bank_account_ready?
255+ when "invite_contractor"
256+ company_workers . active . exists?
257+ when "send_first_payment"
258+ invoices . where ( status : Invoice ::PAID_OR_PAYING_STATES ) . exists?
259+ when "fill_tax_information"
260+ user . user . compliance_info &.tax_information_confirmed_at . present?
261+ when "add_payout_information"
262+ user . user . bank_account . present?
263+ when "sign_contract"
264+ user . contract_signed?
265+ else
266+ false
267+ end
268+ end
214269end
0 commit comments