Class: Ksef::FA3::CorrectedInvoice

Inherits:
Data
  • Object
show all
Includes:
Canonical
Defined in:
lib/ksef/fa3/corrected_invoice.rb

Overview

One invoice a correction corrects (DaneFaKorygowanej).

A KOR names at least one and may name up to 50 000 — art. 106j ust. 3 lets a single correction carry a discount granted across a whole period, and the Ministry's Przykład 6 does exactly that over six invoices with an OkresFaKorygowanej naming the half-year (docs/REFERENCE.md §8.4).

ksef_number is nil-able, and the nil is the point

The schema puts a choice here: either NrKSeF + NrKSeFFaKorygowanej, or NrKSeFN on its own — "znacznik faktury korygowanej wystawionej poza KSeF", the marker for an invoice issued outside the system. Both branches are single-valued markers, so the whole choice is decided by whether a number is known. Modelling it as one nil-able field makes emitting both branches, or neither, unrepresentable rather than merely discouraged.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(number:, issue_date:, ksef_number: nil) ⇒ CorrectedInvoice

Returns a new instance of CorrectedInvoice.

Parameters:

  • number (String) —

    NrFaKorygowanej, the corrected invoice's own number

  • issue_date (Date, String) —

    DataWystFaKorygowanej

  • ksef_number (String, nil) (defaults to: nil) —

    NrKSeFFaKorygowanej; nil for an invoice issued outside KSeF, which emits NrKSeFN instead



28
29
30
31
32
33
# File 'lib/ksef/fa3/corrected_invoice.rb', line 28

def initialize(number:, issue_date:, ksef_number: nil)
  # Coerced here rather than at serialisation, so an invoice built from a String and
  # the same invoice parsed back from XML are one object (§8.2b).
  super(number: Formatting.text(number), issue_date: Formatting.to_date(issue_date),
        ksef_number: Formatting.text(ksef_number))
end

Instance Attribute Details

#issue_date ⇒ Object (readonly)

Returns the value of attribute issue_date

Returns:

  • (Object) —

    the current value of issue_date



20
21
22
# File 'lib/ksef/fa3/corrected_invoice.rb', line 20

def issue_date
  @issue_date
end

#ksef_number ⇒ Object (readonly)

Returns the value of attribute ksef_number

Returns:

  • (Object) —

    the current value of ksef_number



20
21
22
# File 'lib/ksef/fa3/corrected_invoice.rb', line 20

def ksef_number
  @ksef_number
end

#number ⇒ Object (readonly)

Returns the value of attribute number

Returns:

  • (Object) —

    the current value of number



20
21
22
# File 'lib/ksef/fa3/corrected_invoice.rb', line 20

def number
  @number
end

Instance Method Details

#to_fa3 ⇒ Object



35
36
37
38
39
40
# File 'lib/ksef/fa3/corrected_invoice.rb', line 35

def to_fa3
  {
    "DataWystFaKorygowanej" => Formatting.date(issue_date),
    "NrFaKorygowanej" => number
  }.merge(reference)
end