Class: Twinfield::Transaction::Line
- Inherits:
-
Object
- Object
- Twinfield::Transaction::Line
- Defined in:
- lib/twinfield/transaction.rb
Instance Attribute Summary collapse
-
#debitcredit ⇒ Object
Returns the value of attribute debitcredit.
-
#description ⇒ Object
Returns the value of attribute description.
-
#dim1 ⇒ Object
Returns the value of attribute dim1.
-
#dim2 ⇒ Object
Returns the value of attribute dim2.
-
#invoicenumber ⇒ Object
Returns the value of attribute invoicenumber.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
-
#vatcode ⇒ Object
Returns the value of attribute vatcode.
Instance Method Summary collapse
- #balance_code ⇒ Object
- #credit? ⇒ Boolean
- #customer_code ⇒ Object
- #detail? ⇒ Boolean
-
#initialize(dim1: nil, dim2: nil, value: nil, debitcredit: nil, description: nil, invoicenumber: nil, vatcode: nil, customer_code: nil, balance_code: nil, type: :detail) ⇒ Line
constructor
A new instance of Line.
- #to_xml ⇒ Object
- #total? ⇒ Boolean
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
#debitcredit ⇒ Object
Returns the value of attribute debitcredit.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def debitcredit @debitcredit end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def description @description end |
#dim1 ⇒ Object
Returns the value of attribute dim1.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def dim1 @dim1 end |
#dim2 ⇒ Object
Returns the value of attribute dim2.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def dim2 @dim2 end |
#invoicenumber ⇒ Object
Returns the value of attribute invoicenumber.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def invoicenumber @invoicenumber end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def value @value end |
#vatcode ⇒ Object
Returns the value of attribute vatcode.
7 8 9 |
# File 'lib/twinfield/transaction.rb', line 7 def vatcode @vatcode end |
Instance Method Details
#balance_code ⇒ Object
20 21 22 |
# File 'lib/twinfield/transaction.rb', line 20 def balance_code dim1 end |
#credit? ⇒ Boolean
51 52 53 |
# File 'lib/twinfield/transaction.rb', line 51 def credit? debitcredit == :credit end |
#customer_code ⇒ Object
24 25 26 |
# File 'lib/twinfield/transaction.rb', line 24 def customer_code dim2 end |
#detail? ⇒ Boolean
43 44 45 |
# File 'lib/twinfield/transaction.rb', line 43 def detail? type == :detail end |
#to_xml ⇒ Object
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
47 48 49 |
# File 'lib/twinfield/transaction.rb', line 47 def total? type == :total end |