Hi all, I have a billing application in which I want to create a matrix-type view of period billings by accounting number and by period. It's almost working, but not quite, and I'm not Rails-savvy enough to take it further. Can anyone point me in the right direction? Thanks in advance! -Katie
The app is on github so you can see the models, joins, etc: https://github.com/sdstoic/billing/tree/master/app
CONTROLLER (period_billings):
def period_billings @sla = Sla.find(params[:sla_id]) @current_period = PeriodCounter.first.period.pe_number @period_billings = @sla.period_billings.sort_by { |pb| [pb.period.pe_number, pb.general_ledger.general_ledger_number] } @billings = Array.new(@period_billings.collect { |pb| pb.general_ledger.general_ledger_number }).uniq.sort_by { |gl| gl } @periods = Period.where("fiscal_year = ?", @sla.fiscal_year) @general_ledgers = GeneralLedger.sla_related @total_period_billings = @sla.period_billings.group_by(&:general_ledger_id) #@sum_current_amt = @sla.period_billings.sum(current_amt).group_by(&:general_ledger_id) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @period_billings } end end
VIEW (_period_billings.html.erb):
<% @cumulative_total = 0 %>
<div id="gl_crosstab"> <table> <tr> <th>Period</th> <% @general_ledgers.each do |g| %> <th><%= g.general_ledger_number %></th> <% end %> <th>Total</th> <th>% Expended</th> </tr> <% @period_billings.group_by(&:general_ledger_id).each do |pb| %> <tr> <td><%= pb[1].first.period.pe_number %></td> <% pb[1].each do |p| %> <td> <% @sum_current_amt = pb[1].inject(0){|sum,p| sum + p.current_amt.to_i} %> <%= number_to_currency(@sum_current_amt) %> </td> <% end %> <td> <% @cumulative_total = @cumulative_total + pb[1].inject(0){| sum,billing| sum+billing.current_amt.to_i} %> <%= number_to_currency( @cumulative_total ) %> </td> <td><%= number_to_currency((@cumulative_total/ @sla.project_total)*100) %> % </td> </tr> <% end %>
</table> </div>