-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # app/app/models/payroll_account.rb # app/db/schema.rb # docs/app/rendered/database-schema.pdf
- Loading branch information
1 parent
cf539d0
commit f3469b0
Showing
6 changed files
with
76 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,19 @@ | ||
class PayrollAccount < ApplicationRecord | ||
def self.sti_name | ||
# "PayrollAccount::Pinwheel" => "pinwheel" | ||
name.demodulize.downcase | ||
end | ||
|
||
def self.sti_class_for(type_name) | ||
# "pinwheel" => PayrollAccount::Pinwheel | ||
PayrollAccount.const_get(type_name.capitalize) | ||
end | ||
|
||
belongs_to :cbv_flow | ||
|
||
after_update_commit { | ||
I18n.with_locale(cbv_flow.cbv_flow_invitation.language) do | ||
broadcast_replace target: self, partial: "cbv/synchronizations/indicators", locals: { pinwheel_account: self } | ||
end | ||
} | ||
|
||
EVENTS_MAP = { | ||
"employment.added" => :employment_synced_at, | ||
"income.added" => :income_synced_at, | ||
"identity.added" => :identity_synced_at, | ||
"paystubs.fully_synced" => :paystubs_synced_at | ||
} | ||
|
||
EVENTS_ERRORS_MAP = { | ||
"employment.added" => :employment_errored_at, | ||
"income.added" => :income_errored_at, | ||
"identity.added" => :identity_errored_at, | ||
"paystubs.fully_synced" => :paystubs_errored_at | ||
} | ||
|
||
def has_fully_synced? | ||
(supported_jobs.exclude?("paystubs") || paystubs_synced_at.present?) && | ||
(supported_jobs.exclude?("employment") || employment_synced_at.present?) && | ||
(supported_jobs.exclude?("income") || income_synced_at.present?) && | ||
(supported_jobs.exclude?("identity") || identity_synced_at.present?) | ||
end | ||
|
||
def job_succeeded?(job) | ||
error_column, sync_column = event_columns_for(job) | ||
return nil unless error_column.present? | ||
|
||
supported_jobs.include?(job) && send(sync_column).present? && send(error_column).blank? | ||
end | ||
|
||
def synchronization_status(job) | ||
error_column, sync_column = event_columns_for(job) | ||
return nil unless error_column.present? | ||
|
||
if supported_jobs.exclude?(job) | ||
:unsupported | ||
elsif job_succeeded?(job) | ||
:succeeded | ||
elsif supported_jobs.include?(job) && (send(sync_column).blank? && send(error_column).blank?) | ||
:in_progress | ||
elsif supported_jobs.include?(job) && (send(error_column).present?) | ||
:failed | ||
end | ||
end | ||
|
||
def has_required_data? | ||
job_succeeded?("paystubs") | ||
end | ||
|
||
private | ||
|
||
def event_columns_for(job) | ||
error_column = EVENTS_ERRORS_MAP.select { |key| key.start_with? job }&.values.last | ||
sync_column = EVENTS_MAP.select { |key| key.start_with? job }&.values.last | ||
|
||
[ error_column, sync_column ] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class PayrollAccount::Pinwheel < PayrollAccount | ||
EVENTS_MAP = { | ||
"employment.added" => :employment_synced_at, | ||
"income.added" => :income_synced_at, | ||
"identity.added" => :identity_synced_at, | ||
"paystubs.fully_synced" => :paystubs_synced_at | ||
} | ||
|
||
EVENTS_ERRORS_MAP = { | ||
"employment.added" => :employment_errored_at, | ||
"income.added" => :income_errored_at, | ||
"identity.added" => :identity_errored_at, | ||
"paystubs.fully_synced" => :paystubs_errored_at | ||
} | ||
|
||
def has_fully_synced? | ||
(supported_jobs.exclude?("paystubs") || paystubs_synced_at.present?) && | ||
(supported_jobs.exclude?("employment") || employment_synced_at.present?) && | ||
(supported_jobs.exclude?("income") || income_synced_at.present?) && | ||
(supported_jobs.exclude?("identity") || identity_synced_at.present?) | ||
end | ||
|
||
def job_succeeded?(job) | ||
error_column, sync_column = event_columns_for(job) | ||
return nil unless error_column.present? | ||
|
||
supported_jobs.include?(job) && send(sync_column).present? && send(error_column).blank? | ||
end | ||
|
||
def synchronization_status(job) | ||
error_column, sync_column = event_columns_for(job) | ||
return nil unless error_column.present? | ||
|
||
if supported_jobs.exclude?(job) | ||
:unsupported | ||
elsif job_succeeded?(job) | ||
:succeeded | ||
elsif supported_jobs.include?(job) && (send(sync_column).blank? && send(error_column).blank?) | ||
:in_progress | ||
elsif supported_jobs.include?(job) && (send(error_column).present?) | ||
:failed | ||
end | ||
end | ||
|
||
def has_required_data? | ||
job_succeeded?("paystubs") | ||
end | ||
|
||
private | ||
|
||
def event_columns_for(job) | ||
error_column = EVENTS_ERRORS_MAP.select { |key| key.start_with? job }&.values.last | ||
sync_column = EVENTS_MAP.select { |key| key.start_with? job }&.values.last | ||
|
||
[ error_column, sync_column ] | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
app/db/migrate/20250225204333_add_type_to_payroll_accounts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddTypeToPayrollAccounts < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :pinwheel_accounts, :type, :string, null: false, default: "pinwheel" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.