diff --git a/app/controllers/kaui/accounts_controller.rb b/app/controllers/kaui/accounts_controller.rb index 7d196305..3ea15aba 100644 --- a/app/controllers/kaui/accounts_controller.rb +++ b/app/controllers/kaui/accounts_controller.rb @@ -49,9 +49,15 @@ def pagination end def download - columns = params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase } start_date = params[:startDate] 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 start_date = begin Date.parse(start_date) rescue StandardError diff --git a/app/controllers/kaui/invoices_controller.rb b/app/controllers/kaui/invoices_controller.rb index ac931640..674c5c1c 100644 --- a/app/controllers/kaui/invoices_controller.rb +++ b/app/controllers/kaui/invoices_controller.rb @@ -17,7 +17,13 @@ def download account_id = params[:account_id] start_date = params[:startDate] end_date = params[:endDate] - columns = params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase } + all_fields_checked = params[:allFieldsChecked] == 'true' + columns = if all_fields_checked + KillBillClient::Model::InvoiceAttributes.instance_variable_get('@json_attributes') - Kaui::Invoice::TABLE_IGNORE_COLUMNS + else + params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase } + end + kb_params = {} kb_params[:startDate] = Date.parse(start_date).strftime('%Y-%m-%d') if start_date kb_params[:endDate] = Date.parse(end_date).strftime('%Y-%m-%d') if end_date @@ -55,32 +61,27 @@ def pagination end account_id = (params[:search] || {})[:value] - if account_id.blank? - # Don't show amount and balance, and they will not be populated - data_extractor = lambda do |invoice, column| - [ - invoice.invoice_number.to_i, - invoice.invoice_date - ][column] - end - formatter = lambda do |invoice| - row = [view_context.link_to(invoice.invoice_number, view_context.url_for(controller: :invoices, action: :show, account_id: invoice.account_id, id: invoice.invoice_id))] - row += Kaui.invoice_search_columns.call(invoice, view_context, cached_options_for_klient)[1] - row - end - else - data_extractor = lambda do |invoice, column| - [ - invoice.invoice_number.to_i, - invoice.invoice_date, - invoice.amount, - invoice.balance, - invoice.status - ][column] - end - formatter = lambda do |invoice| - Kaui.account_invoices_columns.call(invoice, view_context)[1] - end + data_extractor = if account_id.blank? + lambda do |invoice, column| + [ + invoice.invoice_number.to_i, + invoice.invoice_date + ][column] + end + else + lambda do |invoice, column| + [ + invoice.invoice_number.to_i, + invoice.invoice_date, + invoice.amount, + invoice.balance, + invoice.status + ][column] + end + end + + formatter = lambda do |invoice| + Kaui.account_invoices_columns.call(invoice, view_context)[1] end paginate searcher, data_extractor, formatter diff --git a/app/controllers/kaui/payments_controller.rb b/app/controllers/kaui/payments_controller.rb index 3c61c796..c85a72f5 100644 --- a/app/controllers/kaui/payments_controller.rb +++ b/app/controllers/kaui/payments_controller.rb @@ -18,7 +18,13 @@ def download account_id = params[:account_id] start_date = params[:startDate] end_date = params[:endDate] - columns = params.require(:columnsString).split(',').map { |attr| attr.split.join('_').downcase } + 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 + kb_params = {} kb_params[:startDate] = Date.parse(start_date).strftime('%Y-%m-%d') if start_date kb_params[:endDate] = Date.parse(end_date).strftime('%Y-%m-%d') if end_date @@ -28,11 +34,12 @@ def download else payments = Kaui::Payment.list_or_search(nil, 0, MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, options_for_klient.merge(params: kb_params)) end + payments.each do |payment| created_date = nil payment.transactions.each do |transaction| transaction_date = Date.parse(transaction.effective_date) - created_date = transaction_date if created_date.nil? || (transaction_date < created_date) + created_date ||= transaction_date if transaction_date < created_date end payment.payment_date = created_date end @@ -41,6 +48,8 @@ def download csv << columns payments.each do |payment| + next if start_date && end_date && (payment.payment_date < Date.parse(start_date) || payment.payment_date > Date.parse(end_date)) + data = columns.map do |attr| case attr when 'payment_number' diff --git a/app/models/kaui/invoice.rb b/app/models/kaui/invoice.rb index ac1f291b..3ca5eabd 100644 --- a/app/models/kaui/invoice.rb +++ b/app/models/kaui/invoice.rb @@ -2,6 +2,8 @@ module Kaui class Invoice < KillBillClient::Model::Invoice + TABLE_IGNORE_COLUMNS = %w[amount balance credit_adj refund_adj items is_parent_invoice parent_invoice_id parent_account_id].freeze + def self.build_from_raw_invoice(raw_invoice) result = Kaui::Invoice.new KillBillClient::Model::InvoiceAttributes.instance_variable_get('@json_attributes').each do |attr| diff --git a/app/views/kaui/account_timelines/_multi_functions_bar.html.erb b/app/views/kaui/account_timelines/_multi_functions_bar.html.erb index ec47e9e8..0d7634c2 100644 --- a/app/views/kaui/account_timelines/_multi_functions_bar.html.erb +++ b/app/views/kaui/account_timelines/_multi_functions_bar.html.erb @@ -9,7 +9,7 @@