@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.
Files changed (477) hide show
  1. package/.bob/cjs/api/generate.d.ts +44 -0
  2. package/.bob/cjs/api/generate.js +115 -0
  3. package/.bob/cjs/api/parse.d.ts +28 -0
  4. package/.bob/cjs/api/parse.js +38 -0
  5. package/.bob/cjs/api/response.d.ts +24 -0
  6. package/.bob/cjs/api/response.js +75 -0
  7. package/.bob/cjs/api/validate.d.ts +16 -0
  8. package/.bob/cjs/api/validate.js +15 -0
  9. package/.bob/cjs/codec/boolean.d.ts +7 -0
  10. package/.bob/cjs/codec/boolean.js +49 -0
  11. package/.bob/cjs/codec/date.d.ts +6 -0
  12. package/.bob/cjs/codec/date.js +68 -0
  13. package/.bob/cjs/codec/enum.d.ts +4 -0
  14. package/.bob/cjs/codec/enum.js +26 -0
  15. package/.bob/cjs/codec/numeric.d.ts +56 -0
  16. package/.bob/cjs/codec/numeric.js +186 -0
  17. package/.bob/cjs/codec/padding.d.ts +10 -0
  18. package/.bob/cjs/codec/padding.js +26 -0
  19. package/.bob/cjs/codec/percent.d.ts +6 -0
  20. package/.bob/cjs/codec/percent.js +33 -0
  21. package/.bob/cjs/codec/phone.d.ts +4 -0
  22. package/.bob/cjs/codec/phone.js +48 -0
  23. package/.bob/cjs/codec/record.d.ts +18 -0
  24. package/.bob/cjs/codec/record.js +176 -0
  25. package/.bob/cjs/codec/registry.d.ts +8 -0
  26. package/.bob/cjs/codec/registry.js +27 -0
  27. package/.bob/cjs/codec/sections.d.ts +41 -0
  28. package/.bob/cjs/codec/sections.js +177 -0
  29. package/.bob/cjs/codec/text.d.ts +5 -0
  30. package/.bob/cjs/codec/text.js +29 -0
  31. package/.bob/cjs/codec/types.d.ts +36 -0
  32. package/.bob/cjs/codec/types.js +16 -0
  33. package/.bob/cjs/codec/windows1255.d.ts +9 -0
  34. package/.bob/cjs/codec/windows1255.js +38 -0
  35. package/.bob/cjs/errors.d.ts +32 -0
  36. package/.bob/cjs/errors.js +103 -0
  37. package/.bob/cjs/file/assemble.d.ts +17 -0
  38. package/.bob/cjs/file/assemble.js +28 -0
  39. package/.bob/cjs/file/control.d.ts +13 -0
  40. package/.bob/cjs/file/control.js +45 -0
  41. package/.bob/cjs/file/parse.d.ts +18 -0
  42. package/.bob/cjs/file/parse.js +478 -0
  43. package/.bob/cjs/file/split.d.ts +17 -0
  44. package/.bob/cjs/file/split.js +71 -0
  45. package/.bob/cjs/index.d.ts +16 -0
  46. package/.bob/cjs/index.js +28 -0
  47. package/.bob/cjs/layout/2024/layout.generated.d.ts +6919 -0
  48. package/.bob/cjs/layout/2024/layout.generated.js +7224 -0
  49. package/.bob/cjs/layout/2025/index.d.ts +6 -0
  50. package/.bob/cjs/layout/2025/index.js +10 -0
  51. package/.bob/cjs/layout/capital-gains.d.ts +9 -0
  52. package/.bob/cjs/layout/capital-gains.js +15 -0
  53. package/.bob/cjs/layout/countries.d.ts +5 -0
  54. package/.bob/cjs/layout/countries.js +10 -0
  55. package/.bob/cjs/layout/freeze.d.ts +5 -0
  56. package/.bob/cjs/layout/freeze.js +16 -0
  57. package/.bob/cjs/layout/registry.d.ts +10 -0
  58. package/.bob/cjs/layout/registry.js +32 -0
  59. package/.bob/cjs/layout/types.d.ts +82 -0
  60. package/.bob/cjs/layout/types.js +35 -0
  61. package/.bob/cjs/model/codes.generated.d.ts +48 -0
  62. package/.bob/cjs/model/codes.generated.js +628 -0
  63. package/.bob/cjs/model/index.d.ts +3 -0
  64. package/.bob/cjs/model/index.js +5 -0
  65. package/.bob/cjs/model/input.d.ts +543 -0
  66. package/.bob/cjs/model/input.js +24 -0
  67. package/.bob/cjs/model/normalized.d.ts +43 -0
  68. package/.bob/cjs/model/normalized.js +0 -0
  69. package/.bob/cjs/model/options.d.ts +14 -0
  70. package/.bob/cjs/model/options.js +0 -0
  71. package/.bob/cjs/model/schema.d.ts +594 -0
  72. package/.bob/cjs/model/schema.js +339 -0
  73. package/.bob/cjs/normalize/canonical.d.ts +13 -0
  74. package/.bob/cjs/normalize/canonical.js +288 -0
  75. package/.bob/cjs/normalize/capital-gains/assets.d.ts +37 -0
  76. package/.bob/cjs/normalize/capital-gains/assets.js +94 -0
  77. package/.bob/cjs/normalize/capital-gains/index.d.ts +61 -0
  78. package/.bob/cjs/normalize/capital-gains/index.js +149 -0
  79. package/.bob/cjs/normalize/capital-gains/no-withholding.d.ts +18 -0
  80. package/.bob/cjs/normalize/capital-gains/no-withholding.js +36 -0
  81. package/.bob/cjs/normalize/capital-gains/other.d.ts +54 -0
  82. package/.bob/cjs/normalize/capital-gains/other.js +122 -0
  83. package/.bob/cjs/normalize/capital-gains/section6.d.ts +7 -0
  84. package/.bob/cjs/normalize/capital-gains/section6.js +13 -0
  85. package/.bob/cjs/normalize/capital-gains/securities.d.ts +26 -0
  86. package/.bob/cjs/normalize/capital-gains/securities.js +58 -0
  87. package/.bob/cjs/normalize/denormalize.d.ts +42 -0
  88. package/.bob/cjs/normalize/denormalize.js +359 -0
  89. package/.bob/cjs/normalize/derive.d.ts +57 -0
  90. package/.bob/cjs/normalize/derive.js +111 -0
  91. package/.bob/cjs/normalize/enums.d.ts +58 -0
  92. package/.bob/cjs/normalize/enums.js +69 -0
  93. package/.bob/cjs/normalize/fields.d.ts +28 -0
  94. package/.bob/cjs/normalize/fields.js +86 -0
  95. package/.bob/cjs/normalize/foreign.d.ts +22 -0
  96. package/.bob/cjs/normalize/foreign.js +85 -0
  97. package/.bob/cjs/normalize/main.d.ts +24 -0
  98. package/.bob/cjs/normalize/main.js +208 -0
  99. package/.bob/cjs/normalize/paths.d.ts +74 -0
  100. package/.bob/cjs/normalize/paths.js +169 -0
  101. package/.bob/cjs/normalize/phone.d.ts +12 -0
  102. package/.bob/cjs/normalize/phone.js +35 -0
  103. package/.bob/cjs/normalize/rd-investments.d.ts +10 -0
  104. package/.bob/cjs/normalize/rd-investments.js +25 -0
  105. package/.bob/cjs/normalize/related-companies.d.ts +10 -0
  106. package/.bob/cjs/normalize/related-companies.js +25 -0
  107. package/.bob/cjs/normalize/report.d.ts +9 -0
  108. package/.bob/cjs/normalize/report.js +53 -0
  109. package/.bob/cjs/normalize/shareholders.d.ts +10 -0
  110. package/.bob/cjs/normalize/shareholders.js +30 -0
  111. package/.bob/cjs/normalize/text.d.ts +11 -0
  112. package/.bob/cjs/normalize/text.js +41 -0
  113. package/.bob/cjs/normalize/today.d.ts +4 -0
  114. package/.bob/cjs/normalize/today.js +14 -0
  115. package/.bob/cjs/pipeline.d.ts +13 -0
  116. package/.bob/cjs/pipeline.js +37 -0
  117. package/.bob/cjs/response/codes.d.ts +2 -0
  118. package/.bob/cjs/response/codes.js +31 -0
  119. package/.bob/cjs/validate/capital-gains-rules.d.ts +6 -0
  120. package/.bob/cjs/validate/capital-gains-rules.js +162 -0
  121. package/.bob/cjs/validate/check-digit.d.ts +10 -0
  122. package/.bob/cjs/validate/check-digit.js +26 -0
  123. package/.bob/cjs/validate/engine.d.ts +5 -0
  124. package/.bob/cjs/validate/engine.js +35 -0
  125. package/.bob/cjs/validate/field-rules.d.ts +4 -0
  126. package/.bob/cjs/validate/field-rules.js +331 -0
  127. package/.bob/cjs/validate/foreign-rules.d.ts +6 -0
  128. package/.bob/cjs/validate/foreign-rules.js +171 -0
  129. package/.bob/cjs/validate/issue.d.ts +51 -0
  130. package/.bob/cjs/validate/issue.js +78 -0
  131. package/.bob/cjs/validate/main-rules.d.ts +24 -0
  132. package/.bob/cjs/validate/main-rules.js +425 -0
  133. package/.bob/cjs/validate/parse-rules.d.ts +31 -0
  134. package/.bob/cjs/validate/parse-rules.js +114 -0
  135. package/.bob/cjs/validate/rules.d.ts +746 -0
  136. package/.bob/cjs/validate/rules.js +680 -0
  137. package/.bob/cjs/validate/shape.d.ts +19 -0
  138. package/.bob/cjs/validate/shape.js +231 -0
  139. package/.bob/cjs/validate/shareholder-rules.d.ts +6 -0
  140. package/.bob/cjs/validate/shareholder-rules.js +83 -0
  141. package/.bob/cjs/validate/structure-rules.d.ts +26 -0
  142. package/.bob/cjs/validate/structure-rules.js +130 -0
  143. package/.bob/esm/api/generate.d.ts +44 -0
  144. package/.bob/esm/api/generate.js +111 -0
  145. package/.bob/esm/api/parse.d.ts +28 -0
  146. package/.bob/esm/api/parse.js +34 -0
  147. package/.bob/esm/api/response.d.ts +24 -0
  148. package/.bob/esm/api/response.js +72 -0
  149. package/.bob/esm/api/validate.d.ts +16 -0
  150. package/.bob/esm/api/validate.js +11 -0
  151. package/.bob/esm/codec/boolean.d.ts +7 -0
  152. package/.bob/esm/codec/boolean.js +46 -0
  153. package/.bob/esm/codec/date.d.ts +6 -0
  154. package/.bob/esm/codec/date.js +64 -0
  155. package/.bob/esm/codec/enum.d.ts +4 -0
  156. package/.bob/esm/codec/enum.js +23 -0
  157. package/.bob/esm/codec/numeric.d.ts +56 -0
  158. package/.bob/esm/codec/numeric.js +175 -0
  159. package/.bob/esm/codec/padding.d.ts +10 -0
  160. package/.bob/esm/codec/padding.js +21 -0
  161. package/.bob/esm/codec/percent.d.ts +6 -0
  162. package/.bob/esm/codec/percent.js +30 -0
  163. package/.bob/esm/codec/phone.d.ts +4 -0
  164. package/.bob/esm/codec/phone.js +45 -0
  165. package/.bob/esm/codec/record.d.ts +18 -0
  166. package/.bob/esm/codec/record.js +172 -0
  167. package/.bob/esm/codec/registry.d.ts +8 -0
  168. package/.bob/esm/codec/registry.js +23 -0
  169. package/.bob/esm/codec/sections.d.ts +41 -0
  170. package/.bob/esm/codec/sections.js +170 -0
  171. package/.bob/esm/codec/text.d.ts +5 -0
  172. package/.bob/esm/codec/text.js +26 -0
  173. package/.bob/esm/codec/types.d.ts +36 -0
  174. package/.bob/esm/codec/types.js +12 -0
  175. package/.bob/esm/codec/windows1255.d.ts +9 -0
  176. package/.bob/esm/codec/windows1255.js +32 -0
  177. package/.bob/esm/errors.d.ts +32 -0
  178. package/.bob/esm/errors.js +94 -0
  179. package/.bob/esm/file/assemble.d.ts +17 -0
  180. package/.bob/esm/file/assemble.js +25 -0
  181. package/.bob/esm/file/control.d.ts +13 -0
  182. package/.bob/esm/file/control.js +41 -0
  183. package/.bob/esm/file/parse.d.ts +18 -0
  184. package/.bob/esm/file/parse.js +474 -0
  185. package/.bob/esm/file/split.d.ts +17 -0
  186. package/.bob/esm/file/split.js +68 -0
  187. package/.bob/esm/index.d.ts +16 -0
  188. package/.bob/esm/index.js +11 -0
  189. package/.bob/esm/layout/2024/layout.generated.d.ts +6919 -0
  190. package/.bob/esm/layout/2024/layout.generated.js +7221 -0
  191. package/.bob/esm/layout/2025/index.d.ts +6 -0
  192. package/.bob/esm/layout/2025/index.js +7 -0
  193. package/.bob/esm/layout/capital-gains.d.ts +9 -0
  194. package/.bob/esm/layout/capital-gains.js +11 -0
  195. package/.bob/esm/layout/countries.d.ts +5 -0
  196. package/.bob/esm/layout/countries.js +7 -0
  197. package/.bob/esm/layout/freeze.d.ts +5 -0
  198. package/.bob/esm/layout/freeze.js +13 -0
  199. package/.bob/esm/layout/registry.d.ts +10 -0
  200. package/.bob/esm/layout/registry.js +27 -0
  201. package/.bob/esm/layout/types.d.ts +82 -0
  202. package/.bob/esm/layout/types.js +32 -0
  203. package/.bob/esm/model/codes.generated.d.ts +48 -0
  204. package/.bob/esm/model/codes.generated.js +625 -0
  205. package/.bob/esm/model/index.d.ts +3 -0
  206. package/.bob/esm/model/index.js +2 -0
  207. package/.bob/esm/model/input.d.ts +543 -0
  208. package/.bob/esm/model/input.js +21 -0
  209. package/.bob/esm/model/normalized.d.ts +43 -0
  210. package/.bob/esm/model/normalized.js +0 -0
  211. package/.bob/esm/model/options.d.ts +14 -0
  212. package/.bob/esm/model/options.js +0 -0
  213. package/.bob/esm/model/schema.d.ts +594 -0
  214. package/.bob/esm/model/schema.js +335 -0
  215. package/.bob/esm/normalize/canonical.d.ts +13 -0
  216. package/.bob/esm/normalize/canonical.js +285 -0
  217. package/.bob/esm/normalize/capital-gains/assets.d.ts +37 -0
  218. package/.bob/esm/normalize/capital-gains/assets.js +87 -0
  219. package/.bob/esm/normalize/capital-gains/index.d.ts +61 -0
  220. package/.bob/esm/normalize/capital-gains/index.js +142 -0
  221. package/.bob/esm/normalize/capital-gains/no-withholding.d.ts +18 -0
  222. package/.bob/esm/normalize/capital-gains/no-withholding.js +31 -0
  223. package/.bob/esm/normalize/capital-gains/other.d.ts +54 -0
  224. package/.bob/esm/normalize/capital-gains/other.js +112 -0
  225. package/.bob/esm/normalize/capital-gains/section6.d.ts +7 -0
  226. package/.bob/esm/normalize/capital-gains/section6.js +9 -0
  227. package/.bob/esm/normalize/capital-gains/securities.d.ts +26 -0
  228. package/.bob/esm/normalize/capital-gains/securities.js +52 -0
  229. package/.bob/esm/normalize/denormalize.d.ts +42 -0
  230. package/.bob/esm/normalize/denormalize.js +354 -0
  231. package/.bob/esm/normalize/derive.d.ts +57 -0
  232. package/.bob/esm/normalize/derive.js +99 -0
  233. package/.bob/esm/normalize/enums.d.ts +58 -0
  234. package/.bob/esm/normalize/enums.js +64 -0
  235. package/.bob/esm/normalize/fields.d.ts +28 -0
  236. package/.bob/esm/normalize/fields.js +81 -0
  237. package/.bob/esm/normalize/foreign.d.ts +22 -0
  238. package/.bob/esm/normalize/foreign.js +81 -0
  239. package/.bob/esm/normalize/main.d.ts +24 -0
  240. package/.bob/esm/normalize/main.js +204 -0
  241. package/.bob/esm/normalize/paths.d.ts +74 -0
  242. package/.bob/esm/normalize/paths.js +161 -0
  243. package/.bob/esm/normalize/phone.d.ts +12 -0
  244. package/.bob/esm/normalize/phone.js +32 -0
  245. package/.bob/esm/normalize/rd-investments.d.ts +10 -0
  246. package/.bob/esm/normalize/rd-investments.js +22 -0
  247. package/.bob/esm/normalize/related-companies.d.ts +10 -0
  248. package/.bob/esm/normalize/related-companies.js +22 -0
  249. package/.bob/esm/normalize/report.d.ts +9 -0
  250. package/.bob/esm/normalize/report.js +50 -0
  251. package/.bob/esm/normalize/shareholders.d.ts +10 -0
  252. package/.bob/esm/normalize/shareholders.js +27 -0
  253. package/.bob/esm/normalize/text.d.ts +11 -0
  254. package/.bob/esm/normalize/text.js +37 -0
  255. package/.bob/esm/normalize/today.d.ts +4 -0
  256. package/.bob/esm/normalize/today.js +11 -0
  257. package/.bob/esm/pipeline.d.ts +13 -0
  258. package/.bob/esm/pipeline.js +34 -0
  259. package/.bob/esm/response/codes.d.ts +2 -0
  260. package/.bob/esm/response/codes.js +28 -0
  261. package/.bob/esm/validate/capital-gains-rules.d.ts +6 -0
  262. package/.bob/esm/validate/capital-gains-rules.js +159 -0
  263. package/.bob/esm/validate/check-digit.d.ts +10 -0
  264. package/.bob/esm/validate/check-digit.js +23 -0
  265. package/.bob/esm/validate/engine.d.ts +5 -0
  266. package/.bob/esm/validate/engine.js +32 -0
  267. package/.bob/esm/validate/field-rules.d.ts +4 -0
  268. package/.bob/esm/validate/field-rules.js +328 -0
  269. package/.bob/esm/validate/foreign-rules.d.ts +6 -0
  270. package/.bob/esm/validate/foreign-rules.js +168 -0
  271. package/.bob/esm/validate/issue.d.ts +51 -0
  272. package/.bob/esm/validate/issue.js +72 -0
  273. package/.bob/esm/validate/main-rules.d.ts +24 -0
  274. package/.bob/esm/validate/main-rules.js +420 -0
  275. package/.bob/esm/validate/parse-rules.d.ts +31 -0
  276. package/.bob/esm/validate/parse-rules.js +110 -0
  277. package/.bob/esm/validate/rules.d.ts +746 -0
  278. package/.bob/esm/validate/rules.js +676 -0
  279. package/.bob/esm/validate/shape.d.ts +19 -0
  280. package/.bob/esm/validate/shape.js +227 -0
  281. package/.bob/esm/validate/shareholder-rules.d.ts +6 -0
  282. package/.bob/esm/validate/shareholder-rules.js +80 -0
  283. package/.bob/esm/validate/structure-rules.d.ts +26 -0
  284. package/.bob/esm/validate/structure-rules.js +122 -0
  285. package/.bob/tsconfig.tsbuildinfo +1 -0
  286. package/.gitattributes +1 -0
  287. package/CLAUDE.md +39 -0
  288. package/README.md +337 -0
  289. package/dist/cjs/index.js +28 -0
  290. package/dist/esm/index.js +11 -0
  291. package/documentation/IMPLEMENTATION_PLAN.md +2258 -0
  292. package/documentation/SPEC.md +1803 -0
  293. package/documentation/layout/2024/codes.csv +261 -0
  294. package/documentation/layout/2024/countries.csv +256 -0
  295. package/documentation/layout/2024/fields.csv +271 -0
  296. package/documentation/layout/2024/records.csv +18 -0
  297. package/documentation/layout/README.md +87 -0
  298. package/documentation/specifications/1214-2024.pdf +0 -0
  299. package/documentation/tools/extract_layout.py +191 -0
  300. package/package.json +77 -0
  301. package/scripts/generate-layout.ts +23 -0
  302. package/scripts/layout/csv.ts +111 -0
  303. package/scripts/layout/derived-codes.ts +12 -0
  304. package/scripts/layout/render.ts +364 -0
  305. package/scripts/layout/sources.ts +51 -0
  306. package/scripts/layout/values.ts +42 -0
  307. package/scripts/render-rules-table.ts +66 -0
  308. package/src/api/generate.ts +169 -0
  309. package/src/api/parse.ts +58 -0
  310. package/src/api/response.ts +110 -0
  311. package/src/api/validate.ts +26 -0
  312. package/src/codec/boolean.ts +62 -0
  313. package/src/codec/date.ts +75 -0
  314. package/src/codec/enum.ts +28 -0
  315. package/src/codec/numeric.ts +208 -0
  316. package/src/codec/padding.ts +33 -0
  317. package/src/codec/percent.ts +35 -0
  318. package/src/codec/phone.ts +54 -0
  319. package/src/codec/record.ts +206 -0
  320. package/src/codec/registry.ts +27 -0
  321. package/src/codec/sections.ts +208 -0
  322. package/src/codec/text.ts +31 -0
  323. package/src/codec/types.ts +47 -0
  324. package/src/codec/windows1255.ts +38 -0
  325. package/src/errors.ts +114 -0
  326. package/src/file/assemble.ts +42 -0
  327. package/src/file/control.ts +59 -0
  328. package/src/file/parse.ts +620 -0
  329. package/src/file/split.ts +86 -0
  330. package/src/index.ts +70 -0
  331. package/src/layout/2024/layout.generated.ts +7238 -0
  332. package/src/layout/2025/index.ts +9 -0
  333. package/src/layout/capital-gains.ts +20 -0
  334. package/src/layout/countries.ts +7 -0
  335. package/src/layout/freeze.ts +13 -0
  336. package/src/layout/registry.ts +33 -0
  337. package/src/layout/types.ts +134 -0
  338. package/src/model/codes.generated.ts +1190 -0
  339. package/src/model/index.ts +4 -0
  340. package/src/model/input.ts +594 -0
  341. package/src/model/normalized.ts +38 -0
  342. package/src/model/options.ts +17 -0
  343. package/src/model/schema.ts +381 -0
  344. package/src/normalize/canonical.ts +374 -0
  345. package/src/normalize/capital-gains/assets.ts +112 -0
  346. package/src/normalize/capital-gains/index.ts +212 -0
  347. package/src/normalize/capital-gains/no-withholding.ts +46 -0
  348. package/src/normalize/capital-gains/other.ts +153 -0
  349. package/src/normalize/capital-gains/section6.ts +14 -0
  350. package/src/normalize/capital-gains/securities.ts +73 -0
  351. package/src/normalize/denormalize.ts +426 -0
  352. package/src/normalize/derive.ts +136 -0
  353. package/src/normalize/enums.ts +87 -0
  354. package/src/normalize/fields.ts +110 -0
  355. package/src/normalize/foreign.ts +114 -0
  356. package/src/normalize/main.ts +284 -0
  357. package/src/normalize/paths.ts +184 -0
  358. package/src/normalize/phone.ts +45 -0
  359. package/src/normalize/rd-investments.ts +38 -0
  360. package/src/normalize/related-companies.ts +37 -0
  361. package/src/normalize/report.ts +59 -0
  362. package/src/normalize/shareholders.ts +42 -0
  363. package/src/normalize/text.ts +40 -0
  364. package/src/normalize/today.ts +15 -0
  365. package/src/pipeline.ts +42 -0
  366. package/src/response/codes.ts +30 -0
  367. package/src/validate/capital-gains-rules.ts +199 -0
  368. package/src/validate/check-digit.ts +25 -0
  369. package/src/validate/engine.ts +45 -0
  370. package/src/validate/field-rules.ts +383 -0
  371. package/src/validate/foreign-rules.ts +274 -0
  372. package/src/validate/issue.ts +121 -0
  373. package/src/validate/main-rules.ts +678 -0
  374. package/src/validate/parse-rules.ts +169 -0
  375. package/src/validate/rules.ts +747 -0
  376. package/src/validate/shape.ts +278 -0
  377. package/src/validate/shareholder-rules.ts +92 -0
  378. package/src/validate/structure-rules.ts +136 -0
  379. package/tests/api/batch.test.ts +227 -0
  380. package/tests/api/exports.test.ts +355 -0
  381. package/tests/api/generate.test.ts +409 -0
  382. package/tests/api/parse.test.ts +789 -0
  383. package/tests/api/response.test.ts +152 -0
  384. package/tests/api/validate.test.ts +86 -0
  385. package/tests/codec/numeric.test.ts +325 -0
  386. package/tests/codec/record.test.ts +318 -0
  387. package/tests/codec/registry.test.ts +17 -0
  388. package/tests/codec/sections.test.ts +333 -0
  389. package/tests/codec/text.test.ts +454 -0
  390. package/tests/codec/windows1255.test.ts +46 -0
  391. package/tests/docs/readme.test.ts +69 -0
  392. package/tests/edge-cases.test.ts +359 -0
  393. package/tests/errors.test.ts +138 -0
  394. package/tests/file/assemble.test.ts +188 -0
  395. package/tests/file/split.test.ts +61 -0
  396. package/tests/fixtures/builders.ts +512 -0
  397. package/tests/fixtures/files.ts +78 -0
  398. package/tests/fixtures/golden/README.md +37 -0
  399. package/tests/fixtures/golden/VERIFICATION.md +72 -0
  400. package/tests/fixtures/golden/batch-50.input.ts +92 -0
  401. package/tests/fixtures/golden/batch-50.opcn +150 -0
  402. package/tests/fixtures/golden/capital-gains-max.input.ts +177 -0
  403. package/tests/fixtures/golden/capital-gains-max.opcn +17 -0
  404. package/tests/fixtures/golden/cg-27.input.ts +63 -0
  405. package/tests/fixtures/golden/cg-27.opcn +4 -0
  406. package/tests/fixtures/golden/cg-50.input.ts +59 -0
  407. package/tests/fixtures/golden/cg-50.opcn +4 -0
  408. package/tests/fixtures/golden/cg-51.input.ts +60 -0
  409. package/tests/fixtures/golden/cg-51.opcn +4 -0
  410. package/tests/fixtures/golden/cg-54.input.ts +53 -0
  411. package/tests/fixtures/golden/cg-54.opcn +4 -0
  412. package/tests/fixtures/golden/cg-60.input.ts +77 -0
  413. package/tests/fixtures/golden/cg-60.opcn +4 -0
  414. package/tests/fixtures/golden/cg-63.input.ts +51 -0
  415. package/tests/fixtures/golden/cg-63.opcn +4 -0
  416. package/tests/fixtures/golden/cg-64.input.ts +62 -0
  417. package/tests/fixtures/golden/cg-64.opcn +4 -0
  418. package/tests/fixtures/golden/cg-65.input.ts +79 -0
  419. package/tests/fixtures/golden/cg-65.opcn +4 -0
  420. package/tests/fixtures/golden/cg-66.input.ts +53 -0
  421. package/tests/fixtures/golden/cg-66.opcn +4 -0
  422. package/tests/fixtures/golden/cg-77.input.ts +109 -0
  423. package/tests/fixtures/golden/cg-77.opcn +4 -0
  424. package/tests/fixtures/golden/foreign.input.ts +202 -0
  425. package/tests/fixtures/golden/foreign.opcn +27 -0
  426. package/tests/fixtures/golden/hebrew-edge.input.ts +90 -0
  427. package/tests/fixtures/golden/hebrew-edge.opcn +8 -0
  428. package/tests/fixtures/golden/kibbutz.input.ts +31 -0
  429. package/tests/fixtures/golden/kibbutz.opcn +2 -0
  430. package/tests/fixtures/golden/main-full.input.ts +780 -0
  431. package/tests/fixtures/golden/main-full.opcn +101 -0
  432. package/tests/fixtures/golden/minimal.input.ts +37 -0
  433. package/tests/fixtures/golden/minimal.opcn +3 -0
  434. package/tests/fixtures/golden/related-and-rd.input.ts +59 -0
  435. package/tests/fixtures/golden/related-and-rd.opcn +11 -0
  436. package/tests/fixtures/random.ts +843 -0
  437. package/tests/golden/fixtures.test.ts +627 -0
  438. package/tests/golden/golden.test.ts +95 -0
  439. package/tests/helpers/coverage.ts +18 -0
  440. package/tests/helpers/sample-values.ts +114 -0
  441. package/tests/layout/codegen-sync.test.ts +19 -0
  442. package/tests/layout/integrity.test.ts +232 -0
  443. package/tests/layout/registry.test.ts +98 -0
  444. package/tests/model/code-unions.test.ts +91 -0
  445. package/tests/model/schema.test.ts +1031 -0
  446. package/tests/normalize/canonical.test.ts +728 -0
  447. package/tests/normalize/capital-gains.test.ts +1850 -0
  448. package/tests/normalize/coverage.test.ts +88 -0
  449. package/tests/normalize/denormalize.test.ts +318 -0
  450. package/tests/normalize/enums.test.ts +118 -0
  451. package/tests/normalize/foreign.test.ts +273 -0
  452. package/tests/normalize/main.test.ts +839 -0
  453. package/tests/normalize/paths.test.ts +257 -0
  454. package/tests/normalize/rd-investments.test.ts +99 -0
  455. package/tests/normalize/related-companies.test.ts +106 -0
  456. package/tests/normalize/shareholders.test.ts +117 -0
  457. package/tests/normalize/text.test.ts +86 -0
  458. package/tests/pipeline.test.ts +96 -0
  459. package/tests/roundtrip/determinism.test.ts +207 -0
  460. package/tests/roundtrip/property.test.ts +126 -0
  461. package/tests/roundtrip/roundtrip.test.ts +573 -0
  462. package/tests/rules/cases.ts +873 -0
  463. package/tests/rules/rules.test.ts +69 -0
  464. package/tests/rules/spec-sync.test.ts +80 -0
  465. package/tests/scripts/csv.test.ts +78 -0
  466. package/tests/scripts/values.test.ts +80 -0
  467. package/tests/validate/capital-gains-rules.test.ts +307 -0
  468. package/tests/validate/check-digit.test.ts +42 -0
  469. package/tests/validate/field-rules.test.ts +867 -0
  470. package/tests/validate/foreign-rules.test.ts +255 -0
  471. package/tests/validate/issue.test.ts +96 -0
  472. package/tests/validate/main-rules.test.ts +761 -0
  473. package/tests/validate/parse-rules.test.ts +293 -0
  474. package/tests/validate/shareholder-rules.test.ts +143 -0
  475. package/tsconfig.json +10 -0
  476. package/tsconfig.typecheck.json +9 -0
  477. package/vitest.config.ts +11 -0
