<p>Reveal shared tax rules for invoice..</p>
@param pReqVars request scoped vars
@param pInv invoice
@param pAs Accounting Settings
@param pIsExtrTx if extract taxes
@return tax rules, NULL if not taxable
@throws Exception - an exception.
327841
public final TaxDestination revealTaxRules(final Map<String, Object> pReqVars,
    final IInvoice pInv, final AccSettings pAs,
      final Boolean pIsExtrTx) throws Exception {
    return this.utlInvBase.revealTaxRules(pReqVars, pInv, pAs, pIsExtrTx);
  }
665466
protected final PrcSalesInvoiceServiceLineSave<RS>
    lazyGetPrcSalesInvoiceServiceLineSave(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcSalesInvoiceServiceLineSave<RS> proc =
      (PrcSalesInvoiceServiceLineSave<RS>) this.processorsMap
        .get(PrcSalesInvoiceServiceLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcSalesInvoiceServiceLineSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setUtlInvLine(lazyGetUtlSalSrLn(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcSalesInvoiceServiceLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
519665
@Override
  public final void makeReport(final Map<String, Object> pReqVars,
    final SalesInvoice pInvoice, final IRequestData pRequestData,
      final OutputStream pOus) throws Exception {
    AccSettings accSet = this.srvAccSettings.lazyGetAccSettings(pReqVars);
    String lang = (String) pReqVars.get("lang");
    String langDef = (String) pReqVars.get("langDef");
    DateFormat dateFormat = DateFormat
      .getDateInstance(DateFormat.MEDIUM, new Locale(lang));
    SalesInvoice inv = retrieveEntity(pReqVars, pInvoice, lang,
      !lang.equals(langDef));
    boolean isInvoiceBasis = false;
    for (SalesInvoiceTaxLine itl : inv.getTaxesLines()) {
      if (itl.getTaxableInvBas().compareTo(BigDecimal.ZERO) == 1) {
        isInvoiceBasis = true;
        break;
      }
    }
    Currency currency;
    if (inv.getForeignCurrency() != null) {
      currency = inv.getForeignCurrency();
    } else {
      currency = accSet.getCurrency();
    }
    String priceName;
    if (inv.getPriceIncTax()) {
      priceName = "priceIncTax";
    } else {
      priceName = "itsPrice";
    }
    I18nCurrency i18nCurrency = null;
    String curSign;
    boolean isPrnCurLf;
    if (!lang.equals(langDef)) {
      List<I18nCurrency> i18nCurrencyLst = this.srvOrm.retrieveList(
        pReqVars, I18nCurrency.class);
      for (I18nCurrency i18nCur : i18nCurrencyLst) {
        if (i18nCur.getHasName().getItsId().equals(currency.getItsId())
          && i18nCur.getLang().getItsId().equals(lang)) {
          i18nCurrency = i18nCur;
          break;
        }
      }
    }
    if (i18nCurrency != null) {
      isPrnCurLf = i18nCurrency.getPrintCurrencyLeft();
      if (i18nCurrency.getUseCurrencySign()) {
        curSign = i18nCurrency.getHasName().getItsSign();
      } else {
        curSign = " " + i18nCurrency.getItsName() + " ";
      }
    } else {
      isPrnCurLf = accSet.getPrintCurrencyLeft();
      if (accSet.getUseCurrencySign()) {
        curSign = currency.getItsSign();
      } else {
        curSign = " " + currency.getItsName() + " ";
      }
    }
    Document<WI> doc = this.pdfFactory.lazyGetFctDocument()
      .createDoc(accSet.getPageSize(), accSet.getPageOrientation());
    doc.setFontSize(accSet.getFontSize());
    doc.getPages().get(0).setMarginBottom(accSet.getMarginBottom());
    doc.getPages().get(0).setMarginTop(accSet.getMarginTop());
    doc.getPages().get(0).setMarginLeft(accSet.getMarginLeft());
    doc.getPages().get(0).setMarginRight(accSet.getMarginRight());
    PdfDocument<WI> docPdf = this.pdfFactory.createPdfDoc(doc);
    IDocumentMaker<WI> docMaker = this.pdfFactory.lazyGetDocumentMaker();
    docPdf.getPdfInfo().setAuthor("Beigesoft (TM) Accounting, "
      + accSet.getOrganization());
    IPdfMaker<WI> pdfMaker = this.pdfFactory.lazyGetPdfMaker();
    if (accSet.getTtfBoldFileName() != null) {
      pdfMaker.addFontTtf(docPdf, accSet.getTtfBoldFileName());
    }
    pdfMaker.addFontTtf(docPdf, accSet.getTtfFileName());
    double widthNdot = this.pdfFactory.lazyGetUomHelper()
      .fromPoints(2.0, 300.0, doc.getUnitOfMeasure()); //printer resolution
    doc.setBorder(widthNdot);
    doc.setContentPadding(0.0);
    doc.setContentPaddingBottom(mmToDocUom(1.0, doc.getUnitOfMeasure()));
    DocTable<WI> tblOwner = docMaker.addDocTableNoBorder(doc, 1, 1);
    I18nAccounting i18nAccounting =
      (I18nAccounting) pReqVars.get("i18nAccounting");
    if (i18nAccounting != null) {
      tblOwner.getItsCells().get(0)
        .setItsContent(i18nAccounting.getOrganizationName());
    } else {
      tblOwner.getItsCells().get(0).setItsContent(accSet.getOrganization());
    }
    int n = 0;
    if (accSet.getTaxIdentificationNumber() != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("taxIdentificationNumber", lang) + ": "
          + accSet.getTaxIdentificationNumber());
    }
    if (accSet.getRegZip() != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regZip", lang) + ": " + accSet.getRegZip());
    }
    String addr = null;
    if (i18nAccounting != null) {
      addr = i18nAccounting.getRegAddress1();
    } else {
      addr = accSet.getRegAddress1();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regAddress1", lang) + ": " + addr);
    }
    if (i18nAccounting != null) {
      addr = i18nAccounting.getRegAddress2();
    } else {
      addr = accSet.getRegAddress2();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regAddress2", lang) + ": " + addr);
    }
    if (i18nAccounting != null) {
      addr = i18nAccounting.getRegCity();
    } else {
      addr = accSet.getRegCity();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regCity", lang) + ": " + addr);
    }
    if (i18nAccounting != null) {
      addr = i18nAccounting.getRegState();
    } else {
      addr = accSet.getRegState();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regState", lang) + ": " + addr);
    }
    if (i18nAccounting != null) {
      addr = i18nAccounting.getRegCountry();
    } else {
      addr = accSet.getRegCountry();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblOwner);
      tblOwner.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regCountry", lang) + ": " + addr);
    }
    tblOwner.getItsCells().get(0).setFontNumber(1);
    docMaker.makeDocTableWrapping(tblOwner);
    tblOwner.setAlignHorizontal(EAlignHorizontal.RIGHT);
    DocTable<WI> tblTitle = docMaker.addDocTableNoBorder(doc, 1, 1);
    String invNum;
    if (inv.getIdBirth() != null) {
      invNum = inv.getIdDatabaseBirth().toString() + "-"
        + inv.getIdBirth();
    } else {
      invNum = inv.getIdDatabaseBirth().toString() + "-"
        + inv.getItsId();
    }
    String title = this.srvI18n.getMsg("Invoice", lang) + " #" + invNum + ", "
      + this.srvI18n.getMsg("date", lang) + ": "
        + dateFormat.format(inv.getItsDate());
    tblTitle.getItsCells().get(0).setItsContent(title);
    tblTitle.getItsCells().get(0).setFontNumber(1);
    tblTitle.setAlignHorizontal(EAlignHorizontal.CENTER);
    doc.setContainerMarginBottom(mmToDocUom(1.0, doc.getUnitOfMeasure()));
    docMaker.makeDocTableWrapping(tblTitle);
    DocTable<WI> tblCustomer = docMaker.addDocTableNoBorder(doc, 1, 1);
    I18nBuyer i18nBuyer = null;
    if (!lang.equals(langDef)) {
      i18nBuyer = getSrvOrm().retrieveEntityById(pReqVars,
        I18nBuyer.class, inv.getCustomer());
    }
    if (i18nBuyer != null) {
      tblCustomer.getItsCells().get(0)
        .setItsContent(i18nBuyer.getItsName());
    } else {
      tblCustomer.getItsCells().get(0)
        .setItsContent(inv.getCustomer().getItsName());
    }
    n = 0;
    if (inv.getCustomer().getTaxIdentificationNumber() != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("taxIdentificationNumber", lang) + ": "
          + inv.getCustomer().getTaxIdentificationNumber());
    }
    if (inv.getCustomer().getRegZip() != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regZip", lang) + ": " + inv.getCustomer().getRegZip());
    }
    if (i18nBuyer != null) {
      addr = i18nBuyer.getRegAddress1();
    } else {
      addr = inv.getCustomer().getRegAddress1();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regAddress1", lang) + ": " + addr);
    }
    if (i18nBuyer != null) {
      addr = i18nBuyer.getRegAddress2();
    } else {
      addr = inv.getCustomer().getRegAddress2();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regAddress2", lang) + ": " + addr);
    }
    if (i18nBuyer != null) {
      addr = i18nBuyer.getRegCity();
    } else {
      addr = inv.getCustomer().getRegCity();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regCity", lang) + ": " + addr);
    }
    if (i18nBuyer != null) {
      addr = i18nBuyer.getRegState();
    } else {
      addr = inv.getCustomer().getRegState();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regState", lang) + ": " + addr);
    }
    if (i18nBuyer != null) {
      addr = i18nBuyer.getRegCountry();
    } else {
      addr = inv.getCustomer().getRegCountry();
    }
    if (addr != null) {
      docMaker.addRowToDocTable(tblCustomer);
      tblCustomer.getItsCells().get(++n).setItsContent(this.srvI18n
        .getMsg("regCountry", lang) + ": " + addr);
    }
    tblCustomer.getItsCells().get(0).setFontNumber(1);
    BigDecimal price;
    BigDecimal subtotal;
    BigDecimal totalTaxes;
    BigDecimal total;
    if (inv.getItsLines() != null && inv.getItsLines().size() > 0) {
      doc.setContainerMarginBottom(mmToDocUom(2.0, doc.getUnitOfMeasure()));
      DocTable<WI> tblTiGoods = docMaker.addDocTableNoBorder(doc, 1, 1);
      tblTiGoods.getItsCells().get(0).setItsContent(this.srvI18n
        .getMsg(SalesInvoiceLine.class.getSimpleName() + "s", lang));
      tblTiGoods.getItsCells().get(0).setFontNumber(1);
      tblTiGoods.setAlignHorizontal(EAlignHorizontal.CENTER);
      docMaker.makeDocTableWrapping(tblTiGoods);
      doc.setContentPadding(mmToDocUom(1.0, doc.getUnitOfMeasure()));
      doc.setContentPaddingBottom(mmToDocUom(1.5, doc.getUnitOfMeasure()));
      int rowc;
      if (isInvoiceBasis) {
        rowc = 6;
      } else if (inv.getPriceIncTax()) {
        rowc = 7;
      } else {
        rowc = 8;
      }
      DocTable<WI> tblGoods = docMaker
        .addDocTable(doc, rowc, inv.getItsLines().size() + 1);
      tblGoods.setIsRepeatHead(true);
      tblGoods.getItsRows().get(0).setIsHead(true);
      tblGoods.getItsCells().get(0).setItsContent(this.srvI18n
        .getMsg("invItem", lang).replace(" ", "\n"));
      tblGoods.getItsColumns().get(0).setIsWidthFixed(true);
      tblGoods.getItsColumns().get(0).setWidthInPercentage(60.0);
      tblGoods.getItsCells().get(1).setItsContent(this.srvI18n
        .getMsg("unitOfMeasure", lang).replace(" ", "\n"));
      tblGoods.getItsColumns().get(1).setWraping(EWraping.WRAP_CONTENT);
      tblGoods.getItsCells().get(2).setItsContent(this.srvI18n
        .getMsg(priceName, lang).replace(" ", "\n"));
      tblGoods.getItsColumns().get(2).setWraping(EWraping.WRAP_CONTENT);
      tblGoods.getItsCells().get(3).setItsContent(this.srvI18n
        .getMsg("itsQuantity", lang).replace(" ", "\n"));
      tblGoods.getItsColumns().get(3).setWraping(EWraping.WRAP_CONTENT);
      int pos = 3;
      if (!inv.getPriceIncTax()) {
        pos++;
        tblGoods.getItsCells().get(pos).setItsContent(this.srvI18n
        .getMsg("subtotal", lang).replace(" ", "\n"));
        tblGoods.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
      } else if (isInvoiceBasis && inv.getPriceIncTax()) {
        pos++;
        tblGoods.getItsCells().get(pos).setItsContent(this.srvI18n
        .getMsg("itsTotal", lang).replace(" ", "\n"));
        tblGoods.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
      }
      pos++;
      tblGoods.getItsCells().get(pos)
        .setItsContent(this.srvI18n.getMsg("taxesDescription", lang));
      if (!isInvoiceBasis) {
        pos++;
        tblGoods.getItsCells().get(pos).setItsContent(this.srvI18n
          .getMsg("totalTaxes", lang).replace(" ", "\n"));
        tblGoods.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
        pos++;
        tblGoods.getItsCells().get(pos).setItsContent(this.srvI18n
          .getMsg("itsTotal", lang).replace(" ", "\n"));
        tblGoods.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
      }
      for (int i = 0; i < rowc; i++) {
        tblGoods.getItsCells().get(i).setFontNumber(1);
        tblGoods.getItsCells().get(i)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
      }
      int j = 1;
      for (SalesInvoiceLine ln : inv.getItsLines()) {
        if (inv.getForeignCurrency() != null) {
          price = ln.getForeignPrice();
          subtotal = ln.getForeignSubtotal();
          totalTaxes = ln.getForeignTotalTaxes();
          total = ln.getForeignTotal();
        } else {
          price = ln.getItsPrice();
          subtotal = ln.getSubtotal();
          totalTaxes = ln.getTotalTaxes();
          total = ln.getItsTotal();
        }
        int i = 0;
        int k = j * rowc + i++;
        tblGoods.getItsCells().get(k)
          .setItsContent(ln.getInvItem().getItsName());
        k = j * rowc + i++;
        tblGoods.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
        tblGoods.getItsCells().get(k)
          .setItsContent(ln.getUnitOfMeasure().getItsName());
        k = j * rowc + i++;
        tblGoods.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.RIGHT);
        tblGoods.getItsCells().get(k)
          .setItsContent(prn(pReqVars, price));
        k = j * rowc + i++;
        tblGoods.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.RIGHT);
        tblGoods.getItsCells().get(k)
          .setItsContent(prn(pReqVars, ln.getItsQuantity()));
        if (!inv.getPriceIncTax()) {
          k = j * rowc + i++;
          tblGoods.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblGoods.getItsCells().get(k)
            .setItsContent(prn(pReqVars, subtotal));
        } else if (isInvoiceBasis && inv.getPriceIncTax()) {
          k = j * rowc + i++;
          tblGoods.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblGoods.getItsCells().get(k)
            .setItsContent(prn(pReqVars, total));
        }
        k = j * rowc + i++;
        tblGoods.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
        tblGoods.getItsCells().get(k)
          .setItsContent(ln.getTaxesDescription());
        if (!isInvoiceBasis) {
          k = j * rowc + i++;
          tblGoods.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblGoods.getItsCells().get(k)
            .setItsContent(prn(pReqVars, totalTaxes));
          k = j * rowc + i++;
          tblGoods.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblGoods.getItsCells().get(k)
            .setItsContent(prn(pReqVars, total));
        }
        j++;
      }
    }
    if (inv.getServices() != null && inv.getServices().size() > 0) {
      doc.setContainerMarginBottom(mmToDocUom(2.0, doc.getUnitOfMeasure()));
      DocTable<WI> tblTiServices = docMaker.addDocTableNoBorder(doc, 1, 1);
      tblTiServices.getItsCells().get(0).setItsContent(this.srvI18n
        .getMsg(SalesInvoiceServiceLine.class.getSimpleName() + "s", lang));
      tblTiServices.getItsCells().get(0).setFontNumber(1);
      tblTiServices.setAlignHorizontal(EAlignHorizontal.CENTER);
      docMaker.makeDocTableWrapping(tblTiServices);
      doc.setContentPadding(mmToDocUom(1.0, doc.getUnitOfMeasure()));
      doc.setContentPaddingBottom(mmToDocUom(1.5, doc.getUnitOfMeasure()));
      int rowc;
      double wd15;
      if (isInvoiceBasis) {
        rowc = 6;
        wd15 = 30.0d;
      } else if (inv.getPriceIncTax()) {
        rowc = 7;
        wd15 = 15.0d;
      } else {
        rowc = 8;
        wd15 = 15.0d;
      }
      DocTable<WI> tblServices = docMaker
        .addDocTable(doc, rowc, inv.getServices().size() + 1);
      tblServices.setIsRepeatHead(true);
      tblServices.getItsRows().get(0).setIsHead(true);
      tblServices.getItsCells().get(0)
        .setItsContent(this.srvI18n.getMsg("service", lang));
      tblServices.getItsColumns().get(0).setIsWidthFixed(true);
      tblServices.getItsColumns().get(0).setWidthInPercentage(35.0);
      tblServices.getItsCells().get(1).setItsContent(this.srvI18n
        .getMsg("unitOfMeasure", lang).replace(" ", "\n"));
      tblServices.getItsColumns().get(1).setWraping(EWraping.WRAP_CONTENT);
      tblServices.getItsCells().get(2)
        .setItsContent(this.srvI18n.getMsg(priceName, lang).replace(" ", "\n"));
      tblServices.getItsColumns().get(2).setIsWidthFixed(true);
      tblServices.getItsColumns().get(2).setWidthInPercentage(wd15);
      tblServices.getItsCells().get(3).setItsContent(this.srvI18n
        .getMsg("itsQuantity", lang).replace(" ", "\n"));
      tblServices.getItsColumns().get(3).setWraping(EWraping.WRAP_CONTENT);
      int pos = 3;
      if (!inv.getPriceIncTax()) {
        pos++;
        tblServices.getItsCells().get(pos).setItsContent(this.srvI18n
          .getMsg("subtotal", lang).replace(" ", "\n"));
        tblServices.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
      } else if (isInvoiceBasis && inv.getPriceIncTax()) {
        pos++;
        tblServices.getItsCells().get(pos).setItsContent(this.srvI18n
          .getMsg("itsTotal", lang).replace(" ", "\n"));
        tblServices.getItsColumns().get(pos).setWraping(EWraping.WRAP_CONTENT);
      }
      pos++;
      tblServices.getItsCells().get(pos)
        .setItsContent(this.srvI18n.getMsg("taxesDescription", lang));
      if (!isInvoiceBasis) {
        tblServices.getItsColumns().get(pos).setIsWidthFixed(true);
        tblServices.getItsColumns().get(pos).setWidthInPercentage(20.0);
        pos++;
        tblServices.getItsCells().get(pos)
          .setItsContent(this.srvI18n.getMsg("totalTaxes", lang));
        tblServices.getItsColumns().get(pos).setIsWidthFixed(true);
        tblServices.getItsColumns().get(pos).setWidthInPercentage(wd15);
        pos++;
        tblServices.getItsCells().get(pos)
          .setItsContent(this.srvI18n.getMsg("itsTotal", lang));
        tblServices.getItsColumns().get(pos).setIsWidthFixed(true);
        tblServices.getItsColumns().get(pos).setWidthInPercentage(wd15);
      }
      for (int i = 0; i < rowc; i++) {
        tblServices.getItsCells().get(i).setFontNumber(1);
        tblServices.getItsCells().get(i)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
      }
      int j = 1;
      for (SalesInvoiceServiceLine ln : inv.getServices()) {
        if (inv.getForeignCurrency() != null) {
          price = ln.getForeignPrice();
          subtotal = ln.getForeignSubtotal();
          totalTaxes = ln.getForeignTotalTaxes();
          total = ln.getForeignTotal();
        } else {
          price = ln.getItsPrice();
          subtotal = ln.getSubtotal();
          totalTaxes = ln.getTotalTaxes();
          total = ln.getItsTotal();
        }
        int i = 0;
        int k = j * rowc + i++;
        tblServices.getItsCells().get(k)
          .setItsContent(ln.getService().getItsName());
        k = j * rowc + i++;
        tblServices.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
        tblServices.getItsCells().get(k)
          .setItsContent(ln.getUnitOfMeasure().getItsName());
        k = j * rowc + i++;
        tblServices.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.RIGHT);
        tblServices.getItsCells().get(k)
          .setItsContent(prn(pReqVars, price));
        k = j * rowc + i++;
        tblServices.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.RIGHT);
        tblServices.getItsCells().get(k)
          .setItsContent(prn(pReqVars, ln.getItsQuantity()));
        if (!inv.getPriceIncTax()) {
          k = j * rowc + i++;
          tblServices.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblServices.getItsCells().get(k)
            .setItsContent(prn(pReqVars, subtotal));
        } else if (isInvoiceBasis && inv.getPriceIncTax()) {
          k = j * rowc + i++;
          tblServices.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblServices.getItsCells().get(k)
            .setItsContent(prn(pReqVars, total));
        }
        k = j * rowc + i++;
        tblServices.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
        tblServices.getItsCells().get(k)
          .setItsContent(ln.getTaxesDescription());
        if (!isInvoiceBasis) {
          k = j * rowc + i++;
          tblServices.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblServices.getItsCells().get(k)
            .setItsContent(prn(pReqVars, totalTaxes));
          k = j * rowc + i++;
          tblServices.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblServices.getItsCells().get(k)
            .setItsContent(prn(pReqVars, total));
        }
        j++;
      }
    }
    if (inv.getTaxesLines() != null && inv.getTaxesLines().size() > 0) {
      doc.setContainerMarginBottom(mmToDocUom(2.0, doc.getUnitOfMeasure()));
      DocTable<WI> tblTiTaxes = docMaker.addDocTableNoBorder(doc, 1, 1);
      tblTiTaxes.setIsRepeatHead(true);
      tblTiTaxes.getItsRows().get(0).setIsHead(true);
      tblTiTaxes.getItsCells().get(0).setItsContent(this.srvI18n
        .getMsg(SalesInvoiceTaxLine.class.getSimpleName() + "s", lang));
      tblTiTaxes.getItsCells().get(0).setFontNumber(1);
      tblTiTaxes.setAlignHorizontal(EAlignHorizontal.CENTER);
      docMaker.makeDocTableWrapping(tblTiTaxes);
      doc.setContentPadding(mmToDocUom(1.0, doc.getUnitOfMeasure()));
      doc.setContentPaddingBottom(mmToDocUom(1.5, doc.getUnitOfMeasure()));
      int rowc;
      double rowtw;
      if (isInvoiceBasis) {
        rowc = 3;
        rowtw = 40.0d;
      } else {
        rowc = 2;
        rowtw = 70.0d;
      }
      DocTable<WI> tblTaxes = docMaker
        .addDocTable(doc, rowc, inv.getTaxesLines().size() + 1);
      tblTaxes.getItsCells().get(0)
        .setItsContent(this.srvI18n.getMsg("tax", lang));
      tblTaxes.getItsColumns().get(0).setIsWidthFixed(true);
      tblTaxes.getItsColumns().get(0).setWidthInPercentage(rowtw);
      if (isInvoiceBasis) {
        tblTaxes.getItsCells().get(1)
          .setItsContent(this.srvI18n.getMsg("taxable", lang));
      }
      tblTaxes.getItsCells().get(rowc - 1)
        .setItsContent(this.srvI18n.getMsg("itsTotal", lang));
      for (int i = 0; i < rowc; i++) {
        tblTaxes.getItsCells().get(i).setFontNumber(1);
        tblTaxes.getItsCells().get(i)
          .setAlignHorizontal(EAlignHorizontal.CENTER);
      }
      BigDecimal taxable;
      int j = 1;
      for (SalesInvoiceTaxLine ln : inv.getTaxesLines()) {
        if (inv.getForeignCurrency() != null) {
          taxable = ln.getTaxableInvBasFc();
          total = ln.getForeignTotalTaxes();
        } else {
          taxable = ln.getTaxableInvBas();
          total = ln.getItsTotal();
        }
        int i = 0;
        tblTaxes.getItsCells().get(j * rowc + i++)
          .setItsContent(ln.getTax().getItsName());
        int k = j * rowc + i++;
        if (isInvoiceBasis) {
          tblTaxes.getItsCells().get(k)
            .setAlignHorizontal(EAlignHorizontal.RIGHT);
          tblTaxes.getItsCells().get(k)
            .setItsContent(prn(pReqVars, taxable));
          k = j * rowc + i++;
        }
        tblTaxes.getItsCells().get(k)
          .setAlignHorizontal(EAlignHorizontal.RIGHT);
        tblTaxes.getItsCells().get(k)
          .setItsContent(prn(pReqVars, total));
        j++;
      }
    }
    doc.setAlignHoriCont(EAlignHorizontal.RIGHT);
    DocTable<WI> tblRez = docMaker.addDocTableNoBorder(doc, 2, 3);
    tblRez.getItsCells().get(0).setFontNumber(1);
    tblRez.getItsCells().get(0).setItsContent(this.srvI18n.getMsg("subtotal",
      lang) + ": ");
    tblRez.getItsCells().get(1).setFontNumber(1);
    String cnt;
    if (inv.getForeignCurrency() != null) {
      subtotal = inv.getForeignSubtotal();
      totalTaxes = inv.getForeignTotalTaxes();
      total = inv.getForeignTotal();
    } else {
      subtotal = inv.getSubtotal();
      totalTaxes = inv.getTotalTaxes();
      total = inv.getItsTotal();
    }
    if (isPrnCurLf) {
      cnt = curSign + prn(pReqVars, subtotal);
    } else {
      cnt = prn(pReqVars, subtotal) + curSign;
    }
    tblRez.getItsCells().get(1).setItsContent(cnt);
    tblRez.getItsCells().get(2).setFontNumber(1);
    tblRez.getItsCells().get(2).setItsContent(this.srvI18n.getMsg("totalTaxes",
      lang) + ": ");
    tblRez.getItsCells().get(3).setFontNumber(1);
    if (isPrnCurLf) {
      cnt = curSign + prn(pReqVars, totalTaxes);
    } else {
      cnt = prn(pReqVars, totalTaxes) + curSign;
    }
    tblRez.getItsCells().get(3).setItsContent(cnt);
    tblRez.getItsCells().get(4).setFontNumber(1);
    tblRez.getItsCells().get(4).setItsContent(this.srvI18n.getMsg("itsTotal",
      lang) + ": ");
    tblRez.getItsCells().get(5).setFontNumber(1);
    if (isPrnCurLf) {
      cnt = curSign + prn(pReqVars, total);
    } else {
      cnt = prn(pReqVars, total) + curSign;
    }
    tblRez.getItsCells().get(5).setItsContent(cnt);
    tblRez.setAlignHorizontal(EAlignHorizontal.RIGHT);
    docMaker.makeDocTableWrapping(tblRez);
    docMaker.addPagination(doc);
    docMaker.deriveElements(doc);
    pdfMaker.prepareBeforeWrite(docPdf);
    try {
      this.pdfFactory.lazyGetPdfWriter().write(null, docPdf, pOus);
    } finally {
      pOus.close();
    }
  }
