Class: Movement
- Inherits:
-
Entity
- Object
- Entity
- Movement
- Defined in:
- lib/africompta/entities/movement.rb
Instance Method Summary collapse
- #account_dst ⇒ Object
-
#account_src ⇒ Object
Copying over data from old AfriCompta.
- #data_set(f, v) ⇒ Object
- #delete ⇒ Object
- #get_index ⇒ Object
- #get_other_account(account) ⇒ Object
- #get_value(account) ⇒ Object
- #init_instance ⇒ Object
- #is_in_account(a) ⇒ Object
- #move_from_to(from, to) ⇒ Object
- #new_index ⇒ Object
- #set(desc, date, value, source, dest) ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #value=(v) ⇒ Object
- #value_form ⇒ Object
Instance Method Details
#account_dst ⇒ Object
274 275 276 |
# File 'lib/africompta/entities/movement.rb', line 274 def account_dst account_dst_id end |
#account_src ⇒ Object
Copying over data from old AfriCompta
270 271 272 |
# File 'lib/africompta/entities/movement.rb', line 270 def account_src account_src_id end |
#data_set(f, v) ⇒ Object
175 176 177 178 179 180 181 |
# 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 ⇒ Object
278 279 280 281 282 283 284 285 286 287 |
# 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 ⇒ Object
191 192 193 |
# File 'lib/africompta/entities/movement.rb', line 191 def get_index return self.rev_index end |
#get_other_account(account) ⇒ Object
216 217 218 |
# File 'lib/africompta/entities/movement.rb', line 216 def get_other_account(account) account_src == account ? account_dst : account_src end |
#get_value(account) ⇒ Object
209 210 211 212 213 214 |
# 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 ⇒ Object
172 173 |
# File 'lib/africompta/entities/movement.rb', line 172 def init_instance end |
#is_in_account(a) ⇒ Object
195 196 197 |
# 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) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 |
# 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 ⇒ Object
183 184 185 186 187 188 189 |
# 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) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# 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 ⇒ Object
265 266 267 |
# File 'lib/africompta/entities/movement.rb', line 265 def to_json ActiveSupport::JSON.encode(:str => to_s) end |
#to_s ⇒ Object
257 258 259 260 261 262 263 |
# 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) ⇒ Object
199 200 201 202 203 204 205 206 207 |
# 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 ⇒ Object
289 290 291 |
# File 'lib/africompta/entities/movement.rb', line 289 def value_form Account.total_form(value) end |