meemup-library 1.5.33 → 1.5.35

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.
@@ -23,6 +23,7 @@ declare class _PreviewContentController {
23
23
  labelLayout(detail: IOrderDetails, template: IPrintTemplate): string;
24
24
  paymentFailed(detail: IOrderDetails, currency: string): string;
25
25
  packageLabel(detail: IOrderDetails, template: IPrintTemplate): string;
26
+ preview(account: IAccount, detail: IOrderDetails, template: IPrintTemplate): string;
26
27
  previewForPos(account: IAccount, detail: IOrderDetails, template: IPrintTemplate): string;
27
28
  createPrintFromTurnoverDetail(data: ITurnover, currency: string, printParts: IPointOfSalePrintParts): Promise<string>;
28
29
  createCashDrawerPaidInOutMarkup(device: IPointOfSaleActionFormCashDrawer, setting: IPointOfSaleSetting, member: IPointOfSaleTeamMember): Promise<string>;
@@ -315,33 +315,24 @@ class _PreviewContentController {
315
315
  </div>
316
316
  </div>`;
317
317
  }
318
- // preview(account: IAccount, detail: IOrderDetails, template: IPrintTemplate) {
319
- // switch (template.layout) {
320
- // case EnumPrintLayout.SIMPLE:
321
- // return this.simpleLayout(account, detail, template);
322
- // case EnumPrintLayout.LARGE:
323
- // return this.largeLayout(account, detail, template);
324
- // case EnumPrintLayout.LABEL:
325
- //
326
- // const products: IOrderDetailProduct[] =
327
- // this.filterByCategoryList(
328
- // this.sortProduct(detail.products, template.sortProducts),
329
- // template.printOnlyCertainCategoriesList,
330
- // template.printOnlyCertainCategories,
331
- // template.printOnlyCertainProductsList,
332
- // template.printOnlyCertainProducts);
333
- //
334
- // if (products.length === 0) {
335
- // return `<div>no product </div>`;
336
- // }
337
- //
338
- // return this.labelLayout(detail, template);
339
- // case EnumPrintLayout.PACKAGE_LABEL:
340
- // return this.packageLabel(detail, template);
341
- // default:
342
- // return `<div> template.layout : ${template.layout}</div>`;
343
- // }
344
- // }
318
+ preview(account, detail, template) {
319
+ switch (template.layout) {
320
+ case EnumPrintLayout.SIMPLE:
321
+ return this.simpleLayout(account, detail, template);
322
+ case EnumPrintLayout.LARGE:
323
+ return this.largeLayout(account, detail, template);
324
+ case EnumPrintLayout.LABEL:
325
+ const products = this.filterByCategoryList(this.sortProduct(detail.products, template.sortProducts), template.printOnlyCertainCategoriesList, template.printOnlyCertainCategories, template.printOnlyCertainProductsList, template.printOnlyCertainProducts);
326
+ if (products.length === 0) {
327
+ return `<div>no product </div>`;
328
+ }
329
+ return this.labelLayout(detail, template);
330
+ case EnumPrintLayout.PACKAGE_LABEL:
331
+ return this.packageLabel(detail, template);
332
+ default:
333
+ return `<div> template.layout : ${template.layout}</div>`;
334
+ }
335
+ }
345
336
  previewForPos(account, detail, template) {
346
337
  let content;
347
338
  switch (template.layout) {
@@ -3,7 +3,7 @@ import IPrintTemplate from "../interfaces/IPrintTemplate";
3
3
  import IOrderDetails from "../interfaces/print/IOrderDetails";
4
4
  import IOrderDetailCustomer from "../interfaces/print/IOrderDetailCustomer";
5
5
  import IOrderDetailProduct from "../interfaces/print/IOrderDetailProduct";
6
- declare const _default: {
6
+ declare class _PreviewContentController {
7
7
  createAddressText: (customer: IOrderDetailCustomer) => null | [string, string];
8
8
  ccyFormat: (num: number, pre?: string) => string;
9
9
  calculatePaperSize: (paper: number, width: string | number) => string;
@@ -21,5 +21,6 @@ declare const _default: {
21
21
  paymentFailed(detail: IOrderDetails, currency: string): string;
22
22
  packageLabel(detail: IOrderDetails): string;
23
23
  preview(account: IAccount, detail: IOrderDetails, template: IPrintTemplate, symbol?: string): string;
24
- };
25
- export default _default;
24
+ }
25
+ declare const PreviewContentController: _PreviewContentController;
26
+ export default PreviewContentController;
@@ -1,5 +1,5 @@
1
1
  import PhoneController from "./PhoneController";
2
- export default new class {
2
+ class _PreviewContentController {
3
3
  constructor() {
4
4
  this.createAddressText = (customer) => {
5
5
  let text = "";
@@ -512,4 +512,6 @@ export default new class {
512
512
  return `<div> template.layout : ${template.layout}</div>`;
513
513
  }
514
514
  }
515
- }();
515
+ }
516
+ const PreviewContentController = new _PreviewContentController();
517
+ export default PreviewContentController;
@@ -1,3 +1,5 @@
1
+ import PrintToolController from "./PrintToolController.js";
2
+ import EnumFeeType from "../enums/EnumFeeType.js";
1
3
  import PhoneController from "./PhoneController";
2
4
  import EnumPaymentType from "../enums/EnumPaymentType";
3
5
  import MoneyController from "./MoneyController";
@@ -7,7 +9,7 @@ import EnumPizzaSide from "../enums/EnumPizzaSide";
7
9
  import EnumPaymentState from "../enums/EnumPaymentState";
8
10
  import OrderToolController from "./OrderToolController";
9
11
  import EnumOrderDateTimePrintModeType from "../enums/EnumOrderDateTimePrintModeType";
10
- import { Formats, printPoweredBy } from "../statics";
12
+ import { BundleGroupPreName, BundleIdPreName, BundleProductQuantityPreName, Formats, printPoweredBy } from "../statics";
11
13
  import dayjs from "../utils/dayjs";
12
14
  class SimplePreviewController {
13
15
  constructor() {
@@ -202,6 +204,7 @@ class SimplePreviewController {
202
204
  return content;
203
205
  }
204
206
  printProducts(template, detail) {
207
+ var _a, _b, _c;
205
208
  let content = this.createDivContainer(template);
206
209
  content += `<table style="width: 100%; border-collapse: collapse;">
207
210
  <thead style="border-bottom: 1px solid #000000;">
@@ -213,7 +216,84 @@ class SimplePreviewController {
213
216
  </thead>
214
217
  <tbody>
215
218
  `;
216
- detail.products.forEach((row) => {
219
+ const bundledProducts = detail.products.filter(i => Array.isArray(i.tags) && i.tags.findIndex(tag => tag.startsWith(BundleIdPreName)) !== -1);
220
+ if (bundledProducts.length > 0) {
221
+ const bundleGroups = [];
222
+ bundledProducts.forEach(pro => {
223
+ var _a;
224
+ const tag = (_a = pro.tags) === null || _a === void 0 ? void 0 : _a.find(i => i.startsWith(BundleGroupPreName));
225
+ if (tag) {
226
+ const bundleGroup = (tag + '').split(BundleGroupPreName)[1];
227
+ if (!bundleGroups.includes(bundleGroup)) {
228
+ bundleGroups.push(bundleGroup);
229
+ }
230
+ }
231
+ });
232
+ const bundles = detail.order.items.filter(i => i.type === EnumFeeType.BundleProduct);
233
+ for (let ind = 0; ind < bundleGroups.length; ind++) {
234
+ const group = bundleGroups[ind] + '';
235
+ const groupTag = BundleGroupPreName + group;
236
+ const list = bundledProducts.filter(pro => Array.isArray(pro.tags) && pro.tags.includes(groupTag));
237
+ if (list.length > 0) {
238
+ const firstItem = list[0];
239
+ // const bundleGroup: string = (firstItem.tags?.find(i => i.startsWith(BundleGroupPreName)) + '').split(BundleGroupPreName)[1];
240
+ // const bundleId: number = +(firstItem.tags?.find(i => i.startsWith(BundleIdPreName)) + '').split(BundleIdPreName)[1];
241
+ const firstItemRatio = +(((_a = firstItem.tags) === null || _a === void 0 ? void 0 : _a.find(i => i.startsWith(BundleProductQuantityPreName))) + '').split(BundleProductQuantityPreName)[1];
242
+ const bundleQuantity = firstItem.quantity / firstItemRatio;
243
+ const bundle = bundles.find(i => { var _a; return ((_a = i.metadata.find(j => j.text === "BundleGroup")) === null || _a === void 0 ? void 0 : _a.value) === group; });
244
+ if (bundle) {
245
+ const sharp = ` ${bundleQuantity}×`;
246
+ const sumBundleDiscount = bundle.amount; // bundleQuantity * bundle.discountAmount;
247
+ const _total = MoneyController.sumField(list, 'totalAmount');
248
+ // let _lastTotal = _total - sumBundleDiscount;
249
+ let _lastTotal = _total - sumBundleDiscount;
250
+ if (_lastTotal < 0) {
251
+ _lastTotal = 0;
252
+ }
253
+ const price = template.showPrices ? MoneyController.format(_lastTotal, detail.company.currencySymbol) : '';
254
+ let bundleText = bundle.text;
255
+ bundleText = ((_b = bundleText === null || bundleText === void 0 ? void 0 : bundleText.replace(sharp, '')) === null || _b === void 0 ? void 0 : _b.trim()) + "";
256
+ content += `<tr style="height: 28px;">
257
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;">${sharp}</td>
258
+ <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: left; font-weight: bold;">${bundleText}</td>
259
+ <td style="font-size:${template.fontSize}px; max-width: 90px; text-align: right;">${price}</td>
260
+ </tr>`;
261
+ for (let index = 0; index < list.length; index++) {
262
+ const row = list[index];
263
+ const sharp = `${row.quantity}× `;
264
+ let product = (template.showProductKitchenName && row.kitchenReceiptName !== '' && row.kitchenReceiptName !== null) ? row.kitchenReceiptName : row.title;
265
+ product = sharp + ((_c = product === null || product === void 0 ? void 0 : product.replace(sharp, '')) === null || _c === void 0 ? void 0 : _c.trim()) + "";
266
+ content += `<tr>
267
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
268
+ <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: left; column-span: 2;">${product}</td>
269
+ </tr>`;
270
+ if (row.extrasNames) {
271
+ const extList = row.extras
272
+ .filter(item => !item.doNotPrintOnReceipt)
273
+ .map(item => PrintToolController.extraItemToText(item, template.skipWholePizzaToppingText))
274
+ .filter(i => i.length > 0);
275
+ for (let ind = 0; ind < extList.length; ind++) {
276
+ content += `<tr>
277
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
278
+ <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: left; column-span: 2; padding-left: 24px;">${extList[ind]}</td>
279
+ </tr>`;
280
+ }
281
+ }
282
+ const note = PrintToolController.productNote(row);
283
+ if (note !== '') {
284
+ content += `<tr>
285
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
286
+ <td style="font-size:${template.fontSize}px; font-weight: bold; flex: 1; width: 100%; text-align: left; column-span: 2; padding-left: 24px;">${note}</td>
287
+ </tr>`;
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }
294
+ const unBundledProducts = detail.products.filter(i => !(Array.isArray(i.tags) && i.tags.findIndex(tag => tag.startsWith(BundleIdPreName)) !== -1));
295
+ const list = this.filterByCategoryList(this.sortProduct(unBundledProducts, template.sortProducts), template.printOnlyCertainCategoriesList, template.printOnlyCertainCategories, template.printOnlyCertainProductsList, template.printOnlyCertainProducts);
296
+ list.forEach((row) => {
217
297
  let cat;
218
298
  if (!template.showCategoryTitle || !row.categoryTitle || row.categoryTitle.trim().length === 0)
219
299
  cat = "";
@@ -295,7 +375,7 @@ class SimplePreviewController {
295
375
  ${MoneyController.format(detail.order.subtotalAmount, detail.company.currencySymbol)}
296
376
  </td>
297
377
  </tr>`;
298
- if (detail.order.hstAmount > 0 && detail.order.serviceFee < 1) {
378
+ if (detail.order.hstAmount > 0) {
299
379
  //hst and service fee and company fee amount
300
380
  content += `<tr style=" border-top: 1px dashed #000000; margin: 4px 0;">
301
381
  <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
@@ -319,6 +399,18 @@ class SimplePreviewController {
319
399
  </td>
320
400
  </tr>`;
321
401
  }
402
+ if (detail.order.thirdPartyDriverTipAmount > 0) {
403
+ //tip amount
404
+ content += `<tr style=" border-top: 1px dashed #000000; margin: 4px 0;">
405
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
406
+ <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: right; padding-right: 8px;">
407
+ Driver tip:
408
+ </td>
409
+ <td style="font-size:${template.fontSize}px; width: 90px; text-align: right;">
410
+ ${MoneyController.format(detail.order.thirdPartyDriverTipAmount, detail.company.currencySymbol)}
411
+ </td>
412
+ </tr>`;
413
+ }
322
414
  }
323
415
  content += `</tbody></table>`;
324
416
  //total amount
@@ -335,6 +427,7 @@ class SimplePreviewController {
335
427
  return content;
336
428
  }
337
429
  printLargeProducts(template, detail) {
430
+ var _a, _b, _c;
338
431
  let content = this.createDivContainer(template);
339
432
  const largeFontSize = template.printer === 5 ? 22 : parseInt((template.fontSize + 10) + "");
340
433
  content += `<table style="width: 100%; border-collapse: collapse;">
@@ -347,16 +440,95 @@ class SimplePreviewController {
347
440
  </thead>
348
441
  <tbody>
349
442
  `;
350
- detail.products.forEach((row) => {
443
+ const bundledProducts = detail.products.filter(i => Array.isArray(i.tags) && i.tags.findIndex(tag => tag.startsWith(BundleIdPreName)) !== -1);
444
+ if (bundledProducts.length > 0) {
445
+ const bundleGroups = [];
446
+ bundledProducts.forEach(pro => {
447
+ var _a;
448
+ const tag = (_a = pro.tags) === null || _a === void 0 ? void 0 : _a.find(i => i.startsWith(BundleGroupPreName));
449
+ if (tag) {
450
+ const bundleGroup = (tag + '').split(BundleGroupPreName)[1];
451
+ if (!bundleGroups.includes(bundleGroup)) {
452
+ bundleGroups.push(bundleGroup);
453
+ }
454
+ }
455
+ });
456
+ const bundles = detail.order.items.filter(i => i.type === EnumFeeType.BundleProduct);
457
+ for (let ind = 0; ind < bundleGroups.length; ind++) {
458
+ const group = bundleGroups[ind] + '';
459
+ const groupTag = BundleGroupPreName + group;
460
+ const list = bundledProducts.filter(pro => Array.isArray(pro.tags) && pro.tags.includes(groupTag));
461
+ if (list.length > 0) {
462
+ const firstItem = list[0];
463
+ const firstItemRatio = +(((_a = firstItem.tags) === null || _a === void 0 ? void 0 : _a.find(i => i.startsWith(BundleProductQuantityPreName))) + '').split(BundleProductQuantityPreName)[1];
464
+ const bundleQuantity = firstItem.quantity / firstItemRatio;
465
+ const bundle = bundles.find(i => { var _a; return ((_a = i.metadata.find(j => j.text === "BundleGroup")) === null || _a === void 0 ? void 0 : _a.value) === group; });
466
+ if (bundle) {
467
+ const sharp = ` ${bundleQuantity}×`;
468
+ const sumBundleDiscount = bundle.amount; // bundleQuantity * bundle.discountAmount;
469
+ const _total = MoneyController.sumField(list, 'totalAmount');
470
+ // let _lastTotal = _total - sumBundleDiscount;
471
+ let _lastTotal = _total - sumBundleDiscount;
472
+ if (_lastTotal < 0) {
473
+ _lastTotal = 0;
474
+ }
475
+ const price = template.showPrices ? MoneyController.format(_lastTotal, detail.company.currencySymbol) : '';
476
+ let bundleText = bundle.text;
477
+ bundleText = ((_b = bundleText === null || bundleText === void 0 ? void 0 : bundleText.replace(sharp, '')) === null || _b === void 0 ? void 0 : _b.trim()) + "";
478
+ content += `<tr>
479
+ <td style="font-size:${largeFontSize}px; min-width:40px; width: 40px; text-align: left;">${sharp}</td>
480
+ <td style="font-size:${largeFontSize}px; flex: 1; width: 100%; text-align: left; font-weight: bold;">${bundleText}</td>
481
+ <td style="font-size:${largeFontSize}px; max-width: 90px; text-align: right;">${price}</td>
482
+ </tr>`;
483
+ for (let index = 0; index < list.length; index++) {
484
+ const row = list[index];
485
+ const sharp = `${row.quantity}× `;
486
+ let product = (template.showProductKitchenName && row.kitchenReceiptName !== '' && row.kitchenReceiptName !== null) ? row.kitchenReceiptName : row.title;
487
+ product = sharp + ((_c = product === null || product === void 0 ? void 0 : product.replace(sharp, '')) === null || _c === void 0 ? void 0 : _c.trim()) + "";
488
+ // content += `<tr>
489
+ // <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
490
+ // <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: left; column-span: 2;">${product}</td>
491
+ // </tr>`;
492
+ content += `<tr>
493
+ <td style="font-size:${largeFontSize}px; min-width:40px; width: 40px; text-align: left;">&ensp;</td>
494
+ <td style="font-size:${largeFontSize}px; flex: 1; width: 100%; text-align: left; column-span: 2;">${product}</td>
495
+ </tr>`;
496
+ if (row.extrasNames) {
497
+ const extList = row.extras
498
+ .filter(item => !item.doNotPrintOnReceipt)
499
+ .map(item => PrintToolController.extraItemToText(item, template.skipWholePizzaToppingText))
500
+ .filter(i => i.length > 0);
501
+ for (let ind = 0; ind < extList.length; ind++) {
502
+ content += `<tr>
503
+ <td style=" min-width:40px; width: 40px;">&ensp;</td>
504
+ <td style="font-size:${largeFontSize}px; flex: 1; width: 100%; text-align: left;column-span: 2; padding-left: 24px;">${extList[ind]}</td>
505
+ </tr>`;
506
+ }
507
+ }
508
+ const note = PrintToolController.productNote(row);
509
+ if (note !== '') {
510
+ content += `<tr>
511
+ <td style=" min-width:40px; width: 40px;">&ensp;</td>
512
+ <td style="font-size:${largeFontSize}px; flex: 1; width: 100%; text-align: left;column-span: 2; padding-left: 24px;">${note}</td>
513
+ </tr>`;
514
+ }
515
+ }
516
+ }
517
+ }
518
+ }
519
+ }
520
+ const unBundledProducts = detail.products.filter(i => !(Array.isArray(i.tags) && i.tags.findIndex(tag => tag.startsWith(BundleIdPreName)) !== -1));
521
+ const list = this.filterByCategoryList(this.sortProduct(unBundledProducts, template.sortProducts), template.printOnlyCertainCategoriesList, template.printOnlyCertainCategories, template.printOnlyCertainProductsList, template.printOnlyCertainProducts);
522
+ list.forEach((row) => {
351
523
  const productName = (template.showCategoryTitle ? `[${row.categoryTitle}] ` : "") + ((template.showProductKitchenName && row.kitchenReceiptName !== null) ? row.kitchenReceiptName : row.title);
352
524
  const amount = template.showPrices ? MoneyController.format(row.totalAmount, detail.company.currencySymbol) : "";
353
525
  content += `<tr>
354
- <td style="font-size:${largeFontSize}px; min-width:40px; width: 40px; text-align: left;">${row.quantity}X</td>
526
+ <td style="font-size:${largeFontSize}px; min-width:40px; width: 40px; text-align: left;">${row.quantity}×</td>
355
527
  <td style="font-size:${largeFontSize}px; flex: 1; width: 100%; text-align: left; font-weight: bold;">${productName}</td>
356
528
  <td style="font-size:${largeFontSize}px; max-width: 90px; text-align: right;">${amount}</td>
357
529
  </tr>`;
358
530
  row.extras.filter(i => !i.doNotPrintOnReceipt).forEach(element => {
359
- const extraText = this.pizzaSideText(element.pizzaSide, template.skipWholePizzaToppingText) + element.quantity + "X " + element.extraItemTitle;
531
+ const extraText = this.pizzaSideText(element.pizzaSide, template.skipWholePizzaToppingText) + element.quantity + "× " + element.extraItemTitle;
360
532
  const extraAmount = template.showPrices ? MoneyController.format(element.totalAmount, detail.company.currencySymbol) : "";
361
533
  content += `<tr>
362
534
  <td style="font-size:${largeFontSize}px; min-width:40px; width: 40px; text-align: left;">&ensp;</td>
@@ -417,7 +589,7 @@ class SimplePreviewController {
417
589
  ${MoneyController.format(detail.order.subtotalAmount, detail.company.currencySymbol)}
418
590
  </td>
419
591
  </tr>`;
420
- if (detail.order.hstAmount > 0 && detail.order.serviceFee < 1) {
592
+ if (detail.order.hstAmount > 0) {
421
593
  //hst and service fee and company fee amount
422
594
  content += `<tr style=" border-top: 1px dashed #000000; margin: 4px 0;">
423
595
  <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
@@ -441,6 +613,18 @@ class SimplePreviewController {
441
613
  </td>
442
614
  </tr>`;
443
615
  }
616
+ if (detail.order.thirdPartyDriverTipAmount > 0) {
617
+ //tip amount
618
+ content += `<tr style=" border-top: 1px dashed #000000; margin: 4px 0;">
619
+ <td style="font-size:${template.fontSize}px; min-width:40px; width: 40px; text-align: left;"></td>
620
+ <td style="font-size:${template.fontSize}px; flex: 1; width: 100%; text-align: right; padding-right: 8px;">
621
+ Driver tip:
622
+ </td>
623
+ <td style="font-size:${template.fontSize}px; width: 90px; text-align: right;">
624
+ ${MoneyController.format(detail.order.thirdPartyDriverTipAmount, detail.company.currencySymbol)}
625
+ </td>
626
+ </tr>`;
627
+ }
444
628
  }
445
629
  content += `</tbody></table>`;
446
630
  //total amount
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.5.33",
3
+ "version": "1.5.35",
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.1.5.33\" && git push origin "
14
+ "commit": "git add . && git commit -m \"version.1.5.35\" && git push origin "
15
15
  },
16
16
  "files": [
17
17
  "/dist"
@@ -26,4 +26,4 @@
26
26
  "dependencies": {
27
27
  "dayjs": "^1.11.13"
28
28
  }
29
- }
29
+ }