409520
@Override
  public final void makeOtherEntries(final Map<String, Object> pAddParam,
    final SalesReturn pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)
      && pEntity.getReversedId() != null) {
      //reverse none-reversed lines:
      SalesReturnLine srl = new SalesReturnLine();
      SalesReturn reversed = new SalesReturn();
      reversed.setItsId(pEntity.getReversedId());
      srl.setItsOwner(reversed);
      List<SalesReturnLine> reversedLines = getSrvOrm().
        retrieveListForField(pAddParam, srl, "itsOwner");
      String langDef = (String) pAddParam.get("langDef");
      for (SalesReturnLine reversedLine : reversedLines) {
        if (reversedLine.getReversedId() == null) {
          if (!reversedLine.getItsQuantity()
            .equals(reversedLine.getTheRest())) {
            throw new ExceptionWithCode(PurchaseInvoice.SOURSE_IS_IN_USE,
              "There is withdrawals from this source!");
          }
          SalesReturnLine reversingLine = new SalesReturnLine();
          reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
          reversingLine.setReversedId(reversedLine.getItsId());
          reversingLine.setWarehouseSite(reversedLine.getWarehouseSite());
          reversingLine.setInvItem(reversedLine.getInvItem());
          reversingLine.setUnitOfMeasure(reversedLine.getUnitOfMeasure());
          reversingLine.setItsCost(reversedLine.getItsCost());
          reversingLine.setItsQuantity(reversedLine.getItsQuantity()
            .negate());
          reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
          reversingLine.setSubtotal(reversedLine.getSubtotal().negate());
          reversingLine.setTotalTaxes(reversedLine.getTotalTaxes().negate());
          reversingLine.setTaxesDescription(reversedLine
            .getTaxesDescription());
          reversingLine.setIsNew(true);
          reversingLine.setItsOwner(pEntity);
          reversingLine.setDescription(getSrvI18n()
            .getMsg("reversed_n", langDef) + reversedLine.getIdDatabaseBirth()
              + "-" + reversedLine.getItsId()); //local
          getSrvOrm().insertEntity(pAddParam, reversingLine);
          reversingLine.setIsNew(false);
          getSrvWarehouseEntry().load(pAddParam, reversingLine,
            reversingLine.getWarehouseSite());
          String descr;
          if (reversedLine.getDescription() == null) {
            descr = "";
          } else {
            descr = reversedLine.getDescription();
          }
          reversedLine.setDescription(descr
            + " " + getSrvI18n().getMsg("reversing_n", langDef) + reversingLine
              .getIdDatabaseBirth() + "-" + reversingLine.getItsId());
          reversedLine.setReversedId(reversingLine.getItsId());
          reversedLine.setTheRest(BigDecimal.ZERO);
          getSrvOrm().updateEntity(pAddParam, reversedLine);
          SalesReturnGoodsTaxLine pigtlt =
            new SalesReturnGoodsTaxLine();
          pigtlt.setItsOwner(reversedLine);
          List<SalesReturnGoodsTaxLine> tls = getSrvOrm()
            .retrieveListForField(pAddParam, pigtlt, "itsOwner");
          for (SalesReturnGoodsTaxLine pigtl : tls) {
            getSrvOrm().deleteEntity(pAddParam, pigtl);
          }
        }
      }
      SalesReturnTaxLine srtl = new SalesReturnTaxLine();
      srtl.setItsOwner(reversed);
      List<SalesReturnTaxLine> reversedTaxLines = getSrvOrm().
        retrieveListForField(pAddParam, srtl, "itsOwner");
      for (SalesReturnTaxLine reversedLine : reversedTaxLines) {
        if (reversedLine.getReversedId() == null) {
          SalesReturnTaxLine reversingLine = new SalesReturnTaxLine();
          reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
          reversingLine.setReversedId(reversedLine.getItsId());
          reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
          reversingLine.setTax(reversedLine.getTax());
          reversingLine.setIsNew(true);
          reversingLine.setItsOwner(pEntity);
          getSrvOrm().insertEntity(pAddParam, reversingLine);
          reversingLine.setIsNew(false);
          reversedLine.setReversedId(reversingLine.getItsId());
          getSrvOrm().updateEntity(pAddParam, reversedLine);
        }
      }
    }
  }
