protected String buildObjectCodeCachingKey(ObjectCode objectCode) {
   return objectCode.getUniversityFiscalYear()
       + KRADConstants.Maintenance.LOCK_AFTER_VALUE_DELIM
       + objectCode.getChartOfAccountsCode()
       + KRADConstants.Maintenance.LOCK_AFTER_VALUE_DELIM
       + objectCode.getFinancialObjectCode();
 }
示例#2
0
 public ObjectCode createObjectCode() {
   ObjectCode objectCode = new ObjectCode();
   objectCode.setUniversityFiscalYear(this.universityFiscalYear);
   objectCode.setChartOfAccountsCode(this.chartOfAccountsCode);
   objectCode.setFinancialObjectCode(this.financialObjectCode);
   return objectCode;
 }
  /**
   * Gets the fieldInfo attribute.
   *
   * @return Returns the fieldInfo.
   */
  protected List<Map<String, String>> getFieldInfo(List<EffortCertificationDetail> detailLines) {
    LOG.debug("getFieldInfo(List<EffortCertificationDetail>) start");

    List<Map<String, String>> fieldInfo = new ArrayList<Map<String, String>>();
    EffortCertificationDocument document = (EffortCertificationDocument) this.getDocument();
    KualiDecimal totalOriginalPayrollAmount = document.getTotalOriginalPayrollAmount();

    for (EffortCertificationDetail detailLine : detailLines) {
      detailLine.refreshNonUpdateableReferences();

      Map<String, String> fieldInfoForAttribute = new HashMap<String, String>();

      fieldInfoForAttribute.put(
          KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
          detailLine.getChartOfAccounts().getFinChartOfAccountDescription());

      String accountInfo = buildAccountInfo(detailLine.getAccount());
      fieldInfoForAttribute.put(KFSPropertyConstants.ACCOUNT_NUMBER, accountInfo);

      SubAccount subAccount = detailLine.getSubAccount();
      if (ObjectUtils.isNotNull(subAccount)) {
        fieldInfoForAttribute.put(
            KFSPropertyConstants.SUB_ACCOUNT_NUMBER, subAccount.getSubAccountName());
      }

      ObjectCode objectCode = detailLine.getFinancialObject();
      if (ObjectUtils.isNotNull(objectCode)) {
        fieldInfoForAttribute.put(
            KFSPropertyConstants.FINANCIAL_OBJECT_CODE, objectCode.getFinancialObjectCodeName());
      }

      Account sourceAccount = detailLine.getSourceAccount();
      if (ObjectUtils.isNotNull(sourceAccount)) {
        fieldInfoForAttribute.put(
            EffortPropertyConstants.SOURCE_ACCOUNT_NUMBER, sourceAccount.getAccountName());
      }

      Chart sourceChart = detailLine.getSourceChartOfAccounts();
      if (ObjectUtils.isNotNull(sourceChart)) {
        fieldInfoForAttribute.put(
            EffortPropertyConstants.SOURCE_CHART_OF_ACCOUNTS_CODE,
            sourceChart.getFinChartOfAccountDescription());
      }

      KualiDecimal originalPayrollAmount = detailLine.getEffortCertificationOriginalPayrollAmount();
      String actualOriginalPercent =
          PayrollAmountHolder.recalculateEffortPercentAsString(
              totalOriginalPayrollAmount, originalPayrollAmount);
      fieldInfoForAttribute.put(
          EffortPropertyConstants.EFFORT_CERTIFICATION_CALCULATED_OVERALL_PERCENT,
          actualOriginalPercent);

      fieldInfo.add(fieldInfoForAttribute);
    }

    return fieldInfo;
  }
 protected Collection<SubObjectCode> getAssociatedSubObjects(ObjectCode objectCode) {
   Map<String, Object> fieldValues = new HashMap<String, Object>();
   fieldValues.put(
       KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, objectCode.getUniversityFiscalYear());
   fieldValues.put(
       KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, objectCode.getChartOfAccountsCode());
   fieldValues.put(
       KFSPropertyConstants.FINANCIAL_OBJECT_CODE, objectCode.getFinancialObjectCode());
   return businessObjectService.findMatching(SubObjectCode.class, fieldValues);
 }
 @Override
 protected Map<String, String> buildInactivationBlockerQueryMap(
     BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
   ObjectCode blockedObjectCode = (ObjectCode) blockedBo;
   if (universityDateService
       .getCurrentFiscalYear()
       .equals(blockedObjectCode.getUniversityFiscalYear())) {
     return super.buildInactivationBlockerQueryMap(blockedBo, inactivationBlockingMetadata);
   }
   return null;
 }
 /**
  * @see
  *     org.kuali.kfs.module.cam.document.service.AssetPaymentService#isPaymentFinancialObjectActive(org.kuali.kfs.module.cam.businessobject.AssetPayment)
  */
 public boolean isPaymentFinancialObjectActive(AssetPayment assetPayment) {
   ObjectCode financialObjectCode = new ObjectCode();
   financialObjectCode.setUniversityFiscalYear(getUniversityDateService().getCurrentFiscalYear());
   financialObjectCode.setChartOfAccountsCode(assetPayment.getChartOfAccountsCode());
   financialObjectCode.setFinancialObjectCode(assetPayment.getFinancialObjectCode());
   financialObjectCode = (ObjectCode) getBusinessObjectService().retrieve(financialObjectCode);
   if (ObjectUtils.isNotNull(financialObjectCode)) {
     return financialObjectCode.isActive();
   }
   return false;
 }
  /**
   * @see org.kuali.kfs.coa.dataaccess.ObjectCodeDao#getYearList(java.lang.String, java.lang.String)
   */
  public List getYearList(String chartOfAccountsCode, String financialObjectCode) {

    List returnList = new ArrayList();
    Criteria criteria = new Criteria();
    criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode);
    criteria.addEqualTo("financialObjectCode", financialObjectCode);
    Collection years =
        getPersistenceBrokerTemplate()
            .getCollectionByQuery(QueryFactory.newQuery(ObjectCode.class, criteria));
    for (Iterator iter = years.iterator(); iter.hasNext(); ) {
      ObjectCode o = (ObjectCode) iter.next();
      if (o != null) {
        returnList.add(o.getUniversityFiscalYear());
      }
    }
    return returnList;
  }
 protected Map<String, Boolean> buildObjectCodeActiveStatusCache(
     ObjectCodeGlobal objectCodeGlobal) {
   ObjectCodeService objectCodeService = SpringContext.getBean(ObjectCodeService.class);
   Map<String, Boolean> cache = new HashMap<String, Boolean>();
   for (ObjectCodeGlobalDetail detail : objectCodeGlobal.getObjectCodeGlobalDetails()) {
     ObjectCode objectCodeFromDB =
         objectCodeService.getByPrimaryId(
             detail.getUniversityFiscalYear(),
             detail.getChartOfAccountsCode(),
             objectCodeGlobal.getFinancialObjectCode());
     if (ObjectUtils.isNotNull(objectCodeFromDB)) {
       cache.put(
           buildObjectCodeCachingKey(objectCodeFromDB),
           Boolean.valueOf(objectCodeFromDB.isActive()));
     }
   }
   return cache;
 }
  public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurApAccountingLine account =
        (PurApAccountingLine) ((AddAccountingLineEvent) event).getAccountingLine();
    ObjectCode objectCode = account.getObjectCode();

    ParameterEvaluator parameterEvaluator = /*REFACTORME*/
        SpringContext.getBean(ParameterEvaluatorService.class)
            .getParameterEvaluator(
                VendorCreditMemoDocument.class,
                PurapRuleConstants.VALID_OBJECT_LEVELS_BY_OBJECT_TYPE_PARM_NM,
                PurapRuleConstants.INVALID_OBJECT_LEVELS_BY_OBJECT_TYPE_PARM_NM,
                objectCode.getFinancialObjectTypeCode(),
                objectCode.getFinancialObjectLevelCode());
    return parameterEvaluator.evaluateAndAddError(
        SourceAccountingLine.class,
        "objectCode.financialObjectLevelCode",
        KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
  }
 protected boolean isInactivatingObjectCode(
     ObjectCode objectCode, Map<String, Boolean> objectCodeActiveStatusCache) {
   if (!objectCode.isActive()) {
     if (Boolean.TRUE.equals(
         objectCodeActiveStatusCache.get(buildObjectCodeCachingKey(objectCode)))) {
       return true;
     }
   }
   return false;
 }
  /**
   * This generates the appropriate maintenance locks for the {@link ObjectCode}
   *
   * @see org.kuali.rice.kns.maintenance.Maintainable#generateMaintenanceLocks()
   */
  @Override
  public List<MaintenanceLock> generateMaintenanceLocks() {
    ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) getBusinessObject();
    List<MaintenanceLock> maintenanceLocks = new ArrayList();
    SubObjectTrickleDownInactivationService subObjectTrickleDownInactivationService =
        SpringContext.getBean(SubObjectTrickleDownInactivationService.class);

    for (ObjectCodeGlobalDetail detail : objectCodeGlobal.getObjectCodeGlobalDetails()) {
      MaintenanceLock maintenanceLock = new MaintenanceLock();
      StringBuffer lockrep = new StringBuffer();

      lockrep.append(ObjectCode.class.getName() + KFSConstants.Maintenance.AFTER_CLASS_DELIM);
      lockrep.append("universityFiscalYear" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getUniversityFiscalYear() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
      lockrep.append("chartOfAccountsCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getChartOfAccountsCode() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
      lockrep.append("financialObjectCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getFinancialObjectCode());

      maintenanceLock.setDocumentNumber(objectCodeGlobal.getDocumentNumber());
      maintenanceLock.setLockingRepresentation(lockrep.toString());
      maintenanceLocks.add(maintenanceLock);

      ObjectCode objectCode = new ObjectCode();
      objectCode.setUniversityFiscalYear(detail.getUniversityFiscalYear());
      objectCode.setChartOfAccountsCode(detail.getChartOfAccountsCode());
      objectCode.setFinancialObjectCode(detail.getFinancialObjectCode());
      objectCode.setActive(objectCodeGlobal.isFinancialObjectActiveIndicator());

      if (isInactivatingObjectCode(objectCode)) {
        // if it turns out that the object code does not have associated sub-objects (either because
        // the object code doesn't exist or doesn't have sub-objects)
        // then the generateTrickleDownMaintenanceLocks method returns an empty list
        maintenanceLocks.addAll(
            subObjectTrickleDownInactivationService.generateTrickleDownMaintenanceLocks(
                objectCode, getDocumentNumber()));
      }
    }
    return maintenanceLocks;
  }
  /**
   * determines if object code sub types are valid with the object type code. <strong>Expects an
   * accounting line as the first a parameter</strong>
   *
   * @see org.kuali.kfs.sys.document.validation.Validation#validate(java.lang.Object[])
   */
  public boolean validate(AttributedDocumentEvent event) {
    accountingLineForValidation.refreshReferenceObject("objectCode");
    ObjectCode code = accountingLineForValidation.getObjectCode();
    boolean retVal = true;

    if (!ObjectUtils.isNull(code)) {
      ParameterEvaluator parameterEvaluator = /*REFACTORME*/
          SpringContext.getBean(ParameterEvaluatorService.class)
              .getParameterEvaluator(
                  GeneralErrorCorrectionDocument.class,
                  VALID_OBJECT_SUB_TYPES_BY_OBJECT_TYPE,
                  INVALID_OBJECT_SUB_TYPES_BY_OBJECT_TYPE,
                  code.getFinancialObjectTypeCode(),
                  code.getFinancialObjectSubTypeCode());

      retVal =
          parameterEvaluator.evaluateAndAddError(
              SourceAccountingLine.class,
              "objectCode.financialObjectSubTypeCode",
              KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
    }
    return retVal;
  }
 protected boolean isInactivatingObjectCode(ObjectCode objectCode) {
   ObjectCodeService objectCodeService = SpringContext.getBean(ObjectCodeService.class);
   if (!objectCode.isActive()) {
     ObjectCode objectCodeFromDB =
         objectCodeService.getByPrimaryId(
             objectCode.getUniversityFiscalYear(),
             objectCode.getChartOfAccountsCode(),
             objectCode.getFinancialObjectCode());
     if (objectCodeFromDB != null && objectCodeFromDB.isActive()) {
       return true;
     }
   }
   return false;
 }
  /**
   * Creates a new asset payment record for each new asset payment detail record and then save them
   *
   * @param document
   */
  protected void processPayments(AssetPaymentDocument document) {
    List<AssetPaymentDetail> assetPaymentDetailLines = document.getSourceAccountingLines();
    List<AssetPaymentAssetDetail> assetPaymentAssetDetails = document.getAssetPaymentAssetDetail();
    List<PersistableBusinessObject> assetPayments = new ArrayList<PersistableBusinessObject>();
    Integer maxSequenceNo = new Integer(0);

    // instantiate asset payment distributor
    AssetDistribution paymentDistributor = document.getAssetPaymentDistributor();

    // Calculating the asset payments distributions for each individual asset on the list
    Map<String, Map<AssetPaymentAssetDetail, KualiDecimal>> assetPaymentDistributionMap =
        paymentDistributor.getAssetPaymentDistributions();

    try {
      // Creating a new payment record for each asset that has payments.
      for (AssetPaymentAssetDetail assetPaymentAssetDetail : assetPaymentAssetDetails) {

        maxSequenceNo = getMaxSequenceNumber(assetPaymentAssetDetail.getCapitalAssetNumber());

        KualiDecimal totalAmount = KualiDecimal.ZERO;
        for (AssetPaymentDetail assetPaymentDetail : assetPaymentDetailLines) {

          // Retrieve the asset payment from the distribution map
          KualiDecimal amount =
              assetPaymentDistributionMap
                  .get(assetPaymentDetail.getAssetPaymentDetailKey())
                  .get(assetPaymentAssetDetail);
          totalAmount = totalAmount.add(amount);

          AssetPayment assetPayment = new AssetPayment(assetPaymentDetail);
          assetPayment.setCapitalAssetNumber(assetPaymentAssetDetail.getCapitalAssetNumber());
          assetPayment.setTransferPaymentCode(CamsConstants.AssetPayment.TRANSFER_PAYMENT_CODE_N);
          assetPayment.setPaymentSequenceNumber(++maxSequenceNo);
          if (StringUtils.isBlank(assetPayment.getDocumentNumber())) {
            assetPayment.setDocumentNumber(document.getDocumentNumber());
          }
          assetPayment.setAccountChargeAmount(amount);

          KualiDecimal baseAmount = KualiDecimal.ZERO;

          // If the object sub type is not in the list of federally owned object sub types, then...
          ObjectCode objectCode =
              this.getObjectCodeService()
                  .getByPrimaryId(
                      assetPaymentDetail.getPostingYear(),
                      assetPaymentDetail.getChartOfAccountsCode(),
                      assetPaymentDetail.getFinancialObjectCode());

          // Depreciation Base Amount will be assigned to each payment only when the object code's
          // sub type code is not a
          // federally owned one
          if (!this.isNonDepreciableFederallyOwnedObjSubType(
              objectCode.getFinancialObjectSubTypeCode())) {
            baseAmount = baseAmount.add(amount);
          }
          assetPayment.setPrimaryDepreciationBaseAmount(baseAmount);

          // Resetting each period field its value with nulls
          this.adjustPaymentAmounts(assetPayment, false, true);

          // add new payment
          assetPayments.add(assetPayment);
        }
        // *********************BEGIN - Updating Asset
        // ***********************************************************
        // Retrieving the asset that will have its cost updated
        HashMap<String, Long> keys = new HashMap<String, Long>();
        keys.put(
            CamsPropertyConstants.Asset.CAPITAL_ASSET_NUMBER,
            assetPaymentAssetDetail.getCapitalAssetNumber());
        Asset asset = (Asset) getBusinessObjectService().findByPrimaryKey(Asset.class, keys);

        // Set previous total cost
        if (assetPaymentAssetDetail.getPreviousTotalCostAmount() == null) {
          assetPaymentAssetDetail.setPreviousTotalCostAmount(new KualiDecimal(0));
        }

        // Setting the asset's new cost.
        asset.setTotalCostAmount(
            assetPaymentAssetDetail.getPreviousTotalCostAmount().add(totalAmount));

        // Setting the asset's financial object sub-type Code. Only when the asset doesn't have one.
        if (asset.getFinancialObjectSubTypeCode() == null
            || asset.getFinancialObjectSubTypeCode().trim().equals("")) {
          asset.setFinancialObjectSubTypeCode(
              assetPaymentDetailLines.get(0).getObjectCode().getFinancialObjectSubTypeCode());
        }
        // Saving changes
        getBusinessObjectService().save(asset);
        // *********************END - Updating Asset
        // ***********************************************************
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    // Finally, saving all the asset payment records.
    this.getBusinessObjectService().save(assetPayments);
  }