Module: Ksef::FA3::CorrectionReader
- Extended by:
- NodeReader
- Defined in:
- lib/ksef/fa3/correction_reader.rb
Overview
Reads the correction group of Fa, and the summary a correction states rather than
derives (docs/REFERENCE.md §8.4).
Split out of Parser for the same reason RowReader is: it is the one part of reading an invoice that is entirely about corrections, and keeping it here means the parser itself still reads as the shape of an invoice.
Constant Summary
Constants included from NodeReader
NodeReader::NAMESPACES, NodeReader::PREFIX
Class Method Summary collapse
-
.correction_from(fa_node) ⇒ Correction?
Keyed on
DaneFaKorygowanejrather than onRodzajFaktury: the whole group isminOccurs="0", so aKORthat omits it is schema-valid and simply has no correction to read — and re-serialising such a document must not invent one. -
.totals_from(fa_node) ⇒ Totals
The summary the document states, read verbatim.
Class Method Details
.correction_from(fa_node) ⇒ Correction?
Keyed on DaneFaKorygowanej rather than on RodzajFaktury: the whole group is
minOccurs="0", so a KOR that omits it is schema-valid and simply has no
correction to read — and re-serialising such a document must not invent one.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ksef/fa3/correction_reader.rb', line 22 def correction_from(fa_node) corrected = elements(fa_node, "DaneFaKorygowanej") return nil if corrected.empty? Correction.new( corrected: corrected.map { |node| corrected_invoice_from(node) }, reason: text(fa_node, "PrzyczynaKorekty"), effect: text(fa_node, "TypKorekty"), period: text(fa_node, "OkresFaKorygowanej"), corrected_number: text(fa_node, "NrFaKorygowany"), previous_seller: previous_seller_from(fa_node), previous_buyers: elements(fa_node, "Podmiot2K").map do |node| SubjectReader.subject_from(node, role: :previous_buyer) end, paid_before: text(fa_node, "P_15ZK"), exchange_rate_before: text(fa_node, "KursWalutyZK") ) end |
.totals_from(fa_node) ⇒ Totals
The summary the document states, read verbatim. Reached only for the types in Invoice::STATED_TOTALS_TYPES; everything else has its summaries recomputed from its lines, which is what lets RoundingInference recover how they were computed.
46 47 48 49 50 51 52 53 |
# File 'lib/ksef/fa3/correction_reader.rb', line 46 def totals_from(fa_node) buckets = Totals::ELEMENTS.each_with_object({}) do |name, acc| value = text(fa_node, name) acc[name] = value unless value.nil? end Totals.new(buckets: buckets, gross: text!(fa_node, "P_15")) end |