912588
private <R extends J4pResponse<T>, T extends J4pRequest> List<R> extractResponses(JSONAware pJsonResponse,
                                                                                      List<T> pRequests,
                                                                                      J4pResponseExtractor pResponseExtractor) throws J4pException {
        JSONArray responseArray = (JSONArray) pJsonResponse;
        List<R> ret = new ArrayList<R>(responseArray.size());
        J4pRemoteException remoteExceptions[] = new J4pRemoteException[responseArray.size()];
        boolean exceptionFound = false;
        for (int i = 0; i < pRequests.size(); i++) {
            T request = pRequests.get(i);
            Object jsonResp = responseArray.get(i);
            if (!(jsonResp instanceof JSONObject)) {
                throw new J4pException("Response for request Nr. " + i + " is invalid (expected a map but got " + jsonResp.getClass() + ")");
            }
            try {
                ret.add(i,pResponseExtractor.<R,T>extract(request, (JSONObject) jsonResp));
            } catch (J4pRemoteException exp) {
                remoteExceptions[i] = exp;
                exceptionFound = true;
                ret.add(i,null);
            }
        }
        if (exceptionFound) {
            List partialResults = new ArrayList();
            // Merge partial results and exceptions in a single list
            for (int i = 0;i<pRequests.size();i++) {
                J4pRemoteException exp = remoteExceptions[i];
                if (exp != null) {
                    partialResults.add(exp);
                } else {
                    partialResults.add(ret.get(i));
                }
            }
            throw new J4pBulkRemoteException(partialResults);
        }
        return ret;
    }
