Class: Twinfield::Create::GeneralLedger

Inherits:
Object
  • Object
show all
Defined in:
lib/twinfield/create/general_ledger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ GeneralLedger

Returns a new instance of GeneralLedger.



6
7
8
# File 'lib/twinfield/create/general_ledger.rb', line 6

def initialize(hash = {})
  hash.each { |k, v| send(:"#{k}=", CGI.escapeHTML(v)) }
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/twinfield/create/general_ledger.rb', line 4

def code
  @code
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/twinfield/create/general_ledger.rb', line 4

def name
  @name
end

Instance Method Details

#saveObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/twinfield/create/general_ledger.rb', line 10

def save
  response = Twinfield::Api::Process.request do
    %(
      <dimension>
        <office>#{Twinfield.configuration.company}</office>
        <type>PNL</type>
        <name>#{name}</name>
        <code>#{code}</code>
      </dimension>
    )
  end

  xml = Nokogiri::XML(response.body[:process_xml_string_response][:process_xml_string_result])

  if xml.at_css("dimension").attributes["result"].value == "1"
    {
      code: code,
      status: 1
    }
  else
    {
      code: code,
      status: 0,
      messages: xml.css("[msg]").map { |x| x.attributes["msg"].value }
    }
  end
end