makeapps-transformer 1.0.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 (174) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/dist/index.d.ts +7 -0
  3. package/dist/index.js +4 -0
  4. package/dist/lib-public/FA3-generator.js +50 -0
  5. package/dist/lib-public/enums/invoice.enums.js +9 -0
  6. package/dist/lib-public/generate-invoice.js +21 -0
  7. package/dist/lib-public/generators/FA2/Adnotacje.js +174 -0
  8. package/dist/lib-public/generators/FA2/Adres.js +23 -0
  9. package/dist/lib-public/generators/FA2/DodatkoweInformacje.js +69 -0
  10. package/dist/lib-public/generators/FA2/Platnosc.js +91 -0
  11. package/dist/lib-public/generators/FA2/Podmiot1.js +32 -0
  12. package/dist/lib-public/generators/FA2/Podmiot1Podmiot1K.js +63 -0
  13. package/dist/lib-public/generators/FA2/Podmiot2.js +28 -0
  14. package/dist/lib-public/generators/FA2/Podmiot2Podmiot2k.js +62 -0
  15. package/dist/lib-public/generators/FA2/Podmiot3.js +37 -0
  16. package/dist/lib-public/generators/FA2/Podmiot3Podmiot2k.js +57 -0
  17. package/dist/lib-public/generators/FA2/PodmiotAdres.js +14 -0
  18. package/dist/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot1Dto.js +10 -0
  19. package/dist/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot2Dto.js +34 -0
  20. package/dist/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot3Dto.js +44 -0
  21. package/dist/lib-public/generators/FA2/PodmiotDaneKontaktowe.js +13 -0
  22. package/dist/lib-public/generators/FA2/PodmiotUpowazniony.js +29 -0
  23. package/dist/lib-public/generators/FA2/PodmiotUpowaznionyDaneKontaktowe.js +28 -0
  24. package/dist/lib-public/generators/FA2/Podmioty.js +92 -0
  25. package/dist/lib-public/generators/FA2/PodsumowanieStawekPodatkuVat.js +260 -0
  26. package/dist/lib-public/generators/FA2/Przewoznik.js +17 -0
  27. package/dist/lib-public/generators/FA2/Rabat.js +57 -0
  28. package/dist/lib-public/generators/FA2/RachunekBankowy.js +54 -0
  29. package/dist/lib-public/generators/FA2/Szczegoly.js +138 -0
  30. package/dist/lib-public/generators/FA2/Transport.js +78 -0
  31. package/dist/lib-public/generators/FA2/WarunkiTransakcji.js +68 -0
  32. package/dist/lib-public/generators/FA2/Wiersze.js +140 -0
  33. package/dist/lib-public/generators/FA2/Zamowienie.js +148 -0
  34. package/dist/lib-public/generators/FA3/Adnotacje.js +185 -0
  35. package/dist/lib-public/generators/FA3/Adres.js +23 -0
  36. package/dist/lib-public/generators/FA3/DodatkoweInformacje.js +69 -0
  37. package/dist/lib-public/generators/FA3/Platnosc.js +105 -0
  38. package/dist/lib-public/generators/FA3/Podmiot1.js +32 -0
  39. package/dist/lib-public/generators/FA3/Podmiot1Podmiot1K.js +67 -0
  40. package/dist/lib-public/generators/FA3/Podmiot2.js +34 -0
  41. package/dist/lib-public/generators/FA3/Podmiot2Podmiot2k.js +49 -0
  42. package/dist/lib-public/generators/FA3/Podmiot3.js +37 -0
  43. package/dist/lib-public/generators/FA3/Podmiot3Podmiot2k.js +57 -0
  44. package/dist/lib-public/generators/FA3/PodmiotAdres.js +14 -0
  45. package/dist/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot1Dto.js +10 -0
  46. package/dist/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot2Dto.js +34 -0
  47. package/dist/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot3Dto.js +44 -0
  48. package/dist/lib-public/generators/FA3/PodmiotDaneKontaktowe.js +13 -0
  49. package/dist/lib-public/generators/FA3/PodmiotUpowazniony.js +29 -0
  50. package/dist/lib-public/generators/FA3/PodmiotUpowaznionyDaneKontaktowe.js +28 -0
  51. package/dist/lib-public/generators/FA3/Podmioty.js +92 -0
  52. package/dist/lib-public/generators/FA3/PodsumowanieStawekPodatkuVat.js +264 -0
  53. package/dist/lib-public/generators/FA3/Przewoznik.js +17 -0
  54. package/dist/lib-public/generators/FA3/Rabat.js +57 -0
  55. package/dist/lib-public/generators/FA3/RachunekBankowy.js +58 -0
  56. package/dist/lib-public/generators/FA3/Szczegoly.js +138 -0
  57. package/dist/lib-public/generators/FA3/Transport.js +78 -0
  58. package/dist/lib-public/generators/FA3/WarunkiTransakcji.js +68 -0
  59. package/dist/lib-public/generators/FA3/Wiersze.js +140 -0
  60. package/dist/lib-public/generators/FA3/Zamowienie.js +148 -0
  61. package/dist/lib-public/generators/common/DaneFaKorygowanej.js +74 -0
  62. package/dist/lib-public/generators/common/Naglowek.js +100 -0
  63. package/dist/lib-public/generators/common/Rozliczenie.js +120 -0
  64. package/dist/lib-public/generators/common/Stopka.js +113 -0
  65. package/dist/lib-public/generators/common/Wiersze.js +28 -0
  66. package/dist/lib-public/generators/common/Zalaczniki.js +182 -0
  67. package/dist/lib-public/index.js +5 -0
  68. package/dist/lib-public/types/common.types.js +2 -0
  69. package/dist/lib-public/types/fa1-additional-types.js +2 -0
  70. package/dist/lib-public/types/fa1.types.js +2 -0
  71. package/dist/lib-public/types/fa2-additional-types.js +2 -0
  72. package/dist/lib-public/types/fa2.types.js +2 -0
  73. package/dist/lib-public/types/fa2Podmiot3DaneIdentyfikacyjne.types.js +2 -0
  74. package/dist/lib-public/types/fa3.types.js +2 -0
  75. package/dist/lib-public/types/fa3Podmiot3DaneIdentyfikacyjne.types.js +2 -0
  76. package/dist/lib-public/types/tax-summary.types.js +2 -0
  77. package/dist/lib-public/types/upo-v4_2.types.js +2 -0
  78. package/dist/shared/PDF-functions.js +429 -0
  79. package/dist/shared/XML-parser.js +21 -0
  80. package/dist/shared/consts/const.js +390 -0
  81. package/dist/shared/enums/common.enum.js +48 -0
  82. package/dist/shared/enums/invoice.enums.js +13 -0
  83. package/dist/shared/generators/common/functions.js +95 -0
  84. package/dist/shared/types/additional-data.types.js +2 -0
  85. package/dist/shared/types/pdf-types.js +2 -0
  86. package/dist/shared/types/universal.types.js +2 -0
  87. package/package.json +21 -0
  88. package/src/index.d.ts +7 -0
  89. package/src/index.ts +2 -0
  90. package/src/lib-public/FA3-generator.ts +56 -0
  91. package/src/lib-public/enums/invoice.enums.ts +5 -0
  92. package/src/lib-public/generate-invoice.ts +32 -0
  93. package/src/lib-public/generators/FA2/Adnotacje.ts +206 -0
  94. package/src/lib-public/generators/FA2/Adres.ts +20 -0
  95. package/src/lib-public/generators/FA2/DodatkoweInformacje.ts +97 -0
  96. package/src/lib-public/generators/FA2/Platnosc.ts +131 -0
  97. package/src/lib-public/generators/FA2/Podmiot1.ts +40 -0
  98. package/src/lib-public/generators/FA2/Podmiot1Podmiot1K.ts +73 -0
  99. package/src/lib-public/generators/FA2/Podmiot2.ts +42 -0
  100. package/src/lib-public/generators/FA2/Podmiot2Podmiot2k.ts +74 -0
  101. package/src/lib-public/generators/FA2/Podmiot3.ts +50 -0
  102. package/src/lib-public/generators/FA2/Podmiot3Podmiot2k.ts +77 -0
  103. package/src/lib-public/generators/FA2/PodmiotAdres.ts +19 -0
  104. package/src/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot1Dto.ts +10 -0
  105. package/src/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot2Dto.ts +37 -0
  106. package/src/lib-public/generators/FA2/PodmiotDaneIdentyfikacyjneTPodmiot3Dto.ts +44 -0
  107. package/src/lib-public/generators/FA2/PodmiotDaneKontaktowe.ts +12 -0
  108. package/src/lib-public/generators/FA2/PodmiotUpowazniony.ts +31 -0
  109. package/src/lib-public/generators/FA2/PodmiotUpowaznionyDaneKontaktowe.ts +34 -0
  110. package/src/lib-public/generators/FA2/Podmioty.ts +96 -0
  111. package/src/lib-public/generators/FA2/PodsumowanieStawekPodatkuVat.ts +294 -0
  112. package/src/lib-public/generators/FA2/Przewoznik.ts +21 -0
  113. package/src/lib-public/generators/FA2/Rabat.ts +47 -0
  114. package/src/lib-public/generators/FA2/RachunekBankowy.ts +60 -0
  115. package/src/lib-public/generators/FA2/Szczegoly.ts +187 -0
  116. package/src/lib-public/generators/FA2/Transport.ts +108 -0
  117. package/src/lib-public/generators/FA2/WarunkiTransakcji.ts +105 -0
  118. package/src/lib-public/generators/FA2/Wiersze.ts +126 -0
  119. package/src/lib-public/generators/FA2/Zamowienie.ts +144 -0
  120. package/src/lib-public/generators/FA3/Adnotacje.ts +249 -0
  121. package/src/lib-public/generators/FA3/Adres.ts +20 -0
  122. package/src/lib-public/generators/FA3/DodatkoweInformacje.ts +92 -0
  123. package/src/lib-public/generators/FA3/Platnosc.ts +144 -0
  124. package/src/lib-public/generators/FA3/Podmiot1.ts +40 -0
  125. package/src/lib-public/generators/FA3/Podmiot1Podmiot1K.ts +78 -0
  126. package/src/lib-public/generators/FA3/Podmiot2.ts +55 -0
  127. package/src/lib-public/generators/FA3/Podmiot2Podmiot2k.ts +59 -0
  128. package/src/lib-public/generators/FA3/Podmiot3.ts +50 -0
  129. package/src/lib-public/generators/FA3/Podmiot3Podmiot2k.ts +78 -0
  130. package/src/lib-public/generators/FA3/PodmiotAdres.ts +19 -0
  131. package/src/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot1Dto.ts +10 -0
  132. package/src/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot2Dto.ts +37 -0
  133. package/src/lib-public/generators/FA3/PodmiotDaneIdentyfikacyjneTPodmiot3Dto.ts +44 -0
  134. package/src/lib-public/generators/FA3/PodmiotDaneKontaktowe.ts +12 -0
  135. package/src/lib-public/generators/FA3/PodmiotUpowazniony.ts +31 -0
  136. package/src/lib-public/generators/FA3/PodmiotUpowaznionyDaneKontaktowe.ts +34 -0
  137. package/src/lib-public/generators/FA3/Podmioty.ts +96 -0
  138. package/src/lib-public/generators/FA3/PodsumowanieStawekPodatkuVat.ts +298 -0
  139. package/src/lib-public/generators/FA3/Przewoznik.ts +24 -0
  140. package/src/lib-public/generators/FA3/Rabat.ts +45 -0
  141. package/src/lib-public/generators/FA3/RachunekBankowy.ts +60 -0
  142. package/src/lib-public/generators/FA3/Szczegoly.ts +184 -0
  143. package/src/lib-public/generators/FA3/Transport.ts +108 -0
  144. package/src/lib-public/generators/FA3/WarunkiTransakcji.ts +100 -0
  145. package/src/lib-public/generators/FA3/Wiersze.ts +126 -0
  146. package/src/lib-public/generators/FA3/Zamowienie.ts +143 -0
  147. package/src/lib-public/generators/common/DaneFaKorygowanej.ts +91 -0
  148. package/src/lib-public/generators/common/Naglowek.ts +84 -0
  149. package/src/lib-public/generators/common/Rozliczenie.ts +119 -0
  150. package/src/lib-public/generators/common/Stopka.ts +161 -0
  151. package/src/lib-public/generators/common/Wiersze.ts +32 -0
  152. package/src/lib-public/generators/common/Zalaczniki.ts +232 -0
  153. package/src/lib-public/index.ts +3 -0
  154. package/src/lib-public/types/common.types.ts +29 -0
  155. package/src/lib-public/types/fa1-additional-types.ts +26 -0
  156. package/src/lib-public/types/fa1.types.ts +299 -0
  157. package/src/lib-public/types/fa2-additional-types.ts +30 -0
  158. package/src/lib-public/types/fa2.types.ts +307 -0
  159. package/src/lib-public/types/fa2Podmiot3DaneIdentyfikacyjne.types.ts +12 -0
  160. package/src/lib-public/types/fa3.types.ts +384 -0
  161. package/src/lib-public/types/fa3Podmiot3DaneIdentyfikacyjne.types.ts +12 -0
  162. package/src/lib-public/types/tax-summary.types.ts +8 -0
  163. package/src/lib-public/types/upo-v4_2.types.ts +68 -0
  164. package/src/shared/PDF-functions.ts +466 -0
  165. package/src/shared/XML-parser.ts +42 -0
  166. package/src/shared/consts/const.ts +406 -0
  167. package/src/shared/enums/common.enum.ts +45 -0
  168. package/src/shared/enums/invoice.enums.ts +9 -0
  169. package/src/shared/generators/common/functions.ts +101 -0
  170. package/src/shared/types/additional-data.types.ts +15 -0
  171. package/src/shared/types/pdf-types.ts +58 -0
  172. package/src/shared/types/universal.types.ts +16 -0
  173. package/transformer.code-workspace +45 -0
  174. package/tsconfig.json +16 -0