813220
protected final InvTxMeth<SalesInvoice, SalesInvoiceTaxLine>
    lazyGetSalInvTxMeth(final Map<String, Object> pAddParam) throws Exception {
    InvTxMeth<SalesInvoice, SalesInvoiceTaxLine> salInvTxMe =
      this.salInvTxMeth;
    if (salInvTxMe == null) {
      salInvTxMe = new InvTxMeth<SalesInvoice, SalesInvoiceTaxLine>();
      salInvTxMe.setGoodLnCl(SalesInvoiceLine.class);
      salInvTxMe.setServiceLnCl(SalesInvoiceServiceLine.class);
      salInvTxMe.setInvTxLnCl(SalesInvoiceTaxLine.class);
      salInvTxMe.setIsTxByUser(true);
      salInvTxMe.setStWhereAdjGdLnInvBas(
        "where SALESINVOICELINE.TAXCATEGORY is not null and REVERSEDID "
          + "is null and ITSOWNER=");
      salInvTxMe.setStWhereAdjSrLnInvBas(
      "where SALESINVOICESERVICELINE.TAXCATEGORY is not null and REVERSEDID "
          + "is null and ITSOWNER=");
      salInvTxMe.setFlTotals("invTotals.sql");
      salInvTxMe.setFlTxItBas("invTxItBas.sql");
      salInvTxMe.setFlTxItBasAggr("invTxItBasAggr.sql");
      salInvTxMe.setFlTxInvBas("invTxInvBas.sql");
      salInvTxMe.setFlTxInvAdj("invTxInvAdj.sql");
      salInvTxMe.setFlTxInvBasAggr("invTxInvBasAggr.sql");
      salInvTxMe.setTblNmsTot(new String[] {"SALESINVOICELINE",
        "SALESINVOICESERVICELINE", "SALESINVOICETAXLINE",
           "SALESINVOICEGOODSTAXLINE", "SALESINVOICESERVICETAXLINE"});
      FactoryPersistableBase<SalesInvoiceTaxLine> fctItl =
        new FactoryPersistableBase<SalesInvoiceTaxLine>();
      fctItl.setObjectClass(SalesInvoiceTaxLine.class);
      fctItl.setDatabaseId(getSrvDatabase().getIdDatabase());
      salInvTxMe.setFctInvTxLn(fctItl);
      //assigning fully initialized object:
      this.salInvTxMeth = salInvTxMe;
    }
    return salInvTxMe;
  }
