Class: OpenTableExplorer::Finance::TaxForm

Inherits:
Object
  • Object
show all
Extended by:
Assertions::ClassMethods, ClassMethods
Includes:
OpenTableExplorer, Constants, Assertions
Defined in:
app/models/tax_form.rb

Overview

Constants

Defined Under Namespace

Modules: Assertions, ClassMethods, Examples

Constant Summary

Constants included from Constants

Constants::Command, Constants::Data_source_directory, Constants::Default_tax_year, Constants::OTS_template_filename, Constants::Open_Tax_Filler_Directory, Constants::Open_tax_solver_binary, Constants::Open_tax_solver_data_directory, Constants::Open_tax_solver_directory, Constants::Open_tax_solver_input, Constants::Open_tax_solver_sysout

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_post_conditions, assert_pre_conditions

Methods included from Assertions

#assert_build, #assert_fdf_to_pdf, #assert_json_to_fdf, #assert_open_tax_solver, #assert_pdf_to_jpeg, #assert_post_conditions, #assert_pre_conditions

Constructor Details

#initialize(taxpayer = 'example', form = '1040', jurisdiction = :US, tax_year = Finance::Constants::Default_tax_year, open_tax_solver_data_directory = nil) ⇒ TaxForm

Returns a new instance of TaxForm.


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/tax_form.rb', line 39

def initialize(taxpayer='example', form='1040',
			jurisdiction=:US,
			tax_year=Finance::Constants::Default_tax_year,
			open_tax_solver_data_directory=nil
 )
	@taxpayer=taxpayer.to_s
	@form=form
	@jurisdiction=jurisdiction # :US, or :CA
	@tax_year=tax_year
	@open_tax_solver_directory=Dir["../OpenTaxSolver#{@tax_year}_*"].sort[-1]
	@form_filename="#{@jurisdiction.to_s}_#{@form}"
	if open_tax_solver_data_directory.nil? then
		@open_tax_solver_data_directory="#{@open_tax_solver_directory}/examples_and_templates/#{@form_filename}/"
	else
		@open_tax_solver_data_directory=open_tax_solver_data_directory+"/#{@form_filename}/"
	end #if
	@taxpayer_basename="#{@form_filename}_#{@taxpayer}"
	@taxpayer_basename_with_year=@form_filename+'_'+@tax_year.to_s+'_'+@taxpayer
	if File.exists?(@open_tax_solver_data_directory+'/'+@taxpayer_basename_with_year+'.txt') then
		@taxpayer_basename=@taxpayer_basename_with_year
	end #if
	@open_tax_solver_binary="#{@open_tax_solver_directory}/bin/taxsolve_#{@form_filename}_#{@tax_year}"
	@open_tax_solver_input="#{@open_tax_solver_data_directory}/#{@taxpayer_basename}.txt"
	@open_tax_solver_output="#{@open_tax_solver_data_directory}/#{@taxpayer_basename}_out.txt"
	@open_tax_solver_sysout="#{@open_tax_solver_data_directory}/#{@taxpayer_basename}_sysout.txt"
	@output_pdf="#{@open_tax_solver_data_directory}/taxes/#{@taxpayer_basename}_otff.pdf"
	
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form


33
34
35
# File 'app/models/tax_form.rb', line 33

def form
  @form
end

#form_filenameObject (readonly)

Returns the value of attribute form_filename


33
34
35
# File 'app/models/tax_form.rb', line 33

def form_filename
  @form_filename
end

#jurisdictionObject (readonly)

Returns the value of attribute jurisdiction


33
34
35
# File 'app/models/tax_form.rb', line 33

def jurisdiction
  @jurisdiction
end

#open_tax_solver_binaryObject (readonly)

Returns the value of attribute open_tax_solver_binary


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_binary
  @open_tax_solver_binary
end

#open_tax_solver_data_directoryObject (readonly)

Returns the value of attribute open_tax_solver_data_directory


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_data_directory
  @open_tax_solver_data_directory
end

#open_tax_solver_directoryObject (readonly)

Returns the value of attribute open_tax_solver_directory


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_directory
  @open_tax_solver_directory
end

#open_tax_solver_inputObject (readonly)

Returns the value of attribute open_tax_solver_input


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_input
  @open_tax_solver_input
end

#open_tax_solver_outputObject (readonly)

Returns the value of attribute open_tax_solver_output


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_output
  @open_tax_solver_output
end

#open_tax_solver_to_filler_runObject (readonly)

Returns the value of attribute open_tax_solver_to_filler_run


33
34
35
# File 'app/models/tax_form.rb', line 33

def open_tax_solver_to_filler_run
  @open_tax_solver_to_filler_run
end

#ots_jsonObject (readonly)

Returns the value of attribute ots_json


33
34
35
# File 'app/models/tax_form.rb', line 33

def ots_json
  @ots_json
end

#ots_template_filenameObject (readonly)

Returns the value of attribute ots_template_filename


