Search in sources :

Example 11 with PurchaseOrderAccount

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

the class FavoriteAccountLineBuilderTest method testCreateAndAddFavoriteAccountLinesForLineItems.

/*
     * Test creating favorite accounting lines for use with line items.
     */
@Test
public void testCreateAndAddFavoriteAccountLinesForLineItems() throws Exception {
    reqsItem.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    poItem.setFavoriteAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    PurchasingFavoriteAccountLineBuilderForLineItem<RequisitionAccount> reqsBuilder = createBuilderForLineItem(reqsItem, 0, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForLineItem<PurchaseOrderAccount> poBuilder = createBuilderForLineItem(poItem, 0, new PurchaseOrderAccount());
    assertAccountLineCreation(reqsBuilder, testFavoriteAccount, RequisitionAccount.class);
    assertAccountLineCreation(poBuilder, testAltFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(reqsBuilder, testFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testAltFavoriteAccount, PurchaseOrderAccount.class);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Example 12 with PurchaseOrderAccount

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

PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)12 RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Iterator (java.util.Iterator)5 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)5 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)4 HashMap (java.util.HashMap)4 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)4 List (java.util.List)3 Map (java.util.Map)3 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)3 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1 SequenceAccessorService (org.kuali.kfs.krad.service.SequenceAccessorService)1 CreditMemoItem (org.kuali.kfs.module.purap.businessobject.CreditMemoItem)1 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)1 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)1