@accounter/opcn1214-generator 0.0.0-bootstrap.0
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.
- package/.bob/cjs/api/generate.d.ts +44 -0
- package/.bob/cjs/api/generate.js +115 -0
- package/.bob/cjs/api/parse.d.ts +28 -0
- package/.bob/cjs/api/parse.js +38 -0
- package/.bob/cjs/api/response.d.ts +24 -0
- package/.bob/cjs/api/response.js +75 -0
- package/.bob/cjs/api/validate.d.ts +16 -0
- package/.bob/cjs/api/validate.js +15 -0
- package/.bob/cjs/codec/boolean.d.ts +7 -0
- package/.bob/cjs/codec/boolean.js +49 -0
- package/.bob/cjs/codec/date.d.ts +6 -0
- package/.bob/cjs/codec/date.js +68 -0
- package/.bob/cjs/codec/enum.d.ts +4 -0
- package/.bob/cjs/codec/enum.js +26 -0
- package/.bob/cjs/codec/numeric.d.ts +56 -0
- package/.bob/cjs/codec/numeric.js +186 -0
- package/.bob/cjs/codec/padding.d.ts +10 -0
- package/.bob/cjs/codec/padding.js +26 -0
- package/.bob/cjs/codec/percent.d.ts +6 -0
- package/.bob/cjs/codec/percent.js +33 -0
- package/.bob/cjs/codec/phone.d.ts +4 -0
- package/.bob/cjs/codec/phone.js +48 -0
- package/.bob/cjs/codec/record.d.ts +18 -0
- package/.bob/cjs/codec/record.js +176 -0
- package/.bob/cjs/codec/registry.d.ts +8 -0
- package/.bob/cjs/codec/registry.js +27 -0
- package/.bob/cjs/codec/sections.d.ts +41 -0
- package/.bob/cjs/codec/sections.js +177 -0
- package/.bob/cjs/codec/text.d.ts +5 -0
- package/.bob/cjs/codec/text.js +29 -0
- package/.bob/cjs/codec/types.d.ts +36 -0
- package/.bob/cjs/codec/types.js +16 -0
- package/.bob/cjs/codec/windows1255.d.ts +9 -0
- package/.bob/cjs/codec/windows1255.js +38 -0
- package/.bob/cjs/errors.d.ts +32 -0
- package/.bob/cjs/errors.js +103 -0
- package/.bob/cjs/file/assemble.d.ts +17 -0
- package/.bob/cjs/file/assemble.js +28 -0
- package/.bob/cjs/file/control.d.ts +13 -0
- package/.bob/cjs/file/control.js +45 -0
- package/.bob/cjs/file/parse.d.ts +18 -0
- package/.bob/cjs/file/parse.js +478 -0
- package/.bob/cjs/file/split.d.ts +17 -0
- package/.bob/cjs/file/split.js +71 -0
- package/.bob/cjs/index.d.ts +16 -0
- package/.bob/cjs/index.js +28 -0
- package/.bob/cjs/layout/2024/layout.generated.d.ts +6919 -0
- package/.bob/cjs/layout/2024/layout.generated.js +7224 -0
- package/.bob/cjs/layout/2025/index.d.ts +6 -0
- package/.bob/cjs/layout/2025/index.js +10 -0
- package/.bob/cjs/layout/capital-gains.d.ts +9 -0
- package/.bob/cjs/layout/capital-gains.js +15 -0
- package/.bob/cjs/layout/countries.d.ts +5 -0
- package/.bob/cjs/layout/countries.js +10 -0
- package/.bob/cjs/layout/freeze.d.ts +5 -0
- package/.bob/cjs/layout/freeze.js +16 -0
- package/.bob/cjs/layout/registry.d.ts +10 -0
- package/.bob/cjs/layout/registry.js +32 -0
- package/.bob/cjs/layout/types.d.ts +82 -0
- package/.bob/cjs/layout/types.js +35 -0
- package/.bob/cjs/model/codes.generated.d.ts +48 -0
- package/.bob/cjs/model/codes.generated.js +628 -0
- package/.bob/cjs/model/index.d.ts +3 -0
- package/.bob/cjs/model/index.js +5 -0
- package/.bob/cjs/model/input.d.ts +543 -0
- package/.bob/cjs/model/input.js +24 -0
- package/.bob/cjs/model/normalized.d.ts +43 -0
- package/.bob/cjs/model/normalized.js +0 -0
- package/.bob/cjs/model/options.d.ts +14 -0
- package/.bob/cjs/model/options.js +0 -0
- package/.bob/cjs/model/schema.d.ts +594 -0
- package/.bob/cjs/model/schema.js +339 -0
- package/.bob/cjs/normalize/canonical.d.ts +13 -0
- package/.bob/cjs/normalize/canonical.js +288 -0
- package/.bob/cjs/normalize/capital-gains/assets.d.ts +37 -0
- package/.bob/cjs/normalize/capital-gains/assets.js +94 -0
- package/.bob/cjs/normalize/capital-gains/index.d.ts +61 -0
- package/.bob/cjs/normalize/capital-gains/index.js +149 -0
- package/.bob/cjs/normalize/capital-gains/no-withholding.d.ts +18 -0
- package/.bob/cjs/normalize/capital-gains/no-withholding.js +36 -0
- package/.bob/cjs/normalize/capital-gains/other.d.ts +54 -0
- package/.bob/cjs/normalize/capital-gains/other.js +122 -0
- package/.bob/cjs/normalize/capital-gains/section6.d.ts +7 -0
- package/.bob/cjs/normalize/capital-gains/section6.js +13 -0
- package/.bob/cjs/normalize/capital-gains/securities.d.ts +26 -0
- package/.bob/cjs/normalize/capital-gains/securities.js +58 -0
- package/.bob/cjs/normalize/denormalize.d.ts +42 -0
- package/.bob/cjs/normalize/denormalize.js +359 -0
- package/.bob/cjs/normalize/derive.d.ts +57 -0
- package/.bob/cjs/normalize/derive.js +111 -0
- package/.bob/cjs/normalize/enums.d.ts +58 -0
- package/.bob/cjs/normalize/enums.js +69 -0
- package/.bob/cjs/normalize/fields.d.ts +28 -0
- package/.bob/cjs/normalize/fields.js +86 -0
- package/.bob/cjs/normalize/foreign.d.ts +22 -0
- package/.bob/cjs/normalize/foreign.js +85 -0
- package/.bob/cjs/normalize/main.d.ts +24 -0
- package/.bob/cjs/normalize/main.js +208 -0
- package/.bob/cjs/normalize/paths.d.ts +74 -0
- package/.bob/cjs/normalize/paths.js +169 -0
- package/.bob/cjs/normalize/phone.d.ts +12 -0
- package/.bob/cjs/normalize/phone.js +35 -0
- package/.bob/cjs/normalize/rd-investments.d.ts +10 -0
- package/.bob/cjs/normalize/rd-investments.js +25 -0
- package/.bob/cjs/normalize/related-companies.d.ts +10 -0
- package/.bob/cjs/normalize/related-companies.js +25 -0
- package/.bob/cjs/normalize/report.d.ts +9 -0
- package/.bob/cjs/normalize/report.js +53 -0
- package/.bob/cjs/normalize/shareholders.d.ts +10 -0
- package/.bob/cjs/normalize/shareholders.js +30 -0
- package/.bob/cjs/normalize/text.d.ts +11 -0
- package/.bob/cjs/normalize/text.js +41 -0
- package/.bob/cjs/normalize/today.d.ts +4 -0
- package/.bob/cjs/normalize/today.js +14 -0
- package/.bob/cjs/pipeline.d.ts +13 -0
- package/.bob/cjs/pipeline.js +37 -0
- package/.bob/cjs/response/codes.d.ts +2 -0
- package/.bob/cjs/response/codes.js +31 -0
- package/.bob/cjs/validate/capital-gains-rules.d.ts +6 -0
- package/.bob/cjs/validate/capital-gains-rules.js +162 -0
- package/.bob/cjs/validate/check-digit.d.ts +10 -0
- package/.bob/cjs/validate/check-digit.js +26 -0
- package/.bob/cjs/validate/engine.d.ts +5 -0
- package/.bob/cjs/validate/engine.js +35 -0
- package/.bob/cjs/validate/field-rules.d.ts +4 -0
- package/.bob/cjs/validate/field-rules.js +331 -0
- package/.bob/cjs/validate/foreign-rules.d.ts +6 -0
- package/.bob/cjs/validate/foreign-rules.js +171 -0
- package/.bob/cjs/validate/issue.d.ts +51 -0
- package/.bob/cjs/validate/issue.js +78 -0
- package/.bob/cjs/validate/main-rules.d.ts +24 -0
- package/.bob/cjs/validate/main-rules.js +425 -0
- package/.bob/cjs/validate/parse-rules.d.ts +31 -0
- package/.bob/cjs/validate/parse-rules.js +114 -0
- package/.bob/cjs/validate/rules.d.ts +746 -0
- package/.bob/cjs/validate/rules.js +680 -0
- package/.bob/cjs/validate/shape.d.ts +19 -0
- package/.bob/cjs/validate/shape.js +231 -0
- package/.bob/cjs/validate/shareholder-rules.d.ts +6 -0
- package/.bob/cjs/validate/shareholder-rules.js +83 -0
- package/.bob/cjs/validate/structure-rules.d.ts +26 -0
- package/.bob/cjs/validate/structure-rules.js +130 -0
- package/.bob/esm/api/generate.d.ts +44 -0
- package/.bob/esm/api/generate.js +111 -0
- package/.bob/esm/api/parse.d.ts +28 -0
- package/.bob/esm/api/parse.js +34 -0
- package/.bob/esm/api/response.d.ts +24 -0
- package/.bob/esm/api/response.js +72 -0
- package/.bob/esm/api/validate.d.ts +16 -0
- package/.bob/esm/api/validate.js +11 -0
- package/.bob/esm/codec/boolean.d.ts +7 -0
- package/.bob/esm/codec/boolean.js +46 -0
- package/.bob/esm/codec/date.d.ts +6 -0
- package/.bob/esm/codec/date.js +64 -0
- package/.bob/esm/codec/enum.d.ts +4 -0
- package/.bob/esm/codec/enum.js +23 -0
- package/.bob/esm/codec/numeric.d.ts +56 -0
- package/.bob/esm/codec/numeric.js +175 -0
- package/.bob/esm/codec/padding.d.ts +10 -0
- package/.bob/esm/codec/padding.js +21 -0
- package/.bob/esm/codec/percent.d.ts +6 -0
- package/.bob/esm/codec/percent.js +30 -0
- package/.bob/esm/codec/phone.d.ts +4 -0
- package/.bob/esm/codec/phone.js +45 -0
- package/.bob/esm/codec/record.d.ts +18 -0
- package/.bob/esm/codec/record.js +172 -0
- package/.bob/esm/codec/registry.d.ts +8 -0
- package/.bob/esm/codec/registry.js +23 -0
- package/.bob/esm/codec/sections.d.ts +41 -0
- package/.bob/esm/codec/sections.js +170 -0
- package/.bob/esm/codec/text.d.ts +5 -0
- package/.bob/esm/codec/text.js +26 -0
- package/.bob/esm/codec/types.d.ts +36 -0
- package/.bob/esm/codec/types.js +12 -0
- package/.bob/esm/codec/windows1255.d.ts +9 -0
- package/.bob/esm/codec/windows1255.js +32 -0
- package/.bob/esm/errors.d.ts +32 -0
- package/.bob/esm/errors.js +94 -0
- package/.bob/esm/file/assemble.d.ts +17 -0
- package/.bob/esm/file/assemble.js +25 -0
- package/.bob/esm/file/control.d.ts +13 -0
- package/.bob/esm/file/control.js +41 -0
- package/.bob/esm/file/parse.d.ts +18 -0
- package/.bob/esm/file/parse.js +474 -0
- package/.bob/esm/file/split.d.ts +17 -0
- package/.bob/esm/file/split.js +68 -0
- package/.bob/esm/index.d.ts +16 -0
- package/.bob/esm/index.js +11 -0
- package/.bob/esm/layout/2024/layout.generated.d.ts +6919 -0
- package/.bob/esm/layout/2024/layout.generated.js +7221 -0
- package/.bob/esm/layout/2025/index.d.ts +6 -0
- package/.bob/esm/layout/2025/index.js +7 -0
- package/.bob/esm/layout/capital-gains.d.ts +9 -0
- package/.bob/esm/layout/capital-gains.js +11 -0
- package/.bob/esm/layout/countries.d.ts +5 -0
- package/.bob/esm/layout/countries.js +7 -0
- package/.bob/esm/layout/freeze.d.ts +5 -0
- package/.bob/esm/layout/freeze.js +13 -0
- package/.bob/esm/layout/registry.d.ts +10 -0
- package/.bob/esm/layout/registry.js +27 -0
- package/.bob/esm/layout/types.d.ts +82 -0
- package/.bob/esm/layout/types.js +32 -0
- package/.bob/esm/model/codes.generated.d.ts +48 -0
- package/.bob/esm/model/codes.generated.js +625 -0
- package/.bob/esm/model/index.d.ts +3 -0
- package/.bob/esm/model/index.js +2 -0
- package/.bob/esm/model/input.d.ts +543 -0
- package/.bob/esm/model/input.js +21 -0
- package/.bob/esm/model/normalized.d.ts +43 -0
- package/.bob/esm/model/normalized.js +0 -0
- package/.bob/esm/model/options.d.ts +14 -0
- package/.bob/esm/model/options.js +0 -0
- package/.bob/esm/model/schema.d.ts +594 -0
- package/.bob/esm/model/schema.js +335 -0
- package/.bob/esm/normalize/canonical.d.ts +13 -0
- package/.bob/esm/normalize/canonical.js +285 -0
- package/.bob/esm/normalize/capital-gains/assets.d.ts +37 -0
- package/.bob/esm/normalize/capital-gains/assets.js +87 -0
- package/.bob/esm/normalize/capital-gains/index.d.ts +61 -0
- package/.bob/esm/normalize/capital-gains/index.js +142 -0
- package/.bob/esm/normalize/capital-gains/no-withholding.d.ts +18 -0
- package/.bob/esm/normalize/capital-gains/no-withholding.js +31 -0
- package/.bob/esm/normalize/capital-gains/other.d.ts +54 -0
- package/.bob/esm/normalize/capital-gains/other.js +112 -0
- package/.bob/esm/normalize/capital-gains/section6.d.ts +7 -0
- package/.bob/esm/normalize/capital-gains/section6.js +9 -0
- package/.bob/esm/normalize/capital-gains/securities.d.ts +26 -0
- package/.bob/esm/normalize/capital-gains/securities.js +52 -0
- package/.bob/esm/normalize/denormalize.d.ts +42 -0
- package/.bob/esm/normalize/denormalize.js +354 -0
- package/.bob/esm/normalize/derive.d.ts +57 -0
- package/.bob/esm/normalize/derive.js +99 -0
- package/.bob/esm/normalize/enums.d.ts +58 -0
- package/.bob/esm/normalize/enums.js +64 -0
- package/.bob/esm/normalize/fields.d.ts +28 -0
- package/.bob/esm/normalize/fields.js +81 -0
- package/.bob/esm/normalize/foreign.d.ts +22 -0
- package/.bob/esm/normalize/foreign.js +81 -0
- package/.bob/esm/normalize/main.d.ts +24 -0
- package/.bob/esm/normalize/main.js +204 -0
- package/.bob/esm/normalize/paths.d.ts +74 -0
- package/.bob/esm/normalize/paths.js +161 -0
- package/.bob/esm/normalize/phone.d.ts +12 -0
- package/.bob/esm/normalize/phone.js +32 -0
- package/.bob/esm/normalize/rd-investments.d.ts +10 -0
- package/.bob/esm/normalize/rd-investments.js +22 -0
- package/.bob/esm/normalize/related-companies.d.ts +10 -0
- package/.bob/esm/normalize/related-companies.js +22 -0
- package/.bob/esm/normalize/report.d.ts +9 -0
- package/.bob/esm/normalize/report.js +50 -0
- package/.bob/esm/normalize/shareholders.d.ts +10 -0
- package/.bob/esm/normalize/shareholders.js +27 -0
- package/.bob/esm/normalize/text.d.ts +11 -0
- package/.bob/esm/normalize/text.js +37 -0
- package/.bob/esm/normalize/today.d.ts +4 -0
- package/.bob/esm/normalize/today.js +11 -0
- package/.bob/esm/pipeline.d.ts +13 -0
- package/.bob/esm/pipeline.js +34 -0
- package/.bob/esm/response/codes.d.ts +2 -0
- package/.bob/esm/response/codes.js +28 -0
- package/.bob/esm/validate/capital-gains-rules.d.ts +6 -0
- package/.bob/esm/validate/capital-gains-rules.js +159 -0
- package/.bob/esm/validate/check-digit.d.ts +10 -0
- package/.bob/esm/validate/check-digit.js +23 -0
- package/.bob/esm/validate/engine.d.ts +5 -0
- package/.bob/esm/validate/engine.js +32 -0
- package/.bob/esm/validate/field-rules.d.ts +4 -0
- package/.bob/esm/validate/field-rules.js +328 -0
- package/.bob/esm/validate/foreign-rules.d.ts +6 -0
- package/.bob/esm/validate/foreign-rules.js +168 -0
- package/.bob/esm/validate/issue.d.ts +51 -0
- package/.bob/esm/validate/issue.js +72 -0
- package/.bob/esm/validate/main-rules.d.ts +24 -0
- package/.bob/esm/validate/main-rules.js +420 -0
- package/.bob/esm/validate/parse-rules.d.ts +31 -0
- package/.bob/esm/validate/parse-rules.js +110 -0
- package/.bob/esm/validate/rules.d.ts +746 -0
- package/.bob/esm/validate/rules.js +676 -0
- package/.bob/esm/validate/shape.d.ts +19 -0
- package/.bob/esm/validate/shape.js +227 -0
- package/.bob/esm/validate/shareholder-rules.d.ts +6 -0
- package/.bob/esm/validate/shareholder-rules.js +80 -0
- package/.bob/esm/validate/structure-rules.d.ts +26 -0
- package/.bob/esm/validate/structure-rules.js +122 -0
- package/.bob/tsconfig.tsbuildinfo +1 -0
- package/.gitattributes +1 -0
- package/CLAUDE.md +39 -0
- package/README.md +337 -0
- package/dist/cjs/index.js +28 -0
- package/dist/esm/index.js +11 -0
- package/documentation/IMPLEMENTATION_PLAN.md +2258 -0
- package/documentation/SPEC.md +1803 -0
- package/documentation/layout/2024/codes.csv +261 -0
- package/documentation/layout/2024/countries.csv +256 -0
- package/documentation/layout/2024/fields.csv +271 -0
- package/documentation/layout/2024/records.csv +18 -0
- package/documentation/layout/README.md +87 -0
- package/documentation/specifications/1214-2024.pdf +0 -0
- package/documentation/tools/extract_layout.py +191 -0
- package/package.json +77 -0
- package/scripts/generate-layout.ts +23 -0
- package/scripts/layout/csv.ts +111 -0
- package/scripts/layout/derived-codes.ts +12 -0
- package/scripts/layout/render.ts +364 -0
- package/scripts/layout/sources.ts +51 -0
- package/scripts/layout/values.ts +42 -0
- package/scripts/render-rules-table.ts +66 -0
- package/src/api/generate.ts +169 -0
- package/src/api/parse.ts +58 -0
- package/src/api/response.ts +110 -0
- package/src/api/validate.ts +26 -0
- package/src/codec/boolean.ts +62 -0
- package/src/codec/date.ts +75 -0
- package/src/codec/enum.ts +28 -0
- package/src/codec/numeric.ts +208 -0
- package/src/codec/padding.ts +33 -0
- package/src/codec/percent.ts +35 -0
- package/src/codec/phone.ts +54 -0
- package/src/codec/record.ts +206 -0
- package/src/codec/registry.ts +27 -0
- package/src/codec/sections.ts +208 -0
- package/src/codec/text.ts +31 -0
- package/src/codec/types.ts +47 -0
- package/src/codec/windows1255.ts +38 -0
- package/src/errors.ts +114 -0
- package/src/file/assemble.ts +42 -0
- package/src/file/control.ts +59 -0
- package/src/file/parse.ts +620 -0
- package/src/file/split.ts +86 -0
- package/src/index.ts +70 -0
- package/src/layout/2024/layout.generated.ts +7238 -0
- package/src/layout/2025/index.ts +9 -0
- package/src/layout/capital-gains.ts +20 -0
- package/src/layout/countries.ts +7 -0
- package/src/layout/freeze.ts +13 -0
- package/src/layout/registry.ts +33 -0
- package/src/layout/types.ts +134 -0
- package/src/model/codes.generated.ts +1190 -0
- package/src/model/index.ts +4 -0
- package/src/model/input.ts +594 -0
- package/src/model/normalized.ts +38 -0
- package/src/model/options.ts +17 -0
- package/src/model/schema.ts +381 -0
- package/src/normalize/canonical.ts +374 -0
- package/src/normalize/capital-gains/assets.ts +112 -0
- package/src/normalize/capital-gains/index.ts +212 -0
- package/src/normalize/capital-gains/no-withholding.ts +46 -0
- package/src/normalize/capital-gains/other.ts +153 -0
- package/src/normalize/capital-gains/section6.ts +14 -0
- package/src/normalize/capital-gains/securities.ts +73 -0
- package/src/normalize/denormalize.ts +426 -0
- package/src/normalize/derive.ts +136 -0
- package/src/normalize/enums.ts +87 -0
- package/src/normalize/fields.ts +110 -0
- package/src/normalize/foreign.ts +114 -0
- package/src/normalize/main.ts +284 -0
- package/src/normalize/paths.ts +184 -0
- package/src/normalize/phone.ts +45 -0
- package/src/normalize/rd-investments.ts +38 -0
- package/src/normalize/related-companies.ts +37 -0
- package/src/normalize/report.ts +59 -0
- package/src/normalize/shareholders.ts +42 -0
- package/src/normalize/text.ts +40 -0
- package/src/normalize/today.ts +15 -0
- package/src/pipeline.ts +42 -0
- package/src/response/codes.ts +30 -0
- package/src/validate/capital-gains-rules.ts +199 -0
- package/src/validate/check-digit.ts +25 -0
- package/src/validate/engine.ts +45 -0
- package/src/validate/field-rules.ts +383 -0
- package/src/validate/foreign-rules.ts +274 -0
- package/src/validate/issue.ts +121 -0
- package/src/validate/main-rules.ts +678 -0
- package/src/validate/parse-rules.ts +169 -0
- package/src/validate/rules.ts +747 -0
- package/src/validate/shape.ts +278 -0
- package/src/validate/shareholder-rules.ts +92 -0
- package/src/validate/structure-rules.ts +136 -0
- package/tests/api/batch.test.ts +227 -0
- package/tests/api/exports.test.ts +355 -0
- package/tests/api/generate.test.ts +409 -0
- package/tests/api/parse.test.ts +789 -0
- package/tests/api/response.test.ts +152 -0
- package/tests/api/validate.test.ts +86 -0
- package/tests/codec/numeric.test.ts +325 -0
- package/tests/codec/record.test.ts +318 -0
- package/tests/codec/registry.test.ts +17 -0
- package/tests/codec/sections.test.ts +333 -0
- package/tests/codec/text.test.ts +454 -0
- package/tests/codec/windows1255.test.ts +46 -0
- package/tests/docs/readme.test.ts +69 -0
- package/tests/edge-cases.test.ts +359 -0
- package/tests/errors.test.ts +138 -0
- package/tests/file/assemble.test.ts +188 -0
- package/tests/file/split.test.ts +61 -0
- package/tests/fixtures/builders.ts +512 -0
- package/tests/fixtures/files.ts +78 -0
- package/tests/fixtures/golden/README.md +37 -0
- package/tests/fixtures/golden/VERIFICATION.md +72 -0
- package/tests/fixtures/golden/batch-50.input.ts +92 -0
- package/tests/fixtures/golden/batch-50.opcn +150 -0
- package/tests/fixtures/golden/capital-gains-max.input.ts +177 -0
- package/tests/fixtures/golden/capital-gains-max.opcn +17 -0
- package/tests/fixtures/golden/cg-27.input.ts +63 -0
- package/tests/fixtures/golden/cg-27.opcn +4 -0
- package/tests/fixtures/golden/cg-50.input.ts +59 -0
- package/tests/fixtures/golden/cg-50.opcn +4 -0
- package/tests/fixtures/golden/cg-51.input.ts +60 -0
- package/tests/fixtures/golden/cg-51.opcn +4 -0
- package/tests/fixtures/golden/cg-54.input.ts +53 -0
- package/tests/fixtures/golden/cg-54.opcn +4 -0
- package/tests/fixtures/golden/cg-60.input.ts +77 -0
- package/tests/fixtures/golden/cg-60.opcn +4 -0
- package/tests/fixtures/golden/cg-63.input.ts +51 -0
- package/tests/fixtures/golden/cg-63.opcn +4 -0
- package/tests/fixtures/golden/cg-64.input.ts +62 -0
- package/tests/fixtures/golden/cg-64.opcn +4 -0
- package/tests/fixtures/golden/cg-65.input.ts +79 -0
- package/tests/fixtures/golden/cg-65.opcn +4 -0
- package/tests/fixtures/golden/cg-66.input.ts +53 -0
- package/tests/fixtures/golden/cg-66.opcn +4 -0
- package/tests/fixtures/golden/cg-77.input.ts +109 -0
- package/tests/fixtures/golden/cg-77.opcn +4 -0
- package/tests/fixtures/golden/foreign.input.ts +202 -0
- package/tests/fixtures/golden/foreign.opcn +27 -0
- package/tests/fixtures/golden/hebrew-edge.input.ts +90 -0
- package/tests/fixtures/golden/hebrew-edge.opcn +8 -0
- package/tests/fixtures/golden/kibbutz.input.ts +31 -0
- package/tests/fixtures/golden/kibbutz.opcn +2 -0
- package/tests/fixtures/golden/main-full.input.ts +780 -0
- package/tests/fixtures/golden/main-full.opcn +101 -0
- package/tests/fixtures/golden/minimal.input.ts +37 -0
- package/tests/fixtures/golden/minimal.opcn +3 -0
- package/tests/fixtures/golden/related-and-rd.input.ts +59 -0
- package/tests/fixtures/golden/related-and-rd.opcn +11 -0
- package/tests/fixtures/random.ts +843 -0
- package/tests/golden/fixtures.test.ts +627 -0
- package/tests/golden/golden.test.ts +95 -0
- package/tests/helpers/coverage.ts +18 -0
- package/tests/helpers/sample-values.ts +114 -0
- package/tests/layout/codegen-sync.test.ts +19 -0
- package/tests/layout/integrity.test.ts +232 -0
- package/tests/layout/registry.test.ts +98 -0
- package/tests/model/code-unions.test.ts +91 -0
- package/tests/model/schema.test.ts +1031 -0
- package/tests/normalize/canonical.test.ts +728 -0
- package/tests/normalize/capital-gains.test.ts +1850 -0
- package/tests/normalize/coverage.test.ts +88 -0
- package/tests/normalize/denormalize.test.ts +318 -0
- package/tests/normalize/enums.test.ts +118 -0
- package/tests/normalize/foreign.test.ts +273 -0
- package/tests/normalize/main.test.ts +839 -0
- package/tests/normalize/paths.test.ts +257 -0
- package/tests/normalize/rd-investments.test.ts +99 -0
- package/tests/normalize/related-companies.test.ts +106 -0
- package/tests/normalize/shareholders.test.ts +117 -0
- package/tests/normalize/text.test.ts +86 -0
- package/tests/pipeline.test.ts +96 -0
- package/tests/roundtrip/determinism.test.ts +207 -0
- package/tests/roundtrip/property.test.ts +126 -0
- package/tests/roundtrip/roundtrip.test.ts +573 -0
- package/tests/rules/cases.ts +873 -0
- package/tests/rules/rules.test.ts +69 -0
- package/tests/rules/spec-sync.test.ts +80 -0
- package/tests/scripts/csv.test.ts +78 -0
- package/tests/scripts/values.test.ts +80 -0
- package/tests/validate/capital-gains-rules.test.ts +307 -0
- package/tests/validate/check-digit.test.ts +42 -0
- package/tests/validate/field-rules.test.ts +867 -0
- package/tests/validate/foreign-rules.test.ts +255 -0
- package/tests/validate/issue.test.ts +96 -0
- package/tests/validate/main-rules.test.ts +761 -0
- package/tests/validate/parse-rules.test.ts +293 -0
- package/tests/validate/shareholder-rules.test.ts +143 -0
- package/tsconfig.json +10 -0
- package/tsconfig.typecheck.json +9 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Record 1000 conditional requirements and consistency warnings (SPEC §9.2 stage 4, §10.3): pure
|
|
3
|
+
* checks over the normalized main record, so they run on validated input and on parsed files alike.
|
|
4
|
+
*/
|
|
5
|
+
import { isIsoDate } from '../codec/date.js';
|
|
6
|
+
import { Opcn1214InternalError } from '../errors.js';
|
|
7
|
+
import { isCapitalGainsRecordType } from '../layout/capital-gains.js';
|
|
8
|
+
import { codeKey, pathFor, REPORTABLE_POSITION_KEYS, REPORTABLE_POSITIONS, } from '../normalize/paths.js';
|
|
9
|
+
import { isValidIsraeliCheckDigit } from './check-digit.js';
|
|
10
|
+
import { makeIssue } from './issue.js';
|
|
11
|
+
const FAMILY_COMPANY = 'declarations.familyCompany.isFamilyCompany';
|
|
12
|
+
const BENEFICIARY_ENTERPRISE = 'declarations.beneficiaryEnterprise.marked';
|
|
13
|
+
const SPECIAL_YEAR = 'declarations.specialYear.marked';
|
|
14
|
+
const NOTICE_DATE = 'declarations.beneficiaryEnterprise.noticeDate';
|
|
15
|
+
const BALANCE_SHEET_DATE = 'declarations.specialYear.balanceSheetDate';
|
|
16
|
+
const INVESTMENT_LAW = 'declarations.claimsCapitalInvestmentLawBenefits';
|
|
17
|
+
/** The field the positions issue is located at, 1000@1034. */
|
|
18
|
+
const FIRST_POSITION = 'declarations.reportablePositions[0]';
|
|
19
|
+
/** Codes whose presence calls for 849 (p.8). */
|
|
20
|
+
const INVESTMENT_LAW_CODES = ['101', '102'];
|
|
21
|
+
/** Code 226 value "other cooperative society, not a kibbutz" (p.18). */
|
|
22
|
+
const OTHER_COOPERATIVE = 9;
|
|
23
|
+
const UNTRANSMITTED_COUNT = 'capitalGainsSummary.untransmittedCount';
|
|
24
|
+
/** The reasons for untransmitted capital-gains appendices, 1000@964–967 (p.10–11). */
|
|
25
|
+
const UNTRANSMITTED_REASONS = [
|
|
26
|
+
'capitalGainsSummary.reasons.lossOrNoGain',
|
|
27
|
+
'capitalGainsSummary.reasons.overFiveImprovementBalances',
|
|
28
|
+
'capitalGainsSummary.reasons.over14Appendices',
|
|
29
|
+
'capitalGainsSummary.reasons.other',
|
|
30
|
+
];
|
|
31
|
+
/** Codes derived from `bankAccount` (SPEC §7.4). */
|
|
32
|
+
const BANK_ACCOUNT_CODES = ['277', '278', '280'];
|
|
33
|
+
const ISRAELI_PURCHASE = 'qualifyingCompany.israeliPurchaseAmount';
|
|
34
|
+
const FOREIGN_PURCHASE = 'qualifyingCompany.foreignPurchaseAmount';
|
|
35
|
+
/**
|
|
36
|
+
* True for a number above 0: an optional count or amount of 0 is absent in the file (SPEC §8.4), so
|
|
37
|
+
* input and parsed files are judged alike.
|
|
38
|
+
*/
|
|
39
|
+
function isPositive(value) {
|
|
40
|
+
return typeof value === 'number' && value > 0;
|
|
41
|
+
}
|
|
42
|
+
/** The 1000 records of `report` (one per report). */
|
|
43
|
+
function mainRecords(report) {
|
|
44
|
+
return report.records.filter(record => record.recordType === '1000');
|
|
45
|
+
}
|
|
46
|
+
function mainField(report, key) {
|
|
47
|
+
const field = report.layout.records['1000'].fields.find(def => def.key === key);
|
|
48
|
+
if (!field) {
|
|
49
|
+
throw new Opcn1214InternalError(`Record 1000 has no field "${key}"`);
|
|
50
|
+
}
|
|
51
|
+
return field;
|
|
52
|
+
}
|
|
53
|
+
/** An issue of `ruleId` located at the header field `key` of `record`. */
|
|
54
|
+
function fieldIssue(ruleId, report, record, key, message, path = pathFor(record.recordType, record.index, key)) {
|
|
55
|
+
const field = mainField(report, key);
|
|
56
|
+
return makeIssue(ruleId, {
|
|
57
|
+
message,
|
|
58
|
+
path,
|
|
59
|
+
recordType: record.recordType,
|
|
60
|
+
recordIndex: record.index,
|
|
61
|
+
field: { position: field.position, length: field.length, nameHe: field.nameHe },
|
|
62
|
+
specRef: { page: field.specPage },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** An issue of `ruleId` located at the absent `code` of `record`. */
|
|
66
|
+
function codeIssue(ruleId, report, record, code, message) {
|
|
67
|
+
const def = report.layout.records['1000'].codes.find(candidate => candidate.code === code);
|
|
68
|
+
if (!def) {
|
|
69
|
+
throw new Opcn1214InternalError(`Record 1000 has no code ${code}`);
|
|
70
|
+
}
|
|
71
|
+
return makeIssue(ruleId, {
|
|
72
|
+
message,
|
|
73
|
+
path: pathFor(record.recordType, record.index, codeKey(code)),
|
|
74
|
+
recordType: record.recordType,
|
|
75
|
+
recordIndex: record.index,
|
|
76
|
+
code,
|
|
77
|
+
specRef: { page: def.specPage },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** A rule: when the flag or yes/no `condition` is true, the header field `key` must have a value. */
|
|
81
|
+
function requiresField(ruleId, condition, key, why) {
|
|
82
|
+
return report => mainRecords(report)
|
|
83
|
+
.filter(record => record.values[condition] === true && record.values[key] === undefined)
|
|
84
|
+
.map(record => fieldIssue(ruleId, report, record, key, `${why}: field ${key} (1000@${mainField(report, key).position}) is required.`));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A rule: when the flag or yes/no `condition` is true, `code` must be in the code-amount section
|
|
88
|
+
* (with value 0 when the code is zeroAllowed: zeros of other codes are omitted while normalizing).
|
|
89
|
+
*/
|
|
90
|
+
function requiresCode(ruleId, condition, code, why) {
|
|
91
|
+
return report => mainRecords(report)
|
|
92
|
+
.filter(record => record.values[condition] === true && !record.codes.has(code))
|
|
93
|
+
.map(record => codeIssue(ruleId, report, record, code, `${why}: code ${code} is required.`));
|
|
94
|
+
}
|
|
95
|
+
const COMPANY_FILE_NUMBER = 'company.fileNumber';
|
|
96
|
+
const WITHHOLDING_FILE_NUMBER = 'company.withholdingFileNumber';
|
|
97
|
+
/** Width of the company and withholding file numbers (1000@137, 1000@225). */
|
|
98
|
+
const FILE_NUMBER_WIDTH = 9;
|
|
99
|
+
/** A withholding file number starts with 9 (SPEC §15 A-28). */
|
|
100
|
+
const WITHHOLDING_FILE_LEAD = '9';
|
|
101
|
+
/** Digits of the company file number a withholding file number repeats after its lead 9. */
|
|
102
|
+
const COMPANY_DIGITS_IN_WITHHOLDING_FILE = 7;
|
|
103
|
+
const DIGITS = /^\d+$/;
|
|
104
|
+
/** The first 8 digits of the withholding file number of company `fileNumber` (SPEC §15 A-28). */
|
|
105
|
+
function withholdingFilePrefix(fileNumber) {
|
|
106
|
+
return (WITHHOLDING_FILE_LEAD +
|
|
107
|
+
fileNumber.padStart(FILE_NUMBER_WIDTH, '0').slice(0, COMPANY_DIGITS_IN_WITHHOLDING_FILE));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The withholding file number (תיק ניכויים) of company `fileNumber` (digits, left-padded to 9): 9,
|
|
111
|
+
* the first 7 digits of the company file number and the Israeli check digit over all 9 digits
|
|
112
|
+
* (SPEC §15 A-28; 514000009 → 951400001).
|
|
113
|
+
*/
|
|
114
|
+
export function expectedWithholdingFileNumber(fileNumber) {
|
|
115
|
+
const prefix = withholdingFilePrefix(fileNumber);
|
|
116
|
+
for (let check = 0; check <= 9; check++) {
|
|
117
|
+
if (isValidIsraeliCheckDigit(`${prefix}${check}`)) {
|
|
118
|
+
return `${prefix}${check}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Unreachable: exactly one check digit completes any 8 digits.
|
|
122
|
+
throw new Opcn1214InternalError(`No check digit completes ${prefix}`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* main.withholdingFile.companyNumber: the first 8 digits of the withholding file number (1000@225)
|
|
126
|
+
* must be 9 and the first 7 digits of the company file number (SPEC §15 A-28, found on shopcn).
|
|
127
|
+
* The 9th digit is left to field.checkDigit, and values that are not digit strings to
|
|
128
|
+
* field.numeric.
|
|
129
|
+
*/
|
|
130
|
+
function withholdingFileCompanyNumber(report) {
|
|
131
|
+
return mainRecords(report).flatMap(record => {
|
|
132
|
+
const withholding = record.values[WITHHOLDING_FILE_NUMBER];
|
|
133
|
+
const fileNumber = record.values[COMPANY_FILE_NUMBER];
|
|
134
|
+
if (typeof withholding !== 'string' ||
|
|
135
|
+
typeof fileNumber !== 'string' ||
|
|
136
|
+
!DIGITS.test(withholding) ||
|
|
137
|
+
!DIGITS.test(fileNumber) ||
|
|
138
|
+
withholding.length > FILE_NUMBER_WIDTH ||
|
|
139
|
+
fileNumber.length > FILE_NUMBER_WIDTH ||
|
|
140
|
+
withholding.padStart(FILE_NUMBER_WIDTH, '0').startsWith(withholdingFilePrefix(fileNumber))) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
const expected = expectedWithholdingFileNumber(fileNumber);
|
|
144
|
+
const field = mainField(report, WITHHOLDING_FILE_NUMBER);
|
|
145
|
+
return [
|
|
146
|
+
makeIssue('main.withholdingFile.companyNumber', {
|
|
147
|
+
message: `${WITHHOLDING_FILE_NUMBER} (1000@${field.position}) ${withholding} does not match the company file number ${fileNumber}: a withholding file number is 9, the first 7 digits of the company file number and a check digit, here ${expected}.`,
|
|
148
|
+
path: record.paths[WITHHOLDING_FILE_NUMBER] ??
|
|
149
|
+
pathFor(record.recordType, record.index, WITHHOLDING_FILE_NUMBER),
|
|
150
|
+
recordType: record.recordType,
|
|
151
|
+
recordIndex: record.index,
|
|
152
|
+
field: { position: field.position, length: field.length, nameHe: field.nameHe },
|
|
153
|
+
value: withholding,
|
|
154
|
+
expected,
|
|
155
|
+
specRef: { page: field.specPage },
|
|
156
|
+
}),
|
|
157
|
+
];
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** main.familyCompany.fileNumber: 836 marked without 837 (p.7). */
|
|
161
|
+
const familyCompanyFileNumber = requiresField('main.familyCompany.fileNumber', FAMILY_COMPANY, 'declarations.familyCompany.representativeFileNumber', 'The company is a family company (1000@836)');
|
|
162
|
+
/** main.familyCompany.code080: 836 marked without code 080, 0 allowed (p.15). */
|
|
163
|
+
const familyCompanyCode080 = requiresCode('main.familyCompany.code080', FAMILY_COMPANY, '080', 'The company is a family company (1000@836)');
|
|
164
|
+
/** main.houseCompany.code084: 846 marked without code 084, 0 allowed (p.15). */
|
|
165
|
+
const houseCompanyCode084 = requiresCode('main.houseCompany.code084', 'declarations.isHouseCompany', '084', 'The company is a house company (1000@846)');
|
|
166
|
+
/** main.investmentLaw.flag: code 101 or 102 filled but 849 not marked (p.8). */
|
|
167
|
+
function investmentLawFlag(report) {
|
|
168
|
+
return mainRecords(report).flatMap(record => {
|
|
169
|
+
const filled = INVESTMENT_LAW_CODES.filter(code => record.codes.has(code));
|
|
170
|
+
if (filled.length === 0 || record.values[INVESTMENT_LAW] === true) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
return [
|
|
174
|
+
fieldIssue('main.investmentLaw.flag', report, record, INVESTMENT_LAW, `Code ${filled.join(' and ')} is filled, so ${INVESTMENT_LAW} (1000@849) must be marked.`),
|
|
175
|
+
];
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/** main.beneficiaryEnterprise.noticeDate: 851 marked without 852 (p.8). */
|
|
179
|
+
const beneficiaryEnterpriseNoticeDate = requiresField('main.beneficiaryEnterprise.noticeDate', BENEFICIARY_ENTERPRISE, NOTICE_DATE, 'A beneficiary enterprise is marked (1000@851)');
|
|
180
|
+
/** An ISO `YYYY-MM-DD` date as written in the file, `DD/MM/YYYY`. */
|
|
181
|
+
function fileDate(iso) {
|
|
182
|
+
const [year, month, day] = iso.split('-');
|
|
183
|
+
return `${day}/${month}/${year}`;
|
|
184
|
+
}
|
|
185
|
+
/** The ISO date of a UTC Date. */
|
|
186
|
+
function isoOf(date) {
|
|
187
|
+
return date.toISOString().slice(0, 10);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The earliest beneficiary-enterprise notice date (1000@852) SHAAM accepts (SPEC §15 A-33): the
|
|
191
|
+
* start of the tax year, 1 January of `taxYear`. With a valid special-year balance-sheet date
|
|
192
|
+
* (1000@864) the special year's start is used when it is earlier: the day after the same calendar
|
|
193
|
+
* date one year before (29 February maps to 28 February), so 2024-09-30 → 2023-10-01 and
|
|
194
|
+
* 2024-02-29 → 2023-03-01. Permissive on purpose: shopcn was only probed with a calendar year.
|
|
195
|
+
*/
|
|
196
|
+
export function earliestNoticeDate(taxYear, balanceSheetDate) {
|
|
197
|
+
const yearStart = isoOf(new Date(Date.UTC(taxYear, 0, 1)));
|
|
198
|
+
if (balanceSheetDate === undefined || !isIsoDate(balanceSheetDate)) {
|
|
199
|
+
return yearStart;
|
|
200
|
+
}
|
|
201
|
+
const [year, month, day] = balanceSheetDate.split('-').map(Number);
|
|
202
|
+
const lastDayOfMonth = new Date(Date.UTC(year - 1, month, 0)).getUTCDate();
|
|
203
|
+
const specialYearStart = isoOf(new Date(Date.UTC(year - 1, month - 1, Math.min(day, lastDayOfMonth) + 1)));
|
|
204
|
+
return specialYearStart < yearStart ? specialYearStart : yearStart;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* main.beneficiaryEnterprise.noticeDateBeforeTaxYear: the notice date (1000@852) may not precede
|
|
208
|
+
* the start of the tax year (SPEC §15 A-33, found on shopcn); earliestNoticeDate gives the bound.
|
|
209
|
+
* An invalid date is left to field.date.
|
|
210
|
+
*/
|
|
211
|
+
function beneficiaryEnterpriseNoticeDateBeforeTaxYear(report) {
|
|
212
|
+
return mainRecords(report).flatMap(record => {
|
|
213
|
+
const noticeDate = record.values[NOTICE_DATE];
|
|
214
|
+
if (!isIsoDate(noticeDate)) {
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
const balanceSheetDate = record.values[BALANCE_SHEET_DATE];
|
|
218
|
+
const earliest = earliestNoticeDate(report.taxYear, typeof balanceSheetDate === 'string' ? balanceSheetDate : undefined);
|
|
219
|
+
if (noticeDate >= earliest) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const field = mainField(report, NOTICE_DATE);
|
|
223
|
+
return [
|
|
224
|
+
makeIssue('main.beneficiaryEnterprise.noticeDateBeforeTaxYear', {
|
|
225
|
+
message: `The beneficiary-enterprise notice date (1000@${field.position}) ${fileDate(noticeDate)} is before the start of tax year ${report.taxYear}; the earliest date SHAAM accepts is ${fileDate(earliest)}.`,
|
|
226
|
+
path: record.paths[NOTICE_DATE] ?? pathFor(record.recordType, record.index, NOTICE_DATE),
|
|
227
|
+
recordType: record.recordType,
|
|
228
|
+
recordIndex: record.index,
|
|
229
|
+
field: { position: field.position, length: field.length, nameHe: field.nameHe },
|
|
230
|
+
value: noticeDate,
|
|
231
|
+
expected: `on or after ${fileDate(earliest)}`,
|
|
232
|
+
specRef: { page: field.specPage },
|
|
233
|
+
}),
|
|
234
|
+
];
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/** main.specialYear.balanceSheetDate: 863 marked without 864 (p.8). */
|
|
238
|
+
const specialYearBalanceSheetDate = requiresField('main.specialYear.balanceSheetDate', SPECIAL_YEAR, BALANCE_SHEET_DATE, 'A special year is marked (1000@863)');
|
|
239
|
+
/** main.kibbutz.code226: isKibbutz without code 226 (p.9, p.18; SPEC §15 A-13). */
|
|
240
|
+
const kibbutzCode226 = requiresCode('main.kibbutz.code226', 'declarations.isKibbutz', '226', 'The company is a kibbutz (1000@877)');
|
|
241
|
+
/** main.buildingIncome.code259: hasBuildingIncome (884 = yes) without code 259 (p.9). */
|
|
242
|
+
const buildingIncomeCode259 = requiresCode('main.buildingIncome.code259', 'declarations.hasBuildingIncome', '259', 'The company has income from a building (1000@884)');
|
|
243
|
+
/** main.cgReasons.otherText: reason "other" (967) marked without its text (968) (p.11). */
|
|
244
|
+
const cgReasonsOtherText = requiresField('main.cgReasons.otherText', 'capitalGainsSummary.reasons.other', 'capitalGainsSummary.reasons.otherText', 'The capital-gains reason "other" is marked (1000@967)');
|
|
245
|
+
/**
|
|
246
|
+
* main.reportablePositions.required: tookReportablePosition (1030 = yes) and none of the positions
|
|
247
|
+
* 1034–1046 (p.11). Reported at the positions array, located at the first position field.
|
|
248
|
+
*/
|
|
249
|
+
function reportablePositionsRequired(report) {
|
|
250
|
+
return mainRecords(report)
|
|
251
|
+
.filter(record => record.values['declarations.tookReportablePosition'] === true &&
|
|
252
|
+
REPORTABLE_POSITION_KEYS.every(key => record.values[key] === undefined))
|
|
253
|
+
.map(record => fieldIssue('main.reportablePositions.required', report, record, FIRST_POSITION, `declarations.tookReportablePosition is yes (1000@1030), so at least one reportable position number (1000@1034–1046) is required.`, REPORTABLE_POSITIONS));
|
|
254
|
+
}
|
|
255
|
+
/** main.kibbutz.code226Other: code 226 = 9 ("other cooperative, not kibbutz") while kibbutz (p.18). */
|
|
256
|
+
function kibbutzCode226Other(report) {
|
|
257
|
+
return mainRecords(report)
|
|
258
|
+
.filter(record => record.values['declarations.isKibbutz'] === true &&
|
|
259
|
+
record.codes.get('226') === OTHER_COOPERATIVE)
|
|
260
|
+
.map(record => ({
|
|
261
|
+
...codeIssue('main.kibbutz.code226Other', report, record, '226', `The company is a kibbutz (1000@877), but code 226 is ${OTHER_COOPERATIVE} ("other cooperative society, not a kibbutz").`),
|
|
262
|
+
value: OTHER_COOPERATIVE,
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* main.reportablePositions.unexpected: positions 1034–1046 given while tookReportablePosition
|
|
267
|
+
* (1030) is no (p.11). Reported at the positions array, located at the first position field.
|
|
268
|
+
*/
|
|
269
|
+
function reportablePositionsUnexpected(report) {
|
|
270
|
+
return mainRecords(report)
|
|
271
|
+
.filter(record => record.values['declarations.tookReportablePosition'] === false &&
|
|
272
|
+
REPORTABLE_POSITION_KEYS.some(key => record.values[key] !== undefined))
|
|
273
|
+
.map(record => fieldIssue('main.reportablePositions.unexpected', report, record, FIRST_POSITION, `Reportable position numbers (1000@1034–1046) are given, but declarations.tookReportablePosition is no (1000@1030).`, REPORTABLE_POSITIONS));
|
|
274
|
+
}
|
|
275
|
+
/** Code 165: the total of the investments in R&D companies, detailed in records 1030 (p.17). */
|
|
276
|
+
const RD_TOTAL_CODE = '165';
|
|
277
|
+
/** The amount a field or code holds in whole shekels, as the file holds it; 0 when not a number. */
|
|
278
|
+
function wholeShekels(value) {
|
|
279
|
+
return typeof value === 'number' ? Math.round(value) : 0;
|
|
280
|
+
}
|
|
281
|
+
/** main.rd.records: code 165 > 0 without any 1030 record (p.17). */
|
|
282
|
+
function rdRecords(report) {
|
|
283
|
+
if (report.records.some(record => record.recordType === '1030')) {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
return mainRecords(report)
|
|
287
|
+
.filter(record => isPositive(record.codes.get(RD_TOTAL_CODE)))
|
|
288
|
+
.map(record => codeIssue('main.rd.records', report, record, RD_TOTAL_CODE, `Code ${RD_TOTAL_CODE} (investments in R&D companies) is filled, so the investments must be detailed in rdInvestments (records 1030).`));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* main.rd.total: the investment amounts of the 1030 records do not add up to code 165 (p.17),
|
|
292
|
+
* compared in whole shekels (each amount rounded as it is written). Checked only when code 165 and
|
|
293
|
+
* at least one 1030 record are present: code 165 without records is main.rd.records.
|
|
294
|
+
*/
|
|
295
|
+
function rdTotal(report) {
|
|
296
|
+
const investments = report.records.filter(record => record.recordType === '1030');
|
|
297
|
+
if (investments.length === 0) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const total = investments.reduce((sum, record) => sum + wholeShekels(record.values['investmentAmount']), 0);
|
|
301
|
+
return mainRecords(report)
|
|
302
|
+
.filter(record => {
|
|
303
|
+
const code = record.codes.get(RD_TOTAL_CODE);
|
|
304
|
+
return code !== undefined && wholeShekels(code) !== total;
|
|
305
|
+
})
|
|
306
|
+
.map(record => {
|
|
307
|
+
const code = wholeShekels(record.codes.get(RD_TOTAL_CODE));
|
|
308
|
+
return {
|
|
309
|
+
...codeIssue('main.rd.total', report, record, RD_TOTAL_CODE, `Code ${RD_TOTAL_CODE} is ${code}, but the R&D investments (records 1030) total ${total}.`),
|
|
310
|
+
value: code,
|
|
311
|
+
expected: String(total),
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* main.cgUntransmitted.reason: untransmitted appendices (962 > 0) without any of the reasons
|
|
317
|
+
* 964–967 (p.10–11). Reported at the reasons object, located at the first reason field.
|
|
318
|
+
*/
|
|
319
|
+
function cgUntransmittedReason(report) {
|
|
320
|
+
return mainRecords(report)
|
|
321
|
+
.filter(record => isPositive(record.values[UNTRANSMITTED_COUNT]) &&
|
|
322
|
+
UNTRANSMITTED_REASONS.every(key => record.values[key] !== true))
|
|
323
|
+
.map(record => fieldIssue('main.cgUntransmitted.reason', report, record, UNTRANSMITTED_REASONS[0], `${String(record.values[UNTRANSMITTED_COUNT])} capital-gains appendices were not transmitted (1000@962), but no reason (1000@964–967) is marked.`, 'capitalGainsSummary.reasons'));
|
|
324
|
+
}
|
|
325
|
+
/** main.cgUntransmitted.reasonWithoutCount: a reason 964–967 marked while 962 is 0 or absent. */
|
|
326
|
+
function cgUntransmittedReasonWithoutCount(report) {
|
|
327
|
+
return mainRecords(report)
|
|
328
|
+
.filter(record => UNTRANSMITTED_REASONS.some(key => record.values[key] === true) &&
|
|
329
|
+
!isPositive(record.values[UNTRANSMITTED_COUNT]))
|
|
330
|
+
.map(record => fieldIssue('main.cgUntransmitted.reasonWithoutCount', report, record, UNTRANSMITTED_COUNT, `A reason for untransmitted capital-gains appendices (1000@964–967) is marked, but ${UNTRANSMITTED_COUNT} (1000@962) is 0 or absent.`));
|
|
331
|
+
}
|
|
332
|
+
const TOTAL_APPENDICES = 'capitalGainsSummary.totalAppendicesCount';
|
|
333
|
+
/**
|
|
334
|
+
* main.appendixTotal.min: the total number of appendices (960, "transmitted and not") is lower than
|
|
335
|
+
* the appendices the report transmits, the foreign appendix (2000) and the capital-gains records
|
|
336
|
+
* (30xx), plus the untransmitted ones (962) (p.10; SPEC §15 A-12). Checked only when 960 is above
|
|
337
|
+
* 0: 0 is written as absent.
|
|
338
|
+
*/
|
|
339
|
+
function appendixTotalMin(report) {
|
|
340
|
+
const transmitted = report.records.filter(record => record.recordType === '2000' || isCapitalGainsRecordType(record.recordType)).length;
|
|
341
|
+
return mainRecords(report).flatMap(record => {
|
|
342
|
+
const total = record.values[TOTAL_APPENDICES];
|
|
343
|
+
const untransmitted = record.values[UNTRANSMITTED_COUNT];
|
|
344
|
+
const expected = transmitted + (isPositive(untransmitted) ? Number(untransmitted) : 0);
|
|
345
|
+
if (!isPositive(total) || Number(total) >= expected) {
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
return [
|
|
349
|
+
{
|
|
350
|
+
...fieldIssue('main.appendixTotal.min', report, record, TOTAL_APPENDICES, `${TOTAL_APPENDICES} (1000@960) is ${String(total)}, but the report transmits ${transmitted} appendices (2000 and 30xx records) and ${expected - transmitted} were not transmitted (1000@962).`),
|
|
351
|
+
value: total,
|
|
352
|
+
expected: `at least ${expected}`,
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/** main.bankAccount.withNoBank: noBankAccount (1064) marked while a bank account is given (p.12). */
|
|
358
|
+
function bankAccountWithNoBank(report) {
|
|
359
|
+
return mainRecords(report)
|
|
360
|
+
.filter(record => record.values['declarations.noBankAccount'] === true &&
|
|
361
|
+
BANK_ACCOUNT_CODES.some(code => record.codes.has(code)))
|
|
362
|
+
.map(record => fieldIssue('main.bankAccount.withNoBank', report, record, 'declarations.noBankAccount', 'declarations.noBankAccount (1000@1064) is marked, but a bank account (codes 277/278/280) is given.'));
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* main.qualifyingCompany.purchaseAmounts: purchased (1065 = yes) without either purchase amount
|
|
366
|
+
* (1066, 1078) (p.12). Located at the first amount.
|
|
367
|
+
*/
|
|
368
|
+
function qualifyingCompanyPurchaseAmounts(report) {
|
|
369
|
+
return mainRecords(report)
|
|
370
|
+
.filter(record => record.values['qualifyingCompany.purchased'] === true &&
|
|
371
|
+
!isPositive(record.values[ISRAELI_PURCHASE]) &&
|
|
372
|
+
!isPositive(record.values[FOREIGN_PURCHASE]))
|
|
373
|
+
.map(record => fieldIssue('main.qualifyingCompany.purchaseAmounts', report, record, ISRAELI_PURCHASE, `qualifyingCompany.purchased is yes (1000@1065), but neither ${ISRAELI_PURCHASE} (1000@1066) nor ${FOREIGN_PURCHASE} (1000@1078) is given.`));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* main.qualifyingCompany.amortizationAmount: amortizationClaimed (1090 = yes) without the amount
|
|
377
|
+
* (1091), where 0 is an amount (p.12; SPEC §15 A-21).
|
|
378
|
+
*/
|
|
379
|
+
const qualifyingCompanyAmortizationAmount = requiresField('main.qualifyingCompany.amortizationAmount', 'qualifyingCompany.amortizationClaimed', 'qualifyingCompany.amortizationAmount', 'qualifyingCompany.amortizationClaimed is yes (1000@1090)');
|
|
380
|
+
/** A rule: when the count `countKey` is above 0, `code` must be in the code-amount section (p.10). */
|
|
381
|
+
function countRequiresCode(ruleId, countKey, code) {
|
|
382
|
+
return report => mainRecords(report)
|
|
383
|
+
.filter(record => isPositive(record.values[countKey]) && !record.codes.has(code))
|
|
384
|
+
.map(record => codeIssue(ruleId, report, record, code, `${countKey} (1000@${mainField(report, countKey).position}) is ${String(record.values[countKey])}, but code ${code}, whose certificates it counts, is absent.`));
|
|
385
|
+
}
|
|
386
|
+
/** main.attachments.code070: donation receipts attached (954 > 0) without code 070. */
|
|
387
|
+
const attachmentsCode070 = countRequiresCode('main.attachments.code070', 'attachments.donationReceiptsCount', '070');
|
|
388
|
+
/** main.attachments.code010: withholding certificates attached (957 > 0) without code 010. */
|
|
389
|
+
const attachmentsCode010 = countRequiresCode('main.attachments.code010', 'attachments.withholdingCertificatesCount', '010');
|
|
390
|
+
/**
|
|
391
|
+
* The conditional requirements and consistency warnings of record 1000
|
|
392
|
+
* (main.reportablePositions.max, main.bankAccount.format and main.capitalGains.flag are normalizer
|
|
393
|
+
* notices).
|
|
394
|
+
*/
|
|
395
|
+
export const MAIN_RULES = [
|
|
396
|
+
withholdingFileCompanyNumber,
|
|
397
|
+
familyCompanyFileNumber,
|
|
398
|
+
familyCompanyCode080,
|
|
399
|
+
houseCompanyCode084,
|
|
400
|
+
investmentLawFlag,
|
|
401
|
+
beneficiaryEnterpriseNoticeDate,
|
|
402
|
+
beneficiaryEnterpriseNoticeDateBeforeTaxYear,
|
|
403
|
+
specialYearBalanceSheetDate,
|
|
404
|
+
kibbutzCode226,
|
|
405
|
+
buildingIncomeCode259,
|
|
406
|
+
cgReasonsOtherText,
|
|
407
|
+
reportablePositionsRequired,
|
|
408
|
+
kibbutzCode226Other,
|
|
409
|
+
reportablePositionsUnexpected,
|
|
410
|
+
rdRecords,
|
|
411
|
+
rdTotal,
|
|
412
|
+
cgUntransmittedReason,
|
|
413
|
+
cgUntransmittedReasonWithoutCount,
|
|
414
|
+
appendixTotalMin,
|
|
415
|
+
bankAccountWithNoBank,
|
|
416
|
+
qualifyingCompanyPurchaseAmounts,
|
|
417
|
+
qualifyingCompanyAmortizationAmount,
|
|
418
|
+
attachmentsCode070,
|
|
419
|
+
attachmentsCode010,
|
|
420
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RecordType } from '../layout/types.js';
|
|
2
|
+
import type { NormalizedRecord, NormalizedReport } from '../model/normalized.js';
|
|
3
|
+
import { type Issue } from './issue.js';
|
|
4
|
+
import type { RuleId } from './rules.js';
|
|
5
|
+
/** Where an issue was found: 1-based line and column, plus the record when it is known. */
|
|
6
|
+
export interface Location {
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
recordType?: RecordType;
|
|
10
|
+
recordIndex?: number;
|
|
11
|
+
}
|
|
12
|
+
/** A parse issue of `ruleId` at `location`; the message is prefixed with the line and column. */
|
|
13
|
+
export declare function parseIssue(ruleId: RuleId, message: string, { line, column, ...record }: Location, details?: Omit<Issue, 'ruleId' | 'severity' | 'message' | 'path' | 'line' | 'column'> & {
|
|
14
|
+
path?: string;
|
|
15
|
+
}): Issue;
|
|
16
|
+
/** A decoded record of a file with its 1-based line number and its text. */
|
|
17
|
+
export interface LocatedRecord {
|
|
18
|
+
record: NormalizedRecord;
|
|
19
|
+
line: number;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The parse.derivedMismatch issues of `located` (the decoded records of one report, 9999 excluded,
|
|
24
|
+
* in file order) for `report`, the report they make: the report is denormalized to its input and
|
|
25
|
+
* normalized again, so every derived value is derived by the generator's own derivations from its
|
|
26
|
+
* source in the file; each one that differs from the file is an issue at its field or code (path
|
|
27
|
+
* per NormalizedRecord.paths, '' for derived values without an input path). A required header value
|
|
28
|
+
* the file leaves empty is not compared (field.required reports it). Records of one type are
|
|
29
|
+
* matched by their index among the records of that type.
|
|
30
|
+
*/
|
|
31
|
+
export declare function derivedMismatches(report: NormalizedReport, located: readonly LocatedRecord[]): Issue[];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Opcn1214InternalError } from '../errors.js';
|
|
2
|
+
import { denormalize } from '../normalize/denormalize.js';
|
|
3
|
+
import { codeKey } from '../normalize/paths.js';
|
|
4
|
+
import { normalizeReport } from '../normalize/report.js';
|
|
5
|
+
import { makeIssue } from './issue.js';
|
|
6
|
+
/** A parse issue of `ruleId` at `location`; the message is prefixed with the line and column. */
|
|
7
|
+
export function parseIssue(ruleId, message, { line, column, ...record }, details = {}) {
|
|
8
|
+
return makeIssue(ruleId, {
|
|
9
|
+
message: `Line ${line}, column ${column}: ${message}`,
|
|
10
|
+
path: '',
|
|
11
|
+
...record,
|
|
12
|
+
...details,
|
|
13
|
+
line,
|
|
14
|
+
column,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Header key of 1000@833: derived (SPEC §7.4), but also an input property, so the denormalizer
|
|
19
|
+
* reads 833 = yes back as `hasCapitalGainsAppendix` when nothing else explains it. Only 833 = no
|
|
20
|
+
* while capital-gains records or untransmitted appendices exist can disagree.
|
|
21
|
+
*/
|
|
22
|
+
const HAS_CAPITAL_GAINS_APPENDIX = 'declarations.hasCapitalGainsAppendix';
|
|
23
|
+
/** Length of the code of a code-amount entry. */
|
|
24
|
+
const CODE_LENGTH = 3;
|
|
25
|
+
const NOT_ZERO = /[^0]/;
|
|
26
|
+
/**
|
|
27
|
+
* The 1-based column of the entry of `code` in the code-amount section of `text`, a line that
|
|
28
|
+
* decoded as a record of `def`; the section start when the line has no entry for `code`.
|
|
29
|
+
*/
|
|
30
|
+
function codeColumn(def, text, code) {
|
|
31
|
+
const section = def.section;
|
|
32
|
+
if (!section) {
|
|
33
|
+
throw new Opcn1214InternalError(`Record ${def.type} has no section`);
|
|
34
|
+
}
|
|
35
|
+
const end = section.start - 1 + section.length;
|
|
36
|
+
let offset = section.start - 1;
|
|
37
|
+
while (offset + CODE_LENGTH <= end && NOT_ZERO.test(text.slice(offset, end))) {
|
|
38
|
+
const entry = text.slice(offset, offset + CODE_LENGTH);
|
|
39
|
+
if (entry === code) {
|
|
40
|
+
return offset + 1;
|
|
41
|
+
}
|
|
42
|
+
const width = def.codes.find(candidate => candidate.code === entry)?.length;
|
|
43
|
+
if (width === undefined) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
offset += CODE_LENGTH + width;
|
|
47
|
+
}
|
|
48
|
+
return section.start;
|
|
49
|
+
}
|
|
50
|
+
function show(value) {
|
|
51
|
+
return value === undefined ? 'absent' : String(value);
|
|
52
|
+
}
|
|
53
|
+
/** The header fields of a record whose value is derived (SPEC §7.4), 9999 aside. */
|
|
54
|
+
function derivedFields(def) {
|
|
55
|
+
return def.fields.filter(field => field.derived || field.key === HAS_CAPITAL_GAINS_APPENDIX);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The parse.derivedMismatch issues of `located` (the decoded records of one report, 9999 excluded,
|
|
59
|
+
* in file order) for `report`, the report they make: the report is denormalized to its input and
|
|
60
|
+
* normalized again, so every derived value is derived by the generator's own derivations from its
|
|
61
|
+
* source in the file; each one that differs from the file is an issue at its field or code (path
|
|
62
|
+
* per NormalizedRecord.paths, '' for derived values without an input path). A required header value
|
|
63
|
+
* the file leaves empty is not compared (field.required reports it). Records of one type are
|
|
64
|
+
* matched by their index among the records of that type.
|
|
65
|
+
*/
|
|
66
|
+
export function derivedMismatches(report, located) {
|
|
67
|
+
// No clock access: the save date is not derived, so any value does.
|
|
68
|
+
const derived = normalizeReport(denormalize(report), report.layout, { today: () => '' });
|
|
69
|
+
const issues = [];
|
|
70
|
+
for (const { record, line, text } of located) {
|
|
71
|
+
const def = report.layout.records[record.recordType];
|
|
72
|
+
const fields = derivedFields(def);
|
|
73
|
+
const codes = def.codes.filter(code => code.derived).map(code => code.code);
|
|
74
|
+
if (fields.length === 0 && codes.length === 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const expected = derived.records.filter(candidate => candidate.recordType === record.recordType)[record.index];
|
|
78
|
+
if (!expected) {
|
|
79
|
+
throw new Opcn1214InternalError(`No derived record ${record.recordType} #${record.index} for a parsed record`);
|
|
80
|
+
}
|
|
81
|
+
const at = { line, recordType: record.recordType, recordIndex: record.index };
|
|
82
|
+
for (const field of fields) {
|
|
83
|
+
const actual = record.values[field.key];
|
|
84
|
+
const wanted = expected.values[field.key];
|
|
85
|
+
if (actual === wanted || (actual === undefined && field.required === 'yes')) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
issues.push(parseIssue('parse.derivedMismatch', `${field.key} (${def.type}@${field.position}) is ${show(actual)}; derived from the file it is ${show(wanted)}.`, { ...at, column: field.position }, {
|
|
89
|
+
path: record.paths[field.key] ?? '',
|
|
90
|
+
field: { position: field.position, length: field.length, nameHe: field.nameHe },
|
|
91
|
+
...(actual === undefined ? {} : { value: actual }),
|
|
92
|
+
expected: show(wanted),
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
for (const code of codes) {
|
|
96
|
+
const actual = record.codes.get(code);
|
|
97
|
+
const wanted = expected.codes.get(code);
|
|
98
|
+
if (actual === wanted) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
issues.push(parseIssue('parse.derivedMismatch', `Code ${code} of record ${def.type} is ${show(actual)}; derived from the file it is ${show(wanted)}.`, { ...at, column: codeColumn(def, text, code) }, {
|
|
102
|
+
path: record.paths[codeKey(code)] ?? '',
|
|
103
|
+
code,
|
|
104
|
+
...(actual === undefined ? {} : { value: actual }),
|
|
105
|
+
expected: show(wanted),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return issues;
|
|
110
|
+
}
|