Here's my problem:
This particular table stores information about visits that clients have made so far
'Income' controller (basic summing) - by days/months/years
def index
@days = Visit.select("start_time,SUM(price) as price").group("strftime('%Y-%m-%d', start_time)").where(:start_time => DateTime.now.beginning_of_month..DateTime.now.end_of_month).where(:status => true).order('start_time DESC').all
@months = Visit.select("start_time,SUM(price) as price").group("strftime('%Y-%m', start_time)").where(:status => true).order('start_time DESC').all
@years = Visit.select("start_time,SUM(price) as price").group("strftime('%Y', start_time)").where(:status => true).order('start_time DESC').all
@total = 0
@years.collect { |x| @total = @total + x.price }
end
Switching to Postgres from sqlite made strftime impossible to use - I tried changing it to something like this:
@days = Visit.select("to_char(start_time, 'YYYY-MM-DD'),SUM(price) as price").group("to_char(start_time,'YYYY-MM-DD')").where(:start_time => DateTime.now.beginning_of_month..DateTime.now.end_of_month).where(:status => true).order("to_char(start_time,'YYYY-MM-DD') DESC").all
@months = Visit.select("to_char(start_time, 'YYYY-MM'),SUM(price) as price").group("to_char(start_time,'YYYY-MM')").where(:status => true).order("to_char(start_time,'YYYY-MM') DESC").all
@years = Visit.select("to_char(start_time, 'YYYY'),SUM(price) as price").group("to_char(start_time,'YYYY')").where(:status => true).order("to_char(start_time,'YYYY') DESC").all
But now I get error
missing start_time
in View:
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
<th class="text-center">Time period</th>
<th class="text-center">Sum</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2">days</th>
</tr>
<% @days.each do |s| %>
<tr>
<td><%= s.start_time.strftime('%d.%m.%Y') %></td>
<td class="text-right"><%= s.price %> eur</td>
</tr>
<% end %>
<tr>
<th colspan="2">months</th>
</tr>
<% @months.each do |s| %>
<tr>
<td><%= s.start_time.strftime('%m.%Y') %></td>
<td class="text-right"><%= s.price %> eur</td>
</tr>
<% end %>
<tr>
<th colspan="2">years</th>
</tr>
<% @years.each do |s| %>
<tr>
<td><%= s.start_time.strftime('%Y') %>r</td>
<td class="text-right"><%= s.price %> eur</td>
</tr>
<% end %>
<tr>
<th class="text-right">All</th>
<td class="text-right"><%= @total %> eur</td>
</tr>
</tbody>
</table>
I don't really understand why do I get such an error.