@managesome/eposmatic-toolkit 0.3.10 → 0.4.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.
Files changed (145) hide show
  1. package/esm/constants/ENUMS.js +17 -1988
  2. package/esm/constants/MATERIALIZED_REPORTS.js +105 -0
  3. package/esm/constants/enums/cash.js +45 -0
  4. package/esm/constants/enums/communications.js +329 -0
  5. package/esm/constants/enums/delivery.js +35 -0
  6. package/esm/constants/enums/geo.js +150 -0
  7. package/esm/constants/enums/hr.js +130 -0
  8. package/esm/constants/enums/internal.js +132 -0
  9. package/esm/constants/enums/items.js +126 -0
  10. package/esm/constants/enums/misc.js +35 -0
  11. package/esm/constants/enums/offers.js +102 -0
  12. package/esm/constants/enums/order.js +135 -0
  13. package/esm/constants/enums/payments.js +186 -0
  14. package/esm/constants/enums/platform.js +215 -0
  15. package/esm/constants/enums/printing.js +107 -0
  16. package/esm/constants/enums/users.js +245 -0
  17. package/esm/constants/enums/wallet.js +32 -0
  18. package/esm/helpers/materialized-reports/index.js +5 -0
  19. package/esm/helpers/materialized-reports/key-helpers.js +59 -0
  20. package/esm/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +60 -0
  21. package/esm/helpers/materialized-reports/scope-helpers.js +107 -0
  22. package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +251 -0
  23. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +860 -0
  24. package/esm/helpers/store/cart-actions.js +1 -1
  25. package/esm/helpers/store/common-tenant-purchase-order-actions.js +7 -7
  26. package/esm/helpers/store/common-warehouse-purchase-order-actions.js +1 -1
  27. package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +1 -1
  28. package/esm/helpers/store/common-warehouse-sale-order-actions.js +1 -1
  29. package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +1 -1
  30. package/esm/helpers/store/offline-ordering.js +1 -1
  31. package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +1 -1
  32. package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +1 -1
  33. package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +1 -1
  34. package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +1 -1
  35. package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +1 -1
  36. package/esm/helpers/utils/cancellation-helpers.js +7 -0
  37. package/esm/helpers/utils/common.js +0 -46
  38. package/esm/helpers/utils/getFormFieldsDiff.js +1 -1
  39. package/esm/helpers/utils/index.js +2 -0
  40. package/esm/helpers/utils/phone-helpers.js +40 -0
  41. package/esm/helpers/utils/receipt-engine.js +3 -1
  42. package/esm/helpers/utils/specials-helpers.js +1 -1
  43. package/esm/helpers/utils/void-items-report-helpers.js +2 -1
  44. package/esm/schemas/models/materialized_tenant_reports_iterations.js +82 -0
  45. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +399 -0
  46. package/esm/schemas/types/materialized_tenant_reports_iterations.js +1 -0
  47. package/esm/schemas/types/materialized_tenant_sales_overview_reports.js +1 -0
  48. package/lib/constants/ENUMS.d.ts +15 -1275
  49. package/lib/constants/ENUMS.js +31 -1994
  50. package/lib/constants/MATERIALIZED_REPORTS.d.ts +96 -0
  51. package/lib/constants/MATERIALIZED_REPORTS.js +108 -0
  52. package/lib/constants/enums/cash.d.ts +35 -0
  53. package/lib/constants/enums/cash.js +48 -0
  54. package/lib/constants/enums/communications.d.ts +79 -0
  55. package/lib/constants/enums/communications.js +332 -0
  56. package/lib/constants/enums/delivery.d.ts +26 -0
  57. package/lib/constants/enums/delivery.js +38 -0
  58. package/lib/constants/enums/geo.d.ts +133 -0
  59. package/lib/constants/enums/geo.js +153 -0
  60. package/lib/constants/enums/hr.d.ts +105 -0
  61. package/lib/constants/enums/hr.js +133 -0
  62. package/lib/constants/enums/internal.d.ts +104 -0
  63. package/lib/constants/enums/internal.js +135 -0
  64. package/lib/constants/enums/items.d.ts +94 -0
  65. package/lib/constants/enums/items.js +129 -0
  66. package/lib/constants/enums/misc.d.ts +25 -0
  67. package/lib/constants/enums/misc.js +38 -0
  68. package/lib/constants/enums/offers.d.ts +80 -0
  69. package/lib/constants/enums/offers.js +105 -0
  70. package/lib/constants/enums/order.d.ts +108 -0
  71. package/lib/constants/enums/order.js +138 -0
  72. package/lib/constants/enums/payments.d.ts +129 -0
  73. package/lib/constants/enums/payments.js +189 -0
  74. package/lib/constants/enums/platform.d.ts +100 -0
  75. package/lib/constants/enums/platform.js +218 -0
  76. package/lib/constants/enums/printing.d.ts +89 -0
  77. package/lib/constants/enums/printing.js +110 -0
  78. package/lib/constants/enums/users.d.ts +142 -0
  79. package/lib/constants/enums/users.js +248 -0
  80. package/lib/constants/enums/wallet.d.ts +26 -0
  81. package/lib/constants/enums/wallet.js +35 -0
  82. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  83. package/lib/helpers/materialized-reports/index.js +21 -0
  84. package/lib/helpers/materialized-reports/key-helpers.d.ts +35 -0
  85. package/lib/helpers/materialized-reports/key-helpers.js +64 -0
  86. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.d.ts +66 -0
  87. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +63 -0
  88. package/lib/helpers/materialized-reports/scope-helpers.d.ts +57 -0
  89. package/lib/helpers/materialized-reports/scope-helpers.js +114 -0
  90. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +125 -0
  91. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +256 -0
  92. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +223 -0
  93. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +875 -0
  94. package/lib/helpers/store/cart-actions.js +6 -6
  95. package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +2 -2
  96. package/lib/helpers/store/common-tenant-purchase-order-actions.js +10 -10
  97. package/lib/helpers/store/common-warehouse-purchase-order-actions.js +4 -4
  98. package/lib/helpers/store/common-warehouse-purchase-order-rfq-actions.js +4 -4
  99. package/lib/helpers/store/common-warehouse-sale-order-actions.js +4 -4
  100. package/lib/helpers/store/common-warehouse-sale-order-rfq-actions.js +4 -4
  101. package/lib/helpers/store/offline-ordering.js +2 -2
  102. package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +2 -2
  103. package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +2 -2
  104. package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +2 -2
  105. package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.js +2 -2
  106. package/lib/helpers/store/warehouse-sale-orders-cart-actions.js +2 -2
  107. package/lib/helpers/utils/cancellation-helpers.d.ts +1 -0
  108. package/lib/helpers/utils/cancellation-helpers.js +13 -0
  109. package/lib/helpers/utils/common.d.ts +0 -6
  110. package/lib/helpers/utils/common.js +1 -54
  111. package/lib/helpers/utils/getFormFieldsDiff.js +5 -2
  112. package/lib/helpers/utils/index.d.ts +2 -0
  113. package/lib/helpers/utils/index.js +2 -0
  114. package/lib/helpers/utils/phone-helpers.d.ts +5 -0
  115. package/lib/helpers/utils/phone-helpers.js +46 -0
  116. package/lib/helpers/utils/receipt-engine.js +4 -2
  117. package/lib/helpers/utils/specials-helpers.js +2 -2
  118. package/lib/helpers/utils/void-items-report-helpers.js +3 -2
  119. package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +80 -0
  120. package/lib/schemas/models/materialized_tenant_reports_iterations.js +85 -0
  121. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +569 -0
  122. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +402 -0
  123. package/lib/schemas/types/materialized_tenant_reports_iterations.d.ts +62 -0
  124. package/lib/schemas/types/materialized_tenant_reports_iterations.js +2 -0
  125. package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +242 -0
  126. package/lib/schemas/types/materialized_tenant_sales_overview_reports.js +3 -0
  127. package/lib/tests/materialized-reports/fixtures.d.ts +81 -0
  128. package/lib/tests/materialized-reports/fixtures.js +87 -0
  129. package/lib/tests/materialized-reports/fixtures.test.d.ts +1 -0
  130. package/lib/tests/materialized-reports/fixtures.test.js +123 -0
  131. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.d.ts +1 -0
  132. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.js +75 -0
  133. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.d.ts +1 -0
  134. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +73 -0
  135. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.d.ts +1 -0
  136. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +207 -0
  137. package/lib/tests/materialized-reports/sales-overview-baseline.test.d.ts +1 -0
  138. package/lib/tests/materialized-reports/sales-overview-baseline.test.js +326 -0
  139. package/lib/tests/materialized-reports/sales-overview-reference.d.ts +63 -0
  140. package/lib/tests/materialized-reports/sales-overview-reference.js +131 -0
  141. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.d.ts +1 -0
  142. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +335 -0
  143. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.d.ts +1 -0
  144. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +885 -0
  145. package/package.json +5 -2
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { DISCOUNT_APPLICABILITY_ENUM, GIFT_CARD_REWARD_TYPE_ENUM, OFFER_NO_LONGER_QUALIFIED_VOID_REASON, OFFER_REWARD_TYPE_ENUM, ORDER_STATUS_ENUM, ORDER_TYPE_ENUM, PLATFORMS_BY_ORDER_TYPE, SORT_TYPE_ENUM, TAX_INVOICE_PROVIDER_CHARGES_MAP, TAX_INVOICE_PROVIDER_ENUM, WALLET_CASHBACK_LOYALTY_DISCOUNT_ID, WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME, WALLET_CASHBACK_LOYALTY_REFERENCE, } from '../../constants';
4
4
  import { calculateEligibleOfferDiscountDetails, getCappedOfferDiscountAmount, getCardChargesAndAmountCollected, getDeliveryAmt, getNetItemsValueAfterItemDiscount, getPercentageAmount, getPriceEnum, parseFloatCeil, parseNum, } from '../utils';
