Module: Ksef::FA3::DocumentMapping

Included in:
Invoice
Defined in:
lib/ksef/fa3/document_mapping.rb

Overview

How an Invoice becomes the nested, element-name-keyed structure Serializer writes.

Mixed into Invoice and kept apart from it for the same reason Provenance is: this is the only part that knows FA(3)'s element names, while the invoice itself is about parties, lines and arithmetic. Ordering is never expressed here — Serializer takes it from the generated schema metadata, so this only says what the document contains.

Instance Method Summary collapse

Instance Method Details

#summary_buckets ⇒ Hash{String => BigDecimal}

The summary buckets as the document will carry them: element name => amount, rounded to the two places TKwotowy allows. A stated summary answers with what it states; a derived one with what it derives, rounded per bucket exactly as #to_xml rounds it.

Public because tier 3 reconciles against it (BusinessValidator) and reaching for it through send would have made a private method load-bearing from outside.

Returns:

  • (Hash{String => BigDecimal})


30
31
32
33
34
# File 'lib/ksef/fa3/document_mapping.rb', line 30

def summary_buckets
  return totals.buckets if totals

  bucket_totals.transform_values { |amount| amount.round(Formatting::AMOUNT_SCALE) }
end

#to_fa3 ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/ksef/fa3/document_mapping.rb', line 12

def to_fa3
  {
    "Naglowek" => header,
    "Podmiot1" => seller.to_fa3(role: :seller),
    "Podmiot2" => buyer.to_fa3(role: :buyer),
    "Fa" => invoice_body,
    "Zalacznik" => attachment&.to_fa3
  }.compact
end