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-12-20 11:37:26 -05:00
|
|
|
search_query = Current.family.transactions.search(@q).includes(:entryable).reverse_chronological
|
|
|
|
@pagy, @transaction_entries = pagy(search_query, limit: params[:per_page] || "50")
|
2024-05-30 20:55:18 -04:00
|
|
|
|
2024-03-28 13:23:54 -04:00
|
|
|
@totals = {
|
2024-12-20 11:37:26 -05:00
|
|
|
count: search_query.select { |t| t.currency == Current.family.currency }.count,
|
|
|
|
income: search_query.income_total(Current.family.currency).abs,
|
|
|
|
expense: search_query.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
|