Beispiel #1
0
  private void addHeaderCategories(
      LinkedHashMap<String, XMLInvoiceHeaderCategoryDTO> headerCategories,
      Document doc,
      Element parent,
      boolean entreprise) {

    Element categories = doc.createElement("categories");
    parent.appendChild(categories);
    for (XMLInvoiceHeaderCategoryDTO xmlInvoiceHeaderCategoryDTO : headerCategories.values()) {

      Element category = doc.createElement("category");
      category.setAttribute("label", xmlInvoiceHeaderCategoryDTO.getDescription());
      category.setAttribute(
          "code",
          xmlInvoiceHeaderCategoryDTO != null && xmlInvoiceHeaderCategoryDTO.getCode() != null
              ? xmlInvoiceHeaderCategoryDTO.getCode()
              : "");
      categories.appendChild(category);

      Element amountWithoutTax = doc.createElement("amountWithoutTax");
      Text amountWithoutTaxTxt =
          doc.createTextNode(round(xmlInvoiceHeaderCategoryDTO.getAmountWithoutTax()));
      amountWithoutTax.appendChild(amountWithoutTaxTxt);
      category.appendChild(amountWithoutTax);

      Element amountWithTax = doc.createElement("amountWithTax");
      Text amountWithTaxTxt =
          doc.createTextNode(round(xmlInvoiceHeaderCategoryDTO.getAmountWithTax()));
      amountWithTax.appendChild(amountWithTaxTxt);
      category.appendChild(amountWithTax);
      if (entreprise) {
        for (RatedTransaction headerTransaction :
            xmlInvoiceHeaderCategoryDTO.getRatedtransactions().values()) {

          Element line = doc.createElement("line");
          line.setAttribute("code", headerTransaction.getUsageCode());
          line.setAttribute("taxPercent", round(headerTransaction.getTaxPercent()) + "");

          Element lebel = doc.createElement("label");
          Text lebelTxt =
              doc.createTextNode(
                  headerTransaction.getDescription() != null
                      ? headerTransaction.getDescription()
                      : "");
          lebel.appendChild(lebelTxt);
          line.appendChild(lebel);
          logger.info(
              "addHeaderCategories2 headerRatedTransaction amountHT="
                  + headerTransaction.getAmount1WithoutTax());
          Element lineAmountWithoutTax = doc.createElement("amountWithoutTax");
          Text lineAmountWithoutTaxTxt =
              doc.createTextNode(round(headerTransaction.getAmount1WithoutTax()) + "");
          lineAmountWithoutTax.appendChild(lineAmountWithoutTaxTxt);
          line.appendChild(lineAmountWithoutTax);

          Element lineAmountWithTax = doc.createElement("amountWithTax");
          Text lineAmountWithTaxTxt =
              doc.createTextNode(round(headerTransaction.getAmount1WithTax()) + "");
          lineAmountWithTax.appendChild(lineAmountWithTaxTxt);
          line.appendChild(lineAmountWithTax);

          category.appendChild(line);
        }
      }
    }
  }
