コード例 #1
0
  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));
    }
  }
コード例 #2
0
  public static boolean validate(BillingProcessConfigurationWS ws) {
    boolean retValue = true;

    // validate nextRunDate - Unique if there is already a successful run for that date
    // (if a process failed, it is fine to run it again)
    // TODO Should I Util.truncateDate before using the ws.nextRunDate?
    BillingProcessDTO billingProcessDTO =
        new BillingProcessDAS().isPresent(ws.getEntityId(), 0, ws.getNextRunDate());
    if (billingProcessDTO != null) {
      for (ProcessRunDTO run : billingProcessDTO.getProcessRuns()) {
        // if status is not failed i.e. for the same date, if the process is either running or
        // finished
        if (!Constants.PROCESS_RUN_STATUS_FAILED.equals(run.getStatus().getId())) {
          LOG.error("Trying to set this configuration: " + ws + " but already has this: " + run);
          SessionInternalError exception =
              new SessionInternalError(
                  "There is already a billing process for the give date." + ws.getNextRunDate());
          String messages[] = new String[1];
          messages[0] =
              new String(
                  "BillingProcessConfigurationWS,nextRunDate,billing.configuration.error.unique.nextrundate,");
          exception.setErrorMessages(messages);
          throw exception;
        }
      }
    }

    ProcessRunDTO run = new ProcessRunDAS().getLatestSuccessful(ws.getEntityId());

    // The nextRunDate must be greater than the latest successful one
    if (run != null
        && run.getBillingProcess().getBillingDate() != null
        && !run.getBillingProcess().getBillingDate().before(ws.getNextRunDate())) {

      LOG.error(
          "Trying to set this configuration: "
              + ws
              + " but the it should be in the future "
              + run.getBillingProcess());
      SessionInternalError exception =
          new SessionInternalError(
              "The new next date needs to be in the future from the last successful run");
      String messages[] = new String[1];
      messages[0] =
          new String(
              "BillingProcessConfigurationWS,nextRunDate,"
                  + "billing.configuration.error.past.nextrundate,"
                  + run.getBillingProcess().getBillingDate());

      exception.setErrorMessages(messages);
      throw exception;
    }

    return retValue;
  }
コード例 #3
0
  public void purgeReview(Integer entityId, boolean isReview) {
    BillingProcessDTO review = billingProcessDas.findReview(entityId);
    if (review == null) {
      // no review, nothing to delete then
      return;
    }

    // if we are here, a review exists
    ConfigurationBL configBL = new ConfigurationBL(entityId);
    if (configBL.getEntity().getGenerateReport().intValue() == 1
        && !new Integer(configBL.getEntity().getReviewStatus())
            .equals(Constants.REVIEW_STATUS_APPROVED)
        && !isReview) {
      eLogger.warning(
          entityId,
          null,
          configBL.getEntity().getId(),
          EventLogger.MODULE_BILLING_PROCESS,
          EventLogger.BILLING_REVIEW_NOT_APPROVED,
          Constants.TABLE_BILLING_PROCESS_CONFIGURATION);
    }
    // delete the review
    LOG.debug("Removing review id = " + review.getId() + " from " + " entity " + entityId);
    // this is needed while the order process is JPA, but the billing process is Entity
    OrderProcessDAS processDas = new OrderProcessDAS();
    com.sapienter.jbilling.server.process.db.BillingProcessDTO processDto =
        new BillingProcessDAS().find(review.getId());
    for (OrderProcessDTO orderDto : processDto.getOrderProcesses()) {
      processDas.delete(orderDto);
    }
    processDto.getOrderProcesses().clear();
    // delete processRunUsers otherwise will be constraint violation
    for (ProcessRunDTO processRun : review.getProcessRuns()) {
      new ProcessRunUserDAS().removeProcessRunUsersForProcessRun(processRun.getId());
    }
    // otherwise this line would cascade de delete
    getHome().delete(review);
  }
コード例 #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;
  }