@ConfigureContext(session = appleton, shouldCommitTransactions = true) public void testDeleteSummaryAccounts_CreditMemo() { PurapAccountingServiceFixture fixture = PurapAccountingServiceFixture.CREDIT_MEMO_ONE_ACCOUNT; VendorCreditMemoDocument vcm = fixture.generateVendorCreditMemoDocument_OneItem(); List<SummaryAccount> summaryAccounts = purapAccountingService.generateSummaryAccounts(vcm); assertNotNull(summaryAccounts); purapAccountingService.deleteSummaryAccounts( vcm.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT); assertNull( purapAccountingService.getAccountsPayableSummaryAccounts( vcm.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT)); }
/** * Clears out fields of the init tab. * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @throws Exception * @return An ActionForward */ public ActionForward clearInitFields( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { VendorCreditMemoForm cmForm = (VendorCreditMemoForm) form; VendorCreditMemoDocument creditMemoDocument = (VendorCreditMemoDocument) cmForm.getDocument(); creditMemoDocument.clearInitFields(); return super.refresh(mapping, form, request, response); }
/** * Set CAB line item information from PurAp PaymentRequestItem or CreditMemoItem. * * @param purchasingAccountsPayableItemAsset * @param docTypeCode */ public void setAccountsPayableItemsFromPurAp( PurchasingAccountsPayableItemAsset purchasingAccountsPayableItemAsset, String docTypeCode) { Map<String, Object> pKeys = new HashMap<String, Object>(); pKeys.put( PurapPropertyConstants.ITEM_IDENTIFIER, purchasingAccountsPayableItemAsset.getAccountsPayableLineItemIdentifier()); // Access PurAp data based on item type(PREQ or CM). if (CabConstants.PREQ.equalsIgnoreCase(docTypeCode)) { // for PREQ document PaymentRequestItem item = (PaymentRequestItem) businessObjectService.findByPrimaryKey(PaymentRequestItem.class, pKeys); if (ObjectUtils.isNull(item)) { throw new PurApDocumentUnavailableException( "PaymentRequestItem with id = " + purchasingAccountsPayableItemAsset.getAccountsPayableLineItemIdentifier() + " doesn't exist in table."); } purchasingAccountsPayableItemAsset.setItemLineNumber(item.getItemLineNumber()); if (item.getItemType() != null) { purchasingAccountsPayableItemAsset.setAdditionalChargeNonTradeInIndicator( item.getItemType().isAdditionalChargeIndicator() & !CabConstants.TRADE_IN_TYPE_CODE.equalsIgnoreCase(item.getItemTypeCode())); purchasingAccountsPayableItemAsset.setTradeInAllowance( item.getItemType().isAdditionalChargeIndicator() & CabConstants.TRADE_IN_TYPE_CODE.equalsIgnoreCase(item.getItemTypeCode())); purchasingAccountsPayableItemAsset.setItemTypeCode(item.getItemTypeCode()); } purchasingAccountsPayableItemAsset.setItemAssignedToTradeInIndicator( item.getItemAssignedToTradeInIndicator()); // PurchaseOrderItemIdentifier will be used when populate PurAp asset data PurchaseOrderItem poi = item.getPurchaseOrderItem(); if (poi != null) { purchasingAccountsPayableItemAsset.setPurchaseOrderItemIdentifier(poi.getItemIdentifier()); } } else { // for CM document CreditMemoItem item = (CreditMemoItem) businessObjectService.findByPrimaryKey(CreditMemoItem.class, pKeys); if (ObjectUtils.isNull(item)) { throw new PurApDocumentUnavailableException( "CreditMemoItem with id = " + purchasingAccountsPayableItemAsset.getAccountsPayableLineItemIdentifier() + " doesn't exist in table."); } purchasingAccountsPayableItemAsset.setItemLineNumber(item.getItemLineNumber()); if (item.getItemType() != null) { purchasingAccountsPayableItemAsset.setAdditionalChargeNonTradeInIndicator( item.getItemType().isAdditionalChargeIndicator() & !CabConstants.TRADE_IN_TYPE_CODE.equalsIgnoreCase(item.getItemTypeCode())); purchasingAccountsPayableItemAsset.setTradeInAllowance( item.getItemType().isAdditionalChargeIndicator() & CabConstants.TRADE_IN_TYPE_CODE.equalsIgnoreCase(item.getItemTypeCode())); purchasingAccountsPayableItemAsset.setItemTypeCode(item.getItemTypeCode()); } purchasingAccountsPayableItemAsset.setItemAssignedToTradeInIndicator( item.getItemAssignedToTradeInIndicator()); // PurchaseOrderItemIdentifier will be used when populate PurAp asset data PurchaseOrderItem poi = getPurchaseOrderItemfromCreditMemoItem(item); if (poi != null) { purchasingAccountsPayableItemAsset.setPurchaseOrderItemIdentifier(poi.getItemIdentifier()); } // if PREQ Credit Memo document VendorCreditMemoDocument cmDoc = (VendorCreditMemoDocument) item.getPurapDocument(); if (ObjectUtils.isNotNull(cmDoc) && cmDoc.isSourceDocumentPaymentRequest()) { purchasingAccountsPayableItemAsset.setPaymentRequestIdentifier( cmDoc.getPaymentRequestIdentifier()); } } }
/** * Handles continue request. This request comes from the initial screen which gives indicates * whether the type is payment request, purchase order, or vendor. Based on that, the credit memo * is initially populated and the remaining tabs shown. * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @throws Exception * @return An ActionForward */ public ActionForward continueCreditMemo( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { VendorCreditMemoForm cmForm = (VendorCreditMemoForm) form; VendorCreditMemoDocument creditMemoDocument = (VendorCreditMemoDocument) cmForm.getDocument(); String defaultDistributionMethod = SpringContext.getBean(ParameterService.class) .getParameterValueAsString( PurapConstants.PURAP_NAMESPACE, "Document", PurapParameterConstants.DISTRIBUTION_METHOD_FOR_ACCOUNTING_LINES); String preqId = request.getParameter("document.paymentRequestIdentifier"); if (!StringUtils.isEmpty(preqId)) { // get the po document and get the account distribution method code.... String distributionCode = getDistributionMethodFromPReq(preqId); if (ObjectUtils.isNotNull(distributionCode)) { defaultDistributionMethod = distributionCode; } } else { String poId = request.getParameter("document.purchaseOrderIdentifier"); if (!StringUtils.isEmpty(poId)) { // get the po document and get the account distribution method code.... String distributionCode = getDistributionMethodFromPO(poId); if (ObjectUtils.isNotNull(distributionCode)) { defaultDistributionMethod = distributionCode; } } } // set the account distribution method code on the document. creditMemoDocument.setAccountDistributionMethod(defaultDistributionMethod); boolean rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AttributedContinuePurapEvent(creditMemoDocument)); if (!rulePassed) { return mapping.findForward(KFSConstants.MAPPING_BASIC); } if (creditMemoDocument.isSourceDocumentPaymentRequest()) { PaymentRequestDocument preq = SpringContext.getBean(PaymentRequestService.class) .getPaymentRequestById(creditMemoDocument.getPaymentRequestIdentifier()); if (ObjectUtils.isNotNull(preq)) { // TODO figure out a more straightforward way to do this. ailish put this in so the link id // would be set and the perm check would work creditMemoDocument.setAccountsPayablePurchasingDocumentLinkIdentifier( preq.getAccountsPayablePurchasingDocumentLinkIdentifier()); if (!SpringContext.getBean(DocumentHelperService.class) .getDocumentAuthorizer(creditMemoDocument) .isAuthorizedByTemplate( creditMemoDocument, KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, GlobalVariables.getUserSession().getPrincipalId())) { throw buildAuthorizationException("initiate document", creditMemoDocument); } } } else if (creditMemoDocument.isSourceDocumentPurchaseOrder()) { PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class) .getCurrentPurchaseOrder(creditMemoDocument.getPurchaseOrderIdentifier()); if (ObjectUtils.isNotNull(po)) { // TODO figure out a more straightforward way to do this. ailish put this in so the link id // would be set and the perm check would work creditMemoDocument.setAccountsPayablePurchasingDocumentLinkIdentifier( po.getAccountsPayablePurchasingDocumentLinkIdentifier()); if (!SpringContext.getBean(DocumentHelperService.class) .getDocumentAuthorizer(creditMemoDocument) .isAuthorizedByTemplate( creditMemoDocument, KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, GlobalVariables.getUserSession().getPrincipalId())) { throw buildAuthorizationException("initiate document", creditMemoDocument); } } } else { // do nothing for credit memos against a vendor; no link to PO means no need to hide doc based // on sensitive data } // preform duplicate check which will forward to a question prompt if one is found ActionForward forward = performDuplicateCreditMemoCheck(mapping, form, request, response, creditMemoDocument); if (forward != null) { return forward; } // perform validation of init tab SpringContext.getBean(CreditMemoService.class).populateAndSaveCreditMemo(creditMemoDocument); // sort below the line (doesn't really need to be done on CM, but will help if we ever bring btl // from other docs) SpringContext.getBean(PurapService.class).sortBelowTheLine(creditMemoDocument); // update the counts on the form cmForm.updateItemCounts(); // if source is (PREQ or PO) and the PO status is CLOSED, automatically reopen the PO PurchaseOrderDocument po = creditMemoDocument.getPurchaseOrderDocument(); if ((creditMemoDocument.isSourceDocumentPaymentRequest() || creditMemoDocument.isSourceDocumentPurchaseOrder()) && PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals( po.getApplicationDocumentStatus())) { initiateReopenPurchaseOrder(po, cmForm.getAnnotation()); } // update the accounts amounts to zero. The recalculate will calculate the totals... List<PurApItem> items = creditMemoDocument.getItems(); for (PurApItem item : items) { for (PurApAccountingLine accountLine : item.getSourceAccountingLines()) { accountLine.setAmount(KualiDecimal.ZERO); } } return mapping.findForward(KFSConstants.MAPPING_BASIC); }