makeapps-transformer 1.0.0 → 1.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.
|
@@ -103,7 +103,7 @@ function generateTable(tabela) {
|
|
|
103
103
|
function createTable(cols, rows, subTableIndex, totalLength) {
|
|
104
104
|
const definedHeader = cols.map((item) => { var _a; return (0, PDF_functions_1.formatText)((_a = item.NKom) === null || _a === void 0 ? void 0 : _a._text, common_enum_1.default.GrayBoldTitle); });
|
|
105
105
|
const tableBody = [];
|
|
106
|
-
rows.forEach((item) => {
|
|
106
|
+
(0, PDF_functions_1.getTable)(rows).forEach((item) => {
|
|
107
107
|
const WKom = (0, PDF_functions_1.getTable)(item.WKom);
|
|
108
108
|
while (WKom.length < totalLength) {
|
|
109
109
|
WKom.push({ _text: '' });
|
|
@@ -158,10 +158,10 @@ function chunkArray(columns) {
|
|
|
158
158
|
else if (n >= 8 && n <= 14) {
|
|
159
159
|
const half = Math.floor(n / 2);
|
|
160
160
|
if (n % 2 === 0) {
|
|
161
|
-
return [columns.slice(0, half), columns.slice(half)];
|
|
161
|
+
return [columns.slice(0, half), [columns[0], ...columns.slice(half)]];
|
|
162
162
|
}
|
|
163
163
|
else {
|
|
164
|
-
return [columns.slice(0, half + 1), columns.slice(half + 1)];
|
|
164
|
+
return [columns.slice(0, half + 1), [columns[0], ...columns.slice(half + 1)]];
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
else {
|
|
@@ -177,6 +177,8 @@ function chunkArray(columns) {
|
|
|
177
177
|
result.push(columns.slice(idx, idx + size));
|
|
178
178
|
idx += size;
|
|
179
179
|
}
|
|
180
|
+
result[1].unshift(columns[0]);
|
|
181
|
+
result[2].unshift(columns[0]);
|
|
180
182
|
return result;
|
|
181
183
|
}
|
|
182
184
|
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateZalaczniki = generateZalaczniki;
|
|
7
|
+
exports.chunkArray = chunkArray;
|
|
8
|
+
const const_1 = require("../../../shared/consts/const");
|
|
9
|
+
const PDF_functions_1 = require("../../../shared/PDF-functions");
|
|
10
|
+
const common_enum_1 = __importDefault(require("../../../shared/enums/common.enum"));
|
|
11
|
+
function generateZalaczniki(zalacznik) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (!(0, PDF_functions_1.getTable)(zalacznik === null || zalacznik === void 0 ? void 0 : zalacznik.BlokDanych).length) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const result = [];
|
|
17
|
+
const definedHeader = [
|
|
18
|
+
{ name: 'PelnaNazwa', title: 'Pełna nazwa', format: common_enum_1.default.Default },
|
|
19
|
+
{ name: 'KRS', title: 'KRS', format: common_enum_1.default.Default },
|
|
20
|
+
{ name: 'REGON', title: 'REGON', format: common_enum_1.default.Default },
|
|
21
|
+
{ name: 'BDO', title: 'BDO', format: common_enum_1.default.Default },
|
|
22
|
+
];
|
|
23
|
+
const faWiersze = (0, PDF_functions_1.getTable)((_a = zalacznik === null || zalacznik === void 0 ? void 0 : zalacznik.BlokDanych) !== null && _a !== void 0 ? _a : []);
|
|
24
|
+
const content = (0, PDF_functions_1.getContentTable)([...definedHeader], faWiersze, '*');
|
|
25
|
+
result.push((0, PDF_functions_1.createHeader)('Załącznik do Faktury VAT'));
|
|
26
|
+
(0, PDF_functions_1.getTable)(zalacznik === null || zalacznik === void 0 ? void 0 : zalacznik.BlokDanych).forEach((blok, index) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
result.push((0, PDF_functions_1.createSubHeader)(`Szczegółowe dane załącznika (${index + 1})`));
|
|
29
|
+
if (blok.ZNaglowek) {
|
|
30
|
+
result.push((0, PDF_functions_1.createLabelText)('Nagłówek bloku danych: ', blok.ZNaglowek, common_enum_1.default.Value, { marginBottom: 8 }));
|
|
31
|
+
}
|
|
32
|
+
if ((_a = (0, PDF_functions_1.getTable)(blok.MetaDane)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
33
|
+
result.push(generateKluczWartosc((0, PDF_functions_1.getTable)(blok.MetaDane)));
|
|
34
|
+
}
|
|
35
|
+
if ((_b = blok.Tekst) === null || _b === void 0 ? void 0 : _b.Akapit) {
|
|
36
|
+
result.push((0, PDF_functions_1.createLabelText)('Opis: ', ' '));
|
|
37
|
+
(0, PDF_functions_1.getTable)(blok.Tekst.Akapit).forEach((text) => {
|
|
38
|
+
if ((0, PDF_functions_1.hasValue)(text)) {
|
|
39
|
+
result.push((0, PDF_functions_1.formatText)(text._text, common_enum_1.default.Value));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if ((0, PDF_functions_1.getTable)(blok.Tabela).length) {
|
|
44
|
+
(0, PDF_functions_1.getTable)(blok.Tabela).forEach((tabela, index) => {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f;
|
|
46
|
+
if ((_a = blok.ZNaglowek) === null || _a === void 0 ? void 0 : _a._text) {
|
|
47
|
+
result.push((0, PDF_functions_1.createSubHeader)(`${(_b = blok.ZNaglowek) === null || _b === void 0 ? void 0 : _b._text} ${index + 1}`));
|
|
48
|
+
}
|
|
49
|
+
if ((_c = (0, PDF_functions_1.getTable)(tabela.TMetaDane)) === null || _c === void 0 ? void 0 : _c.length) {
|
|
50
|
+
result.push({
|
|
51
|
+
stack: generateKluczWartosc((0, PDF_functions_1.getTable)(tabela.TMetaDane).map((item) => ({
|
|
52
|
+
ZKlucz: item.TKlucz,
|
|
53
|
+
ZWartosc: item.TWartosc,
|
|
54
|
+
}))),
|
|
55
|
+
margin: [0, 8, 0, 0],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (tabela.Opis) {
|
|
59
|
+
result.push((0, PDF_functions_1.createLabelText)('Opis: ', tabela.Opis));
|
|
60
|
+
}
|
|
61
|
+
if ((0, PDF_functions_1.getTable)((_d = tabela.TNaglowek) === null || _d === void 0 ? void 0 : _d.Kol).length) {
|
|
62
|
+
result.push((0, PDF_functions_1.formatText)('Tabela', [common_enum_1.default.GrayBoldTitle, common_enum_1.default.LabelSmallMargin]));
|
|
63
|
+
result.push(generateTable(tabela));
|
|
64
|
+
}
|
|
65
|
+
if ((0, PDF_functions_1.getTable)((_e = tabela.Suma) === null || _e === void 0 ? void 0 : _e.SKom).length) {
|
|
66
|
+
result.push(generateSuma((0, PDF_functions_1.getTable)((_f = tabela.Suma) === null || _f === void 0 ? void 0 : _f.SKom)));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (content.fieldsWithValue.length && content.content) {
|
|
72
|
+
result.push(content.content);
|
|
73
|
+
}
|
|
74
|
+
return (0, PDF_functions_1.createSection)(result, false);
|
|
75
|
+
}
|
|
76
|
+
function generateKluczWartosc(data) {
|
|
77
|
+
const result = [];
|
|
78
|
+
const definedHeader = [
|
|
79
|
+
{ name: 'ZKlucz', title: 'Klucz', format: common_enum_1.default.Default },
|
|
80
|
+
{ name: 'ZWartosc', title: 'Wartość', format: common_enum_1.default.Default },
|
|
81
|
+
];
|
|
82
|
+
const faWiersze = (0, PDF_functions_1.getTable)(data !== null && data !== void 0 ? data : []);
|
|
83
|
+
const content = (0, PDF_functions_1.getContentTable)([...definedHeader], faWiersze, '*');
|
|
84
|
+
if (content.fieldsWithValue.length && content.content) {
|
|
85
|
+
result.push(content.content);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
function generateTable(tabela) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
if (!((_b = (_a = tabela.TNaglowek) === null || _a === void 0 ? void 0 : _a.Kol) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const result = [];
|
|
95
|
+
const Kol = (0, PDF_functions_1.getTable)(tabela.TNaglowek.Kol);
|
|
96
|
+
const cutedTableHeader = chunkArray(Kol);
|
|
97
|
+
cutedTableHeader.forEach((table, index) => {
|
|
98
|
+
var _a;
|
|
99
|
+
result.push(createTable(table, (_a = tabela.Wiersz) !== null && _a !== void 0 ? _a : [], index, Kol.length));
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function createTable(cols, rows, subTableIndex, totalLength) {
|
|
104
|
+
const definedHeader = cols.map((item) => { var _a; return (0, PDF_functions_1.formatText)((_a = item.NKom) === null || _a === void 0 ? void 0 : _a._text, common_enum_1.default.GrayBoldTitle); });
|
|
105
|
+
const tableBody = [];
|
|
106
|
+
rows.forEach((item) => {
|
|
107
|
+
const WKom = (0, PDF_functions_1.getTable)(item.WKom);
|
|
108
|
+
while (WKom.length < totalLength) {
|
|
109
|
+
WKom.push({ _text: '' });
|
|
110
|
+
}
|
|
111
|
+
const cuttedRows = chunkArray(WKom !== null && WKom !== void 0 ? WKom : []);
|
|
112
|
+
if (cuttedRows.length >= subTableIndex + 1) {
|
|
113
|
+
tableBody.push(cuttedRows[subTableIndex].map((subItem, index) => {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
return (0, PDF_functions_1.formatText)((_a = subItem._text) !== null && _a !== void 0 ? _a : '', ((_b = cols[index]._attributes) === null || _b === void 0 ? void 0 : _b.Typ) ? const_1.TableDataType[cols[index]._attributes.Typ] : common_enum_1.default.Value);
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const widths = definedHeader.map((index) => {
|
|
120
|
+
if (index) {
|
|
121
|
+
return ['*'];
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return ['auto'];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
table: {
|
|
129
|
+
headerRows: 1,
|
|
130
|
+
widths: [...widths],
|
|
131
|
+
heights: 8,
|
|
132
|
+
body: [[...definedHeader], ...tableBody],
|
|
133
|
+
},
|
|
134
|
+
layout: const_1.DEFAULT_TABLE_LAYOUT,
|
|
135
|
+
marginTop: 8,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function generateSuma(data) {
|
|
139
|
+
const result = [];
|
|
140
|
+
const definedHeader = [
|
|
141
|
+
{ name: '', title: 'Podsumowanie tabeli', format: common_enum_1.default.Default },
|
|
142
|
+
];
|
|
143
|
+
const faWiersze = (0, PDF_functions_1.getTable)(data !== null && data !== void 0 ? data : []);
|
|
144
|
+
const content = (0, PDF_functions_1.getContentTable)([...definedHeader], faWiersze, '*', [0, 8, 0, 0]);
|
|
145
|
+
if (content.fieldsWithValue.length && content.content) {
|
|
146
|
+
result.push(content.content);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
function chunkArray(columns) {
|
|
151
|
+
if (!Array.isArray(columns)) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const n = columns.length;
|
|
155
|
+
if (n <= 7) {
|
|
156
|
+
return [columns];
|
|
157
|
+
}
|
|
158
|
+
else if (n >= 8 && n <= 14) {
|
|
159
|
+
const half = Math.floor(n / 2);
|
|
160
|
+
if (n % 2 === 0) {
|
|
161
|
+
return [columns.slice(0, half), columns.slice(half)];
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return [columns.slice(0, half + 1), columns.slice(half + 1)];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const base = Math.floor(n / 3);
|
|
169
|
+
const remainder = n % 3;
|
|
170
|
+
const splits = [base, base, base];
|
|
171
|
+
for (let i = 0; i < remainder; i++) {
|
|
172
|
+
splits[i] += 1;
|
|
173
|
+
}
|
|
174
|
+
const result = [];
|
|
175
|
+
let idx = 0;
|
|
176
|
+
for (const size of splits) {
|
|
177
|
+
result.push(columns.slice(idx, idx + size));
|
|
178
|
+
idx += size;
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
}
|
package/package.json
CHANGED
|
@@ -128,13 +128,18 @@ function generateTable(tabela: Tabela): Content[] {
|
|
|
128
128
|
return result;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function createTable(
|
|
131
|
+
function createTable(
|
|
132
|
+
cols: Kol[],
|
|
133
|
+
rows: Wiersz | Wiersz[],
|
|
134
|
+
subTableIndex: number,
|
|
135
|
+
totalLength: number
|
|
136
|
+
): ContentTable {
|
|
132
137
|
const definedHeader: Content[] = cols.map((item: Kol): string | ContentText =>
|
|
133
138
|
formatText(item.NKom?._text, FormatTyp.GrayBoldTitle)
|
|
134
139
|
);
|
|
135
140
|
const tableBody: TableCell[] = [];
|
|
136
141
|
|
|
137
|
-
rows.forEach((item: Wiersz): void => {
|
|
142
|
+
getTable(rows).forEach((item: Wiersz): void => {
|
|
138
143
|
const WKom: FP[] = getTable(item.WKom);
|
|
139
144
|
|
|
140
145
|
while (WKom.length < totalLength) {
|
|
@@ -149,7 +154,7 @@ function createTable(cols: Kol[], rows: Wiersz[], subTableIndex: number, totalLe
|
|
|
149
154
|
return formatText(
|
|
150
155
|
subItem._text ?? '',
|
|
151
156
|
cols[index]._attributes?.Typ ? TableDataType[cols[index]._attributes.Typ] : FormatTyp.Value
|
|
152
|
-
) as TableCell
|
|
157
|
+
) as TableCell;
|
|
153
158
|
})
|
|
154
159
|
);
|
|
155
160
|
}
|
|
@@ -206,9 +211,9 @@ export function chunkArray<T>(columns: T[]): T[][] {
|
|
|
206
211
|
const half: number = Math.floor(n / 2);
|
|
207
212
|
|
|
208
213
|
if (n % 2 === 0) {
|
|
209
|
-
return [columns.slice(0, half), columns.slice(half)];
|
|
214
|
+
return [columns.slice(0, half), [columns[0], ...columns.slice(half)]];
|
|
210
215
|
} else {
|
|
211
|
-
return [columns.slice(0, half + 1), columns.slice(half + 1)];
|
|
216
|
+
return [columns.slice(0, half + 1), [columns[0], ...columns.slice(half + 1)]];
|
|
212
217
|
}
|
|
213
218
|
} else {
|
|
214
219
|
const base: number = Math.floor(n / 3);
|
|
@@ -227,6 +232,8 @@ export function chunkArray<T>(columns: T[]): T[][] {
|
|
|
227
232
|
result.push(columns.slice(idx, idx + size));
|
|
228
233
|
idx += size;
|
|
229
234
|
}
|
|
235
|
+
result[1].unshift(columns[0]);
|
|
236
|
+
result[2].unshift(columns[0]);
|
|
230
237
|
return result;
|
|
231
238
|
}
|
|
232
|
-
}
|
|
239
|
+
}
|