zipdatev 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16ae34c9ade5ebebaf3ec979f10d8816b5ab871f68aa06070051ca9b41d2b4c0
4
- data.tar.gz: ef6f9b9345a13d8b2fc1aff5a0e67d7d932a4a244cdbc384a2b79fceb25267f8
3
+ metadata.gz: 7e98150333d568e203ad3f8bea658bdfed75a411d116ec79e17de683a320c14e
4
+ data.tar.gz: feebaad2cd0de26f16f5d09e1049776a68549618d93fff64f37042ad13f3bb38
5
5
  SHA512:
6
- metadata.gz: b47bb6b5874e07f1a0a85e3a0f6ad4b28e39124bdf78c322e3772584ea04f3c6f924c5ea5f5b2c3f9ca206245de1fcb86e126188021806b9808ec0dc6a64819d
7
- data.tar.gz: d691a9ee6263c1cbb54aa8679df7caac69e70c4b7e53db18b3831b5a0395fdecc134f4b6ac0f10bbb26319b37ec6ab61f9bdceb0296953f030916bca1c492c1a
6
+ metadata.gz: e62f20679ffcc4ab682a7b376944bac39850c15d319e04befbaecf47cb3e2a3305ea40ac07c371a9ddec42f3414a648952c03d63255f8f49b5bbf171d22c59bb
7
+ data.tar.gz: b8c49308ff909e730adb7a2ea664030dfcc501cf8d8179dbea9f9dc0722abb28c0a2b07e25fe0a4b05dbc29f0378510daf4180a22c74b0015ec3a00b6b98cad4
@@ -45,7 +45,7 @@ module ZipDatev
45
45
  # discount_payment_date_2: Date.new(2023, 1, 22),
46
46
  # due_date: Date.new(2023, 1, 26)
47
47
  # )
48
- # rubocop:disable Metrics/ClassLength
48
+ # rubocop:disable-next Metrics/ClassLength
49
49
  class Invoice
50
50
  include ActiveModel::Model
51
51
  include ActiveModel::Attributes
@@ -344,5 +344,4 @@ module ZipDatev
344
344
  attributes.compact.transform_keys(&:to_sym)
345
345
  end
346
346
  end
347
- # rubocop:enable Metrics/ClassLength
348
347
  end
@@ -16,6 +16,10 @@ module ZipDatev
16
16
  # @example Apply to Invoice
17
17
  # validates_with ConsolidationValidator
18
18
  class ConsolidationValidator < ActiveModel::Validator
19
+ # Validates consolidation rules for multi-line invoices.
20
+ #
21
+ # @param record [Invoice] The invoice record to validate
22
+ # @return [void]
19
23
  def validate(record)
20
24
  # Only validate if there are line items
21
25
  return unless record.respond_to?(:multi_line?) && record.multi_line?
@@ -14,9 +14,17 @@ require "date"
14
14
  # @example Allow nil values
15
15
  # validates :due_date, date_range: true, allow_nil: true
16
16
  class DateRangeValidator < ActiveModel::EachValidator
17
+ # Minimum date accepted by DATEV (matches SQL Server datetime lower bound)
17
18
  MIN_DATE = Date.new(1753, 1, 1)
19
+ # Maximum date accepted by DATEV
18
20
  MAX_DATE = Date.new(9999, 12, 31)
19
21
 
22
+ # Validates that the date value falls within the DATEV-allowed range.
23
+ #
24
+ # @param record [Object] The model record being validated
25
+ # @param attribute [Symbol] The attribute name being validated
26
+ # @param value [Date] The date value to validate
27
+ # @return [void]
20
28
  def validate_each(record, attribute, value)
21
29
  return if value.nil?
22
30
 
@@ -17,6 +17,12 @@ require "bigdecimal"
17
17
  # @example Allow nil values
18
18
  # validates :tax, decimal_precision: { places: 2 }, allow_nil: true
19
19
  class DecimalPrecisionValidator < ActiveModel::EachValidator
20
+ # Validates that the decimal value has exactly the required number of decimal places.
21
+ #
22
+ # @param record [Object] The model record being validated
23
+ # @param attribute [Symbol] The attribute name being validated
24
+ # @param value [BigDecimal, Numeric] The decimal value to validate
25
+ # @return [void]
20
26
  def validate_each(record, attribute, value)
21
27
  return if value.nil?
22
28
 
@@ -6,16 +6,23 @@ module ZipDatev
6
6
  module Validators
7
7
  # Validates the chronological ordering of discount-related dates.
8
8
  #
9
- # DATEV requires discount dates to be in a specific order:
9
+ # Discount dates must be in a specific order:
10
10
  # 1. invoice date < discount_payment_date
11
11
  # 2. discount_payment_date < discount_payment_date_2
12
- # 3. discount_payment_date_2 < due_date
12
+ # 3. last discount date (discount_payment_date_2, else discount_payment_date) <= due_date
13
+ #
14
+ # The due date may equal the last discount date to support "discount only"
15
+ # terms (e.g. "7 Tage 3 % Skonto") where both fall on the same day.
13
16
  #
14
17
  # Also validates that delivery_date is not after invoice date.
15
18
  #
16
19
  # @example Apply to Invoice or LineItem
17
20
  # validates_with ZipDatev::Validators::DiscountDatesValidator
18
21
  class DiscountDatesValidator < ActiveModel::Validator
22
+ # Validates the chronological ordering of discount-related dates.
23
+ #
24
+ # @param record [Invoice, LineItem] The record to validate
25
+ # @return [void]
19
26
  def validate(record)
20
27
  validate_delivery_date(record)
21
28
  validate_dates_after_invoice(record)
@@ -63,9 +70,9 @@ module ZipDatev
63
70
  discount_2 = record.discount_payment_date_2
64
71
  discount_1 = record.discount_payment_date
65
72
 
66
- if discount_2 && discount_2 >= due_date
73
+ if discount_2 && discount_2 > due_date
67
74
  record.errors.add(:due_date, "must be after discount_payment_date_2")
68
- elsif discount_1 && !discount_2 && discount_1 >= due_date
75
+ elsif discount_1 && !discount_2 && discount_1 > due_date
69
76
  record.errors.add(:due_date, "must be after discount_payment_date")
70
77
  end
71
78
  end
@@ -19,6 +19,7 @@ module ZipDatev
19
19
  # @example Apply to Invoice or LineItem
20
20
  # validates_with PaymentConditionsValidator
21
21
  class PaymentConditionsValidator < ActiveModel::Validator
22
+ # Manual discount fields that are mutually exclusive with payment_conditions_id
22
23
  DISCOUNT_FIELDS = %i[
23
24
  discount_amount
24
25
  discount_percentage
@@ -29,6 +30,10 @@ module ZipDatev
29
30
  due_date
30
31
  ].freeze
31
32
 
33
+ # Validates that payment_conditions_id and manual discount fields are mutually exclusive.
34
+ #
35
+ # @param record [Invoice, LineItem] The record to validate
36
+ # @return [void]
32
37
  def validate(record)
33
38
  return unless record.payment_conditions_id
34
39
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipDatev
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipdatev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dexter Team