Class: Liberic::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/liberic/process.rb

Overview

Process encapsulates the main functionality of ERiC. (eric_bearbeite_vorgang).

Process must be initialized with an XML string containing the tax filing (or other data to be submitted) as well as the type of case.

Process exposes the check method to let ERiC check the validity of the supplied XML schema. An Exception is thrown if validation fails.

Calling check is optional. See execute to start the actual execution of the tax case. execute will check as well (not in this library, but ERiC will do this

Defined Under Namespace

Classes: ExecutionError

Instance Method Summary collapse

Constructor Details

#initialize(xml, type) ⇒ Process

Returns a new instance of Process


16
17
18
19
# File 'lib/liberic/process.rb', line 16

def initialize(xml, type)
  @xml = xml
  @type = type
end

Instance Method Details

#checkObject


21
22
23
24
25
# File 'lib/liberic/process.rb', line 21

def check
  Helpers::Invocation.with_result_buffer do |handle|
    SDK::API.check_xml(@xml, @type, handle)
  end
end

#execute(options = {}) ⇒ Object

Executes the actual call to EricBearbeiteVorgang()

Taken an optional hash with an :action parameter, which can be one of the following:

* +:validate+ validate the tax filing and return errors (local processing only)
* +:print+ validate the tax filing and create summary PDF
* +:print_and_submit+ validate the tax filing, create summary PDF and submit filing to ELSTER (server).

Options for controlling the PDF output (printing)

* +:filename+     (set a filename including path where to store the PDF file)
* +:draft+        (set to +false+ to remove the the text "*** ENTWURF ***" on every page)
* +:footer+       (set a string that will be printed on ever page footer)
* +:cover_page+   (set to +true+ to include a cover page)
* +:duplex+       (set to +true+ to generate pages for duplex printing (alternating margin left and right)

Other options

* +:encryption+  An instance of +SDK::Types::VerschluesselungsParameter+ (Leave this empty when requesting BescheidRueckuebermittlung with CEZ (locally generated certificate))
                 No use case tested yet.

TODO: Please note that some parameter combinations might result in errors and will return empty strings for the XML (these errors are currently not checked). One example is using draft: false with test data

Set Liberic.config.data_path to the location where the PDF should be stored, if :filename is not provided.

Example:

filing = Liberic::Process.new(xml_tax_filing, 'ESt_2011')
filing.execute(action: :print)

Will generate a PDF in the current directory if not specified otherwise. WARNING method signature and parameters are WIP and subject to change


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/liberic/process.rb', line 59

def execute(options = {})
  action = options[:action] ||= :validate
  eric_action = ACTIONS[action] || (raise ExecutionError.new("Invalid action: #{action}. Valid actions are #{ACTIONS.keys.join(', ')}"))
  print_params = create_print_params(options)
  server_buffer = SDK::API.rueckgabepuffer_erzeugen
  result = Helpers::Invocation.with_result_buffer(false) do |local_buffer|
    SDK::API.bearbeite_vorgang(@xml, @type,
      eric_action,
      (action == :submit ? nil : print_params),
      options[:encryption],
      (action == :submit ? FFI::MemoryPointer.new(:uint32, 1) : nil), # transferHandle
      local_buffer,
      server_buffer)
  end
  server_result = SDK::API.rueckgabepuffer_inhalt(server_buffer)
  SDK::API.rueckgabepuffer_freigeben(server_buffer)
  print_params.pointer.free
  {
    result: result,
    server_result: server_result
  }
end