78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/controllers/kaui/accounts_controller.rb', line 78
def show
cached_options_for_klient = options_for_klient
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), true, true, cached_options_for_klient)
fetch_children = promise { @account.children(false, false, 'NONE',cached_options_for_klient)}
fetch_parent = promise (!@account.parent_account_id.nil?){ Kaui::Account::find_by_id(@account.parent_account_id,false,false,cached_options_for_klient)}
fetch_overdue_state = promise { @account.overdue(cached_options_for_klient) }
fetch_account_tags = promise { @account.tags(false, 'NONE', cached_options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b } }
fetch_account_fields = promise { @account.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } }
fetch_account_emails = promise { Kaui::AccountEmail.find_all_sorted_by_account_id(@account.account_id, 'NONE', cached_options_for_klient) }
fetch_payments = promise { @account.payments(cached_options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) } }
fetch_payment_methods = promise(false) { Kaui::PaymentMethod.find_all_by_account_id(@account.account_id, false, cached_options_for_klient) }
is_email_notifications_plugin_available = Kenui::EmailNotificationService.email_notification_plugin_available?(cached_options_for_klient).first
fetch_email_notification_configuration = promise(is_email_notifications_plugin_available) do
Kenui::EmailNotificationService.get_configuration_per_account(params.require(:account_id),cached_options_for_klient)
end.then do |configuration|
if configuration.first.is_a?(FalseClass)
Rails.logger.warn(configuration[1])
configuration = []
end
configuration
end
fetch_payment_methods_with_details = fetch_payment_methods.then do |pms|
ops = []
pms.each do |pm|
ops << promise(false) {
begin
Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, cached_options_for_klient)
rescue => e
Rails.logger.warn(e)
nil
end
}
end
ops
end
fetch_available_tags = promise { Kaui::TagDefinition.all_for_account(cached_options_for_klient) }
@overdue_state = wait(fetch_overdue_state)
@tags = wait(fetch_account_tags)
@custom_fields = wait(fetch_account_fields)
@account_emails = wait(fetch_account_emails)
wait(fetch_payment_methods)
@payment_methods = wait(fetch_payment_methods_with_details).map { |pm_f| pm_f.execute }.map { |pm_f| wait(pm_f) }.reject { |pm| pm.nil? }
@available_tags = wait(fetch_available_tags)
@children = wait(fetch_children)
@account_parent = @account.parent_account_id.nil? ? nil : wait(fetch_parent)
@email_notification_configuration = wait(fetch_email_notification_configuration) if is_email_notifications_plugin_available
@last_transaction_by_payment_method_id = {}
wait(fetch_payments).each do |payment|
transaction = payment.transactions.last
transaction_date = Date.parse(transaction.effective_date)
last_seen_transaction_date = @last_transaction_by_payment_method_id[payment.payment_method_id]
if last_seen_transaction_date.nil? || Date.parse(last_seen_transaction_date.effective_date) < transaction_date
@last_transaction_by_payment_method_id[payment.payment_method_id] = transaction
end
end
params.permit!
end
|