Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
3.9 kB
2
Indexable
Never
let orderItems = data.items.map(item => item.name);
   let orderList = data.items.map((item, index) => {
      let el = [];
      el.push(`x${item.quantity}`);
      el.push('');
      el.push(item.price.toFixed(2));
      return el;
   })

   let columnAliment = [0, 1, 2];
   let columnWidth = [23, 1, 13];
   try {
      //set aligment: 0-left,1-center,2-right
      await SunmiV2Printer.setAlignment(1);
      if (data.logoBitmap.length) {
         await SunmiV2Printer.printBitmap(
            data.logoBitmap,
            384 /*width*/,
            380 /*height*/
         );
         SunmiV2Printer.commitPrinterBuffer();
      }
      await SunmiV2Printer.printOriginalText('\n\n');
      await SunmiV2Printer.setFontSize(28);
      await SunmiV2Printer.printOriginalText(`#${data.order} | ${data.buyerFirstName}\n`);
      await SunmiV2Printer.setFontSize(20);
      await SunmiV2Printer.printOriginalText(`${data.time}\n`);
      await SunmiV2Printer.printOriginalText('\n');
      if (data.note && data.note.length) {
         await SunmiV2Printer.printOriginalText(`Note from client: ${data.note}`);
         await SunmiV2Printer.printOriginalText('\n');
      }
      await SunmiV2Printer.setAlignment(0);
      if (data.pickupTime && data.pickupTime.length) {
         let buff_1 = ['Pickup time', '', data.pickupTime];
         await SunmiV2Printer.printColumnsText(
            buff_1,
            columnWidth,
            columnAliment,
         );
      } else {
         await SunmiV2Printer.printOriginalText(`${data.deliveryAddress}\n`);
         if (data.deliveryTime)
            await SunmiV2Printer.printOriginalText(`Delivery time: ${data.deliveryTime}\n`);
      }
      let buff = ['Total articles', '', `${data.items.length} articles`];
      await SunmiV2Printer.printColumnsText(
         buff,
         columnWidth,
         columnAliment,
      );
      columnWidth = [28, 1, 8];
      await SunmiV2Printer.printOriginalText(
         '======================================\n',
      );
      for (var i in orderList) {
         await SunmiV2Printer.printOriginalText(`${orderItems[i]}\n`);
         await SunmiV2Printer.printColumnsText(
            orderList[i],
            columnWidth,
            columnAliment
         );
      }
      await SunmiV2Printer.printOriginalText(
         '======================================\n',
      );
      await SunmiV2Printer.printOriginalText('\n');
      await SunmiV2Printer.setAlignment(0);
      if (data.auto === false) {
         await SunmiV2Printer.printOriginalText('1\n');
         await SunmiV2Printer.printBitmap(
            data.logoBitmap,
            384 /*width*/,
            380 /*height*/
         );
         SunmiV2Printer.commitPrinterBuffer();
         await SunmiV2Printer.printOriginalText('2\n');
         await SunmiV2Printer.printBitmap(
            data.logoBitmap,
            140 /*width*/,
            44 /*height*/
         );
         SunmiV2Printer.commitPrinterBuffer();
         await SunmiV2Printer.printOriginalText('3\n');
         await SunmiV2Printer.printBitmap(
            halalLogo,
            140,
            44
         );
         SunmiV2Printer.commitPrinterBuffer();
      }
      await SunmiV2Printer.printOriginalText('\n');
      await SunmiV2Printer.setAlignment(2);
      await SunmiV2Printer.setFontSize(24);
      await SunmiV2Printer.printOriginalText(`Tax: ${data.tax}\n`);
      if (data.refundHere && data.refund) {
         await SunmiV2Printer.printOriginalText(`Refund: -${data.refund}\n`);
      }
      // if (data.subTotal) {
      //    await SunmiV2Printer.printOriginalText(`Items total: ${data.subTotal}\n`);
      // }
      // await SunmiV2Printer.printOriginalText(`Shipping: ${data.shipping}\n`);
      await SunmiV2Printer.printOriginalText(`Total: ${data.total}\n`);
      await SunmiV2Printer.printOriginalText('\n\n');