class Movement
Public Instance Methods
account_dst()
click to toggle source
# File lib/africompta/entities/movement.rb, line 274 def account_dst account_dst_id end
account_src()
click to toggle source
Copying over data from old AfriCompta
# File lib/africompta/entities/movement.rb, line 270 def account_src account_src_id end
data_set(f, v)
click to toggle source
Calls superclass method
# File lib/africompta/entities/movement.rb, line 175 def data_set(f, v) if f != :_rev_index dputs(3){"Updating index for field #{f.inspect}"} new_index end super(f, v) end
delete()
click to toggle source
Calls superclass method
# File lib/africompta/entities/movement.rb, line 278 def delete dputs(DEBUG_SLOW) { "Deleting movement #{desc}" } src, dst = account_src, account_dst dputs(3) { "totals before: #{src.get_path}=#{src.total}, " + "#{dst.get_path}=#{dst.total}" } self.value = 0 dputs(3) { "totals after: #{src.get_path}=#{src.total}, " + "#{dst.get_path}=#{dst.total}" } super end
get_index()
click to toggle source
# File lib/africompta/entities/movement.rb, line 191 def get_index return self.rev_index end
get_other_account(account)
click to toggle source
# File lib/africompta/entities/movement.rb, line 216 def get_other_account(account) account_src == account ? account_dst : account_src end
get_value(account)
click to toggle source
# File lib/africompta/entities/movement.rb, line 209 def get_value(account) account_side = (account_src == account ? -1 : 1) dputs(5) { "account_src #{account_src.inspect} == account #{account.inspect}" } dputs(5) { "Account_side = #{account_side}" } value.to_f * account.multiplier.to_f * account_side end
init_instance()
click to toggle source
# File lib/africompta/entities/movement.rb, line 172 def init_instance end
is_in_account(a)
click to toggle source
# File lib/africompta/entities/movement.rb, line 195 def is_in_account(a) return (a == account_src or a == account_dst) end
move_from_to(from, to)
click to toggle source
# File lib/africompta/entities/movement.rb, line 220 def move_from_to(from, to) v = self.value self.value = 0 if account_src_id == from self.account_src_id = to end if account_dst_id == from self.account_dst_id = to end self.value = v end
new_index()
click to toggle source
# File lib/africompta/entities/movement.rb, line 183 def new_index u_l = Users.match_by_name('local') self.rev_index = u_l.movement_index.to_i u_l.movement_index = self.rev_index + 1 dputs(3) { "index is #{self.rev_index} and date is --#{self.date}--" } dputs(3) { "User('local').rev_index is: " + Users.match_by_name('local').movement_index.to_s } end
set(desc, date, value, source, dest)
click to toggle source
# File lib/africompta/entities/movement.rb, line 232 def set(desc, date, value, source, dest) dputs(3) { 'self.value ' + self.value.to_s + ' - ' + value.to_s } self.value = 0 self.account_src_id, self.account_dst_id = source, dest if false # Do some date-magic, so that we can give either the day, day and month or # a complete date. The rest is filled up with todays date. date = date.split('/') da = Date.today d = [da.day, da.month, da.year] date += d.last(3 - date.size) if date[2].to_s.size > 2 self.date = Date.strptime(date.join('/'), '%d/%m/%Y') else self.date = Date.strptime(date.join('/'), '%d/%m/%y') end else self.date = Date.from_s(date.to_s) end self.desc, self.value = desc, value dputs(DEBUG_SLOW) { 'Getting new index' } self.new_index dputs(DEBUG_SLOW) { 'Date ' + self.date.to_s } end
to_json()
click to toggle source
# File lib/africompta/entities/movement.rb, line 265 def to_json ActiveSupport::JSON.encode(:str => to_s) end
to_s()
click to toggle source
# File lib/africompta/entities/movement.rb, line 257 def to_s dputs(5) { "I am: #{to_hash.inspect} - my id is: #{global_id}" } "#{desc}\r#{global_id}\t" + "#{sprintf('%.3f', value.to_f.round(3))}\t#{date.to_s}\t" + account_src.global_id.to_s + "\t" + account_dst.global_id.to_s end
value=(v)
click to toggle source
# File lib/africompta/entities/movement.rb, line 199 def value=(v) if account_src and account_dst dputs(3) { 'value=' + v.to_s + ':' + account_src.total.to_s } diff = value.to_f - v.to_f account_src.total = account_src.total.to_f + (diff * account_src.multiplier) account_dst.total = account_dst.total.to_f - (diff * account_dst.multiplier) end data_set(:_value, v) end
value_form()
click to toggle source
# File lib/africompta/entities/movement.rb, line 289 def value_form Account.total_form(value) end