Beispiel #2
0
  private void addHeaderCategories(Invoice invoice, Document doc, Element parent) {
    boolean entreprise = invoice.getProvider().isEntreprise();
    LinkedHashMap<String, XMLInvoiceHeaderCategoryDTO> headerCategories =
        new LinkedHashMap<String, XMLInvoiceHeaderCategoryDTO>();
    List<CategoryInvoiceAgregate> categoryInvoiceAgregates =
        new ArrayList<CategoryInvoiceAgregate>();
    for (InvoiceAgregate invoiceAgregate : invoice.getInvoiceAgregates()) {
      if (invoiceAgregate instanceof CategoryInvoiceAgregate) {
        CategoryInvoiceAgregate categoryInvoiceAgregate = (CategoryInvoiceAgregate) invoiceAgregate;
        categoryInvoiceAgregates.add(categoryInvoiceAgregate);
      }
    }
    Collections.sort(
        categoryInvoiceAgregates,
        new Comparator<CategoryInvoiceAgregate>() {
          public int compare(CategoryInvoiceAgregate c0, CategoryInvoiceAgregate c1) {
            if (c0.getInvoiceCategory() != null
                && c1.getInvoiceCategory() != null
                && c0.getInvoiceCategory().getSortIndex() != null
                && c1.getInvoiceCategory().getSortIndex() != null) {
              return c0.getInvoiceCategory()
                  .getSortIndex()
                  .compareTo(c1.getInvoiceCategory().getSortIndex());
            }
            return 0;
          }
        });

    for (CategoryInvoiceAgregate categoryInvoiceAgregate : categoryInvoiceAgregates) {
      InvoiceCategory invoiceCategory = categoryInvoiceAgregate.getInvoiceCategory();
      System.out.println("invoiceCategory:::" + invoiceCategory.getDescription());
      XMLInvoiceHeaderCategoryDTO headerCat = null;
      if (headerCategories.containsKey(invoiceCategory.getCode())) {
        headerCat = headerCategories.get(invoiceCategory.getCode());
        headerCat.addAmountWithoutTax(categoryInvoiceAgregate.getAmountWithoutTax());
        headerCat.addAmountWithTax(categoryInvoiceAgregate.getAmountWithTax());
      } else {
        headerCat = new XMLInvoiceHeaderCategoryDTO();
        headerCat.setDescription(invoiceCategory.getDescription());
        headerCat.setCode(invoiceCategory.getCode());
        headerCat.setAmountWithoutTax(categoryInvoiceAgregate.getAmountWithoutTax());
        headerCat.setAmountWithTax(categoryInvoiceAgregate.getAmountWithTax());
        headerCategories.put(invoiceCategory.getCode(), headerCat);
      }
      if (entreprise) {
        Set<SubCategoryInvoiceAgregate> subCategoryInvoiceAgregates =
            categoryInvoiceAgregate.getSubCategoryInvoiceAgregates();

        for (SubCategoryInvoiceAgregate subCatInvoiceAgregate : subCategoryInvoiceAgregates) {
          List<RatedTransaction> transactions = subCatInvoiceAgregate.getRatedtransactions();

          logger.info(
              "subCatInvoiceAgregate code="
                  + subCatInvoiceAgregate.getId()
                  + ",transactions="
                  + subCatInvoiceAgregate.getRatedtransactions().size());

          Collections.sort(
              transactions,
              new Comparator<RatedTransaction>() {
                public int compare(RatedTransaction c0, RatedTransaction c1) {
                  if (c0.getChargeApplication() != null && c1.getChargeApplication() != null) {
                    return c0.getChargeApplication()
                        .getId()
                        .compareTo(c1.getChargeApplication().getId());
                  }
                  return 0;
                }
              });
          Map<String, RatedTransaction> headerRatedTransactions = headerCat.getRatedtransactions();
          for (RatedTransaction ratedTrnsaction : transactions) {
            BigDecimal transactionAmountWithTax = ratedTrnsaction.getAmount1WithTax();
            if (transactionAmountWithTax == null
                || transactionAmountWithTax.equals(BigDecimal.ZERO)) {
              continue;
            }
            RatedTransaction headerRatedTransaction = null;
            logger.info(
                "headerRatedTransaction id="
                    + ratedTrnsaction.getId()
                    + ",code="
                    + ratedTrnsaction.getUsageCode()
                    + ",Amount1WithoutTax="
                    + ratedTrnsaction.getAmount1WithoutTax());

            if (headerRatedTransactions.containsKey(ratedTrnsaction.getUsageCode())) {
              headerRatedTransaction = headerRatedTransactions.get(ratedTrnsaction.getUsageCode());
              headerRatedTransaction.setAmount1WithoutTax(
                  headerRatedTransaction
                      .getAmount1WithoutTax()
                      .add(ratedTrnsaction.getAmount1WithoutTax()));
              headerRatedTransaction.setAmount1WithTax(
                  headerRatedTransaction.getAmount1WithTax().add(transactionAmountWithTax));

            } else {
              headerRatedTransaction = new RatedTransaction();
              headerRatedTransaction.setUsageCode(ratedTrnsaction.getUsageCode());
              headerRatedTransaction.setDescription(
                  ratedTrnsaction.getChargeApplication() != null
                      ? ratedTrnsaction.getChargeApplication().getDescription()
                      : "");
              headerRatedTransaction.setAmount1WithoutTax(ratedTrnsaction.getAmount1WithoutTax());
              headerRatedTransaction.setAmount1WithTax(ratedTrnsaction.getAmount1WithTax());
              headerRatedTransaction.setTaxPercent(ratedTrnsaction.getTaxPercent());
              headerRatedTransactions.put(ratedTrnsaction.getUsageCode(), headerRatedTransaction);
            }
            logger.info(
                "addHeaderCategories headerRatedTransaction amoutHT="
                    + headerRatedTransaction.getAmount1WithoutTax());
          }

          logger.info(
              "addHeaderCategories headerRatedTransactions.size=" + headerRatedTransactions.size());
          logger.info(
              "addHeaderCategories headerCat.getRatedtransactions().size="
                  + headerCat.getRatedtransactions().size());
        }
      }
    }
    addHeaderCategories(headerCategories, doc, parent, entreprise);
  }