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,466 @@
1
+ import {
2
+ Column,
3
+ Content,
4
+ ContentQr,
5
+ ContentTable,
6
+ ContentText,
7
+ CustomTableLayout,
8
+ Margins,
9
+ Style,
10
+ TableCell,
11
+ TDocumentDefinitions,
12
+ } from 'pdfmake/interfaces';
13
+ import { DEFAULT_TABLE_LAYOUT, Kraj } from './consts/const';
14
+ import { formatDateTime, getFormaPlatnosciString } from './generators/common/functions';
15
+ import { HeaderDefine, PdfFP, PdfOptionField } from './types/pdf-types';
16
+ import { FP } from '../lib-public/types/fa3.types';
17
+ import { DifferentValues, FilteredKeysOfValues, TypesOfValues } from './types/universal.types';
18
+ import { CreateLabelTextData } from './types/additional-data.types';
19
+ import FormatTyp, { Answer, Position } from './enums/common.enum';
20
+
21
+ export function formatText(
22
+ value: number | string | undefined | null,
23
+ format: FormatTyp | FormatTyp[] | null = null,
24
+ options: PdfOptionField = {},
25
+ currency = ''
26
+ ): ContentText | string {
27
+ if (!value) {
28
+ return '';
29
+ }
30
+ const result: ContentText = { text: value.toString() };
31
+
32
+ Object.assign(result, options);
33
+
34
+ if (format) {
35
+ result.style = format;
36
+ if (!Array.isArray(format)) {
37
+ formatValue(format, result, value, currency);
38
+ } else {
39
+ format.forEach((item: FormatTyp): void => {
40
+ formatValue(item, result, value, currency);
41
+ });
42
+ }
43
+ }
44
+
45
+ return result;
46
+ }
47
+
48
+ export function generateTable<T>(array: T[], keys: Partial<Record<keyof T, string>>): Content {
49
+ const faRows: NonNullable<T>[] = getTable(array);
50
+
51
+ const headers: { name: string; title: string; format: FormatTyp }[] = Object.entries(keys).map(
52
+ ([key, value]: [string, unknown]): { name: string; title: string; format: FormatTyp } => {
53
+ return {
54
+ name: key,
55
+ title: value as string,
56
+ format: FormatTyp.Default,
57
+ };
58
+ }
59
+ );
60
+
61
+ const table: { content: ContentTable | null; fieldsWithValue: string[] } = getContentTable(
62
+ headers,
63
+ faRows,
64
+ '*'
65
+ );
66
+
67
+ return table.content ?? [];
68
+ }
69
+
70
+ function formatValue(
71
+ item: FormatTyp,
72
+ result: ContentText,
73
+ value: number | string | undefined,
74
+ currency = ''
75
+ ): void {
76
+ switch (item) {
77
+ case FormatTyp.Currency:
78
+ result.text = isNaN(Number(value)) ? (value as string) : `${Number(value).toFixed(2)} ${currency}`;
79
+ result.alignment = Position.RIGHT;
80
+ break;
81
+ case FormatTyp.CurrencyAbs:
82
+ result.text = isNaN(Number(value))
83
+ ? (value as string)
84
+ : `${Math.abs(Number(value)).toFixed(2)} ${currency}`;
85
+ result.alignment = Position.RIGHT;
86
+ break;
87
+ case FormatTyp.CurrencyGreater:
88
+ result.text = isNaN(Number(value)) ? (value as string) : `${Number(value).toFixed(2)} ${currency}`;
89
+ result.fontSize = 10;
90
+ break;
91
+ case FormatTyp.Currency6:
92
+ result.text = isNaN(Number(value)) ? (value as string) : `${Number(value).toFixed(6)} ${currency}`;
93
+ result.alignment = Position.RIGHT;
94
+ break;
95
+ case FormatTyp.DateTime:
96
+ result.text = formatDateTime(value as string, false, true);
97
+ break;
98
+ case FormatTyp.Date:
99
+ result.text = formatDateTime(value as string, false, true);
100
+ break;
101
+ case FormatTyp.FormOfPayment:
102
+ result.text = getFormaPlatnosciString({ _text: value as string });
103
+ break;
104
+ case FormatTyp.Boolean:
105
+ result.text = (value as string) === '1' ? Answer.TRUE : Answer.FALSE;
106
+ break;
107
+ case FormatTyp.Percentage:
108
+ result.text = `${value}%`;
109
+ break;
110
+ }
111
+ }
112
+
113
+ export function hasValue(value: FP | string | number | undefined): boolean {
114
+ return (
115
+ !!((typeof value !== 'object' && value) || (typeof value === 'object' && value._text)) || value === 0
116
+ );
117
+ }
118
+
119
+ export function getValue(value: FP | string | number | undefined): string | number | undefined {
120
+ if (typeof value === 'object') {
121
+ return value._text;
122
+ }
123
+ return value;
124
+ }
125
+
126
+ export function getNumber(value: FP | string | number | undefined): number {
127
+ const text: string | number | undefined = getValue(value);
128
+
129
+ if (!text) {
130
+ return 0;
131
+ }
132
+ if (typeof text === 'number') {
133
+ return text;
134
+ }
135
+
136
+ return parseFloat(text.toString());
137
+ }
138
+
139
+ export function getNumberRounded(value: FP | string | number | undefined): number {
140
+ const number: number = getNumber(value);
141
+
142
+ return Math.round(number * 100) / 100;
143
+ }
144
+
145
+ export function createLabelTextArray(data: CreateLabelTextData[]): Content[] {
146
+ return [
147
+ {
148
+ text: data.map((textEl: CreateLabelTextData): string | ContentText =>
149
+ formatText(getValue(textEl.value) ?? '', textEl.formatTyp ?? FormatTyp.Label, {}, textEl.currency)
150
+ ),
151
+ },
152
+ ];
153
+ }
154
+
155
+ export function createLabelText(
156
+ label: string,
157
+ value: FP | string | number | undefined | null,
158
+ formatTyp: FormatTyp | FormatTyp[] = FormatTyp.Value,
159
+ style: Style = {}
160
+ ): Content[] {
161
+ if (!value || (typeof value === 'object' && !value._text)) {
162
+ return [];
163
+ }
164
+ if (typeof value === 'object') {
165
+ return [
166
+ {
167
+ text: [formatText(label, FormatTyp.Label), formatText(value._text, formatTyp)],
168
+ ...style,
169
+ },
170
+ ];
171
+ }
172
+
173
+ return [
174
+ {
175
+ text: [formatText(label, FormatTyp.Label), formatText(value, formatTyp)],
176
+ ...style,
177
+ },
178
+ ];
179
+ }
180
+
181
+ export function createSection(content: Content[], isLineOnTop: boolean, margin?: Margins): Content[] {
182
+ return [
183
+ {
184
+ stack: [
185
+ ...(content.length
186
+ ? [...(isLineOnTop ? [{ stack: [generateLine()], margin: [0, 8, 0, 0] } as Content] : []), content]
187
+ : []),
188
+ ],
189
+ margin: margin ?? [0, 0, 0, 8],
190
+ },
191
+ ];
192
+ }
193
+
194
+ export function createHeader(text: string, margin?: Margins): Content[] {
195
+ return [
196
+ {
197
+ stack: [formatText(text, FormatTyp.HeaderContent)],
198
+ margin: margin ?? [0, 8, 0, 8],
199
+ },
200
+ ];
201
+ }
202
+
203
+ export function createSubHeader(text: string, margin?: Margins): Content[] {
204
+ return [
205
+ {
206
+ stack: [formatText(text, FormatTyp.SubHeaderContent)],
207
+ margin: margin ?? [0, 4, 0, 4],
208
+ },
209
+ ];
210
+ }
211
+
212
+ export function generateStyle(): Partial<TDocumentDefinitions> {
213
+ return {
214
+ styles: {
215
+ columnMarginLeft: {
216
+ margin: [4, 0, 0, 0],
217
+ },
218
+ columnMarginRight: {
219
+ margin: [0, 0, 4, 0],
220
+ },
221
+ GrayBoldTitle: {
222
+ fillColor: '#F6F7FA',
223
+ bold: true,
224
+ },
225
+ GrayTitle: {
226
+ fillColor: '#F6F7FA',
227
+ },
228
+ Label: {
229
+ color: '#343A40',
230
+ bold: true,
231
+ },
232
+ LabelMargin: {
233
+ margin: [0, 12, 0, 1.3],
234
+ },
235
+ LabelSmallMargin: {
236
+ margin: [0, 6, 0, 1.3],
237
+ },
238
+ LabelMedium: {
239
+ color: '#343A40',
240
+ bold: true,
241
+ fontSize: 9,
242
+ },
243
+ LabelGreater: {
244
+ color: '#343A40',
245
+ bold: true,
246
+ fontSize: 10,
247
+ },
248
+ Value: {
249
+ color: '#343A40',
250
+ },
251
+ ValueMedium: {
252
+ color: '#343A40',
253
+ fontSize: 9,
254
+ },
255
+ Bold: {
256
+ fontSize: 9,
257
+ bold: true,
258
+ },
259
+ Description: {
260
+ color: 'blue',
261
+ bold: false,
262
+ },
263
+ HeaderPosition: {
264
+ fontSize: 16,
265
+ bold: true,
266
+ },
267
+ Right: {
268
+ alignment: Position.RIGHT,
269
+ },
270
+ header: {
271
+ fontSize: 12,
272
+ bold: true,
273
+ margin: [0, 12, 0, 5],
274
+ },
275
+ HeaderContent: {
276
+ fontSize: 10,
277
+ bold: true,
278
+ },
279
+ SubHeaderContent: {
280
+ fontSize: 7,
281
+ bold: true,
282
+ },
283
+ TitleContent: {
284
+ fontSize: 10,
285
+ bold: true,
286
+ },
287
+ Link: {
288
+ color: 'blue',
289
+ },
290
+ MarginBottom4: {
291
+ marginBottom: 4,
292
+ },
293
+ MarginBottom8: {
294
+ marginBottom: 8,
295
+ },
296
+ MarginTop4: {
297
+ marginTop: 4,
298
+ },
299
+ },
300
+ defaultStyle: {
301
+ font: 'Roboto',
302
+ fontSize: 7,
303
+ lineHeight: 1.2,
304
+ },
305
+ };
306
+ }
307
+
308
+ export function getTable<T>(data: T | T[]): NonNullable<T>[] {
309
+ if (!data) {
310
+ return [];
311
+ }
312
+ if (Array.isArray(data)) {
313
+ return data as NonNullable<T>[];
314
+ }
315
+ return [data];
316
+ }
317
+
318
+ export function getRowTable(data: string[], formatColumn: FormatTyp | FormatTyp[]): Content[] {
319
+ return data.map((el: string, index: number): Content => {
320
+ if (Array.isArray(formatColumn)) {
321
+ return formatText(el, formatColumn[index] ?? FormatTyp.Default);
322
+ }
323
+ return formatText(el, formatColumn ?? FormatTyp.Default);
324
+ });
325
+ }
326
+
327
+ export function hasColumnsValue<T, K extends FilteredKeysOfValues<T>>(name: K, data: T[]): boolean {
328
+ return data.some((el: T): boolean => {
329
+ return hasValue(el[name] as TypesOfValues);
330
+ });
331
+ }
332
+
333
+ export function getDifferentColumnsValue<T, K extends FilteredKeysOfValues<T>>(
334
+ name: K,
335
+ data: T[]
336
+ ): DifferentValues[] {
337
+ const result: DifferentValues[] = [];
338
+
339
+ data.forEach((el: T): void => {
340
+ const val: string | number | undefined = getValue(el[name] as TypesOfValues);
341
+
342
+ if (val) {
343
+ const index: number = result.findIndex((el: DifferentValues): boolean => el.value === val);
344
+
345
+ if (index < 0) {
346
+ result.push({ value: val, count: 1 });
347
+ } else {
348
+ result[index].count++;
349
+ }
350
+ }
351
+ });
352
+ return result;
353
+ }
354
+
355
+ export function getContentTable<T>(
356
+ headers: HeaderDefine[],
357
+ data: T[],
358
+ defaultWidths: string,
359
+ margin?: Margins
360
+ ): { content: ContentTable | null; fieldsWithValue: string[] } {
361
+ const fieldsWithValue: HeaderDefine[] = headers.filter((header: HeaderDefine): boolean => {
362
+ return data.some((d: T): boolean => {
363
+ const name = header.name as keyof T;
364
+
365
+ if (name === '' && (d as FP)?._text) {
366
+ return true;
367
+ }
368
+
369
+ if (name === '') {
370
+ return false;
371
+ }
372
+
373
+ if (typeof d[name] === 'object' && (d[name] as FP)?._text) {
374
+ return true;
375
+ }
376
+
377
+ return !!(typeof d[name] !== 'object' && d[name]);
378
+ });
379
+ });
380
+
381
+ if (fieldsWithValue.length < 1) {
382
+ return { content: null, fieldsWithValue: [] };
383
+ }
384
+
385
+ const headerRow: Content[] = getRowTable(
386
+ fieldsWithValue.map((header: HeaderDefine): string => header.title),
387
+ FormatTyp.GrayBoldTitle
388
+ );
389
+ const tableBody: (string | ContentText)[][] = data.map((row: T): (string | ContentText)[] => {
390
+ return fieldsWithValue.map((header: HeaderDefine): string | ContentText => {
391
+ const fp = (header.name ? row[header.name as keyof T] : row) as PdfFP;
392
+ const value: string | undefined = typeof fp === 'object' ? fp?._text : fp;
393
+
394
+ return formatText(
395
+ header.mappingData && value ? header.mappingData[value] : (value ?? ''),
396
+ header.format ?? FormatTyp.Default,
397
+ { rowSpan: fp?._rowSpan ?? 1 }
398
+ );
399
+ });
400
+ });
401
+
402
+ return {
403
+ fieldsWithValue: fieldsWithValue.map((el: HeaderDefine): string => el.name),
404
+ content: {
405
+ table: {
406
+ headerRows: 1,
407
+ keepWithHeaderRows: 1,
408
+ widths: fieldsWithValue.map((header: HeaderDefine): string => header.width ?? defaultWidths),
409
+ body: [headerRow, ...tableBody] as TableCell[][],
410
+ },
411
+ margin: margin ?? [0, 0, 0, 8],
412
+ layout: DEFAULT_TABLE_LAYOUT,
413
+ },
414
+ };
415
+ }
416
+
417
+ export function generateTwoColumns(kol1: Column, kol2: Column, margin?: Margins): Content {
418
+ return {
419
+ columns: [
420
+ { stack: [kol1], margin: [0, 0, 5, 0] },
421
+ { stack: [kol2], margin: [5, 0, 0, 0] },
422
+ ],
423
+ margin: margin ?? [0, 0, 0, 0],
424
+ };
425
+ }
426
+
427
+ export function generateQRCode(qrCode?: string): ContentQr | undefined {
428
+ return qrCode
429
+ ? {
430
+ qr: qrCode,
431
+ fit: 150,
432
+ foreground: 'black',
433
+ background: 'white',
434
+ eccLevel: 'M',
435
+ }
436
+ : undefined;
437
+ }
438
+
439
+ export function verticalSpacing(height: number): ContentText {
440
+ return { text: '\n', fontSize: height };
441
+ }
442
+
443
+ export function getKraj(kod: string): string {
444
+ if (Kraj[kod]) {
445
+ return Kraj[kod];
446
+ }
447
+ return kod;
448
+ }
449
+
450
+ export function generateLine(): Content {
451
+ return {
452
+ table: {
453
+ widths: ['*'],
454
+ body: [[{ text: ' ', fontSize: 1 }]],
455
+ },
456
+ layout: {
457
+ hLineWidth: (i: number): 0 | 1 => (i === 0 ? 1 : 0),
458
+ vLineWidth: (): number => 0,
459
+ hLineColor: function (): string {
460
+ return '#c0bfc1';
461
+ },
462
+ paddingTop: (): number => 0,
463
+ paddingBottom: (): number => 0,
464
+ } as CustomTableLayout,
465
+ };
466
+ }
@@ -0,0 +1,42 @@
1
+ import { xml2js } from 'xml-js';
2
+ import { Faktura } from '../lib-public/types/fa2.types';
3
+
4
+ interface Kontener {
5
+ Faktura?: Faktura;
6
+ }
7
+
8
+ export function stripPrefixes<T>(obj: T): T {
9
+ if (Array.isArray(obj)) {
10
+ return obj.map(stripPrefixes) as T;
11
+ } else if (typeof obj === 'object' && obj !== null) {
12
+ return Object.fromEntries(
13
+ Object.entries(obj).map(([key, value]: [string, T]): [string, T] => [
14
+ key.includes(':') ? key.split(':')[1] : key,
15
+ stripPrefixes(value),
16
+ ])
17
+ ) as T;
18
+ }
19
+ return obj;
20
+ }
21
+
22
+ // export function parseXML(file: File): Promise<unknown> {
23
+ // return new Promise((resolve, reject): void => {
24
+ // const reader = new FileReader();
25
+
26
+ // reader.onload = function (e: ProgressEvent<FileReader>): void {
27
+ // try {
28
+ // const xmlStr: string = e.target?.result as string;
29
+ // const jsonDoc: Faktura = stripPrefixes(xml2js(xmlStr, { compact: true })) as Faktura;
30
+
31
+ // resolve(jsonDoc);
32
+ // } catch (error) {
33
+ // reject(error);
34
+ // }
35
+ // };
36
+ // reader.readAsText(file);
37
+ // });
38
+ // }
39
+
40
+ export function parseXML(xml: string) {
41
+ return stripPrefixes(xml2js(xml, { compact: true })) as Kontener;
42
+ };