Class: Twinfield::Browse::Transaction::CostCenter

Inherits:
AbstractModel
  • Object
show all
Extended by:
Helpers::Parsers
Includes:
Helpers::TransactionMatch
Defined in:
lib/twinfield/browse/transaction/cost_center.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Parsers

parse_date, parse_datetime, parse_float

Methods included from Helpers::TransactionMatch

#match!, #to_match_xml, #to_transaction_match_line_xml

Constructor Details

#initialize(number: nil, yearperiod: nil, currency: "EUR", value: nil, status: nil, dim1: nil, dim2: nil, key: nil, code: nil) ⇒ CostCenter

Returns a new instance of CostCenter.



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 131

def initialize(number: nil, yearperiod: nil, currency: "EUR", value: nil, status: nil, dim1: nil, dim2: nil, key: nil, code: nil)
  self.number = number
  self.yearperiod = yearperiod
  self.currency = currency
  self.value = value
  self.status = status
  self.dim1 = dim1
  self.dim2 = dim2
  self.key = key
  self.code = code
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def code
  @code
end

#currencyObject

Returns the value of attribute currency.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def currency
  @currency
end

#dim1Object

Returns the value of attribute dim1.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def dim1
  @dim1
end

#dim2Object

Returns the value of attribute dim2.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def dim2
  @dim2
end

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def key
  @key
end

#numberObject

Returns the value of attribute number.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def number
  @number
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def status
  @status
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def value
  @value
end

#yearperiodObject

Returns the value of attribute yearperiod.



8
9
10
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 8

def yearperiod
  @yearperiod
end

Class Method Details

.find(customer_code: nil, invoice_number: nil, code: nil, number: nil) ⇒ Object



25
26
27
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 25

def find(customer_code: nil, invoice_number: nil, code: nil, number: nil)
  where(customer_code: customer_code, invoice_number: invoice_number, code: code, number: number).first
end

.initialize_from_columns_response_row(transaction_xml) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 11

def initialize_from_columns_response_row(transaction_xml)
  new(
    number: transaction_xml.css("td[field='fin.trs.head.number']").text,
    yearperiod: transaction_xml.css("td[field='fin.trs.head.yearperiod']").text,
    currency: transaction_xml.css("td[field='fin.trs.head.curcode']").text,
    value: transaction_xml.css("td[field='fin.trs.line.valuesigned']").text&.to_f,
    status: transaction_xml.css("td[field='fin.trs.head.status']").text,
    dim1: transaction_xml.css("td[field='fin.trs.line.dim1']").text,
    dim2: transaction_xml.css("td[field='fin.trs.line.dim2']").text,
    key: transaction_xml.css("key").text.gsub(/\s/, ""),
    code: transaction_xml.css("td[field='fin.trs.head.code']").text
  )
end

.where(years: ((Date.today.year - 30)..Date.today.year), dim1: nil, dim2: nil) ⇒ Object

Parameters:

  • years: (defaults to: ((Date.today.year - 30)..Date.today.year))

    range



31
32
33
34
35
36
37
38
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/twinfield/browse/transaction/cost_center.rb', line 31

def where(years: ((Date.today.year - 30)..Date.today.year), dim1: nil, dim2: nil)
  build_request = %(
    <column>
        <field>fin.trs.head.yearperiod</field>
        <label>Periode</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>between</operator>
        <from>#{years.first}/01</from>
        <to>#{years.last}/12</to>
        <finderparam/>
    </column>
    <column>
        <field>fin.trs.line.dim1</field>
        <label>Grootboek</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>between</operator>
        <from>#{dim1}</from>
        <to>#{dim1}</to>
        <finderparam/>
    </column>
    <column>
        <field>fin.trs.line.dim2</field>
        <label>Kostenplaats</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>between</operator>
        <from>#{dim2}</from>
        <to>#{dim2}</to>
        <finderparam>dimtype=KPL</finderparam>
      </column>
      <column>
        <field>fin.trs.head.code</field>
        <label>Dagboek</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>equal</operator>
        <from/>
        <to/>
        <finderparam>hidden=1</finderparam>
      </column>
      <column>
        <field>fin.trs.head.number</field>
        <label>Boekst.nr.</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>between</operator>
        <from/>
        <to/>
        <finderparam/>
      </column>
      <column>
        <field>fin.trs.head.curcode</field>
        <label>Valuta</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>none</operator>
        <from/>
        <to/>
        <finderparam/>
      </column>
      <column>
        <field>fin.trs.line.valuesigned</field>
        <label>Bedrag</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>between</operator>
        <from/>
        <to/>
        <finderparam/>
      </column>
      <column>
        <field>fin.trs.head.status</field>
        <label>Status</label>
        <visible>true</visible>
        <ask>false</ask>
        <operator>equal</operator>
        <from>normal</from>
        <to/>
        <finderparam/>
      </column>
      )

  response = Twinfield::Api::Process.request(:process_xml_string) do
    %(
      <columns code="900">
        #{build_request}
      </columns>
    )
  end

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

  xml.css("tr").map do |transaction_xml|
    Twinfield::Browse::Transaction::CostCenter.initialize_from_columns_response_row(transaction_xml)
  end
end