Пример #1
0
  private String getRecieptRows(PosReceipt posReceipt) {
    String s = "";

    for (ReceiptRow receiptRow : posReceipt.getReceipt().getReceiptRows()) {
      s +=
          receiptRow.getItemName()
              + "\r\n"
              + receiptRow.getPrice()
              + " x "
              + receiptRow.getQuantity()
              + "="
              + Money.MULTIPLY(receiptRow.getPrice(), receiptRow.getQuantity())
              + "\r\n";
    }

    return s;
  }
Пример #2
0
  @Override
  public Result printReceipt(Path receiptsFile) {
    try {
      PosReceipt posReceipt = PosReceipt.getFromJSON(receiptsFile);

      List<String> lines =
          Files.readAllLines(
              rootPath.resolve(Paths.get("templates", "receipt.txt")), Charset.defaultCharset());

      String receipt = "";
      for (String line : lines) {
        line = line.replaceAll("\\{receiptRows\\}", getRecieptRows(posReceipt));
        line = line.replaceAll("\\{totalDiscountSum\\}", "" + posReceipt.getTotalDiscountSum());
        line =
            line.replaceAll("\\{totalSum\\}", "" + POSUtil.getReceiptSum(posReceipt.getReceipt()));
        line = line.replaceAll("\\{cash\\}", "" + posReceipt.getCash());
        line =
            line.replaceAll(
                "\\{rest\\}",
                ""
                    + Money.SUBSTRACT(
                        posReceipt.getCash(), POSUtil.getReceiptSum(posReceipt.getReceipt())));
        line = line.replaceAll("\\{fiscal\\}", getFiscalString(posReceipt));

        receipt += line + "\r\n";
      }

      printStringList = Arrays.asList(receipt.split("\r\n"));
      printDoc();
      return Result.newEmptySuccess();

    } catch (Exception e) {
      Logger.getGlobal().log(Level.WARNING, null, e);
      return Result.newResultError(e.toString());
    }
  }