use of org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument in project cu-kfs by CU-CommunityApps.
the class PurchasingCommodityCodeValidation method shouldCheckCommodityCodeIsActive.
/**
* This method analyzes the document status and determines if the commodity codes associated with this item should be verified as active.
* The current implementation only checks that a commodity code is active if the document associated is in either INITIATED or SAVED status.
* For all other statuses the document may be in, the commodity code will not be checked for active status and the method will simply return
* true unconditionally.
*
* @param item
* @return
*/
private boolean shouldCheckCommodityCodeIsActive(PurApItem item) {
if (ObjectUtils.isNotNull(item.getPurapDocument())) {
String docNum = item.getPurapDocument().getDocumentNumber();
PurchasingAccountsPayableDocument purapDoc = item.getPurapDocument();
// Ran into issues with workflow doc not being populated in doc header for some PURAP docs, so needed to add check and retrieval.
FinancialSystemDocumentHeader docHdr = (FinancialSystemDocumentHeader) purapDoc.getDocumentHeader();
WorkflowDocument kwd = null;
kwd = WorkflowDocumentFactory.loadDocument(GlobalVariables.getUserSession().getPrincipalId(), docNum);
docHdr.setWorkflowDocument(kwd);
// Only check for active commodity codes if the doc is in initiated or saved status.
if (ObjectUtils.isNull(kwd)) {
kwd = docHdr.getWorkflowDocument();
}
if (!(kwd.isInitiated() || kwd.isSaved())) {
return false;
}
}
return true;
}
use of org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method doDistribution.
/**
* Distribute accounting line(s) to the item(s). Does not distribute the accounting line(s) to an item if there are already
* accounting lines associated with that item, if the item is a below-the-line item and has no unit cost, or if the item is
* inactive. Distribute commodity code to the item(s). Does not distribute the commodity code to an item if the item is not
* above the line item, is inactive or if the commodity code fails the validation (i.e. inactive commodity code or non existence
* commodity code).
*
* @param mapping An ActionMapping
* @param form An ActionForm
* @param request The HttpServletRequest
* @param response The HttpServletResponse
* @return An ActionForward
* @throws Exception
*/
public ActionForward doDistribution(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
boolean needToDistributeCommodityCode = false;
if (StringUtils.isNotBlank(purchasingForm.getDistributePurchasingCommodityCode())) {
// Do the logic for distributing purchasing commodity code to all the items.
needToDistributeCommodityCode = true;
}
boolean needToDistributeAccount = false;
List<PurApAccountingLine> distributionsourceAccountingLines = purchasingForm.getAccountDistributionsourceAccountingLines();
if (distributionsourceAccountingLines.size() > 0) {
needToDistributeAccount = true;
}
if (needToDistributeAccount || needToDistributeCommodityCode) {
PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) purchasingForm.getDocument();
boolean institutionNeedsDistributeAccountValidation = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.VALIDATE_ACCOUNT_DISTRIBUTION_IND);
boolean foundAccountDistributionError = false;
boolean foundCommodityCodeDistributionError = false;
boolean performedAccountDistribution = false;
boolean performedCommodityCodeDistribution = false;
// do check for account percents only if distribution method not equal to "P"
if (!PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(purApDocument.getAccountDistributionMethod())) {
// the total percentage in the distribute account list does not equal 100 % then we should display error
if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && purchasingForm.getTotalPercentageOfAccountDistributionsourceAccountingLines().compareTo(new BigDecimal(100)) != 0) {
GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.ERROR_DISTRIBUTE_ACCOUNTS_NOT_100_PERCENT);
foundAccountDistributionError = true;
}
}
// there is a validation error in the accounts to distribute then we should display an error
if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && (validateDistributeAccounts(purchasingForm.getDocument(), distributionsourceAccountingLines) == false)) {
foundAccountDistributionError = true;
}
for (PurApItem item : ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems()) {
boolean itemIsActive = true;
if (item instanceof PurchaseOrderItem) {
// if item is PO item... only validate active items
itemIsActive = ((PurchaseOrderItem) item).isItemActiveIndicator();
}
if (needToDistributeCommodityCode) {
// only the above the line items need the commodity code.
if (item.getItemType().isLineItemIndicator() && StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
// Ideally we should invoke rules to check whether the commodity code is valid (active, not restricted,
// not missing, etc), probably somewhere here or invoke the rule class from here.
boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCommodityCodesForDistributionEvent("", purchasingForm.getDocument(), purchasingForm.getDistributePurchasingCommodityCode()));
if (rulePassed) {
((PurchasingItemBase) item).setPurchasingCommodityCode(purchasingForm.getDistributePurchasingCommodityCode());
performedCommodityCodeDistribution = true;
} else {
foundCommodityCodeDistributionError = true;
}
} else if (item.getItemType().isLineItemIndicator() && !StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
// could not apply to line, as it wasn't blank
foundCommodityCodeDistributionError = true;
}
}
if (needToDistributeAccount && !foundAccountDistributionError) {
BigDecimal zero = new BigDecimal(0);
// We should be distributing accounting lines to above the line items all the time;
// but only to the below the line items when there is a unit cost.
boolean unitCostNotZeroForBelowLineItems = item.getItemType().isLineItemIndicator() ? true : item.getItemUnitPrice() != null && zero.compareTo(item.getItemUnitPrice()) < 0;
Document document = ((PurchasingFormBase) form).getDocument();
Class clazz = document instanceof PurchaseOrderAmendmentDocument ? PurchaseOrderDocument.class : document.getClass();
List<String> typesNotAllowingEdit = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(clazz, PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
boolean itemOnExcludeList = (typesNotAllowingEdit == null) ? false : typesNotAllowingEdit.contains(item.getItemTypeCode());
if (item.getSourceAccountingLines().size() == 0 && unitCostNotZeroForBelowLineItems && !itemOnExcludeList && itemIsActive) {
for (PurApAccountingLine purApAccountingLine : distributionsourceAccountingLines) {
item.getSourceAccountingLines().add((PurApAccountingLine) ObjectUtils.deepCopy(purApAccountingLine));
}
performedAccountDistribution = true;
}
}
}
if ((needToDistributeCommodityCode && performedCommodityCodeDistribution && !foundCommodityCodeDistributionError) || (needToDistributeAccount && performedAccountDistribution && !foundAccountDistributionError)) {
if (needToDistributeCommodityCode && !foundCommodityCodeDistributionError && performedCommodityCodeDistribution) {
KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PUR_COMMODITY_CODE_DISTRIBUTED);
purchasingForm.setDistributePurchasingCommodityCode(null);
}
if (needToDistributeAccount && !foundAccountDistributionError && performedAccountDistribution) {
KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PURAP_GENERAL_ACCOUNTS_DISTRIBUTED);
distributionsourceAccountingLines.clear();
}
purchasingForm.setHideDistributeAccounts(true);
}
if ((needToDistributeAccount && !performedAccountDistribution && foundAccountDistributionError)) {
GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "account numbers");
}
if (needToDistributeCommodityCode && !performedCommodityCodeDistribution && foundCommodityCodeDistributionError) {
GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_PURCHASING_COMMODITY_CODE, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "commodity codes");
}
} else {
GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ACCOUNTS_TO_DISTRIBUTE);
}
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument in project cu-kfs by CU-CommunityApps.
the class CuPurchaseOrderForm method populateItemAccountingLines.
// end KFSUPGRADE-411
/**
* Overridden to properly increment the local "itemCount" loop counter when processing POA documents,
* but otherwise has the same code as in the superclass.
*
* @see org.kuali.kfs.module.purap.document.web.struts.PurchasingAccountsPayableFormBase#populateItemAccountingLines(java.util.Map)
*/
@SuppressWarnings("rawtypes")
@Override
protected void populateItemAccountingLines(Map parameterMap) {
if (!(getDocument() instanceof PurchaseOrderAmendmentDocument)) {
super.populateItemAccountingLines(parameterMap);
return;
}
int itemCount = 0;
for (PurApItem item : ((PurchasingAccountsPayableDocument) getDocument()).getItems()) {
populateAccountingLine(item.getNewSourceLine(), KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.ITEM + "[" + itemCount + "]." + KFSPropertyConstants.NEW_SOURCE_LINE, parameterMap);
int sourceLineCount = 0;
for (PurApAccountingLine purApLine : item.getSourceAccountingLines()) {
populateAccountingLine(purApLine, KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.ITEM + "[" + itemCount + "]." + KFSPropertyConstants.SOURCE_ACCOUNTING_LINE + "[" + sourceLineCount + "]", parameterMap);
sourceLineCount += 1;
}
itemCount += 1;
}
}
use of org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument in project cu-kfs by CU-CommunityApps.
the class CuRelatedDocumentDerivedRoleTypeServiceImpl method getRoleMembersFromDerivedRole.
@Override
public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName, Map<String, String> qualification) {
List<RoleMembership> members = new ArrayList<RoleMembership>();
if (qualification != null && !qualification.isEmpty()) {
if (SOURCE_DOCUMENT_ROUTER_ROLE_NAME.equals(roleName)) {
try {
PurchasingAccountsPayableDocument document = (PurchasingAccountsPayableDocument) getDocumentService().getByDocumentHeaderId(qualification.get(KFSPropertyConstants.DOCUMENT_NUMBER));
if (document != null) {
PurchasingAccountsPayableDocument sourceDocument = document.getPurApSourceDocumentIfPossible();
if (sourceDocument != null && StringUtils.isNotBlank(sourceDocument.getDocumentHeader().getWorkflowDocument().getRoutedByPrincipalId())) {
Map<String, String> roleQualifier = new HashMap<String, String>(1);
roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_NUMBER, sourceDocument.getDocumentNumber());
Builder roleMember = RoleMembership.Builder.create(null, null, sourceDocument.getDocumentHeader().getWorkflowDocument().getRoutedByPrincipalId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, roleQualifier);
members.add(roleMember.build());
}
}
} catch (WorkflowException e) {
throw new RuntimeException("Unable to load document in getPrincipalIdsFromApplicationRole", e);
}
} else if (SENSITIVE_RELATED_DOCUMENT_INITATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) {
// KFSUPGRADE-346
if (!qualification.containsKey(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER)) {
Map<String, String> tempQualification = new HashMap<String, String>(1);
tempQualification.put(KFSPropertyConstants.DOCUMENT_NUMBER, qualification.get("documentNumber"));
for (String principalId : getRoleService().getRoleMemberPrincipalIds(KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE, RouteLogDerivedRoleTypeServiceImpl.INITIATOR_OR_REVIEWER_ROLE_NAME, tempQualification)) {
Builder roleMember = RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, tempQualification);
members.add(roleMember.build());
}
} else {
for (String documentId : getPurapService().getRelatedDocumentIds(new Integer(qualification.get(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER)))) {
Map<String, String> tempQualification = new HashMap<String, String>(1);
tempQualification.put(KFSPropertyConstants.DOCUMENT_NUMBER, documentId);
for (String principalId : getRoleService().getRoleMemberPrincipalIds(KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE, RouteLogDerivedRoleTypeServiceImpl.INITIATOR_OR_REVIEWER_ROLE_NAME, tempQualification)) {
Builder roleMember = RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, tempQualification);
members.add(roleMember.build());
}
}
}
}
}
return members;
}
use of org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument in project cu-kfs by CU-CommunityApps.
the class CuPurchaseOrderProcessVendorValidation method validate.
@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.
// KFSUPGRADE-266 remove kfsmi-8690/kfscntrb-929
// 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;
}
Aggregations