mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 22:59:39 +02:00
Add reconciliation manager (#2459)
* Add reconciliation manager * Fix notes editing
This commit is contained in:
parent
89cc64418e
commit
52333e3fa6
11 changed files with 273 additions and 64 deletions
|
@ -5,6 +5,12 @@ class ValuationsController < ApplicationController
|
|||
@account = Current.family.accounts.find(params.dig(:entry, :account_id))
|
||||
@entry = @account.entries.build(entry_params.merge(currency: @account.currency))
|
||||
|
||||
@reconciliation_dry_run = @entry.account.create_reconciliation(
|
||||
balance: entry_params[:amount],
|
||||
date: entry_params[:date],
|
||||
dry_run: true
|
||||
)
|
||||
|
||||
render :confirm_create
|
||||
end
|
||||
|
||||
|
@ -13,19 +19,28 @@ class ValuationsController < ApplicationController
|
|||
@account = @entry.account
|
||||
@entry.assign_attributes(entry_params.merge(currency: @account.currency))
|
||||
|
||||
@reconciliation_dry_run = @entry.account.update_reconciliation(
|
||||
@entry,
|
||||
balance: entry_params[:amount],
|
||||
date: entry_params[:date],
|
||||
dry_run: true
|
||||
)
|
||||
|
||||
render :confirm_update
|
||||
end
|
||||
|
||||
def create
|
||||
account = Current.family.accounts.find(params.dig(:entry, :account_id))
|
||||
result = perform_balance_update(account, entry_params.merge(currency: account.currency))
|
||||
|
||||
result = account.create_reconciliation(
|
||||
balance: entry_params[:amount],
|
||||
date: entry_params[:date],
|
||||
)
|
||||
|
||||
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) }
|
||||
format.html { redirect_back_or_to account_path(account), notice: "Account updated" }
|
||||
format.turbo_stream { stream_redirect_back_or_to(account_path(account), notice: "Account updated") }
|
||||
end
|
||||
else
|
||||
@error_message = result.error_message
|
||||
|
@ -34,13 +49,22 @@ class ValuationsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
result = perform_balance_update(@entry.account, entry_params.merge(currency: @entry.currency, existing_valuation_id: @entry.id))
|
||||
# Notes updating is independent of reconciliation, just a simple CRUD operation
|
||||
@entry.update!(notes: entry_params[:notes]) if entry_params[:notes].present?
|
||||
|
||||
if result.success?
|
||||
if entry_params[:date].present? && entry_params[:amount].present?
|
||||
result = @entry.account.update_reconciliation(
|
||||
@entry,
|
||||
balance: entry_params[:amount],
|
||||
date: entry_params[:date],
|
||||
)
|
||||
end
|
||||
|
||||
if result.nil? || 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.html { redirect_back_or_to account_path(@entry.account), notice: "Entry updated" }
|
||||
format.turbo_stream do
|
||||
render turbo_stream: [
|
||||
turbo_stream.replace(
|
||||
|
@ -60,17 +84,6 @@ class ValuationsController < ApplicationController
|
|||
|
||||
private
|
||||
def entry_params
|
||||
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]
|
||||
)
|
||||
params.require(:entry).permit(:date, :amount, :notes)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue