예제 #1
0
  public void storeAdDcCoop(AdDcCoopBean adcb) throws ApplicationException {
    boolean success = false;
    try {
      //			DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      // Get the AdDcCoop entry from the database
      AdDcCoopBean temp = getAdDcCoopByIdAndDivision(adcb.getCoopId(), adcb.getRegionMemberId());

      // If the AdDcCoop was not already in the database ...
      if (temp == null) {
        // Create the AdDcCoop entry in the database
        AdDcCoopManager.createDivisionCoop(
            adcb.getCoopId(),
            adcb.getRegionMemberId(),
            adcb.getInitialAmount(),
            adcb.getBilledAmount(),
            adcb.getEstimatedCases(),
            adcb.getActualCases(),
            adcb.getWorkFlowPhaseId(),
            adcb.getDivisionTaken(),
            adcb.getDivisionRejectReason(),
            adcb.getBillDate(),
            adcb.getBillSign(),
            adcb.getAccountRejectReason(),
            adcb.getAccountingExportWeek(),
            adcb.getAccountingExportPeriod(),
            adcb.getAccountingExportYear());
      } else {
        // Update the AdDcCoop entry
        AdDcCoopManager.updateDivisionCoop(
            adcb.getRegionMemberId(),
            adcb.getInitialAmount(),
            adcb.getBilledAmount(),
            adcb.getEstimatedCases(),
            adcb.getActualCases(),
            adcb.getWorkFlowPhaseId(),
            adcb.getDivisionTaken(),
            adcb.getDivisionRejectReason(),
            adcb.getBillDate(),
            adcb.getBillSign(),
            adcb.getAccountRejectReason(),
            adcb.getCoopId(),
            adcb.getAccountingExportWeek(),
            adcb.getAccountingExportPeriod(),
            adcb.getAccountingExportYear());
      }

      success = true;
    } finally {
      //			DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }
  }
예제 #2
0
  public void deleteDcCoopsByCoopIdAndRegionMemberId(AdDcCoopBean dcCoop)
      throws ApplicationException {
    if (LOG.isLoggable(Level.FINER)) {
      LOG.entering(
          AdDcCoopCommandImpl.class.getName(),
          "deleteDcCoopsByCoopIdAndRegionMemberId",
          new Object[] {new Integer(dcCoop.getCoopId()), new Integer(dcCoop.getRegionMemberId())});
    }
    boolean success = false;

    try {
      DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      cancelWorkflowForDcCoop(dcCoop);
      AdDcCoopManager.deleteDcCoopByCoopIdAndRegMbrId(
          dcCoop.getCoopId(), dcCoop.getRegionMemberId());

      success = true;
    } finally {
      DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }
    if (LOG.isLoggable(Level.FINER)) {
      LOG.exiting(AdDcCoopCommandImpl.class.getName(), "deleteDcCoopsByCoopIdAndRegionMemberId");
    }
  }
예제 #3
0
  /**
   * Returns the status of the items in the requested region member (division) for the specified
   * week. Possible statuses are:
   *
   * <p>None - there are no entries in the specified group Billed - All of the entries are complete.
   * Submitted - No entries are in DC open, and at least one is not in billed Open - At least one
   * entry is in the DC-open phase.
   *
   * @param adWeek
   * @param regionMemId. ID of the requested region member (division), -1 indicates statuses for ALL
   *     divisions should be returned.
   * @return HashMap where the key is the reg member ID and the value is the status string for that
   *     region.
   * @throws ApplicationException
   */
  public HashMap<Integer, String> getDivisionAdWeekStatusDescriptions(
      Calendar adWeek, int regionMemId) throws ApplicationException {
    ArrayList<AdDcCoopStatusBean> stateNames =
        AdDcCoopManager.getDistinctStatesByWeekAndRegMbrIds(adWeek);
    HashMap<Integer, HashSet<String>> statusesForRegMem = new HashMap<Integer, HashSet<String>>();
    for (AdDcCoopStatusBean statusBean : stateNames) {
      // If statuses for ALL region members have been requested, OR the current reg mem Id matches
      // the requested reg mem Id ...
      if ((regionMemId < 0) || (regionMemId == statusBean.getRegionMemberId())) {
        // If the HashSet containing the statuses for a region member has not yet been created,
        // create it ...
        if (!statusesForRegMem.containsKey(statusBean.getRegionMemberId())) {
          statusesForRegMem.put(statusBean.getRegionMemberId(), new HashSet<String>());
        }
        statusesForRegMem.get(statusBean.getRegionMemberId()).add(statusBean.getStatus());
      }
    }

    HashMap<Integer, String> resultsMap = new HashMap<Integer, String>();

    Iterator<Integer> keyIter = statusesForRegMem.keySet().iterator();

    // If the status for a specific region Member Id was requested ...
    if (regionMemId >= 0) {
      // Initialize the result for the specified region member to "None".
      resultsMap.put(regionMemId, "None");
    }

    while (keyIter.hasNext()) {
      Integer regMemIdVal = keyIter.next();
      HashSet<String> hs = statusesForRegMem.get(regMemIdVal);
      if (hs.contains("Accounting-exported")) {
        resultsMap.put(regMemIdVal, "Exported");
      } else if (hs.contains("DC-open")) {
        resultsMap.put(regMemIdVal, "Open");
      } else if (hs.contains("Accounting-open")) {
        resultsMap.put(regMemIdVal, "Accounting Open");
      } else if (hs.contains("DC-accept")) {
        resultsMap.put(regMemIdVal, "Submitted");
      } else if (hs.contains("Accounting-billed") || hs.contains("Accounting-invalid")) {
        resultsMap.put(regMemIdVal, "Accounting Closed");
      } else if (hs.contains("DC-reject") || hs.contains("DC-expire")) {
        resultsMap.put(regMemIdVal, "Rejected");
      } else {
        resultsMap.put(regMemIdVal, "None");
      }
    }

    return resultsMap;
  }
예제 #4
0
  /**
   * Returns the status of the items in the provided division in the specified week. Returned
   * results are:
   *
   * <p>None - there are no entries in the specified group Billed - All of the entries are complete.
   * Submitted - No entries are in DC open, and at least one is not in billed Open - At least one
   * entry is in the DC-open phase.
   *
   * @param adWeek
   * @param division
   * @return
   * @throws ApplicationException
   */
  public String getDivisionAdWeekStatusDescription(Calendar adWeek, int regionMemberId)
      throws ApplicationException {
    ArrayList<String> stateNames =
        AdDcCoopManager.getDistinctStatesByWeekAndRegMbrId(adWeek, regionMemberId);

    int highWaterMarker = 0;
    for (int i = 0; i < stateNames.size(); i++) {
      String name = stateNames.get(i);
      if (name.equalsIgnoreCase("DC-reject") || name.equalsIgnoreCase("DC-expire")) {
        highWaterMarker = highWaterMarker < 1 ? 1 : highWaterMarker;
      } else if (name.equalsIgnoreCase("Accounting-billed")
          || name.equalsIgnoreCase("Accounting-invalid")) {
        highWaterMarker = highWaterMarker < 2 ? 2 : highWaterMarker;
      } else if (name.equalsIgnoreCase("DC-accept")) {
        highWaterMarker = highWaterMarker < 3 ? 3 : highWaterMarker;
      } else if (name.equalsIgnoreCase("Accounting-open")) {
        highWaterMarker = highWaterMarker < 4 ? 4 : highWaterMarker;
      } else if (name.equalsIgnoreCase("DC-open")) {
        highWaterMarker = highWaterMarker < 5 ? 5 : highWaterMarker;
      } else if (name.equalsIgnoreCase("Accounting-exported")) {
        highWaterMarker = 6;
      }
    }

    switch (highWaterMarker) {
      case 0:
      default:
        return "None";
      case 1:
        return "Rejected";
      case 2:
        return "Accounting Closed";
      case 3:
        return "Submitted";
      case 4:
        return "Accounting Open";
      case 5:
        return "Open";
      case 6:
        return "Exported";
    }
  }
예제 #5
0
 public AdDcCoopBean[] getDcEntriesWaitingForWorkflow(Calendar adDateBefore)
     throws ApplicationException {
   ArrayList<AdDcCoopBean> entries = AdDcCoopManager.getDcEntriesWaitingForWorkflow(adDateBefore);
   return (AdDcCoopBean[]) ArrayUtils.toTypedArray(entries, AdDcCoopBean.class);
 }
예제 #6
0
  public void updateDivisionCoopMonies(int coopId) throws ApplicationException {

    if (LOG.isLoggable(Level.FINE)) {
      LOG.entering(this.getClass().getName(), "updateDivisionCoopMonies", String.valueOf(coopId));
    }

    boolean success = false;

    try {
      //			DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      AdCoopBean coop = AdCoopManager.getCoopById(coopId);
      if (coop == null) throw new ApplicationException("No coop exists having id: " + coopId);

      ArrayList<AdDcCoopBean> divisionCoops = AdDcCoopManager.getDivisionCoops(coopId);

      if (coop.getType() == ContractsUtils.getCoopIdRegional()) {
        AdDcCoopBean divisionBean = null, lastAccepted = null;
        double acceptedDollars = 0.0;
        double runningTotal = 0.0;
        // Find the total sum for all accepted dollars
        for (int i = 0; i < divisionCoops.size(); i++) {
          divisionBean = divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1 && divisionBean.getAccountRejectReason() <= 0) {
            acceptedDollars += divisionBean.getInitialAmount();
          }
        }

        if (LOG.isLoggable(Level.FINER)) {
          LOG.finer("total amount of accepted coop dollars is: " + acceptedDollars);
        }

        for (int i = 0; i < divisionCoops.size(); i++) {
          divisionBean = (AdDcCoopBean) divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1
              && divisionBean.getAccountRejectReason() <= 0
              && acceptedDollars > 0.0) {
            lastAccepted = divisionBean;
            // Multiply the accepted amount by a scaling factor in order to reallocate the dollars
            // that were
            //   not accepted.  For example, if only $500 (acceptedDollars) out of $1000
            // (coop.getTotal)
            //   dollars were accepted, the amounts that WERE accepted would be multiplied by 2 =
            // 1000/500
            double newAmount =
                (divisionBean.getInitialAmount() * coop.getTotal()) / acceptedDollars;
            newAmount = Math.round(newAmount * 100.0D) / 100.0D; // get rid of extra digits
            runningTotal += newAmount;
            divisionBean.setBilledAmount(newAmount);
          } else {
            divisionBean.setBilledAmount(0.0);
          }
        }

        if (lastAccepted != null && runningTotal != coop.getTotal()) {
          if (LOG.isLoggable(Level.FINER)) {
            LOG.finer(
                "offsetting funds from rounding errors of "
                    + (coop.getTotal() - runningTotal)
                    + " to division "
                    + lastAccepted.getRegionMemberId());
          }
          double newAmount = lastAccepted.getBilledAmount() + coop.getTotal() - runningTotal;
          lastAccepted.setBilledAmount(Math.round(newAmount * 100.0D) / 100.0D);
        }
      } else {
        boolean isCaseRate = coop.getType() == ContractsUtils.getCoopIdCaseRate();

        for (int i = 0; i < divisionCoops.size(); i++) {
          AdDcCoopBean divisionBean = (AdDcCoopBean) divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1 && divisionBean.getAccountRejectReason() <= 0) {
            if (isCaseRate) {
              int actualCases =
                  divisionBean.getActualCases() <= 0 ? 0 : divisionBean.getActualCases();
              divisionBean.setBilledAmount(
                  Math.round(actualCases * divisionBean.getInitialAmount() * 100.0D) / 100.0D);
            } else {
              divisionBean.setBilledAmount(divisionBean.getInitialAmount());
            }
          } else {
            divisionBean.setBilledAmount(0.0);
          }
          LOG.finer("billed amount for division : " + divisionBean.getBilledAmount());
        }
      }

      this.storeAdDcCoops(
          (AdDcCoopBean[]) ArrayUtils.toTypedArray(divisionCoops, AdDcCoopBean.class));

      success = true;
    } finally {
      //			DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }

    if (LOG.isLoggable(Level.FINE)) {
      LOG.exiting(this.getClass().getName(), "updateDivisionCoopMonies", String.valueOf(coopId));
    }
  }
예제 #7
0
  public AdDcCoopDetailBean[] getAdDcCoopDetailsByWeekAndDivision(
      Calendar adWeek, int regionMemberId) throws Exception {

    LOG.log(
        Level.FINE,
        "beginning of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");

    ArrayList<AdDcCoopBean> coops =
        AdDcCoopManager.getDivisionCoopsByDateAndRegMbrId(adWeek, regionMemberId);

    LOG.log(Level.FINE, "coops_________________" + coops);

    AdDcCoopDetailBean[] results = new AdDcCoopDetailBean[coops.size()];

    LOG.log(Level.FINE, "results_________________" + results);

    LOG.log(
        Level.FINE, "inside of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");
    Workflow coopWorkflow = ContractsUtils.getWorkflowCommand().getWorkflowByName(COOP_WORKFLOW);

    LOG.log(Level.FINE, "coopWorkflow_____________________________" + coopWorkflow);

    if (coopWorkflow == null) {
      LOG.log(Level.FINE, "coopWorkflow_____________________________is null");
      throw new ApplicationException("Unable to locate coop workflow configuration.");
    }

    LOG.log(Level.FINE, "before divisionStateGroup_____________________________");

    State divisionStateGroup =
        ContractsUtils.getStateCommand()
            .getStateByNameAndWorkflowId(DIVISION_STATE, coopWorkflow.getId());

    LOG.log(
        Level.FINE, "before divisionStateGroup_____________________________" + divisionStateGroup);

    State accountingStateGroup =
        ContractsUtils.getStateCommand()
            .getStateByNameAndWorkflowId(ACCOUNTING_STATE, coopWorkflow.getId());

    if (divisionStateGroup == null) {
      throw new ApplicationException("Unable to locate division state in workflow configuration.");
    }

    if (accountingStateGroup == null) {
      throw new ApplicationException(
          "Unable to locate accounting state in workflow configuration.");
    }

    for (int i = 0; i < coops.size(); i++) {
      AdDcCoopBean bean = coops.get(i);
      AdDcCoopDetailBean current = new AdDcCoopDetailBean(bean);
      AdCoopBean adCoop =
          ServiceLocator.getInstance()
              .getService(AdCoopCommand.class)
              .getAdCoopById(current.getCoopId());
      AdEntryBean adEntry =
          ServiceLocator.getInstance()
              .getService(AdEntryCommand.class)
              .getAdEntryByCoopId(current.getCoopId());
      current.setAdEntry(adEntry);
      current.setAdCoop(adCoop);

      current.setInDivisionPhase(
          ContractsUtils.getTransactionPhaseCommand()
              .isPhaseInState(bean.getWorkFlowPhaseId(), divisionStateGroup.getId()));

      current.setInAccountingPhase(
          ContractsUtils.getTransactionPhaseCommand()
              .isPhaseInState(bean.getWorkFlowPhaseId(), accountingStateGroup.getId()));

      results[i] = current;
    }

    LOG.log(Level.FINE, "end of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");

    return results;
  }
예제 #8
0
 public ArrayList<AdDcCoopBean> getAdDcCoopsByCoopIds(int[] coopIds) throws ApplicationException {
   return AdDcCoopManager.getAdDcCoopsByCoopIds(coopIds);
 }
예제 #9
0
 public AdDcCoopBean[] getAdDcCoopsByCoopId(int coopId) throws ApplicationException {
   return (AdDcCoopBean[])
       ArrayUtils.toTypedArray(AdDcCoopManager.getDivisionCoops(coopId), AdDcCoopBean.class);
 }
예제 #10
0
 public AdDcCoopBean getAdDcCoopByPhaseId(int phaseId) throws ApplicationException {
   return AdDcCoopManager.getDivisionCoopByPhaseId(phaseId);
 }
예제 #11
0
 public AdDcCoopBean getAdDcCoopByIdAndDivision(int coopId, int regionMemberId)
     throws ApplicationException {
   return AdDcCoopManager.getAdDcCoopByIdAndRegMbrId(coopId, regionMemberId);
 }