@harbortouch/skytab-analytics-report-utils 0.8.2 → 0.9.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.
package/dist/index.cjs CHANGED
@@ -509,7 +509,16 @@ var FIELDS6 = {
509
509
  orderTypeName: { type: "string", columnKey: "orderType", filteringAvailable: false },
510
510
  taxName: { type: "string", columnKey: "taxName", filteringAvailable: false },
511
511
  taxValue: { type: "money", columnKey: "taxableSales" },
512
- taxRate: { type: "number", columnKey: "taxRate" },
512
+ taxRate: {
513
+ type: "conditional",
514
+ columnKey: "taxRate",
515
+ conditionalConfiguration: {
516
+ conditionalField: "taxIsFlat",
517
+ conditionalFormat: (field) => {
518
+ return field ? "money" : "percent";
519
+ }
520
+ }
521
+ },
513
522
  recordsCount: { type: "number", columnKey: "quantity" },
514
523
  taxableSales: { type: "money", columnKey: "taxableSales" },
515
524
  totalCollected: { type: "money", columnKey: "totalCollected" },
@@ -1720,9 +1729,18 @@ var getReportFormattingLocaleOptions = (locations) => {
1720
1729
  ).values()
1721
1730
  );
1722
1731
  };
1723
- var formatFieldValue = (value, type, localeOptions) => {
1732
+ var DEFAULT_FIELD_CONFIG = { type: "string" };
1733
+ var formatFieldValue = (value, type, localeOptions, fullRecord, fieldConfig = DEFAULT_FIELD_CONFIG) => {
1724
1734
  const { currency, locale } = localeOptions;
1725
1735
  switch (type) {
1736
+ case "conditional": {
1737
+ if (!fullRecord) {
1738
+ return formatString(value);
1739
+ }
1740
+ const conditionalConfig = fieldConfig.conditionalConfiguration;
1741
+ const configType = conditionalConfig.conditionalFormat(fullRecord[conditionalConfig.conditionalField]);
1742
+ return formatFieldValue(value, configType, localeOptions, fullRecord, fieldConfig);
1743
+ }
1726
1744
  case "string":
1727
1745
  return formatString(value);
1728
1746
  case "money":
package/dist/index.d.cts CHANGED
@@ -1179,7 +1179,7 @@ declare function getColumnMetadata(key: ReportColumnKey): {
1179
1179
  };
1180
1180
  declare function getColumnExportHeaderLabel(colTitle: string, groupTitle: string | null): string;
1181
1181
 
1182
- type FieldType = 'string' | 'money' | 'percent' | 'number' | 'fixedNumber' | 'date' | 'time' | 'boolean';
1182
+ type FieldType = 'string' | 'money' | 'percent' | 'number' | 'fixedNumber' | 'date' | 'time' | 'boolean' | 'conditional';
1183
1183
  type ColumnAlignment = 'left' | 'right';
1184
1184
  type FooterCalculationType = 'sum' | 'percentChange' | 'average' | 'none';
1185
1185
  interface FooterCalculation<TField = string> {
@@ -1187,14 +1187,24 @@ interface FooterCalculation<TField = string> {
1187
1187
  numeratorField?: TField;
1188
1188
  denominatorField?: TField;
1189
1189
  }
1190
- interface ColumnPresentationConfig<TField = string> {
1190
+ interface ConditionalConfiguration<TField = string> {
1191
+ conditionalField: TField;
1192
+ conditionalFormat: (value: unknown) => Exclude<FieldType, 'conditional'>;
1193
+ }
1194
+ interface BaseColumnPresentationConfig<TField = string> {
1191
1195
  columnKey?: ReportColumnKey;
1192
- type: FieldType;
1193
1196
  size?: number;
1194
1197
  enableSorting?: boolean;
1195
1198
  filteringAvailable?: boolean;
1196
1199
  footerCalculation?: FooterCalculation<TField>;
1197
1200
  }
1201
+ type ColumnPresentationConfig<TField = string> = (BaseColumnPresentationConfig<TField> & {
1202
+ type: Exclude<FieldType, 'conditional'>;
1203
+ conditionalConfiguration?: never;
1204
+ }) | (BaseColumnPresentationConfig<TField> & {
1205
+ type: 'conditional';
1206
+ conditionalConfiguration: ConditionalConfiguration<TField>;
1207
+ });
1198
1208
  interface ColumnGroupConfig {
1199
1209
  id: string;
1200
1210
  headerTranslationKey: string;
@@ -1342,6 +1352,6 @@ declare const getReportFormattingLocaleOptions: (locations: {
1342
1352
  countryCode: string;
1343
1353
  language: string;
1344
1354
  }[]) => LocaleOption[];
1345
- declare const formatFieldValue: (value: unknown, type: FieldType, localeOptions: LocaleOption) => string;
1355
+ declare const formatFieldValue: (value: unknown, type: FieldType, localeOptions: LocaleOption, fullRecord: Record<string, unknown> | null, fieldConfig?: ColumnPresentationConfig) => string;
1346
1356
 
1347
1357
  export { COLUMN_REGISTRY, type CalculateReportTotalsOptions, type ColumnAlignment, type ColumnGroupConfig, type ColumnMetadata, type ColumnPresentationConfig, DAILY_SALES_AVAILABLE_COLUMNS, DAILY_SALES_BY_GROUP_AVAILABLE_COLUMNS, DAILY_SALES_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_DISCOUNTS_AVAILABLE_COLUMNS, DAILY_SALES_DISCOUNTS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_PAYMENTS_AVAILABLE_COLUMNS, DAILY_SALES_PAYMENTS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_REFUNDS_VOIDS_AVAILABLE_COLUMNS, DAILY_SALES_REFUNDS_VOIDS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_TAXES_AVAILABLE_COLUMNS, DAILY_SALES_TAXES_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_TRENDS_AVAILABLE_COLUMNS, EMPLOYEE_TIMECARD_AVAILABLE_COLUMNS, EMPLOYEE_TIMECARD_DEFAULT_VISIBLE_COLUMNS, type FieldType, type FooterCalculation, type FooterCalculationType, type FormatDateOptions, type FormatMoneyOptions, type FormatNumberOptions, type FormatTimeOptions, ITEM_TAX_AVAILABLE_COLUMNS, ITEM_TAX_DEFAULT_VISIBLE_COLUMNS, type LocaleOption, MODIFIER_MIX_AVAILABLE_COLUMNS, MODIFIER_MIX_DEFAULT_VISIBLE_COLUMNS, PRODUCT_MIX_AVAILABLE_COLUMNS, PRODUCT_MIX_CHART_FIELDS, PRODUCT_MIX_DEFAULT_VISIBLE_COLUMNS, Report, type ReportColumnKey, type ReportConfig, type ReportType, SALES_BY_ITEM_DETAIL_AVAILABLE_COLUMNS, SALES_BY_ITEM_DETAIL_DEFAULT_VISIBLE_COLUMNS, SALES_SUMMARY_AVAILABLE_COLUMNS, SALES_SUMMARY_DEFAULT_VISIBLE_COLUMNS, TICKET_LIVE_AVAILABLE_COLUMNS, TICKET_LIVE_DEFAULT_VISIBLE_COLUMNS, TICKET_SUMMARY_AVAILABLE_COLUMNS, TICKET_SUMMARY_DEFAULT_VISIBLE_COLUMNS, type TimeFormat, calculateReportTotals, dailySalesConfig, dailySalesDiscountsConfig, dailySalesPaymentsConfig, dailySalesRefundsVoidsConfig, dailySalesTaxesConfig, dailySalesTrendsConfig, employeeTimecardConfig, formatDate, formatFieldValue, formatFixedNumber, formatInteger, formatMoney, formatMoneyWithoutSymbol, formatPercent, formatString, formatTime, getColumnAlignment, getColumnExportHeaderLabel, getColumnMetadata, getDateToFormat, getNumberToFormat, getReportConfig, getReportFormattingLocaleOptions, isNumericType, itemTaxConfig, modifierMixConfig, productMixConfig, salesByItemDetailConfig, salesSummaryConfig, ticketLiveConfig, ticketSummaryConfig };
package/dist/index.d.ts CHANGED
@@ -1179,7 +1179,7 @@ declare function getColumnMetadata(key: ReportColumnKey): {
1179
1179
  };
1180
1180
  declare function getColumnExportHeaderLabel(colTitle: string, groupTitle: string | null): string;
1181
1181
 
1182
- type FieldType = 'string' | 'money' | 'percent' | 'number' | 'fixedNumber' | 'date' | 'time' | 'boolean';
1182
+ type FieldType = 'string' | 'money' | 'percent' | 'number' | 'fixedNumber' | 'date' | 'time' | 'boolean' | 'conditional';
1183
1183
  type ColumnAlignment = 'left' | 'right';
1184
1184
  type FooterCalculationType = 'sum' | 'percentChange' | 'average' | 'none';
1185
1185
  interface FooterCalculation<TField = string> {
@@ -1187,14 +1187,24 @@ interface FooterCalculation<TField = string> {
1187
1187
  numeratorField?: TField;
1188
1188
  denominatorField?: TField;
1189
1189
  }
1190
- interface ColumnPresentationConfig<TField = string> {
1190
+ interface ConditionalConfiguration<TField = string> {
1191
+ conditionalField: TField;
1192
+ conditionalFormat: (value: unknown) => Exclude<FieldType, 'conditional'>;
1193
+ }
1194
+ interface BaseColumnPresentationConfig<TField = string> {
1191
1195
  columnKey?: ReportColumnKey;
1192
- type: FieldType;
1193
1196
  size?: number;
1194
1197
  enableSorting?: boolean;
1195
1198
  filteringAvailable?: boolean;
1196
1199
  footerCalculation?: FooterCalculation<TField>;
1197
1200
  }
1201
+ type ColumnPresentationConfig<TField = string> = (BaseColumnPresentationConfig<TField> & {
1202
+ type: Exclude<FieldType, 'conditional'>;
1203
+ conditionalConfiguration?: never;
1204
+ }) | (BaseColumnPresentationConfig<TField> & {
1205
+ type: 'conditional';
1206
+ conditionalConfiguration: ConditionalConfiguration<TField>;
1207
+ });
1198
1208
  interface ColumnGroupConfig {
1199
1209
  id: string;
1200
1210
  headerTranslationKey: string;
@@ -1342,6 +1352,6 @@ declare const getReportFormattingLocaleOptions: (locations: {
1342
1352
  countryCode: string;
1343
1353
  language: string;
1344
1354
  }[]) => LocaleOption[];
1345
- declare const formatFieldValue: (value: unknown, type: FieldType, localeOptions: LocaleOption) => string;
1355
+ declare const formatFieldValue: (value: unknown, type: FieldType, localeOptions: LocaleOption, fullRecord: Record<string, unknown> | null, fieldConfig?: ColumnPresentationConfig) => string;
1346
1356
 
1347
1357
  export { COLUMN_REGISTRY, type CalculateReportTotalsOptions, type ColumnAlignment, type ColumnGroupConfig, type ColumnMetadata, type ColumnPresentationConfig, DAILY_SALES_AVAILABLE_COLUMNS, DAILY_SALES_BY_GROUP_AVAILABLE_COLUMNS, DAILY_SALES_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_DISCOUNTS_AVAILABLE_COLUMNS, DAILY_SALES_DISCOUNTS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_PAYMENTS_AVAILABLE_COLUMNS, DAILY_SALES_PAYMENTS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_REFUNDS_VOIDS_AVAILABLE_COLUMNS, DAILY_SALES_REFUNDS_VOIDS_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_TAXES_AVAILABLE_COLUMNS, DAILY_SALES_TAXES_DEFAULT_VISIBLE_COLUMNS, DAILY_SALES_TRENDS_AVAILABLE_COLUMNS, EMPLOYEE_TIMECARD_AVAILABLE_COLUMNS, EMPLOYEE_TIMECARD_DEFAULT_VISIBLE_COLUMNS, type FieldType, type FooterCalculation, type FooterCalculationType, type FormatDateOptions, type FormatMoneyOptions, type FormatNumberOptions, type FormatTimeOptions, ITEM_TAX_AVAILABLE_COLUMNS, ITEM_TAX_DEFAULT_VISIBLE_COLUMNS, type LocaleOption, MODIFIER_MIX_AVAILABLE_COLUMNS, MODIFIER_MIX_DEFAULT_VISIBLE_COLUMNS, PRODUCT_MIX_AVAILABLE_COLUMNS, PRODUCT_MIX_CHART_FIELDS, PRODUCT_MIX_DEFAULT_VISIBLE_COLUMNS, Report, type ReportColumnKey, type ReportConfig, type ReportType, SALES_BY_ITEM_DETAIL_AVAILABLE_COLUMNS, SALES_BY_ITEM_DETAIL_DEFAULT_VISIBLE_COLUMNS, SALES_SUMMARY_AVAILABLE_COLUMNS, SALES_SUMMARY_DEFAULT_VISIBLE_COLUMNS, TICKET_LIVE_AVAILABLE_COLUMNS, TICKET_LIVE_DEFAULT_VISIBLE_COLUMNS, TICKET_SUMMARY_AVAILABLE_COLUMNS, TICKET_SUMMARY_DEFAULT_VISIBLE_COLUMNS, type TimeFormat, calculateReportTotals, dailySalesConfig, dailySalesDiscountsConfig, dailySalesPaymentsConfig, dailySalesRefundsVoidsConfig, dailySalesTaxesConfig, dailySalesTrendsConfig, employeeTimecardConfig, formatDate, formatFieldValue, formatFixedNumber, formatInteger, formatMoney, formatMoneyWithoutSymbol, formatPercent, formatString, formatTime, getColumnAlignment, getColumnExportHeaderLabel, getColumnMetadata, getDateToFormat, getNumberToFormat, getReportConfig, getReportFormattingLocaleOptions, isNumericType, itemTaxConfig, modifierMixConfig, productMixConfig, salesByItemDetailConfig, salesSummaryConfig, ticketLiveConfig, ticketSummaryConfig };
package/dist/index.js CHANGED
@@ -421,7 +421,16 @@ var FIELDS6 = {
421
421
  orderTypeName: { type: "string", columnKey: "orderType", filteringAvailable: false },
422
422
  taxName: { type: "string", columnKey: "taxName", filteringAvailable: false },
423
423
  taxValue: { type: "money", columnKey: "taxableSales" },
424
- taxRate: { type: "number", columnKey: "taxRate" },
424
+ taxRate: {
425
+ type: "conditional",
426
+ columnKey: "taxRate",
427
+ conditionalConfiguration: {
428
+ conditionalField: "taxIsFlat",
429
+ conditionalFormat: (field) => {
430
+ return field ? "money" : "percent";
431
+ }
432
+ }
433
+ },
425
434
  recordsCount: { type: "number", columnKey: "quantity" },
426
435
  taxableSales: { type: "money", columnKey: "taxableSales" },
427
436
  totalCollected: { type: "money", columnKey: "totalCollected" },
@@ -1632,9 +1641,18 @@ var getReportFormattingLocaleOptions = (locations) => {
1632
1641
  ).values()
1633
1642
  );
1634
1643
  };
1635
- var formatFieldValue = (value, type, localeOptions) => {
1644
+ var DEFAULT_FIELD_CONFIG = { type: "string" };
1645
+ var formatFieldValue = (value, type, localeOptions, fullRecord, fieldConfig = DEFAULT_FIELD_CONFIG) => {
1636
1646
  const { currency, locale } = localeOptions;
1637
1647
  switch (type) {
1648
+ case "conditional": {
1649
+ if (!fullRecord) {
1650
+ return formatString(value);
1651
+ }
1652
+ const conditionalConfig = fieldConfig.conditionalConfiguration;
1653
+ const configType = conditionalConfig.conditionalFormat(fullRecord[conditionalConfig.conditionalField]);
1654
+ return formatFieldValue(value, configType, localeOptions, fullRecord, fieldConfig);
1655
+ }
1638
1656
  case "string":
1639
1657
  return formatString(value);
1640
1658
  case "money":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbortouch/skytab-analytics-report-utils",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Centralized report column presentation configuration for SkyTab Analytics",
5
5
  "engines": {
6
6
  "node": ">=22.6.0",