2024-08-09 11:22:57 -04:00
|
|
|
<%# locals: (entry:) %>
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% type = params[:type] || "buy" %>
|
|
|
|
|
|
|
|
<%= styled_form_with model: entry, url: account_trades_path, data: { controller: "trade-form" } do |form| %>
|
|
|
|
|
|
|
|
<%= form.hidden_field :account_id %>
|
|
|
|
|
2024-08-09 11:22:57 -04:00
|
|
|
<div class="space-y-4">
|
2024-11-27 16:01:50 -05:00
|
|
|
<% if entry.errors.any? %>
|
|
|
|
<%= render "shared/form_errors", model: entry %>
|
|
|
|
<% 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",
|
|
|
|
trade_form_url_param: new_account_trade_path(account_id: entry.account_id),
|
|
|
|
trade_form_key_param: "type",
|
|
|
|
}} %>
|
|
|
|
|
|
|
|
<% if %w[buy sell].include?(type) %>
|
2024-10-28 15:49:19 -04:00
|
|
|
<div class="form-field combobox">
|
2024-11-27 16:01:50 -05:00
|
|
|
<%= form.combobox :ticker, securities_path(country_code: Current.family.country), label: t(".holding"), placeholder: t(".ticker_placeholder"), required: true %>
|
2024-10-28 15:49:19 -04:00
|
|
|
</div>
|
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
|
|
|
<%= form.date_field :date, label: true, value: Date.today, required: true %>
|
2024-08-09 20:11:27 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
<% unless %w[buy sell].include?(type) %>
|
|
|
|
<%= form.money_field :amount, label: t(".amount"), required: true %>
|
|
|
|
<% 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 %>
|