Class: Ksef::FA3::OrderLine

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

Overview

One position of the order or contract an advance invoice relates to (Zamowienie/ZamowienieWiersz).

Nothing here is derived, and that is the difference from Line

Line#net computes a net from quantity × price when the document does not state one, because a VAT invoice's tax summary is computed from its rows. An order's rows feed nothing: WartoscZamowienia is stated, and so are the invoice's own buckets — every type that carries a Zamowienie is in Invoice::STATED_TOTALS_TYPES. So a derivation here would have no consumer, and inventing an amount the contract does not state is the thing this model spends its effort avoiding (docs/REFERENCE.md §8.5).

The tax is stated too, in P_11VatZ — "kwota podatku od zamówionego towaru lub usługi". FaWiersz has no such element and the tax is computed from the rate; here the document carries both, so both are read.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(name: nil, quantity: nil, unit: nil, net_unit_price: nil, net_amount: nil, vat_amount: nil, vat_rate: nil, row_number: nil, state_before: false) ⇒ OrderLine

Every element of ZamowienieWiersz except NrWierszaZam is minOccurs="0", so every field here is optional and an absent one is omitted rather than written empty.

P_9AZ is TKwotowy2, not TKwotowy — the same eight-place unit price as Line's P_9A, and rounded to the same scale for the same reason.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ksef/fa3/order_line.rb', line 30

def initialize(name: nil, quantity: nil, unit: nil, net_unit_price: nil, net_amount: nil,
               vat_amount: nil, vat_rate: nil, row_number: nil, state_before: false)
  super(
    name: Formatting.text(name), unit: Formatting.text(unit),
    vat_rate: Formatting.text(vat_rate),
    quantity: Line.scaled(quantity, Formatting::QUANTITY_SCALE),
    net_unit_price: Line.scaled(net_unit_price, Formatting::UNIT_PRICE_SCALE),
    net_amount: Line.scaled(net_amount, Formatting::AMOUNT_SCALE),
    vat_amount: Line.scaled(vat_amount, Formatting::AMOUNT_SCALE),
    row_number: row_number.nil? ? nil : Formatting.integer(row_number),
    state_before: Formatting.unflag(state_before)
  )
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



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

def name
  @name
end

#net_amount ⇒ Object (readonly)

Returns the value of attribute net_amount

Returns:

  • (Object) —

    the current value of net_amount



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

def net_amount
  @net_amount
end

#net_unit_price ⇒ Object (readonly)

Returns the value of attribute net_unit_price

Returns:

  • (Object) —

    the current value of net_unit_price



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

def net_unit_price
  @net_unit_price
end

#quantity ⇒ Object (readonly)

Returns the value of attribute quantity

Returns:

  • (Object) —

    the current value of quantity



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

def quantity
  @quantity
end

#row_number ⇒ Object (readonly)

Returns the value of attribute row_number

Returns:

  • (Object) —

    the current value of row_number



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

def row_number
  @row_number
end

#state_before ⇒ Object (readonly)

Returns the value of attribute state_before

Returns:

  • (Object) —

    the current value of state_before



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

def state_before
  @state_before
end

#unit ⇒ Object (readonly)

Returns the value of attribute unit

Returns:

  • (Object) —

    the current value of unit



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

def unit
  @unit
end

#vat_amount ⇒ Object (readonly)

Returns the value of attribute vat_amount

Returns:

  • (Object) —

    the current value of vat_amount



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

def vat_amount
  @vat_amount
end

#vat_rate ⇒ Object (readonly)

Returns the value of attribute vat_rate

Returns:

  • (Object) —

    the current value of vat_rate



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

def vat_rate
  @vat_rate
end

Instance Method Details

#to_fa3(row_number:) ⇒ Object

StanPrzedZ is StanPrzed's twin for an order position: a KOR_ZAL shows a corrected position before and after as separate rows. Same shape, same pairing by row number.

Parameters:

  • row_number (Integer) —

    the row's position, used when the line states none itself



48
49
50
51
52
53
54
55
56
# File 'lib/ksef/fa3/order_line.rb', line 48

def to_fa3(row_number:)
  {
    "NrWierszaZam" => self.row_number || row_number,
    "P_7Z" => name,
    "P_8AZ" => unit,
    "P_12Z" => vat_rate,
    "StanPrzedZ" => state_before ? Formatting.flag(true) : nil
  }.merge(amounts).compact
end