Esempio n. 1
0
  private String getFiscalString(PosReceipt posReceipt) {
    String s =
        "\r\n"
            + zeroLead(posReceipt.getNumbeReceipt())
            + " "
            + zeroLead(posReceipt.getNumberDoc())
            + " "
            + posReceipt.getSection()
            + " K"
            + posReceipt.getPassword();

    switch (posReceipt.getReceiptType()) {
      case PosReceipt.TYPE_SALE:
        s = s + " ==" + POSUtil.getReceiptSum(posReceipt.getReceipt());
        break;

      case PosReceipt.TYPE_MONEY_IN:
        s = s + posReceipt.getCash();
        break;

      case PosReceipt.TYPE_MONEY_OUT:
        s = s + posReceipt.getCash();
        break;
    }

    return s;
  }
Esempio n. 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());
    }
  }
Esempio n. 3
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;
  }