1170543
public final void makePrepaymentMatchingReversed(
    final Map<String, Object> pReqVars, final String pPrepayId,
      final BankStatementLine pBsl, final DateFormat pDateFormat,
        final String pLangDef) throws Exception {
    EBankEntryResultType resultRecordType = null;
    EBankEntryResultAction resultAction = null;
    String resultDescription = null;
    Long resultRecordId = null;
    if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) > 0) {
      PrepaymentFrom prep = getSrvOrm().retrieveEntityById(pReqVars,
        PrepaymentFrom.class, Long.parseLong(pPrepayId));
      if (!prep.getHasMadeAccEntries() || pBsl.getItsAmount().abs()
        .compareTo(prep.getItsTotal().abs()) != 0
          || prep.getSubaccCashType() != 2002 || !pBsl.getItsOwner()
            .getBankAccount().getItsId().equals(prep.getSubaccCashId())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "record_is_not_matching");
      }
      resultRecordType = EBankEntryResultType.PREPAYMENTFROM;
      if (EBankEntryStatus.VOIDED.equals(pBsl.getItsStatus())
        && prep.getReversedId() == null) {
        resultAction = EBankEntryResultAction.CREATE;
        PrepaymentFrom reversed = prep;
        prep = new PrepaymentFrom();
        prep.setAccCash(reversed.getAccCash());
        prep.setSubaccCash(reversed.getSubaccCash());
        prep.setSubaccCashId(reversed.getSubaccCashId());
        prep.setSubaccCashType(2002);
        prep.setCustomer(reversed.getCustomer());
        prep.setForeignTotal(reversed.getForeignTotal().negate());
        prep.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef)
          + " " + getSrvI18n().getMsg("reversed_n", pLangDef) + reversed
            .getIdDatabaseBirth() + "-" + reversed.getItsId());
        makeDocReversed(pReqVars, prep, reversed, pLangDef);
      } else {
        resultAction = EBankEntryResultAction.MATCH;
      }
      resultRecordId = prep.getItsId();
      resultDescription = makeBslResDescr(resultAction, pDateFormat, prep,
        prep.getItsDate(), pLangDef);
    } else {
      PrepaymentTo prep = getSrvOrm().retrieveEntityById(pReqVars,
        PrepaymentTo.class, Long.parseLong(pPrepayId));
      if (!prep.getHasMadeAccEntries() || pBsl.getItsAmount().abs()
        .compareTo(prep.getItsTotal().abs()) != 0
          || prep.getSubaccCashType() != 2002 || !pBsl.getItsOwner()
            .getBankAccount().getItsId().equals(prep.getSubaccCashId())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "record_is_not_matching");
      }
      resultRecordType = EBankEntryResultType.PREPAYMENTTO;
      if (EBankEntryStatus.VOIDED.equals(pBsl.getItsStatus())
        && prep.getReversedId() == null) {
        resultAction = EBankEntryResultAction.CREATE;
        PrepaymentTo reversed = prep;
        prep = new PrepaymentTo();
        prep.setAccCash(reversed.getAccCash());
        prep.setSubaccCash(reversed.getSubaccCash());
        prep.setSubaccCashId(reversed.getSubaccCashId());
        prep.setSubaccCashType(2002);
        prep.setVendor(reversed.getVendor());
        prep.setForeignTotal(reversed.getForeignTotal().negate());
        prep.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef)
          + " " + getSrvI18n().getMsg("reversed_n", pLangDef) + reversed
            .getIdDatabaseBirth() + "-" + reversed.getItsId());
        makeDocReversed(pReqVars, prep, reversed, pLangDef);
      } else {
        resultAction = EBankEntryResultAction.MATCH;
      }
      resultRecordId = prep.getItsId();
      resultDescription = makeBslResDescr(resultAction, pDateFormat, prep,
        prep.getItsDate(), pLangDef);
    }
    pBsl.setResultAction(resultAction);
    pBsl.setResultRecordType(resultRecordType);
    pBsl.setResultRecordId(resultRecordId);
    pBsl.setResultDescription(resultDescription);
    getSrvOrm().updateEntity(pReqVars, pBsl);
  }