5
5
  import { buildClearVoucherDiscountDetails } from '../utils/offers-helpers';
@@ -1,6 +1,13 @@
1
1
  import { convertDecimalToInt, convertIntToDecimal, parseNum } from '../utils';
2
2
  import { getOrderPaymentsCardDetailsWithPrice } from './common-order-actions';
3
3
  import { calculateCartTenantPurchaseOrderInfoAndSyncData } from './tenant-purchase-orders-cart-actions';
4
+ // ══════════════════════════════════════════════════════════════════════
5
+ // Cart Items Obj (moved from admin-panel utils)
6
+ // ══════════════════════════════════════════════════════════════════════
7
+ import ObjectID from 'bson-objectid';
8
+ import isEqual from 'lodash/isEqual';
9
+ import { SORT_TYPE_ENUM } from '../../constants';
10
+ import { getTenantPurchaseOrderItemComparableData } from './tenant-purchase-orders-cart-actions';
4
11
  export function getTenantPurchaseOrderIterationsWithPrice(iterations, writeable) {
5
12
  if (!iterations)
6
13
  return [];
@@ -124,13 +131,6 @@ export function getTenantPurchaseOrderWithAllFields(order, skipItemMetadata) {
124
131
  cancel_reason: order['cancel_reason'] ?? null,
125
132
  };
126
133
  }
