Class: AccountRoot

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

Class Method Summary collapse

Class Method Details

.accountsObject



585
586
587
# File 'lib/africompta/entities/account.rb', line 585

def self.accounts
  Accounts.(0)
end

.actualObject



573
574
575
# File 'lib/africompta/entities/account.rb', line 573

def self.actual
  self.accounts.find { |a| a.name == 'Root' }
end

.archiveObject



581
582
583
# File 'lib/africompta/entities/account.rb', line 581

def self.archive
  self.accounts.find { |a| a.name == 'Archive' }
end

.cleanObject



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/africompta/entities/account.rb', line 589

def self.clean
  count_mov, count_acc = 0, 0
  bad_mov, bad_acc = 0, 0
  log_msg 'Account.clean', 'starting to clean up'
  Movements.search_all_.each { |m|
    dputs(4) { "Testing movement #{m.inspect}" }
    if not m or not m.date or not m.desc or not m.value or
        not m.rev_index or not m. or not m.
      if m and m.desc
        log_msg 'Account.clean', "Bad movement: #{m.inspect}"
      end
      m.delete
      bad_mov += 1
    end
    if m.rev_index
      count_mov = [count_mov, m.rev_index].max
    end
  }
  Accounts.search_all_.each { |a|
    if (a. && (a. > 0)) && (!a.)
      log_msg 'Account.clean', "Account has unexistent parent: #{a.inspect}"
      a.delete
      bad_acc += 1
    end
    if !(a. || a.deleted)
      log_msg 'Account.clean', "Account has undefined parent: #{a.inspect}"
      a.delete
      bad_acc += 1
    end
    if a. == 0 || a. == nil
      if !((a.name =~ /(Root|Archive)/) || a.deleted)
        log_msg 'Account.clean', 'Account is in root but neither ' +
                                   "'Root' nor 'Archive': #{a.inspect}"
        a.delete
        bad_acc += 1
      end
    end
    if !a.rev_index
      log_msg 'Account.clean', "Didn't find rev_index for #{a.inspect}"
      a.new_index
      bad_acc += 1
    end
    count_acc = [count_acc, a.rev_index].max
  }

  # Check also whether our counters are OK
  u_l = Users.match_by_name('local')
  dputs(1) { "Movements-index: #{count_mov} - #{u_l.movement_index}" }
  dputs(1) { "Accounts-index: #{count_acc} - #{u_l.}" }
  @ul_mov, @ul_acc = u_l.movement_index, u_l.
  if count_mov > u_l.movement_index
    log_msg 'Account.clean', 'Error, there is a bigger movement! Fixing'
    u_l.movement_index = count_mov + 1
  end
  if count_acc > u_l.
    log_msg 'Account.clean', 'Error, there is a bigger account! Fixing'
    u_l. = count_acc + 1
  end
  return [count_mov, bad_mov, count_acc, bad_acc]
end

.currentObject



577
578
579
# File 'lib/africompta/entities/account.rb', line 577

def self.current
  AccountRoot.actual
end

.idObject



654
655
656
# File 'lib/africompta/entities/account.rb', line 654

def self.id
  0
end

.keep_totalObject



662
663
664
# File 'lib/africompta/entities/account.rb', line 662

def self.keep_total
  false
end

.multObject



658
659
660
# File 'lib/africompta/entities/account.rb', line 658

def self.mult
  1
end

.multiplierObject



666
667
668
# File 'lib/africompta/entities/account.rb', line 666

def self.multiplier
  1
end

.path_idObject



650
651
652
# File 'lib/africompta/entities/account.rb', line 650

def self.path_id
  return ''
end