Exemplo n.º 1
0
  public ListModelList<InvoiceCheck> getInvoices() throws Exception {
    if (user != null) {
      auditLogger.log(INVOICE_OVERVIEW, user);
      FiscalPeriod period = DateHelper.getPeriodTillDate(balanceDate);
      List<Cost> sentAndPaidInvoicesInPeriod = costDao.getInvoicesSentAndPaid(period);
      invoices = new ListModelList<>();

      int currentYear = DateHelper.getYear(new Date());

      for (Cost cost : sentAndPaidInvoicesInPeriod) {
        InvoiceCheck invoiceCheck = new InvoiceCheck();
        if (cost.getCostType().equals(INVOICE_SENT)) {
          invoiceCheck.setDateSent(cost.getDate());
          invoiceCheck.setInvoiceNumber(getInvoiceNumber(cost.getDescription()));
          invoiceCheck.setNetAmount(cost.getAmount());
          invoiceCheck.setVatAmount(cost.getVat());
          totalIncome = totalIncome.add(cost.getAmount());
          invoices.add(invoiceCheck);
        } else {
          if (!invoiceCheck.isPaymentFromPreviousYear()) {}
        }
      }
      for (Cost cost : sentAndPaidInvoicesInPeriod) {
        if (cost.getCostType().equals(INVOICE_PAID)) {

          Iterator<InvoiceCheck> sentInvoices = invoices.iterator();
          boolean hasMatchingInvoice = false;
          while (sentInvoices.hasNext()) {
            InvoiceCheck invoiceCheck = sentInvoices.next();
            if (cost.getDescription().contains(invoiceCheck.getInvoiceNumber())) {
              invoiceCheck.setDateReceived(cost.getDate());
              invoiceCheck.setDescriptionReceived(cost.getDescription());
              invoiceCheck.setGrossAmount(cost.getAmount());
              if (cost.getAmount()
                  .equals(invoiceCheck.getNetAmount().add(invoiceCheck.getVatAmount()))) {
                invoiceCheck.setInvoiceNumber(invoiceCheck.getInvoiceNumber() + " ok");
              }
              hasMatchingInvoice = true;
              break;
            } else {

            }
          }
          if (!hasMatchingInvoice) {
            paidInvoicesWithoutMatch = paidInvoicesWithoutMatch.add(cost.getAmount());
          }
        }
      }
      Iterator<InvoiceCheck> sentInvoices = invoices.iterator();
      while (sentInvoices.hasNext()) {
        InvoiceCheck invoiceCheck = sentInvoices.next();
        if (invoiceCheck.getDateReceived() == null) {
          unpaidInvoicesFromThisYear =
              unpaidInvoicesFromThisYear.add(
                  invoiceCheck.getNetAmount().add(invoiceCheck.getVatAmount()));
        }
      }
      BookValue bookValuePreviousYear =
          bookValueDao.getBookValue(BalanceType.INVOICES_TO_BE_PAID, currentYear - 1);
      if (bookValuePreviousYear != null) {
        unpaidInvoicesFromPreviousYear = bookValuePreviousYear.getSaldo();
      }
    } else {
      Executions.sendRedirect("login.zul");
    }
    return invoices;
  }