Example #1
0
  private void createOrderProcess(
      NewInvoiceDTO newInvoice, InvoiceDTO invoice, BillingProcessDTO process, Integer origin)
      throws SessionInternalError {
    LOG.debug("Generating order process records...");
    // update the orders involved, now that their old data is not needed
    // anymore
    for (int f = 0; f < newInvoice.getOrders().size(); f++) {

      OrderDTO order = (OrderDTO) newInvoice.getOrders().get(f);

      LOG.debug(" ... order " + order.getId());
      // this will help later
      List<PeriodOfTime> periodsList = newInvoice.getPeriods().get(f);
      Date startOfBillingPeriod = (Date) periodsList.get(0).getStart();
      Date endOfBillingPeriod = periodsList.get(periodsList.size() - 1).getEnd();
      Integer periods = (Integer) newInvoice.getPeriods().get(f).size();

      // We don't update orders if this is just a review
      if (newInvoice.getIsReview().intValue() == 0) {
        // update the to_process if applicable
        updateStatusFinished(order, startOfBillingPeriod, endOfBillingPeriod);

        // update this order process field
        updateNextBillableDay(order, endOfBillingPeriod);
      }

      // create the period and update the order-invoice relationship
      try {

        OrderProcessDAS das = new OrderProcessDAS();
        OrderProcessDTO orderProcess = new OrderProcessDTO();
        orderProcess.setPeriodStart(startOfBillingPeriod);
        orderProcess.setPeriodEnd(endOfBillingPeriod);
        orderProcess.setIsReview(newInvoice.getIsReview());
        orderProcess.setPurchaseOrder(order);
        InvoiceDAS invDas = new InvoiceDAS();
        orderProcess.setInvoice(invDas.find(invoice.getId()));
        BillingProcessDAS proDas = new BillingProcessDAS();
        orderProcess.setBillingProcess(process != null ? proDas.find(process.getId()) : null);
        orderProcess.setPeriodsIncluded(periods);
        orderProcess.setOrigin(origin);
        orderProcess = das.save(orderProcess);
        LOG.debug(
            "created order process id " + orderProcess.getId() + " for order " + order.getId());

      } catch (Exception e) {
        throw new SessionInternalError(e);
      }
    }
  }
Example #2
0
  public Integer findOrCreate(BillingProcessDTO dto) {
    billingProcess =
        billingProcessDas.isPresent(
            dto.getEntity().getId(), dto.getIsReview(), dto.getBillingDate());
    if (billingProcess == null) {
      create(dto);
    }

    return billingProcess.getId();
  }
Example #3
0
 public BillingProcessDTOEx getReviewDTO(Integer entityId, Integer languageId) {
   billingProcess = billingProcessDas.findReview(entityId);
   if (billingProcess == null) {
     System.out.println("Don't found the billingProcess");
     return null;
   } else {
     System.out.println("found the billingProcess");
   }
   return getDtoEx(languageId);
 }
Example #4
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);
  }
Example #5
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();
  }
Example #6
0
 public void set(Integer id) {
   billingProcess = billingProcessDas.find(id);
 }
Example #7
0
 public boolean isReviewPresent(Integer entityId) {
   return billingProcessDas.findReview(entityId) != null;
 }