@posx/core 5.5.357 → 5.5.363

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/build/index.d.ts CHANGED
@@ -1520,6 +1520,10 @@ interface ISectionItem extends IAppBaseModel {
1520
1520
  /** List of printer ID order */
1521
1521
  printer_id_order_list: number[];
1522
1522
  order_printer_uids: string[];
1523
+ /** Receipt printer UID for this section item */
1524
+ receipt_printer_uid: string;
1525
+ /** Check printer UID for this section item */
1526
+ check_printer_uid: string;
1523
1527
  /** Total amount */
1524
1528
  total: number;
1525
1529
  /** Time duration */
@@ -1557,6 +1561,8 @@ interface ISectionItem extends IAppBaseModel {
1557
1561
  declare class SectionItem extends AppBaseModel implements ISectionItem {
1558
1562
  printer_id_order_list: number[];
1559
1563
  order_printer_uids: string[];
1564
+ receipt_printer_uid: string;
1565
+ check_printer_uid: string;
1560
1566
  total: number;
1561
1567
  time: number;
1562
1568
  pax: number;
@@ -2719,9 +2725,11 @@ interface IInvoiceCoreLine {
2719
2725
  unit_of_measure: UomType;
2720
2726
  /** Quantity if it is quantity, e.g. 5*/
2721
2727
  quantity: number;
2722
- /** Whether it is sent to server, e.g. send = 3, it means 2 items are not sent to server*/
2723
- /** item A, qty = 5 sent 3 => kitchen slip will show quantity 2 on item A */
2728
+ /** 已发送到厨房的数量,如 qty=5, sent=3 表示还有2个未发送 */
2729
+ /** minusLineQuantity (quantity - sent) 计算可自由删除的未发送数量 */
2724
2730
  sent: number;
2731
+ /** UI标志,用于Order List区分已下单/未下单,应与 sent > 0 同步 */
2732
+ is_sent: boolean;
2725
2733
  /** Whether cancel slip is printed */
2726
2734
  is_cancel_printed: boolean;
2727
2735
  /** Whether it is selected */
@@ -2936,6 +2944,7 @@ declare class InvoiceCoreLine implements IInvoiceCoreLine {
2936
2944
  unit_of_measure: UomType;
2937
2945
  quantity: number;
2938
2946
  sent: number;
2947
+ is_sent: boolean;
2939
2948
  is_cancel_printed: boolean;
2940
2949
  selected: boolean;
2941
2950
  constructor();
@@ -2965,6 +2974,7 @@ declare class InvoiceLine extends AppCoreModel implements IInvoiceLine {
2965
2974
  modifiers: any[];
2966
2975
  duplicated_from_uid: string;
2967
2976
  sent: number;
2977
+ is_sent: boolean;
2968
2978
  is_cancel_printed: boolean;
2969
2979
  selected: boolean;
2970
2980
  meta: {};
@@ -4154,6 +4164,8 @@ interface IPrinter extends IAppBaseModel {
4154
4164
  device_uid: string;
4155
4165
  /** Printer type */
4156
4166
  type: PrinterType;
4167
+ /** If true, this printer is not the default for its type */
4168
+ is_not_default?: boolean;
4157
4169
  /** Actual printer name using printer driver*/
4158
4170
  driver_printer_name: string;
4159
4171
  /** Backup printer ID */
@@ -4180,6 +4192,7 @@ interface IPrinter extends IAppBaseModel {
4180
4192
  declare class Printer extends AppBaseModel implements IPrinter {
4181
4193
  device_uid: string;
4182
4194
  type: PrinterType;
4195
+ is_not_default?: boolean;
4183
4196
  driver_printer_name: string;
4184
4197
  fallback_printer_uid: number;
4185
4198
  protocol: PrinterProtocols;
@@ -4997,6 +5010,7 @@ declare class PrinterService extends AppRemoteService<IPrinter> implements IPrin
4997
5010
  getPhysicalPrintersFromNode(): Promise<INodePrinter[]>;
4998
5011
  getUnpairedNode(): Promise<CustomResponse<INode>>;
4999
5012
  pairNode(nodeUid: string): Promise<CustomResponse<INode>>;
5013
+ private getDefaultPrinter;
5000
5014
  getDefaultReceiptPrinter(): Promise<IPrinter>;
5001
5015
  getDefaultPrinterByType(type: PrinterType): Promise<IPrinter>;
5002
5016
  getDefaultKioskPrinter(): Promise<IPrinter>;
@@ -5083,6 +5097,7 @@ type LineOptions = {
5083
5097
  quantity?: number;
5084
5098
  price?: number;
5085
5099
  remark?: string;
5100
+ is_sent?: boolean;
5086
5101
  };
5087
5102
  declare class InvoiceBaseService extends AppRemoteService<IInvoice> implements IInvoiceBaseService {
5088
5103
  readonly http: AxiosInstance;
@@ -5371,7 +5386,7 @@ declare class LineOperationService extends InvoiceBaseService implements ILineOp
5371
5386
  addModifierQuantity(modifiers: IInvoiceCoreLine[], modifier: IInvoiceCoreLine, quantity?: number): IInvoiceCoreLine[];
5372
5387
  changeModifierPrice(modifier: IInvoiceCoreLine, price: number): IInvoiceCoreLine;
5373
5388
  overwriteNoteToLine(line: IInvoiceLine, note: string): IInvoiceLine;
5374
- findOrCreateLine(invoice: IInvoice, item: IItem, quantity: number, price?: number, modifiers?: IInvoiceCoreLine[], remark?: string, createNewLine?: boolean, comboLineUid?: string, comboGroupUid?: string): IInvoiceLine;
5389
+ findOrCreateLine(invoice: IInvoice, item: IItem, quantity: number, price?: number, modifiers?: IInvoiceCoreLine[], remark?: string, createNewLine?: boolean, comboLineUid?: string, comboGroupUid?: string, is_sent?: boolean): IInvoiceLine;
5375
5390
  private createInvoiceLine;
5376
5391
  protected compareModifiers(target: IInvoiceCoreLine[], source: IInvoiceCoreLine[]): boolean;
5377
5392
  /**
package/build/index.js CHANGED
@@ -419,6 +419,8 @@ var SectionItem = class extends AppBaseModel {
419
419
  super();
420
420
  _defineProperty(this, "printer_id_order_list", []);
421
421
  _defineProperty(this, "order_printer_uids", []);
422
+ _defineProperty(this, "receipt_printer_uid", "");
423
+ _defineProperty(this, "check_printer_uid", "");
422
424
  _defineProperty(this, "total", 0);
423
425
  _defineProperty(this, "time", 0);
424
426
  _defineProperty(this, "pax", 0);
@@ -1425,6 +1427,7 @@ var Printer = class extends AppBaseModel {
1425
1427
  super();
1426
1428
  _defineProperty(this, "device_uid", "");
1427
1429
  _defineProperty(this, "type", PrinterType.ReceiptPrinter);
1430
+ _defineProperty(this, "is_not_default", false);
1428
1431
  _defineProperty(this, "driver_printer_name", "");
1429
1432
  _defineProperty(this, "fallback_printer_uid", 0);
1430
1433
  _defineProperty(this, "protocol", PrinterProtocols.ESCPOS);
@@ -1712,6 +1715,7 @@ var InvoiceCoreLine = class {
1712
1715
  _defineProperty(this, "unit_of_measure", UomType.quantity);
1713
1716
  _defineProperty(this, "quantity", 0);
1714
1717
  _defineProperty(this, "sent", 0);
1718
+ _defineProperty(this, "is_sent", false);
1715
1719
  _defineProperty(this, "is_cancel_printed", false);
1716
1720
  _defineProperty(this, "selected", false);
1717
1721
  }
@@ -1743,6 +1747,7 @@ var InvoiceLine = class extends AppCoreModel {
1743
1747
  _defineProperty(this, "modifiers", []);
1744
1748
  _defineProperty(this, "duplicated_from_uid", "");
1745
1749
  _defineProperty(this, "sent", 0);
1750
+ _defineProperty(this, "is_sent", false);
1746
1751
  _defineProperty(this, "is_cancel_printed", false);
1747
1752
  _defineProperty(this, "selected", false);
1748
1753
  _defineProperty(this, "meta", {});
@@ -2453,23 +2458,27 @@ var PrinterService = class extends AppRemoteService {
2453
2458
  async pairNode(nodeUid) {
2454
2459
  return this.http.get(`api/v5/merchants/` + this.options.merchant_uid + `/nodes/${nodeUid}/pair-node`);
2455
2460
  }
2461
+ async getDefaultPrinter(type) {
2462
+ const printers = await this.db.table("printers").filter((p) => p.type === type && p.deleted_at == null).toArray();
2463
+ return printers.find((p) => !p.is_not_default) || printers[0] || null;
2464
+ }
2456
2465
  async getDefaultReceiptPrinter() {
2457
- return this.getOneByParams({ type: PrinterType.ReceiptPrinter });
2466
+ return this.getDefaultPrinter(PrinterType.ReceiptPrinter);
2458
2467
  }
2459
2468
  async getDefaultPrinterByType(type) {
2460
- return this.getOneByParams({ type });
2469
+ return this.getDefaultPrinter(type);
2461
2470
  }
2462
2471
  async getDefaultKioskPrinter() {
2463
- return this.getOneByParams({ type: PrinterType.KioskPrinter });
2472
+ return this.getDefaultPrinter(PrinterType.KioskPrinter);
2464
2473
  }
2465
2474
  async getDefaultCheckPrinter() {
2466
- return this.getOneByParams({ type: PrinterType.CheckPrinter });
2475
+ return this.getDefaultPrinter(PrinterType.CheckPrinter);
2467
2476
  }
2468
2477
  async getDefaultKitchenPrinter() {
2469
- return this.getOneByParams({ type: PrinterType.KitchenPrinter });
2478
+ return this.getDefaultPrinter(PrinterType.KitchenPrinter);
2470
2479
  }
2471
2480
  async getDefaultOrderPrinter() {
2472
- return this.getOneByParams({ type: PrinterType.OrderPrinter });
2481
+ return this.getDefaultPrinter(PrinterType.OrderPrinter);
2473
2482
  }
2474
2483
  async getPrintersByUids(uids) {
2475
2484
  return this.db.table("printers").where("uid").anyOf(uids).filter((printer) => printer.deleted_at == null).toArray();
@@ -3304,8 +3313,10 @@ var InvoiceBaseService = class extends AppRemoteService {
3304
3313
  invoice.service_chargeable_subtotal = 0;
3305
3314
  }
3306
3315
  this.calculateInvoiceCharges(invoice, CalcFlow.AfterSubtotal);
3307
- const serviceChargeableDiscountRatio = invoice.discountable_subtotal > 0 ? invoice.service_chargeable_subtotal / invoice.discountable_subtotal : 0;
3308
- invoice.service_chargeable_subtotal = preciseRound(Math.max(0, invoice.service_chargeable_subtotal - invoice.discount_amount * serviceChargeableDiscountRatio));
3316
+ if (invoice.subtotal > 0 && invoice.discount_amount > 0) {
3317
+ const discountRatio = 1 - invoice.discount_amount / invoice.subtotal;
3318
+ invoice.service_chargeable_subtotal = preciseRound(Math.max(0, invoice.service_chargeable_subtotal * discountRatio), 2);
3319
+ } else if (invoice.discount_amount >= invoice.subtotal) invoice.service_chargeable_subtotal = 0;
3309
3320
  const serviceChargeRate = appConfig.config.charges.service_charge ? appConfig.config.charges.service_charge_rate : 0;
3310
3321
  this.calculateServiceCharge(invoice, serviceChargeRate);
3311
3322
  this.calculateDiscount(invoice, CalcFlow.AfterServiceCharge);
@@ -3482,16 +3493,11 @@ var InvoiceBaseService = class extends AppRemoteService {
3482
3493
  invoice.tax = 0;
3483
3494
  if (taxRate <= 0) return;
3484
3495
  const ratio = this.calculateTaxSubtotalRatio(invoice);
3485
- if (taxMethod === TaxMethod.Inclusive) {
3486
- invoice.tax = preciseRound((invoice.grand_total - invoice.service_chargeable_subtotal) * ratio * taxRate / (100 + taxRate), 2);
3487
- invoice.tax += preciseRound(invoice.service_chargeable_subtotal * taxRate * ratio / (100 + taxRate), 2);
3488
- invoice.tax = preciseRound(invoice.tax, 2);
3489
- } else {
3490
- invoice.tax = preciseRound((invoice.grand_total - invoice.service_chargeable_subtotal) * ratio * taxRate / 100, 2);
3491
- invoice.tax += preciseRound(invoice.service_chargeable_subtotal * taxRate * ratio / 100, 2);
3492
- invoice.tax = preciseRound(invoice.tax, 2);
3493
- invoice.grand_total += invoice.tax;
3494
- invoice.grand_total = preciseRound(invoice.grand_total, 2);
3496
+ const taxableBase = invoice.grand_total - invoice.service_charge;
3497
+ if (taxMethod === TaxMethod.Inclusive) invoice.tax = preciseRound(taxableBase * ratio * taxRate / (100 + taxRate) + invoice.service_charge * taxRate / (100 + taxRate), 2);
3498
+ else {
3499
+ invoice.tax = preciseRound(taxableBase * ratio * taxRate / 100 + invoice.service_charge * taxRate / 100, 2);
3500
+ invoice.grand_total = preciseRound(invoice.grand_total + invoice.tax, 2);
3495
3501
  }
3496
3502
  }
3497
3503
  /**
@@ -3618,7 +3624,7 @@ var LineOperationService = class extends InvoiceBaseService {
3618
3624
  ...lineOptions
3619
3625
  };
3620
3626
  if (invoice.lines == null) invoice.lines = [];
3621
- const line = this.findOrCreateLine(invoice, item, options.quantity, options.price, modifiers, options.remark, createNewLine, comboLineUid, comboGroupUid);
3627
+ const line = this.findOrCreateLine(invoice, item, options.quantity, options.price, modifiers, options.remark, createNewLine, comboLineUid, comboGroupUid, options.is_sent);
3622
3628
  if (item.type == ProductType.Combo) line.is_combo = true;
3623
3629
  if (line.uid) {
3624
3630
  line.quantity += options.quantity;
@@ -3739,7 +3745,7 @@ var LineOperationService = class extends InvoiceBaseService {
3739
3745
  line.remark = note;
3740
3746
  return line;
3741
3747
  }
3742
- findOrCreateLine(invoice, item, quantity, price = 0, modifiers = [], remark = "", createNewLine = false, comboLineUid, comboGroupUid) {
3748
+ findOrCreateLine(invoice, item, quantity, price = 0, modifiers = [], remark = "", createNewLine = false, comboLineUid, comboGroupUid, is_sent) {
3743
3749
  price = price ?? item.price;
3744
3750
  if (!invoice.lines || invoice.lines.length <= 0 || createNewLine) return this.createInvoiceLine(item, quantity, price, modifiers, remark);
3745
3751
  else {
@@ -3748,7 +3754,7 @@ var LineOperationService = class extends InvoiceBaseService {
3748
3754
  else {
3749
3755
  if (comboLineUid && comboGroupUid) {
3750
3756
  for (const line of lines.filter((l) => l.is_combo_item)) if (this.compareModifiers(line.modifiers, modifiers) && line.remark === remark && line.price === price && line.combo_line_uid === comboLineUid && line.combo_group_uid === comboGroupUid) return line;
3751
- } else for (const line of lines) if (this.compareModifiers(line.modifiers, modifiers) && line.remark === remark && line.price === price && !line.is_take_out) return line;
3757
+ } else for (const line of lines) if (this.compareModifiers(line.modifiers, modifiers) && line.remark === remark && line.price === price && !line.is_take_out && (is_sent === void 0 || line.is_sent === is_sent)) return line;
3752
3758
  return this.createInvoiceLine(item, quantity, price, modifiers, remark);
3753
3759
  }
3754
3760
  }
@@ -4369,8 +4375,12 @@ var InvoiceOperationService = class extends LineOperationService {
4369
4375
  async createReceiptPrintJob(invoice, printerType, saveOnly = false, printTimes = 0, specificPrinter = null, specificDeviceUid) {
4370
4376
  let printer;
4371
4377
  if (specificPrinter) printer = specificPrinter;
4372
- else if (printerType == PrinterType.ReceiptPrinter) printer = await this.printerService.getDefaultReceiptPrinter();
4373
- else if (printerType == PrinterType.CheckPrinter) printer = await this.printerService.getDefaultCheckPrinter();
4378
+ else if (printerType == PrinterType.ReceiptPrinter || printerType == PrinterType.CheckPrinter) {
4379
+ const sectionItem = invoice.table_uid ? await this.sectionItemService.getOne(invoice.table_uid) : null;
4380
+ const printerUid = printerType == PrinterType.ReceiptPrinter ? sectionItem?.receipt_printer_uid : sectionItem?.check_printer_uid;
4381
+ if (printerUid) printer = await this.printerService.getOne(printerUid);
4382
+ if (!printer) printer = printerType == PrinterType.ReceiptPrinter ? await this.printerService.getDefaultReceiptPrinter() : await this.printerService.getDefaultCheckPrinter();
4383
+ }
4374
4384
  if (!printer || !printer.print_template_uid) return null;
4375
4385
  if (!printTimes) printTimes = printer.print_times;
4376
4386
  const appConfig = await this.configService.getDefaultOne();
@@ -4579,7 +4589,10 @@ var InvoiceOperationService = class extends LineOperationService {
4579
4589
  });
4580
4590
  }
4581
4591
  async preprocessInvoice(invoice) {
4582
- if (invoice.lines) for (const line of invoice.lines) line.sent = line.quantity;
4592
+ if (invoice.lines) for (const line of invoice.lines) {
4593
+ line.sent = line.quantity;
4594
+ line.is_sent = true;
4595
+ }
4583
4596
  return invoice;
4584
4597
  }
4585
4598
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.357",
3
+ "version": "5.5.363",
4
4
  "description": "POSX core libraries",
5
5
  "main": "./build/index.js",
6
6
  "author": "Steven Lee",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.357",
3
+ "version": "5.5.363",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",