foodsoft/app/controllers/finance/bank_transactions_controller.rb
Philipp Rothmann fb2b4d8a8a chore: rubocop
chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
2023-06-09 17:35:05 +02:00

39 lines
1.4 KiB
Ruby

class Finance::BankTransactionsController < ApplicationController
before_action :authenticate_finance
inherit_resources
def index
sort = if params['sort']
case params['sort']
when 'date' then 'date'
when 'amount' then 'amount'
when 'financial_link' then 'financial_link_id'
when 'date_reverse' then 'date DESC'
when 'amount_reverse' then 'amount DESC'
when 'financial_link_reverse' then 'financial_link_id DESC'
end
else
'date DESC'
end
@bank_account = BankAccount.find(params[:bank_account_id])
@bank_transactions_all = @bank_account.bank_transactions.order(sort).includes(:financial_link)
unless params[:query].nil?
@bank_transactions_all = @bank_transactions_all.where('reference LIKE ? OR text LIKE ?', "%#{params[:query]}%",
"%#{params[:query]}%")
end
@bank_transactions = @bank_transactions_all.page(params[:page]).per(@per_page)
respond_to do |format|
format.js
format.html { render }
format.csv do
send_data BankTransactionsCsv.new(@bank_transactions_all).to_csv, filename: 'transactions.csv', type: 'text/csv'
end
end
end
def show
@bank_transaction = BankTransaction.find(params[:id])
end
end