Class: Movement

Inherits:
Entity
  • Object
show all
Defined in:
lib/africompta/entities/movement.rb

Instance Method Summary collapse

Instance Method Details

#account_dstObject



274
275
276
# File 'lib/africompta/entities/movement.rb', line 274

def 
  
end

#account_srcObject

Copying over data from old AfriCompta



270
271
272
# File 'lib/africompta/entities/movement.rb', line 270

def 
  
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

#deleteObject



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 = , 
  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_indexObject



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 ()
   ==  ?  : 
end

#get_value(account) ⇒ Object



209
210
211
212
213
214
# File 'lib/africompta/entities/movement.rb', line 209

def get_value()
   = ( ==  ? -1 : 1)
  dputs(5) { "account_src #{.inspect} == account #{.inspect}" }
  dputs(5) { "Account_side = #{}" }
  value.to_f * .multiplier.to_f * 
end

#init_instanceObject



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 (a)
  return (a ==  or a == )
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  == from
    self. = to
  end
  if  == from
    self. = to
  end
  self.value = v
end

#new_indexObject



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., self. = 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_jsonObject



265
266
267
# File 'lib/africompta/entities/movement.rb', line 265

def to_json
  ActiveSupport::JSON.encode(:str => to_s)
end

#to_sObject



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" +
      .global_id.to_s + "\t" +
      .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  and 
    dputs(3) { 'value=' + v.to_s + ':' + .total.to_s }
    diff = value.to_f - v.to_f
    .total = .total.to_f + (diff * .multiplier)
    .total = .total.to_f - (diff * .multiplier)
  end
  data_set(:_value, v)
end

#value_formObject



289
290
291
# File 'lib/africompta/entities/movement.rb', line 289

def value_form
  Account.total_form(value)
end