2024-02-02 09:05:04 -06:00
|
|
|
module AccountsHelper
|
2024-02-07 04:48:05 +03:00
|
|
|
def to_accountable_title(accountable)
|
|
|
|
accountable.model_name.human
|
|
|
|
end
|
2024-03-06 09:56:59 -05:00
|
|
|
|
|
|
|
def accountable_text_class(accountable_type)
|
|
|
|
class_mapping(accountable_type)[:text]
|
|
|
|
end
|
|
|
|
|
2024-04-23 17:05:18 +01:00
|
|
|
def accountable_fill_class(accountable_type)
|
|
|
|
class_mapping(accountable_type)[:fill]
|
|
|
|
end
|
|
|
|
|
2024-03-06 09:56:59 -05:00
|
|
|
def accountable_bg_class(accountable_type)
|
|
|
|
class_mapping(accountable_type)[:bg]
|
|
|
|
end
|
|
|
|
|
|
|
|
def accountable_bg_transparent_class(accountable_type)
|
|
|
|
class_mapping(accountable_type)[:bg_transparent]
|
|
|
|
end
|
|
|
|
|
2024-04-25 15:32:45 +01:00
|
|
|
def accountable_color(accountable_type)
|
|
|
|
class_mapping(accountable_type)[:hex]
|
|
|
|
end
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
# Eventually, we'll have an accountable form for each type of accountable, so
|
|
|
|
# this helper is a convenience for now to reuse common logic in the accounts controller
|
|
|
|
def new_account_form_url(account)
|
|
|
|
case account.accountable_type
|
|
|
|
when "Property"
|
|
|
|
properties_path
|
2024-08-23 09:33:42 -04:00
|
|
|
when "Vehicle"
|
|
|
|
vehicles_path
|
2024-08-23 08:47:08 -04:00
|
|
|
else
|
|
|
|
accounts_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_account_form_url(account)
|
|
|
|
case account.accountable_type
|
|
|
|
when "Property"
|
|
|
|
property_path(account)
|
2024-08-23 09:33:42 -04:00
|
|
|
when "Vehicle"
|
|
|
|
vehicle_path(account)
|
2024-08-23 08:47:08 -04:00
|
|
|
else
|
|
|
|
account_path(account)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-25 16:46:04 -04:00
|
|
|
def account_tabs(account)
|
2024-08-23 08:47:08 -04:00
|
|
|
overview_tab = { key: "overview", label: t("accounts.show.overview"), path: account_path(account, tab: "overview"), partial_path: "accounts/overview" }
|
|
|
|
holdings_tab = { key: "holdings", label: t("accounts.show.holdings"), path: account_path(account, tab: "holdings"), route: account_holdings_path(account) }
|
|
|
|
cash_tab = { key: "cash", label: t("accounts.show.cash"), path: account_path(account, tab: "cash"), route: account_cashes_path(account) }
|
|
|
|
value_tab = { key: "valuations", label: t("accounts.show.value"), path: account_path(account, tab: "valuations"), route: account_valuations_path(account) }
|
|
|
|
transactions_tab = { key: "transactions", label: t("accounts.show.transactions"), path: account_path(account, tab: "transactions"), route: account_transactions_path(account) }
|
|
|
|
trades_tab = { key: "trades", label: t("accounts.show.trades"), path: account_path(account, tab: "trades"), route: account_trades_path(account) }
|
2024-07-25 16:46:04 -04:00
|
|
|
|
2024-10-07 20:23:33 -04:00
|
|
|
return [ value_tab ] if account.other_asset? || account.other_liability?
|
2024-08-23 09:33:42 -04:00
|
|
|
return [ overview_tab, value_tab ] if account.property? || account.vehicle?
|
2024-08-02 17:09:25 -04:00
|
|
|
return [ holdings_tab, cash_tab, trades_tab ] if account.investment?
|
2024-03-06 09:56:59 -05:00
|
|
|
|
2024-07-25 16:46:04 -04:00
|
|
|
[ value_tab, transactions_tab ]
|
2024-03-06 09:56:59 -05:00
|
|
|
end
|
2024-07-25 16:46:04 -04:00
|
|
|
|
|
|
|
def selected_account_tab(account)
|
|
|
|
available_tabs = account_tabs(account)
|
|
|
|
|
|
|
|
tab = available_tabs.find { |tab| tab[:key] == params[:tab] }
|
|
|
|
|
|
|
|
tab || available_tabs.first
|
|
|
|
end
|
|
|
|
|
2024-09-10 17:17:10 -04:00
|
|
|
def account_groups(period: nil)
|
|
|
|
assets, liabilities = Current.family.accounts.by_group(currency: Current.family.currency, period: period || Period.last_30_days).values_at(:assets, :liabilities)
|
|
|
|
[ assets.children, liabilities.children ].flatten
|
|
|
|
end
|
|
|
|
|
2024-07-25 16:46:04 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def class_mapping(accountable_type)
|
|
|
|
{
|
|
|
|
"CreditCard" => { text: "text-red-500", bg: "bg-red-500", bg_transparent: "bg-red-500/10", fill: "fill-red-500", hex: "#F13636" },
|
|
|
|
"Loan" => { text: "text-fuchsia-500", bg: "bg-fuchsia-500", bg_transparent: "bg-fuchsia-500/10", fill: "fill-fuchsia-500", hex: "#D444F1" },
|
|
|
|
"OtherLiability" => { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500", hex: "#737373" },
|
|
|
|
"Depository" => { text: "text-violet-500", bg: "bg-violet-500", bg_transparent: "bg-violet-500/10", fill: "fill-violet-500", hex: "#875BF7" },
|
|
|
|
"Investment" => { text: "text-blue-600", bg: "bg-blue-600", bg_transparent: "bg-blue-600/10", fill: "fill-blue-600", hex: "#1570EF" },
|
|
|
|
"OtherAsset" => { text: "text-green-500", bg: "bg-green-500", bg_transparent: "bg-green-500/10", fill: "fill-green-500", hex: "#12B76A" },
|
|
|
|
"Property" => { text: "text-cyan-500", bg: "bg-cyan-500", bg_transparent: "bg-cyan-500/10", fill: "fill-cyan-500", hex: "#06AED4" },
|
|
|
|
"Vehicle" => { text: "text-pink-500", bg: "bg-pink-500", bg_transparent: "bg-pink-500/10", fill: "fill-pink-500", hex: "#F23E94" }
|
|
|
|
}.fetch(accountable_type, { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500", hex: "#737373" })
|
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|