Search in sources :

Example 1 with PaymentRequestAccount

use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount 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 2 with PaymentRequestAccount

use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount 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 3 with PaymentRequestAccount

use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount in project cu-kfs by CU-CommunityApps.

the class CuPurapAccountingServiceImpl method isFiscalOfficersForAllAcctLines.

public boolean isFiscalOfficersForAllAcctLines(PurchasingAccountsPayableDocument document) {
    boolean isFoForAcctLines = true;
    String personId = GlobalVariables.getUserSession().getPrincipalId();
    for (SourceAccountingLine accountingLine : (List<SourceAccountingLine>) document.getSourceAccountingLines()) {
        List<String> fiscalOfficers = new ArrayList<String>();
        Map<String, String> roleQualifier = new HashMap<String, String>();
        // KFSPTS-1273 : this method is final, so can't be overriden by REQ Auth.  This is a fix for REQ existing issue.  a broader solution need more work.
        // the authorizer is called by validation rule and rendertag, so has to do it here.  otherwise the invalid account will be saved.
        boolean isExistingReqAcctline = false;
        String updatedAccountNumber = KFSConstants.EMPTY_STRING;
        if (accountingLine instanceof RequisitionAccount && ((RequisitionAccount) accountingLine).getAccountIdentifier() != null) {
            RequisitionAccount dbAcctLine = (RequisitionAccount) getAccountFromDb((RequisitionAccount) accountingLine, RequisitionAccount.class);
            if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
                updatedAccountNumber = accountingLine.getAccountNumber();
                accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
                isExistingReqAcctline = true;
            }
        }
        if (accountingLine instanceof PurchaseOrderAccount && ((PurchaseOrderAccount) accountingLine).getAccountIdentifier() != null) {
            PurchaseOrderAccount dbAcctLine = (PurchaseOrderAccount) getAccountFromDb((PurchaseOrderAccount) accountingLine, PurchaseOrderAccount.class);
            if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
                updatedAccountNumber = accountingLine.getAccountNumber();
                accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
                isExistingReqAcctline = true;
            }
        }
        if (accountingLine instanceof PaymentRequestAccount && ((PaymentRequestAccount) accountingLine).getAccountIdentifier() != null) {
            PaymentRequestAccount dbAcctLine = (PaymentRequestAccount) getAccountFromDb((PaymentRequestAccount) accountingLine, PaymentRequestAccount.class);
            if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
                updatedAccountNumber = accountingLine.getAccountNumber();
                accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
                isExistingReqAcctline = true;
            }
        }
        roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_NUMBER, document.getDocumentNumber());
        roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
        roleQualifier.put(KfsKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, document.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount().toString());
        roleQualifier.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, accountingLine.getChartOfAccountsCode());
        roleQualifier.put(KfsKimAttributes.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
        fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_KIM_ROLE_NAME, roleQualifier));
        if (!fiscalOfficers.contains(personId)) {
            fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_PRIMARY_DELEGATE_KIM_ROLE_NAME, roleQualifier));
        }
        if (!fiscalOfficers.contains(personId)) {
            fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_SECONDARY_DELEGATE_KIM_ROLE_NAME, roleQualifier));
        }
        if (isExistingReqAcctline) {
            accountingLine.setAccountNumber(updatedAccountNumber);
        }
        if (!fiscalOfficers.contains(personId)) {
            isFoForAcctLines = false;
            break;
        }
    }
    return isFoForAcctLines;
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) PaymentRequestAccount(org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)

Aggregations

PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)3 BigDecimal (java.math.BigDecimal)2 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)2 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)2 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)1 RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1