Class: Vfwcash::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/vfwcash/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Controller

Returns a new instance of Controller.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vfwcash/controller.rb', line 10

def initialize(date)
  @config = Vfwcash.config
  require_relative './sqlite_base'
  @date = date
  Dir.glob(File.join(LibPath,'models/*')).each do |file|
    require file
  end
  @cash = Gcash.new(@config)
  unless @cash.dates.include?(@date)
    puts "No transactions exist for #{@date.beginning_of_month}"
    exit(0)
  end
end

Instance Attribute Details

#cashObject

Returns the value of attribute cash.



9
10
11
# File 'lib/vfwcash/controller.rb', line 9

def cash
  @cash
end

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/vfwcash/controller.rb', line 9

def config
  @config
end

Instance Method Details

#auditObject



68
69
70
71
72
73
# File 'lib/vfwcash/controller.rb', line 68

def audit
  pdf = Audit.new(@date,@cash)
  filename = "#{PWD}/pdf/audit_#{Vfwcash.yyyymm(@date.beginning_of_quarter)}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#balanceObject



75
76
77
78
79
80
# File 'lib/vfwcash/controller.rb', line 75

def balance
  pdf = Balance.new(@date,@cash)
  filename = "#{PWD}/pdf/balance_#{Vfwcash.yyyymm(@date)}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#between(from, to) ⇒ Object



32
33
34
35
36
37
# File 'lib/vfwcash/controller.rb', line 32

def between(from,to)
  pdf = Between.new(@date,@cash,from,to)
  filename = "#{PWD}/pdf/between_#{from}_#{to}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#cb_registerObject



54
55
56
57
58
59
# File 'lib/vfwcash/controller.rb', line 54

def cb_register
  pdf = RegisterPdf.new(@date,@cash)
  filename = "#{PWD}/pdf/register_#{Vfwcash.yyyymm(@date)}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#ledgerObject



39
40
41
42
43
44
# File 'lib/vfwcash/controller.rb', line 39

def ledger
  pdf = Ledger.new(@date,@cash)
  filename = "#{PWD}/pdf/ledger_#{Vfwcash.yyyymm(@date)}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#open_pdf(filename) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/vfwcash/controller.rb', line 82

def open_pdf(filename)
  if Gem::Platform.local.os == 'darwin'
    `open #{filename}`
  else
    `start #{filename}`
  end
end

#profit_loss(options) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/vfwcash/controller.rb', line 24

def profit_loss(options)
  report =  @cash.profit_loss(options)
  pdf = ProfitLoss.new(report)
  filename = "#{PWD}/pdf/pl_#{report['options'][:from]}_#{report['options'][:to]}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#splitObject



61
62
63
64
65
66
# File 'lib/vfwcash/controller.rb', line 61

def split
  pdf = SplitLedger.new(@date,@cash)
  filename = "#{PWD}/pdf/split_#{Vfwcash.yyyymm(@date)}.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end

#summaryObject



46
47
48
49
50
51
# File 'lib/vfwcash/controller.rb', line 46

def summary
  pdf = Summary.new(@cash)
  filename = "#{PWD}/pdf/ledger_summary.pdf"
  pdf.render_file(filename)
  open_pdf(filename)
end