1086807
public static void consumeTPVObject(TPVObject tpv, Processor processor, GpsdEndpoint endpoint, ExceptionHandler exceptionHandler) {
        // Simplify logging when https://github.com/taimos/GPSd4Java/pull/19 is merged into upstream.
        LOG.debug("About to consume TPV object {},{} from {}", tpv.getLatitude(), tpv.getLongitude(), endpoint);

        Validate.notNull(tpv);
        Validate.notNull(processor);
        Validate.notNull(endpoint);

        GpsCoordinates coordinates = gpsCoordinates(new Date(new Double(tpv.getTimestamp()).longValue()), tpv.getLatitude(), tpv.getLongitude());
        Exchange exchange = anExchange(endpoint.getCamelContext()).withPattern(OutOnly).
                withHeader(TPV_HEADER, tpv).withBody(coordinates).build();

        try {
            processor.process(exchange);
        } catch (Exception e) {
            exceptionHandler.handleException(e);
        }
    }
888954
public final void makeAccentryMatchingReversed(
    final Map<String, Object> pReqVars, final String pEntryId,
      final BankStatementLine pBsl, final DateFormat pDateFormat,
        final String pLangDef) throws Exception {
    EBankEntryResultType resultRecordType = EBankEntryResultType.ACC_ENTRY;
    EBankEntryResultAction resultAction = null;
    String resultDescription = null;
    Long resultRecordId = null;
    AccountingEntry accent = getSrvOrm().retrieveEntityById(pReqVars,
      AccountingEntry.class, Long.parseLong(pEntryId));
    if (accent == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "cant_found_accentry");
    }
    if (accent.getSourceType() == 1010) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "AlreadyDone");
    }
    if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) > 0 && pBsl
      .getItsAmount().compareTo(accent.getDebit()) != 0
        && accent.getSubaccDebitType() != 2002 && !pBsl.getItsOwner()
          .getBankAccount().getItsId().equals(accent.getSubaccDebitId())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "record_is_not_matching");
    } else if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) < 0 && pBsl
      .getItsAmount().abs().compareTo(accent.getCredit()) != 0
        && accent.getSubaccCreditType() != 2002 && !pBsl.getItsOwner()
          .getBankAccount().getItsId().equals(accent.getSubaccCreditId())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "record_is_not_matching");
    }
    if (EBankEntryStatus.VOIDED.equals(pBsl.getItsStatus())) {
      if (accent.getIdDatabaseBirth() != getSrvOrm().getIdDatabase()) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "can_not_change_foreign_src");
      }
      resultAction = EBankEntryResultAction.CREATE;
      AccountingEntry reversed = accent;
      accent = new AccountingEntry();
      accent.setSourceType(pBsl.constTypeCode());
      accent.setSourceId(pBsl.getItsId());
      accent.setSourceDatabaseBirth(pBsl.getIdDatabaseBirth());
      accent.setIdDatabaseBirth(reversed.getIdDatabaseBirth());
      accent.setReversedId(reversed.getItsId());
      accent.setReversedIdDatabaseBirth(reversed.getIdDatabaseBirth());
      accent.setItsDate(new Date(reversed.getItsDate().getTime() + 1));
      accent.setAccDebit(reversed.getAccDebit());
      accent.setSubaccDebit(reversed.getSubaccDebit());
      accent.setSubaccDebitId(reversed.getSubaccDebitId());
      accent.setSubaccDebitType(reversed.getSubaccDebitType());
      accent.setDebit(reversed.getDebit().negate());
      accent.setAccCredit(reversed.getAccCredit());
      accent.setSubaccCredit(reversed.getSubaccCredit());
      accent.setSubaccCreditId(reversed.getSubaccCreditId());
      accent.setSubaccCreditType(reversed.getSubaccCreditType());
      accent.setCredit(reversed.getCredit().negate());
      accent.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef)
        + " " + getSrvI18n().getMsg("reversed_n", pLangDef)
          + accent.getReversedIdDatabaseBirth() + "-" + accent.getReversedId());
      getSrvOrm().insertEntity(pReqVars, accent);
      accent.setIsNew(false);
      String oldDesr = "";
      if (reversed.getDescription() != null) {
        oldDesr = reversed.getDescription();
      }
      reversed.setDescription(oldDesr + " " + getSrvI18n()
        .getMsg("reversing_n", pLangDef) + accent.getIdDatabaseBirth() + "-"
          + accent.getItsId());
      reversed.setReversedId(accent.getItsId());
      reversed.setReversedIdDatabaseBirth(accent.getIdDatabaseBirth());
      getSrvOrm().updateEntity(pReqVars, reversed);
    } else {
      resultAction = EBankEntryResultAction.MATCH;
    }
    resultRecordId = accent.getItsId();
    resultDescription = makeBslResDescr(resultAction, pDateFormat, accent,
      accent.getItsDate(), pLangDef);
    pBsl.setResultAction(resultAction);
    pBsl.setResultRecordType(resultRecordType);
    pBsl.setResultRecordId(resultRecordId);
    pBsl.setResultDescription(resultDescription);
    getSrvOrm().updateEntity(pReqVars, pBsl);
  }
