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
|
|
|
|
2025-01-07 09:41:24 -05:00
|
|
|
totals_query = search_query.incomes_and_expenses
|
|
|
|
family_currency = Current.family.currency
|
|
|
|
count_with_transfers = search_query.count
|
|
|
|
count_without_transfers = totals_query.count
|
|
|
|
|
2024-03-28 13:23:54 -04:00
|
|
|
@totals = {
|
2025-01-07 09:41:24 -05:00
|
|
|
count: ((count_with_transfers - count_without_transfers) / 2) + count_without_transfers,
|
|
|
|
income: totals_query.income_total(family_currency).abs,
|
|
|
|
expense: totals_query.expense_total(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
|