2024-08-09 11:22:57 -04:00
|
|
|
class Account::TransactionsController < ApplicationController
|
2024-11-27 16:01:50 -05:00
|
|
|
include EntryableResource
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
permitted_entryable_attributes :id, :category_id, :merchant_id, { tag_ids: [] }
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def bulk_delete
|
|
|
|
destroyed = Current.family.entries.destroy_by(id: bulk_delete_params[:entry_ids])
|
|
|
|
destroyed.map(&:account).uniq.each(&:sync_later)
|
|
|
|
redirect_back_or_to transactions_url, notice: t(".success", count: destroyed.count)
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def bulk_edit
|
|
|
|
end
|
2024-11-04 20:27:31 -05:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def bulk_update
|
|
|
|
updated = Current.family
|
|
|
|
.entries
|
|
|
|
.where(id: bulk_update_params[:entry_ids])
|
|
|
|
.bulk_update!(bulk_update_params)
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
redirect_back_or_to transactions_url, notice: t(".success", count: updated)
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def mark_transfers
|
2024-12-30 17:29:59 -05:00
|
|
|
selected_entries = Current.family.entries.account_transactions.where(id: bulk_update_params[:entry_ids])
|
|
|
|
|
|
|
|
TransferMatcher.new(Current.family).match!(selected_entries)
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
redirect_back_or_to transactions_url, notice: t(".success")
|
|
|
|
end
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def unmark_transfers
|
|
|
|
Current.family
|
|
|
|
.entries
|
2024-12-30 17:29:59 -05:00
|
|
|
.account_transactions
|
|
|
|
.includes(:entryable)
|
2024-11-27 16:01:50 -05:00
|
|
|
.where(id: bulk_update_params[:entry_ids])
|
2024-12-30 17:29:59 -05:00
|
|
|
.each do |entry|
|
|
|
|
entry.entryable.update!(category_id: nil)
|
|
|
|
end
|
2024-11-04 20:27:31 -05:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
redirect_back_or_to transactions_url, notice: t(".success")
|
|
|
|
end
|
2024-08-26 19:10:17 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
private
|
|
|
|
def bulk_delete_params
|
|
|
|
params.require(:bulk_delete).permit(entry_ids: [])
|
|
|
|
end
|
2024-08-26 19:10:17 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def bulk_update_params
|
|
|
|
params.require(:bulk_update).permit(:date, :notes, :category_id, :merchant_id, entry_ids: [])
|
|
|
|
end
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def search_params
|
|
|
|
params.fetch(:q, {})
|
|
|
|
.permit(:start_date, :end_date, :search, :amount, :amount_operator, accounts: [], account_ids: [], categories: [], merchants: [], types: [], tags: [])
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
end
|