Class: Twinfield::Transaction::Line

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dim1: nil, dim2: nil, value: nil, debitcredit: nil, description: nil, invoicenumber: nil, vatcode: nil, customer_code: nil, balance_code: nil, type: :detail) ⇒ Line

Returns a new instance of Line.



9
10
11
12
13
14
15
16
17
18
# File 'lib/twinfield/transaction.rb', line 9

def initialize(dim1: nil, dim2: nil, value: nil, debitcredit: nil, description: nil, invoicenumber: nil, vatcode: nil, customer_code: nil, balance_code: nil, type: :detail)
  self.dim1 = dim1 || balance_code
  self.dim2 = dim2 || customer_code
  self.value = value.to_f
  self.debitcredit = debitcredit
  self.description = description
  self.invoicenumber = invoicenumber
  self.vatcode = vatcode
  self.type = type.to_sym
end

Instance Attribute Details

#debitcreditObject

Returns the value of attribute debitcredit.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def debitcredit
  @debitcredit
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def description
  @description
end

#dim1Object

Returns the value of attribute dim1.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def dim1
  @dim1
end

#dim2Object

Returns the value of attribute dim2.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def dim2
  @dim2
end

#invoicenumberObject

Returns the value of attribute invoicenumber.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def invoicenumber
  @invoicenumber
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def type
  @type
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def value
  @value
end

#vatcodeObject

Returns the value of attribute vatcode.



7
8
9
# File 'lib/twinfield/transaction.rb', line 7

def vatcode
  @vatcode
end

Instance Method Details

#balance_codeObject



20
21
22
# File 'lib/twinfield/transaction.rb', line 20

def balance_code
  dim1
end

#credit?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/twinfield/transaction.rb', line 51

def credit?
  debitcredit == :credit
end

#customer_codeObject



24
25
26
# File 'lib/twinfield/transaction.rb', line 24

def customer_code
  dim2
end

#detail?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/twinfield/transaction.rb', line 43

def detail?
  type == :detail
end

#to_xmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twinfield/transaction.rb', line 28

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.line(type: type) {
      xml.dim1 dim1 if dim1
      xml.dim2 dim2 if dim2
      xml.value value if value
      xml.description description if description && type != :total
      xml.debitcredit debitcredit if debitcredit
      xml.invoicenumber invoicenumber if invoicenumber
      xml.vatcode vatcode if vatcode
      xml.currencydate Date.today.strftime("%Y%m%d")
    }
  end.doc.root.to_xml
end

#total?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/twinfield/transaction.rb', line 47

def total?
  type == :total
end