vfwcash 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5b7a58fa43c192b95fed4bf74681afd42feac1e
4
- data.tar.gz: 2e231cdb176989b019e35a9fbc2c960a575e8fda
3
+ metadata.gz: ecad30a1ccdfcc984f964d88abacc8da6c818b21
4
+ data.tar.gz: c555f9198c15bf59c7999195fcbd66ea0dc254ec
5
5
  SHA512:
6
- metadata.gz: 8f77bc7d021f09d39663a6165d67d654f036059cfa82e788044d50124cca4ef771df569e88e3cb21ab28497e1d1a19acc35b7a810424ad33daf5db695e4ea97e
7
- data.tar.gz: 108570a5feafc5b98c888eab59bb39108c646e9a5557848e2329856bfb2abded84b7b3261ba0785771338c7307192415b6208d9c68dcf3d04b2a83b41e1f7ec0
6
+ metadata.gz: 305c258d3d8246f8f5cc1b759e1c7de817d16628f9d7acf90384c834baf536ae9c5a807a62c73218da7f63f866cdbf9b934dd55c01e30e0ee417ae8ef294486d
7
+ data.tar.gz: dfb5d6612774fef53fef0e73d7cbd888206921f7058aa2d96d3046ecdfe4bf97b43b8bfa7fce66ae7c4dd775b038b9b1e317454e0bb8fa35630a834a743147f1
data/lib/models/audit.rb CHANGED
@@ -1,4 +1,3 @@
1
- module Pdf
2
1
  class Audit < Prawn::Document
3
2
  attr_accessor :cur, :config, :balances
4
3
  def initialize(date,cash)
@@ -225,4 +224,3 @@ class Audit < Prawn::Document
225
224
  end
226
225
 
227
226
  end
228
- end
@@ -1,4 +1,4 @@
1
- class Pdf::Balance < Prawn::Document
1
+ class Balance < Prawn::Document
2
2
  attr_accessor :cash, :date, :cwidths
3
3
 
4
4
  def initialize(date,cash)
@@ -1,4 +1,4 @@
1
- class Pdf::Between < Prawn::Document
1
+ class Between < Prawn::Document
2
2
  attr_accessor :cash, :date, :cwidths
3
3
 
4
4
  def initialize(date,cash,from,to)
@@ -11,7 +11,7 @@ class CashAccount < SqliteBase
11
11
  end
12
12
 
13
13
  def children
14
- CashAccount.where(parent_guid:self.guid)
14
+ CashAccount.where(parent_guid:self.guid).order(:name)
15
15
  end
16
16
 
17
17
  def account_ledger
data/lib/models/gcash.rb CHANGED
@@ -189,6 +189,39 @@ module Vfwcash
189
189
  lines
190
190
  end
191
191
 
192
+ def profit_loss(options)
193
+ today = Date.today
194
+ @from = options[:from].nil? ? today.beginning_of_month : Vfwcash.set_date(options[:from])
195
+ @to = options[:to].nil? ? today.end_of_month : Vfwcash.set_date(options[:to])
196
+ level = options[:lev]
197
+ i = CashAccount.find_by(name:'Income')
198
+ e = CashAccount.find_by(name:'Expenses')
199
+ report = {"Income" => {amount:period_splits(i),total:0,children:{}},
200
+ "Expense" => {amount:period_splits(e),total:0,children:{}},
201
+ "options" => {level:level,from:@from,to:@to}}
202
+ tree(i,report['Income'])
203
+ tree(e,report['Expense'])
204
+ return report
205
+ end
206
+
207
+
208
+ private
209
+
210
+ def tree(branch,hash)
211
+ branch.children.each do |c|
212
+ hash[:children][c.name] = {amount:period_splits(c),total:0,children: {}}
213
+ tree(c,hash[:children][c.name])
214
+ hash[:total] += (hash[:children][c.name][:amount] + hash[:children][c.name][:total])
215
+ end
216
+ end
217
+
218
+ def period_splits(acct)
219
+ flipper = acct.account_type == 'INCOME' ? -1 : 1
220
+ sp = acct.splits.joins(:tran).where('transactions.post_date between ? and ?',@from.strftime('%Y%m%d')+'00',@to.strftime('%Y%m%d')+'24')
221
+ sp.sum(:value_num) * flipper
222
+ end
223
+
224
+
192
225
  end
