/**
  * Converts the instance of SuretaxResponse object into tax lines.
  *
  * @param suretaxResponse
  * @param order
  * @return
  */
 private List<InvoiceLineDTO> getTaxLines(SuretaxResponse suretaxResponse, OrderDTO order) {
   List<InvoiceLineDTO> taxLines = new ArrayList<InvoiceLineDTO>();
   if (suretaxResponse.successful.equals("Y")) {
     for (Group group : suretaxResponse.groupList) {
       for (TaxItem taxItem : group.taxList) {
         InvoiceLineDTO invoiceLineDTO = new InvoiceLineDTO();
         invoiceLineDTO.setAmount(new BigDecimal(taxItem.taxAmount));
         invoiceLineDTO.setDescription(taxItem.taxTypeCode + ":" + taxItem.taxTypeDesc);
         invoiceLineDTO.setInvoiceLineType(
             new InvoiceLineTypeDTO(ServerConstants.INVOICE_LINE_TYPE_TAX));
         invoiceLineDTO.setIsPercentage(null);
         invoiceLineDTO.setOrder(order);
         invoiceLineDTO.setPrice(new BigDecimal(taxItem.taxAmount));
         invoiceLineDTO.setQuantity(1);
         taxLines.add(invoiceLineDTO);
       }
     }
   }
   return taxLines;
 }
Esempio n. 2
0
  public InvoiceDTO getDTOEx(Integer languageId, boolean forDisplay) {

    if (!forDisplay) {
      return invoice;
    }

    InvoiceDTO invoiceDTO = new InvoiceDTO(invoice);
    // make sure that the lines are properly ordered
    List<InvoiceLineDTO> orderdLines = new ArrayList<InvoiceLineDTO>(invoiceDTO.getInvoiceLines());
    Collections.sort(orderdLines, new InvoiceLineComparator());
    invoiceDTO.setInvoiceLines(orderdLines);

    UserBL userBl = new UserBL(invoice.getBaseUser());
    Locale locale = userBl.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("entityNotifications", locale);

    // now add headres and footers if this invoices has subaccount
    // lines
    if (invoiceDTO.hasSubAccounts()) {
      addHeadersFooters(orderdLines, bundle);
    }
    // add a grand total final line
    InvoiceLineDTO total = new InvoiceLineDTO();
    total.setDescription(bundle.getString("invoice.line.total"));
    total.setAmount(invoice.getTotal());
    total.setIsPercentage(0);
    invoiceDTO.getInvoiceLines().add(total);

    // add some currency info for the human
    CurrencyBL currency = new CurrencyBL(invoice.getCurrency().getId());
    if (languageId != null) {
      invoiceDTO.setCurrencyName(currency.getEntity().getDescription(languageId));
    }
    invoiceDTO.setCurrencySymbol(currency.getEntity().getSymbol());

    return invoiceDTO;
  }
Esempio n. 3
0
  /**
   * Will add lines with headers and footers to make an invoice with subaccounts more readable. The
   * lines have to be already sorted.
   *
   * @param lines
   */
  private void addHeadersFooters(List<InvoiceLineDTO> lines, ResourceBundle bundle) {
    Integer nowProcessing = Integer.valueOf(-1);
    BigDecimal total = null;
    int totalLines = lines.size();
    int subaccountNumber = 0;

    LOG.debug("adding headers & footers." + totalLines);

    for (int idx = 0; idx < totalLines; idx++) {
      InvoiceLineDTO line = (InvoiceLineDTO) lines.get(idx);

      if (line.getTypeId() == Constants.INVOICE_LINE_TYPE_SUB_ACCOUNT
          && !line.getSourceUserId().equals(nowProcessing)) {
        // line break
        nowProcessing = line.getSourceUserId();
        subaccountNumber++;
        // put the total first
        if (total != null) { // it could be the first subaccount
          InvoiceLineDTO totalLine = new InvoiceLineDTO();
          totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
          totalLine.setAmount(total);
          lines.add(idx, totalLine);
          idx++;
          totalLines++;
        }
        total = BigDecimal.ZERO;

        // now the header anouncing a new subaccout
        InvoiceLineDTO headerLine = new InvoiceLineDTO();
        try {
          ContactBL contact = new ContactBL();
          contact.set(nowProcessing);
          StringBuffer text = new StringBuffer();
          text.append(subaccountNumber + " - ");
          text.append(bundle.getString("invoice.line.subAccount.header1"));
          text.append(
              " " + bundle.getString("invoice.line.subAccount.header2") + " " + nowProcessing);
          if (contact.getEntity().getFirstName() != null) {
            text.append(" " + contact.getEntity().getFirstName());
          }
          if (contact.getEntity().getLastName() != null) {
            text.append(" " + contact.getEntity().getLastName());
          }
          headerLine.setDescription(text.toString());
          lines.add(idx, headerLine);
          idx++;
          totalLines++;
        } catch (Exception e) {
          LOG.error("Exception", e);
          return;
        }
      }

      // update the total
      if (total != null) {
        // there had been at least one sub-account processed
        if (line.getTypeId() == Constants.INVOICE_LINE_TYPE_SUB_ACCOUNT) {
          total = total.add(line.getAmount());
        } else {
          // this is the last total to display, from now on the
          // lines are not of subaccounts
          InvoiceLineDTO totalLine = new InvoiceLineDTO();
          totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
          totalLine.setAmount(total);
          lines.add(idx, totalLine);
          total = null; // to avoid repeating
        }
      }
    }
    // if there are no lines after the last subaccount, we need
    // a total for it
    if (total != null) { // only if it wasn't added before
      InvoiceLineDTO totalLine = new InvoiceLineDTO();
      totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
      totalLine.setAmount(total);
      lines.add(totalLine);
    }

    LOG.debug("done " + lines.size());
  }