Class: Ksef::FA3::AdvanceInvoice

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

Overview

Reopened rather than using a Data.define block, so the constant below lands on the class and resolves from inside #initialize — a block body's constant lookup is lexical, against Ksef::FA3, so ONE_OF defined on the class would not be found there.

Constant Summary collapse

ONE_OF =
"An advance invoice is named by exactly one of ksef_number: (its KSeF number) " \
"or number: (its own number, for one issued outside KSeF). The schema puts a " \
"choice here, so naming both or neither is not a document that exists."

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(ksef_number: nil, number: nil) ⇒ AdvanceInvoice

Returns a new instance of AdvanceInvoice.

Parameters:

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

    NrKSeFFaZaliczkowej, for an advance invoice issued through KSeF

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

    NrFaZaliczkowej, for one issued outside it

Raises:



40
41
42
43
44
45
# File 'lib/ksef/fa3/advance_invoice.rb', line 40

def initialize(ksef_number: nil, number: nil)
  given = [ksef_number, number].compact
  raise ValidationError, ONE_OF unless given.size == 1

  super(ksef_number: Formatting.text(ksef_number), number: Formatting.text(number))
end

Instance Attribute Details

#ksef_number ⇒ Object (readonly)

Returns the value of attribute ksef_number

Returns:

  • (Object) —

    the current value of ksef_number



23
24
25
# File 'lib/ksef/fa3/advance_invoice.rb', line 23

def ksef_number
  @ksef_number
end

#number ⇒ Object (readonly)

Returns the value of attribute number

Returns:

  • (Object) —

    the current value of number



23
24
25
# File 'lib/ksef/fa3/advance_invoice.rb', line 23

def number
  @number
end

Instance Method Details

#to_fa3 ⇒ Object



47
48
49
50
51
52
# File 'lib/ksef/fa3/advance_invoice.rb', line 47

def to_fa3
  return { "NrKSeFFaZaliczkowej" => ksef_number } if ksef_number

  # `TWybor1` has one member: the marker is present or absent, with no "no" to write.
  { "NrKSeFZN" => "1", "NrFaZaliczkowej" => number }
end