17154
@Override
  public final void makeFirstPrepareForSave(final Map<String, Object> pReqVars,
    final PurchaseInvoice pEntity,
      final IRequestData pRequestData) throws Exception {
    if (pEntity.getPrepaymentTo() != null) {
      pEntity.setPrepaymentTo(getSrvOrm()
        .retrieveEntity(pReqVars, pEntity.getPrepaymentTo()));
      if (pEntity.getReversedId() == null && pEntity.getPrepaymentTo()
        .getPurchaseInvoiceId() != null && !pEntity.getHasMadeAccEntries()) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_already_in_use");
      }
      if (pEntity.getReversedId() == null && !pEntity.getPrepaymentTo()
        .getVendor().getItsId().equals(pEntity.getVendor().getItsId())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_for_different_vendor");
      }
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() != null
      && pEntity.getPaymentTotal().compareTo(pEntity.getPrepaymentTo()
        .getItsTotal()) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() == null
      && pEntity.getPaymentTotal().compareTo(BigDecimal.ZERO) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() == null) {
      calculateTotalPayment(pReqVars, pEntity);
    }
    if (!pEntity.getIsNew()) {
      pReqVars.put("DebtorCreditortaxDestinationdeepLevel", 2);
      Set<String> ndFlDc = new HashSet<String>();
      ndFlDc.add("itsId");
      ndFlDc.add("isForeigner");
      ndFlDc.add("taxDestination");
      pReqVars.put("DebtorCreditorneededFields", ndFlDc);
    }
  }
646131
public final <T extends IInvoice, L extends IInvoiceLine<T>> void mkLnFinal(
    final L pLine, final BigDecimal pTotTxs, final BigDecimal pTotTxsFc,
      final Boolean pIsTxByUser) {
    if (pIsTxByUser) {
      if (pLine.getItsOwner().getForeignCurrency() == null) {
        if (pLine.getTotalTaxes().compareTo(pTotTxs) != 0) {
          if (pLine.getDescription() == null) {
            pLine.setDescription(pLine.getTotalTaxes().toString() + "!="
              + pTotTxs + "!");
          } else {
            pLine.setDescription(pLine.getDescription() + " " + pLine
              .getTotalTaxes().toString() + "!=" + pTotTxs + "!");
          }
        }
      } else {
        pLine.setTotalTaxes(pTotTxs);
        if (pLine.getForeignTotalTaxes().compareTo(pTotTxsFc) != 0) {
          if (pLine.getDescription() == null) {
            pLine.setDescription(pLine.getForeignTotalTaxes().toString()
              + "!=" + pTotTxsFc + "!");
          } else {
            pLine.setDescription(pLine.getDescription() + " " + pLine
              .getForeignTotalTaxes().toString() + "!=" + pTotTxsFc + "!");
          }
        }
      }
    } else {
      pLine.setTotalTaxes(pTotTxs);
      pLine.setForeignTotalTaxes(pTotTxsFc);
    }
  }
869775
public final void createAccentry(final Map<String, Object> pReqVars,
    final BankStatementLine pBsl, final DateFormat pDateFormat,
      final String pLangDef, final IRequestData pRequestData) throws Exception {
    Account accCash;
    Account corAcc;
    String subcorAcc = null;
    Long subcorAccId = null;
    Integer subcorAccType = null;
    Date itsDate;
    try {
      String accCashStr = pRequestData.getParameter("accCash");
      accCash = new Account();
      accCash.setItsId(accCashStr);
      accCash = getSrvOrm().retrieveEntity(pReqVars, accCash);
      if (accCash == null) {
        throw new Exception("cant_find_account");
      }
      String corAccStr = pRequestData.getParameter("corAcc");
      corAcc = new Account();
      corAcc.setItsId(corAccStr);
      corAcc = getSrvOrm().retrieveEntity(pReqVars, corAcc);
      if (corAcc == null) {
        throw new Exception("cant_find_account");
      }
      if (corAcc.getSubaccType() != null) {
        subcorAcc = pRequestData.getParameter("subcorAcc");
        String subcorAccTypeStr = pRequestData.getParameter("subcorAccType");
        subcorAccType = Integer.parseInt(subcorAccTypeStr);
        String subcorAccIdStr = pRequestData.getParameter("subcorAccId");
        subcorAccId = Long.parseLong(subcorAccIdStr);
      }
      String itsDateStr = pRequestData.getParameter("itsDate");
      itsDate = this.dateTimeNoTzFormatIso8601.parse(itsDateStr);
    } catch (Exception e) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "wrong_paramaters", e);
    }
    EBankEntryResultType resultRecordType = EBankEntryResultType.ACC_ENTRY;
    EBankEntryResultAction resultAction = EBankEntryResultAction.CREATE;
    String resultDescription = null;
    Long resultRecordId = null;
    AccountingEntry accent = new AccountingEntry();
    if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) > 0) {
      accent.setAccDebit(accCash);
      accent.setSubaccDebit(pBsl.getItsOwner().getBankAccount().getItsName());
      accent.setSubaccDebitId(pBsl.getItsOwner().getBankAccount().getItsId());
      accent.setSubaccDebitType(2002);
      accent.setAccCredit(corAcc);
      accent.setSubaccCredit(subcorAcc);
      accent.setSubaccCreditId(subcorAccId);
      accent.setSubaccCreditType(subcorAccType);
    } else {
      accent.setAccDebit(corAcc);
      accent.setSubaccDebit(subcorAcc);
      accent.setSubaccDebitId(subcorAccId);
      accent.setSubaccDebitType(subcorAccType);
      accent.setAccCredit(accCash);
      accent.setSubaccCredit(pBsl.getItsOwner().getBankAccount().getItsName());
      accent.setSubaccCreditId(pBsl.getItsOwner().getBankAccount().getItsId());
      accent.setSubaccCreditType(2002);
    }
    accent.setSourceType(pBsl.constTypeCode());
    accent.setSourceId(pBsl.getItsId());
    accent.setSourceDatabaseBirth(pBsl.getIdDatabaseBirth());
    accent.setIdDatabaseBirth(pBsl.getIdDatabaseBirth());
    accent.setItsDate(itsDate);
    accent.setDebit(pBsl.getItsAmount().abs());
    accent.setCredit(accent.getDebit());
    accent.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef));
    getSrvOrm().insertEntity(pReqVars, accent);
    accent.setIsNew(false);
    resultRecordId = accent.getItsId();
    resultDescription = makeBslResDescr(resultAction, pDateFormat, accent,
      accent.getItsDate(), pLangDef);
    pBsl.setResultAction(resultAction);
    pBsl.setResultRecordType(resultRecordType);
    pBsl.setResultRecordId(resultRecordId);
    pBsl.setResultDescription(resultDescription);
    getSrvOrm().updateEntity(pReqVars, pBsl);
  }