33
34
35
# File 'app/models/tax_form.rb', line 33

def ots_template_filename
  @ots_template_filename
end

#ots_to_json_runObject (readonly)

Returns the value of attribute ots_to_json_run


33
34
35
# File 'app/models/tax_form.rb', line 33

def ots_to_json_run
  @ots_to_json_run
end

#output_pdfObject (readonly)

Returns the value of attribute output_pdf


33
34
35
# File 'app/models/tax_form.rb', line 33

def output_pdf
  @output_pdf
end

#tax_yearObject (readonly)

Returns the value of attribute tax_year


33
34
35
# File 'app/models/tax_form.rb', line 33

def tax_year
  @tax_year
end

#taxpayer_basenameObject (readonly)

Returns the value of attribute taxpayer_basename


33
34
35
# File 'app/models/tax_form.rb', line 33

def taxpayer_basename
  @taxpayer_basename
end

#taxpayer_basename_with_yearObject (readonly)

Returns the value of attribute taxpayer_basename_with_year


33
34
35
# File 'app/models/tax_form.rb', line 33

def taxpayer_basename_with_year
  @taxpayer_basename_with_year
end

Instance Method Details

#buildObject

initialize


67
68
69
70
71
72
73
74
# File 'app/models/tax_form.rb', line 67

def build
	run_open_tax_solver
	run_ots_to_json
	run_json_to_fdf
	run_fdf_to_pdf
	run_pdf_to_jpeg
	self
end

#run_fdf_to_pdfObject

run_json_to_fdf


106
107
108
109
110
111
112
113
# File 'app/models/tax_form.rb', line 106

def run_fdf_to_pdf
#	assert_pathname_exists(@open_tax_solver_data_directory, @open_tax_solver_data_directory+' does not exist')
	@fdf_to_pdf_run=ShellCommands.new("pdftk #{Open_Tax_Filler_Directory}/#{@tax_year}/PDF/#{@otff_form}.pdf fill_form #{@fdf} output #{output_pdf}")
#	assert_pathname_exists(@open_tax_solver_data_directory+'Federal_f1040_otff.pdf', Dir[@open_tax_solver_data_directory+'*'].join(';'))
	@evince_run=ShellCommands.new("evince @open_tax_solver_data_directory+Federal_f1040_otff.pdf") if $VERBOSE
	@evince_run.assert_post_conditions if $VERBOSE
	self
end

#run_json_to_fdfObject

run_ots_to_json


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/tax_form.rb', line 89

def run_json_to_fdf
	form='Federal/f1040'
	form_filename=form.sub('/','_')
	if @jurisdiction==:US then
		@otff_form='Federal/f'+@form.to_s
	else
		@otff_form=@jurisdiction.to_s+'/f'+@form.to_s
	end #if
	@fdf='/tmp/output.fdf'
	output_pdf="#{@open_tax_solver_data_directory}/#{@taxpayer_basename_with_year}_otff.pdf"
	assert_pathname_exists(@ots_json)
	pdf_input="#{Open_Tax_Filler_Directory}/"
	assert_pathname_exists(@ots_json)
	command="nodejs #{Open_Tax_Filler_Directory}/script/apply_values.js #{Open_Tax_Filler_Directory}/#{@tax_year}/definition/#{@otff_form}.json #{Open_Tax_Filler_Directory}/#{@tax_year}/transform/#{@otff_form}.json #{@ots_json} > #{@fdf}"
	@json_to_fdf_run=ShellCommands.new(command)
	self
end

#run_open_tax_solverObject

build


75
76
77
78
79
80
# File 'app/models/tax_form.rb', line 75

def run_open_tax_solver

	command="#{@open_tax_solver_binary} #{@open_tax_solver_input} >#{@open_tax_solver_sysout}"
	@open_tax_solver_run=ShellCommands.new(command)
	self
end

#run_ots_to_jsonObject

run_open_tax_solver


81
82
83
84
85
86
87
88
# File 'app/models/tax_form.rb', line 81

def run_ots_to_json
	@open_tax_form_filler_ots_js="#{Open_Tax_Filler_Directory}/script/json_ots.js"
	@ots_json="#{@open_tax_solver_data_directory}/#{@taxpayer_basename}_OTS.json"
	command="nodejs #{@open_tax_form_filler_ots_js} #{@open_tax_solver_output} > #{@ots_json}"
	@ots_to_json_run=ShellCommands.new(command)
	assert_pathname_exists(@ots_json)
	self
end

#run_pdf_to_jpegObject

run_fdf_to_pdf


114
115
116
117
118
119
120
# File 'app/models/tax_form.rb', line 114

def run_pdf_to_jpeg
	
	@pdf_to_jpeg_run=ShellCommands.new("pdftoppm -jpeg  #{output_pdf} #{form_filename}")
	@display_jpeg_run=ShellCommands.new("display  Federal_f1040-1.jpg") if $VERBOSE
	@display_jpeg_run.assert_post_conditions if $VERBOSE
	self
end