makeapps-transformer 1.0.7 → 1.0.9

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.
@@ -70,7 +70,7 @@ function generateWiersze(faVat) {
70
70
  { name: 'P_11A', title: 'Wartość sprzedaży brutto', format: common_enum_1.default.Currency, width: 'auto' },
71
71
  { name: 'P_11Vat', title: 'Wartość sprzedaży vat', format: common_enum_1.default.Currency, width: 'auto' },
72
72
  { name: 'KursWaluty', title: 'Kurs waluty', format: common_enum_1.default.Currency6, width: 'auto' },
73
- { name: 'StanPrzed', title: 'Stan przed', format: common_enum_1.default.Boolean, width: 'auto' },
73
+ { name: 'StanPrzed', title: 'Stan przed', format: common_enum_1.default.Boolean, width: 'auto' }
74
74
  ];
75
75
  const definedHeader2 = [
76
76
  { name: 'GTIN', title: 'GTIN', format: common_enum_1.default.Default, width: 'auto' },
@@ -49,6 +49,7 @@ exports.getTable = getTable;
49
49
  exports.getRowTable = getRowTable;
50
50
  exports.hasColumnsValue = hasColumnsValue;
51
51
  exports.getDifferentColumnsValue = getDifferentColumnsValue;
52
+ exports.makeBreakable = makeBreakable;
52
53
  exports.getContentTable = getContentTable;
53
54
  exports.generateTwoColumns = generateTwoColumns;
54
55
  exports.generateQRCode = generateQRCode;
@@ -347,6 +348,30 @@ function getDifferentColumnsValue(name, data) {
347
348
  });
348
349
  return result;
349
350
  }
