public BillingProcessWS(BillingProcessDTO dto) {
    this.id = dto.getId();
    this.entityId = dto.getEntity() != null ? dto.getEntity().getId() : null;
    this.periodUnitId = dto.getPeriodUnit() != null ? dto.getPeriodUnit().getId() : null;
    this.periodValue = dto.getPeriodValue();
    this.billingDate = dto.getBillingDate();
    this.isReview = dto.getIsReview();
    this.retriesToDo = dto.getRetriesToDo();

    // invoice ID's
    if (!dto.getInvoices().isEmpty()) {
      invoiceIds = new ArrayList<Integer>(dto.getInvoices().size());
      for (InvoiceDTO invoice : dto.getInvoices()) invoiceIds.add(invoice.getId());
    }

    // order processes
    if (!dto.getOrderProcesses().isEmpty()) {
      orderProcesses = new ArrayList<OrderProcessWS>(dto.getOrderProcesses().size());
      for (OrderProcessDTO process : dto.getOrderProcesses())
        orderProcesses.add(new OrderProcessWS(process));
    }

    if (!dto.getProcessRuns().isEmpty()) {
      // billing process runs
      processRuns = new ArrayList<ProcessRunWS>(dto.getProcessRuns().size());
      for (ProcessRunDTO run : dto.getProcessRuns()) processRuns.add(new ProcessRunWS(run));
    }
  }
Exemplo n.º 2
0
  public static Date getEndOfProcessPeriod(BillingProcessDTO process) throws SessionInternalError {
    GregorianCalendar cal = new GregorianCalendar();

    cal.setTime(process.getBillingDate());
    cal.add(MapPeriodToCalendar.map(process.getPeriodUnit().getId()), process.getPeriodValue());

    return cal.getTime();
  }
Exemplo n.º 3
0
  public Integer create(BillingProcessDTO dto) {
    // create the record
    billingProcess =
        billingProcessDas.create(
            dto.getEntity(),
            dto.getBillingDate(),
            dto.getPeriodUnit().getId(),
            dto.getPeriodValue(),
            dto.getRetriesToDo());
    billingProcess.setIsReview(dto.getIsReview());
    processRun =
        processRunHome.create(
            billingProcess,
            dto.getBillingDate(),
            0,
            new ProcessRunStatusDAS().find(Constants.PROCESS_RUN_STATUS_RINNING));

    if (dto.getIsReview() == 1) {
      ConfigurationBL config = new ConfigurationBL(dto.getEntity().getId());
      config.getEntity().setReviewStatus(Constants.REVIEW_STATUS_GENERATED);
    }

    return billingProcess.getId();
  }
Exemplo n.º 4
0
  public BillingProcessDTOEx getDtoEx(Integer language) {
    BillingProcessDTOEx retValue = new BillingProcessDTOEx();

    retValue.setBillingDate(billingProcess.getBillingDate());
    retValue.setEntity(billingProcess.getEntity());
    retValue.setId(billingProcess.getId());
    retValue.setPeriodUnit(billingProcess.getPeriodUnit());
    retValue.setPeriodValue(billingProcess.getPeriodValue());
    retValue.setIsReview(billingProcess.getIsReview());

    // now add the runs and grand total
    BillingProcessRunDTOEx grandTotal = new BillingProcessRunDTOEx();
    int totalInvoices = 0;
    int runsCounter = 0;
    List<BillingProcessRunDTOEx> runs = new ArrayList<BillingProcessRunDTOEx>();
    // go throuhg every run
    for (Iterator it = billingProcess.getProcessRuns().iterator(); it.hasNext(); ) {
      ProcessRunDTO run = (ProcessRunDTO) it.next();
      BillingProcessRunBL runBL = new BillingProcessRunBL(run);
      BillingProcessRunDTOEx runDto = runBL.getDTO(language);
      runs.add(runDto);
      runsCounter++;

      // add statistic for InProgress run proccess in DTO
      if (run.getPaymentFinished() == null) {
        addRuntimeStatistic(run.getBillingProcess().getId(), language, runDto);
      }

      LOG.debug(
          "Run:" + run.getId() + " has " + run.getProcessRunTotals().size() + " total records");
      // go over the totals, since there's one per currency
      for (Iterator it2 = runDto.getTotals().iterator(); it2.hasNext(); ) {
        // the total to process
        BillingProcessRunTotalDTOEx totalDto = (BillingProcessRunTotalDTOEx) it2.next();

        BillingProcessRunTotalDTOEx sum = getTotal(totalDto.getCurrency(), grandTotal.getTotals());

        BigDecimal totalTmp = totalDto.getTotalInvoiced().add(sum.getTotalInvoiced());
        sum.setTotalInvoiced(totalTmp);

        totalTmp = totalDto.getTotalPaid().add(sum.getTotalPaid());
        sum.setTotalPaid(totalTmp);

        // can't add up the not paid, because many runs will try to
        // get the same invoices paid, so the not paid field gets
        // duplicated amounts.
        totalTmp = sum.getTotalInvoiced().subtract(sum.getTotalPaid());
        sum.setTotalNotPaid(totalTmp);

        // make sure this total has the currency name initialized
        if (sum.getCurrencyName() == null) {
          CurrencyBL currency = new CurrencyBL(sum.getCurrency().getId());
          sum.setCurrencyName(currency.getEntity().getDescription(language));
        }
        // add the payment method totals
        for (Enumeration en = totalDto.getPmTotals().keys(); en.hasMoreElements(); ) {
          String method = (String) en.nextElement();
          BigDecimal methodTotal = new BigDecimal(totalDto.getPmTotals().get(method).toString());

          if (sum.getPmTotals().containsKey(method)) {
            if (sum.getPmTotals().get(method) != null) {
              methodTotal =
                  methodTotal.add(
                      new BigDecimal(((Float) sum.getPmTotals().get(method)).toString()));
            }
          }
          sum.getPmTotals().put(method, new Float(methodTotal.floatValue()));
        }

        LOG.debug(
            "Added total to run dto. PMs in total:"
                + sum.getPmTotals().size()
                + " now grandTotal totals:"
                + grandTotal.getTotals().size());
      }
      totalInvoices += runDto.getInvoicesGenerated();
    }

    grandTotal.setInvoicesGenerated(new Integer(totalInvoices));

    retValue.setRetries(new Integer(runsCounter));
    retValue.setRuns(runs);
    retValue.setGrandTotal(grandTotal);
    retValue.setBillingDateEnd(getEndOfProcessPeriod(billingProcess));
    retValue.setOrdersProcessed(new Integer(billingProcess.getOrderProcesses().size()));

    return retValue;
  }