193
226
 
194
227
  end
data/lib/models/ledger.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Pdf::Ledger < Prawn::Document
1
+ class Ledger < Prawn::Document
2
2
  attr_accessor :response, :date, :cwidths
3
3
 
4
4
  def initialize(date,cash)
@@ -1,30 +1,118 @@
1
- class ProfitLoss
2
-
3
- attr_accessor :from, :to, :flipper, :report
4
-
5
- def generate(from,to)
6
- @from = Vfwcash.set_date(from)
7
- @to = Vfwcash.set_date(to)
8
- i = CashAccount.find_by(name:'Income')
9
- e = CashAccount.find_by(name:'Expenses')
10
- @report = {"Income" => {amount:period_splits(i),total:0,children:{}}, "Expense" => {amount:period_splits(e),total:0,children:{}}}
11
- tree(i,report['Income'])
12
- tree(e,report['Expense'])
13
- return self
14
- end
15
-
16
- def tree(branch,hash)
17
- branch.children.each do |c|
18
- hash[:children][c.name] = {amount:period_splits(c),total:0,children: {}}
19
- tree(c,hash[:children][c.name])
20
- hash[:total] += (hash[:children][c.name][:amount] + hash[:children][c.name][:total])
1
+
2
+ class ProfitLoss < Prawn::Document
3
+ attr_accessor :report, :level, :cur
4
+ COL = [140,210,280,350]
5
+ def initialize(report)
6
+ super(page_layout: :portrait, top_margin:32, left_margin:32, right_margin:32,bottom_margin:32)
7
+ level = 2 if level.nil?
8
+ @report = report
9
+ @level = @report['options'][:level]
10
+ from = @report['options'][:from]
11
+ to = @report['options'][:to]
12
+ font_size(14)
13
+ text "VFW Post 8600 Profit/Loss Report #{from} to #{to}", style: :bold, align: :center
14
+ move_down 6
15
+ font_size(9)
16
+ @cur = cursor.to_i
17
+ generate_report
18
+ end
19
+
20
+ def generate_report
21
+ total_row("Income",'','Increase')
22
+ pad = 1
23
+ children(pad,@report["Income"][:children])
24
+ total_row("Total Income",@report["Income"][:total])
25
+ pad = 1
26
+ total_row("Expenses",'','Decrease')
27
+ children(pad,@report["Expense"][:children])
28
+ total_row("Total Expenses",@report["Expense"][:total])
29
+ total_row("Profit(+)/Loss(-)",@report["Income"][:total] - @report["Expense"][:total])
30
+ end
31
+
32
+ def children(pad,kids)
33
+ kids.each do |k,v|
34
+ if v[:children].blank?
35
+ send "pad#{pad}#{@level}_row", k,v[:amount] unless v[:amount].zero?
36
+ else
37
+ # if @level == 1
38
+ if pad == @level
39
+ unless v[:total].zero?
40
+ send "pad#{pad}#{@level}_row",k,v[:total]+v[:amount]
41
+ end
42
+ else
43
+ unless v[:total].zero?
44
+ send "pad#{pad}#{@level}_row", k,v[:amount]
45
+ pad += 1
46
+ children(pad,v[:children])
47
+ pad -= 1
48
+ send "pad#{pad}#{@level}_row", "Total #{k}",v[:amount] + v[:total]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def total_row(name,amount,extra=nil)
56
+ text_box name, at: [0,@cur], width:140,align: :left, style: :bold
57
+ unless extra.nil?
58
+ text_box extra, at: [COL[@level - 1],@cur], width:70,align: :right, style: :bold
21
59
  end
