Skip to content

Commit

Permalink
Merge pull request #433 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 26, 2024
2 parents 1548640 + 3f79fbd commit c6f8f8f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 29 deletions.
15 changes: 10 additions & 5 deletions app/controllers/kaui/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ def download
end_date = params[:endDate]
all_fields_checked = params[:allFieldsChecked] == 'true'

columns = if all_fields_checked
KillBillClient::Model::AccountAttributes.instance_variable_get('@json_attributes')
else
params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase }
end
if all_fields_checked
columns = KillBillClient::Model::AccountAttributes.instance_variable_get('@json_attributes')
else
columns = params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase }
Kaui::Account::REMAPPING_FIELDS.each do |k, v|
index = columns.index(v)
columns[index] = k if index
end
end

start_date = begin
Date.parse(start_date)
rescue StandardError
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/audit_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def download
end
end

send_data csv_file, type: 'text/csv', filename: "audit_logs_#{account_id}.csv"
send_data csv_file, type: 'text/csv', filename: "audit-logs-#{Date.today}.csv"
end

def history
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/kaui/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ def download
start_date = params[:startDate]
end_date = params[:endDate]
all_fields_checked = params[:allFieldsChecked] == 'true'
columns = if all_fields_checked
KillBillClient::Model::PaymentAttributes.instance_variable_get('@json_attributes') - %w[transactions audit_logs]
else
params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase }
end
if all_fields_checked
columns = KillBillClient::Model::PaymentAttributes.instance_variable_get('@json_attributes') - %w[transactions audit_logs]
else
columns = params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase }
Kaui::Payment::REMAPPING_FIELDS.each do |k, v|
index = columns.index(v)
columns[index] = k if index
end
end

kb_params = {}
kb_params[:startDate] = Date.parse(start_date).strftime('%Y-%m-%d') if start_date
Expand All @@ -39,7 +43,7 @@ def download
created_date = nil
payment.transactions.each do |transaction|
transaction_date = Date.parse(transaction.effective_date)
created_date ||= transaction_date if transaction_date < created_date
created_date = transaction_date if created_date.nil? || (transaction_date < created_date)
end
payment.payment_date = created_date
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/kaui/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class Account < KillBillClient::Model::Account
attr_accessor :phone, :bill_cycle_day_local

SENSIVITE_DATA_FIELDS = %w[name email].freeze
REMAPPING_FIELDS = {
'is_payment_delegated_to_parent' => 'pay_via_parent',
'bill_cycle_day_local' => 'bcd',
'account_balance' => 'balance',
'account_cba' => 'cba',
'is_migrated' => 'migrated'
}.freeze

def check_account_details_phone
return true if phone =~ /\A(?:\+?\d{1,3}\s*-?)?\(?(?:\d{3})?\)?[- ]?\d{3}[- ]?\d{4}\z/i
Expand Down
7 changes: 7 additions & 0 deletions app/models/kaui/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class Payment < KillBillClient::Model::Payment
attr_accessor :payment_date, :target_invoice_id

TRANSACTION_STATUSES = %w[SUCCESS PENDING PAYMENT_FAILURE PLUGIN_FAILURE UNKNOWN].freeze
REMAPPING_FIELDS = {
'auth_amount' => 'auth',
'captured_amount' => 'capture',
'purchased_amount' => 'purchase',
'credited_amount' => 'credit',
'refunded_amount' => 'refund'
}.freeze

def self.build_from_raw_payment(raw_payment)
result = Kaui::Payment.new
Expand Down
3 changes: 1 addition & 2 deletions app/views/kaui/payments/_multi_functions_bar.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div class="dropdown-container">
<% unless @account.account_id.blank? %>
<button class="btn btn-default download-button-right" type="button" id="modalDownloadButton">
<i class="glyphicon glyphicon-download-alt"></i>
<strong>Download CSV</strong>
</button>
<% end %>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle toggle-button-right" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="glyphicon glyphicon-cog"></i>
Expand Down Expand Up @@ -174,6 +172,7 @@ $(document).ready(function() {
});

$('#downloadCsvModal').on('show.bs.modal', function (e) {
$('#allData').prop('checked', true);
$('#startDate, #endDate').prop('disabled', true);
$('#startDate').val(null);
$('#endDate').val(null);
Expand Down
25 changes: 10 additions & 15 deletions lib/kaui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ module Kaui
# Add additional fields if needed
fields = original_fields.dup
fields -= %w[audit_logs first_name_length]
headers = fields.dup
Kaui::Account::REMAPPING_FIELDS.each do |k, v|
headers[fields.index(k)] = v
end
headers.map! { |attr| attr.split('_').join(' ').capitalize }

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

Expand All @@ -85,13 +89,6 @@ module Kaui
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 @@ -157,13 +154,11 @@ module Kaui
fields.unshift('status')
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'
headers = fields.dup
Kaui::Payment::REMAPPING_FIELDS.each do |k, v|
headers[fields.index(k)] = v
end
headers.map! { |attr| attr.split('_').join(' ').capitalize }

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

Expand Down

0 comments on commit c6f8f8f

Please sign in to comment.