Search in sources :

Example 1 with CuPurchaseOrderAmendmentDocument

use of edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument in project cu-kfs by CU-CommunityApps.

the class CuReceivingServiceImpl method spawnPoAmendmentForUnorderedItems.

protected void spawnPoAmendmentForUnorderedItems(ReceivingDocument receivingDocument, PurchaseOrderDocument po) {
    // if receiving line document
    if (receivingDocument instanceof LineItemReceivingDocument) {
        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) receivingDocument;
        // if a new item has been added spawn a purchase order amendment
        if (hasNewUnorderedItem((LineItemReceivingDocument) receivingDocument)) {
            String newSessionUserId = KFSConstants.SYSTEM_USER;
            try {
                LogicContainer logicToRun = new LogicContainer() {

                    @Override
                    public Object runLogic(Object[] objects) throws Exception {
                        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) objects[0];
                        String poDocNumber = (String) objects[1];
                        // create a PO amendment
                        PurchaseOrderAmendmentDocument amendmentPo = (PurchaseOrderAmendmentDocument) purchaseOrderService.createAndSavePotentialChangeDocument(poDocNumber, PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT, PurchaseOrderStatuses.APPDOC_AMENDMENT);
                        // KFSPTS-1769, KFSUPGRADE-339
                        ((CuPurchaseOrderAmendmentDocument) amendmentPo).setSpawnPoa(true);
                        // add new lines to amendement
                        addUnorderedItemsToAmendment(amendmentPo, rlDoc);
                        // route amendment
                        documentService.routeDocument(amendmentPo, null, null);
                        // add note to amendment po document
                        String note = "Purchase Order Amendment " + amendmentPo.getPurapDocumentIdentifier() + " (document id " + amendmentPo.getDocumentNumber() + ") created for new unordered line items due to Receiving (document id " + rlDoc.getDocumentNumber() + ")";
                        Note noteObj = documentService.createNoteFromDocument(amendmentPo, note);
                        amendmentPo.addNote(noteObj);
                        noteService.save(noteObj);
                        return null;
                    }
                };
                purapService.performLogicWithFakedUserSession(newSessionUserId, logicToRun, new Object[] { rlDoc, po.getDocumentNumber() });
            } catch (WorkflowException e) {
                String errorMsg = "Workflow Exception caught: " + e.getLocalizedMessage();
                throw new RuntimeException(errorMsg, e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) LineItemReceivingDocument(org.kuali.kfs.module.purap.document.LineItemReceivingDocument) Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) LogicContainer(org.kuali.kfs.module.purap.document.service.LogicContainer) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 2 with CuPurchaseOrderAmendmentDocument

use of edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderAmendmentHasUnitCostAndValidPercentage method validate.

public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
    List<PurApItem> items = purapDocument.getItems();
    for (PurApItem item : items) {
        if (item.isConsideredEntered()) {
            BigDecimal unitPrice = ((PurchaseOrderItem) item).getItemUnitPrice();
            List<PurApAccountingLine> lines = item.getSourceAccountingLines();
            // check if unit price is zero or null and item has accounts associated with it
            if ((unitPrice == null || (unitPrice.compareTo(BigDecimal.ZERO) == 0)) && lines.size() > 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERRORS, CUKFSKeyConstants.ERROR_NO_UNIT_COST_WITH_ACCOUNTS, item.getItemIdentifierString());
                valid = false;
            }
            if ((unitPrice != null && unitPrice.compareTo(BigDecimal.ZERO) != 0) && lines.size() == 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERRORS, CUKFSKeyConstants.ERROR_UNIT_COST_W_O_ACCOUNT, item.getItemIdentifierString());
                valid = false;
            }
            BigDecimal totalPercent = new BigDecimal(0);
            for (PurApAccountingLine accountingLine : lines) {
                totalPercent = totalPercent.add(accountingLine.getAccountLinePercent());
                // if an account distribution is zero percent, invalid
                if (accountingLine.getAccountLinePercent().compareTo(BigDecimal.ZERO) == 0) {
                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, CUKFSKeyConstants.ERROR_NO_ZERO_PERCENT_ACCOUNT_LINES_ALLOWED, item.getItemIdentifierString());
                    valid = false;
                }
            }
            // if total percent is not 100, error
            if (totalPercent.compareTo(new BigDecimal(100)) != 0) {
                // KFSPTS-1769.  if it is spawnpoa for unordered item, then don't check
                if (!((purapDocument instanceof CuPurchaseOrderAmendmentDocument) && ((CuPurchaseOrderAmendmentDocument) purapDocument).isSpawnPoa())) {
                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_TOTAL, item.getItemIdentifierString());
                    valid = false;
                }
            }
        }
    }
    return valid;
}
Also used : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) BigDecimal(java.math.BigDecimal)

Aggregations

CuPurchaseOrderAmendmentDocument (edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument)2 BigDecimal (java.math.BigDecimal)1 Note (org.kuali.kfs.krad.bo.Note)1 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)1 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)1 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)1 LineItemReceivingDocument (org.kuali.kfs.module.purap.document.LineItemReceivingDocument)1 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)1 PurchasingAccountsPayableDocument (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)1 LogicContainer (org.kuali.kfs.module.purap.document.service.LogicContainer)1 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)1