351
+ function makeBreakable(value, wordBreak = 40) {
352
+ if (typeof value === 'string') {
353
+ const words = value.split(/\s+/);
354
+ const lines = [];
355
+ let currentLine = '';
356
+ for (const word of words) {
357
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
358
+ if (testLine.length <= wordBreak) {
359
+ currentLine = testLine;
360
+ }
361
+ else {
362
+ if (currentLine) {
363
+ lines.push(currentLine);
364
+ }
365
+ currentLine = word;
366
+ }
367
+ }
368
+ if (currentLine) {
369
+ lines.push(currentLine);
370
+ }
371
+ return lines.join('\u200B');
372
+ }
373
+ return value;
374
+ }
350
375
  function getContentTable(headers, data, defaultWidths, margin) {
351
376
  const fieldsWithValue = headers.filter((header) => {
352
377
  return data.some((d) => {
@@ -373,7 +398,7 @@ function getContentTable(headers, data, defaultWidths, margin) {
373
398
  var _a, _b;
374
399
  const fp = (header.name ? row[header.name] : row);
375
400
  const value = typeof fp === 'object' ? fp === null || fp === void 0 ? void 0 : fp._text : fp;
376
- return formatText(header.mappingData && value ? header.mappingData[value] : (value !== null && value !== void 0 ? value : ''), (_a = header.format) !== null && _a !== void 0 ? _a : common_enum_1.default.Default, { rowSpan: (_b = fp === null || fp === void 0 ? void 0 : fp._rowSpan) !== null && _b !== void 0 ? _b : 1 });
401
+ return formatText(makeBreakable(header.mappingData && value ? header.mappingData[value] : (value !== null && value !== void 0 ? value : ''), 40), (_a = header.format) !== null && _a !== void 0 ? _a : common_enum_1.default.Default, { rowSpan: (_b = fp === null || fp === void 0 ? void 0 : fp._rowSpan) !== null && _b !== void 0 ? _b : 1 });
377
402
  });
378
403
  });
379
404
  return {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "makeapps-transformer",
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.ts",
5
- "version": "1.0.7",
5
+ "version": "1.0.9",
6
6
  "scripts": {
7
7
  "build": "tsc"
8
8
  },
@@ -23,7 +23,7 @@ import { AdditionalDataTypes } from './types/common.types';
23
23
 
24
24
  pdfMake.vfs = pdfFonts.vfs;
25
25
 
26
- export function generateFA3(invoice: Faktura, additionalData: AdditionalDataTypes): TCreatedPdf {
26
+ export function generateFA3(invoice: Faktura, additionalData: AdditionalDataTypes): TCreatedPdf {
27
27
  const isKOR_RABAT: boolean =
28
28
  invoice.Fa?.RodzajFaktury?._text == TRodzajFaktury.KOR && hasValue(invoice.Fa?.OkresFaKorygowanej);
29
29
  const rabatOrRowsInvoice: Content = isKOR_RABAT ? generateRabat(invoice.Fa!) : generateWiersze(invoice.Fa!);
@@ -7,7 +7,7 @@ import { AdditionalDataTypes } from './types/common.types';
7
7
  export async function generateInvoice(
8
8
  xmlString: string,
9
9
  additionalData: AdditionalDataTypes
10
- ) {
10
+ ) {
11
11
  const xml = parseXML(xmlString);
12
12
  const wersja: any = xml.Faktura?.Naglowek?.KodFormularza?._attributes?.kodSystemowy;
13
13
 
@@ -14,7 +14,7 @@ import { Fa, FP } from '../../types/fa3.types';
14
14
  import FormatTyp, { Position } from '../../../shared/enums/common.enum';
15
15
  import { shouldAddMarza } from '../common/Wiersze';
16
16
 
17
- export function generateWiersze(faVat: Fa): Content {
17
+ export function generateWiersze(faVat: Fa): Content {
18
18
  const table: Content[] = [];
19
19
  const rodzajFaktury: string | number | undefined = getValue(faVat.RodzajFaktury);
20
20
  const isP_PMarzy: boolean = Boolean(Number(getValue(faVat.Adnotacje?.PMarzy?.P_PMarzy)));
@@ -27,7 +27,7 @@ export function generateWiersze(faVat: Fa): Content {
27
27
  const definedHeaderLp: HeaderDefine[] = [
28
28
  { name: 'NrWierszaFa', title: 'Lp.', format: FormatTyp.Default, width: 'auto' },
29
29
  ];
30
- const definedHeader1: HeaderDefine[] = [
30
+ const definedHeader1: HeaderDefine[] = [
31
31
  { name: 'UU_ID', title: 'Unikalny numer wiersza', format: FormatTyp.Default, width: 'auto' },
32
32
  { name: 'P_7', title: 'Nazwa towaru lub usługi', format: FormatTyp.Default, width: '*' },
33
33
  { name: 'P_9A', title: 'Cena jedn. netto', format: FormatTyp.Currency, width: 'auto' },
@@ -47,7 +47,7 @@ export function generateWiersze(faVat: Fa): Content {
47
47
  { name: 'P_11A', title: 'Wartość sprzedaży brutto', format: FormatTyp.Currency, width: 'auto' },
48
48
  { name: 'P_11Vat', title: 'Wartość sprzedaży vat', format: FormatTyp.Currency, width: 'auto' },
49
49
  { name: 'KursWaluty', title: 'Kurs waluty', format: FormatTyp.Currency6, width: 'auto' },
50
- { name: 'StanPrzed', title: 'Stan przed', format: FormatTyp.Boolean, width: 'auto' },
50
+ { name: 'StanPrzed', title: 'Stan przed', format: FormatTyp.Boolean, width: 'auto' }
51
51
  ];
52
52
  const definedHeader2: HeaderDefine[] = [
53
53
  { name: 'GTIN', title: 'GTIN', format: FormatTyp.Default, width: 'auto' },
@@ -361,6 +361,38 @@ export function getDifferentColumnsValue<T, K extends FilteredKeysOfValues<T>>(
361
361
  return result;
362
362
  }
363
363
 
364
+ export function makeBreakable(
365
+ value: string | number | undefined,
366
+ wordBreak = 40
367
+ ): string | number | undefined {
368
+ if (typeof value === 'string') {
369
+ const words = value.split(/\s+/);
370
+ const lines: string[] = [];
371
+ let currentLine = '';
372
+
373
+ for (const word of words) {
374
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
375
+
376
+ if (testLine.length <= wordBreak) {
377
+ currentLine = testLine;
378
+ } else {
379
+ if (currentLine) {
380
+ lines.push(currentLine);
381
+ }
382
+ currentLine = word;
383
+ }
384
+ }
385
+
386
+ if (currentLine) {
387
+ lines.push(currentLine);
388
+ }
389
+
390
+ return lines.join('\u200B');
391
+ }
392
+
393
+ return value;
394
+ }
395
+
364
396
  export function getContentTable<T>(
365
397
  headers: HeaderDefine[],
366
398
  data: T[],
@@ -370,7 +402,7 @@ export function getContentTable<T>(
370
402
  const fieldsWithValue: HeaderDefine[] = headers.filter((header: HeaderDefine): boolean => {
371
403
  return data.some((d: T): boolean => {
372
404
  const name = header.name as keyof T;
373
-
405
+
374
406
  if (name === '' && (d as FP)?._text) {
375
407
  return true;
376
408
  }
@@ -401,7 +433,7 @@ export function getContentTable<T>(
401
433
  const value: string | undefined = typeof fp === 'object' ? fp?._text : fp;
402
434
 
403
435
  return formatText(
404
- header.mappingData && value ? header.mappingData[value] : (value ?? ''),
436
+ makeBreakable(header.mappingData && value ? header.mappingData[value] : (value ?? ''), 40),
405
437
  header.format ?? FormatTyp.Default,
406
438
  { rowSpan: fp?._rowSpan ?? 1 }
407
439
  );
@@ -436,12 +468,12 @@ export function generateTwoColumns(kol1: Column, kol2: Column, margin?: Margins)
436
468
  export function generateQRCode(qrCode?: string): ContentQr | undefined {
437
469
  return qrCode
438
470
  ? {
439
- qr: qrCode,
440
- fit: 150,
441
- foreground: 'black',
442
- background: 'white',
443
- eccLevel: 'M',
444
- }
471
+ qr: qrCode,
472
+ fit: 150,
473
+ foreground: 'black',
474
+ background: 'white',
475
+ eccLevel: 'M',
476
+ }
445
477
  : undefined;
446
478
  }
447
479
 
@@ -37,9 +37,9 @@
37
37
  "terminal.integrated.fontFamily": "Droid Sans Mono",
38
38
  "terminal.integrated.fontSize": 13,
39
39
  "window.autoDetectColorScheme": true,
40
- "workbench.preferredDarkColorTheme": "Default Dark+",
41
- "workbench.preferredHighContrastColorTheme": "Default Dark Modern",
42
- "workbench.preferredLightColorTheme": "Default Light+",
40
+ "workbench.preferredDarkColorTheme": "Dark+",
41
+ "workbench.preferredHighContrastColorTheme": "Dark Modern",
42
+ "workbench.preferredLightColorTheme": "Light+",
43
43
  "editor.stickyScroll.enabled": false
44
44
  }
45
45
  }
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- interface Data {
2
- nrKSeF: string;
3
- qrCode?: string;
4
- isMobile?: boolean;
5
- }
6
-
7
- export default function generateInvoice(xmlString: string, data: Data): Promise<string>;
@@ -1,182 +0,0 @@
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
- }