mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
* Initial multi-step property form * Improve form structure, add optional tooltip help icons to form fields * Add basic inline alert component * Clean up and improve property form lifecycle * Implement Account status concept * Lint fixes * Remove whitespace * Balance editing, scope updates for account * Passing tests * Fix brakeman warning * Remove stale columns * data constraint tweaks * Redundant property
62 lines
1.8 KiB
Ruby
62 lines
1.8 KiB
Ruby
class ValuationsController < ApplicationController
|
|
include EntryableResource, StreamExtensions
|
|
|
|
def create
|
|
account = Current.family.accounts.find(params.dig(:entry, :account_id))
|
|
|
|
result = account.update_balance(
|
|
balance: entry_params[:amount],
|
|
date: entry_params[:date],
|
|
currency: entry_params[:currency],
|
|
notes: entry_params[:notes]
|
|
)
|
|
|
|
if result.success?
|
|
@success_message = result.updated? ? "Balance updated" : "No changes made. Account is already up to date."
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to account_path(account), notice: @success_message }
|
|
format.turbo_stream { stream_redirect_back_or_to(account_path(account), notice: @success_message) }
|
|
end
|
|
else
|
|
@error_message = result.error_message
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
result = @entry.account.update_balance(
|
|
date: @entry.date,
|
|
balance: entry_params[:amount],
|
|
currency: entry_params[:currency],
|
|
notes: entry_params[:notes]
|
|
)
|
|
|
|
if result.success?
|
|
@entry.reload
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to account_path(@entry.account), notice: result.updated? ? "Balance updated" : "No changes made. Account is already up to date." }
|
|
format.turbo_stream do
|
|
render turbo_stream: [
|
|
turbo_stream.replace(
|
|
dom_id(@entry, :header),
|
|
partial: "valuations/header",
|
|
locals: { entry: @entry }
|
|
),
|
|
turbo_stream.replace(@entry)
|
|
]
|
|
end
|
|
end
|
|
else
|
|
@error_message = result.error_message
|
|
render :show, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
def entry_params
|
|
params.require(:entry)
|
|
.permit(:date, :amount, :currency, :notes)
|
|
end
|
|
end
|