View Source UkraineTaxidEx.Edrpou.CheckSum (ukraine_tax_id v0.1.1)

Summary

Types

Coefficients (weights) for digits to calculate EDRPOU check sum may be two types: base ([1, 2, 3, 4, 5, 6, 7] for EDRPOU < 30M or EDRPOU > 60M) or alternative ([7, 1, 2, 3, 4, 5, 6] if EDRPOU between 30M and 60M)

Functions

Calculate checksum for EDRPOU number. The checksum for EDRPOU is calculated in several steps

Returns a list of weights used for EDRPOU check sum calculation. When double_added is true, adds 2 to each weight in the list.

Types

weights_type()

@type weights_type() :: :base | :alternative

Coefficients (weights) for digits to calculate EDRPOU check sum may be two types: base ([1, 2, 3, 4, 5, 6, 7] for EDRPOU < 30M or EDRPOU > 60M) or alternative ([7, 1, 2, 3, 4, 5, 6] if EDRPOU between 30M and 60M)

Functions

check_sum(digits)

@spec check_sum(digits :: UkraineTaxidEx.Commons.digits()) :: integer()

Calculate checksum for EDRPOU number. The checksum for EDRPOU is calculated in several steps:

  1. Define the type of weights (base or alternative) as described in weights_type/1
  2. Multiply each digit by its corresponding weight
  3. Sum the products
  4. Take mod 11 of the sum
  5. If mod 11 is greater or equal than 10, repeat steps 2-4 with weights +2

weights(type \\ :base, double_added \\ false)

@spec weights(type :: weights_type(), double_added? :: boolean()) ::
  UkraineTaxidEx.Commons.digits()

Returns a list of weights used for EDRPOU check sum calculation. When double_added is true, adds 2 to each weight in the list.

## Parameters

- type: `:base` or `:alternative` weights pattern
- double_added: when true, adds 2 to each weight

## Examples

      iex> weights(:base)
      [1, 2, 3, 4, 5, 6, 7]

      iex> weights(:alternative)
      [7, 1, 2, 3, 4, 5, 6]

      iex> weights(:base, true)
      [3, 4, 5, 6, 7, 8, 9]

      iex> weights(:alternative, true)
      [9, 3, 4, 5, 6, 7, 8]