@managesome/eposmatic-toolkit 0.2.362 → 0.2.364

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.
@@ -22,6 +22,7 @@ export declare function sentenceCase(str: string): string;
22
22
  export declare function parseNum(num: number, abs?: boolean): number;
23
23
  export declare function countLeadingSpaces(inputString: string): number;
24
24
  export declare function formatDateToDateTime(date: Date, gmtOffset: number): string;
25
+ export declare function formatMoneyAmount(amount: number): string;
25
26
  export declare function localeAmount(currency: string | undefined, amount: number): string;
26
27
  export declare const getOfflineOrderNumber: () => number;
27
28
  export declare function sanitizeText(input: string): string;
@@ -20,6 +20,7 @@ exports.sentenceCase = sentenceCase;
20
20
  exports.parseNum = parseNum;
21
21
  exports.countLeadingSpaces = countLeadingSpaces;
22
22
  exports.formatDateToDateTime = formatDateToDateTime;
23
+ exports.formatMoneyAmount = formatMoneyAmount;
23
24
  exports.localeAmount = localeAmount;
24
25
  exports.sanitizeText = sanitizeText;
25
26
  exports.getGSTName = getGSTName;
@@ -182,8 +183,20 @@ function formatDateToDateTime(date, gmtOffset) {
182
183
  return customFormat;
183
184
  }
184
185
  // ==============================>><<==============================
186
+ function addThousandsSeparator(value) {
187
+ return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
188
+ }
189
+ function formatMoneyAmount(amount) {
190
+ const rounded = parseNum(amount);
191
+ const fixed = Math.abs(rounded).toFixed(2);
192
+ const [integerPart, decimalPart = ''] = fixed.split('.');
193
+ const groupedInteger = addThousandsSeparator(integerPart);
194
+ const trimmedDecimal = decimalPart.replace(/0+$/, '');
195
+ const sign = rounded < 0 ? '-' : '';
196
+ return `${sign}${groupedInteger}${trimmedDecimal ? `.${trimmedDecimal}` : ''}`;
197
+ }
185
198
  function localeAmount(currency, amount) {
186
- return `${currency ?? ''}${parseNum(amount).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}`;
199
+ return `${currency ?? ''}${formatMoneyAmount(amount)}`;
187
200
  }
188
201
  let lastOfflineOrderNumber;
189
202
  const getOfflineOrderNumber = () => {
@@ -177,11 +177,9 @@ function getItemComparisonReportHtml(props) {
177
177
  : (cellData ?? 0)}`;
178
178
  }
179
179
  else {
180
- displayValue = `${currency_symbol}${(typeof cellData === 'object' &&
181
- cellData !== null &&
182
- selectedField in cellData
180
+ displayValue = `${currency_symbol}${typeof cellData === 'object' && cellData !== null && selectedField in cellData
183
181
  ? cellData[selectedField] || 0
184
- : 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })} (${typeof cellData === 'object' && cellData !== null && 'count' in cellData ? cellData.count : 0})`;
182
+ : 0} (${typeof cellData === 'object' && cellData !== null && 'count' in cellData ? cellData.count : 0})`;
185
183
  }
186
184
  rowHtml += `<td class="css-1itf2nwdsdsdd"><span class="css-l5zp2sfsdfsd">${displayValue}</span></td>`;
187
185
  }
@@ -232,7 +230,7 @@ function getItemComparisonReportHtml(props) {
232
230
  const count = typeof cellData === 'object' && cellData !== null && 'count' in cellData
233
231
  ? cellData.count
234
232
  : 0;
235
- displayValue = `${currency_symbol}${amount.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })} (${count})`;
233
+ displayValue = `${currency_symbol}${(0, common_1.formatMoneyAmount)(amount)} (${count})`;
236
234
  }
237
235
  rowHtml += `<td class="css-1itf2nwdsdsdd"><span class="css-l5zp2sfsdfsd">${displayValue}</span></td>`;
238
236
  }
@@ -842,7 +840,7 @@ function getItemComparisonReportReceiptHtml(props) {
842
840
  const count = typeof cellData === 'object' && cellData !== null && 'count' in cellData
843
841
  ? cellData.count
844
842
  : 0;
845
- displayValue = `${amount.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })} (${count})`;
843
+ displayValue = `${(0, common_1.formatMoneyAmount)(amount)} (${count})`;
846
844
  }
847
845
  content += `
848
846
  <div class="receipt-item-row">
@@ -890,7 +888,7 @@ function getItemComparisonReportReceiptHtml(props) {
890
888
  const count = typeof cellData === 'object' && cellData !== null && 'count' in cellData
891
889
  ? cellData.count
892
890
  : 0;
893
- displayValue = `${amount.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })} (${count})`;
891
+ displayValue = `${(0, common_1.formatMoneyAmount)(amount)} (${count})`;
894
892
  }
895
893
  content += `
896
894
  <div class="receipt-item-row">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.362",
3
+ "version": "0.2.364",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",