mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-28 09:39:39 +02:00
45 lines
1.2 KiB
Ruby
45 lines
1.2 KiB
Ruby
|
class Account::TransactionsController < ApplicationController
|
||
|
layout "with_sidebar"
|
||
|
|
||
|
before_action :set_account
|
||
|
before_action :set_transaction, only: %i[ show update destroy ]
|
||
|
|
||
|
def index
|
||
|
@transactions = @account.transactions.ordered
|
||
|
end
|
||
|
|
||
|
def show
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
@transaction.update! transaction_params
|
||
|
@transaction.sync_account_later
|
||
|
|
||
|
redirect_back_or_to account_transaction_url(@transaction.account, @transaction), notice: t(".success")
|
||
|
end
|
||
|
|
||
|
def destroy
|
||
|
@transaction.destroy!
|
||
|
@transaction.sync_account_later
|
||
|
redirect_back_or_to account_url(@transaction.account), notice: t(".success")
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def set_account
|
||
|
@account = Current.family.accounts.find(params[:account_id])
|
||
|
end
|
||
|
|
||
|
def set_transaction
|
||
|
@transaction = @account.transactions.find(params[:id])
|
||
|
end
|
||
|
|
||
|
def search_params
|
||
|
params.fetch(:q, {}).permit(:start_date, :end_date, :search, accounts: [], account_ids: [], categories: [], merchants: [])
|
||
|
end
|
||
|
|
||
|
def transaction_params
|
||
|
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, tag_ids: [])
|
||
|
end
|
||
|
end
|