@@ -0,0 +1,1850 @@
1
+ import { renderReport } from '../../src/file/assemble.js';
2
+ import { generate1214, parse1214, validate1214 } from '../../src/index.js';
3
+ import {
4
+ capitalGainsRecordType,
5
+ isCapitalGainsRecordType,
6
+ } from '../../src/layout/capital-gains.js';
7
+ import { getLayout } from '../../src/layout/registry.js';
8
+ import type { Report1214Input } from '../../src/model/input.js';
9
+ import type { ValidateOptions } from '../../src/model/options.js';
10
+ import { placeCapitalGains } from '../../src/normalize/capital-gains/index.js';
11
+ import { normalizeReport } from '../../src/normalize/report.js';
12
+ import { fieldRules } from '../../src/validate/field-rules.js';
13
+ import {
14
+ bettermentTaxAppendix,
15
+ breakdownCountries,
16
+ forcedVirtualCurrencyAppendix,
17
+ foreignAppendixWithBreakdown,
18
+ improvements,
19
+ minimalInput,
20
+ noWithholding1322Appendix,
21
+ noWithholding1326Appendix,
22
+ oilPartnershipAppendix,
23
+ otherTransactionsAppendix,
24
+ rdInvestments,
25
+ rdInvestmentsTotal,
26
+ reitAppendix,
27
+ section6Appendices,
28
+ section6Appendix,
29
+ securitiesAppendix,
30
+ sharesAppendix,
31
+ withholders,
32
+ } from '../fixtures/builders.js';
33
+ import { unmappedHeaderKeys } from '../helpers/coverage.js';
34
+
35
+ const LAYOUT = getLayout(2024);
36
+ const OPTIONS: ValidateOptions = { today: () => '2024-06-30' };
37
+
38
+ function reportOf(input: Report1214Input, options = OPTIONS) {
39
+ return normalizeReport(input, LAYOUT, options);
40
+ }
41
+
42
+ function capitalGainsRecords(input: Report1214Input, options = OPTIONS) {
43
+ return reportOf(input, options).records.filter(r => isCapitalGainsRecordType(r.recordType));
44
+ }
45
+
46
+ function mainOf(input: Report1214Input) {
47
+ const main = reportOf(input).records[0];
48
+ if (main?.recordType !== '1000') {
49
+ throw new Error('expected record 1000 first');
50
+ }
51
+ return main;
52
+ }
53
+
54
+ /** The lines of the file of `input`, 9999 last. */
55
+ function linesOf(input: Report1214Input): string[] {
56
+ return renderReport(reportOf(input)).lines;
57
+ }
58
+
59
+ /** The `length` characters of `line` at the 1-based layout `position`. */
60
+ function at(line: string | undefined, position: number, length: number): string | undefined {
61
+ return line?.slice(position - 1, position - 1 + length);
62
+ }
63
+
64
+ describe('capital-gains record types (SPEC §3.7)', () => {
65
+ it('maps a symbol to its record type, 3000 + symbol', () => {
66
+ expect(capitalGainsRecordType(63)).toBe('3063');
67
+ expect(capitalGainsRecordType(27)).toBe('3027');
68
+ });
69
+
70
+ it('recognizes the ten capital-gains record types only', () => {
71
+ const types = Object.keys(LAYOUT.records).filter(type =>
72
+ isCapitalGainsRecordType(type as keyof typeof LAYOUT.records),
73
+ );
74
+ expect(types).toEqual([
75
+ '3027',
76
+ '3050',
77
+ '3051',
78
+ '3054',
79
+ '3060',
80
+ '3063',
81
+ '3064',
82
+ '3065',
83
+ '3066',
84
+ '3077',
85
+ ]);
86
+ });
87
+ });
88
+
89
+ describe('placeCapitalGains (SPEC §3.3, §7.4, §15 A-7)', () => {
90
+ const appendices = [
91
+ { symbol: 77, name: 'a' },
92
+ { symbol: 63, name: 'b' },
93
+ { symbol: 77, name: 'c' },
94
+ { symbol: 27, name: 'd' },
95
+ { symbol: 63, name: 'e' },
96
+ ];
97
+
98
+ it('groups by record type ascending, input order within a type', () => {
99
+ expect(placeCapitalGains(appendices).map(placed => placed.appendix.name)).toEqual([
100
+ 'd',
101
+ 'b',
102
+ 'e',
103
+ 'a',
104
+ 'c',
105
+ ]);
106
+ });
107
+
108
+ it('keeps the input index of every appendix', () => {
109
+ expect(placeCapitalGains(appendices).map(placed => placed.inputIndex)).toEqual([3, 1, 4, 0, 2]);
110
+ });
111
+
112
+ it('numbers appendices per symbol (30xx@139), 1-based in emission order', () => {
113
+ expect(placeCapitalGains(appendices).map(placed => placed.appendixNumber)).toEqual([
114
+ 1, 1, 2, 1, 2,
115
+ ]);
116
+ });
117
+
118
+ it('numbers the "מספר בתל"ם" sequence across all appendices, 1-based in emission order', () => {
119
+ expect(placeCapitalGains(appendices).map(placed => placed.sequenceNumber)).toEqual([
120
+ 1, 2, 3, 4, 5,
121
+ ]);
122
+ });
123
+
124
+ it('places nothing for no appendices', () => {
125
+ expect(placeCapitalGains([])).toEqual([]);
126
+ });
127
+ });
128
+
129
+ describe('normalizeReport: record 3063 (securities under section 6)', () => {
130
+ it('maps the header and the codes, with paths capitalGains[i].<key> and amounts["NNN"]', () => {
131
+ const [record] = capitalGainsRecords(minimalInput({ capitalGains: [section6Appendix()] }));
132
+ expect(record?.recordType).toBe('3063');
133
+ expect(record?.index).toBe(0);
134
+ expect(record?.inputIndex).toBe(0);
135
+ expect(record?.values).toEqual({
136
+ transactionSymbol: 63,
137
+ appendixNumber: 1,
138
+ foreignAsset: true,
139
+ lossesCarriedForward: 12_000,
140
+ });
141
+ expect([...(record?.codes ?? [])]).toEqual([
142
+ ['022', 50_000],
143
+ ['056', 3000],
144
+ ]);
145
+ expect(record?.countries).toEqual([]);
146
+ expect(record?.paths).toEqual({
147
+ transactionSymbol: '',
148
+ appendixNumber: '',
149
+ foreignAsset: 'capitalGains[0].foreignAsset',
150
+ lossesCarriedForward: 'capitalGains[0].lossesCarriedForward',
151
+ 'code:022': 'capitalGains[0].amounts["022"]',
152
+ 'code:056': 'capitalGains[0].amounts["056"]',
153
+ });
154
+ });
155
+
156
+ it('sets every non-filler header field of record 3063', () => {
157
+ const report = reportOf(minimalInput({ capitalGains: [section6Appendix()] }));
158
+ expect(unmappedHeaderKeys(LAYOUT.records['3063'], report.records)).toEqual([]);
159
+ });
160
+
161
+ it('writes the symbol at 137 and the appendix number at 139, the section at 1161', () => {
162
+ const lines = linesOf(minimalInput({ capitalGains: [section6Appendix()] }));
163
+ const line = lines.find(text => text.slice(4, 8) === '3063');
164
+ expect(at(line, 137, 2)).toBe('63');
165
+ expect(at(line, 139, 3)).toBe('001');
166
+ expect(at(line, 142, 1)).toBe('1');
167
+ expect(at(line, 143, 10)).toBe('0000012000');
168
+ expect(at(line, 1161, 26)).toBe('0220000050000' + '0560000003000');
169
+ expect(line?.slice(1186)).toMatch(/^0+$/);
170
+ });
171
+
172
+ it('writes foreignAsset false as 2 (no) and an absent one as 0', () => {
173
+ const [no] = linesOf(
174
+ minimalInput({ capitalGains: [section6Appendix({ foreignAsset: false })] }),
175
+ ).filter(text => text.slice(4, 8) === '3063');
176
+ expect(at(no, 142, 1)).toBe('2');
177
+ const [absent] = linesOf(minimalInput({ capitalGains: [{ symbol: 63, amounts: {} }] })).filter(
178
+ text => text.slice(4, 8) === '3063',
179
+ );
180
+ expect(at(absent, 142, 1)).toBe('0');
181
+ expect(at(absent, 143, 10)).toBe('0'.repeat(10));
182
+ });
183
+
184
+ it('numbers two 3063 appendices 1 and 2, in input order, with their input index', () => {
185
+ const records = capitalGainsRecords(minimalInput({ capitalGains: section6Appendices(2) }));
186
+ expect(records.map(r => [r.index, r.inputIndex, r.values.appendixNumber])).toEqual([
187
+ [0, 0, 1],
188
+ [1, 1, 2],
189
+ ]);
190
+ expect(records[1]?.codes.get('022')).toBe(2000);
191
+ expect(records[1]?.paths['code:022']).toBe('capitalGains[1].amounts["022"]');
192
+ const lines = linesOf(minimalInput({ capitalGains: section6Appendices(2) }));
193
+ expect(lines.filter(text => text.slice(4, 8) === '3063').map(text => at(text, 139, 3))).toEqual(
194
+ ['001', '002'],
195
+ );
196
+ });
197
+
198
+ it('omits zero codes (none of 3063 is zeroAllowed) and lists them by record index', () => {
199
+ const report = reportOf(
200
+ minimalInput({
201
+ capitalGains: [
202
+ section6Appendix(),
203
+ section6Appendix({ amounts: { '022': 0, '023': 0, '026': 5 } }),
204
+ ],
205
+ }),
206
+ );
207
+ const second = report.records.filter(r => r.recordType === '3063')[1];
208
+ expect([...(second?.codes.keys() ?? [])]).toEqual(['026', '056']);
209
+ expect(report.omittedZeroCodes).toEqual([
210
+ { record: '3063', recordIndex: 1, code: '022' },
211
+ { record: '3063', recordIndex: 1, code: '023' },
212
+ ]);
213
+ });
214
+
215
+ it('rounds the losses and the codes per options.rounding', () => {
216
+ const [record] = capitalGainsRecords(
217
+ minimalInput({
218
+ capitalGains: [section6Appendix({ lossesCarriedForward: 99.5, amounts: { '022': 0.4 } })],
219
+ }),
220
+ { ...OPTIONS, rounding: 'halfUp' },
221
+ );
222
+ expect(record?.values.lossesCarriedForward).toBe(100);
223
+ expect(record?.codes.has('022')).toBe(false);
224
+ });
225
+
226
+ it('emits the capital-gains records after 1030, 2000 and 2200', () => {
227
+ const report = reportOf(
228
+ minimalInput({
229
+ rdInvestments: rdInvestments(1),
230
+ amounts: { '165': rdInvestmentsTotal(1) },
231
+ foreignAppendix: foreignAppendixWithBreakdown('420', {
232
+ countries: breakdownCountries(1),
233
+ }),
234
+ capitalGains: section6Appendices(2),
235
+ }),
236
+ );
237
+ expect(report.records.map(r => [r.recordType, r.index])).toEqual([
238
+ ['1000', 0],
239
+ ['1020', 0],
240
+ ['1030', 0],
241
+ ['2000', 0],
242
+ ['2200', 0],
243
+ ['3063', 0],
244
+ ['3063', 1],
245
+ ]);
246
+ });
247
+
248
+ it('emits no capital-gains record without appendices or for an empty list', () => {
249
+ expect(capitalGainsRecords(minimalInput())).toEqual([]);
250
+ expect(capitalGainsRecords(minimalInput({ capitalGains: [] }))).toEqual([]);
251
+ });
252
+ });
253
+
254
+ describe('1000@833, code 028 and 9999@145 from the appendices (SPEC §7.4)', () => {
255
+ it('833 = yes when any appendix exists', () => {
256
+ const main = mainOf(minimalInput({ capitalGains: [section6Appendix()] }));
257
+ expect(main.values['declarations.hasCapitalGainsAppendix']).toBe(true);
258
+ expect(at(linesOf(minimalInput({ capitalGains: [section6Appendix()] }))[0], 833, 1)).toBe('1');
259
+ });
260
+
261
+ it('833 = no without appendices, untransmitted count or override', () => {
262
+ expect(mainOf(minimalInput({ capitalGains: [] })).values).toMatchObject({
263
+ 'declarations.hasCapitalGainsAppendix': false,
264
+ });
265
+ });
266
+
267
+ it('code 028 = appendices + untransmittedCount', () => {
268
+ const main = mainOf(
269
+ minimalInput({
270
+ capitalGains: section6Appendices(2),
271
+ capitalGainsSummary: { untransmittedCount: 3, reasons: { lossOrNoGain: true } },
272
+ }),
273
+ );
274
+ expect(main.codes.get('028')).toBe(5);
275
+ expect(main.paths['code:028']).toBe('');
276
+ });
277
+
278
+ it('code 028 = the number of appendices without untransmitted ones', () => {
279
+ expect(mainOf(minimalInput({ capitalGains: section6Appendices(2) })).codes.get('028')).toBe(2);
280
+ expect(mainOf(minimalInput()).codes.has('028')).toBe(false);
281
+ });
282
+
283
+ it('9999@145 counts the capital-gains appendices', () => {
284
+ expect(at(linesOf(minimalInput({ capitalGains: section6Appendices(3) })).at(-1), 145, 2)).toBe(
285
+ '03',
286
+ );
287
+ expect(at(linesOf(minimalInput()).at(-1), 145, 2)).toBe('00');
288
+ });
289
+
290
+ it('raises main.capitalGains.flag when hasCapitalGainsAppendix is false while appendices exist', () => {
291
+ const report = reportOf(
292
+ minimalInput({
293
+ declarations: { hasCapitalGainsAppendix: false },
294
+ capitalGains: [section6Appendix()],
295
+ }),
296
+ );
297
+ expect(report.notices).toEqual([
298
+ expect.objectContaining({
299
+ ruleId: 'main.capitalGains.flag',
300
+ severity: 'error',
301
+ path: 'declarations.hasCapitalGainsAppendix',
302
+ recordType: '1000',
303
+ recordIndex: 0,
304
+ value: false,
305
+ }),
306
+ ]);
307
+ // 833 itself is derived: yes.
308
+ expect(report.records[0]?.values['declarations.hasCapitalGainsAppendix']).toBe(true);
309
+ });
310
+
311
+ it('raises no notice for false without appendices, or true with appendices', () => {
312
+ const noticesOf = (overrides: Parameters<typeof minimalInput>[0]) =>
313
+ reportOf(minimalInput(overrides)).notices;
314
+ expect(noticesOf({ declarations: { hasCapitalGainsAppendix: false } })).toEqual([]);
315
+ expect(
316
+ noticesOf({
317
+ declarations: { hasCapitalGainsAppendix: true },
318
+ capitalGains: [section6Appendix()],
319
+ }),
320
+ ).toEqual([]);
321
+ });
322
+ });
323
+
324
+ /** The lines of record type `type` in the file of `input`. */
325
+ function linesOfType(input: Report1214Input, type: string): string[] {
326
+ return linesOf(input).filter(text => text.slice(4, 8) === type);
327
+ }
328
+
329
+ describe.each([
330
+ ['3060', 'securities', securitiesAppendix],
331
+ ['3064', 'REIT', reitAppendix],
332
+ ] as const)('normalizeReport: record %s (%s, with withholders)', (type, _name, build) => {
333
+ const def = LAYOUT.records[type];
334
+
335
+ it('has the shared securities header, the same keys at the same positions as the other type', () => {
336
+ const other = LAYOUT.records[type === '3060' ? '3064' : '3060'];
337
+ const shape = (fields: typeof def.fields) =>
338
+ fields.filter(f => f.kind !== 'filler').map(f => [f.key, f.position, f.length, f.kind]);
339
+ expect(shape(def.fields)).toEqual(shape(other.fields));
340
+ // No "מספר בתל"ם" sequence field: the header is symbol, appendix number, members only.
341
+ expect(def.fields.filter(f => f.kind !== 'filler').map(f => f.key)).toEqual([
342
+ 'transactionSymbol',
343
+ 'appendixNumber',
344
+ 'foreignAsset',
345
+ 'soldToRelatedParty',
346
+ 'boughtFromRelatedParty',
347
+ 'gainFromInvestmentFund',
348
+ ...[0, 1, 2, 3].flatMap(i => [
349
+ `withholders[${i}].name`,
350
+ `withholders[${i}].branch`,
351
+ `withholders[${i}].account`,
352
+ ]),
353
+ 'lossesCarriedForward',
354
+ ]);
355
+ });
356
+
357
+ it('maps the header, withholders[j] to keys withholders[j].<member>, with input paths', () => {
358
+ const appendix = build({ withholders: withholders(2) });
359
+ const [record] = capitalGainsRecords(minimalInput({ capitalGains: [appendix] }));
360
+ expect(record?.recordType).toBe(type);
361
+ expect(record?.inputIndex).toBe(0);
362
+ expect(record?.values).toEqual({
363
+ transactionSymbol: Number(type.slice(2)),
364
+ appendixNumber: 1,
365
+ foreignAsset: appendix.foreignAsset,
366
+ soldToRelatedParty: appendix.soldToRelatedParty,
367
+ boughtFromRelatedParty: appendix.boughtFromRelatedParty,
368
+ gainFromInvestmentFund: appendix.gainFromInvestmentFund,
369
+ 'withholders[0].name': 'בנק הפועלים',
370
+ 'withholders[0].branch': '011',
371
+ 'withholders[0].account': '000123450',
372
+ 'withholders[1].name': 'בנק לאומי',
373
+ 'withholders[1].branch': '012',
374
+ 'withholders[1].account': '000123451',
375
+ lossesCarriedForward: appendix.lossesCarriedForward,
376
+ });
377
+ expect(record?.paths).toMatchObject({
378
+ transactionSymbol: '',
379
+ appendixNumber: '',
380
+ foreignAsset: 'capitalGains[0].foreignAsset',
381
+ gainFromInvestmentFund: 'capitalGains[0].gainFromInvestmentFund',
382
+ 'withholders[1].name': 'capitalGains[0].withholders[1].name',
383
+ 'withholders[1].branch': 'capitalGains[0].withholders[1].branch',
384
+ 'withholders[1].account': 'capitalGains[0].withholders[1].account',
385
+ lossesCarriedForward: 'capitalGains[0].lossesCarriedForward',
386
+ 'code:056': 'capitalGains[0].amounts["056"]',
387
+ });
388
+ });
389
+
390
+ it('sets every non-filler header field with four withholders', () => {
391
+ const report = reportOf(
392
+ minimalInput({ capitalGains: [build({ withholders: withholders(4) })] }),
393
+ );
394
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
395
+ });
396
+
397
+ it('writes the header at its layout positions', () => {
398
+ const [line] = linesOfType(
399
+ minimalInput({
400
+ capitalGains: [
401
+ build({
402
+ foreignAsset: true,
403
+ soldToRelatedParty: false,
404
+ boughtFromRelatedParty: true,
405
+ gainFromInvestmentFund: false,
406
+ withholders: [{}, { name: 'בנק', branch: '12', account: '345' }],
407
+ lossesCarriedForward: 777,
408
+ }),
409
+ ],
410
+ }),
411
+ type,
412
+ );
413
+ expect(at(line, 137, 2)).toBe(type.slice(2));
414
+ expect(at(line, 139, 3)).toBe('001');
415
+ expect(at(line, 142, 4)).toBe('1212');
416
+ // Slot 0 is empty; slot 1 at 188 (name, padded on the left), 218 (branch), 221 (account).
417
+ expect(at(line, 146, 42)).toBe(' '.repeat(30) + '0'.repeat(12));
418
+ expect(at(line, 188, 30)).toBe('בנק'.padStart(30, ' '));
419
+ expect(at(line, 218, 3)).toBe('012');
420
+ expect(at(line, 221, 9)).toBe('000000345');
421
+ expect(at(line, 230, 84)).toBe((' '.repeat(30) + '0'.repeat(12)).repeat(2));
422
+ expect(at(line, 314, 10)).toBe('0000000777');
423
+ });
424
+
425
+ it('writes gainFromInvestmentFund as yes/no {1, 2} (SPEC §15 A-8)', () => {
426
+ const flag = (gainFromInvestmentFund: boolean | undefined) =>
427
+ at(
428
+ linesOfType(minimalInput({ capitalGains: [build({ gainFromInvestmentFund })] }), type)[0],
429
+ 145,
430
+ 1,
431
+ );
432
+ expect(flag(true)).toBe('1');
433
+ expect(flag(false)).toBe('2');
434
+ expect(flag(undefined)).toBe('0');
435
+ expect(def.fields.find(f => f.key === 'gainFromInvestmentFund')?.kind).toBe('yesNo');
436
+ });
437
+
438
+ it('reports a withholder name that does not start with a Hebrew letter at its input path', () => {
439
+ const input = minimalInput({
440
+ capitalGains: [
441
+ build({ withholders: [...withholders(2), { name: 'Bank Hapoalim', branch: '1' }] }),
442
+ ],
443
+ });
444
+ expect(validate1214(input, OPTIONS).errors).toEqual([
445
+ expect.objectContaining({
446
+ ruleId: 'field.hebrewFirstLetter',
447
+ path: 'capitalGains[0].withholders[2].name',
448
+ recordType: type,
449
+ recordIndex: 0,
450
+ }),
451
+ ]);
452
+ });
453
+
454
+ it('accepts four withholders and empty slots without issues', () => {
455
+ expect(
456
+ validate1214(
457
+ minimalInput({ capitalGains: [build({ withholders: withholders(4) })] }),
458
+ OPTIONS,
459
+ ),
460
+ ).toEqual({ valid: true, errors: [], warnings: [] });
461
+ expect(
462
+ validate1214(
463
+ minimalInput({ capitalGains: [build({ withholders: [{}, {}, ...withholders(1)] })] }),
464
+ OPTIONS,
465
+ ),
466
+ ).toEqual({ valid: true, errors: [], warnings: [] });
467
+ });
468
+
469
+ it('reports a fifth withholder as input.shape', () => {
470
+ const input = minimalInput({
471
+ capitalGains: [build({ withholders: [...withholders(4), { name: 'בנק' }] })],
472
+ });
473
+ expect(validate1214(input, OPTIONS).errors).toEqual([
474
+ expect.objectContaining({ ruleId: 'input.shape', path: 'capitalGains[0].withholders' }),
475
+ ]);
476
+ });
477
+ });
478
+
479
+ describe('mixed appendices (SPEC §3.3, §15 A-7)', () => {
480
+ // Input order 64, 60, 63, 60: emitted 3060, 3060, 3063, 3064.
481
+ const appendices = [
482
+ reitAppendix(),
483
+ securitiesAppendix({ amounts: { '012': 1 } }),
484
+ section6Appendix(),
485
+ securitiesAppendix({ amounts: { '012': 2 } }),
486
+ ];
487
+ const input = minimalInput({ capitalGains: appendices });
488
+
489
+ it('groups the records by type ascending, numbers them per symbol, keeps the input index', () => {
490
+ expect(
491
+ capitalGainsRecords(input).map(r => [
492
+ r.recordType,
493
+ r.index,
494
+ r.inputIndex,
495
+ r.values.appendixNumber,
496
+ ]),
497
+ ).toEqual([
498
+ ['3060', 0, 1, 1],
499
+ ['3060', 1, 3, 2],
500
+ ['3063', 0, 2, 1],
501
+ ['3064', 0, 0, 1],
502
+ ]);
503
+ const lines = linesOf(input).filter(text =>
504
+ isCapitalGainsRecordType(text.slice(4, 8) as '3060'),
505
+ );
506
+ expect(lines.map(text => [text.slice(4, 8), at(text, 137, 5)])).toEqual([
507
+ ['3060', '60001'],
508
+ ['3060', '60002'],
509
+ ['3063', '63001'],
510
+ ['3064', '64001'],
511
+ ]);
512
+ // Code 028 and 9999@145 count all of them.
513
+ expect(mainOf(input).codes.get('028')).toBe(4);
514
+ expect(at(linesOf(input).at(-1), 145, 2)).toBe('04');
515
+ });
516
+
517
+ it('writes no sequence for these types: the header ends with the losses carried forward', () => {
518
+ for (const line of linesOf(input).slice(2, -1)) {
519
+ const type = line.slice(4, 8) as '3060' | '3063' | '3064';
520
+ const def = LAYOUT.records[type];
521
+ const filler = def.fields.find(f => f.kind === 'filler');
522
+ expect(filler).toBeDefined();
523
+ expect(at(line, filler?.position ?? 0, filler?.length ?? 0)).toMatch(/^0+$/);
524
+ }
525
+ });
526
+ });
527
+
528
+ describe('end to end: appendices [64, 60, 63]', () => {
529
+ const appendices = [
530
+ reitAppendix({ withholders: [{ name: 'Leumi' }] }),
531
+ securitiesAppendix(),
532
+ section6Appendix({ foreignAsset: false }),
533
+ ];
534
+ const input = minimalInput({ capitalGains: appendices });
535
+
536
+ it('reports an issue of the 3064 appendix at capitalGains[0], its input index', () => {
537
+ expect(validate1214(input, OPTIONS).errors).toEqual([
538
+ expect.objectContaining({
539
+ ruleId: 'field.hebrewFirstLetter',
540
+ path: 'capitalGains[0].withholders[0].name',
541
+ recordType: '3064',
542
+ recordIndex: 0,
543
+ }),
544
+ ]);
545
+ });
546
+
547
+ it('reports an issue of the 3060 appendix at capitalGains[1] and of 3063 at capitalGains[2]', () => {
548
+ const errors = validate1214(
549
+ minimalInput({
550
+ capitalGains: [
551
+ reitAppendix(),
552
+ securitiesAppendix({ lossesCarriedForward: 1.5 }),
553
+ section6Appendix({ lossesCarriedForward: -1 }),
554
+ ],
555
+ }),
556
+ OPTIONS,
557
+ ).errors;
558
+ expect(errors.map(issue => [issue.ruleId, issue.path, issue.recordType])).toEqual([
559
+ ['field.integer', 'capitalGains[1].lossesCarriedForward', '3060'],
560
+ ['field.negative', 'capitalGains[2].lossesCarriedForward', '3063'],
561
+ ]);
562
+ });
563
+
564
+ it('generates 3060, 3063, 3064 and parses them back in file order', () => {
565
+ const valid = minimalInput({
566
+ capitalGains: [reitAppendix(), securitiesAppendix(), section6Appendix()],
567
+ });
568
+ const { text } = generate1214(valid, OPTIONS);
569
+ const parsed = parse1214(text);
570
+ expect(parsed.issues).toEqual([]);
571
+ expect(parsed.report.capitalGains).toEqual([
572
+ securitiesAppendix(),
573
+ section6Appendix(),
574
+ reitAppendix(),
575
+ ]);
576
+ });
577
+ });
578
+
579
+ describe('normalizeReport: record 3065 (no withholding, form 1322)', () => {
580
+ const def = LAYOUT.records['3065'];
581
+
582
+ it('has the securities header with a withholding status and the sequence, one position later', () => {
583
+ const position = (key: string) => def.fields.find(f => f.key === key)?.position;
584
+ expect(def.fields.filter(f => f.kind !== 'filler').map(f => f.key)).toEqual([
585
+ 'transactionSymbol',
586
+ 'appendixNumber',
587
+ 'foreignAsset',
588
+ 'soldToRelatedParty',
589
+ 'boughtFromRelatedParty',
590
+ 'gainFromInvestmentFund',
591
+ 'withholdingStatus',
592
+ ...[0, 1, 2, 3].flatMap(i => [
593
+ `withholders[${i}].name`,
594
+ `withholders[${i}].branch`,
595
+ `withholders[${i}].account`,
596
+ ]),
597
+ 'lossesCarriedForward',
598
+ 'sequenceNumber',
599
+ ]);
600
+ // 3060 has its first withholder at 146; 3065 has the withholding status there.
601
+ expect(LAYOUT.records['3060'].fields.find(f => f.key === 'withholders[0].name')?.position).toBe(
602
+ 146,
603
+ );
604
+ expect(position('withholdingStatus')).toBe(146);
605
+ expect(position('withholders[0].name')).toBe(147);
606
+ expect(position('sequenceNumber')).toBe(325);
607
+ });
608
+
609
+ it('maps the header, the withholders and the status code, with input paths', () => {
610
+ const appendix = noWithholding1322Appendix();
611
+ const [record] = capitalGainsRecords(minimalInput({ capitalGains: [appendix] }));
612
+ expect(record?.recordType).toBe('3065');
613
+ expect(record?.inputIndex).toBe(0);
614
+ expect(record?.values).toEqual({
615
+ transactionSymbol: 65,
616
+ appendixNumber: 1,
617
+ sequenceNumber: 1,
618
+ foreignAsset: false,
619
+ soldToRelatedParty: true,
620
+ boughtFromRelatedParty: true,
621
+ gainFromInvestmentFund: false,
622
+ withholdingStatus: 2,
623
+ 'withholders[0].name': 'בנק הפועלים',
624
+ 'withholders[0].branch': '011',
625
+ 'withholders[0].account': '000123450',
626
+ 'withholders[1].name': 'בנק לאומי',
627
+ 'withholders[1].branch': '012',
628
+ 'withholders[1].account': '000123451',
629
+ lossesCarriedForward: 6000,
630
+ });
631
+ expect(record?.paths).toEqual({
632
+ transactionSymbol: '',
633
+ appendixNumber: '',
634
+ sequenceNumber: '',
635
+ foreignAsset: 'capitalGains[0].foreignAsset',
636
+ soldToRelatedParty: 'capitalGains[0].soldToRelatedParty',
637
+ boughtFromRelatedParty: 'capitalGains[0].boughtFromRelatedParty',
638
+ gainFromInvestmentFund: 'capitalGains[0].gainFromInvestmentFund',
639
+ withholdingStatus: 'capitalGains[0].withholdingStatus',
640
+ 'withholders[0].name': 'capitalGains[0].withholders[0].name',
641
+ 'withholders[0].branch': 'capitalGains[0].withholders[0].branch',
642
+ 'withholders[0].account': 'capitalGains[0].withholders[0].account',
643
+ 'withholders[1].name': 'capitalGains[0].withholders[1].name',
644
+ 'withholders[1].branch': 'capitalGains[0].withholders[1].branch',
645
+ 'withholders[1].account': 'capitalGains[0].withholders[1].account',
646
+ lossesCarriedForward: 'capitalGains[0].lossesCarriedForward',
647
+ 'code:012': 'capitalGains[0].amounts["012"]',
648
+ 'code:056': 'capitalGains[0].amounts["056"]',
649
+ });
650
+ });
651
+
652
+ it('sets every non-filler header field with four withholders', () => {
653
+ const report = reportOf(
654
+ minimalInput({ capitalGains: [noWithholding1322Appendix({ withholders: withholders(4) })] }),
655
+ );
656
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
657
+ });
658
+
659
+ it('writes the header at its layout positions', () => {
660
+ const [line] = linesOfType(
661
+ minimalInput({
662
+ capitalGains: [
663
+ noWithholding1322Appendix({
664
+ foreignAsset: true,
665
+ soldToRelatedParty: false,
666
+ boughtFromRelatedParty: true,
667
+ gainFromInvestmentFund: false,
668
+ withholdingStatus: 'notWithheldSecondHalf',
669
+ withholders: [{}, { name: 'בנק', branch: '12', account: '345' }],
670
+ lossesCarriedForward: 777,
671
+ }),
672
+ ],
673
+ }),
674
+ '3065',
675
+ );
676
+ expect(at(line, 137, 5)).toBe('65001');
677
+ expect(at(line, 142, 4)).toBe('1212');
678
+ expect(at(line, 146, 1)).toBe('3');
679
+ // Slot 0 is empty; slot 1 at 189 (name, padded on the left), 219 (branch), 222 (account).
680
+ expect(at(line, 147, 42)).toBe(' '.repeat(30) + '0'.repeat(12));
681
+ expect(at(line, 189, 30)).toBe('בנק'.padStart(30, ' '));
682
+ expect(at(line, 219, 3)).toBe('012');
683
+ expect(at(line, 222, 9)).toBe('000000345');
684
+ expect(at(line, 231, 84)).toBe((' '.repeat(30) + '0'.repeat(12)).repeat(2));
685
+ expect(at(line, 315, 10)).toBe('0000000777');
686
+ expect(at(line, 325, 2)).toBe('01');
687
+ expect(at(line, 327, 834)).toMatch(/^0+$/);
688
+ expect(at(line, 1161, 26)).toBe('0120000025000' + '0560000001250');
689
+ });
690
+
691
+ it('reports a withholder name that does not start with a Hebrew letter at its input path', () => {
692
+ const input = minimalInput({
693
+ capitalGains: [
694
+ section6Appendix(),
695
+ noWithholding1322Appendix({ withholders: [{}, { name: 'Bank Leumi' }] }),
696
+ ],
697
+ });
698
+ expect(validate1214(input, OPTIONS).errors).toEqual([
699
+ expect.objectContaining({
700
+ ruleId: 'field.hebrewFirstLetter',
701
+ path: 'capitalGains[1].withholders[1].name',
702
+ recordType: '3065',
703
+ recordIndex: 0,
704
+ }),
705
+ ]);
706
+ });
707
+
708
+ it('reports a fifth withholder as input.shape', () => {
709
+ const input = minimalInput({
710
+ capitalGains: [
711
+ noWithholding1322Appendix({ withholders: [...withholders(4), { name: 'בנק' }] }),
712
+ ],
713
+ });
714
+ expect(validate1214(input, OPTIONS).errors).toEqual([
715
+ expect.objectContaining({ ruleId: 'input.shape', path: 'capitalGains[0].withholders' }),
716
+ ]);
717
+ });
718
+ });
719
+
720
+ describe('normalizeReport: record 3066 (no withholding, form 1326)', () => {
721
+ const def = LAYOUT.records['3066'];
722
+
723
+ it('has a short header: foreign asset, withholding status, losses and the sequence', () => {
724
+ expect(
725
+ def.fields.filter(f => f.kind !== 'filler').map(f => [f.key, f.position, f.length]),
726
+ ).toEqual([
727
+ ['transactionSymbol', 137, 2],
728
+ ['appendixNumber', 139, 3],
729
+ ['foreignAsset', 142, 1],
730
+ ['withholdingStatus', 143, 1],
731
+ ['lossesCarriedForward', 144, 10],
732
+ ['sequenceNumber', 154, 2],
733
+ ]);
734
+ });
735
+
736
+ it('maps the header and the status code, with input paths', () => {
737
+ const [record] = capitalGainsRecords(
738
+ minimalInput({ capitalGains: [noWithholding1326Appendix()] }),
739
+ );
740
+ expect(record?.recordType).toBe('3066');
741
+ expect(record?.values).toEqual({
742
+ transactionSymbol: 66,
743
+ appendixNumber: 1,
744
+ sequenceNumber: 1,
745
+ foreignAsset: true,
746
+ withholdingStatus: 3,
747
+ lossesCarriedForward: 4000,
748
+ });
749
+ expect(record?.paths).toEqual({
750
+ transactionSymbol: '',
751
+ appendixNumber: '',
752
+ sequenceNumber: '',
753
+ foreignAsset: 'capitalGains[0].foreignAsset',
754
+ withholdingStatus: 'capitalGains[0].withholdingStatus',
755
+ lossesCarriedForward: 'capitalGains[0].lossesCarriedForward',
756
+ 'code:022': 'capitalGains[0].amounts["022"]',
757
+ 'code:056': 'capitalGains[0].amounts["056"]',
758
+ });
759
+ });
760
+
761
+ it('sets every non-filler header field of record 3066', () => {
762
+ const report = reportOf(minimalInput({ capitalGains: [noWithholding1326Appendix()] }));
763
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
764
+ });
765
+
766
+ it('writes the header at its layout positions', () => {
767
+ const [line] = linesOfType(
768
+ minimalInput({
769
+ capitalGains: [
770
+ noWithholding1326Appendix({
771
+ foreignAsset: false,
772
+ withholdingStatus: 'notWithheldFirstHalf',
773
+ lossesCarriedForward: 321,
774
+ }),
775
+ ],
776
+ }),
777
+ '3066',
778
+ );
779
+ expect(at(line, 137, 5)).toBe('66001');
780
+ expect(at(line, 142, 1)).toBe('2');
781
+ expect(at(line, 143, 1)).toBe('2');
782
+ expect(at(line, 144, 10)).toBe('0000000321');
783
+ expect(at(line, 154, 2)).toBe('01');
784
+ expect(at(line, 156, 1005)).toMatch(/^0+$/);
785
+ expect(at(line, 1161, 26)).toBe('0220000018000' + '0560000000900');
786
+ });
787
+
788
+ it('has no withholders member: one is input.shape', () => {
789
+ const input = {
790
+ ...minimalInput(),
791
+ capitalGains: [{ ...noWithholding1326Appendix(), withholders: withholders(1) }],
792
+ };
793
+ expect(validate1214(input, OPTIONS).errors).toEqual([
794
+ expect.objectContaining({ ruleId: 'input.shape', path: 'capitalGains[0].withholders' }),
795
+ ]);
796
+ });
797
+ });
798
+
799
+ describe.each([
800
+ ['3065', 146, noWithholding1322Appendix],
801
+ ['3066', 143, noWithholding1326Appendix],
802
+ ] as const)('withholdingStatus of record %s (SPEC §7.3, §15 A-18)', (type, position, build) => {
803
+ const status = (
804
+ withholdingStatus: 'notWithheldFirstHalf' | 'notWithheldSecondHalf' | undefined,
805
+ ) =>
806
+ at(
807
+ linesOfType(minimalInput({ capitalGains: [build({ withholdingStatus })] }), type)[0],
808
+ position,
809
+ 1,
810
+ );
811
+
812
+ it(`writes notWithheldFirstHalf → 2, notWithheldSecondHalf → 3, absent → 0 at ${position}`, () => {
813
+ expect(status('notWithheldFirstHalf')).toBe('2');
814
+ expect(status('notWithheldSecondHalf')).toBe('3');
815
+ expect(status(undefined)).toBe('0');
816
+ });
817
+
818
+ it('reads the status back as its literal, and an absent one as absent', () => {
819
+ for (const withholdingStatus of ['notWithheldFirstHalf', 'notWithheldSecondHalf'] as const) {
820
+ const input = minimalInput({ capitalGains: [build({ withholdingStatus })] });
821
+ const [appendix] = parse1214(generate1214(input, OPTIONS).text).report.capitalGains ?? [];
822
+ expect(appendix).toMatchObject({ withholdingStatus });
823
+ }
824
+ const appendix = { ...build() };
825
+ delete appendix.withholdingStatus;
826
+ const input = minimalInput({ capitalGains: [appendix] });
827
+ const [parsed] = parse1214(generate1214(input, OPTIONS).text).report.capitalGains ?? [];
828
+ expect(parsed).toEqual(appendix);
829
+ expect(parsed).not.toHaveProperty('withholdingStatus');
830
+ });
831
+ });
832
+
833
+ describe('the "מספר בתל"ם" sequence across mixed appendices (SPEC §7.4, §15 A-7)', () => {
834
+ // Input order 63, 65, 60, 66: emitted 3060, 3063, 3065, 3066.
835
+ const input = minimalInput({
836
+ capitalGains: [
837
+ section6Appendix(),
838
+ noWithholding1322Appendix(),
839
+ securitiesAppendix(),
840
+ noWithholding1326Appendix(),
841
+ ],
842
+ });
843
+
844
+ it('numbers 3065 and 3066 by their emission position among all appendices', () => {
845
+ expect(
846
+ capitalGainsRecords(input).map(r => [
847
+ r.recordType,
848
+ r.inputIndex,
849
+ r.values.appendixNumber,
850
+ r.values.sequenceNumber,
851
+ ]),
852
+ ).toEqual([
853
+ ['3060', 2, 1, undefined],
854
+ ['3063', 0, 1, undefined],
855
+ ['3065', 1, 1, 3],
856
+ ['3066', 3, 1, 4],
857
+ ]);
858
+ });
859
+
860
+ it('writes the sequence at 3065@325 and 3066@154, and keeps the input index in paths', () => {
861
+ const lines = linesOf(input);
862
+ expect(lines.map(line => line.slice(4, 8))).toEqual([
863
+ '1000',
864
+ '1020',
865
+ '3060',
866
+ '3063',
867
+ '3065',
868
+ '3066',
869
+ '9999',
870
+ ]);
871
+ expect(at(lines[4], 325, 2)).toBe('03');
872
+ expect(at(lines[5], 154, 2)).toBe('04');
873
+ expect(at(lines.at(-1), 145, 2)).toBe('04');
874
+ const errors = validate1214(
875
+ minimalInput({
876
+ capitalGains: [
877
+ section6Appendix(),
878
+ noWithholding1322Appendix({ lossesCarriedForward: -1 }),
879
+ securitiesAppendix(),
880
+ noWithholding1326Appendix({ lossesCarriedForward: 1.5 }),
881
+ ],
882
+ }),
883
+ OPTIONS,
884
+ ).errors;
885
+ expect(errors.map(issue => [issue.ruleId, issue.path, issue.recordType])).toEqual([
886
+ ['field.negative', 'capitalGains[1].lossesCarriedForward', '3065'],
887
+ ['field.integer', 'capitalGains[3].lossesCarriedForward', '3066'],
888
+ ]);
889
+ });
890
+
891
+ it('generates the four records and parses them back in file order', () => {
892
+ const { text } = generate1214(input, OPTIONS);
893
+ const parsed = parse1214(text);
894
+ expect(parsed.issues).toEqual([]);
895
+ expect(parsed.report.capitalGains).toEqual([
896
+ securitiesAppendix(),
897
+ section6Appendix(),
898
+ noWithholding1322Appendix(),
899
+ noWithholding1326Appendix(),
900
+ ]);
901
+ });
902
+ });
903
+
904
+ /** The [ruleId, path, recordType] of every error of `input`. */
905
+ function errorsOf(input: Report1214Input): Array<[string, string, string | undefined]> {
906
+ return validate1214(input, OPTIONS).errors.map(issue => [
907
+ issue.ruleId,
908
+ issue.path,
909
+ issue.recordType,
910
+ ]);
911
+ }
912
+
913
+ /**
914
+ * The [ruleId, path] of the field-rule issues of the report of `input`, normalized without the
915
+ * shape stage: an untyped caller's input that lacks a member the types require (SPEC §9.3).
916
+ */
917
+ function fieldIssuesOf(input: unknown): Array<[string, string]> {
918
+ return fieldRules(reportOf(input as Report1214Input)).map(issue => [issue.ruleId, issue.path]);
919
+ }
920
+
921
+ describe('normalizeReport: record 3027 (shares)', () => {
922
+ const def = LAYOUT.records['3027'];
923
+
924
+ it('has the asset header with three dates and the sequence at 255', () => {
925
+ expect(
926
+ def.fields.filter(f => f.kind !== 'filler').map(f => [f.key, f.position, f.length, f.kind]),
927
+ ).toEqual([
928
+ ['transactionSymbol', 137, 2, 'const'],
929
+ ['appendixNumber', 139, 3, 'serial'],
930
+ ['expropriation', 142, 1, 'yesNo'],
931
+ ['assetDetails', 143, 50, 'hebrewText'],
932
+ ['assetLocation', 193, 1, 'enum'],
933
+ ['relatedParty', 194, 1, 'yesNo'],
934
+ ['buyerName', 195, 30, 'text'],
935
+ ['dates.code15', 225, 10, 'date'],
936
+ ['dates.code20', 235, 10, 'date'],
937
+ ['dates.code53', 245, 10, 'date'],
938
+ ['sequenceNumber', 255, 2, 'serial'],
939
+ ]);
940
+ });
941
+
942
+ it('maps the header, the dates as dates.<code> and the location code, with input paths', () => {
943
+ const [record] = capitalGainsRecords(minimalInput({ capitalGains: [sharesAppendix()] }));
944
+ expect(record?.recordType).toBe('3027');
945
+ expect(record?.inputIndex).toBe(0);
946
+ expect(record?.values).toEqual({
947
+ transactionSymbol: 27,
948
+ appendixNumber: 1,
949
+ sequenceNumber: 1,
950
+ expropriation: false,
951
+ assetDetails: 'מניות חברה פרטית',
952
+ assetLocation: 1,
953
+ relatedParty: true,
954
+ buyerName: 'קונה בע"מ',
955
+ 'dates.code15': '2024-03-15',
956
+ 'dates.code20': '2015-06-01',
957
+ 'dates.code53': '2010-01-31',
958
+ });
959
+ expect([...(record?.codes ?? [])]).toEqual([
960
+ ['015', 90_000],
961
+ ['018', 23],
962
+ ['020', 1234.56],
963
+ ['074', 5000],
964
+ ]);
965
+ expect(record?.paths).toEqual({
966
+ transactionSymbol: '',
967
+ appendixNumber: '',
968
+ sequenceNumber: '',
969
+ expropriation: 'capitalGains[0].expropriation',
970
+ assetDetails: 'capitalGains[0].assetDetails',
971
+ assetLocation: 'capitalGains[0].assetLocation',
972
+ relatedParty: 'capitalGains[0].relatedParty',
973
+ buyerName: 'capitalGains[0].buyerName',
974
+ 'dates.code15': 'capitalGains[0].dates.code15',
975
+ 'dates.code20': 'capitalGains[0].dates.code20',
976
+ 'dates.code53': 'capitalGains[0].dates.code53',
977
+ 'code:015': 'capitalGains[0].amounts["015"]',
978
+ 'code:018': 'capitalGains[0].amounts["018"]',
979
+ 'code:020': 'capitalGains[0].amounts["020"]',
980
+ 'code:074': 'capitalGains[0].amounts["074"]',
981
+ });
982
+ });
983
+
984
+ it('sets every non-filler header field of record 3027', () => {
985
+ const report = reportOf(minimalInput({ capitalGains: [sharesAppendix()] }));
986
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
987
+ });
988
+
989
+ it('writes the header at its layout positions, the dates as DD/MM/YYYY', () => {
990
+ const [line] = linesOfType(minimalInput({ capitalGains: [sharesAppendix()] }), '3027');
991
+ expect(at(line, 137, 5)).toBe('27001');
992
+ expect(at(line, 142, 1)).toBe('2');
993
+ expect(at(line, 143, 50)).toBe('מניות חברה פרטית'.padStart(50, ' '));
994
+ expect(at(line, 193, 1)).toBe('1');
995
+ expect(at(line, 194, 1)).toBe('1');
996
+ expect(at(line, 195, 30)).toBe('קונה בע"מ'.padStart(30, ' '));
997
+ expect(at(line, 225, 10)).toBe('15/03/2024');
998
+ expect(at(line, 235, 10)).toBe('01/06/2015');
999
+ expect(at(line, 245, 10)).toBe('31/01/2010');
1000
+ expect(at(line, 255, 2)).toBe('01');
1001
+ expect(at(line, 257, 904)).toMatch(/^0+$/);
1002
+ });
1003
+
1004
+ it('writes codes 020/053/027 ×100 with agorot (1234.56 → 123456) and the rate 018 ×100', () => {
1005
+ const [line] = linesOfType(
1006
+ minimalInput({
1007
+ capitalGains: [
1008
+ sharesAppendix({
1009
+ amounts: { '015': 7, '018': 23, '020': 1234.56, '027': 0.01, '053': 99 },
1010
+ }),
1011
+ ],
1012
+ }),
1013
+ '3027',
1014
+ );
1015
+ expect(at(line, 1161, 3 + 10 + 3 + 4 + 3 * (3 + 12) + 3 + 10)).toBe(
1016
+ '015' +
1017
+ '0000000007' +
1018
+ '018' +
1019
+ '2300' +
1020
+ '020' +
1021
+ '000000123456' +
1022
+ '027' +
1023
+ '000000000001' +
1024
+ '053' +
1025
+ '000000009900' +
1026
+ '074' +
1027
+ '0000005000',
1028
+ );
1029
+ const [rate50] = linesOfType(
1030
+ minimalInput({ capitalGains: [sharesAppendix({ amounts: { '015': 1, '018': 50 } })] }),
1031
+ '3027',
1032
+ );
1033
+ expect(at(rate50, 1174, 7)).toBe('0185000');
1034
+ });
1035
+
1036
+ it('reports code 018 outside {23, 50} as field.enum and a third decimal as field.decimals', () => {
1037
+ expect(
1038
+ errorsOf(
1039
+ minimalInput({
1040
+ capitalGains: [
1041
+ section6Appendix(),
1042
+ sharesAppendix({ amounts: { '018': 30, '053': 1.234 } }),
1043
+ ],
1044
+ }),
1045
+ ),
1046
+ ).toEqual([
1047
+ ['field.enum', 'capitalGains[1].amounts["018"]', '3027'],
1048
+ ['field.decimals', 'capitalGains[1].amounts["053"]', '3027'],
1049
+ ]);
1050
+ });
1051
+
1052
+ it('writes assetLocation abroad → 1, israel → 2, absent → 0', () => {
1053
+ const location = (assetLocation: 'abroad' | 'israel' | undefined) =>
1054
+ at(
1055
+ linesOfType(minimalInput({ capitalGains: [sharesAppendix({ assetLocation })] }), '3027')[0],
1056
+ 193,
1057
+ 1,
1058
+ );
1059
+ expect(location('abroad')).toBe('1');
1060
+ expect(location('israel')).toBe('2');
1061
+ expect(location(undefined)).toBe('0');
1062
+ });
1063
+
1064
+ it('accepts an appendix without dates or other members: the date fields are blank', () => {
1065
+ const input = minimalInput({ capitalGains: [{ symbol: 27, amounts: { '015': 1 } }] });
1066
+ expect(validate1214(input, OPTIONS)).toEqual({ valid: true, errors: [], warnings: [] });
1067
+ const [line] = linesOfType(input, '3027');
1068
+ expect(at(line, 142, 1)).toBe('0');
1069
+ expect(at(line, 225, 30)).toBe(' '.repeat(30));
1070
+ expect(at(line, 255, 2)).toBe('01');
1071
+ const partial = minimalInput({
1072
+ capitalGains: [
1073
+ sharesAppendix({ dates: { code15: undefined, code20: undefined, code53: '2020-02-29' } }),
1074
+ ],
1075
+ });
1076
+ const [partialLine] = linesOfType(partial, '3027');
1077
+ expect(at(partialLine, 225, 30)).toBe(' '.repeat(20) + '29/02/2020');
1078
+ });
1079
+
1080
+ it('reports a date that is not a real calendar date at capitalGains[i].dates.<code>', () => {
1081
+ expect(
1082
+ errorsOf(
1083
+ minimalInput({ capitalGains: [sharesAppendix({ dates: { code20: '2023-02-29' } })] }),
1084
+ ),
1085
+ ).toEqual([['field.date', 'capitalGains[0].dates.code20', '3027']]);
1086
+ });
1087
+
1088
+ it('takes a buyer name that does not start with a Hebrew letter (kind text)', () => {
1089
+ expect(
1090
+ errorsOf(minimalInput({ capitalGains: [sharesAppendix({ buyerName: 'Buyer Ltd' })] })),
1091
+ ).toEqual([]);
1092
+ });
1093
+ });
1094
+
1095
+ describe.each([
1096
+ ['3050', 'betterment tax', bettermentTaxAppendix, 193, 203],
1097
+ ['3054', 'oil partnership', oilPartnershipAppendix, 192, 202],
1098
+ ] as const)(
1099
+ 'normalizeReport: record %s (%s)',
1100
+ (type, _name, build, purchaseDatePosition, code15Position) => {
1101
+ const def = LAYOUT.records[type];
1102
+ const symbol = Number(type.slice(2));
1103
+
1104
+ it('requires the purchase date and the code-15 date and has no sequence field', () => {
1105
+ const keys = def.fields.filter(f => f.kind !== 'filler').map(f => f.key);
1106
+ expect(keys).not.toContain('sequenceNumber');
1107
+ expect(
1108
+ def.fields
1109
+ .filter(f => f.key === 'purchaseDate' || f.key === 'dates.code15')
1110
+ .map(f => [f.key, f.position, f.required, f.kind]),
1111
+ ).toEqual([
1112
+ ['purchaseDate', purchaseDatePosition, 'yes', 'date'],
1113
+ ['dates.code15', code15Position, 'yes', 'date'],
1114
+ ]);
1115
+ });
1116
+
1117
+ it('maps the header with input paths', () => {
1118
+ const appendix = build();
1119
+ const [record] = capitalGainsRecords(minimalInput({ capitalGains: [appendix] }));
1120
+ expect(record?.recordType).toBe(type);
1121
+ expect(record?.values).toEqual({
1122
+ transactionSymbol: symbol,
1123
+ appendixNumber: 1,
1124
+ ...('expropriation' in appendix ? { expropriation: appendix.expropriation } : {}),
1125
+ assetDetails: appendix.assetDetails,
1126
+ purchaseDate: appendix.purchaseDate,
1127
+ 'dates.code15': appendix.dates.code15,
1128
+ });
1129
+ expect(record?.paths).toMatchObject({
1130
+ transactionSymbol: '',
1131
+ appendixNumber: '',
1132
+ assetDetails: 'capitalGains[0].assetDetails',
1133
+ purchaseDate: 'capitalGains[0].purchaseDate',
1134
+ 'dates.code15': 'capitalGains[0].dates.code15',
1135
+ 'code:015': 'capitalGains[0].amounts["015"]',
1136
+ });
1137
+ });
1138
+
1139
+ it(`sets every non-filler header field of record ${type}`, () => {
1140
+ const report = reportOf(minimalInput({ capitalGains: [build()] }));
1141
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
1142
+ });
1143
+
1144
+ it('writes the header at its layout positions', () => {
1145
+ const appendix = build({ purchaseDate: '2001-02-03', dates: { code15: '2024-11-30' } });
1146
+ const [line] = linesOfType(minimalInput({ capitalGains: [appendix] }), type);
1147
+ expect(at(line, 137, 5)).toBe(`${symbol}001`);
1148
+ expect(at(line, purchaseDatePosition, 10)).toBe('03/02/2001');
1149
+ expect(at(line, code15Position, 10)).toBe('30/11/2024');
1150
+ expect(at(line, purchaseDatePosition - 50, 50)).toBe(
1151
+ (appendix.assetDetails ?? '').padStart(50, ' '),
1152
+ );
1153
+ expect(at(line, code15Position + 10, 1160 - code15Position - 9)).toMatch(/^0+$/);
1154
+ });
1155
+
1156
+ it('reports an absent purchase date or code-15 date: input.shape for typed input', () => {
1157
+ const appendix: Record<string, unknown> = { ...build() };
1158
+ delete appendix['purchaseDate'];
1159
+ const input = { ...minimalInput(), capitalGains: [appendix, { ...build(), dates: {} }] };
1160
+ expect(validate1214(input, OPTIONS).errors.map(issue => [issue.ruleId, issue.path])).toEqual([
1161
+ ['input.shape', 'capitalGains[0].purchaseDate'],
1162
+ ['input.shape', 'capitalGains[1].dates.code15'],
1163
+ ]);
1164
+ });
1165
+
1166
+ it('reports them as field.required at capitalGains[i].purchaseDate / .dates.code15', () => {
1167
+ const withoutPurchaseDate: Record<string, unknown> = { ...build() };
1168
+ delete withoutPurchaseDate['purchaseDate'];
1169
+ const withoutDates: Record<string, unknown> = { ...build() };
1170
+ delete withoutDates['dates'];
1171
+ expect(
1172
+ fieldIssuesOf({
1173
+ ...minimalInput(),
1174
+ capitalGains: [section6Appendix(), withoutDates, withoutPurchaseDate],
1175
+ }),
1176
+ ).toEqual([
1177
+ ['field.required', 'capitalGains[1].dates.code15'],
1178
+ ['field.required', 'capitalGains[2].purchaseDate'],
1179
+ ]);
1180
+ });
1181
+ },
1182
+ );
1183
+
1184
+ describe('record 3050 codes', () => {
1185
+ it('accepts code 014 = 10 or 20 and reports any other value as field.enum', () => {
1186
+ expect(
1187
+ errorsOf(minimalInput({ capitalGains: [bettermentTaxAppendix({ amounts: { '014': 20 } })] })),
1188
+ ).toEqual([]);
1189
+ expect(
1190
+ errorsOf(minimalInput({ capitalGains: [bettermentTaxAppendix({ amounts: { '014': 15 } })] })),
1191
+ ).toEqual([['field.enum', 'capitalGains[0].amounts["014"]', '3050']]);
1192
+ });
1193
+
1194
+ it('writes 014, then 015, 016 and the rate 018 ×100 in ascending code order', () => {
1195
+ const [line] = linesOfType(minimalInput({ capitalGains: [bettermentTaxAppendix()] }), '3050');
1196
+ expect(at(line, 1161, 5 + 13 + 13 + 7)).toBe(
1197
+ '01410' + '0150001200000' + '0160000700000' + '0185000',
1198
+ );
1199
+ });
1200
+
1201
+ it('reports code 018 outside {23, 50} as field.enum (D-6)', () => {
1202
+ expect(
1203
+ errorsOf(minimalInput({ capitalGains: [bettermentTaxAppendix({ amounts: { '018': 25 } })] })),
1204
+ ).toEqual([['field.enum', 'capitalGains[0].amounts["018"]', '3050']]);
1205
+ });
1206
+
1207
+ it('omits code 016 = 0 (not zeroAllowed in 3050)', () => {
1208
+ const report = reportOf(
1209
+ minimalInput({ capitalGains: [bettermentTaxAppendix({ amounts: { '016': 0 } })] }),
1210
+ );
1211
+ expect(report.omittedZeroCodes).toEqual([{ record: '3050', recordIndex: 0, code: '016' }]);
1212
+ });
1213
+ });
1214
+
1215
+ describe('record 3054 codes', () => {
1216
+ it('writes code 016 = 0 (zeroAllowed, SPEC §4.5)', () => {
1217
+ const input = minimalInput({
1218
+ capitalGains: [oilPartnershipAppendix({ amounts: { '015': 0, '016': 0 } })],
1219
+ });
1220
+ const report = reportOf(input);
1221
+ expect(report.omittedZeroCodes).toEqual([{ record: '3054', recordIndex: 0, code: '015' }]);
1222
+ const [line] = linesOfType(input, '3054');
1223
+ expect(at(line, 1161, 14)).toBe('0160000000000' + '0');
1224
+ expect(validate1214(input, OPTIONS).errors).toEqual([]);
1225
+ });
1226
+ });
1227
+
1228
+ describe('normalizeReport: record 3051 (forced virtual-currency transaction)', () => {
1229
+ const def = LAYOUT.records['3051'];
1230
+
1231
+ it('has the asset header, the sequence at 234 and two wallet addresses at 236 and 386', () => {
1232
+ expect(
1233
+ def.fields
1234
+ .filter(f => f.kind !== 'filler')
1235
+ .map(f => [f.key, f.position, f.length, f.kind, f.required]),
1236
+ ).toEqual([
1237
+ ['transactionSymbol', 137, 2, 'const', 'yes'],
1238
+ ['appendixNumber', 139, 3, 'serial', 'yes'],
1239
+ ['assetDetails', 142, 50, 'hebrewText', 'no'],
1240
+ ['assetLocation', 192, 1, 'enum', 'no'],
1241
+ ['relatedParty', 193, 1, 'yesNo', 'no'],
1242
+ ['buyerName', 194, 30, 'hebrewText', 'no'],
1243
+ ['dates.code15', 224, 10, 'date', 'yes'],
1244
+ ['sequenceNumber', 234, 2, 'serial', 'yes'],
1245
+ ['walletAddresses[0]', 236, 150, 'text', 'no'],
1246
+ ['walletAddresses[1]', 386, 150, 'text', 'no'],
1247
+ ]);
1248
+ });
1249
+
1250
+ it('maps the header, walletAddresses[i] to keys walletAddresses[i], with input paths', () => {
1251
+ const [record] = capitalGainsRecords(
1252
+ minimalInput({ capitalGains: [forcedVirtualCurrencyAppendix()] }),
1253
+ );
1254
+ expect(record?.recordType).toBe('3051');
1255
+ expect(record?.values).toEqual({
1256
+ transactionSymbol: 51,
1257
+ appendixNumber: 1,
1258
+ sequenceNumber: 1,
1259
+ assetDetails: 'ביטקוין',
1260
+ assetLocation: 2,
1261
+ relatedParty: false,
1262
+ buyerName: 'בורסת מטבעות',
1263
+ 'dates.code15': '2024-12-31',
1264
+ 'walletAddresses[0]': 'bc1qwalletaddressone',
1265
+ 'walletAddresses[1]': 'bc1qwalletaddresstwo',
1266
+ });
1267
+ expect([...(record?.codes ?? [])]).toEqual([
1268
+ ['015', 80_000],
1269
+ ['016', 30_000],
1270
+ ['071', 1],
1271
+ ]);
1272
+ expect(record?.paths).toEqual({
1273
+ transactionSymbol: '',
1274
+ appendixNumber: '',
1275
+ sequenceNumber: '',
1276
+ assetDetails: 'capitalGains[0].assetDetails',
1277
+ assetLocation: 'capitalGains[0].assetLocation',
1278
+ relatedParty: 'capitalGains[0].relatedParty',
1279
+ buyerName: 'capitalGains[0].buyerName',
1280
+ 'dates.code15': 'capitalGains[0].dates.code15',
1281
+ 'walletAddresses[0]': 'capitalGains[0].walletAddresses[0]',
1282
+ 'walletAddresses[1]': 'capitalGains[0].walletAddresses[1]',
1283
+ 'code:015': 'capitalGains[0].amounts["015"]',
1284
+ 'code:016': 'capitalGains[0].amounts["016"]',
1285
+ 'code:071': 'capitalGains[0].amounts["071"]',
1286
+ });
1287
+ });
1288
+
1289
+ it('sets every non-filler header field of record 3051', () => {
1290
+ const report = reportOf(minimalInput({ capitalGains: [forcedVirtualCurrencyAppendix()] }));
1291
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
1292
+ });
1293
+
1294
+ it('writes the header at its layout positions, the wallet addresses padded to 150', () => {
1295
+ const [line] = linesOfType(
1296
+ minimalInput({ capitalGains: [forcedVirtualCurrencyAppendix()] }),
1297
+ '3051',
1298
+ );
1299
+ expect(at(line, 137, 5)).toBe('51001');
1300
+ expect(at(line, 142, 50)).toBe('ביטקוין'.padStart(50, ' '));
1301
+ expect(at(line, 192, 2)).toBe('22');
1302
+ expect(at(line, 194, 30)).toBe('בורסת מטבעות'.padStart(30, ' '));
1303
+ expect(at(line, 224, 10)).toBe('31/12/2024');
1304
+ expect(at(line, 234, 2)).toBe('01');
1305
+ expect(at(line, 236, 150)).toBe('bc1qwalletaddressone'.padStart(150, ' '));
1306
+ expect(at(line, 386, 150)).toBe('bc1qwalletaddresstwo'.padStart(150, ' '));
1307
+ expect(at(line, 536, 625)).toMatch(/^0+$/);
1308
+ expect(at(line, 1161, 13 + 13 + 4)).toBe('0150000080000' + '0160000030000' + '0711');
1309
+ });
1310
+
1311
+ it('writes one wallet address in the first slot and leaves the second blank', () => {
1312
+ const [line] = linesOfType(
1313
+ minimalInput({
1314
+ capitalGains: [forcedVirtualCurrencyAppendix({ walletAddresses: ['0xabc'] })],
1315
+ }),
1316
+ '3051',
1317
+ );
1318
+ expect(at(line, 236, 150)).toBe('0xabc'.padStart(150, ' '));
1319
+ expect(at(line, 386, 150)).toBe(' '.repeat(150));
1320
+ });
1321
+
1322
+ it('requires codes 071 and 016 (field.required; 0 counts as absent) and 071 = 1', () => {
1323
+ expect(
1324
+ errorsOf(
1325
+ minimalInput({
1326
+ capitalGains: [
1327
+ sharesAppendix(),
1328
+ forcedVirtualCurrencyAppendix({ amounts: { '071': undefined, '016': 0 } }),
1329
+ ],
1330
+ }),
1331
+ ),
1332
+ ).toEqual([
1333
+ ['field.required', 'capitalGains[1].amounts["016"]', '3051'],
1334
+ ['field.required', 'capitalGains[1].amounts["071"]', '3051'],
1335
+ ]);
1336
+ expect(
1337
+ errorsOf(
1338
+ minimalInput({ capitalGains: [forcedVirtualCurrencyAppendix({ amounts: { '071': 2 } })] }),
1339
+ ),
1340
+ ).toEqual([['field.enum', 'capitalGains[0].amounts["071"]', '3051']]);
1341
+ });
1342
+
1343
+ it('reports an absent code-15 date: input.shape for typed input, field.required in the model', () => {
1344
+ const input = {
1345
+ ...minimalInput(),
1346
+ capitalGains: [{ ...forcedVirtualCurrencyAppendix(), dates: {} }],
1347
+ };
1348
+ expect(validate1214(input, OPTIONS).errors.map(issue => [issue.ruleId, issue.path])).toEqual([
1349
+ ['input.shape', 'capitalGains[0].dates.code15'],
1350
+ ]);
1351
+ expect(fieldIssuesOf(input)).toEqual([['field.required', 'capitalGains[0].dates.code15']]);
1352
+ });
1353
+
1354
+ it('reports a wallet address over 150 characters at its slot and a third one as input.shape', () => {
1355
+ expect(
1356
+ errorsOf(
1357
+ minimalInput({
1358
+ capitalGains: [
1359
+ forcedVirtualCurrencyAppendix({ walletAddresses: ['a', 'b'.repeat(151)] }),
1360
+ ],
1361
+ }),
1362
+ ),
1363
+ ).toEqual([['field.length', 'capitalGains[0].walletAddresses[1]', '3051']]);
1364
+ expect(
1365
+ errorsOf(
1366
+ minimalInput({
1367
+ capitalGains: [forcedVirtualCurrencyAppendix({ walletAddresses: ['a'.repeat(150)] })],
1368
+ }),
1369
+ ),
1370
+ ).toEqual([]);
1371
+ const input = {
1372
+ ...minimalInput(),
1373
+ capitalGains: [{ ...forcedVirtualCurrencyAppendix(), walletAddresses: ['a', 'b', 'c'] }],
1374
+ };
1375
+ expect(validate1214(input, OPTIONS).errors).toEqual([
1376
+ expect.objectContaining({ ruleId: 'input.shape', path: 'capitalGains[0].walletAddresses' }),
1377
+ ]);
1378
+ });
1379
+
1380
+ it('reports a buyer name that does not start with a Hebrew letter (kind hebrewText)', () => {
1381
+ expect(
1382
+ errorsOf(
1383
+ minimalInput({ capitalGains: [forcedVirtualCurrencyAppendix({ buyerName: 'Exchange' })] }),
1384
+ ),
1385
+ ).toEqual([['field.hebrewFirstLetter', 'capitalGains[0].buyerName', '3051']]);
1386
+ });
1387
+ });
1388
+
1389
+ describe('the "מספר בתל"ם" sequence with asset appendices (SPEC §7.4, §15 A-7)', () => {
1390
+ // Input order 51, 63, 27, 65, 50, 54, 27: emitted 3027, 3027, 3050, 3051, 3054, 3063, 3065.
1391
+ const appendices = [
1392
+ forcedVirtualCurrencyAppendix(),
1393
+ section6Appendix(),
1394
+ sharesAppendix(),
1395
+ noWithholding1322Appendix(),
1396
+ bettermentTaxAppendix(),
1397
+ oilPartnershipAppendix(),
1398
+ sharesAppendix({ assetLocation: 'israel' }),
1399
+ ];
1400
+ const input = minimalInput({ capitalGains: appendices });
1401
+
1402
+ it('numbers 3027, 3051 and 3065 by their emission position among all appendices', () => {
1403
+ expect(
1404
+ capitalGainsRecords(input).map(r => [
1405
+ r.recordType,
1406
+ r.inputIndex,
1407
+ r.values.appendixNumber,
1408
+ r.values.sequenceNumber,
1409
+ ]),
1410
+ ).toEqual([
1411
+ ['3027', 2, 1, 1],
1412
+ ['3027', 6, 2, 2],
1413
+ ['3050', 4, 1, undefined],
1414
+ ['3051', 0, 1, 4],
1415
+ ['3054', 5, 1, undefined],
1416
+ ['3063', 1, 1, undefined],
1417
+ ['3065', 3, 1, 7],
1418
+ ]);
1419
+ });
1420
+
1421
+ it('writes the sequences at 3027@255, 3051@234 and 3065@325', () => {
1422
+ const lines = linesOf(input);
1423
+ expect(lines.map(line => line.slice(4, 8))).toEqual([
1424
+ '1000',
1425
+ '1020',
1426
+ '3027',
1427
+ '3027',
1428
+ '3050',
1429
+ '3051',
1430
+ '3054',
1431
+ '3063',
1432
+ '3065',
1433
+ '9999',
1434
+ ]);
1435
+ expect([at(lines[2], 255, 2), at(lines[3], 255, 2)]).toEqual(['01', '02']);
1436
+ expect(at(lines[5], 234, 2)).toBe('04');
1437
+ expect(at(lines[8], 325, 2)).toBe('07');
1438
+ expect(at(lines.at(-1), 145, 2)).toBe('07');
1439
+ });
1440
+
1441
+ it('generates the seven records and parses them back in file order', () => {
1442
+ expect(validate1214(input, OPTIONS)).toEqual({ valid: true, errors: [], warnings: [] });
1443
+ const parsed = parse1214(generate1214(input, OPTIONS).text);
1444
+ expect(parsed.issues).toEqual([]);
1445
+ expect(parsed.report.capitalGains).toEqual([
1446
+ appendices[2],
1447
+ appendices[6],
1448
+ appendices[4],
1449
+ appendices[0],
1450
+ appendices[5],
1451
+ appendices[1],
1452
+ appendices[3],
1453
+ ]);
1454
+ });
1455
+ });
1456
+
1457
+ describe('normalizeReport: record 3077 (other transactions)', () => {
1458
+ const def = LAYOUT.records['3077'];
1459
+
1460
+ it('has the asset header, five improvement slots, a replacement asset, the sequence and two wallets', () => {
1461
+ expect(
1462
+ def.fields
1463
+ .filter(f => f.kind !== 'filler')
1464
+ .map(f => [f.key, f.position, f.length, f.kind, f.required]),
1465
+ ).toEqual([
1466
+ ['transactionSymbol', 137, 2, 'const', 'yes'],
1467
+ ['appendixNumber', 139, 3, 'serial', 'yes'],
1468
+ ['expropriation', 142, 1, 'yesNo', 'no'],
1469
+ ['assetDetails', 143, 50, 'text', 'no'],
1470
+ ['assetLocation', 193, 1, 'enum', 'no'],
1471
+ ['relatedParty', 194, 1, 'yesNo', 'no'],
1472
+ ['buyerName', 195, 30, 'text', 'no'],
1473
+ ['dates.code15', 225, 10, 'date', 'yes'],
1474
+ ['dates.code20', 235, 10, 'date', 'yes'],
1475
+ ['improvementCount', 245, 2, 'count', 'no'],
1476
+ ...[0, 1, 2, 3, 4].flatMap(slot => [
1477
+ [`improvements[${slot}].expense`, 247 + 34 * slot, 12, 'amountX100', 'no'],
1478
+ [`improvements[${slot}].accumulatedDepreciation`, 259 + 34 * slot, 12, 'amountX100', 'no'],
1479
+ [`improvements[${slot}].date`, 271 + 34 * slot, 10, 'date', 'yes'],
1480
+ ]),
1481
+ ['replacementAsset.details', 417, 50, 'text', 'no'],
1482
+ ['replacementAsset.purchaseDate', 467, 10, 'date', 'no'],
1483
+ ['replacementAsset.price', 477, 10, 'amount', 'no'],
1484
+ ['sequenceNumber', 487, 2, 'serial', 'yes'],
1485
+ ['walletAddresses[0]', 489, 150, 'text', 'no'],
1486
+ ['walletAddresses[1]', 639, 150, 'text', 'no'],
1487
+ ]);
1488
+ expect(def.codes.filter(code => code.derived).map(code => code.code)).toEqual([
1489
+ '501',
1490
+ '502',
1491
+ '503',
1492
+ '504',
1493
+ '505',
1494
+ ]);
1495
+ });
1496
+
1497
+ it('maps improvements[i] to keys improvements[i].*, code50Amount to code 50(i+1), 245 to the count', () => {
1498
+ const [section6, other] = capitalGainsRecords(
1499
+ minimalInput({ capitalGains: [section6Appendix(), otherTransactionsAppendix()] }),
1500
+ );
1501
+ expect(section6?.recordType).toBe('3063');
1502
+ expect(other?.recordType).toBe('3077');
1503
+ expect(other?.values).toEqual({
1504
+ transactionSymbol: 77,
1505
+ appendixNumber: 1,
1506
+ sequenceNumber: 2,
1507
+ expropriation: false,
1508
+ assetDetails: 'מבנה תעשייה',
1509
+ assetLocation: 2,
1510
+ relatedParty: true,
1511
+ buyerName: 'רוכש נכסים בע"מ',
1512
+ 'dates.code15': '2024-07-01',
1513
+ 'dates.code20': '2009-02-01',
1514
+ improvementCount: 2,
1515
+ 'improvements[0].expense': 10_000.25,
1516
+ 'improvements[0].accumulatedDepreciation': 1000,
1517
+ 'improvements[0].date': '2010-01-15',
1518
+ 'improvements[1].expense': 20_000.25,
1519
+ 'improvements[1].accumulatedDepreciation': 2000,
1520
+ 'improvements[1].date': '2011-02-15',
1521
+ 'replacementAsset.details': 'מבנה חלופי',
1522
+ 'replacementAsset.purchaseDate': '2024-09-01',
1523
+ 'replacementAsset.price': 2_000_000,
1524
+ 'walletAddresses[0]': 'bc1qotherwalletone',
1525
+ });
1526
+ expect([...(other?.codes ?? [])]).toEqual([
1527
+ ['015', 3_000_000],
1528
+ ['020', 1_500_000.5],
1529
+ ['071', 1],
1530
+ ['501', 9000.5],
1531
+ ['502', 18_000.5],
1532
+ ]);
1533
+ expect(other?.paths).toEqual({
1534
+ transactionSymbol: '',
1535
+ appendixNumber: '',
1536
+ sequenceNumber: '',
1537
+ improvementCount: '',
1538
+ expropriation: 'capitalGains[1].expropriation',
1539
+ assetDetails: 'capitalGains[1].assetDetails',
1540
+ assetLocation: 'capitalGains[1].assetLocation',
1541
+ relatedParty: 'capitalGains[1].relatedParty',
1542
+ buyerName: 'capitalGains[1].buyerName',
1543
+ 'dates.code15': 'capitalGains[1].dates.code15',
1544
+ 'dates.code20': 'capitalGains[1].dates.code20',
1545
+ 'improvements[0].expense': 'capitalGains[1].improvements[0].expense',
1546
+ 'improvements[0].accumulatedDepreciation':
1547
+ 'capitalGains[1].improvements[0].accumulatedDepreciation',
1548
+ 'improvements[0].date': 'capitalGains[1].improvements[0].date',
1549
+ 'improvements[1].expense': 'capitalGains[1].improvements[1].expense',
1550
+ 'improvements[1].accumulatedDepreciation':
1551
+ 'capitalGains[1].improvements[1].accumulatedDepreciation',
1552
+ 'improvements[1].date': 'capitalGains[1].improvements[1].date',
1553
+ 'replacementAsset.details': 'capitalGains[1].replacementAsset.details',
1554
+ 'replacementAsset.purchaseDate': 'capitalGains[1].replacementAsset.purchaseDate',
1555
+ 'replacementAsset.price': 'capitalGains[1].replacementAsset.price',
1556
+ 'walletAddresses[0]': 'capitalGains[1].walletAddresses[0]',
1557
+ 'code:015': 'capitalGains[1].amounts["015"]',
1558
+ 'code:020': 'capitalGains[1].amounts["020"]',
1559
+ 'code:071': 'capitalGains[1].amounts["071"]',
1560
+ 'code:501': 'capitalGains[1].improvements[0].code50Amount',
1561
+ 'code:502': 'capitalGains[1].improvements[1].code50Amount',
1562
+ });
1563
+ });
1564
+
1565
+ it('sets every non-filler header field of record 3077 with five improvements and two wallets', () => {
1566
+ const report = reportOf(
1567
+ minimalInput({
1568
+ capitalGains: [
1569
+ otherTransactionsAppendix({
1570
+ improvements: improvements(5),
1571
+ walletAddresses: ['0x1', '0x2'],
1572
+ }),
1573
+ ],
1574
+ }),
1575
+ );
1576
+ expect(unmappedHeaderKeys(def, report.records)).toEqual([]);
1577
+ });
1578
+
1579
+ it('writes the header at its layout positions: ×100 improvement amounts, dates DD/MM/YYYY', () => {
1580
+ const [line] = linesOfType(
1581
+ minimalInput({
1582
+ capitalGains: [
1583
+ otherTransactionsAppendix({
1584
+ improvements: improvements(5),
1585
+ walletAddresses: ['0x1', '0x2'],
1586
+ }),
1587
+ ],
1588
+ }),
1589
+ '3077',
1590
+ );
1591
+ expect(at(line, 137, 5)).toBe('77001');
1592
+ expect(at(line, 142, 1)).toBe('2');
1593
+ expect(at(line, 143, 50)).toBe('מבנה תעשייה'.padStart(50, ' '));
1594
+ expect(at(line, 193, 2)).toBe('21');
1595
+ expect(at(line, 195, 30)).toBe('רוכש נכסים בע"מ'.padStart(30, ' '));
1596
+ expect(at(line, 225, 10)).toBe('01/07/2024');
1597
+ expect(at(line, 235, 10)).toBe('01/02/2009');
1598
+ expect(at(line, 245, 2)).toBe('05');
1599
+ expect(at(line, 247, 12)).toBe('000001000025');
1600
+ expect(at(line, 259, 12)).toBe('000000100000');
1601
+ expect(at(line, 271, 10)).toBe('15/01/2010');
1602
+ expect(at(line, 383, 12)).toBe('000005000025');
1603
+ expect(at(line, 395, 12)).toBe('000000500000');
1604
+ expect(at(line, 407, 10)).toBe('15/05/2014');
1605
+ expect(at(line, 417, 50)).toBe('מבנה חלופי'.padStart(50, ' '));
1606
+ expect(at(line, 467, 10)).toBe('01/09/2024');
1607
+ expect(at(line, 477, 10)).toBe('0002000000');
1608
+ expect(at(line, 487, 2)).toBe('01');
1609
+ expect(at(line, 489, 150)).toBe('0x1'.padStart(150, ' '));
1610
+ expect(at(line, 639, 150)).toBe('0x2'.padStart(150, ' '));
1611
+ expect(at(line, 789, 372)).toMatch(/^0+$/);
1612
+ });
1613
+
1614
+ it('writes codes 501–505 ×100 after the input codes, in ascending code order', () => {
1615
+ const [line] = linesOfType(
1616
+ minimalInput({
1617
+ capitalGains: [
1618
+ otherTransactionsAppendix({ improvements: improvements(5), amounts: { '092': 1 } }),
1619
+ ],
1620
+ }),
1621
+ '3077',
1622
+ );
1623
+ expect(at(line, 1161, 13 + 15 + 4 + 4 + 5 * 15)).toBe(
1624
+ '0150003000000' +
1625
+ '020000150000050' +
1626
+ '0711' +
1627
+ '0921' +
1628
+ '501000000900050' +
1629
+ '502000001800050' +
1630
+ '503000002700050' +
1631
+ '504000003600050' +
1632
+ '505000004500050',
1633
+ );
1634
+ });
1635
+
1636
+ it('writes 245 = 00 and blank slots without improvements, and reads none back', () => {
1637
+ const appendix = otherTransactionsAppendix({ improvements: undefined });
1638
+ const input = minimalInput({ capitalGains: [appendix] });
1639
+ const [record] = capitalGainsRecords(input);
1640
+ expect(record?.values).not.toHaveProperty('improvementCount');
1641
+ const [line] = linesOfType(input, '3077');
1642
+ expect(at(line, 245, 2)).toBe('00');
1643
+ expect(at(line, 247, 24)).toMatch(/^0+$/);
1644
+ expect(at(line, 271, 10)).toBe(' '.repeat(10));
1645
+ const parsed = parse1214(generate1214(input, OPTIONS).text);
1646
+ expect(parsed.issues).toEqual([]);
1647
+ expect(parsed.report.capitalGains?.[0]).not.toHaveProperty('improvements');
1648
+ });
1649
+
1650
+ it('raises no field.required for the empty slots 2–5 of a 3077 with one improvement', () => {
1651
+ const input = minimalInput({
1652
+ capitalGains: [otherTransactionsAppendix({ improvements: improvements(1) })],
1653
+ });
1654
+ expect(validate1214(input, OPTIONS)).toEqual({ valid: true, errors: [], warnings: [] });
1655
+ });
1656
+
1657
+ it('raises cg.improvements.max as a notice for a sixth improvement and writes the first five', () => {
1658
+ const input = minimalInput({
1659
+ capitalGains: [
1660
+ section6Appendix(),
1661
+ otherTransactionsAppendix({ improvements: improvements(6) }),
1662
+ ],
1663
+ });
1664
+ const report = reportOf(input);
1665
+ expect(report.notices).toEqual([
1666
+ expect.objectContaining({
1667
+ ruleId: 'cg.improvements.max',
1668
+ severity: 'error',
1669
+ path: 'capitalGains[1].improvements[5]',
1670
+ recordType: '3077',
1671
+ recordIndex: 0,
1672
+ }),
1673
+ ]);
1674
+ const record = report.records.find(r => r.recordType === '3077');
1675
+ expect(record?.values['improvements[4].date']).toBe('2014-05-15');
1676
+ expect(
1677
+ Object.keys(record?.values ?? {}).filter(key => key.startsWith('improvements[5]')),
1678
+ ).toEqual([]);
1679
+ expect([...(record?.codes.keys() ?? [])].filter(code => code.startsWith('50'))).toEqual([
1680
+ '501',
1681
+ '502',
1682
+ '503',
1683
+ '504',
1684
+ '505',
1685
+ ]);
1686
+ expect(errorsOf(input)).toEqual([
1687
+ ['cg.improvements.max', 'capitalGains[1].improvements[5]', '3077'],
1688
+ ]);
1689
+ });
1690
+
1691
+ it('accepts only 1 in code 092 (SPEC §15 A-11, A-31: shopcn rejected 2)', () => {
1692
+ expect(
1693
+ errorsOf(
1694
+ minimalInput({ capitalGains: [otherTransactionsAppendix({ amounts: { '092': 1 } })] }),
1695
+ ),
1696
+ ).toEqual([]);
1697
+ for (const value of [2, 9]) {
1698
+ expect(
1699
+ errorsOf(
1700
+ minimalInput({
1701
+ capitalGains: [otherTransactionsAppendix({ amounts: { '092': value } })],
1702
+ }),
1703
+ ),
1704
+ ).toEqual([['field.enum', 'capitalGains[0].amounts["092"]', '3077']]);
1705
+ }
1706
+ });
1707
+
1708
+ it('requires dates.code15 and dates.code20: input.shape for typed input, field.required in the model', () => {
1709
+ const input = {
1710
+ ...minimalInput(),
1711
+ capitalGains: [{ ...otherTransactionsAppendix(), dates: {} }],
1712
+ };
1713
+ expect(validate1214(input, OPTIONS).errors.map(issue => [issue.ruleId, issue.path])).toEqual([
1714
+ ['input.shape', 'capitalGains[0].dates.code15'],
1715
+ ['input.shape', 'capitalGains[0].dates.code20'],
1716
+ ]);
1717
+ expect(fieldIssuesOf(input)).toEqual([
1718
+ ['field.required', 'capitalGains[0].dates.code15'],
1719
+ ['field.required', 'capitalGains[0].dates.code20'],
1720
+ ]);
1721
+ });
1722
+
1723
+ it('reports an improvement without a date: input.shape for typed input, field.required in the model', () => {
1724
+ const { date: _date, ...undated } = improvements(2)[1]!;
1725
+ const input = {
1726
+ ...minimalInput(),
1727
+ capitalGains: [
1728
+ { ...otherTransactionsAppendix(), improvements: [improvements(1)[0], undated] },
1729
+ ],
1730
+ };
1731
+ expect(validate1214(input, OPTIONS).errors.map(issue => [issue.ruleId, issue.path])).toEqual([
1732
+ ['input.shape', 'capitalGains[0].improvements[1].date'],
1733
+ ]);
1734
+ expect(fieldIssuesOf(input)).toEqual([
1735
+ ['field.required', 'capitalGains[0].improvements[1].date'],
1736
+ ]);
1737
+ });
1738
+
1739
+ it('reports a problem of an improvement or of its code-50 amount at the improvement', () => {
1740
+ expect(
1741
+ errorsOf(
1742
+ minimalInput({
1743
+ capitalGains: [
1744
+ otherTransactionsAppendix({
1745
+ improvements: [
1746
+ improvements(1)[0]!,
1747
+ { expense: 1.234, date: '2020-02-30', code50Amount: -1 },
1748
+ ],
1749
+ }),
1750
+ ],
1751
+ }),
1752
+ ),
1753
+ ).toEqual([
1754
+ ['field.decimals', 'capitalGains[0].improvements[1].expense', '3077'],
1755
+ ['field.date', 'capitalGains[0].improvements[1].date', '3077'],
1756
+ ['field.negative', 'capitalGains[0].improvements[1].code50Amount', '3077'],
1757
+ ]);
1758
+ });
1759
+
1760
+ it('reports a derived code 501–505 in amounts as input.derivedCode naming the improvement', () => {
1761
+ const input = {
1762
+ ...minimalInput(),
1763
+ capitalGains: [
1764
+ section6Appendix(),
1765
+ { ...otherTransactionsAppendix(), amounts: { '015': 1, '501': 5, '505': 6 } },
1766
+ ],
1767
+ };
1768
+ const { errors } = validate1214(input, OPTIONS);
1769
+ expect(errors.map(issue => [issue.ruleId, issue.path, issue.recordType])).toEqual([
1770
+ ['input.derivedCode', 'capitalGains[1].amounts["501"]', '3077'],
1771
+ ['input.derivedCode', 'capitalGains[1].amounts["505"]', '3077'],
1772
+ ]);
1773
+ expect(errors[0]?.message).toContain('capitalGains[1].improvements[0].code50Amount');
1774
+ expect(errors[1]?.message).toContain('capitalGains[1].improvements[4].code50Amount');
1775
+ });
1776
+
1777
+ it('reports a wallet address over 150 characters at its slot and a third one as input.shape', () => {
1778
+ expect(
1779
+ errorsOf(
1780
+ minimalInput({
1781
+ capitalGains: [otherTransactionsAppendix({ walletAddresses: ['a', 'b'.repeat(151)] })],
1782
+ }),
1783
+ ),
1784
+ ).toEqual([['field.length', 'capitalGains[0].walletAddresses[1]', '3077']]);
1785
+ const input = {
1786
+ ...minimalInput(),
1787
+ capitalGains: [{ ...otherTransactionsAppendix(), walletAddresses: ['a', 'b', 'c'] }],
1788
+ };
1789
+ expect(validate1214(input, OPTIONS).errors).toEqual([
1790
+ expect.objectContaining({ ruleId: 'input.shape', path: 'capitalGains[0].walletAddresses' }),
1791
+ ]);
1792
+ });
1793
+
1794
+ it('generates a 3077 with every member and parses it back', () => {
1795
+ const appendix = otherTransactionsAppendix({
1796
+ improvements: improvements(5),
1797
+ walletAddresses: ['0x1', '0x2'],
1798
+ amounts: { '092': 1 },
1799
+ });
1800
+ const input = minimalInput({ capitalGains: [appendix] });
1801
+ expect(validate1214(input, OPTIONS)).toEqual({ valid: true, errors: [], warnings: [] });
1802
+ const parsed = parse1214(generate1214(input, OPTIONS).text);
1803
+ expect(parsed.issues).toEqual([]);
1804
+ expect(parsed.report.capitalGains).toEqual([appendix]);
1805
+ });
1806
+ });
1807
+
1808
+ describe('the "מספר בתל"ם" sequence with a 3077 appendix (SPEC §7.4, §15 A-7)', () => {
1809
+ // Input order 77, 27, 66, 77: emitted 3027, 3066, 3077, 3077.
1810
+ const appendices = [
1811
+ otherTransactionsAppendix(),
1812
+ sharesAppendix(),
1813
+ noWithholding1326Appendix(),
1814
+ otherTransactionsAppendix({ assetLocation: 'abroad', improvements: improvements(1) }),
1815
+ ];
1816
+ const input = minimalInput({ capitalGains: appendices });
1817
+
1818
+ it('numbers the 3077 appendices per symbol and writes their sequence at 487', () => {
1819
+ expect(
1820
+ capitalGainsRecords(input).map(r => [
1821
+ r.recordType,
1822
+ r.inputIndex,
1823
+ r.values.appendixNumber,
1824
+ r.values.sequenceNumber,
1825
+ ]),
1826
+ ).toEqual([
1827
+ ['3027', 1, 1, 1],
1828
+ ['3066', 2, 1, 2],
1829
+ ['3077', 0, 1, 3],
1830
+ ['3077', 3, 2, 4],
1831
+ ]);
1832
+ const lines = linesOfType(input, '3077');
1833
+ expect(lines.map(line => [at(line, 137, 5), at(line, 487, 2)])).toEqual([
1834
+ ['77001', '03'],
1835
+ ['77002', '04'],
1836
+ ]);
1837
+ });
1838
+
1839
+ it('generates the four records and parses them back in file order', () => {
1840
+ expect(validate1214(input, OPTIONS)).toEqual({ valid: true, errors: [], warnings: [] });
1841
+ const parsed = parse1214(generate1214(input, OPTIONS).text);
1842
+ expect(parsed.issues).toEqual([]);
1843
+ expect(parsed.report.capitalGains).toEqual([
1844
+ appendices[1],
1845
+ appendices[2],
1846
+ appendices[0],
1847
+ appendices[3],
1848
+ ]);
1849
+ });
1850
+ });