treasurer 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/treasurer/accounts.rb +18 -7
- data/lib/treasurer/analysis.rb +1 -1
- data/lib/treasurer/report.rb +89 -32
- data/treasurer.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35303062ab1213c78219bc4cee48f130315b8622
|
4
|
+
data.tar.gz: 3154086ac7c046ed468f065f0dd8157066335741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0709aac9aa7adfbd5f02e47df4ffa830b05f51e0f48e45ba9b26b3db90cdf593c2b80c220f8fe410783b7283916d084b95c8703491a0aff6572d77717957fa1f'
|
7
|
+
data.tar.gz: 2ce89966f7b2b7cec7c9b3a47dcda0eeed7cfe6a4584ce7e77d213dd6144a52056c934147d81a4d55dde60b7d936c6c2cbb426fe6749b15e928789c17428d6e8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/treasurer/accounts.rb
CHANGED
@@ -99,8 +99,9 @@ class Treasurer::Reporter
|
|
99
99
|
def red_line(date)
|
100
100
|
if Treasurer::LocalCustomisations.instance_methods.include? :red_line
|
101
101
|
val = super(name, date)
|
102
|
-
if rc = @report_currency
|
102
|
+
if rc = @reporter.report_currency and rc != @original_currency
|
103
103
|
er = EXCHANGE_RATES[[@original_currency,rc]]
|
104
|
+
#p ['AAAAAAA', name, @original_currency, er, val, rc]
|
104
105
|
val *= er
|
105
106
|
end
|
106
107
|
val
|
@@ -120,10 +121,15 @@ class Treasurer::Reporter
|
|
120
121
|
def has_balance?
|
121
122
|
not @runs.find{|r| not r.has_balance?}
|
122
123
|
end
|
123
|
-
def balance(date = @reporter.today)
|
124
|
+
def balance(date = @reporter.today, options={})
|
125
|
+
@balance_cache ||= {}
|
126
|
+
if b = @balance_cache[[date,options]]
|
127
|
+
return b
|
128
|
+
end
|
124
129
|
date_i = date.to_datetime.to_time.to_i
|
125
130
|
#if !date
|
126
131
|
#@runs.sort_by{|r| r.date}[-1].balance
|
132
|
+
balance = nil
|
127
133
|
if @external or not has_balance?
|
128
134
|
#p ['name is ', name, type]
|
129
135
|
#
|
@@ -140,8 +146,13 @@ class Treasurer::Reporter
|
|
140
146
|
else
|
141
147
|
#p ['name33 is ', name, type, @runs.size, @currency]
|
142
148
|
nearest_time = @runs.map{|r| (r.date_i - date_i).to_f.abs}.sort[0]
|
143
|
-
@runs.find_all{|r| (r.date_i - date_i).to_f.abs == nearest_time}.sort_by{|r| r.id}[-1].balance
|
149
|
+
balance = @runs.find_all{|r| (r.date_i - date_i).to_f.abs == nearest_time}.sort_by{|r| r.id}[-1].balance
|
150
|
+
end
|
151
|
+
if options[:original_currency] and @original_currency and @original_currency!=currency
|
152
|
+
balance = balance*EXCHANGE_RATES[[currency, @original_currency]]
|
144
153
|
end
|
154
|
+
@balance_cache[[date,options]]=balance
|
155
|
+
balance
|
145
156
|
end
|
146
157
|
def deposited(today, days_before, &block)
|
147
158
|
p ['name223344 is ', name_c, today, days_before]
|
@@ -284,7 +295,7 @@ EOF
|
|
284
295
|
#exit
|
285
296
|
@reporter.projected_account_factor = nil
|
286
297
|
kit += ( kit4 + kit5 + kit2)
|
287
|
-
kit.yrange = [(m = kit.data.map{|dk| dk.y.data.min}.min; m-m.abs*0.1), (m=kit.data.map{|dk| dk.y.data.max}.max; m+m.abs*0.1)]
|
298
|
+
#kit.yrange = [(m = kit.data.map{|dk| dk.y.data.min}.min; m-m.abs*0.1), (m=kit.data.map{|dk| dk.y.data.max}.max; m+m.abs*0.1)]
|
288
299
|
#kit += (kit2)
|
289
300
|
kit = kit3 + kit
|
290
301
|
kit.title = "Balance for #{name_c}"
|
@@ -317,9 +328,9 @@ EOF
|
|
317
328
|
|
318
329
|
fork do
|
319
330
|
(kit).gnuplot_write("#{name_c_file}_balance.eps", size: size) #, latex: true)
|
320
|
-
%x[
|
331
|
+
%x[epstopdf #{name_c_file}_balance.eps]
|
321
332
|
end
|
322
|
-
#%x[
|
333
|
+
#%x[epstopdf #{name}_balance.eps]
|
323
334
|
end
|
324
335
|
# A string to include the balance graph in the document
|
325
336
|
def balance_graph_string
|
@@ -355,7 +366,7 @@ EOF
|
|
355
366
|
else
|
356
367
|
0.0
|
357
368
|
end
|
358
|
-
}.sum
|
369
|
+
}.sum + sum_of_assets
|
359
370
|
end
|
360
371
|
def balance(date=@reporter.today)
|
361
372
|
@accounts.map{|acc|
|
data/lib/treasurer/analysis.rb
CHANGED
@@ -28,7 +28,7 @@ module Analysis
|
|
28
28
|
#ep ['account', account.name_c]
|
29
29
|
counter = 0
|
30
30
|
if not account.info[:period]
|
31
|
-
start_dates.push
|
31
|
+
start_dates.push (account.info[:start]||@start_date)
|
32
32
|
end_dates.push date
|
33
33
|
account_items.push items
|
34
34
|
expenditures.push (items.map{|r| (r.deposit - r.withdrawal) * (account.info[:external] ? -1 : 1)}+[0]).sum
|
data/lib/treasurer/report.rb
CHANGED
@@ -200,6 +200,7 @@ class Treasurer
|
|
200
200
|
report << footer
|
201
201
|
|
202
202
|
File.open('report.tex', 'w'){|f| f.puts report}
|
203
|
+
Process.wait
|
203
204
|
system "lualatex report.tex && lualatex report.tex"
|
204
205
|
end
|
205
206
|
def account_summaries
|
@@ -239,14 +240,24 @@ EOF
|
|
239
240
|
end
|
240
241
|
def expense_account_summary
|
241
242
|
<<EOF
|
242
|
-
\\section{Expense
|
243
|
+
\\section{Expense and Income Summary}
|
243
244
|
\\subsection{Totals for #@days_before-day Budget Period}
|
244
|
-
|
245
|
+
\\subsection{Expense}
|
246
|
+
#{expense_pie_charts_by_currency('accountperiod_expense', @expense_accounts){|r| r.days_ago(@today) < @days_before}}
|
247
|
+
\\subsection{Income}
|
248
|
+
#{expense_pie_charts_by_currency('accountperiod_income', @accounts.find_all{|acc| acc.type==:Income}){|r| r.days_ago(@today) < @days_before}}
|
245
249
|
\\subsection{Expense Account Breakdown}
|
246
250
|
#{@expense_accounts.find_all{|exaccount| exaccount.should_report?}.map{|exaccount|
|
247
251
|
account = exaccount.report_account
|
248
252
|
"
|
249
|
-
\\
|
253
|
+
\\subsubsection{#{account.name_c}}
|
254
|
+
#{expense_pie_chart(account.name_c_file + 'breakdown', account.sub_accounts, account){|r|r.days_ago(@today) < @days_before }}"
|
255
|
+
}.join("\n\n")}
|
256
|
+
\\subsection{Income Account Breakdown}
|
257
|
+
#{@accounts.find_all{|inaccount| inaccount.type==:Income and inaccount.should_report?}.map{|inaccount|
|
258
|
+
account = inaccount.report_account
|
259
|
+
"
|
260
|
+
\\subsubsection{#{account.name_c}}
|
250
261
|
#{expense_pie_chart(account.name_c_file + 'breakdown', account.sub_accounts, account){|r|r.days_ago(@today) < @days_before }}"
|
251
262
|
}.join("\n\n")}
|
252
263
|
EOF
|
@@ -284,21 +295,33 @@ EOF
|
|
284
295
|
start_dates = start_dates.reverse
|
285
296
|
pp ['DATES', start_dates, end_dates, subacc.name]
|
286
297
|
return "No expenditure in account period." if end_dates.size==0
|
298
|
+
#keylabels = []
|
287
299
|
k = (
|
288
300
|
end_dates.size.times.map do |i|
|
289
|
-
exps =
|
290
|
-
|
301
|
+
exps = []
|
302
|
+
if subacc.type==:Expense
|
303
|
+
exps = accounts.map{|acc| acc.deposited(end_dates[i], end_dates[i] - start_dates[i], &block)}
|
304
|
+
else
|
305
|
+
exps = accounts.map{|acc| acc.withdrawn(end_dates[i], end_dates[i] - start_dates[i], &block) -
|
306
|
+
acc.deposited(end_dates[i], end_dates[i] - start_dates[i], &block)
|
307
|
+
}
|
308
|
+
end
|
309
|
+
kt = GraphKit.quick_create([labels.size.times.to_a.map{|l| l.to_f + i.to_f/(end_dates.size+1).to_f}, exps])
|
291
310
|
kt.data[0].gp.title = "Ending #{end_dates[i].strftime("#{end_dates[i].mday.ordinalize} %B")}; total = #{exps.sum}"
|
292
|
-
kt.gp.key = "
|
311
|
+
kt.gp.key = "rmargin"
|
312
|
+
#keylabels.push "'Ending #{end_dates[i].strftime("#{end_dates[i].mday.ordinalize} %B")}; total = #{exps.sum}'"
|
313
|
+
#kt.gp.key = "off rotate by 90"
|
293
314
|
kt
|
294
315
|
end
|
295
316
|
).sum
|
296
317
|
k
|
297
318
|
else
|
298
|
-
exps = accounts.map{|acc| acc.deposited(@today, 50000, &block)}
|
319
|
+
exps = accounts.map{|acc| acc.type==:Expense ? acc.deposited(@today, 50000, &block) - acc.withdrawn(@today, 50000, &block): acc.withdrawn(@today, 50000, &block) - acc.deposited(@today, 50000, &block)}
|
299
320
|
labels, exps = [labels, exps].transpose.find_all{|l, e| e != 0.0}.transpose
|
300
321
|
return "No expenditure in account period." if not labels #<F8> labels.size==0
|
301
|
-
GraphKit.quick_create([labels.size.times.to_a, exps])
|
322
|
+
k = GraphKit.quick_create([labels.size.times.to_a, exps])
|
323
|
+
k.data[0].gp.title = "Cumulative over budget period. Total = #{exps.sum}"
|
324
|
+
k
|
302
325
|
end
|
303
326
|
|
304
327
|
|
@@ -315,20 +338,38 @@ EOF
|
|
315
338
|
kit.gp.yrange = "[#{[kit.data[0].y.data.min,0].min}:]"
|
316
339
|
#kit.gp.xrange = "[-1:#{labels.size+1}]"
|
317
340
|
kit.gp.xrange = "[-1:1]" if labels.size==1
|
318
|
-
kit.gp.
|
341
|
+
kit.gp.mytics = "5"
|
342
|
+
kit.gp.ytics = "autofreq rotate by 45"
|
343
|
+
kit.gp.grid = "ytics mytics lw 2,lw 1"
|
319
344
|
kit.xlabel = nil
|
320
345
|
kit.ylabel = nil
|
321
346
|
i = -1
|
322
|
-
kit.gp.xtics = "(#{labels.map{|l| %["#{l}" #{i+=1}]}.join(', ')}) rotate by
|
347
|
+
kit.gp.xtics = "(#{labels.map{|l| %["#{l}" #{i+=1}]}.join(', ')}) rotate by 90 right"
|
323
348
|
pp ['kit222', kit, labels]
|
324
349
|
fork do
|
325
|
-
|
326
|
-
|
350
|
+
|
351
|
+
kit.gp.key = "off"
|
352
|
+
kit.gnuplot_write("#{name}.eps", size: "#{[[labels.size.to_f/4.5, 4.5].min, 1.0].max}in,4.5in")
|
353
|
+
kit.gp.key = "tmargin"
|
354
|
+
kit.gp.border = "unset"
|
355
|
+
kit.gp.xtics = "unset"
|
356
|
+
kit.gp.ytics = "unset"
|
357
|
+
kit.gp.title = "unset"
|
358
|
+
kit.gp.xlabel = "unset"
|
359
|
+
kit.gp.ylabel = "unset"
|
360
|
+
#kit.gp.xrange = "[-100:-10]"
|
361
|
+
kit.gp.boxwidth = "#{0.0/kit.data.size} absolute"
|
362
|
+
kit.gp.object = " rect from screen 0, screen 0 to screen 1, graph 1 front fc rgb 'white' fillstyle solid noborder"
|
363
|
+
#kit.gp.style = "fill empty noborder"
|
364
|
+
#kit.gp.yrange = "[-10:10]"
|
365
|
+
kit.gnuplot_write("#{name}_key.eps", size: "4.0in,1.5in")
|
366
|
+
%x[convert -density 500 #{name}_key.eps -resize 4000 -bordercolor white -border 20x20 -background white -flatten -trim +repage #{name}_key.pdf]
|
367
|
+
#%x[convert -density 500 #{name}.eps -resize 4000 -bordercolor white -border 20x20 -background white -flatten -trim +repage #{name}.pdf]
|
327
368
|
end
|
328
369
|
|
329
370
|
#"\\begin{center}\\includegraphics[width=3.0in]{#{name}.eps}\\vspace{1em}\\end{center}"
|
330
371
|
#"\\begin{center}\\includegraphics[width=0.9\\textwidth]{#{name}.eps}\\vspace{1em}\\end{center}"
|
331
|
-
"\\
|
372
|
+
"\\myfigurerot{#{name}.eps}{#{name}_key.pdf}{270}"
|
332
373
|
end
|
333
374
|
def get_in_limit_discretionary_account_factor(currency)
|
334
375
|
@projected_account_factor = 1.0
|
@@ -380,13 +421,17 @@ EOF
|
|
380
421
|
\\section{Discretionary Budget Summary (#{currency})}
|
381
422
|
\\begin{tabulary}{0.9\\textwidth}{ R | r r r r }
|
382
423
|
Budget & Average & Projection & Limit & Stable \\\\
|
383
|
-
#{
|
424
|
+
#{tls = [0.0, 0.0, 0.0, 0.0]
|
425
|
+
discretionary_accounts.map{|account, info|
|
384
426
|
#ep info
|
385
|
-
|
386
|
-
(account.projection * @in_limit_discretionary_account_factors[currency]).
|
387
|
-
#{(account.projection * @stable_discretionary_account_factors[currency]).
|
427
|
+
"#{account.name_c} & #{(tls[0]+=account.average).to_tex} & #{(tls[1]+=account.projection).to_tex} & #{
|
428
|
+
(tls[2]+=account.projection * @in_limit_discretionary_account_factors[currency]).to_tex} &
|
429
|
+
#{(tls[3]+=account.projection * @stable_discretionary_account_factors[currency]).to_tex} \\\\"
|
388
430
|
}.join("\n\n")
|
389
431
|
}
|
432
|
+
\\\\
|
433
|
+
\\hline
|
434
|
+
Totals & #{tls.map{|v| v.to_tex}.join(" & ")}
|
390
435
|
\\end{tabulary}
|
391
436
|
EOF
|
392
437
|
end
|
@@ -450,7 +495,7 @@ EOF
|
|
450
495
|
#ep ['kit1122', account, kit]
|
451
496
|
fork do
|
452
497
|
kit.gnuplot_write("#{account.name_c_file}.eps", size: "4.0in,2.0in")
|
453
|
-
exec "
|
498
|
+
exec "epstopdf #{account.name_c_file}.eps"
|
454
499
|
end
|
455
500
|
#%x[ps2eps #{account}.ps]
|
456
501
|
#"\\begin{center}\\includegraphics[width=3.0in]{#{account}.eps}\\vspace{1em}\\end{center}"
|
@@ -597,9 +642,9 @@ EOF
|
|
597
642
|
|
598
643
|
def header
|
599
644
|
<<EOF
|
600
|
-
\\documentclass[a5paper]{article}
|
601
|
-
%\\usepackage[scale=0.
|
602
|
-
\\usepackage[left=
|
645
|
+
\\documentclass[a5paper, 10pt]{article}
|
646
|
+
%\\usepackage[scale=0.92]{geometry}
|
647
|
+
\\usepackage[left=0.9cm,top=0.9cm,right=0.9cm,bottom=0.5cm,nohead,includefoot]{geometry}
|
603
648
|
%\\usepackage[cm]{fullpage}
|
604
649
|
\\usepackage{tabulary}
|
605
650
|
\\usepackage{graphicx}
|
@@ -607,10 +652,22 @@ EOF
|
|
607
652
|
\\usepackage{hyperref}
|
608
653
|
\\usepackage{libertine}
|
609
654
|
\\usepackage{xcolor,listings}
|
655
|
+
\\usepackage{epstopdf}
|
610
656
|
\\newcommand\\Tstrut{\\rule{0pt}{2.8ex}}
|
657
|
+
\\newcommand\\myfigurerot[3]{\\vspace*{1em}\\begin{center}
|
658
|
+
|
659
|
+
\\begin{minipage}{\\textwidth}
|
660
|
+
\\includegraphics[clip,height=0.90\\textwidth,angle=#3]{#1}
|
661
|
+
|
662
|
+
\\hfill
|
663
|
+
\\includegraphics[width=0.5\\textwidth]{#2}
|
664
|
+
\\end{minipage}
|
665
|
+
\\end{center}\\vspace*{0em}
|
666
|
+
|
667
|
+
}
|
611
668
|
\\newcommand\\myfigure[1]{\\vspace*{1em}\\begin{center}
|
612
669
|
|
613
|
-
\\includegraphics[width=0.
|
670
|
+
\\includegraphics[clip,width=0.90\\textwidth]{#1}
|
614
671
|
|
615
672
|
\\end{center}\\vspace*{0em}
|
616
673
|
|
@@ -621,16 +678,16 @@ identifierstyle = \\ttfamily\\color{purple},
|
|
621
678
|
keywordstyle=\\ttfamily\\color{blue},
|
622
679
|
stringstyle=\\color{orange}}
|
623
680
|
\\usepackage[compact]{titlesec}
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
681
|
+
%\\titlespacing{\\section}{0pt}{*0}{*0}
|
682
|
+
%\\titlespacing{\\subsection}{0pt}{*0}{*2}
|
683
|
+
%\\titlespacing{\\subsubsection}{0pt}{*0}{*0}
|
684
|
+
%\\setlength{\\parskip}{0pt}
|
685
|
+
%\\setlength{\\parsep}{0pt}
|
686
|
+
%\\setlength{\\headsep}{0pt}
|
687
|
+
%\\setlength{\\topskip}{0pt}
|
688
|
+
%\\setlength{\\topmargin}{0pt}
|
689
|
+
%\\setlength{\\topsep}{0pt}
|
690
|
+
%\\setlength{\\partopsep}{0pt}
|
634
691
|
\\begin{document}
|
635
692
|
\\title{Budget Report from #{@start_date.strftime("%A #{@start_date.day.ordinalize} of %B %Y")} to #{@today.strftime("%A #{@today.day.ordinalize} of %B %Y")}}
|
636
693
|
\\author{With projections to #{@end_date.strftime("%A #{@end_date.day.ordinalize} of %B %Y")}}
|
data/treasurer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: treasurer 0.
|
5
|
+
# stub: treasurer 0.8.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "treasurer".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.8.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|