Search in sources :

Example 21 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImplTest method testRejectDocumentCreationInvalidData.

public void testRejectDocumentCreationInvalidData() throws Exception {
    String rejectFile = "reject.xml";
    RequisitionDocument reqDoc = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition();
    Integer reqId = reqDoc.getPurapDocumentIdentifier();
    PurchaseOrderDocument poDocument = createPODoc(reqId);
    poDocument.setVendorShippingPaymentTermsCode("AL");
    poDocument.setVendorPaymentTermsCode("00N30");
    poDocument.refreshNonUpdateableReferences();
    AccountingDocumentTestUtils.saveDocument(poDocument, documentService);
    String poNumber = String.valueOf(poDocument.getPurapDocumentIdentifier());
    String vendorDUNS = "133251074";
    String xmlChunk = CuElectronicInvoiceHelperServiceFixture.getCXMLForRejectDocCreation(vendorDUNS, poNumber);
    writeXMLFile(xmlChunk, rejectFile);
    ElectronicInvoiceLoad load = cuElectronicInvoiceHelperService.loadElectronicInvoices();
    assertTrue(load.containsRejects());
    ElectronicInvoiceRejectDocument rejectDoc = (ElectronicInvoiceRejectDocument) load.getRejectDocuments().get(0);
    assertNotNull(rejectDoc);
    assertEquals(rejectDoc.getInvoiceFileName(), rejectFile);
    assertEquals(1, rejectDoc.getInvoiceRejectReasons().size());
    File rejectedFileInRejectDir = new File(electronicInvoiceInputFileType.getDirectoryPath() + File.separator + "reject" + File.separator + rejectFile);
    assertTrue(rejectedFileInRejectDir.exists());
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) ElectronicInvoiceLoad(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad) ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) File(java.io.File)

Example 22 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument 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());
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PaymentRequestAccount(org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount) BigDecimal(java.math.BigDecimal)

Example 23 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument 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());
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PaymentRequestAccount(org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount) BigDecimal(java.math.BigDecimal)

Example 24 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class PurchaseOrderDocumentPresentationController method canRoute.

@Override
public boolean canRoute(Document document) {
    PurchaseOrderDocument poDocument = (PurchaseOrderDocument) document;
    String statusCode = poDocument.getApplicationDocumentStatus();
    if (StringUtils.equals(statusCode, PurchaseOrderStatuses.APPDOC_WAITING_FOR_DEPARTMENT) || StringUtils.equals(statusCode, PurchaseOrderStatuses.APPDOC_WAITING_FOR_VENDOR) || StringUtils.equals(statusCode, PurchaseOrderStatuses.APPDOC_QUOTE)) {
        return false;
    }
    if (poDocument.isPendingSplit()) {
        return false;
    }
    return super.canRoute(document);
}
Also used : PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Example 25 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method changeSystem.

public ActionForward changeSystem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form;
    PurchasingDocument document = (PurchasingDocument) purchasingForm.getDocument();
    Object question = request.getParameter(PurapConstants.QUESTION_INDEX);
    Object buttonClicked = request.getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
    if (question == null) {
        String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.PURCHASING_QUESTION_CONFIRM_CHANGE_SYSTEM);
        return this.performQuestionWithoutInput(mapping, form, request, response, PurapConstants.CapitalAssetTabStrings.SYSTEM_SWITCHING_QUESTION, questionText, KFSConstants.CONFIRMATION_QUESTION, KFSConstants.ROUTE_METHOD, "0");
    } else if (ConfirmationQuestion.YES.equals(buttonClicked)) {
        // Add a note if system change occurs when the document is a PO that is being amended.
        if ((document instanceof PurchaseOrderDocument) && (PurapConstants.PurchaseOrderStatuses.APPDOC_CHANGE_IN_PROCESS.equals(document.getApplicationDocumentStatus()))) {
            Integer poId = document.getPurapDocumentIdentifier();
            PurchaseOrderDocument currentPO = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(poId);
            String oldSystemTypeCode = "";
            if (currentPO != null) {
                oldSystemTypeCode = currentPO.getCapitalAssetSystemTypeCode();
            }
            CapitalAssetSystemType oldSystemType = new CapitalAssetSystemType();
            oldSystemType.setCapitalAssetSystemTypeCode(oldSystemTypeCode);
            Map<String, String> keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(oldSystemType);
            oldSystemType = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(CapitalAssetSystemType.class, keys);
            String description = ((oldSystemType == null) ? "(NONE)" : oldSystemType.getCapitalAssetSystemTypeDescription());
            if (document instanceof PurchaseOrderAmendmentDocument) {
                String noteText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_AMEND_MESSAGE_CHANGE_SYSTEM_TYPE);
                noteText = StringUtils.replace(noteText, "{0}", description);
                try {
                    Note systemTypeChangeNote = getDocumentService().createNoteFromDocument(document, noteText);
                    purchasingForm.setNewNote(systemTypeChangeNote);
                    insertBONote(mapping, purchasingForm, request, response);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        if (form instanceof RequisitionForm) {
            ((RequisitionForm) form).resetNewPurchasingCapitalAssetLocationLine();
        }
        // remove capital assets from db
        if (document instanceof PurchaseOrderAmendmentDocument) {
            for (PurchasingCapitalAssetItem assetItem : document.getPurchasingCapitalAssetItems()) {
                SpringContext.getBean(BusinessObjectService.class).delete((PersistableBusinessObject) assetItem);
            }
        }
        document.clearCapitalAssetFields();
        SpringContext.getBean(PurapService.class).saveDocumentNoValidation(document);
        KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PURCHASING_MESSAGE_SYSTEM_CHANGED);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) CapitalAssetSystemType(org.kuali.kfs.module.purap.businessobject.CapitalAssetSystemType) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ItemParserException(org.kuali.kfs.module.purap.exception.ItemParserException) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) Note(org.kuali.kfs.krad.bo.Note) PurchasingCapitalAssetItem(org.kuali.kfs.module.purap.businessobject.PurchasingCapitalAssetItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) ConfigurationService(org.kuali.rice.core.api.config.property.ConfigurationService) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Aggregations

PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)52 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)17 DocumentService (org.kuali.kfs.krad.service.DocumentService)16 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)14 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)9 ArrayList (java.util.ArrayList)6 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)6 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)5 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)4 MessageMap (org.kuali.kfs.krad.util.MessageMap)4 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)4 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)4 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 Iterator (java.util.Iterator)3