Hi all.. I am trying to generate a report which has multiple columns..
After rendering the report I allow the user to enter a value which is to
be subtracted from the column which is already rendered.. I have
multiple rows.. so I have tries like the following. My views page is

   function sum() {
   var txtFirstNumberValue = document.getElementById('txt1').value;
   var txtSecondNumberValue = document.getElementById('txt2').value;
   var result = parseFloat(txtFirstNumberValue) -
    if(!isNaN(result)) {
    document.getElementById('txt3').value = result; } }
<% @arr.each do |j| %>
<% @q =[] %>
<% t= 0 %>
<%= form_for ProductionReport.new
,:url=>{:controller=>"users",:action=>"rate_per_unit_report" } do |i| %>
<td><%= j[0] %></td>
<td><%= j[1] %></td>
<td><%= j[2] %></td>
<% @q << j[3] %>
<td><%= i.text_field j[3], :value=>@q[t], :id=>"txt1",
:onkeyup=>"sum()", :class=>"txt" %></td>
<td><%= i.text_field :selling_price, :id=>"txt2", :onkeyup=>"sum()",
:class=>"txt" %></td>
<td><%= i.text_field :profit_loss, :id=>"txt3", :class=>"txt", :readonly
=>true %></td>
<% end %>
<% t = t+1 %>
<% end %>
<td><%= @total %></td>
<td><%= @total1 %></td>
<td><%= @total2 %></td>

My controller is

def rate_per_unit_report
   @user = User.find(session[:user_id]).name
   @rpus = params[:production_report][:intial_date]
   @rpue = params[:production_report][:final_date]
   @production_report = ProductionReport.where(:date => @rpus..@rpue)
   @production = @production_report.select(:finished_goods_name).uniq
   g = 0
   @production.each do|i|
     @p = @production_report.pluck(:issue_id)
     @ll =
     @k = Issue.where(:id=>@p).pluck(:consolidated_cost)
     @rate = @k[g].to_f / @ll.to_f
     @r = @rate.round(2)
     @arr[@k[g]] + [@r]
     g = g+1
   @total=@arr.inject(0){|sum,x| sum + x[1].to_i }
   @total1=@arr.inject(0){|sum,y| sum + y[2].to_i }
   @total2=@arr.inject(0){|sum,z| sum + z[3].to_i }

And my sample output page is attached as an image.. Pls look at it..

Shortly., I need to dynamically compute profit/loss based on the selling
price entered by the user. How could I achieve that.. Kindly pls help
me.. Thanks in advance..


Posted via http://www.ruby-forum.com/.

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fac8b2feb741452fcd76cc22ebe97dc6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
postedMar 21, '16 at 4:25a
activeMar 21, '16 at 4:25a

1 user in discussion

Poombavai Sivamani: 1 post



site design / logo © 2022 Grokbase