use of org.kuali.kfs.vnd.businessobject.VendorCommodityCode in project cu-kfs by CU-CommunityApps.
the class CuRequisitionAction method addItem.
@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 && purchasingForm instanceof RequisitionForm) {
CuRequisitionDocument reqs = (CuRequisitionDocument) purchasingForm.getDocument();
VendorDetail dtl = reqs.getVendorDetail();
if (ObjectUtils.isNotNull(dtl)) {
List<VendorCommodityCode> vcc = dtl.getVendorCommodities();
for (VendorCommodityCode commodity : vcc) {
if (commodity.isCommodityDefaultIndicator()) {
requisitionItem.setPurchasingCommodityCode(commodity.getPurchasingCommodityCode());
}
}
}
}
}
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);
}
use of org.kuali.kfs.vnd.businessobject.VendorCommodityCode in project cu-kfs by CU-CommunityApps.
the class VendorRule method validateCommodityCodeDefaultIndicator.
/**
* Validates that there is one and only one default indicator selected
* for commodity code if the vendor contains at least one commodity code.
*
* @param vendorCommodities the list of VendorCommodityCode to be validated
* @return boolean true or false
*/
private boolean validateCommodityCodeDefaultIndicator(List<VendorCommodityCode> vendorCommodities) {
boolean valid = true;
boolean foundDefaultIndicator = false;
for (int i = 0; i < vendorCommodities.size(); i++) {
VendorCommodityCode vcc = vendorCommodities.get(i);
if (vcc.isCommodityDefaultIndicator()) {
if (!foundDefaultIndicator) {
foundDefaultIndicator = true;
} else {
// display error that there can only be 1 commodity code with default indicator = true.
String propertyName = VendorPropertyConstants.VENDOR_COMMODITIES_CODE + "[" + i + "]." + VendorPropertyConstants.VENDOR_COMMODITIES_DEFAULT_INDICATOR;
putFieldError(propertyName, VendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_REQUIRE_ONE_DEFAULT_IND);
valid = false;
}
}
}
if (!foundDefaultIndicator && vendorCommodities.size() > 0) {
// display error that there must be one commodity code selected as the default commodity code for the vendor.
String propertyName = VendorPropertyConstants.VENDOR_COMMODITIES_CODE + "[0]." + VendorPropertyConstants.VENDOR_COMMODITIES_DEFAULT_INDICATOR;
putFieldError(propertyName, VendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_REQUIRE_ONE_DEFAULT_IND);
valid = false;
}
return valid;
}
use of org.kuali.kfs.vnd.businessobject.VendorCommodityCode in project cu-kfs by CU-CommunityApps.
the class VendorRule method processCustomAddCollectionLineBusinessRules.
/**
* Validates business rules for VendorDetail document collection add lines. Add lines are the initial lines on a
* collections, i.e. the ones next to the "Add" button
*/
@Override
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
boolean success = true;
// this incoming bo needs to be refreshed because it doesn't have its subobjects setup
bo.refreshNonUpdateableReferences();
if (bo instanceof VendorAddress) {
VendorAddress address = (VendorAddress) bo;
success = checkAddressCountryEmptyStateZip(address);
}
if (bo instanceof VendorContract) {
VendorContract contract = (VendorContract) bo;
success &= validateVendorContractBeginEndDates(contract);
success &= processContractB2BValidation(contract, -1);
}
if (bo instanceof VendorContractOrganization) {
VendorContractOrganization contractOrg = (VendorContractOrganization) bo;
success &= validateVendorContractOrganization(contractOrg, 0);
}
if (bo instanceof VendorCustomerNumber) {
VendorCustomerNumber customerNumber = (VendorCustomerNumber) bo;
success &= validateVendorCustomerNumber(customerNumber);
}
if (bo instanceof VendorDefaultAddress) {
VendorDefaultAddress defaultAddress = (VendorDefaultAddress) bo;
String parentName = StringUtils.substringBeforeLast(collectionName, ".");
VendorAddress parent = (VendorAddress) ObjectUtils.getPropertyValue(this.getNewBo(), parentName);
VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
success &= checkDefaultAddressCampus(vendorDetail, defaultAddress, parent);
}
if (bo instanceof VendorCommodityCode) {
VendorCommodityCode commodityCode = (VendorCommodityCode) bo;
String purchasingCommodityCode = commodityCode.getPurchasingCommodityCode();
boolean found = ObjectUtils.isNotNull(commodityCode) && StringUtils.isNotBlank(purchasingCommodityCode) && checkVendorCommodityCode(commodityCode);
if (!found) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.PURCHASING_COMMODITY_CODE, KFSKeyConstants.ERROR_EXISTENCE, purchasingCommodityCode);
}
success &= found;
}
return success;
}
use of org.kuali.kfs.vnd.businessobject.VendorCommodityCode in project cu-kfs by CU-CommunityApps.
the class CuRequisitionServiceImpl method checkAutomaticPurchaseOrderRules.
/**
* Checks the rule for Automatic Purchase Order eligibility of the requisition and return a String containing the
* reason why the requisition was not eligible to become an APO if it was not eligible, or return an empty String
* if the requisition is eligible to become an APO
*
* @param requisition the requisition document to be checked for APO eligibility.
* @return String containing the reason why the requisition was not eligible to become an APO if it was not
* eligible, or an empty String if the requisition is eligible to become an APO.
*/
@Override
protected String checkAutomaticPurchaseOrderRules(RequisitionDocument requisition) {
String requisitionSource = requisition.getRequisitionSourceCode();
KualiDecimal reqTotal = requisition.getTotalDollarAmount();
KualiDecimal apoLimit = ((CuPurapService) purapService).getApoLimit(requisition);
requisition.setOrganizationAutomaticPurchaseOrderLimit(apoLimit);
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() reqId = " + requisition.getPurapDocumentIdentifier() + "; apoLimit = " + apoLimit + "; reqTotal = " + reqTotal);
}
if (apoLimit == null) {
return "APO limit is empty.";
} else {
if (reqTotal.compareTo(apoLimit) == 1) {
return "Requisition total is greater than the APO limit.";
}
}
if (reqTotal.compareTo(KualiDecimal.ZERO) <= 0) {
return "Requisition total is not greater than zero.";
}
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() vendor #" + requisition.getVendorHeaderGeneratedIdentifier() + "-" + requisition.getVendorDetailAssignedIdentifier());
}
if (requisition.getVendorHeaderGeneratedIdentifier() == null || requisition.getVendorDetailAssignedIdentifier() == null) {
return "Vendor was not selected from the vendor database.";
} else {
VendorDetail vendorDetail = vendorService.getVendorDetail(requisition.getVendorHeaderGeneratedIdentifier(), requisition.getVendorDetailAssignedIdentifier());
if (vendorDetail == null) {
return "Error retrieving vendor from the database.";
}
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode())) {
return "Requisition does not have all of the vendor address fields that are required for Purchase " + "Order.";
}
requisition.setVendorRestrictedIndicator(vendorDetail.getVendorRestrictedIndicator());
if (requisition.getVendorRestrictedIndicator() != null && requisition.getVendorRestrictedIndicator()) {
return "Selected vendor is marked as restricted.";
}
if (vendorDetail.isVendorDebarred()) {
return "Selected vendor is marked as a debarred vendor";
}
requisition.setVendorDetail(vendorDetail);
if (!PurapConstants.RequisitionSources.B2B.equals(requisitionSource) && ObjectUtils.isNull(requisition.getVendorContractGeneratedIdentifier())) {
Person initiator = personService.getPerson(requisition.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
VendorContract b2bContract = vendorService.getVendorB2BContract(vendorDetail, initiator.getCampusCode());
if (b2bContract != null) {
return "Standard requisition with no contract selected but a B2B contract exists for the " + "selected vendor.";
}
}
// if the vendor is selected through vendor contract is selected
if (StringUtils.isNotBlank(requisition.getVendorContractName())) {
// CU mod: KFSUPGRADE-926
boolean routeToCM = parameterService.getParameterValueAsBoolean(RequisitionDocument.class, CUPurapParameterConstants.ROUTE_REQS_WITH_EXPIRED_CONTRACT_TO_CM, Boolean.FALSE);
if (routeToCM && vendorService.isVendorContractExpired(requisition, requisition.getVendorContractGeneratedIdentifier(), vendorDetail)) {
return "Contracted Vendor used where the contract end date is expired.";
}
}
}
// if vendor address isn't complete, no APO
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode()) || !postalCodeValidationService.validateAddress(requisition.getVendorCountryCode(), requisition.getVendorStateCode(), requisition.getVendorPostalCode(), "", "")) {
return "Requisition does not contain a complete vendor address";
}
// These are needed for commodity codes. They are put in here so that we don't have to loop through items too
// many times.
String purchaseOrderRequiresCommodityCode = parameterService.getParameterValueAsString(PurchaseOrderDocument.class, PurapRuleConstants.ITEMS_REQUIRE_COMMODITY_CODE_IND);
boolean commodityCodeRequired = "Y".equals(purchaseOrderRequiresCommodityCode);
for (Object anItem : requisition.getItems()) {
RequisitionItem item = (RequisitionItem) anItem;
if (item.isItemRestrictedIndicator()) {
return "Requisition contains an item that is marked as restricted.";
}
// We only need to check the commodity codes if this is an above the line item.
if (item.getItemType().isLineItemIndicator()) {
List<VendorCommodityCode> vendorCommodityCodes = commodityCodeRequired ? requisition.getVendorDetail().getVendorCommodities() : null;
String commodityCodesReason = checkAPORulesPerItemForCommodityCodes(item, vendorCommodityCodes, commodityCodeRequired);
if (StringUtils.isNotBlank(commodityCodesReason)) {
return commodityCodesReason;
}
}
if (PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE.equals(item.getItemType().getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE.equals(item.getItemType().getItemTypeCode())) {
if (item.getItemUnitPrice() != null && BigDecimal.ZERO.compareTo(item.getItemUnitPrice()) != 0) {
// discount or trade-in item has unit price that is not empty or zero
return "Requisition contains a " + item.getItemType().getItemTypeDescription() + " item, so it does not qualify as an APO.";
}
}
// //Base code logic check not in CU mod
// if (!PurapConstants.RequisitionSources.B2B.equals(requisitionSource)) {
// for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
// if (capitalAssetManagementModuleService.doesAccountingLineFailAutomaticPurchaseOrderRules(
// accountingLine)) {
// return "Requisition contains accounting line with capital object level";
// }
// }
// }
}
if (StringUtils.isNotEmpty(requisition.getRecurringPaymentTypeCode())) {
return "Payment type is marked as recurring.";
}
if (requisition.getPurchaseOrderTotalLimit() != null && KualiDecimal.ZERO.compareTo(requisition.getPurchaseOrderTotalLimit()) != 0) {
LOG.debug("isAPO() po total limit is not null and not equal to zero; return false.");
return "The 'PO not to exceed' amount has been entered.";
}
if (StringUtils.isNotEmpty(requisition.getAlternate1VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate2VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate3VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate4VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate5VendorName())) {
LOG.debug("isAPO() alternate vendor name exists; return false.");
return "Requisition contains additional suggested vendor names.";
}
if (requisition.isPostingYearNext() && !purapService.isTodayWithinApoAllowedRange()) {
return "Requisition is set to encumber next fiscal year and approval is not within APO allowed date range.";
}
return "";
}
use of org.kuali.kfs.vnd.businessobject.VendorCommodityCode in project cu-kfs by CU-CommunityApps.
the class CuVendorRule method validateB2BDefaultCommodityCode.
protected boolean validateB2BDefaultCommodityCode(MaintenanceDocument document) {
VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
boolean success = true;
List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
List<VendorCommodityCode> vendorCommodities = vendorDetail.getVendorCommodities();
Iterator<VendorContract> it = vendorContracts.iterator();
boolean isB2b = false;
while (it.hasNext()) {
VendorContract contract = (VendorContract) it.next();
if (contract.getVendorB2bIndicator()) {
isB2b = true;
break;
}
}
if (isB2b) {
if (vendorCommodities.size() == 0) {
success = false;
// no vendor commodities exist
putFieldError("vendorCommodities", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DEFAULT_IS_REQUIRED_FOR_B2B);
return success;
}
boolean defaultCommodityCodeSpecified = false;
Iterator<VendorCommodityCode> commodities = vendorCommodities.iterator();
int indice = 0;
while (commodities.hasNext()) {
VendorCommodityCode commodity = (VendorCommodityCode) commodities.next();
if (commodity.isCommodityDefaultIndicator() && !defaultCommodityCodeSpecified) {
defaultCommodityCodeSpecified = true;
} else if (commodity.isCommodityDefaultIndicator()) {
// more than one "default" commodity code has been specified
putFieldError("vendorCommodities[" + indice + "].commodityDefaultIndicator", CUVendorKeyConstants.ERROR_DEFAULT_VENDOR_COMMODITY_CODE_ALREADY_EXISTS);
success = false;
}
CommodityCode persistedCommodity = commodityCodeService.getByPrimaryId(commodity.getPurchasingCommodityCode());
if (persistedCommodity == null) {
// a commodity code entered by a user does not exist
putFieldError("vendorCommodities[" + indice + "].purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DOES_NOT_EXIST, commodity.getPurchasingCommodityCode());
success = false;
}
indice++;
}
if (!defaultCommodityCodeSpecified) {
// no default commodity code has been specified and the vendor has a b2b contract
putFieldError("vendorCommodities", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DEFAULT_IS_REQUIRED_FOR_B2B);
success = false;
}
}
return success;
}
Aggregations