Class: Avmtrf1::Forponto::User::Balance

Inherits:
Object
  • Object
show all
Includes:
EacRubyUtils::SimpleCache
Defined in:
lib/avmtrf1/forponto/user/balance.rb

Defined Under Namespace

Classes: MyBalance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Balance

Returns a new instance of Balance.


11
12
13
14
# File 'lib/avmtrf1/forponto/user/balance.rb', line 11

def initialize(user)
  @user = user
  build_balances
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.


9
10
11
# File 'lib/avmtrf1/forponto/user/balance.rb', line 9

def user
  @user
end

Instance Method Details

#credito_leftObject


40
41
42
# File 'lib/avmtrf1/forponto/user/balance.rb', line 40

def credito_left
  months_balances.inject(0) { |a, e| a + e.credito.left }
end

#debito_leftObject


36
37
38
# File 'lib/avmtrf1/forponto/user/balance.rb', line 36

def debito_left
  months_balances.inject(0) { |a, e| a + e.debito.left }
end

#head_monthObject


30
31
32
33
34
# File 'lib/avmtrf1/forponto/user/balance.rb', line 30

def head_month
  today = ::Date.today
  date = ::Date.civil(today.year, today.month, 1)
  user.month(date.year, date.month)
end

#months_balances_uncachedObject


16
17
18
# File 'lib/avmtrf1/forponto/user/balance.rb', line 16

def months_balances_uncached
  sorted_months.map { |m| MyBalance.new(m) }
end

#saldo_leftObject


44
45
46
# File 'lib/avmtrf1/forponto/user/balance.rb', line 44

def saldo_left
  credito_left - debito_left
end

#sorted_months_uncachedObject


20
21
22
23
24
25
26
27
28
# File 'lib/avmtrf1/forponto/user/balance.rb', line 20

def sorted_months_uncached
  r = []
  current = head_month
  while current.present?
    r << current
    current = current.parent_month
  end
  r.reverse
end