2024-02-23 21:34:33 -05:00
|
|
|
class TransactionsController < ApplicationController
|
2024-07-26 18:00:41 +02:00
|
|
|
layout :with_sidebar
|
2024-05-17 09:09:32 -04:00
|
|
|
|
2024-02-23 21:34:33 -05:00
|
|
|
def index
|
2024-05-30 20:55:18 -04:00
|
|
|
@q = search_params
|
2024-07-01 10:49:43 -04:00
|
|
|
result = Current.family.entries.account_transactions.search(@q).reverse_chronological
|
2024-07-22 15:49:53 +02:00
|
|
|
@pagy, @transaction_entries = pagy(result, limit: params[:per_page] || "50")
|
2024-05-30 20:55:18 -04:00
|
|
|
|
2024-03-28 13:23:54 -04:00
|
|
|
@totals = {
|
2024-06-19 06:52:08 -04:00
|
|
|
count: result.select { |t| t.currency == Current.family.currency }.count,
|
|
|
|
income: result.income_total(Current.family.currency).abs,
|
|
|
|
expense: result.expense_total(Current.family.currency)
|
2024-03-28 13:23:54 -04:00
|
|
|
}
|
2024-02-23 21:34:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2024-05-30 20:55:18 -04:00
|
|
|
def search_params
|
2024-09-17 10:38:02 -04:00
|
|
|
params.fetch(:q, {})
|
2024-11-27 16:01:50 -05:00
|
|
|
.permit(
|
|
|
|
:start_date, :end_date, :search, :amount,
|
|
|
|
:amount_operator, accounts: [], account_ids: [],
|
|
|
|
categories: [], merchants: [], types: [], tags: []
|
|
|
|
)
|
2024-02-23 21:34:33 -05:00
|
|
|
end
|
|
|
|
end
|