329486
public void addVarRefExpr(final INodeReadTrx mTransaction, final String mVarName) {

        final VariableAxis axis = (VariableAxis)mVarRefMap.get(mVarName);
        if (axis != null) {
            getExpression().add(new VarRefExpr(mTransaction, axis));
        } else {
            throw new IllegalStateException("Variable " + mVarName + " unkown.");
        }

    }
332739
public final void adjInvLnsUpdTots(final Map<String, Object> pReqVars,
    final T pInv, final AccSettings pAs,
      final TaxDestination pTxRules) throws Exception {
    List<SalesInvoiceServiceLine> txdLns = this.utlInvBase
      .retrTxdLnsAdjInv(pReqVars, pInv, pAs, pTxRules, this.invTxMeth);
    this.utlInvBase.adjustInvoiceLns(pReqVars, pInv, txdLns, pAs,
      this.invTxMeth);
    this.utlInvBase.updInvTots(pReqVars, pInv, pAs, this.invTxMeth);
  }
1245103
public final FilterInteger revialFilterPrice(final TradingCatalog pTcat,
    final Map<String, Object> pRqVs,
      final IRequestData pRqDt) throws Exception {
    if (pTcat.getCatalog().getUseFilterSpecifics()
      || pTcat.getCatalog().getUseFilterSubcatalog()
        || pTcat.getCatalog().getUseAvailableFilter()
          || pTcat.getCatalog().getUsePickupPlaceFilter()) {
      FilterInteger res = new FilterInteger();
      String operStr = pRqDt.getParameter("fltPriOp");
      String val1Str = pRqDt.getParameter("fltPriVal1");
      String dgsep = (String) pRqVs.get("decGrSepv");
      if (operStr != null && !"".equals(operStr)
        && val1Str != null && !"".equals(val1Str)) {
        res.setOperator(Enum.valueOf(EFilterOperator.class, operStr));
        if (dgsep != null) {
          val1Str = val1Str.replace(dgsep, "");
        }
        res.setValue1(Integer.valueOf(val1Str));
        String val2Str = pRqDt.getParameter("fltPriVal2");
        if (val2Str != null && !"".equals(val2Str)) {
          if (dgsep != null) {
            val2Str = val2Str.replace(dgsep, "");
          }
          res.setValue2(Integer.valueOf(val2Str));
        }
      }
      return res;
    } else {
      return null;
    }
  }
413360
public final void procSeSrv(final Map<String, Object> pRqVs,
    final IRequestData pRqDt, final TradingSettings pTs,
      final OnlineBuyer pBuyer, final Long pItemId) throws Exception {
    List<SeServiceSpecifics> itemSpecLst;
    List<SeServicePlace> itemPlaceLst;
    itemSpecLst = retrieveItemSpecificsList(pRqVs, pTs, pItemId,
      SeServiceSpecifics.class, SeService.class.getSimpleName());
    //extract main image if exist:
    int miIdx = -1;
    for (int i = 0; i < itemSpecLst.size(); i++) {
      if (itemSpecLst.get(i).getSpecifics().getItsType()
        .equals(ESpecificsItemType.IMAGE)) {
        pRqDt.setAttribute("itemImage", itemSpecLst.get(i));
        miIdx = i;
        break;
      }
    }
    if (miIdx != -1) {
      itemSpecLst.remove(miIdx);
    }
    AItemPrice<?, ?> itemPrice = getSrvCart().revealItemPrice(pRqVs, pTs,
        pBuyer, EShopItemType.SESERVICE, pItemId);
    itemPlaceLst = getSrvOrm().retrieveListWithConditions(pRqVs,
        SeServicePlace.class, " where ITEM=" + pItemId);
    pRqDt.setAttribute("itemSpecLst", itemSpecLst);
    pRqDt.setAttribute("itemPlaceLst", itemPlaceLst);
    pRqDt.setAttribute("itemPrice", itemPrice);
  }
737424
public final void updateOwner(final Map<String, Object> pAddParam,
    final WageTaxLine pEntity) throws Exception {
    String query =
    "select sum(ITSTOTAL) as ITSTOTAL from WAGETAXLINE"
      + " join TAX on TAX.ITSID = WAGETAXLINE.TAX"
        + " where TAX.ITSTYPE=3 and ITSOWNER="
          + pEntity.getItsOwner().getItsId();
    Double total = getSrvDatabase().evalDoubleResult(query, "ITSTOTAL");
    if (total == null) {
      total = 0d;
    }
    pEntity.getItsOwner().setTotalTaxesEmployee(BigDecimal.valueOf(total)
      .setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getPricePrecision(), getSrvAccSettings()
          .lazyGetAccSettings(pAddParam).getRoundingMode()));
    query =
    "select sum(ITSTOTAL) as ITSTOTAL from WAGETAXLINE"
      + " join TAX on TAX.ITSID = WAGETAXLINE.TAX"
        + " where TAX.ITSTYPE=4 and ITSOWNER="
          + pEntity.getItsOwner().getItsId();
    total = getSrvDatabase().evalDoubleResult(query, "ITSTOTAL");
    if (total == null) {
      total = 0d;
    }
    pEntity.getItsOwner().setTotalTaxesEmployer(BigDecimal.valueOf(total)
      .setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getPricePrecision(), getSrvAccSettings()
          .lazyGetAccSettings(pAddParam).getRoundingMode()));
    pEntity.getItsOwner().setNetWage(pEntity.getItsOwner()
      .getItsTotal().subtract(pEntity.getItsOwner()
        .getTotalTaxesEmployee()));
    getSrvOrm().updateEntity(pAddParam, pEntity.getItsOwner());
  }