Skip to content

Commit

Permalink
Merge pull request #432 from tungleduyxyz/technical-support-182
Browse files Browse the repository at this point in the history
Update table headers
  • Loading branch information
pierre authored Dec 23, 2024
2 parents 9ab916e + cad67a6 commit 1548640
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/views/kaui/accounts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#accounts-table td, #accounts-table tr {
white-space: nowrap;
}
.custom-checkbox {
pointer-events: none;
}
</style>

<%= javascript_tag do %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/kaui/invoices/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

<%= javascript_tag do %>
$(document).ready(function() {
var stateKey = 'DataTables_invoices-table';
var state = JSON.parse(localStorage.getItem(stateKey));
if (state) {
state.start = <%= @offset %>;
state.search = { search: "<%= @search_query %>" };
localStorage.setItem(stateKey, JSON.stringify(state));
}

var table = $('#invoices-table').DataTable({
"colReorder": {
"enable": false
Expand Down
8 changes: 8 additions & 0 deletions app/views/kaui/payments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

<%= javascript_tag do %>
$(document).ready(function() {
var stateKey = 'DataTables_payments-table';
var state = JSON.parse(localStorage.getItem(stateKey));
if (state) {
state.start = <%= @offset %>;
state.search = { search: "<%= @search_query %>" };
localStorage.setItem(stateKey, JSON.stringify(state));
}

var table = $('#payments-table').DataTable({
"colReorder": {
"enable": false
Expand Down
29 changes: 25 additions & 4 deletions lib/kaui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,33 @@ module Kaui
original_fields = KillBillClient::Model::AccountAttributes.instance_variable_get('@json_attributes')
# Add additional fields if needed
fields = original_fields.dup
fields -= %w[audit_logs]
fields -= %w[audit_logs first_name_length]

headers = fields.map { |attr| attr.split('_').join(' ').capitalize }
values = fields.map do |attr|
next if account.nil? || view_context.nil?

case attr
when 'is_payment_delegated_to_parent', 'is_migrated'
"<div style='text-align: center;'><input type='checkbox' class='custom-checkbox' #{account&.send(attr.downcase) ? 'checked' : ''}></div>"
when 'account_id'
account.nil? || view_context.nil? ? nil : view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.account_id))
view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.account_id))
when 'parent_account_id'
account.nil? || view_context.nil? || account.parent_account_id.nil? ? nil : view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.parent_account_id))
account.parent_account_id.nil? ? nil : view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.parent_account_id))
when 'account_balance'
account.nil? || view_context.nil? ? nil : view_context.humanized_money_with_symbol(account.balance_to_money)
view_context.humanized_money_with_symbol(account.balance_to_money)
else
account&.send(attr.downcase)
end
end

# Update headers if needed
headers[fields.index('is_payment_delegated_to_parent')] = 'Payment via parent'
headers[fields.index('bill_cycle_day_local')] = 'BCD'
headers[fields.index('account_balance')] = 'Balance'
headers[fields.index('account_cba')] = 'CBA'
headers[fields.index('is_migrated')] = 'Migrated'

[headers, values, fields]
end

Expand Down Expand Up @@ -146,10 +158,19 @@ module Kaui
fields.unshift('payment_number')

headers = fields.map { |attr| attr.split('_').join(' ').capitalize }
# Update headers if needed
headers[fields.index('auth_amount')] = 'Auth'
headers[fields.index('captured_amount')] = 'Capture'
headers[fields.index('purchased_amount')] = 'Purchase'
headers[fields.index('refunded_amount')] = 'Refund'
headers[fields.index('credited_amount')] = 'Credit'

return [headers, []] if payment.nil?

values = fields.map do |attr|
case attr
when 'auth_amount', 'captured_amount', 'purchased_amount', 'refunded_amount', 'credited_amount'
view_context.humanized_money_with_symbol(payment&.send(attr.downcase))
when 'payment_number'
view_context.link_to(payment.payment_number, view_context.url_for(controller: :payments, action: :show, account_id: payment.account_id, id: payment.payment_id))
when 'payment_date'
Expand Down

0 comments on commit 1548640

Please sign in to comment.