mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Add confirmation dialog for balance reconciliation creates and updates (#2457)
This commit is contained in:
parent
c1d98fe73b
commit
89cc64418e
13 changed files with 180 additions and 49 deletions
|
@ -1,15 +1,24 @@
|
|||
class ValuationsController < ApplicationController
|
||||
include EntryableResource, StreamExtensions
|
||||
|
||||
def confirm_create
|
||||
@account = Current.family.accounts.find(params.dig(:entry, :account_id))
|
||||
@entry = @account.entries.build(entry_params.merge(currency: @account.currency))
|
||||
|
||||
render :confirm_create
|
||||
end
|
||||
|
||||
def confirm_update
|
||||
@entry = Current.family.entries.find(params[:id])
|
||||
@account = @entry.account
|
||||
@entry.assign_attributes(entry_params.merge(currency: @account.currency))
|
||||
|
||||
render :confirm_update
|
||||
end
|
||||
|
||||
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]
|
||||
)
|
||||
result = perform_balance_update(account, entry_params.merge(currency: account.currency))
|
||||
|
||||
if result.success?
|
||||
@success_message = result.updated? ? "Balance updated" : "No changes made. Account is already up to date."
|
||||
|
@ -25,12 +34,7 @@ class ValuationsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
result = @entry.account.update_balance(
|
||||
date: @entry.date,
|
||||
balance: entry_params[:amount],
|
||||
currency: entry_params[:currency],
|
||||
notes: entry_params[:notes]
|
||||
)
|
||||
result = perform_balance_update(@entry.account, entry_params.merge(currency: @entry.currency, existing_valuation_id: @entry.id))
|
||||
|
||||
if result.success?
|
||||
@entry.reload
|
||||
|
@ -59,4 +63,14 @@ class ValuationsController < ApplicationController
|
|||
params.require(:entry)
|
||||
.permit(:date, :amount, :currency, :notes)
|
||||
end
|
||||
|
||||
def perform_balance_update(account, params)
|
||||
account.update_balance(
|
||||
balance: params[:amount],
|
||||
date: params[:date],
|
||||
currency: params[:currency],
|
||||
notes: params[:notes],
|
||||
existing_valuation_id: params[:existing_valuation_id]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue