Skip to content

Commit b5be9f2

Browse files
authored
Merge pull request #1 from mrfoe7/add-codes
add: department and offices tax offices. registrations reason codes
2 parents 48d2696 + 04df433 commit b5be9f2

File tree

10 files changed

+302
-16
lines changed

10 files changed

+302
-16
lines changed

errors.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@ package ru_doc_code
33
import "errors"
44

55
var (
6-
ErrInvalidINNLength = errors.New("invalid inn length")
7-
ErrInvalidBIKLength = errors.New("invalid bik length")
8-
ErrInvalidKPPLength = errors.New("invalid kpp length")
9-
ErrInvalidOGRNLength = errors.New("invalid ogrn length")
6+
// ErrInvalidINNLength
7+
ErrInvalidINNLength = errors.New("invalid inn length")
8+
9+
// ErrInvalidBIKLength
10+
ErrInvalidBIKLength = errors.New("invalid bik length")
11+
12+
// ErrInvalidKPPLength
13+
ErrInvalidKPPLength = errors.New("invalid kpp length")
14+
15+
// ErrInvalidOGRNLength
16+
ErrInvalidOGRNLength = errors.New("invalid ogrn length")
17+
18+
// ErrInvalidOGRNIPLength
1019
ErrInvalidOGRNIPLength = errors.New("invalid ogrinp length")
11-
ErrInvalidSNILSLength = errors.New("invalid snils length")
1220

21+
// ErrInvalidSNILSLength
22+
ErrInvalidSNILSLength = errors.New("invalid snils length")
23+
24+
// ErrInvalidFormattedSNILSLength
1325
ErrInvalidFormattedSNILSLength = errors.New("invalid formatted snils length")
1426

27+
// ErrInvalidRegistrationReasonCode
28+
ErrInvalidRegistrationReasonCode = errors.New("invalid registration reason code")
29+
30+
// ErrInvalidValue
1531
ErrInvalidValue = errors.New("invalid code value")
1632

33+
// ErrInvalidBIKCountryCode
1734
ErrInvalidBIKCountryCode = errors.New("invalid bik country code")
35+
36+
// ErrNotImplemented
37+
ErrNotImplemented = errors.New("method does not implemented")
1838
)

inn/inn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ const (
1212
lengthPhysical = 12
1313
)
1414

15+
type INN struct {
16+
Code ru_doc_code.TaxRegionCode
17+
SerialNumber ru_doc_code.SerialNumber
18+
Hash10 uint
19+
Hash11 uint
20+
Hash12 uint
21+
}
22+
1523
// Validate check to valid inn from input string.
1624
// example: input format is 7707083893
1725
func Validate(inn string) (bool, error) {

kpp/kpp.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package kpp
22

3-
import ru_doc_code "github.com/mrfoe7/ru-doc-code"
3+
import (
4+
ru_doc_code "github.com/mrfoe7/ru-doc-code"
5+
)
6+
7+
type KPP struct {
8+
Code ru_doc_code.TaxRegionCode
9+
Reason ru_doc_code.ReasonRegistration
10+
SerialNumber ru_doc_code.SerialNumber
11+
}
412

513
// Validate check to valid KPP format
614
// example: input format is 773643301
@@ -14,5 +22,12 @@ func Validate(kpp string) (bool, error) {
1422
return false, err
1523
}
1624

25+
// todo: validate tax region/office ru_doc_code.TaxRegionCode(kpp[:4])
26+
27+
_, ok := ru_doc_code.SupportedRegistrationReasonSet[ru_doc_code.RegistrationReasonCode(kpp[4:6])]
28+
if !ok {
29+
return false, ru_doc_code.ErrInvalidRegistrationReasonCode
30+
}
31+
1732
return true, nil
1833
}

kpp/kpp_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kpp
22

33
import (
44
"errors"
5+
"fmt"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -25,20 +26,20 @@ func TestValidate(t *testing.T) {
2526
IsValid: false,
2627
},
2728
{
28-
Code: "773643301",
29+
Code: "773642301",
2930
Error: nil,
3031
IsValid: true,
3132
},
3233
{
33-
Code: "773643001",
34+
Code: "773642001",
3435
Error: nil,
3536
IsValid: true,
3637
},
3738
}
38-
for _, test := range testCases {
39+
for i, test := range testCases {
3940
isValid, err := Validate(test.Code)
40-
assert.Equal(t, isValid, test.IsValid, test.Code)
41-
assert.Equal(t, true, errors.Is(test.Error, err), test.Code)
41+
assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
42+
assert.Equal(t, true, errors.Is(test.Error, err), fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
4243
}
4344
})
4445

@@ -55,20 +56,40 @@ func TestValidate(t *testing.T) {
5556
IsValid: false,
5657
},
5758
{
58-
Code: "773643301",
59+
Code: "773642301",
60+
Error: nil,
61+
IsValid: true,
62+
},
63+
{
64+
Code: "773642001",
5965
Error: nil,
6066
IsValid: true,
6167
},
68+
}
69+
for i, test := range testCases {
70+
isValid, err := Validate(test.Code)
71+
assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
72+
assert.Equal(t, true, errors.Is(test.Error, err), fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
73+
}
74+
})
75+
76+
t.Run("invalid registration reason code", func(t *testing.T) {
77+
testCases := []ru_doc_code.TestCodeCase{
78+
{
79+
Code: "773643301",
80+
Error: ru_doc_code.ErrInvalidRegistrationReasonCode,
81+
IsValid: false,
82+
},
6283
{
63-
Code: "773643001",
84+
Code: "773642301",
6485
Error: nil,
6586
IsValid: true,
6687
},
6788
}
68-
for _, test := range testCases {
89+
for i, test := range testCases {
6990
isValid, err := Validate(test.Code)
70-
assert.Equal(t, isValid, test.IsValid, test.Code)
71-
assert.Equal(t, true, errors.Is(test.Error, err), test.Code)
91+
assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
92+
assert.Equal(t, true, errors.Is(test.Error, err), fmt.Sprintf("invalid test case %d: input: %s", i, test.Code))
7293
}
7394
})
7495
}

models.go

Lines changed: 185 additions & 0 deletions
Large diffs are not rendered by default.

okato/okato.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package okato
2+
3+
import ru_doc_code "github.com/mrfoe7/ru-doc-code"
4+
5+
// Validate check to valid OKATO format
6+
// example: input format is 17205000000
7+
func Validate() (bool, error) {
8+
return false, ru_doc_code.ErrNotImplemented
9+
}

okato/okato_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package okato
2+
3+
import "testing"
4+
5+
func TestValidate(t *testing.T) {
6+
7+
}

oktmo/oktmo.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package oktmo
2+
3+
import ru_doc_code "github.com/mrfoe7/ru-doc-code"
4+
5+
// Validate check to valid OKTMO format
6+
// example: input format is 17605101
7+
func Validate() (bool, error) {
8+
return false, ru_doc_code.ErrNotImplemented
9+
}

oktmo/oktmo_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package oktmo
2+
3+
import "testing"
4+
5+
func TestValidate(t *testing.T) {
6+
7+
}

snils/snils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ func Validate(snils string) (bool, error) {
3535

3636
return hashSum%101 == code, nil
3737
}
38+
39+
// Generate generate random
40+
func Generate() string {
41+
return ""
42+
}

0 commit comments

Comments
 (0)