Module: LogsHelper

Defined in:
app/helpers/logs_helper.rb

Instance Method Summary collapse

Instance Method Details

#cell(value) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/logs_helper.rb', line 3

def cell(value)
  if @mode == :edit
    "<input type='text' value='#{h value}' />"
  else
    "<div>#{h value}</div>"
  end
end

#make_table_data(account) ⇒ Object

returns [Date(2009/8/1), nil, nil, Income, ..]



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/logs_helper.rb', line 12

def make_table_data()
  condition = {
    :conditions => {:date => @month_range},
  }
  items = [
    .expenses.all(condition),
    .incomes.all(condition),
    .moves_from.all(condition),
    .moves_to.all(condition),
  ].flatten(1)

  @month_range.map{|today|
    todays, items = items.partition{|m| m.date == today}
    positions = todays.map(&:position)
    max_position = (positions.empty?) ? 0 : positions.max

    (0..max_position).map{|i|
      day = (i==0) ? today : :no_date
      [
        today,
        i,
        i == max_position, 
        @cat_all.map{|cat|
          todays.find{|m| m.category == cat && m.position == i}
        }.unshift(day)
      ]
    }
  }.flatten(1)
end