2025-06-20 13:31:58 -04:00
|
|
|
<%# locals: (model:, account:) %>
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% type = params[:type] || "buy" %>
|
|
|
|
|
2025-06-20 13:31:58 -04:00
|
|
|
<%= styled_form_with url: trades_path(account_id: account&.id), scope: :model, data: { controller: "trade-form" } do |form| %>
|
2024-08-09 11:22:57 -04:00
|
|
|
<div class="space-y-4">
|
2025-06-20 13:31:58 -04:00
|
|
|
<% if model.errors.any? %>
|
|
|
|
<%= render "shared/form_errors", model: model %>
|
2024-11-27 16:01:50 -05:00
|
|
|
<% end %>
|
|
|
|
|
2024-08-09 11:22:57 -04:00
|
|
|
<div class="space-y-2">
|
2024-11-27 16:01:50 -05:00
|
|
|
<%= form.select :type, [
|
|
|
|
["Buy", "buy"],
|
|
|
|
["Sell", "sell"],
|
|
|
|
["Deposit", "deposit"],
|
|
|
|
["Withdrawal", "withdrawal"],
|
|
|
|
["Interest", "interest"]
|
|
|
|
],
|
|
|
|
{ label: t(".type"), selected: type },
|
|
|
|
{ data: {
|
|
|
|
action: "trade-form#changeType",
|
2025-06-20 13:31:58 -04:00
|
|
|
trade_form_url_param: new_trade_path(account_id: account&.id),
|
2024-11-27 16:01:50 -05:00
|
|
|
trade_form_key_param: "type",
|
|
|
|
}} %>
|
|
|
|
|
|
|
|
<% if %w[buy sell].include?(type) %>
|
2025-02-28 09:34:14 -05:00
|
|
|
<% if Security.provider.present? %>
|
|
|
|
<div class="form-field combobox">
|
2025-03-03 12:47:30 -05:00
|
|
|
<%= form.combobox :ticker,
|
|
|
|
securities_path(country_code: Current.family.country),
|
2025-04-14 11:40:34 -04:00
|
|
|
name_when_new: "entry[manual_ticker]",
|
2025-03-03 12:47:30 -05:00
|
|
|
label: t(".holding"),
|
|
|
|
placeholder: t(".ticker_placeholder"),
|
2025-02-28 09:34:14 -05:00
|
|
|
required: true %>
|
|
|
|
</div>
|
|
|
|
<% else %>
|
2025-03-17 11:54:53 -04:00
|
|
|
<%= form.text_field :manual_ticker, label: "Ticker symbol", placeholder: "AAPL", required: true %>
|
2025-02-28 09:34:14 -05:00
|
|
|
<% end %>
|
2024-11-27 16:01:50 -05:00
|
|
|
<% end %>
|
2024-08-09 20:11:27 -04:00
|
|
|
|
2025-06-20 13:31:58 -04:00
|
|
|
<%= form.date_field :date, label: true, value: model.date || Date.current, required: true %>
|
2024-08-09 20:11:27 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% unless %w[buy sell].include?(type) %>
|
2025-06-20 13:31:58 -04:00
|
|
|
<%= form.money_field :amount, label: t(".amount"), value: model.amount, required: true %>
|
2024-11-27 16:01:50 -05:00
|
|
|
<% end %>
|
2024-08-09 20:11:27 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% if %w[deposit withdrawal].include?(type) %>
|
2024-08-09 20:11:27 -04:00
|
|
|
<%= form.collection_select :transfer_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".account_prompt"), label: t(".account") } %>
|
2024-11-27 16:01:50 -05:00
|
|
|
<% end %>
|
2024-08-09 20:11:27 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% if %w[buy sell].include?(type) %>
|
|
|
|
<%= form.number_field :qty, label: t(".qty"), placeholder: "10", min: 0.000000000000000001, step: "any", required: true %>
|
|
|
|
<%= form.money_field :price, label: t(".price"), required: true %>
|
|
|
|
<% end %>
|
2024-08-09 11:22:57 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<%= form.submit t(".submit") %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|