60
+ text_box imoney(amount), at: [COL[@level],@cur], width:70,align: :right, style: :bold
61
+ @cur -= 9
62
+ end
63
+
64
+ def pad11_row(acct,amount)
65
+ text_box acct, at: [10,@cur], width:130,align: :left
66
+ text_box imoney(amount), at: [140,@cur], width:70,align: :right
67
+ @cur -= 9
68
+ end
69
+
70
+ def pad12_row(acct,amount)
71
+ text_box acct, at: [10,@cur], width:130,align: :left
72
+ text_box imoney(amount), at: [210,@cur], width:70,align: :right
73
+ @cur -= 9
22
74
  end
23
75
 
24
- def period_splits(acct)
25
- flipper = acct.account_type == 'INCOME' ? -1 : 1
26
- sp = acct.splits.joins(:tran).where('transactions.post_date between ? and ?',from.strftime('%Y%m%d')+'00',to.strftime('%Y%m%d')+'24')
27
- sp.sum(:value_num) * flipper
76
+ def pad22_row(acct,amount)
77
+ text_box acct, at: [20,@cur], width:120,align: :left
78
+ text_box imoney(amount), at: [140,@cur], width:70,align: :right
79
+ @cur -= 9
28
80
  end
29
81
 
82
+ # def pad32_row(acct,amount)
83
+ # text_box acct, at: [30,@cur], width:110,align: :left
84
+ # text_box imoney(amount), at: [140,@cur], width:70,align: :right
85
+ # @cur -= 9
86
+ # end
87
+
88
+
89
+ def pad13_row(acct,amount)
90
+ text_box acct, at: [10,@cur], width:130,align: :left
91
+ text_box imoney(amount), at: [280,@cur], width:70,align: :right
92
+ @cur -= 9
93
+ end
94
+
95
+ def pad23_row(acct,amount)
96
+ text_box acct, at: [20,@cur], width:120,align: :left
97
+ text_box imoney(amount), at: [210,@cur], width:70,align: :right
98
+ @cur -= 9
99
+ end
100
+
101
+ def pad33_row(acct,amount)
102
+ text_box acct, at: [30,@cur], width:100,align: :left
103
+ text_box imoney(amount), at: [140,@cur], width:70,align: :right
104
+ @cur -= 9
105
+ end
106
+
107
+ def imoney(int,dollar="$")
108
+ return '' if int.to_i.zero?
109
+ dollars = int / 100
110
+ cents = (int % 100) / 100.0
111
+ amt = dollars + cents
112
+ set_zero = sprintf('%.2f',amt) # now have a string to 2 decimals
113
+ '$'+set_zero.gsub(/(\d)(?=(\d{3})+(?!\d))/, "\\1,") # add commas
114
+ end
115
+
30
116
  end
117
+
118
+
@@ -1,4 +1,4 @@
1
- class Pdf::Register < Prawn::Document
1
+ class Register < Prawn::Document
2
2
  attr_accessor :response, :date
3
3
 
4
4
  def initialize(date,cash)
@@ -1,4 +1,4 @@
1
- class Pdf::SplitLedger < Prawn::Document
1
+ class SplitLedger < Prawn::Document
2
2
  attr_accessor :response, :date
3
3
 
4
4
  def initialize(date,cash)
@@ -1,4 +1,4 @@
1
- class Pdf::Summary < Prawn::Document
1
+ class Summary < Prawn::Document
2
2
  attr_accessor :cash, :date, :cwidths
3
3
 
4
4
  def initialize(cash)
data/lib/vfwcash.rb CHANGED
@@ -13,6 +13,7 @@ module Vfwcash
13
13
  config = YAML.load_file(ENV['VFWCASHCONFIG'])
