Class: Ksef::InvoiceHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/ksef/invoice_header.rb

Overview

Lightweight value object describing an invoice as returned by ‘POST /invoices/query/metadata`. Built from a single element of the `invoices` array in the API response.

The object intentionally exposes a small, business-meaningful slice of the full payload. The raw hash is preserved on #raw for advanced callers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ InvoiceHeader

Returns a new instance of InvoiceHeader.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ksef/invoice_header.rb', line 25

def initialize(raw)
  @raw = raw
  @ksef_reference_number = raw["ksefNumber"]
  @invoice_number        = raw["invoiceNumber"]
  @issuer_nip            = raw.dig("seller", "nip")
  @issuer_name           = raw.dig("seller", "name")
  @recipient_nip         = raw.dig("buyer", "identifier", "value")
  @recipient_name        = raw.dig("buyer", "name")
  @issued_on             = parse_date(raw["issueDate"])
  @acquired_at           = parse_time(raw["acquisitionDate"])
  @permanently_stored_at = parse_time(raw["permanentStorageDate"])
  @net_amount            = raw["netAmount"]
  @gross_amount          = raw["grossAmount"]
  @vat_amount            = raw["vatAmount"]
  @currency              = raw["currency"]
  @invoicing_mode        = raw["invoicingMode"]
  @invoice_type          = raw["invoiceType"]
  @form_code             = raw.dig("formCode", "value")
  @form_schema_version   = raw.dig("formCode", "schemaVersion")
  @self_invoicing        = raw["isSelfInvoicing"]
  @has_attachment        = raw["hasAttachment"]
  @invoice_hash          = raw["invoiceHash"]
end

Instance Attribute Details

#acquired_atObject (readonly)

Returns the value of attribute acquired_at.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def acquired_at
  @acquired_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def currency
  @currency
end

#form_codeObject (readonly)

Returns the value of attribute form_code.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def form_code
  @form_code
end

#form_schema_versionObject (readonly)

Returns the value of attribute form_schema_version.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def form_schema_version
  @form_schema_version
end

#gross_amountObject (readonly)

Returns the value of attribute gross_amount.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def gross_amount
  @gross_amount
end

#has_attachmentObject (readonly)

Returns the value of attribute has_attachment.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def has_attachment
  @has_attachment
end

#invoice_hashObject (readonly)

Returns the value of attribute invoice_hash.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def invoice_hash
  @invoice_hash
end

#invoice_numberObject (readonly)

Returns the value of attribute invoice_number.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def invoice_number
  @invoice_number
end

#invoice_typeObject (readonly)

Returns the value of attribute invoice_type.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def invoice_type
  @invoice_type
end

#invoicing_modeObject (readonly)

Returns the value of attribute invoicing_mode.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def invoicing_mode
  @invoicing_mode
end

#issued_onObject (readonly)

Returns the value of attribute issued_on.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def issued_on
  @issued_on
end

#issuer_nameObject (readonly)

Returns the value of attribute issuer_name.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def issuer_name
  @issuer_name
end

#issuer_nipObject (readonly)

Returns the value of attribute issuer_nip.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def issuer_nip
  @issuer_nip
end

#ksef_reference_numberObject (readonly)

Returns the value of attribute ksef_reference_number.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def ksef_reference_number
  @ksef_reference_number
end

#net_amountObject (readonly)

Returns the value of attribute net_amount.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def net_amount
  @net_amount
end

#permanently_stored_atObject (readonly)

Returns the value of attribute permanently_stored_at.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def permanently_stored_at
  @permanently_stored_at
end

#rawObject (readonly)

Returns the value of attribute raw.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def raw
  @raw
end

#recipient_nameObject (readonly)

Returns the value of attribute recipient_name.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def recipient_name
  @recipient_name
end

#recipient_nipObject (readonly)

Returns the value of attribute recipient_nip.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def recipient_nip
  @recipient_nip
end

#self_invoicingObject (readonly)

Returns the value of attribute self_invoicing.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def self_invoicing
  @self_invoicing
end

#vat_amountObject (readonly)

Returns the value of attribute vat_amount.



14
15
16
# File 'lib/ksef/invoice_header.rb', line 14

def vat_amount
  @vat_amount
end

Instance Method Details

#has_attachment?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ksef/invoice_header.rb', line 53

def has_attachment?
  @has_attachment == true
end

#self_invoicing?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ksef/invoice_header.rb', line 49

def self_invoicing?
  @self_invoicing == true
end