meemup-library 2.0.2 → 2.0.3

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.
@@ -1,12 +1,17 @@
1
1
  import IOrderDetailProductsExtra from '../interfaces/print/IOrderDetailProductsExtra';
2
2
  import IOrderDetailProduct from '../interfaces/print/IOrderDetailProduct';
3
3
  declare class _PrintToolController {
4
- extraItemToText(item: IOrderDetailProductsExtra, ignoreWholeText?: boolean, showPrices?: boolean): string;
4
+ static instance: _PrintToolController;
5
+ private constructor();
6
+ static getInstance(): _PrintToolController;
7
+ extraItemToText(item: IOrderDetailProductsExtra, ignoreWholeText?: boolean, showPrice?: boolean): string;
5
8
  productNote(item: IOrderDetailProduct): string;
6
- orderItemCountText: (products: IOrderDetailProduct[], catList: number[], onlyListCategory: boolean, productList: number[], onlyListProduct: boolean) => string;
9
+ createOrderItemCount: (count: number) => string;
10
+ orderItemCount: (products: IOrderDetailProduct[], catList: number[], onlyListCategory: boolean, productList: number[], onlyListProduct: boolean) => number;
7
11
  filterProductsByCategoryList: (products: IOrderDetailProduct[], catList: number[], onlyListCategory: boolean, productList: number[], onlyListProduct: boolean) => IOrderDetailProduct[];
8
12
  textWithIndent(text: string, indent?: number, lineWidth?: number): string;
9
13
  createBundleLines(bundleTitle: string, price: string, lineWidth?: number): string;
14
+ orderItemCountText: (products: IOrderDetailProduct[], catList: number[], onlyListCategory: boolean, productList: number[], onlyListProduct: boolean) => string;
10
15
  }
11
16
  declare const PrintToolController: _PrintToolController;
12
17
  export default PrintToolController;
@@ -2,9 +2,15 @@ import EnumPizzaSide from '../enums/EnumPizzaSide';
2
2
  import MoneyController from './MoneyController';