14
14
  else
15
15
  config = YAML.load_file("#{PWD}/config/vfwcash.yml")
16
+
16
17
  end
17
18
  ENV['VFWCASHDATABASE'] = config[:database]
18
19
  return config
data/lib/vfwcash/api.rb CHANGED
@@ -16,35 +16,39 @@ module Vfwcash
16
16
  end
17
17
 
18
18
  def between(from,to)
19
- pdf = Pdf::Between.new(@date,@cash,from,to)
19
+ pdf = Between.new(@date,@cash,from,to)
20
20
  end
21
21
 
22
22
  def profit_loss(from,to)
23
23
  pl = ProfitLoss.new.generate(from,to)
24
24
  end
25
25
 
26
+ def profit_loss_new(options)
27
+ @cash.profit_loss(options)
28
+ end
29
+
26
30
  def ledger
27
- pdf = Pdf::Ledger.new(@date,@cash)
31
+ pdf = Ledger.new(@date,@cash)
28
32
  end
29
33
 
30
34
  def summary
31
- pdf = Pdf::Summary.new(@cash)
35
+ pdf = Summary.new(@cash)
32
36
  end
33
37
 
34
38
  def register
35
- pdf = Pdf::Register.new(@date,@cash)
39
+ pdf = Register.new(@date,@cash)
36
40
  end
37
41
 
38
42
  def split
39
- pdf = Pdf::SplitLedger.new(@date,@cash)
43
+ pdf = SplitLedger.new(@date,@cash)
40
44
  end
41
45
 
42
46
  def audit
43
- pdf = Pdf::Audit.new(@date,@cash)
47
+ pdf = Audit.new(@date,@cash)
44
48
  end
45
49
 
46
50
  def balance
47
- pdf = Pdf::Balance.new(@date,@cash)
51
+ pdf = Balance.new(@date,@cash)
48
52
  end
49
53
 
50
54
  end
data/lib/vfwcash/cli.rb CHANGED
@@ -2,6 +2,8 @@ require 'thor'
2
2
  # require 'vfwcash/cli/register'
3
3
  require 'chronic'
4
4
  require 'active_support'
5
+ require 'active_support/core_ext/object/blank'
6
+ require 'active_support/core_ext/date/calculations'
5
7
 
6
8
 
7
9
  module Vfwcash
@@ -14,7 +16,7 @@ module Vfwcash
14
16
  puts <<-DATE_HELP
15
17
  The DATE parameter is optional on all reports requiring a date and will default to the current date if not present.
16
18
 
17
- All dates will be converted to the first of the month requardless of the date entered.
19
+ Most dates will be converted to the first of the month requardless of the date entered.
18
20
 
