@SuppressWarnings("unchecked")
  @Override
  public ActionForward addItem(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    PurApItem item = purchasingForm.getNewPurchasingItemLine();
    RequisitionItem requisitionItem = (RequisitionItem) item;
    PurchasingDocument purDocument = (PurchasingDocument) purchasingForm.getDocument();

    if (StringUtils.isBlank(requisitionItem.getPurchasingCommodityCode())) {
      boolean commCodeParam =
          SpringContext.getBean(ParameterService.class)
              .getParameterValueAsBoolean(
                  CuRequisitionDocument.class,
                  PurapParameterConstants.ENABLE_DEFAULT_VENDOR_COMMODITY_CODE_IND);

      if (commCodeParam) {
        if (purchasingForm instanceof RequisitionForm) {
          CuRequisitionDocument reqs = (CuRequisitionDocument) purchasingForm.getDocument();
          VendorDetail dtl = reqs.getVendorDetail();
          if (ObjectUtils.isNotNull(dtl)) {
            List<VendorCommodityCode> vcc = dtl.getVendorCommodities();
            String defaultCommodityCode = "";
            Iterator<VendorCommodityCode> it = vcc.iterator();
            while (it.hasNext()) {
              VendorCommodityCode commodity = it.next();
              if (commodity.isCommodityDefaultIndicator()) {
                defaultCommodityCode = commodity.getPurchasingCommodityCode();
                requisitionItem.setPurchasingCommodityCode(defaultCommodityCode);
              }
            }
          }
        }
      }
    }

    boolean rulePassed =
        SpringContext.getBean(KualiRuleService.class)
            .applyRules(new AttributedAddPurchasingAccountsPayableItemEvent("", purDocument, item));

    if (rulePassed) {
      item = purchasingForm.getAndResetNewPurchasingItemLine();
      purDocument.addItem(item);
      // KFSPTS-985
      if (((PurchasingDocumentBase) (purDocument)).isIntegratedWithFavoriteAccount()) {
        populatePrimaryFavoriteAccount(
            item.getSourceAccountingLines(),
            getAccountClassFromNewPurApAccountingLine(purchasingForm));
      }
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }
 protected boolean isVendorQuoteActiveNotDebarredVendor(
     Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifer) {
   VendorDetail vendorDetail =
       vendorService.getVendorDetail(
           vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifer);
   if (vendorDetail != null) {
     if (!vendorDetail.isActiveIndicator()) {
       GlobalVariables.getMessageMap()
           .putError(
               PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME,
               PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_INACTIVE_VENDOR);
       return false;
     } else if (vendorDetail.isVendorDebarred()) {
       GlobalVariables.getMessageMap()
           .putError(
               PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME,
               PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_DEBARRED_VENDOR);
       return false;
     }
   }
   return true;
 }
Beispiel #3
0
  /**
   * Gets the payee's name from KIM or Vendor data, if the payee type is Employee, Entity or Vendor;
   * otherwise returns the stored field value.
   *
   * @return Returns the payee name
   */
  public String getPayeeName() {
    // for Employee, retrieves from Person table by employee ID
    if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.EMPLOYEE)) {
      if (ObjectUtils.isNotNull(payeeIdNumber)) {
        String name =
            SpringContext.getBean(FinancialSystemUserService.class)
                .getPersonNameByEmployeeId(payeeIdNumber);

        // Person person =
        // SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeIdNumber);
        if (ObjectUtils.isNotNull(name)) {
          return name;
        }
      }
    }
    // for Entity, retrieve from Entity table by entity ID
    else if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.ENTITY)) {
      if (ObjectUtils.isNotNull(payeeIdNumber)) {
        EntityDefault entity =
            KimApiServiceLocator.getIdentityService().getEntityDefault(payeeIdNumber);
        if (ObjectUtils.isNotNull(entity) && ObjectUtils.isNotNull(entity.getName())) {
          return entity.getName().getCompositeName();
        }
      }
    }
    // for Vendor, retrieves from Vendor table by vendor number
    else if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.VENDOR_ID)) {
      VendorDetail vendor =
          SpringContext.getBean(VendorService.class).getVendorDetail(payeeIdNumber);
      if (ObjectUtils.isNotNull(vendor)) {
        return vendor.getVendorName();
      }
    }

    // otherwise return field value
    return payeeName;
  }
  /**
   * @see
   *     org.kuali.kfs.sys.batch.service.PaymentSourceToExtractService#createPaymentGroup(org.kuali.kfs.sys.document.PaymentSource,
   *     java.sql.Date)
   */
  @Override
  public PaymentGroup createPaymentGroup(TEMReimbursementDocument document, Date processRunDate) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("createPaymentGroupForReimbursable() started");
    }

    final boolean disburseCorporateCardPayments =
        getParameterService()
            .getParameterValueAsBoolean(
                TemParameterConstants.TEM_DOCUMENT.class,
                TemConstants.TravelParameters.CORPORATE_CARD_PAYMENT_IND);
    if (!disburseCorporateCardPayments) {
      return null; // can't disburse payments? then don't create payment groups
    }

    PaymentGroup pg = new PaymentGroup();
    final CreditCardAgency creditCardAgency = getCorporateCreditCardAgency(document);
    if (creditCardAgency == null) {
      LOG.error(
          "Skipping corporate card payment for "
              + document.getDocumentNumber()
              + " because no credit card agency could be found.");
      return null;
    }
    final VendorDetail vendor = getCorporateCardVendor(creditCardAgency);
    if (vendor == null) {
      LOG.error(
          "Skipping corporate card payment for "
              + document.getDocumentNumber()
              + " because no vendor could be found.");
      return null;
    }
    final VendorAddress vendorAddress =
        getVendorService()
            .getVendorDefaultAddress(
                vendor.getVendorAddresses(),
                vendor
                    .getVendorHeader()
                    .getVendorType()
                    .getAddressType()
                    .getVendorAddressTypeCode(),
                "");

    pg.setCombineGroups(Boolean.TRUE);
    pg.setCampusAddress(Boolean.FALSE);

    pg.setCity(vendorAddress.getVendorCityName());
    pg.setCountry(vendorAddress.getVendorCountryCode());
    pg.setLine1Address(vendorAddress.getVendorLine1Address());
    pg.setLine2Address(vendorAddress.getVendorLine2Address());
    pg.setPayeeName(vendor.getVendorName());
    pg.setState(vendorAddress.getVendorStateCode());
    pg.setZipCd(vendorAddress.getVendorZipCode());
    pg.setPaymentDate(getNextDate(processRunDate));
    pg.setProcessImmediate(false);
    pg.setPymtAttachment(false);
    pg.setPymtSpecialHandling(false);
    pg.setNraPayment(false);
    pg.setBankCode(creditCardAgency.getBankCode());
    pg.setPaymentStatusCode(PdpConstants.PaymentStatusCodes.OPEN);
    if (StringUtils.equals(
        document.getTraveler().getTravelerTypeCode(), TemConstants.EMP_TRAVELER_TYP_CD)) {
      pg.setEmployeeIndicator(true);
    }
    pg.setPayeeId(vendor.getVendorNumber());
    pg.setPayeeIdTypeCd(PdpConstants.PayeeIdTypeCodes.VENDOR_ID);
    pg.setTaxablePayment(Boolean.FALSE);
    pg.setPayeeOwnerCd(vendor.getVendorHeader().getVendorOwnershipCode());

    // now add the payment detail
    final PaymentDetail paymentDetail = buildPaymentDetail(document, processRunDate);
    pg.addPaymentDetails(paymentDetail);
    paymentDetail.setPaymentGroup(pg);

    return pg;
  }
  /**
   * Validation for the Stipulation tab.
   *
   * @param poDocument the purchase order document to be validated
   * @return boolean false if the vendor stipulation description is blank.
   */
  @Override
  public boolean validate(AttributedDocumentEvent event) {
    boolean valid = super.validate(event);
    PurchasingAccountsPayableDocument purapDocument =
        (PurchasingAccountsPayableDocument) event.getDocument();
    PurchaseOrderDocument poDocument = (PurchaseOrderDocument) purapDocument;
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);

    // check to see if the vendor exists in the database, i.e. its ID is not null
    Integer vendorHeaderID = poDocument.getVendorHeaderGeneratedIdentifier();
    if (ObjectUtils.isNull(vendorHeaderID)) {
      valid = false;
      errorMap.putError(
          VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_NONEXIST_VENDOR);
    }

    // vendor active validation...
    VendorDetail vendorDetail =
        super.getVendorService()
            .getVendorDetail(
                poDocument.getVendorHeaderGeneratedIdentifier(),
                poDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNull(vendorDetail)) {
      return valid;
    }

    // make sure that the vendor is active
    if (!vendorDetail.isActiveIndicator()) {
      valid &= false;
      errorMap.putError(
          VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
    }

    // validate vendor address
    super.getPostalCodeValidationService()
        .validateAddress(
            poDocument.getVendorCountryCode(),
            poDocument.getVendorStateCode(),
            poDocument.getVendorPostalCode(),
            PurapPropertyConstants.VENDOR_STATE_CODE,
            PurapPropertyConstants.VENDOR_POSTAL_CODE);

    // Do checks for alternate payee vendor.
    Integer alternateVendorHdrGeneratedId =
        poDocument.getAlternateVendorHeaderGeneratedIdentifier();
    Integer alternateVendorHdrDetailAssignedId =
        poDocument.getAlternateVendorDetailAssignedIdentifier();

    VendorDetail alternateVendor =
        super.getVendorService()
            .getVendorDetail(alternateVendorHdrGeneratedId, alternateVendorHdrDetailAssignedId);

    if (alternateVendor != null) {
      if (alternateVendor.isVendorDebarred()) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DEBARRED);
        valid &= false;
      }
      if (StringUtils.equals(
          alternateVendor.getVendorHeader().getVendorTypeCode(),
          VendorTypes.DISBURSEMENT_VOUCHER)) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DV_TYPE);
        valid &= false;
      }
      if (!alternateVendor.isActiveIndicator()) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_INACTIVE,
            PODocumentsStrings.ALTERNATE_PAYEE_VENDOR);
        valid &= false;
      }
    }

    // make sure that the vendor contract expiration date and not marked inactive.
    if (StringUtils.isNotBlank(poDocument.getVendorContractName())) {
      if (super.getVendorService()
          .isVendorContractExpired(
              poDocument, poDocument.getVendorContractGeneratedIdentifier(), vendorDetail)) {
        errorMap.putError(
            VendorPropertyConstants.VENDOR_CONTRACT_END_DATE,
            PurapKeyConstants.ERROR_EXPIRED_CONTRACT_END_DATE);
        valid &= false;
      }
    }

    errorMap.clearErrorPath();
    return valid;
  }