3
3
  class _PrintToolController {
4
4
  constructor() {
5
- this.orderItemCountText = (products, catList, onlyListCategory, productList, onlyListProduct) => {
6
- const list = this.filterProductsByCategoryList(products, catList, onlyListCategory, productList, onlyListProduct);
7
- return `${MoneyController.sum(list.map(row => row.quantity))} ITEM`;
5
+ this.createOrderItemCount = (count) => {
6
+ if (count <= 1) {
7
+ return `${count} ITEM`;
8
+ }
9
+ return `${count} ITEMS`;
10
+ };
11
+ this.orderItemCount = (products, catList, onlyListCategory, productList, onlyListProduct) => {
12
+ let list = this.filterProductsByCategoryList(products, catList, onlyListCategory, productList, onlyListProduct);
13
+ return MoneyController.sum(list.map(row => row.quantity));
8
14
  };
9
15
  this.filterProductsByCategoryList = (products, catList, onlyListCategory, productList, onlyListProduct) => {
10
16
  if (!onlyListCategory && !onlyListProduct) {
@@ -34,9 +40,19 @@ class _PrintToolController {
34
40
  }
35
41
  return new_product;
36
42
  };
43
+ this.orderItemCountText = (products, catList, onlyListCategory, productList, onlyListProduct) => {
44
+ const list = this.filterProductsByCategoryList(products, catList, onlyListCategory, productList, onlyListProduct);
45
+ return `${MoneyController.sum(list.map(row => row.quantity))} ITEM`;
46
+ };
47
+ }
48
+ static getInstance() {
49
+ if (!_PrintToolController.instance) {
50
+ _PrintToolController.instance = new _PrintToolController();
51
+ }
52
+ return _PrintToolController.instance;
37
53
  }
38
- extraItemToText(item, ignoreWholeText = false, showPrices = true) {
39
- const parts = [];
54
+ extraItemToText(item, ignoreWholeText = false, showPrice = true) {
55
+ let parts = [];
40
56
  switch (item.pizzaSide) {
41
57
  case EnumPizzaSide.all:
42
58
  if (!ignoreWholeText) {
@@ -57,7 +73,7 @@ class _PrintToolController {
57
73
  if (item.extraItemOptionId !== null && item.extraItemOptionId !== -1) {
58
74
  parts.push(`[${item.extraItemOptionTitle.trim()}] `);
59
75
  }
60
- if (showPrices && item.totalAmount !== 0) {
76
+ if (showPrice && item.totalAmount !== 0) {
61
77
  parts.push(`(${MoneyController.format(item.totalAmount, '')})`);
62
78
  }
63
79
  return parts.join(' ').trim();
@@ -72,7 +88,7 @@ class _PrintToolController {
72
88
  function splitString(str, chunkSize) {
73
89
  return Array.from({ length: Math.ceil(str.length / chunkSize) }, (_, i) => str.slice(i * chunkSize, (i + 1) * chunkSize));
74
90
  }
75
- const lineCharLength = lineWidth - indent;
91
+ let lineCharLength = lineWidth - indent;
76
92
  let parts = splitString(text, lineCharLength);
77
93
  const indentStr = ' '.repeat(indent);
78
94
  parts = parts.map(i => indentStr + i);
@@ -82,10 +98,10 @@ class _PrintToolController {
82
98
  function splitString(str, chunkSize) {
83
99
  return Array.from({ length: Math.ceil(str.length / chunkSize) }, (_, i) => str.slice(i * chunkSize, (i + 1) * chunkSize));
84
100
  }
85
- const lineCharLength = lineWidth - (price.length) - 1;
86
- const parts = splitString(bundleTitle, lineCharLength);
101
+ let lineCharLength = lineWidth - price.length - 1;
102
+ let parts = splitString(bundleTitle, lineCharLength);
87
103
  if (parts.length >= 1) {
88
- while ((parts[0].length + price.length + 1) < lineWidth) {
104
+ while (parts[0].length + price.length + 1 < lineWidth) {
89
105
  parts[0] = parts[0] + ' ';
90
106
  }
91
107
  parts[0] = parts[0] + ' ' + price;
@@ -95,5 +111,5 @@ class _PrintToolController {
95
111
  return parts.join('\n') + '\n';
96
112
  }
97
113
  }
98
- const PrintToolController = new _PrintToolController();
114
+ const PrintToolController = _PrintToolController.getInstance();
99
115
  export default PrintToolController;
@@ -410,13 +410,14 @@ class SimplePreviewController {
410
410
  if ((template.printProductsBySeat && detail.order.orderType === EnumOrderType.dining && detail.order.tableId !== null && seats.length > 0) || (detail.order.orderType === EnumOrderType.dining && detail.order.tableId !== null && seats.length > 0)) {
411
411
  return this.printProductInDineIn(template, detail);
412
412
  }
413
+ const count = PrintToolController.orderItemCount(this.sortProduct(detail.products, template.sortProducts), template.printOnlyCertainCategoriesList, template.printOnlyCertainCategories, template.printOnlyCertainProductsList, template.printOnlyCertainProducts);
413
414
  let flag = true;
414
415
  let content = `${this.createDivContainer(template)}
415
416
  <table style="width: 100%; border-collapse: collapse;">
416
417
  <thead style="border-bottom: 1px solid #000000;">
417
418
  <tr style="${isLarge ? '' : 'height: 28px;'}">
418
419
  <th style="font-size:${template.fontSize}px;min-width:40px; width: 40px; text-align: left; font-weight: bold;">#</th>
419
- <th style="font-size:${template.fontSize}px;flex: 1; width: 100%; text-align: left; font-weight: bold; ">Items</th>
420
+ <th style="font-size:${template.fontSize}px;flex: 1; width: 100%; text-align: left; font-weight: bold; ">${count <= 1 ? "Item" : "Items"}</th>
420
421
  <th style="font-size:${template.fontSize}px;max-width: 90px; text-align: right; font-weight: bold;">Price</th>
421
422
  </tr>
422
423
  </thead>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "remove:one": "rimraf dist",
12
12
  "remove:two": "rimraf ./src/dist",
13
13
  "test": "echo \"Error: no test specified\" && exit 1",
14
- "commit": "git add . && git commit -m \"version.2.0.2\" && git push origin "
14
+ "commit": "git add . && git commit -m \"version.2.0.3\" && git push origin "
15
15
  },
16
16
  "files": [
17
17
  "/dist"