19
21
  Entered dates are parsed using Chronic (https://github.com/mojombo/chronic).
20
22
  Chronic provide a wide range options.
@@ -49,6 +51,28 @@ module Vfwcash
49
51
  puts "Version: #{Vfwcash::VERSION}"
50
52
  end
51
53
 
54
+ ##### profit_loss
55
+ desc "profit_loss [--lev --from --to]","Generate profit/loss pdf with depth of --lev beteween dates --from and --to"
56
+ method_option :lev, type: :numeric,
57
+ desc: "Depth of account hiearchy",
58
+ required: false,
59
+ default: 2
60
+ method_option :from, type: :string,
61
+ required: false,
62
+ desc: "From date, defaults to first of current month"
63
+ method_option :to, type: :string,
64
+ required: false,
65
+ desc: "To date, defaults to end of current month"
66
+
67
+ def profit_loss
68
+ # puts "Generate profit_loss report with options #{options.inspect}"
69
+ Controller.new(Date.today).profit_loss(options)
70
+
71
+ # api = Api.new(Date.today.beginning_of_month)
72
+ # pl = api.cash.profit_loss(options)
73
+ # puts api.cash.profit_loss(options).inspect
74
+ end
75
+
52
76
  ######### INSTALL
53
77
  desc "install [--dir --db]", "Install config files and optional test DB in pwd or pwd/--dir"
54
78
  long_desc <<-HELLO_WORLD
@@ -21,22 +21,30 @@ module Vfwcash
21
21
  end
22
22
  end
23
23
 
24
+ def profit_loss(options)
25
+ report = @cash.profit_loss(options)
26
+ pdf = ProfitLoss.new(report)
27
+ filename = "#{PWD}/pdf/pl_#{report['options'][:from]}_#{report['options'][:to]}.pdf"
28
+ pdf.render_file(filename)
29
+ open_pdf(filename)
30
+ end
31
+
24
32
  def between(from,to)
25
- pdf = Pdf::Between.new(@date,@cash,from,to)
33
+ pdf = Between.new(@date,@cash,from,to)
26
34
  filename = "#{PWD}/pdf/between_#{from}_#{to}.pdf"
27
35
  pdf.render_file(filename)
28
36
  open_pdf(filename)
29
37
  end
30
38
 
31
39
  def ledger
32
- pdf = Pdf::Ledger.new(@date,@cash)
40
+ pdf = Ledger.new(@date,@cash)
33
41
  filename = "#{PWD}/pdf/ledger_#{Vfwcash.yyyymm(@date)}.pdf"
34
42
  pdf.render_file(filename)
35
43
  open_pdf(filename)
36
44
  end
37
45
 
38
46
  def summary
39
- pdf = Pdf::Summary.new(@cash)
47
+ pdf = Summary.new(@cash)
40
48
  filename = "#{PWD}/pdf/ledger_summary.pdf"
41
49
  pdf.render_file(filename)
42
50
  open_pdf(filename)
@@ -44,28 +52,28 @@ module Vfwcash
44
52
 
45
53
 
46
54
  def register
47
- pdf = Pdf::Register.new(@date,@cash)
55
+ pdf = Register.new(@date,@cash)
48
56
  filename = "#{PWD}/pdf/register_#{Vfwcash.yyyymm(@date)}.pdf"
49
57
  pdf.render_file(filename)
50
58
  open_pdf(filename)
51
59
  end
52
60
 
53
61
  def split
54
- pdf = Pdf::SplitLedger.new(@date,@cash)
62
+ pdf = SplitLedger.new(@date,@cash)
55
63
  filename = "#{PWD}/pdf/split_#{Vfwcash.yyyymm(@date)}.pdf"
56
64
  pdf.render_file(filename)
57
65
  open_pdf(filename)
58
66
  end
59
67
 
60
68
  def audit
61
- pdf = Pdf::Audit.new(@date,@cash)
69
+ pdf = Audit.new(@date,@cash)
62
70
  filename = "#{PWD}/pdf/audit_#{Vfwcash.yyyymm(@date.beginning_of_quarter)}.pdf"
63
71
  pdf.render_file(filename)
64
72
  open_pdf(filename)
65
73
  end
66
74
 
67
75
  def balance
68
- pdf = Pdf::Balance.new(@date,@cash)
76
+ pdf = Balance.new(@date,@cash)
69
77
  filename = "#{PWD}/pdf/balance_#{Vfwcash.yyyymm(@date)}.pdf"
70
78
  pdf.render_file(filename)
71
79
  open_pdf(filename)
@@ -1,3 +1,3 @@
1
1
  module Vfwcash
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/vfwcash-0.5.1.gem ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vfwcash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Alex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-06 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -172,6 +172,7 @@ files:
172
172
  - pdf_examples/views/checkbooks/split.html.slim
173
173
  - pdf_examples/views/checkbooks/summary.html.slim
174
174
  - vfwcash-0.5.0.gem
175
+ - vfwcash-0.5.1.gem
175
176
  - vfwcash.gemspec
176
177
  homepage: ''
177
178
  licenses: