% # Use activity_label param if provided (from quick-edit badge click), # otherwise determine default based on amount sign # Negative amount (money going out) = Buy, Positive (money coming in) = Sell default_label = params[:activity_label].presence || (@entry.amount > 0 ? "Sell" : "Buy") %> <%= render DS::Dialog.new(variant: "modal", reload_on_close: true) do |dialog| %> <% dialog.with_header do %>
<%= t(".description") %>
<% end %> <% dialog.with_body do %> <%= form_with url: create_trade_from_transaction_transaction_path(@transaction), method: :post, class: "space-y-4", data: { controller: "convert-to-trade", turbo_frame: "_top", convert_to_trade_amount_cents_value: (@entry.amount_money.abs.amount * 100).to_i, convert_to_trade_currency_value: @entry.currency } do |f| %><%= t(".ticker_search_hint") %>
<% else %> <%# No provider: show existing holdings dropdown with custom option %> <% # Get unique securities from account holdings for dropdown account_securities = @entry.account.holdings .includes(:security) .where.not(security: nil) .map(&:security) .uniq(&:ticker) .sort_by(&:ticker) # Build options with price data for validation security_options_with_prices = account_securities.map do |s| price = s.current_price price_display = price ? " (#{format_money(price)})" : "" label = "#{s.ticker}#{price_display}" label += " - #{s.name.truncate(25)}" if s.name.present? price_cents = price ? (price.amount * 100).to_i : nil [label, s.id, { "data-price-cents" => price_cents, "data-ticker" => s.ticker }] end %> <% if account_securities.any? %> <%= f.select :security_id, options_for_select( [[t(".security_prompt"), ""]] + security_options_with_prices + [[t(".security_custom"), "__custom__"]], nil ), {}, { class: "form-field__input border border-secondary rounded-lg px-3 py-2 w-full text-primary bg-container", data: { action: "change->convert-to-trade#toggleCustomTicker change->convert-to-trade#validatePrice", convert_to_trade_target: "tickerSelect" } } %><%= t(".security_not_listed_hint") %>
<%= t(".ticker_hint") %>
<%= t(".ticker_hint") %>
<% end %> <% end %><%= t(".quantity_hint") %>
<%= t(".price_hint", currency: @entry.currency) %>
<%= t(".price_mismatch_title") %>
<%= icon "info", size: "xs", class: "inline-block mr-1" %> <%= t(".qty_or_price_hint", amount: format_money(@entry.amount_money.abs)) %>
<%= t(".trade_type_hint") %>
<%= t(".exchange_hint") %>