Skip to content
Snippets Groups Projects
Commit b4d7910e authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Added the /saldos/new_snapshot method, to allow easy entry of all saldos.

parent 5a67fbed
No related branches found
No related tags found
Loading
...@@ -48,4 +48,33 @@ class SaldosController < ApplicationController ...@@ -48,4 +48,33 @@ class SaldosController < ApplicationController
Saldo.find(params[:id]).destroy Saldo.find(params[:id]).destroy
redirect_to :action => 'list' redirect_to :action => 'list'
end end
def new_snapshot
@saldos = []
for account in Account.find_all
@saldos << Saldo.new(:account_id => account.id,
:date => Date.today)
end
end
def create_snapshot
ok = true
@saldos = []
(0...params[:saldos].to_i).each { |ix|
saldo = Saldo.new(params[:saldo][ix.to_s])
puts ix
puts params[:saldo][ix]
puts params[:saldo]
if not saldo.save
ok = false
end
@saldos << saldo
}
if ok
flash[:notice] = 'Saldos were successfully created.'
redirect_to :action => 'list'
else
render :action => 'new_snapshot'
end
end
end end
...@@ -21,5 +21,6 @@ ...@@ -21,5 +21,6 @@
<br /> <br />
<%= link_to 'Top', :controller => "/" %> <%= link_to 'Top', :controller => "/" %>
<%= link_to 'New saldos', :controller => "saldos", :action => "new_snapshot" %>
</body> </body>
</html> </html>
<% @heading = @saldos[0]["date"].strftime("Saldos per %Y-%m-%d") %>
<%= start_form_tag :action => 'create_snapshot' %>
<input type="hidden" name="saldos" value="<%= @saldos.length %>" />
<% @saldos.each_index { |ix| saldo=@saldos[ix] %>
<p><label for="saldo_account_id"><%= saldo.account.name %></label><br />
<input type="text" name="saldo[<%= ix %>][amount]" value="<%= saldo.amount %>" />
<input type="hidden" name="saldo[<%= ix %>][date]" value="<%= saldo.date %>" />
<input type="hidden" name="saldo[<%= ix %>][account_id]" value="<%= saldo.account.id %>" />
</p>
<% } %>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment