@harbortouch/skytab-analytics-report-utils 0.32.0 → 0.34.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.
@@ -31,7 +31,11 @@ var CsvExporter = class {
31
31
  generate(rows) {
32
32
  const opts = { header: true, delimiter: ",", bom: true, ...this.options };
33
33
  if (!rows.length) {
34
- return opts.bom ? "\uFEFF" : "";
34
+ if (!opts.columns) {
35
+ return opts.bom ? "\uFEFF" : "";
36
+ }
37
+ const withHeader = (0, import_sync.stringify)([{}], opts);
38
+ return withHeader.split("\n").slice(0, 1).join("\n") + "\n";
35
39
  }
36
40
  return (0, import_sync.stringify)(rows, opts);
37
41
  }
@@ -7,7 +7,11 @@ var CsvExporter = class {
7
7
  generate(rows) {
8
8
  const opts = { header: true, delimiter: ",", bom: true, ...this.options };
9
9
  if (!rows.length) {
10
- return opts.bom ? "\uFEFF" : "";
10
+ if (!opts.columns) {
11
+ return opts.bom ? "\uFEFF" : "";
12
+ }
13
+ const withHeader = stringify([{}], opts);
14
+ return withHeader.split("\n").slice(0, 1).join("\n") + "\n";
11
15
  }
12
16
  return stringify(rows, opts);
13
17
  }
@@ -512,7 +512,10 @@ var enUS = {
512
512
  "table.groups.sales": "Sales",
513
513
  "table.groups.net-sales": "Net Sales",
514
514
  "table.groups.guests": "Guests",
515
- "table.groups.sales-per-guest": "Sales / Guest"
515
+ "table.groups.sales-per-guest": "Sales / Guest",
516
+ "employee-timecard.status.active": "Active",
517
+ "employee-timecard.status.inactive": "Inactive",
518
+ "employee-timecard.job.break-suffix": " * break"
516
519
  };
517
520
  var en_US_default = enUS;
518
521
 
@@ -1004,7 +1007,10 @@ var enUS2 = {
1004
1007
  "table.groups.sales": false,
1005
1008
  "table.groups.net-sales": false,
1006
1009
  "table.groups.guests": false,
1007
- "table.groups.sales-per-guest": false
1010
+ "table.groups.sales-per-guest": false,
1011
+ "employee-timecard.status.active": false,
1012
+ "employee-timecard.status.inactive": false,
1013
+ "employee-timecard.job.break-suffix": false
1008
1014
  };
1009
1015
  var en_GB_default = enUS2;
1010
1016
 
@@ -1496,7 +1502,10 @@ var enUS3 = {
1496
1502
  "table.groups.sales": false,
1497
1503
  "table.groups.net-sales": false,
1498
1504
  "table.groups.guests": false,
1499
- "table.groups.sales-per-guest": false
1505
+ "table.groups.sales-per-guest": false,
1506
+ "employee-timecard.status.active": false,
1507
+ "employee-timecard.status.inactive": false,
1508
+ "employee-timecard.job.break-suffix": false
1500
1509
  };
1501
1510
  var es_ES_default = enUS3;
1502
1511
 
@@ -1614,16 +1623,20 @@ var getReportFormattingLocaleOptions = (locations) => {
1614
1623
  );
1615
1624
  };
1616
1625
  var DEFAULT_FIELD_CONFIG = { type: "string" };
1617
- var formatFieldValue = (value, type, localeOptions, fullRecord, fieldConfig = DEFAULT_FIELD_CONFIG) => {
1626
+ var formatFieldValue = (value, type, localeOptions, fullRecord, fieldConfig = DEFAULT_FIELD_CONFIG, timezone, translationLocale) => {
1618
1627
  const { currency, locale } = localeOptions;
1619
1628
  switch (type) {
1629
+ case "custom": {
1630
+ const customConfig = fieldConfig.customConfiguration;
1631
+ return customConfig.customFormat(value, fullRecord ?? null, translationLocale);
1632
+ }
1620
1633
  case "conditional": {
1621
1634
  if (!fullRecord) {
1622
1635
  return formatString(value, localeOptions);
1623
1636
  }
1624
1637
  const conditionalConfig = fieldConfig.conditionalConfiguration;
1625
1638
  const configType = conditionalConfig.conditionalFormat(fullRecord[conditionalConfig.conditionalField]);
1626
- return formatFieldValue(value, configType, localeOptions, fullRecord, fieldConfig);
1639
+ return formatFieldValue(value, configType, localeOptions, fullRecord, fieldConfig, timezone, translationLocale);
1627
1640
  }
1628
1641
  case "string":
1629
1642
  return formatString(value, localeOptions);
@@ -1643,6 +1656,10 @@ var formatFieldValue = (value, type, localeOptions, fullRecord, fieldConfig = DE
1643
1656
  const d = getDateToFormat(value);
1644
1657
  return d ? formatTime(d, { locale, format: "00:00:00" }) : "";
1645
1658
  }
1659
+ case "time-with-time-zone": {
1660
+ const d = getDateToFormat(value);
1661
+ return d ? formatTime(d, { locale, format: "00:00:00", timeZone: timezone }) : "";
1662
+ }
1646
1663
  case "number-empty":
1647
1664
  return value != null ? String(getNumberToFormat(value)) : "";
1648
1665
  case "number":
@@ -2215,11 +2232,17 @@ var FIELDS8 = {
2215
2232
  footerCalculation: { type: "label", label: "table.total" }
2216
2233
  },
2217
2234
  isActive: {
2218
- type: "string",
2235
+ type: "custom",
2219
2236
  size: STATUS_WIDTH,
2220
2237
  columnKey: "status",
2221
2238
  enableSorting: false,
2222
- filteringAvailable: false
2239
+ filteringAvailable: false,
2240
+ customConfiguration: {
2241
+ customFormat: (value, _full, locale) => {
2242
+ const row = value;
2243
+ return row ? resolveTranslate("employee-timecard.status.active", locale) : resolveTranslate("employee-timecard.status.inactive", locale);
2244
+ }
2245
+ }
2223
2246
  },
2224
2247
  lookup: {
2225
2248
  type: "string",
@@ -2232,9 +2255,15 @@ var FIELDS8 = {
2232
2255
  columnKey: "payrollId"
2233
2256
  },
2234
2257
  jobName: {
2235
- type: "string",
2258
+ type: "custom",
2236
2259
  size: JOB_WIDTH,
2237
- columnKey: "employeeJob"
2260
+ columnKey: "employeeJob",
2261
+ customConfiguration: {
2262
+ customFormat: (value, original, locale) => {
2263
+ const job = typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? String(value) : "";
2264
+ return original?.isBreak ? `${job}${resolveTranslate("employee-timecard.job.break-suffix", locale)}` : job;
2265
+ }
2266
+ }
2238
2267
  },
2239
2268
  isBreak: {
2240
2269
  type: "string",
@@ -2242,11 +2271,11 @@ var FIELDS8 = {
2242
2271
  filteringAvailable: false
2243
2272
  },
2244
2273
  startTime: {
2245
- type: "time",
2274
+ type: "time-with-time-zone",
2246
2275
  columnKey: "clockInTime"
2247
2276
  },
2248
2277
  endTime: {
2249
- type: "time",
2278
+ type: "time-with-time-zone",
2250
2279
  columnKey: "clockOutTime"
2251
2280
  },
2252
2281
  shiftHours: {
@@ -3426,7 +3455,7 @@ function getColumnExportHeaderLabel(colTitle, groupTitle) {
3426
3455
  var sumField = (rows, field) => rows.reduce((acc, row) => acc + (row[field] ?? 0), 0);
3427
3456
  var getFooterValue = (rows, field, config) => {
3428
3457
  const { type } = config;
3429
- if (!type || type === "date" || type === "time" || type === "boolean" || type === "conditional") {
3458
+ if (!type || type === "date" || type === "time" || type === "boolean" || type === "conditional" || type === "custom") {
3430
3459
  return null;
3431
3460
  }
3432
3461
  const calc = config.footerCalculation;
@@ -3486,6 +3515,7 @@ var ExportBuilder = class {
3486
3515
  this.reportType = reportType;
3487
3516
  this.locations = locations;
3488
3517
  this.locale = locale;
3518
+ this.translationLocale = locale;
3489
3519
  }
3490
3520
  getFormattingConfig() {
3491
3521
  const configs = getReportFormattingLocaleOptions(this.locations);
@@ -3558,16 +3588,18 @@ var ExportBuilder = class {
3558
3588
  const columnTypes = columns.map((col) => config.fields[col]);
3559
3589
  return { columns, headers, columnTypes };
3560
3590
  }
3561
- formatField(value, config, localeOption, fullRecord) {
3591
+ formatField(value, config, fullRecord) {
3562
3592
  if (!config || value === void 0 || value === null) {
3563
3593
  return "";
3564
3594
  }
3565
- return formatFieldValue(value, config.type, localeOption, fullRecord, config);
3595
+ const localeOption = this.getFormattingConfig();
3596
+ const timezone = (fullRecord?.locationId ? this.locations.find((l) => l.id === fullRecord.locationId)?.timezone : void 0) ?? this.locations[0]?.timezone ?? "UTC";
3597
+ return formatFieldValue(value, config.type, localeOption, fullRecord, config, timezone, this.translationLocale);
3566
3598
  }
3567
- formatRow(raw, columns, columnTypes, localeConfig, fullRecord) {
3599
+ formatRow(raw, columns, columnTypes, fullRecord) {
3568
3600
  const formatted = {};
3569
3601
  columns.forEach((col, i) => {
3570
- formatted[col] = this.formatField(raw[col], columnTypes[i], localeConfig, fullRecord);
3602
+ formatted[col] = this.formatField(raw[col], columnTypes[i], fullRecord);
3571
3603
  });
3572
3604
  return formatted;
3573
3605
  }
@@ -3597,19 +3629,18 @@ var ExportBuilder = class {
3597
3629
  return [];
3598
3630
  }
3599
3631
  renderTableContent(config, reportData, parameters) {
3600
- const localeConfig = this.getFormattingConfig();
3601
3632
  const data = this.getDataForConfig(reportData, config);
3602
3633
  const { columns, headers, columnTypes } = this.resolveColumnsAndHeaders(parameters, config);
3603
3634
  const tableColumns = columns.map((col, i) => ({ header: headers[i], key: col }));
3604
- const rows = data.filter((row) => typeof row === "object" && row !== null).map((row) => this.formatRow(row, columns, columnTypes, localeConfig, row));
3635
+ const rows = data.filter((row) => typeof row === "object" && row !== null).map((row) => this.formatRow(row, columns, columnTypes, row));
3605
3636
  if (config.hasFooter) {
3606
3637
  const totalsRow = this.buildTotalsRow(data, config);
3607
3638
  if (totalsRow) {
3608
- rows.push(this.formatRow(totalsRow, columns, columnTypes, localeConfig, null));
3639
+ rows.push(this.formatRow(totalsRow, columns, columnTypes, null));
3609
3640
  }
3610
3641
  }
3611
3642
  for (const extraRow of this.getExtraFooterRows(reportData, config, data)) {
3612
- rows.push(this.formatRow(extraRow, columns, columnTypes, localeConfig, extraRow));
3643
+ rows.push(this.formatRow(extraRow, columns, columnTypes, extraRow));
3613
3644
  }
3614
3645
  return { table: { columns: tableColumns, rows } };
3615
3646
  }
@@ -1,4 +1,4 @@
1
- import { R as ReportType, A as AnalyticsField } from '../report-07XHPnMh.cjs';
1
+ import { R as ReportType, A as AnalyticsField } from '../report-DOgRgflg.cjs';
2
2
  import { E as ExportSection } from '../types-BPT5hjCR.cjs';
3
3
 
4
4
  type ReportDocumentSection = ExportSection;
@@ -27,6 +27,7 @@ declare class ExportBuilder {
27
27
  private readonly reportType;
28
28
  private readonly locations;
29
29
  private readonly locale;
30
+ private readonly translationLocale;
30
31
  constructor(reportType: ReportType, locations: ReportLocation[], locale: string);
31
32
  private getFormattingConfig;
32
33
  private getConfig;
@@ -1,4 +1,4 @@
1
- import { R as ReportType, A as AnalyticsField } from '../report-07XHPnMh.js';
1
+ import { R as ReportType, A as AnalyticsField } from '../report-DOgRgflg.js';
2
2
  import { E as ExportSection } from '../types-BPT5hjCR.js';
3
3
 
4
4
  type ReportDocumentSection = ExportSection;
@@ -27,6 +27,7 @@ declare class ExportBuilder {
27
27
  private readonly reportType;
28
28
  private readonly locations;
29
29
  private readonly locale;
30
+ private readonly translationLocale;
30
31
  constructor(reportType: ReportType, locations: ReportLocation[], locale: string);
31
32
  private getFormattingConfig;
32
33
  private getConfig;
@@ -7,7 +7,7 @@ import {
7
7
  getReportConfig,
8
8
  getReportFormattingLocaleOptions,
9
9
  resolveTranslate
10
- } from "../chunk-WGCCNROK.js";
10
+ } from "../chunk-IDZ2K4TG.js";
11
11
 
12
12
  // src/exporters/exportBuilder.ts
13
13
  import { format, isValid, parseISO } from "date-fns";
@@ -16,6 +16,7 @@ var ExportBuilder = class {
16
16
  this.reportType = reportType;
17
17
  this.locations = locations;
18
18
  this.locale = locale;
19
+ this.translationLocale = locale;
19
20
  }
20
21
  getFormattingConfig() {
21
22
  const configs = getReportFormattingLocaleOptions(this.locations);
@@ -88,16 +89,18 @@ var ExportBuilder = class {
88
89
  const columnTypes = columns.map((col) => config.fields[col]);
89
90
  return { columns, headers, columnTypes };
90
91
  }
91
- formatField(value, config, localeOption, fullRecord) {
92
+ formatField(value, config, fullRecord) {
92
93
  if (!config || value === void 0 || value === null) {
93
94
  return "";
94
95
  }
95
- return formatFieldValue(value, config.type, localeOption, fullRecord, config);
96
+ const localeOption = this.getFormattingConfig();
97
+ const timezone = (fullRecord?.locationId ? this.locations.find((l) => l.id === fullRecord.locationId)?.timezone : void 0) ?? this.locations[0]?.timezone ?? "UTC";
98
+ return formatFieldValue(value, config.type, localeOption, fullRecord, config, timezone, this.translationLocale);
96
99
  }
97
- formatRow(raw, columns, columnTypes, localeConfig, fullRecord) {
100
+ formatRow(raw, columns, columnTypes, fullRecord) {
98
101
  const formatted = {};
99
102
  columns.forEach((col, i) => {
100
- formatted[col] = this.formatField(raw[col], columnTypes[i], localeConfig, fullRecord);
103
+ formatted[col] = this.formatField(raw[col], columnTypes[i], fullRecord);
101
104
  });
102
105
  return formatted;
103
106
  }
@@ -127,19 +130,18 @@ var ExportBuilder = class {
127
130
  return [];
128
131
  }
129
132
  renderTableContent(config, reportData, parameters) {
130
- const localeConfig = this.getFormattingConfig();
131
133
  const data = this.getDataForConfig(reportData, config);
132
134
  const { columns, headers, columnTypes } = this.resolveColumnsAndHeaders(parameters, config);
133
135
  const tableColumns = columns.map((col, i) => ({ header: headers[i], key: col }));
134
- const rows = data.filter((row) => typeof row === "object" && row !== null).map((row) => this.formatRow(row, columns, columnTypes, localeConfig, row));
136
+ const rows = data.filter((row) => typeof row === "object" && row !== null).map((row) => this.formatRow(row, columns, columnTypes, row));
135
137
  if (config.hasFooter) {
136
138
  const totalsRow = this.buildTotalsRow(data, config);
137
139
  if (totalsRow) {
138
- rows.push(this.formatRow(totalsRow, columns, columnTypes, localeConfig, null));
140
+ rows.push(this.formatRow(totalsRow, columns, columnTypes, null));
139
141
  }
140
142
  }
141
143
  for (const extraRow of this.getExtraFooterRows(reportData, config, data)) {
142
- rows.push(this.formatRow(extraRow, columns, columnTypes, localeConfig, extraRow));
144
+ rows.push(this.formatRow(extraRow, columns, columnTypes, extraRow));
143
145
  }
144
146
  return { table: { columns: tableColumns, rows } };
145
147
  }