Class: Datanorm::Lines::V4::Price
- Inherits:
-
Object
- Object
- Datanorm::Lines::V4::Price
- Defined in:
- lib/datanorm/lines/v4/price.rb
Overview
A Priceset record has one or multiple Price records.
A price represents one price for one product.
Examples:
Q4058352208304;1;39000;1;0
RG601315U1;1;2550;1;5500
100033162;1;28500;;
[0] Artikelnummer
[1] Preiskennzeichen (analogous to Datanorm::Lines::V5::Product)
1=wholesale (higher end-customer price)
2=retail (lower bulk price)
9=ask-for-price (only V5)
Some documentation says this means 1=gross and 2=net but I cannot confirm that,
the prices are always net prices and the retail/wholesale fits the bill.
[2] Preis (6 Vorkomma, 2 Nachkommastellen) Price as Integer (6 digits before the comma, the last two digits represent the fraction)
[3] Rabattkennzeichen (0=Rabattgruppe,1=Rabattsatz,2=Multi,3=Teuerungszuschlag) Discount type "0"=group [no change] "1"=rate [price - price * (factor/10000)] "2"=multiplier [price * (factor/1000)] "3"=surcharge [price + price * (factor/100)]
[4] Rabatt
Instance Method Summary collapse
-
#as_json ⇒ Object
We don't need the Product ID here.
- #cents ⇒ Object
-
#discount_percentage_integer ⇒ Object
How much of a discount do we get?.
-
#id ⇒ Object
------ Basics ------.
-
#initialize(columns:) ⇒ Price
constructor
A new instance of Price.
-
#no_discount? ⇒ Boolean
If this is true, then
centsrepresents the final price. -
#percentage_discount? ⇒ Boolean
If this is true, a discount should be applied to
cents. - #price ⇒ Object
-
#retail? ⇒ Boolean
----- Price -----.
- #to_json ⇒ Object
-
#to_s ⇒ Object
------- Helpers -------.
- #wholesale? ⇒ Boolean
Constructor Details
#initialize(columns:) ⇒ Price
Returns a new instance of Price.
35 36 37 |
# File 'lib/datanorm/lines/v4/price.rb', line 35 def initialize(columns:) @columns = columns end |
Instance Method Details
#as_json ⇒ Object
We don't need the Product ID here.
Our "parent" Priceset has the ID and all Price instances refer to the same product.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/datanorm/lines/v4/price.rb', line 99 def as_json { is_retail: retail?, is_wholesale: wholesale?, is_no_discount: no_discount?, is_percentage_discount: percentage_discount?, discount_percentage: discount_percentage_integer, cents: } end |
#cents ⇒ Object
59 60 61 |
# File 'lib/datanorm/lines/v4/price.rb', line 59 def cents columns[2].to_i end |
#discount_percentage_integer ⇒ Object
How much of a discount do we get?
85 86 87 |
# File 'lib/datanorm/lines/v4/price.rb', line 85 def discount_percentage_integer columns[4]&.to_i end |
#id ⇒ Object
Basics
43 44 45 |
# File 'lib/datanorm/lines/v4/price.rb', line 43 def id ::Datanorm::Helpers::Utf8.call columns[0] end |
#no_discount? ⇒ Boolean
If this is true, then cents represents the final price.
72 73 74 75 76 77 |
# File 'lib/datanorm/lines/v4/price.rb', line 72 def no_discount? return true if columns[3] == '2' # Fallback: If not defined, assume no discount. columns[3].nil? || columns[3].empty? end |
#percentage_discount? ⇒ Boolean
If this is true, a discount should be applied to cents.
80 81 82 |
# File 'lib/datanorm/lines/v4/price.rb', line 80 def percentage_discount? columns[3] == '1' end |
#price ⇒ Object
63 64 65 |
# File 'lib/datanorm/lines/v4/price.rb', line 63 def price BigDecimal(cents) / 100 end |
#retail? ⇒ Boolean
Price
51 52 53 |
# File 'lib/datanorm/lines/v4/price.rb', line 51 def retail? columns[1] == '2' end |
#to_json ⇒ Object
110 111 112 |
# File 'lib/datanorm/lines/v4/price.rb', line 110 def to_json(...) as_json.to_json(...) end |
#to_s ⇒ Object
Helpers
93 94 95 |
# File 'lib/datanorm/lines/v4/price.rb', line 93 def to_s "<Price #{as_json}>" end |
#wholesale? ⇒ Boolean
55 56 57 |
# File 'lib/datanorm/lines/v4/price.rb', line 55 def wholesale? columns[1] == '1' end |