@seidor-cloud-produtos/tax-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+
2
+ root = true
3
+
4
+ [{src,scripts}/**.{ts,json,js}]
5
+ end_of_line = crlf
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ indent_style = space
10
+ indent_size = 4
Binary file
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Seidor Tax Core
2
+
3
+ Nesta biblioteca deve conter ferramentas que auxiliem o desenvolvedor na tarefa de construir e gerar um layout de arquivo fiscal.
4
+
5
+ * Um arquivo fiscal é baseado um layout específico (versão) e organizado em blocos.
6
+ * Cada bloco é constituído de registros. Cada registros pode conter 0 ou N outros registros filhos
7
+ * Cada registro é composto por um sequência exata de campos.
8
+ * Cada campo tem suas características e formato (númerico, alfanumérico, valor monetário, data)
9
+ * Cada característica pode ser um tipo que conterá as características + formato
10
+
11
+ Temos 2 momentos diferentes na geração de um arquivo.
12
+
13
+ * Construção da definição de como os dados deve ser organizados e gerados no arquivo
14
+ * Inserção de dados propriamente dita
15
+
16
+ ## Como foi construída a solução
17
+
18
+ ![Macro view diagram](.github/macro-view.png)
@@ -0,0 +1,45 @@
1
+ import {Register} from "../../lib/taxReport/Register";
2
+ import Block from "../../lib/taxReport/Block";
3
+ import RegisterPersist from "../../lib/taxReport/interfaces/RegisterPersist";
4
+ import {Decimal} from "../../lib/taxReport/Decorators";
5
+ import RegisterEventNotifier, {RegisterEventData} from "../../lib/taxReport/interfaces/RegisterEventNotifier";
6
+
7
+ export class C100 extends Register {
8
+
9
+ // @ts-ignore
10
+ // @Alphanumeric(1)
11
+ indOper: string = "";
12
+
13
+ // @ts-ignore
14
+ // @Alphanumeric(1)
15
+ ser: string = "";
16
+ numDoc: number = 0;
17
+
18
+ // @ts-ignore
19
+ @Decimal()
20
+ vlDoc: number = 0.0;
21
+
22
+ get total(): number {
23
+ return this.vlDoc
24
+ }
25
+
26
+ constructor(notifier: RegisterEventNotifier) {
27
+ super("C100", notifier);
28
+ }
29
+ }
30
+
31
+ export default class BlockC extends Block {
32
+
33
+ constructor(regPersist: RegisterPersist) {
34
+ super("C", regPersist);
35
+ }
36
+
37
+ eventHandler(eventData:RegisterEventData) {
38
+ // throw new Error("Method not implemented.");
39
+ }
40
+
41
+ createC100() : C100 {
42
+ return new C100(this);
43
+ }
44
+ }
45
+
@@ -0,0 +1,41 @@
1
+ import Block from "../../lib/taxReport/Block";
2
+ import {Register} from "../../lib/taxReport/Register";
3
+ import {Decimal} from "../../lib/taxReport/Decorators";
4
+ import RegisterPersist from "../../lib/taxReport/interfaces/RegisterPersist";
5
+ import {RegisterEventData} from "../../lib/taxReport/interfaces/RegisterEventNotifier";
6
+ import {C100} from "./blockC";
7
+
8
+ class M100 extends Register {
9
+ // @ts-ignore
10
+ @Decimal(15,2)
11
+ vl_bc_cont: number = 0;
12
+ }
13
+
14
+ export default class BlockM extends Block {
15
+
16
+ constructor(regPersist: RegisterPersist) {
17
+ super("M", regPersist);
18
+ }
19
+ eventHandler(eventData: RegisterEventData): void {
20
+ switch (eventData.dataTypeName) {
21
+ case 'C100':
22
+ this.sumC100(eventData.data as C100);
23
+ break;
24
+ }
25
+ }
26
+
27
+ private sumC100(data: C100) {
28
+ let m100: M100;
29
+
30
+ if (!this.registersPersist.has("M100")) {
31
+ m100 = new M100("M100", this);
32
+ m100.vl_bc_cont = data.vlDoc
33
+ this.registersPersist.add(m100)
34
+ } else {
35
+ const registers = this.registersPersist.get("M100") as Register[]
36
+ m100 = registers[0] as M100
37
+ m100.vl_bc_cont += data.vlDoc
38
+ }
39
+ }
40
+
41
+ }
@@ -0,0 +1,59 @@
1
+ import BlockC from "./blockC";
2
+ import TaxReport from "../../lib/taxReport/TaxReport";
3
+ import MemoryPersist from "../../lib/taxReport/implementations/MemoryPersist";
4
+ import BlockM from "./blockM";
5
+ import {Register} from "../../lib/taxReport/Register";
6
+
7
+ class OpenFile extends Register {
8
+
9
+ }
10
+
11
+ export interface DFe {
12
+ operation: string;
13
+ series: string;
14
+ documentNumber: number;
15
+ totalAmount: number;
16
+ }
17
+
18
+ export default class EFDContribuicoes extends TaxReport {
19
+
20
+ constructor() {
21
+ super();
22
+ this.registerBlock(new BlockC(MemoryPersist.createInstance()))
23
+ this.registerBlock(new BlockM(MemoryPersist.createInstance()))
24
+
25
+ //Relationships
26
+ this.BlockC.addSubscriber(this.BlockM);
27
+ }
28
+
29
+ public createOpenFile(): OpenFile {
30
+ //Qualquer bloco só para funcionar!
31
+ return new OpenFile("0000", this.BlockC)
32
+ }
33
+
34
+ protected get BlockC(): BlockC {
35
+ return this.getBlock("C") as BlockC
36
+ }
37
+
38
+ protected get BlockM(): BlockC {
39
+ return this.getBlock("M") as BlockC
40
+ }
41
+
42
+ public addDFe(instance: DFe) {
43
+
44
+ //Precisamos validar se este DFe precisa ir pro arquivo!
45
+
46
+
47
+ const item = this.BlockC.createC100();
48
+ item.ser = instance.series;
49
+ item.numDoc = instance.documentNumber
50
+ item.vlDoc = instance.totalAmount;
51
+ switch (instance.operation){
52
+ case "inbound":
53
+ item.indOper = "1";
54
+ break;
55
+ }
56
+
57
+ this.BlockC.addRegister(item);
58
+ }
59
+ }
@@ -0,0 +1,21 @@
1
+ import ReportGenerator from "../../lib/taxReport/ReportGenerator";
2
+ import EFDContribuicoes, { DFe } from "./efdContribuicoes";
3
+ import { Register } from "../../lib/taxReport/Register";
4
+
5
+ console.time("test")
6
+ const fileData = new EFDContribuicoes();
7
+
8
+ //Database simulating
9
+ for (let i = 1; i <= 10; i++) {
10
+ const newDfe: DFe = {
11
+ operation: "inbound",
12
+ series: "A",
13
+ documentNumber: i,
14
+ totalAmount: parseFloat((Math.random() * 100).toFixed(2)),
15
+ }
16
+ fileData.addDFe(newDfe);
17
+ }
18
+
19
+ const generator = ReportGenerator.newWithDefaultOptions(fileData.createOpenFile())
20
+ generator.generateFile(fileData)
21
+ console.timeEnd("test")
@@ -0,0 +1,17 @@
1
+ tools: Classes {
2
+ taxr: Tax Report
3
+ blk: Block
4
+ reg: Register
5
+ fld: Field
6
+ dec: Decorator
7
+
8
+ taxr -> blk: Pode possuir N blocos
9
+ blk -> reg: Pode possuir N registros
10
+ reg -> fld: Pode possuir N campos
11
+ fld -> dec: 1 decorator - define as características do campo
12
+ }
13
+ gen: Report Generator
14
+ out: Report Output
15
+
16
+ gen -> tools.taxr: Usa o TaxReport
17
+ gen -> out: Gera o resultado do arquivo
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@seidor-cloud-produtos/tax-core",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "compile": "npx tsc",
8
+ "test": "node --import tsx --test test/**/*.test.ts",
9
+ "test:w": "node --import tsx --watch --test test/**/*.test.ts"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "devDependencies": {
15
+ "@types/node": "^20.12.7",
16
+ "ts-node": "^10.9.2",
17
+ "tsx": "^4.8.2",
18
+ "typescript": "^5.4.5"
19
+ },
20
+ "dependencies": {
21
+ "body-parser": "^1.20.2",
22
+ "reflect-metadata": "^0.2.2"
23
+ }
24
+ }