intelica-library-ui 0.1.53 → 0.1.55
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.
|
@@ -288,6 +288,7 @@ const ErrorInterceptor = (req, next) => {
|
|
|
288
288
|
const sweetAlertService = inject(SweetAlertService);
|
|
289
289
|
const configService = inject(ConfigService);
|
|
290
290
|
const HeaderSettings = {};
|
|
291
|
+
const authenticationClientID = configService.environment?.clientID ?? "";
|
|
291
292
|
if (!req.url.includes("environment.json")) {
|
|
292
293
|
HeaderSettings["Accept"] = "application/json";
|
|
293
294
|
HeaderSettings["Content-Type"] = "application/json";
|
|
@@ -296,6 +297,7 @@ const ErrorInterceptor = (req, next) => {
|
|
|
296
297
|
HeaderSettings["ClientID"] = configService.environment?.clientID ?? "";
|
|
297
298
|
HeaderSettings["PageRoot"] = commonFeatureFlagService.GetPageRoot();
|
|
298
299
|
HeaderSettings["LanguageCode"] = getCookie("language") ?? "";
|
|
300
|
+
HeaderSettings["Access"] = authenticationClientID == "" ? "" : getCookie(authenticationClientID) ?? "";
|
|
299
301
|
}
|
|
300
302
|
let _request = req.clone({ headers: new HttpHeaders(HeaderSettings) });
|
|
301
303
|
return next(_request).pipe(catchError(handleErrorResponse));
|
|
@@ -2378,7 +2380,7 @@ class HtmlToExcelService {
|
|
|
2378
2380
|
horizontal: "center",
|
|
2379
2381
|
wrapText: true,
|
|
2380
2382
|
};
|
|
2381
|
-
async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters) {
|
|
2383
|
+
async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, subtitles = [], showTotalRow = false) {
|
|
2382
2384
|
const workbook = new Workbook();
|
|
2383
2385
|
const worksheet = workbook.addWorksheet(reportTitle);
|
|
2384
2386
|
worksheet.views = [{ showGridLines: false }];
|
|
@@ -2386,7 +2388,7 @@ class HtmlToExcelService {
|
|
|
2386
2388
|
base64: this.Logo,
|
|
2387
2389
|
extension: "png",
|
|
2388
2390
|
});
|
|
2389
|
-
this.SetReportPage(rowsSerializate, worksheet, columns, imageId);
|
|
2391
|
+
this.SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles, showTotalRow);
|
|
2390
2392
|
this.SetTitle(worksheet, reportTitle);
|
|
2391
2393
|
if (filters.length > 0) {
|
|
2392
2394
|
const worksheetFilter = workbook.addWorksheet(filterTitle);
|
|
@@ -2408,27 +2410,68 @@ class HtmlToExcelService {
|
|
|
2408
2410
|
};
|
|
2409
2411
|
titleCell.alignment = { vertical: "middle", horizontal: "center" };
|
|
2410
2412
|
}
|
|
2411
|
-
SetReportPage(rowsSerializate, worksheet, columns, imageId) {
|
|
2413
|
+
SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles = [], showTotalRow = false) {
|
|
2412
2414
|
let columnsCell = [];
|
|
2413
2415
|
let cells = [];
|
|
2414
2416
|
let rows = JSON.parse(rowsSerializate);
|
|
2417
|
+
//Inserción de filas para imagen
|
|
2418
|
+
const imageRows = 5;
|
|
2415
2419
|
const numberRows = rows.length;
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
worksheet.addRow([""]);
|
|
2420
|
+
for (let i = 0; i < subtitles.length + imageRows; i++) {
|
|
2421
|
+
worksheet.addRow([""]);
|
|
2422
|
+
}
|
|
2423
|
+
//Inserción de nombre de columnas
|
|
2421
2424
|
let columnsNames = [];
|
|
2425
|
+
let startRow = imageRows + 1 + subtitles.length;
|
|
2422
2426
|
for (let i = 0; i < columns.length; i++) {
|
|
2423
|
-
let cell = `${String.fromCharCode(65 + i)}
|
|
2427
|
+
let cell = `${String.fromCharCode(65 + i)}${startRow}`;
|
|
2424
2428
|
columnsNames.push(columns[i].displayColumnName);
|
|
2425
2429
|
columnsCell.push(cell);
|
|
2426
2430
|
}
|
|
2427
2431
|
worksheet.addRow(columnsNames);
|
|
2432
|
+
//Inserción y formato de sumatorias
|
|
2433
|
+
if (showTotalRow) {
|
|
2434
|
+
const sums = columns.map(col => {
|
|
2435
|
+
if (!col.totalRowValue)
|
|
2436
|
+
return null;
|
|
2437
|
+
return rows.reduce((acc, row) => {
|
|
2438
|
+
const value = parseFloat(row[col.columnName]) || 0;
|
|
2439
|
+
return acc + value;
|
|
2440
|
+
}, 0);
|
|
2441
|
+
});
|
|
2442
|
+
const sumRow = columns.map((col, index) => {
|
|
2443
|
+
if (col.columnName === "")
|
|
2444
|
+
return "Total";
|
|
2445
|
+
if (!col.totalRowValue)
|
|
2446
|
+
return "";
|
|
2447
|
+
return (sums[index]?.toLocaleString(undefined, {
|
|
2448
|
+
minimumFractionDigits: 2,
|
|
2449
|
+
maximumFractionDigits: 2,
|
|
2450
|
+
}) || "0.00");
|
|
2451
|
+
});
|
|
2452
|
+
startRow = startRow + 1;
|
|
2453
|
+
worksheet.insertRow(startRow, sumRow);
|
|
2454
|
+
columns.forEach((col, index) => {
|
|
2455
|
+
const cellAddress = `${String.fromCharCode(65 + index)}${startRow}`;
|
|
2456
|
+
const cell = worksheet.getCell(cellAddress);
|
|
2457
|
+
cell.font = {
|
|
2458
|
+
name: "Arial",
|
|
2459
|
+
bold: true,
|
|
2460
|
+
size: 10,
|
|
2461
|
+
color: { argb: "FF7F00" },
|
|
2462
|
+
};
|
|
2463
|
+
cell.alignment = {
|
|
2464
|
+
vertical: "middle",
|
|
2465
|
+
horizontal: col.isNumber ? "right" : "left",
|
|
2466
|
+
};
|
|
2467
|
+
cell.border = { bottom: { style: "thin", color: { argb: "FF7F00" } } };
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
//Inserción de filas
|
|
2428
2471
|
for (let rowIndex = 0; rowIndex < numberRows; rowIndex++) {
|
|
2429
2472
|
let rowCells = [];
|
|
2430
2473
|
let rowValues = [];
|
|
2431
|
-
let index = rowIndex +
|
|
2474
|
+
let index = rowIndex + startRow + 1;
|
|
2432
2475
|
for (let columIndex = 0; columIndex < columns.length; columIndex++) {
|
|
2433
2476
|
let cell = `${String.fromCharCode(65 + columIndex)}${index}`;
|
|
2434
2477
|
rowCells.push(cell);
|
|
@@ -2441,6 +2484,7 @@ class HtmlToExcelService {
|
|
|
2441
2484
|
worksheet.addRow(rowValues);
|
|
2442
2485
|
cells.push({ index: index, cells: rowCells });
|
|
2443
2486
|
}
|
|
2487
|
+
//Formato nombre de columnas
|
|
2444
2488
|
columnsCell.map(key => {
|
|
2445
2489
|
worksheet.getCell(key).fill = {
|
|
2446
2490
|
type: "pattern",
|
|
@@ -2456,6 +2500,7 @@ class HtmlToExcelService {
|
|
|
2456
2500
|
};
|
|
2457
2501
|
worksheet.getCell(key).alignment = this.ColumnAligment;
|
|
2458
2502
|
});
|
|
2503
|
+
//Formato de filas
|
|
2459
2504
|
cells.forEach(element => {
|
|
2460
2505
|
element.cells.map(key => {
|
|
2461
2506
|
if (element.index % 2 !== 1) {
|
|
@@ -2474,12 +2519,29 @@ class HtmlToExcelService {
|
|
|
2474
2519
|
};
|
|
2475
2520
|
});
|
|
2476
2521
|
});
|
|
2522
|
+
//Logo intelica
|
|
2477
2523
|
worksheet.addImage(imageId, {
|
|
2478
2524
|
tl: { col: 0.5, row: 1.5 },
|
|
2479
2525
|
ext: { width: 218, height: 58 },
|
|
2480
2526
|
editAs: "absolute",
|
|
2481
2527
|
});
|
|
2482
2528
|
this.AdjustColumnWidth(worksheet, columns);
|
|
2529
|
+
//Subtitulos: Se inserta al final para evitar altere el autoajuste de las columnas
|
|
2530
|
+
for (let i = 0; i < subtitles.length; i++) {
|
|
2531
|
+
const range = `${String.fromCharCode(65)}${6 + i}:${String.fromCharCode(79)}${6 + i}`;
|
|
2532
|
+
worksheet.mergeCells(range);
|
|
2533
|
+
const cell = worksheet.getCell(`${String.fromCharCode(65)}${6 + i}`);
|
|
2534
|
+
const subtitle = subtitles[i];
|
|
2535
|
+
cell.value = subtitle;
|
|
2536
|
+
cell.font = {
|
|
2537
|
+
name: "Arial",
|
|
2538
|
+
bold: true,
|
|
2539
|
+
italic: true,
|
|
2540
|
+
size: 10,
|
|
2541
|
+
color: { argb: "203764" },
|
|
2542
|
+
};
|
|
2543
|
+
cell.alignment = { vertical: "middle", horizontal: "left", wrapText: true };
|
|
2544
|
+
}
|
|
2483
2545
|
}
|
|
2484
2546
|
SetFilterPage(filterTitle, worksheetFilter, filters) {
|
|
2485
2547
|
let widtFilter = 30;
|
|
@@ -2527,10 +2589,11 @@ class HtmlToExcelService {
|
|
|
2527
2589
|
worksheet.columns.forEach((column, index) => {
|
|
2528
2590
|
if (!column.values)
|
|
2529
2591
|
return;
|
|
2592
|
+
if (columns[index] == undefined)
|
|
2593
|
+
return;
|
|
2530
2594
|
let columnWidth = columns[index].width ?? Math.max(...column.values.map(v => (v ? v.toString().length : 0)).filter(v => typeof v === "number"), columns[index].displayColumnName.length) * 1.2;
|
|
2531
2595
|
column.width = Math.min(Math.max(columnWidth, 5), 100);
|
|
2532
2596
|
column.alignment = columns[index].isNumber ? { vertical: "middle", horizontal: "right", wrapText: true } : { vertical: "middle", horizontal: "left", wrapText: true };
|
|
2533
|
-
console.log(column.width, column);
|
|
2534
2597
|
});
|
|
2535
2598
|
worksheet.eachRow((row, rowIndex) => {
|
|
2536
2599
|
if (rowIndex === 1)
|
|
@@ -2548,6 +2611,46 @@ class HtmlToExcelService {
|
|
|
2548
2611
|
row.height = Math.min(Math.max(15 * maxLines, 15), 30);
|
|
2549
2612
|
});
|
|
2550
2613
|
}
|
|
2614
|
+
async ExportToExcelRawData({ excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, orderColumn = false }) {
|
|
2615
|
+
const workbook = new Workbook();
|
|
2616
|
+
const worksheet = workbook.addWorksheet(reportTitle);
|
|
2617
|
+
const rows = JSON.parse(rowsSerializate);
|
|
2618
|
+
worksheet.views = [{ showGridLines: false }];
|
|
2619
|
+
const allColumns = orderColumn ? [{ displayColumnName: "N°" }, ...columns] : columns;
|
|
2620
|
+
allColumns.forEach((col, index) => {
|
|
2621
|
+
const headerCell = worksheet.getCell(`${String.fromCharCode(65 + index)}1`);
|
|
2622
|
+
headerCell.value = col.displayColumnName;
|
|
2623
|
+
headerCell.alignment = { horizontal: "center", vertical: "middle" };
|
|
2624
|
+
headerCell.font = { name: "Arial", bold: true, size: 10 };
|
|
2625
|
+
});
|
|
2626
|
+
const maxLengths = allColumns.map(col => col.displayColumnName.length);
|
|
2627
|
+
rows.forEach((rowData, rowIndex) => {
|
|
2628
|
+
const rowValues = allColumns.map((col, colIndex) => {
|
|
2629
|
+
if (orderColumn && colIndex === 0) {
|
|
2630
|
+
return (rowIndex + 1).toString();
|
|
2631
|
+
}
|
|
2632
|
+
const originalColIndex = orderColumn ? colIndex - 1 : colIndex;
|
|
2633
|
+
return rowData[columns[originalColIndex].columnName]?.toString() || "";
|
|
2634
|
+
});
|
|
2635
|
+
rowValues.forEach((value, i) => {
|
|
2636
|
+
const length = value.length;
|
|
2637
|
+
if (length > maxLengths[i]) {
|
|
2638
|
+
maxLengths[i] = length;
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
worksheet.addRow(rowValues);
|
|
2642
|
+
});
|
|
2643
|
+
allColumns.forEach((_, index) => {
|
|
2644
|
+
worksheet.getColumn(index + 1).width = maxLengths[index] + 2;
|
|
2645
|
+
});
|
|
2646
|
+
if (filters?.length) {
|
|
2647
|
+
const worksheetFilter = workbook.addWorksheet(filterTitle);
|
|
2648
|
+
worksheetFilter.views = [{ showGridLines: false }];
|
|
2649
|
+
this.SetFilterPage(filterTitle, worksheetFilter, filters);
|
|
2650
|
+
}
|
|
2651
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
2652
|
+
saveAs(new Blob([buffer]), excelName);
|
|
2653
|
+
}
|
|
2551
2654
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2552
2655
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, providedIn: "root" });
|
|
2553
2656
|
}
|