@@ -0,0 +1,119 @@
1
+ import { Content, ContentTable } from 'pdfmake/interfaces';
2
+ import {
3
+ createHeader,
4
+ createLabelText,
5
+ createLabelTextArray,
6
+ createSection,
7
+ createSubHeader,
8
+ generateTwoColumns,
9
+ getContentTable,
10
+ getTable,
11
+ } from '../../../shared/PDF-functions';
12
+ import { HeaderDefine } from '../../../shared/types/pdf-types';
13
+ import { Rozliczenie as Rozliczenie1, Zenia } from '../../types/fa1.types';
14
+ import { Rozliczenie as Rozliczenie2, Rozliczenie as Rozliczenie3 } from '../../types/fa2.types';
15
+ import FormatTyp, { Position } from '../../../shared/enums/common.enum';
16
+ import { FormContentState } from '../../../shared/types/additional-data.types';
17
+
18
+ export function generateRozliczenie(
19
+ rozliczenie: Rozliczenie1 | Rozliczenie2 | Rozliczenie3 | undefined,
20
+ KodWaluty: string
21
+ ): Content[] {
22
+ if (!rozliczenie) {
23
+ return [];
24
+ }
25
+ const obciazenia: Zenia[] = getTable(rozliczenie?.Obciazenia);
26
+ const odliczenia: Zenia[] = getTable(rozliczenie?.Odliczenia);
27
+ const result: Content[] = [];
28
+ const headerOdliczenia: HeaderDefine[] = [
29
+ {
30
+ title: 'Powód odliczenia',
31
+ name: 'Powod',
32
+ format: FormatTyp.Default,
33
+ },
34
+ {
35
+ title: 'Kwota odliczenia',
36
+ name: 'Kwota',
37
+ format: FormatTyp.Currency,
38
+ },
39
+ ];
40
+ const headerObciazenia: HeaderDefine[] = [
41
+ {
42
+ name: 'Powod',
43
+ title: 'Powód obciążenia',
44
+ format: FormatTyp.Default,
45
+ },
46
+ {
47
+ name: 'Kwota',
48
+ title: 'Kwota obciążenia',
49
+ format: FormatTyp.Currency,
50
+ },
51
+ ];
52
+ const tableObciazenia: FormContentState = getContentTable<(typeof obciazenia)[0]>(
53
+ headerObciazenia,
54
+ obciazenia,
55
+ '*'
56
+ );
57
+ const tableOdliczenia: FormContentState = getContentTable<(typeof odliczenia)[0]>(
58
+ headerOdliczenia,
59
+ odliczenia,
60
+ '*'
61
+ );
62
+ const SumaObciazen: Content[] = createLabelText(
63
+ 'Suma kwot obciążenia: ',
64
+ rozliczenie.SumaObciazen,
65
+ FormatTyp.Currency,
66
+ {
67
+ alignment: Position.RIGHT,
68
+ }
69
+ );
70
+ const Sumaodliczen: Content[] = createLabelText(
71
+ 'Suma kwot odliczenia: ',
72
+ rozliczenie?.SumaOdliczen,
73
+ FormatTyp.Currency,
74
+ {
75
+ alignment: Position.RIGHT,
76
+ }
77
+ );
78
+ const resultObciazenia: (ContentTable | Content[])[] = [
79
+ createSubHeader('Obciążenia'),
80
+ tableObciazenia.content ?? [],
81
+ SumaObciazen,
82
+ ];
83
+ const resultOdliczenia: (ContentTable | Content[])[] = [
84
+ createSubHeader('Odliczenia'),
85
+ tableOdliczenia.content ?? [],
86
+ Sumaodliczen,
87
+ ];
88
+
89
+ result.push(createHeader('Rozliczenie', [0, 8, 0, 4]));
90
+ if (obciazenia.length > 0 && odliczenia.length > 0) {
91
+ result.push(generateTwoColumns([resultObciazenia], [resultOdliczenia]));
92
+ } else if (obciazenia.length > 0) {
93
+ result.push(generateTwoColumns([resultObciazenia], []));
94
+ } else if (odliczenia.length > 0) {
95
+ result.push(generateTwoColumns([], [resultOdliczenia]));
96
+ }
97
+
98
+ if (rozliczenie?.DoZaplaty?._text) {
99
+ result.push({
100
+ stack: createLabelTextArray([
101
+ { value: 'Do zapłaty: ', formatTyp: FormatTyp.LabelGreater },
102
+ { value: rozliczenie?.DoZaplaty, formatTyp: FormatTyp.CurrencyGreater, currency: KodWaluty },
103
+ ]),
104
+ alignment: Position.RIGHT,
105
+ margin: [0, 8, 0, 0],
106
+ });
107
+ } else if (rozliczenie?.DoRozliczenia?._text) {
108
+ result.push({
109
+ stack: createLabelTextArray([
110
+ { value: 'Do rozliczenia: ', formatTyp: FormatTyp.LabelGreater },
111
+ { value: rozliczenie?.DoRozliczenia, formatTyp: FormatTyp.CurrencyGreater, currency: KodWaluty },
112
+ ]),
113
+ alignment: Position.RIGHT,
114
+ marginTop: 8,
115
+ });
116
+ }
117
+
118
+ return createSection(result, true);
119
+ }
@@ -0,0 +1,161 @@
1
+ import { Content, ContentQr, ContentStack } from 'pdfmake/interfaces';
2
+ import {
3
+ createHeader,
4
+ createLabelText,
5
+ createSection,
6
+ createSubHeader,
7
+ formatText,
8
+ generateLine,
9
+ generateQRCode,
10
+ generateTwoColumns,
11
+ getContentTable,
12
+ getTable,
13
+ verticalSpacing,
14
+ } from '../../../shared/PDF-functions';
15
+ import { HeaderDefine } from '../../../shared/types/pdf-types';
16
+ import { FormContentState } from '../../../shared/types/additional-data.types';
17
+ import { FP, Naglowek, Stopka } from '../../types/fa2.types';
18
+ import { Zalacznik } from '../../types/fa3.types';
19
+ import { generateZalaczniki } from './Zalaczniki';
20
+ import FormatTyp from '../../../shared/enums/common.enum';
21
+ import { Informacje, Rejestry } from '../../types/fa1.types';
22
+ import { AdditionalDataTypes } from '../../types/common.types';
23
+
24
+ export function generateStopka(
25
+ additionalData?: AdditionalDataTypes,
26
+ stopka?: Stopka,
27
+ naglowek?: Naglowek,
28
+ wz?: FP[],
29
+ zalacznik?: Zalacznik
30
+ ): Content[] {
31
+ const wzty: Content[] = generateWZ(wz);
32
+ const rejestry: Content[] = generateRejestry(stopka);
33
+ const informacje: Content[] = generateInformacje(stopka);
34
+ const qrCode: Content[] = generateQRCodeData(additionalData);
35
+ const zalaczniki: Content[] = !additionalData?.isMobile ? generateZalaczniki(zalacznik) : [];
36
+
37
+ const result: Content = [
38
+ verticalSpacing(1),
39
+ ...(wzty.length ? [generateLine()] : []),
40
+ ...(wzty.length ? [generateTwoColumns(wzty, [])] : []),
41
+ ...(rejestry.length || informacje.length ? [generateLine()] : []),
42
+ ...rejestry,
43
+ ...informacje,
44
+ ...(zalaczniki.length ? zalaczniki : []),
45
+ { stack: [...qrCode], unbreakable: true },
46
+ createSection(
47
+ [
48
+ {
49
+ stack: createLabelText('Wytworzona w:', naglowek?.SystemInfo),
50
+ margin: [0, 8, 0, 0],
51
+ },
52
+ ],
53
+ true,
54
+ [0, 0, 0, 0]
55
+ ),
56
+ ];
57
+
58
+ return createSection(result, false);
59
+ }
60
+
61
+ function generateWZ(wz?: FP[]): Content[] {
62
+ const result: Content[] = [];
63
+ const definedHeader: HeaderDefine[] = [{ name: '', title: 'Numer WZ', format: FormatTyp.Default }];
64
+ const faWiersze: FP[] = getTable(wz ?? []);
65
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
66
+ [...definedHeader],
67
+ faWiersze,
68
+ '*'
69
+ );
70
+
71
+ if (content.fieldsWithValue.length && content.content) {
72
+ result.push(createSubHeader('Numery dokumentów magazynowych WZ', [0, 8, 0, 4]));
73
+ result.push(content.content);
74
+ }
75
+ return result;
76
+ }
77
+
78
+ function generateRejestry(stopka?: Stopka): Content[] {
79
+ const result: Content[] = [];
80
+ const definedHeader: HeaderDefine[] = [
81
+ { name: 'PelnaNazwa', title: 'Pełna nazwa', format: FormatTyp.Default },
82
+ { name: 'KRS', title: 'KRS', format: FormatTyp.Default },
83
+ { name: 'REGON', title: 'REGON', format: FormatTyp.Default },
84
+ { name: 'BDO', title: 'BDO', format: FormatTyp.Default },
85
+ ];
86
+ const faWiersze: Rejestry[] = getTable(stopka?.Rejestry ?? []);
87
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
88
+ [...definedHeader],
89
+ faWiersze,
90
+ '*'
91
+ );
92
+
93
+ if (content.fieldsWithValue.length && content.content) {
94
+ result.push(createHeader('Rejestry'));
95
+ result.push(content.content);
96
+ }
97
+ return result;
98
+ }
99
+
100
+ function generateInformacje(stopka?: Stopka): Content[] {
101
+ const result: Content[] = [];
102
+ const definedHeader: HeaderDefine[] = [
103
+ { name: 'StopkaFaktury', title: 'Stopka faktury', format: FormatTyp.Default },
104
+ ];
105
+ const faWiersze: Informacje[] = getTable(stopka?.Informacje ?? []);
106
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
107
+ [...definedHeader],
108
+ faWiersze,
109
+ '*'
110
+ );
111
+
112
+ if (content.fieldsWithValue.length && content.content) {
113
+ result.push(createHeader('Pozostałe informacje'));
114
+ result.push(content.content);
115
+ }
116
+ return result;
117
+ }
118
+
119
+ function generateQRCodeData(additionalData?: AdditionalDataTypes): Content[] {
120
+ const result: Content = [];
121
+
122
+ if (additionalData?.qrCode && additionalData.nrKSeF) {
123
+ const qrCode: ContentQr | undefined = generateQRCode(additionalData.qrCode);
124
+
125
+ result.push(createHeader('Sprawdź, czy Twoja faktura znajduje się w KSeF!'));
126
+ if (qrCode) {
127
+ result.push({
128
+ columns: [
129
+ {
130
+ stack: [
131
+ qrCode,
132
+
133
+ {
134
+ stack: [formatText(additionalData.nrKSeF, FormatTyp.Default)],
135
+ width: 'auto',
136
+ alignment: 'center',
137
+ marginLeft: 10,
138
+ marginRight: 10,
139
+ marginTop: 10,
140
+ } as ContentStack,
141
+ ],
142
+ width: 150,
143
+ } as ContentStack,
144
+ {
145
+ stack: [
146
+ formatText(
147
+ 'Nie możesz zeskanować kodu z obrazka? Kliknij w link weryfikacyjny i przejdź do weryfikacji faktury!',
148
+ FormatTyp.Value
149
+ ),
150
+ { stack: [formatText(additionalData.qrCode, FormatTyp.Link)], marginTop: 5 },
151
+ ],
152
+ link: additionalData.qrCode,
153
+ margin: [10, (qrCode.fit ?? 120) / 2 - 30, 0, 0],
154
+ width: 'auto',
155
+ } as ContentStack,
156
+ ],
157
+ });
158
+ }
159
+ }
160
+ return createSection(result, true);
161
+ }
@@ -0,0 +1,32 @@
1
+ import { TRodzajFaktury } from '../../../shared/consts/const';
2
+ import { FP } from '../../types/fa1.types';
3
+ import { getValue } from '../../../shared/PDF-functions';
4
+
5
+ export function shouldAddMarza(
6
+ rodzajFaktury: string | number | undefined,
7
+ isP_PMarzy: boolean,
8
+ wiersz: Record<string, FP>
9
+ ): Record<string, FP> | null {
10
+ if (typeof rodzajFaktury === 'string') {
11
+ const isVATType = [
12
+ TRodzajFaktury.VAT,
13
+ TRodzajFaktury.KOR,
14
+ TRodzajFaktury.ROZ,
15
+ TRodzajFaktury.KOR_ROZ,
16
+ ].includes(rodzajFaktury);
17
+
18
+ const isZALType = [TRodzajFaktury.ZAL, TRodzajFaktury.KOR_ZAL].includes(rodzajFaktury);
19
+
20
+ if (isP_PMarzy) {
21
+ if (isVATType && !getValue(wiersz.P_12) && !getValue(wiersz.P_12_XII)) {
22
+ return { P_12: { _text: 'marża' } };
23
+ } else if (isZALType && !getValue(wiersz.P_12Z) && !getValue(wiersz.P_12Z_XII)) {
24
+ return { P_12Z: { _text: 'marża' } };
25
+ } else {
26
+ return null;
27
+ }
28
+ }
29
+ }
30
+
31
+ return null;
32
+ }
@@ -0,0 +1,232 @@
1
+ import { Content, ContentTable, ContentText, TableCell } from 'pdfmake/interfaces';
2
+ import { DEFAULT_TABLE_LAYOUT, TableDataType } from '../../../shared/consts/const';
3
+ import {
4
+ createHeader,
5
+ createLabelText,
6
+ createSection,
7
+ createSubHeader,
8
+ formatText,
9
+ getContentTable,
10
+ getTable,
11
+ hasValue,
12
+ } from '../../../shared/PDF-functions';
13
+ import { HeaderDefine } from '../../../shared/types/pdf-types';
14
+ import { BlokDanych, FP, Kol, MetaDane, Tabela, TMetaDane, Wiersz, Zalacznik } from '../../types/fa3.types';
15
+ import FormatTyp from '../../../shared/enums/common.enum';
16
+ import { FormContentState } from '../../../shared/types/additional-data.types';
17
+
18
+ export function generateZalaczniki(zalacznik?: Zalacznik): Content[] {
19
+ if (!getTable(zalacznik?.BlokDanych).length) {
20
+ return [];
21
+ }
22
+
23
+ const result: Content[] = [];
24
+ const definedHeader: HeaderDefine[] = [
25
+ { name: 'PelnaNazwa', title: 'Pełna nazwa', format: FormatTyp.Default },
26
+ { name: 'KRS', title: 'KRS', format: FormatTyp.Default },
27
+ { name: 'REGON', title: 'REGON', format: FormatTyp.Default },
28
+ { name: 'BDO', title: 'BDO', format: FormatTyp.Default },
29
+ ];
30
+ const faWiersze: BlokDanych[] = getTable(zalacznik?.BlokDanych ?? []);
31
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
32
+ [...definedHeader],
33
+ faWiersze,
34
+ '*'
35
+ );
36
+
37
+ result.push(createHeader('Załącznik do Faktury VAT'));
38
+
39
+ getTable(zalacznik?.BlokDanych).forEach((blok: BlokDanych, index: number): void => {
40
+ result.push(createSubHeader(`Szczegółowe dane załącznika (${index + 1})`));
41
+ if (blok.ZNaglowek) {
42
+ result.push(
43
+ createLabelText('Nagłówek bloku danych: ', blok.ZNaglowek, FormatTyp.Value, { marginBottom: 8 })
44
+ );
45
+ }
46
+ if (getTable(blok.MetaDane)?.length) {
47
+ result.push(generateKluczWartosc(getTable(blok.MetaDane)));
48
+ }
49
+ if (blok.Tekst?.Akapit) {
50
+ result.push(createLabelText('Opis: ', ' '));
51
+ getTable(blok.Tekst.Akapit).forEach((text: FP): void => {
52
+ if (hasValue(text)) {
53
+ result.push(formatText(text._text, FormatTyp.Value));
54
+ }
55
+ });
56
+ }
57
+
58
+ if (getTable(blok.Tabela).length) {
59
+ getTable(blok.Tabela).forEach((tabela: Tabela, index: number): void => {
60
+ if (blok.ZNaglowek?._text) {
61
+ result.push(createSubHeader(`${blok.ZNaglowek?._text} ${index + 1}`));
62
+ }
63
+ if (getTable(tabela.TMetaDane)?.length) {
64
+ result.push({
65
+ stack: generateKluczWartosc(
66
+ getTable(tabela.TMetaDane).map(
67
+ (item: TMetaDane): { ZKlucz: FP | undefined; ZWartosc: FP | undefined } => ({
68
+ ZKlucz: item.TKlucz,
69
+ ZWartosc: item.TWartosc,
70
+ })
71
+ )
72
+ ),
73
+ margin: [0, 8, 0, 0],
74
+ });
75
+ }
76
+ if (tabela.Opis) {
77
+ result.push(createLabelText('Opis: ', tabela.Opis));
78
+ }
79
+ if (getTable(tabela.TNaglowek?.Kol).length) {
80
+ result.push(formatText('Tabela', [FormatTyp.GrayBoldTitle, FormatTyp.LabelSmallMargin]));
81
+ result.push(generateTable(tabela));
82
+ }
83
+ if (getTable(tabela.Suma?.SKom).length) {
84
+ result.push(generateSuma(getTable(tabela.Suma?.SKom)));
85
+ }
86
+ });
87
+ }
88
+ });
89
+
90
+ if (content.fieldsWithValue.length && content.content) {
91
+ result.push(content.content);
92
+ }
93
+
94
+ return createSection(result, false);
95
+ }
96
+
97
+ function generateKluczWartosc(data: MetaDane[]): Content[] {
98
+ const result: Content[] = [];
99
+ const definedHeader: HeaderDefine[] = [
100
+ { name: 'ZKlucz', title: 'Klucz', format: FormatTyp.Default },
101
+ { name: 'ZWartosc', title: 'Wartość', format: FormatTyp.Default },
102
+ ];
103
+ const faWiersze: MetaDane[] = getTable(data ?? []);
104
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
105
+ [...definedHeader],
106
+ faWiersze,
107
+ '*'
108
+ );
109
+
110
+ if (content.fieldsWithValue.length && content.content) {
111
+ result.push(content.content);
112
+ }
113
+ return result;
114
+ }
115
+
116
+ function generateTable(tabela: Tabela): Content[] {
117
+ if (!tabela.TNaglowek?.Kol?.length) {
118
+ return [];
119
+ }
120
+
121
+ const result: Content[] = [];
122
+ const Kol: Kol[] = getTable(tabela.TNaglowek.Kol);
123
+ const cutedTableHeader: Kol[][] = chunkArray(Kol);
124
+
125
+ cutedTableHeader.forEach((table: Kol[], index: number): void => {
126
+ result.push(createTable(table, tabela.Wiersz ?? [], index, Kol.length));
127
+ });
128
+ return result;
129
+ }
130
+
131
+ function createTable(cols: Kol[], rows: Wiersz[], subTableIndex: number, totalLength: number): ContentTable {
132
+ const definedHeader: Content[] = cols.map((item: Kol): string | ContentText =>
133
+ formatText(item.NKom?._text, FormatTyp.GrayBoldTitle)
134
+ );
135
+ const tableBody: TableCell[] = [];
136
+
137
+ rows.forEach((item: Wiersz): void => {
138
+ const WKom: FP[] = getTable(item.WKom);
139
+
140
+ while (WKom.length < totalLength) {
141
+ WKom.push({ _text: '' });
142
+ }
143
+ const cuttedRows: FP[][] = chunkArray(WKom ?? []);
144
+
145
+ if (cuttedRows.length >= subTableIndex + 1) {
146
+ tableBody.push(
147
+ //@ts-ignore
148
+ cuttedRows[subTableIndex].map((subItem: FP, index: number): TableCell => {
149
+ return formatText(
150
+ subItem._text ?? '',
151
+ cols[index]._attributes?.Typ ? TableDataType[cols[index]._attributes.Typ] : FormatTyp.Value
152
+ ) as TableCell
153
+ })
154
+ );
155
+ }
156
+ });
157
+ const widths: Content[] = definedHeader.map((index: Content): string[] => {
158
+ if (index) {
159
+ return ['*'];
160
+ } else {
161
+ return ['auto'];
162
+ }
163
+ });
164
+
165
+ return {
166
+ table: {
167
+ headerRows: 1,
168
+ widths: [...widths] as never[],
169
+ heights: 8,
170
+ body: [[...definedHeader], ...tableBody] as TableCell[][],
171
+ },
172
+ layout: DEFAULT_TABLE_LAYOUT,
173
+ marginTop: 8,
174
+ };
175
+ }
176
+
177
+ function generateSuma(data: FP[]): Content[] {
178
+ const result: Content[] = [];
179
+ const definedHeader: HeaderDefine[] = [
180
+ { name: '', title: 'Podsumowanie tabeli', format: FormatTyp.Default },
181
+ ];
182
+ const faWiersze: FP[] = getTable(data ?? []);
183
+ const content: FormContentState = getContentTable<(typeof faWiersze)[0]>(
184
+ [...definedHeader],
185
+ faWiersze,
186
+ '*',
187
+ [0, 8, 0, 0]
188
+ );
189
+
190
+ if (content.fieldsWithValue.length && content.content) {
191
+ result.push(content.content);
192
+ }
193
+ return result;
194
+ }
195
+
196
+ export function chunkArray<T>(columns: T[]): T[][] {
197
+ if (!Array.isArray(columns)) {
198
+ return [];
199
+ }
200
+
201
+ const n: number = columns.length;
202
+
203
+ if (n <= 7) {
204
+ return [columns];
205
+ } else if (n >= 8 && n <= 14) {
206
+ const half: number = Math.floor(n / 2);
207
+
208
+ if (n % 2 === 0) {
209
+ return [columns.slice(0, half), columns.slice(half)];
210
+ } else {
211
+ return [columns.slice(0, half + 1), columns.slice(half + 1)];
212
+ }
213
+ } else {
214
+ const base: number = Math.floor(n / 3);
215
+ const remainder: number = n % 3;
216
+
217
+ const splits: number[] = [base, base, base];
218
+
219
+ for (let i = 0; i < remainder; i++) {
220
+ splits[i] += 1;
221
+ }
222
+
223
+ const result: T[][] = [];
224
+ let idx = 0;
225
+
226
+ for (const size of splits) {
227
+ result.push(columns.slice(idx, idx + size));
228
+ idx += size;
229
+ }
230
+ return result;
231
+ }
232
+ }
@@ -0,0 +1,3 @@
1
+ import { generateInvoice } from './generate-invoice';
2
+
3
+ export { generateInvoice };
@@ -0,0 +1,29 @@
1
+ import { FP as FP3 } from './fa3.types';
2
+ import { FP as FP2 } from './fa2.types';
3
+
4
+ interface FA2FakturaZaliczkowaDataSpozaKSeF {
5
+ NrKSeFZN: FP2;
6
+ NrFaZaliczkowej: FP2;
7
+ }
8
+
9
+ interface FA2FakturaZaliczkowaDataZKSeF {
10
+ NrKSeFFaZaliczkowej: FP2;
11
+ }
12
+
13
+ interface FA3FakturaZaliczkowaDataSpozaKSeF {
14
+ NrKSeFZN: FP3;
15
+ NrFaZaliczkowej: FP3;
16
+ }
17
+
18
+ interface FA3FakturaZaliczkowaDataZKSeF {
19
+ NrKSeFFaZaliczkowej: FP3;
20
+ }
21
+
22
+ export type FA3FakturaZaliczkowaData = FA3FakturaZaliczkowaDataSpozaKSeF | FA3FakturaZaliczkowaDataZKSeF;
23
+ export type FA2FakturaZaliczkowaData = FA2FakturaZaliczkowaDataSpozaKSeF | FA2FakturaZaliczkowaDataZKSeF;
24
+
25
+ export interface AdditionalDataTypes {
26
+ nrKSeF: string;
27
+ qrCode?: string;
28
+ isMobile?: boolean;
29
+ }
@@ -0,0 +1,26 @@
1
+ import { FP, Podmiot2K, Podmiot3 } from './fa1.types';
2
+ import { ContentTable } from 'pdfmake/interfaces';
3
+
4
+ export interface Podmiot3Podmiot2KDto {
5
+ podmiot2KDto?: Podmiot2K;
6
+ fakturaPodmiotNDto: Podmiot3;
7
+ }
8
+ export type FakturaZaliczkowa = {
9
+ lp: {
10
+ _text: number;
11
+ };
12
+ Klucz?: FP;
13
+ Wartosc?: FP;
14
+ };
15
+
16
+ export type TableWithFields = {
17
+ content: ContentTable | null;
18
+ fieldsWithValue: string[];
19
+ };
20
+
21
+ export type TerminPlatnosciContent = {
22
+ TerminPlatnosciOpis: {
23
+ key: string;
24
+ };
25
+ TerminPlatnosci?: FP;
26
+ };