use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentChanged.
public void testUpdateAccountAmounts_AccountingLinePercentChanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(75).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentUnchanged.
public void testUpdateAccountAmounts_AccountingLinePercentUnchanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(50).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem in project cu-kfs by CU-CommunityApps.
the class PurchaseOrderDocument method populatePurchaseOrderFromRequisition.
/**
* Populates this Purchase Order from the related Requisition Document.
*
* @param requisitionDocument the Requisition Document from which field values are copied.
*/
public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
this.setPurchaseOrderCreateTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
this.getDocumentHeader().setOrganizationDocumentNumber(requisitionDocument.getDocumentHeader().getOrganizationDocumentNumber());
this.getDocumentHeader().setDocumentDescription(requisitionDocument.getDocumentHeader().getDocumentDescription());
this.getDocumentHeader().setExplanation(requisitionDocument.getDocumentHeader().getExplanation());
this.setBillingName(requisitionDocument.getBillingName());
this.setBillingLine1Address(requisitionDocument.getBillingLine1Address());
this.setBillingLine2Address(requisitionDocument.getBillingLine2Address());
this.setBillingCityName(requisitionDocument.getBillingCityName());
this.setBillingStateCode(requisitionDocument.getBillingStateCode());
this.setBillingPostalCode(requisitionDocument.getBillingPostalCode());
this.setBillingCountryCode(requisitionDocument.getBillingCountryCode());
this.setBillingPhoneNumber(requisitionDocument.getBillingPhoneNumber());
this.setBillingEmailAddress(requisitionDocument.getBillingEmailAddress());
this.setReceivingName(requisitionDocument.getReceivingName());
this.setReceivingCityName(requisitionDocument.getReceivingCityName());
this.setReceivingLine1Address(requisitionDocument.getReceivingLine1Address());
this.setReceivingLine2Address(requisitionDocument.getReceivingLine2Address());
this.setReceivingStateCode(requisitionDocument.getReceivingStateCode());
this.setReceivingPostalCode(requisitionDocument.getReceivingPostalCode());
this.setReceivingCountryCode(requisitionDocument.getReceivingCountryCode());
this.setAddressToVendorIndicator(requisitionDocument.getAddressToVendorIndicator());
this.setDeliveryBuildingCode(requisitionDocument.getDeliveryBuildingCode());
this.setDeliveryBuildingRoomNumber(requisitionDocument.getDeliveryBuildingRoomNumber());
this.setDeliveryBuildingName(requisitionDocument.getDeliveryBuildingName());
this.setDeliveryCampusCode(requisitionDocument.getDeliveryCampusCode());
this.setDeliveryCityName(requisitionDocument.getDeliveryCityName());
this.setDeliveryCountryCode(requisitionDocument.getDeliveryCountryCode());
this.setDeliveryInstructionText(requisitionDocument.getDeliveryInstructionText());
this.setDeliveryBuildingLine1Address(requisitionDocument.getDeliveryBuildingLine1Address());
this.setDeliveryBuildingLine2Address(requisitionDocument.getDeliveryBuildingLine2Address());
this.setDeliveryPostalCode(requisitionDocument.getDeliveryPostalCode());
this.setDeliveryRequiredDate(requisitionDocument.getDeliveryRequiredDate());
this.setDeliveryRequiredDateReasonCode(requisitionDocument.getDeliveryRequiredDateReasonCode());
this.setDeliveryStateCode(requisitionDocument.getDeliveryStateCode());
this.setDeliveryToEmailAddress(requisitionDocument.getDeliveryToEmailAddress());
this.setDeliveryToName(requisitionDocument.getDeliveryToName());
this.setDeliveryToPhoneNumber(requisitionDocument.getDeliveryToPhoneNumber());
this.setDeliveryBuildingOtherIndicator(requisitionDocument.isDeliveryBuildingOtherIndicator());
this.setPurchaseOrderBeginDate(requisitionDocument.getPurchaseOrderBeginDate());
this.setPurchaseOrderCostSourceCode(requisitionDocument.getPurchaseOrderCostSourceCode());
this.setPostingYear(requisitionDocument.getPostingYear());
this.setPurchaseOrderEndDate(requisitionDocument.getPurchaseOrderEndDate());
this.setChartOfAccountsCode(requisitionDocument.getChartOfAccountsCode());
this.setDocumentFundingSourceCode(requisitionDocument.getDocumentFundingSourceCode());
this.setInstitutionContactEmailAddress(requisitionDocument.getInstitutionContactEmailAddress());
this.setInstitutionContactName(requisitionDocument.getInstitutionContactName());
this.setInstitutionContactPhoneNumber(requisitionDocument.getInstitutionContactPhoneNumber());
this.setNonInstitutionFundAccountNumber(requisitionDocument.getNonInstitutionFundAccountNumber());
this.setNonInstitutionFundChartOfAccountsCode(requisitionDocument.getNonInstitutionFundChartOfAccountsCode());
this.setNonInstitutionFundOrgChartOfAccountsCode(requisitionDocument.getNonInstitutionFundOrgChartOfAccountsCode());
this.setNonInstitutionFundOrganizationCode(requisitionDocument.getNonInstitutionFundOrganizationCode());
this.setOrganizationCode(requisitionDocument.getOrganizationCode());
this.setRecurringPaymentTypeCode(requisitionDocument.getRecurringPaymentTypeCode());
this.setRequestorPersonEmailAddress(requisitionDocument.getRequestorPersonEmailAddress());
this.setRequestorPersonName(requisitionDocument.getRequestorPersonName());
this.setRequestorPersonPhoneNumber(requisitionDocument.getRequestorPersonPhoneNumber());
this.setRequisitionIdentifier(requisitionDocument.getPurapDocumentIdentifier());
this.setPurchaseOrderTotalLimit(requisitionDocument.getPurchaseOrderTotalLimit());
this.setPurchaseOrderTransmissionMethodCode(requisitionDocument.getPurchaseOrderTransmissionMethodCode());
this.setUseTaxIndicator(requisitionDocument.isUseTaxIndicator());
this.setVendorCityName(requisitionDocument.getVendorCityName());
this.setVendorContractGeneratedIdentifier(requisitionDocument.getVendorContractGeneratedIdentifier());
this.setVendorCountryCode(requisitionDocument.getVendorCountryCode());
this.setVendorCustomerNumber(requisitionDocument.getVendorCustomerNumber());
this.setVendorAttentionName(requisitionDocument.getVendorAttentionName());
this.setVendorDetailAssignedIdentifier(requisitionDocument.getVendorDetailAssignedIdentifier());
this.setVendorFaxNumber(requisitionDocument.getVendorFaxNumber());
this.setVendorHeaderGeneratedIdentifier(requisitionDocument.getVendorHeaderGeneratedIdentifier());
this.setVendorLine1Address(requisitionDocument.getVendorLine1Address());
this.setVendorLine2Address(requisitionDocument.getVendorLine2Address());
this.setVendorAddressInternationalProvinceName(requisitionDocument.getVendorAddressInternationalProvinceName());
this.setVendorName(requisitionDocument.getVendorName());
this.setVendorNoteText(requisitionDocument.getVendorNoteText());
this.setVendorPhoneNumber(requisitionDocument.getVendorPhoneNumber());
this.setVendorPostalCode(requisitionDocument.getVendorPostalCode());
this.setVendorStateCode(requisitionDocument.getVendorStateCode());
this.setVendorRestrictedIndicator(requisitionDocument.getVendorRestrictedIndicator());
this.setJustification(requisitionDocument.getJustification());
// KFSPTS-1458, KFSPTS-16990: Also copy vendorEmailAddress from Requisition to PO
this.setVendorEmailAddress(requisitionDocument.getVendorEmailAddress());
this.setExternalOrganizationB2bSupplierIdentifier(requisitionDocument.getExternalOrganizationB2bSupplierIdentifier());
this.setRequisitionSourceCode(requisitionDocument.getRequisitionSourceCode());
this.setAccountsPayablePurchasingDocumentLinkIdentifier(requisitionDocument.getAccountsPayablePurchasingDocumentLinkIdentifier());
this.setReceivingDocumentRequiredIndicator(requisitionDocument.isReceivingDocumentRequiredIndicator());
this.setPaymentRequestPositiveApprovalIndicator(requisitionDocument.isPaymentRequestPositiveApprovalIndicator());
setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_IN_PROCESS);
this.setAccountDistributionMethod(requisitionDocument.getAccountDistributionMethod());
// Copy items from requisition (which will copy the item's accounts and capital assets)
List<PurchaseOrderItem> items = new ArrayList<>();
for (PurApItem reqItem : ((PurchasingAccountsPayableDocument) requisitionDocument).getItems()) {
RequisitionCapitalAssetItem reqCamsItem = (RequisitionCapitalAssetItem) requisitionDocument.getPurchasingCapitalAssetItemByItemIdentifier(reqItem.getItemIdentifier());
items.add(new PurchaseOrderItem((RequisitionItem) reqItem, this, reqCamsItem));
}
this.setItems(items);
// Copy capital asset information that is directly off the document.
this.setCapitalAssetSystemTypeCode(requisitionDocument.getCapitalAssetSystemTypeCode());
this.setCapitalAssetSystemStateCode(requisitionDocument.getCapitalAssetSystemStateCode());
for (CapitalAssetSystem capitalAssetSystem : requisitionDocument.getPurchasingCapitalAssetSystems()) {
this.getPurchasingCapitalAssetSystems().add(new PurchaseOrderCapitalAssetSystem(capitalAssetSystem));
}
this.fixItemReferences();
// KFSUPGRADE-346/KITI-727
if (ObjectUtils.isNull(getPurapDocumentIdentifier())) {
// need retrieve the next available PO id to save in GL entries (only do if purap id is null which should be on first
// save)
SequenceAccessorService sas = SpringContext.getBean(SequenceAccessorService.class);
Long poSequenceNumber = sas.getNextAvailableSequenceNumber("PO_ID", this.getClass());
setPurapDocumentIdentifier(poSequenceNumber.intValue());
}
// KFSUPGRADE-337/KITI-2414 : checking for duplicate sensitive data types
Set<String> currentSensitiveDataCodes = new HashSet<String>();
if (purchaseOrderSensitiveData != null) {
for (PurchaseOrderSensitiveData sensitiveData : purchaseOrderSensitiveData) {
currentSensitiveDataCodes.add(sensitiveData.getSensitiveDataCode());
}
}
if (requisitionDocument.isSensitive()) {
for (PurchasingItemBase pib : (List<PurchasingItemBase>) requisitionDocument.getItems()) {
CommodityCode cc = pib.getCommodityCode();
if (cc != null && cc.getSensitiveDataCode() != null && currentSensitiveDataCodes.add(cc.getSensitiveDataCode())) {
if (purchaseOrderSensitiveData == null) {
boolean addNewData = true;
purchaseOrderSensitiveData = getPurchaseOrderSensitiveData();
for (PurchaseOrderSensitiveData sensitiveData : purchaseOrderSensitiveData) {
if (!currentSensitiveDataCodes.add(sensitiveData.getSensitiveDataCode())) {
addNewData = false;
}
}
if (addNewData) {
purchaseOrderSensitiveData.add(new PurchaseOrderSensitiveData(getPurapDocumentIdentifier(), getRequisitionIdentifier(), cc.getSensitiveDataCode()));
}
} else {
purchaseOrderSensitiveData.add(new PurchaseOrderSensitiveData(getPurapDocumentIdentifier(), getRequisitionIdentifier(), cc.getSensitiveDataCode()));
}
}
}
}
if (purchaseOrderSensitiveData != null) {
SpringContext.getBean(BusinessObjectService.class).save(purchaseOrderSensitiveData);
}
}
use of org.kuali.kfs.module.purap.businessobject.RequisitionItem 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.module.purap.businessobject.RequisitionItem 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 "";
}
Aggregations