#4 Si tengo claro que algo hago mal, decir tambien que el sql ataca a una tabla distinta de la que llamo desde TaskriskSearch.new(params[:search]) , no se si eso sera la causa del asunto, mañana mirare de meter mas codigo, pero esque me salen dudas sobre si active record puede jugar con 2 tablas no relacionadas y gestionarse un each do anidado dentro de otro (que cada uno seria una de esas 2 variables)
Basicamente cuando intento hacer:
en la clase:
def scope
Employee_Risks_Totals.where('building = ? AND supervisor_login_name= ? AND balance_date BETWEEN ? AND ?', @building_from, @manager, @date_from, @date_to).order('employee_name ASC, balance_date DESC')
end
en el controlador:
@resultados = ActiveRecord::Base.connection.execute("SELECT * FROM booker.funtion.risks")
@search = TaskriskSearch.new(params[:search])
@taskrisks = @search.scope
En la vista
<tbody>
<% arone = 0 %>
<% arthree = 0 %>
<% arseven = 0 %>
<% aryesterday = 0 %>
<% artotal = 0 %>
<% arcontrol = 1 %>
<% arfuturethree = 0 %>
<% arfutureseven = 0 %>
<% artotalfuture = 0 %>
<% artotalfuturecasilla = '' %>
<% final_name = 'new' %>
<% final_login_name = 'new' %>
<% final_building = 'new' %>
<% recommended_task = 'Coming Soon' %>
<% @taskrisks.each do |taskrisk| %>
<% if taskrisk.created_date_utc == (Date.today-1).to_s || arthree != 0 || arseven != 0 %>
<% if final_name != taskrisk.employee_name && final_name != 'new' %>
<% aryesterday = 0.5*arone %>
<% artotal = ((0.5*arone)+(0.3*arthree)+(0.2*arseven)) %>
<tr>
<td><%= final_name %></td>
<td><%= final_login_name %></td>
<td><%= final_building %></td>
<% if aryesterday < 3%>
<td bgcolor="#81F79F"><%= aryesterday %></td>
<% elsif aryesterday >= 3 && aryesterday < 10 %>
<td bgcolor="#F2F5A9"><%= aryesterday %></td>
<% elsif aryesterday > 10 && aryesterday < 20 %>
<td bgcolor="#FA5858"><%= aryesterday %></td>
<% elsif aryesterday >= 20%>
<td bgcolor="#848484"><%= aryesterday %></td>
<% end %>
<% if artotal < 3%>
<td bgcolor="#81F79F"><%= artotal %></td>
<% elsif artotal >= 3 && artotal < 10 %>
<td bgcolor="#F2F5A9"><%= artotal %></td>
<% elsif artotal >= 10 && artotal < 20 %>
<td bgcolor="#FA5858"><%= artotal %></td>
<% elsif artotal >= 20%>
<td bgcolor="#848484"><%= artotal %></td>
<% end %>
<% puts @resultado.first %>
<% @resultados.each do |res| %>
<% puts res.assessment %>
<% artotalfuture = ((0.5*(28800*res.assessment))+((0.3*arfuturethree)+(0.3*(28800*res.assessment)))+((0.2*arfutureseven)+(0.2*(28800*res.assessment)))) %>
<% if artotalfuture < 10 %>
<%= artotalfuturecasilla = artotalfuturecasilla + 'o ' + res.function_name %>
<td><%= artotalfuturecasilla %></td>
<% else %>
<td><%= artotalfuturecasilla %></td>
<% end %>
<% end %>
</tr>
<% arone = 0 %>
<% arthree = 0 %>
<% arseven = 0 %>
<% artotal = 0 %>
<% arcontrol = 1 %>
<% arfuturethree = 0 %>
<% arfutureseven = 0 %>
<% artotalfuture = 0 %>
<% artotalfuturecasilla = '' %>
<% final_name = 'new' %>
<% end %>
<% if taskrisk.created_date_utc == (Date.today-1).to_s %>
<% arone = arone + taskrisk.daily_risk %>
<% puts taskrisk.employee_name + 'UNO' + arone.to_s %>
<% end %>
<% end %>
<% if taskrisk.created_date_utc >= (3.days.ago.to_date.to_s).to_s %>
<% if taskrisk.created_date_utc >= (2.days.ago.to_date.to_s).to_s %>
<% arfuturethree = arfuturethree + taskrisk.daily_risk %>
<% end %>
<% arthree = arthree + taskrisk.daily_risk %>
<% end %>
<% if taskrisk.created_date_utc >= (7.days.ago.to_date.to_s).to_s %>
<% if taskrisk.created_date_utc >= (6.days.ago.to_date.to_s).to_s %>
<% arfutureseven = arfutureseven + taskrisk.daily_risk %>
<% end %>
<% arseven = arseven + taskrisk.daily_risk %>
<% final_name = taskrisk.employee_name %>
<% final_login_name = taskrisk.supervisor_login_name %>
<% final_building = taskrisk.building %>
<%end%>
<% end %>
<% aryesterday = 0.5*arone%>
<% artotal = ((0.5*arone)+(0.3*arthree)+(0.2*arseven)) %>
<tr>
<td><%= final_name %></td>
<td><%= final_login_name %></td>
<td><%= final_building %></td>
<% if aryesterday < 3%>
<td bgcolor="#81F79F"><%= aryesterday %></td>
<% elsif aryesterday >= 3 && aryesterday < 10 %>
<td bgcolor="#F2F5A9"><%= aryesterday %></td>
<% elsif aryesterday > 10 && aryesterday < 20 %>
<td bgcolor="#FA5858"><%= aryesterday %></td>
<% elsif aryesterday >= 20%>
<td bgcolor="#848484"><%= aryesterday %></td>
<% end %>
<% if artotal < 3%>
<td bgcolor="#81F79F"><%= artotal %></td>
<% elsif artotal >= 3 && artotal < 10 %>
<td bgcolor="#F2F5A9"><%= artotal %></td>
<% elsif artotal > 10 && artotal < 20 %>
<td bgcolor="#FA5858"><%= artotal %></td>
<% elsif artotal >= 20%>
<td bgcolor="#848484"><%= artotal %></td>
<% end %>
<% @resultados.each do |res| %>
<% puts res.assessment %>
<% artotalfuture = ((0.5*(28800*res.assessment))+((0.3*arfuturethree)+(0.3*(28800*res.assessment)))+((0.2*arfutureseven)+(0.2*(28800*res.assessment)))) %>
<% if artotalfuture < 10 %>
<%= artotalfuturecasilla = artotalfuturecasilla + 'o ' + res.function_name %>
<td><%= artotalfuturecasilla %></td>
<% else %>
<td><%= artotalfuturecasilla %></td>
<% end %>
<% end %>
</tr>
</tbody>
#4 Basicamente cuando intento mover el segundo each que se supone es un @resultados = ActiveRecord::Base.connection.execute("SELECT * FROM booker.funtion.risks") no muestra resultados