127
- // ══════════════════════════════════════════════════════════════════════
128
- // Cart Items Obj (moved from admin-panel utils)
129
- // ══════════════════════════════════════════════════════════════════════
130
- import ObjectID from 'bson-objectid';
131
- import { isEqual } from 'lodash';
132
- import { SORT_TYPE_ENUM } from '../../constants';
133
- import { getTenantPurchaseOrderItemComparableData } from './tenant-purchase-orders-cart-actions';
134
134
  export function getTenantPurchaseOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId = true, isAnEdit, sortType, }) {
135
135
  const newMappedItems = { ...mappedItems };
136
136
  if (Object.keys(newMappedItems).length === 0) {
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { SORT_TYPE_ENUM } from '../../constants';
4
4
  import { convertDecimalToInt, convertIntToDecimal, parseNum } from '../utils';
5
5
  import { getOrderPaymentsCardDetailsWithPrice } from './common-order-actions';
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { SORT_TYPE_ENUM } from '../../constants';
4
4
  import { convertDecimalToInt, convertIntToDecimal, parseNum } from '../utils';
5
5
  import { calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData } from './warehouse-purchase-order-rfq-cart-actions';
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { SORT_TYPE_ENUM } from '../../constants';
4
4
  import { convertDecimalToInt, convertIntToDecimal, parseNum } from '../utils';
5
5
  import { sortByCreatedAt } from './common-order-actions';
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { SORT_TYPE_ENUM } from '../../constants';
4
4
  import { convertDecimalToInt, convertIntToDecimal, parseNum } from '../utils';
5
5
  import { calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData } from './warehouse-sale-order-rfq-cart-actions';
@@ -1,4 +1,4 @@
1
- import { isEqual } from 'lodash';
1
+ import isEqual from 'lodash/isEqual';
2
2
  import Mongoose from 'mongoose';
3
3
  import { ALL_ORDER_STATUS_NAMES, ORDER_STATUS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM } from '../../constants';
4
4
  import { CUSTOM_ERROR_CODES, CustomError, getCardChargesAndAmountCollected, getOfflineOrderNumber, getOrderPaymentsDetails, isOrderFullyPaid, syncPayments, } from '../utils';
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { TENANT_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
4
4
  import { getCardChargesAndAmountCollected, getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
5
  export function calculateCartTenantPurchaseOrderInfoAndSyncData(data, calculateItemMetadata) {
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
4
4
  import { getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
5
  /* =================================================================
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
4
4
  import { getCardChargesAndAmountCollected, getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
5
  export function calculateCartWarehousePurchaseOrderInfoAndSyncData(data, calculateItemMetadata) {
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
4
4
  import { getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
5
  /* =================================================================
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { WAREHOUSE_SALES_ORDER_STATUS_ENUM } from '../../constants';
4
4
  import { getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
5
  export function calculateCartWarehouseSaleOrderInfoAndSyncData(data, calculateItemMetadata) {
@@ -0,0 +1,7 @@
1
+ import moment from 'moment';
2
+ // ==============================>><<==============================
3
+ export function getFormattedCancellationReason(reason) {
4
+ if (!reason)
5
+ return;
6
+ return reason.replace(/(Cancelled at )(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/, (_, prefix, date) => `${prefix}${moment(date).format('lll')}`);
7
+ }
@@ -1,47 +1,6 @@
1
- import { PhoneNumberUtil } from 'google-libphonenumber';
2
- import moment from 'moment';
3
1
  import { COUNTRY_ALPHA_2_ENUM, SUBSCRIPTION_STATUS_ENUM, TAX_INVOICE_PROVIDER_ENUM, } from '../../constants';
4
2
  import { convertPriceFromCents } from './price-conversion';
5
3
  import { getTenantTime } from './time-helpers';
6
- export const phoneUtil = PhoneNumberUtil.getInstance();
7
- export function getNationalNumberFromPhone(phoneNumber, region) {
8
- let phone = null;
9
- try {
10
- phone = phoneUtil.parse(phoneNumber, region).getNationalNumber();
11
- if (phone != null) {
12
- phone = `0${phone.toString()}`;
13
- }
14
- }
15
- catch (e) {
16
- phone = null;
17
- }
18
- return phone;
19
- }
20
- export function getIntNumberFromPhone(phoneNumber, region) {
21
- let phone = null;
22
- try {
23
- const parsedPhone = phoneUtil.parse(phoneNumber, region);
24
- phone = `${parsedPhone.getCountryCode() ?? ''}${parsedPhone.getNationalNumber() ?? ''}`;
25
- if (phone) {
26
- phone = `+${phone}`;
27
- }
28
- else {
29
- phone = null;
30
- }
31
- }
32
- catch (e) {
33
- phone = null;
34
- }
35
- return phone;
36
- }
37
- export function getCountryCodeFromPhone(phoneNumber) {
38
- try {
39
- return phoneUtil.parse(phoneNumber).getCountryCode();
40
- }
41
- catch (e) {
42
- return null;
43
- }
44
- }
45
4
  // ==============================>><<==============================
46
5
  export function strToNum(str) {
47
6
  const numStr = str.replace(/[^\d.-]/g, '');
@@ -265,11 +224,6 @@ export function getTaxNumberTitle(country_alpha_2, tax_invoice_provider) {
265
224
  return title;
266
225
  }
267
226
  // ==============================>><<==============================
268
- export function getFormattedCancellationReason(reason) {
269
- if (!reason)
270
- return;
271
- return reason.replace(/(Cancelled at )(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/, (_, prefix, date) => `${prefix}${moment(date).format('lll')}`);
272
- }
273
227
  export const formatAmount = (currencySymbol, amount) => localeAmount(currencySymbol, convertPriceFromCents(amount));
274
228
  export const getSubscriptionStatus = (subscription_expiry) => {
275
229
  let subscriptionStatus = SUBSCRIPTION_STATUS_ENUM.ACTIVE;
@@ -1,4 +1,4 @@
1
- import { isEqual } from 'lodash';
1
+ import isEqual from 'lodash/isEqual';
2
2
  export function getFormFieldsDiff(payload, defaultValues, blackList) {
3
3
  const editedFormFields = {};
4
4
  if (defaultValues) {
@@ -1,5 +1,6 @@
1
1
  export * from './asaanbill-identifier-helpers';
2
2
  export * from './business-day-helpers';
3
+ export * from './cancellation-helpers';
3
4
  export * from './cart-helpers';
4
5
  export * from './catalog-conversion';
5
6
  export * from './code-redemption-helpers';
@@ -42,6 +43,7 @@ export * from './order-history';
42
43
  export * from './payment-comparison-report-helpers';
43
44
  export * from './payment-helpers';
44
45
  export * from './pdf-generator';
46
+ export * from './phone-helpers';
45
47
  export * from './platform-catalog';
46
48
  export * from './platform-num';
47
49
  export * from './platform-specific-tenant-shifts';
@@ -0,0 +1,40 @@
1
+ import { PhoneNumberUtil } from 'google-libphonenumber';
2
+ export const phoneUtil = PhoneNumberUtil.getInstance();
3
+ export function getNationalNumberFromPhone(phoneNumber, region) {
4
+ let phone = null;
5
+ try {
6
+ phone = phoneUtil.parse(phoneNumber, region).getNationalNumber();
7
+ if (phone != null) {
8
+ phone = `0${phone.toString()}`;
9
+ }
10
+ }
11
+ catch (e) {
12
+ phone = null;
13
+ }
14
+ return phone;
15
+ }
16
+ export function getIntNumberFromPhone(phoneNumber, region) {
17
+ let phone = null;
18
+ try {
19
+ const parsedPhone = phoneUtil.parse(phoneNumber, region);
20
+ phone = `${parsedPhone.getCountryCode() ?? ''}${parsedPhone.getNationalNumber() ?? ''}`;
21
+ if (phone) {
22
+ phone = `+${phone}`;
23
+ }
24
+ else {
25
+ phone = null;
26
+ }
27
+ }
28
+ catch (e) {
29
+ phone = null;
30
+ }
31
+ return phone;
32
+ }
33
+ export function getCountryCodeFromPhone(phoneNumber) {
34
+ try {
35
+ return phoneUtil.parse(phoneNumber).getCountryCode();
36
+ }
37
+ catch (e) {
38
+ return null;
39
+ }
40
+ }
@@ -3,7 +3,9 @@ import moment from 'moment';
3
3
  import { COUNTRY_ALPHA_2_ENUM, KITCHEN_DOCKET_FONT_TYPE_ENUM, MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, ORDER_TYPE_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PRINTING_PREFERENCE_ENUM, RECEIPT_QR_CODE_TYPE_ENUM, RECEIPT_TYPE_ENUM, } from '../../constants';
4
4
  import { getCartItemsObj } from '../store';
5
5
  import { optionallyGetOrderItemOriginalQuantityPrice } from './cart-helpers';
6
- import { getFormattedCancellationReason, getGSTName, getNationalNumberFromPhone, getTaxNumberTitle, localeAmount, parseNum, sentenceCase, titleCase, } from './common';
6
+ import { getFormattedCancellationReason } from './cancellation-helpers';
7
+ import { getGSTName, getTaxNumberTitle, localeAmount, parseNum, sentenceCase, titleCase } from './common';
8
+ import { getNationalNumberFromPhone } from './phone-helpers';
7
9
  import { getOrderPaymentsDetails, getPaymentSmartTitle, getQRCodePaymentLink, getSortedPayments, isOrderFullyPaid, } from './payment-helpers';
8
10
  // =========================><=========================
9
11
  export function getDiscountLabel(discount_details) {
@@ -1,5 +1,5 @@
1
1
  import ObjectID from 'bson-objectid';
2
- import { isEqual } from 'lodash';
2
+ import isEqual from 'lodash/isEqual';
3
3
  import { MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM } from '../../constants';
4
4
  import { calculateItemTotalWithTax, getComparableOrderItem } from '../store';
5
5
  import { convertHalfHalfToItem } from './halfhalf-setup-helpers';
@@ -1,6 +1,7 @@
1
1
  import moment from 'moment';
2
2
  import { CURRENCY_SYMBOL_ENUM } from '../../constants';
3
- import { getFormattedCancellationReason, localeAmount } from './common';
3
+ import { getFormattedCancellationReason } from './cancellation-helpers';
4
+ import { localeAmount } from './common';
4
5
  // Generate HTML template for void items report
5
6
  export function getVoidItemsReportHtml(props) {
6
7
  const { data, tenantName, from, to, width = 800, monochrome = false, currency_symbol } = props;
@@ -0,0 +1,82 @@
1
+ import { Schema } from 'mongoose';
2
+ import { ALL_MATERIALIZED_REPORT_TYPES } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Mongoose schema for `materialized_tenant_reports_iterations` — the shared iteration
5
+ * history of every materialized report collection (see
6
+ * `MATERIALIZED_REPORTS.md`, "Iteration history").
7
+ *
8
+ * One append-only row per VERSIONED write of a report document; `snapshot`
9
+ * holds the full report document AFTER the write. `snapshot` is Mixed because
10
+ * the collection serves every report kind (`report_type` discriminates).
11
+ * Received-payment patches that change the ledger are versioned writes too
12
+ * (they bump `iteration` and append rows); no-op patches write nothing.
13
+ * Every row carries the backend-generated `reason` for the audit trail.
14
+ */
15
+ export const MaterializedTenantReportIterationSchema = new Schema({
16
+ _id: {
17
+ type: Schema.Types.ObjectId,
18
+ required: true,
19
+ immutable: true,
20
+ },
21
+ report_type: {
22
+ type: String,
23
+ enum: ALL_MATERIALIZED_REPORT_TYPES,
24
+ required: true,
25
+ immutable: true,
26
+ },
27
+ report_id: {
28
+ type: Schema.Types.ObjectId,
29
+ required: true,
30
+ immutable: true,
31
+ },
32
+ iteration: {
33
+ type: Number,
34
+ required: true,
35
+ min: 1,
36
+ },
37
+ schema_version: {
38
+ type: Number,
39
+ required: true,
40
+ },
41
+ // Why the iteration happened — backend-generated free string, e.g.
42
+ // 'NEW_DAY' | 'RECLOSE' | 'RECONCILE' | 'CREDIT_BILL_COLLECTED'.
43
+ reason: {
44
+ type: String,
45
+ required: true,
46
+ },
47
+ // Full report document as written — polymorphic across report kinds, so
48
+ // untyped/Mixed; narrow by `report_type` (see the type file).
49
+ snapshot: {
50
+ type: Schema.Types.Mixed,
51
+ required: true,
52
+ },
53
+ createdAt: {
54
+ type: Schema.Types.Date,
55
+ required: true,
56
+ default: () => new Date(),
57
+ immutable: true,
58
+ },
59
+ updatedAt: {
60
+ type: Schema.Types.Date,
61
+ required: true,
62
+ default: () => new Date(),
63
+ },
64
+ }, {
65
+ timestamps: true,
66
+ versionKey: false,
67
+ minimize: false,
68
+ });
69
+ export const MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = 'materialized_tenant_reports_iterations';
70
+ /**
71
+ * Indexes for `materialized_tenant_reports_iterations` (values are Mongo key patterns that
72
+ * can be passed straight to `.hint()`):
73
+ * - `_id`: unique primary key.
74
+ * - `report_id__iteration`: UNIQUE — one row per (report, iteration); serves
75
+ * per-report history reads (`{ report_id }` + `.sort({ iteration: -1 })`;
76
+ * the head row mirrors the live document) and doubles as the idempotent
77
+ * upsert key (`replaceOne({ report_id, iteration }, row, { upsert: true })`).
78
+ */
79
+ export const MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = {
80
+ _id: { _id: 1 }, // Unique Index
81
+ report_id__iteration: { report_id: 1, iteration: -1 }, // unique — one row per (report, iteration)
82
+ };