added pagination gem, many fixes
[smr.git] / gui / app / views / positions / show.html.erb
blob635482d9a2641beafb75dacae492b6ea349a2f10
2 <h1><%= @position.stock.name %> </h1>
4 <% if @position.is_closed? %>
5   <p><%= @position.comment %></p>
6 <% else %>
7   <%= form_tag :patch_position, :method=>:POST do %>
8     <%= hidden_field_tag :id, @position.id %>
9     <%= text_field_tag :comment, @position.comment, :size=>50, :placeholder=>'Whats the point of holding it? Until when?' %>
10     <% if @position.comment %>
11      <%= submit_tag 'Update Comment' %>
12     <% else %>
13      <%= submit_tag 'Set Comment' %>
14     <% end %>
15   <% end %>
16   <br/>
17 <% end %>
19 <% if @position.is_closed? and not @position.is_viewed_before_closure? %>
20     <p>Position has been settled on <%= @position.time_closed %>.</p>
22     <table>
23         <tr><td>Purchased Volume</td><td><%= smr_humanize(@position.purchase_volume) %></td></tr>
24         <tr><td>Settled Volume</td><td><%= smr_humanize(@position.settled_volume) %></td></tr>
25         <tr><td>= Profit/Loss</td><td><%= smr_humanize(@position.profit_loss) %> <em><%= percentage_change(@position.purchase_volume, @position.settled_volume)%></em></td></tr>
26         <tr><td>Dividend</td><td><%= smr_humanize(@position.dividend.received) %></td></tr>
27         <tr><td>Charges</td><td><%= smr_humanize(@position.charges) %></td></tr>
28         <tr><td>= Gain</td><td><%= smr_humanize(@position.gain) %> <em><%= percentage_of(@position.purchase_volume, @position.gain) %> </em></td></tr>
29     </table>
30 <% elsif @position.is_new? %>
31     <p>This position is new. You may order something or just close it.</p>
32 <% else %>
33     <p>
34     Position <% if @position.shares<0 %> is short by <% else %> holds <% end %> <%= smr_humanize(@position.shares) %> shares
35     which are valued at <%= @position.last_quote %> a share.
37     <% if @position.is_closed? %>
38         It will be closed as of <%= @position.time_closed %>.
39     <% end %>
40     </p> 
42     <table border>
43         <tr><td>Invested Money</td><td><%= smr_humanize(@position.invested) %></td></tr>
44         <tr><td>Market Value</td><td><%= smr_humanize(@position.market_value) %></td></tr>
45         <tr><td>= Profit/Loss</td><td><%= smr_humanize(@position.profit_loss) %> <em><%= percentage_change(@position.invested, @position.market_value)%></em></td></tr>
46         <tr><td>Dividend</td><td><%= smr_humanize(@position.dividend.received) %></td></tr>
47         <tr><td>Charges</td><td><%= smr_humanize(@position.charges) %></td></tr>
48         <tr><td>= Gain</td><td><%= smr_humanize(@position.gain) %> <em><%= percentage_change(@position.invested, @position.dirty_value) %> </em></td></tr>
49     </table>
50 <% end %>
52 <% if @position.has_pending_orders? %>
53 <h2>Pending Orders</h2>
54 <table border>
55     <thead>
56     <tr>
57         <th></th>
58         <th>Exchange</th>
59         <th>Issued / Expires</th>
60         <th></th>
61         <th></th>
62     </tr>
63     </thead>
64     <tbody> 
65 <% @position.pending_orders.reverse.each do |o| %>
66     <tr>
67         <td>#<%= o.id %></td>
68         <td><%=o.exchange%></td>
69         <td><%=o.time_issued%> / <%=o.time_expire%></td>
70         <td><%=o.type%> <%= smr_humanize(o.shares) %> shares at <%=o.limit%></td>
71         <td>
72             <%= label_tag 'execute_quote', 'execute at quote:' %>
73             <%= form_tag(controller: 'positions', action: 'execute_order', method: "post") do %>
74                 <%= hidden_field_tag 'id_order',  o.id %>
75                 <%= number_field_tag 'execute_quote', o.limit, {step: 0.0001} %> <%= submit_tag 'Do' %>
76             <% end %>
77             <%= form_tag(controller: 'positions', action: 'cancel_order', method: "post") do %>
78                 <%= hidden_field_tag 'id_order',  o.id %>
79                 <%= submit_tag 'Cancel this order' %>
80             <% end %>
81         </td>
82     </tr>
83 <% end %>
84     </tbody>
85 </table>
86 <% end %>
88 <% if not @position.is_new? %>
89 <h2>Executed Orders</h2>
90 <table border>
91     <thead>
92     <tr>
93         <th></th>
94         <th>Exchange / Broker</th>
95         <th colspan="3">Ordered</th>
96         <th>Volume Traded</th>
97         <th>Stock after Trade</th>
98         <th>Profit/Loss by Lot</th>
99     </tr>
100     </thead>
101     <tbody> 
102 <% @position.revisions.reverse.each do |pr| %>
103     <% next if pr.id_order==0  # skip old-style first emtpy revision %>
104     <tr>
105         <td>#<%= pr.id_order %></td>
106         <td><% if not pr.Order.exchange.nil? %><%=pr.Order.exchange%> via <% end %><%=@position.portfolio.name%></td>
107         <td><%=smr_humanize(pr.time) %></td>
108         <td><%=pr.Order.type%> <%=smr_humanize(pr.Order.shares)%> shares at <%=pr.Order.quote%></td>
109         <td><%=pr.Order.status%></td>
110         <td><%=smr_humanize(revision_volume(pr.Order.shares, pr.Order.quote)) %></td>
111         <td><%=smr_humanize(pr.shares) %></td>
112         <td><%=smr_humanize(revision_profitloss(@position.last_quote, pr.Order.shares, pr.Order.quote)) %></td>
113     </tr>
114 <% end %>
115     </tbody>
116 </table>
117 <% end %>
119 <% if not @position.is_new? and not @position.dividend.empty? %>
120 <h2>Dividend Log</h2>
121 <table border>
122     <thead>
123     <tr>
124         <th>Date</th>
125         <th>Received</th>
126         <th>Total</th>
127     </tr>
128     </thead>
129     <tbody> 
130     <% @position.dividend.payments.reverse.each do |d| %>
131     <tr>
132         <td><%=  smr_humanize(d[:time]) %></td>
133         <td><%=  smr_humanize(d[:received]) %> on <%= smr_humanize(d[:shares]) %> shares</td>
134         <td><%=  smr_humanize(d[:total]) %></td>
135     </tr>
136     <% end %>
137     </tbody>
138 </table>
139 <% end %>