Search in sources :

Example 6 with RequisitionAccount

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

the class FavoriteAccountLineBuilderTest method testLineBuilderFailureForPreexistingLine.

/*
     * Test that line creation will fail if a matching line already exists.
     */
@Test
public void testLineBuilderFailureForPreexistingLine() throws Exception {
    reqsItem.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    poDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    iwntDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    PurchasingFavoriteAccountLineBuilderForLineItem<RequisitionAccount> reqsBuilder = createBuilderForLineItem(reqsItem, 0, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForDistribution<PurchaseOrderAccount> poBuilder = createBuilderForDistribution(poDoc, poAccounts, new PurchaseOrderAccount());
    PurApFavoriteAccountLineBuilderForIWantDocument iwntBuilder = createBuilderForIWant(iwntDoc);
    // First additions should succeed.
    assertAccountLineAdditionToList(reqsBuilder, testFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(iwntBuilder, testFavoriteAccount, IWantAccount.class);
    // Subsequent creations or additions for the same ID should fail.
    assertUnsuccessfulAccountLineCreation(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(iwntBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(iwntBuilder);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Example 7 with RequisitionAccount

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

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

Example 9 with RequisitionAccount

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

the class CuRequisitionDocument method toCopyFromGateway.

/**
 * toCopyFromGateway
 */
public void toCopyFromGateway() throws WorkflowException, ValidationException {
    // no validation for the KFS copy requisition rules:
    String sourceDocumentHeaderId = getDocumentNumber();
    setNewDocumentHeader();
    getDocumentHeader().setDocumentTemplateNumber(sourceDocumentHeaderId);
    // Clear out existing notes.
    if (getNotes() != null) {
        getNotes().clear();
    }
    addCopyErrorDocumentNote("copied from document " + sourceDocumentHeaderId);
    // --- LedgerPostingDocumentBase:
    setAccountingPeriod(retrieveCurrentAccountingPeriod());
    // --GeneralLedgerPostingDocumentBase:
    getGeneralLedgerPendingEntries().clear();
    // --AccountingDocumentBase:
    copyAccountingLines(false);
    updatePostingYearForAccountingLines(getSourceAccountingLines());
    updatePostingYearForAccountingLines(getTargetAccountingLines());
    // --RequisitionDocument:
    // Clear related views
    this.setAccountsPayablePurchasingDocumentLinkIdentifier(null);
    this.setRelatedViews(null);
    Person currentUser = GlobalVariables.getUserSession().getPerson();
    ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
    this.setPurapDocumentIdentifier(null);
    // Set req status to INPR.
    // for app doc status
    updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
    // Set fields from the user.
    if (ObjectUtils.isNotNull(purapChartOrg)) {
        this.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
        this.setOrganizationCode(purapChartOrg.getOrganizationCode());
    }
    this.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
    boolean activeVendor = true;
    boolean activeContract = true;
    Date today = SpringContext.getBean(DateTimeService.class).getCurrentDate();
    VendorContract vendorContract = new VendorContract();
    vendorContract.setVendorContractGeneratedIdentifier(this.getVendorContractGeneratedIdentifier());
    Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(vendorContract);
    vendorContract = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorContract.class, keys);
    if (!(vendorContract != null && today.after(vendorContract.getVendorContractBeginningDate()) && today.before(vendorContract.getVendorContractEndDate()))) {
        activeContract = false;
    }
    VendorDetail vendorDetail = SpringContext.getBean(VendorService.class).getVendorDetail(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier());
    if (!(vendorDetail != null && vendorDetail.isActiveIndicator())) {
        activeVendor = false;
    }
    // KFSPTS-916 : need vendor address key for business rules and only way to get it is to retrieve the default PO address for the vendor.
    if (vendorDetail != null) {
        VendorAddress vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, "");
        if (vendorAddress != null) {
            super.templateVendorAddress(vendorAddress);
        }
    }
    // B2B - only copy if contract and vendor are both active (throw separate errors to print to screen)
    if (this.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
        if (!activeContract) {
        // --  throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_EXPIRED_CONTRACT);
        }
        if (!activeVendor) {
        // -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_INACTIVE_VENDOR);
        }
    }
    if (!activeVendor) {
        this.setVendorContractGeneratedIdentifier(null);
    }
    if (!activeContract) {
        this.setVendorContractGeneratedIdentifier(null);
    }
    // These fields should not be set in this method; force to be null
    this.setOrganizationAutomaticPurchaseOrderLimit(null);
    this.setPurchaseOrderAutomaticIndicator(false);
    for (Iterator iter = this.getItems().iterator(); iter.hasNext(); ) {
        RequisitionItem item = (RequisitionItem) iter.next();
        item.setPurapDocumentIdentifier(null);
        item.setItemIdentifier(null);
        for (Iterator acctIter = item.getSourceAccountingLines().iterator(); acctIter.hasNext(); ) {
            RequisitionAccount account = (RequisitionAccount) acctIter.next();
            account.setAccountIdentifier(null);
            account.setItemIdentifier(null);
        }
    }
    if (!PurapConstants.RequisitionSources.B2B.equals(this.getRequisitionSourceCode())) {
        SpringContext.getBean(PurapService.class).addBelowLineItems(this);
    }
    this.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(this.getVendorContractGeneratedIdentifier(), this.getChartOfAccountsCode(), this.getOrganizationCode()));
    clearCapitalAssetFields();
    SpringContext.getBean(PurapService.class).clearTax(this, this.isUseTaxIndicator());
    this.refreshNonUpdateableReferences();
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) Date(java.util.Date) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurapService(org.kuali.kfs.module.purap.document.service.PurapService) ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) FinancialSystemUserService(org.kuali.kfs.sys.service.FinancialSystemUserService) Iterator(java.util.Iterator) Person(org.kuali.rice.kim.api.identity.Person) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService) Map(java.util.Map) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Aggregations

RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)9 PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)7 Test (org.junit.Test)6 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)4 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)1 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)1 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)1 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)1 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)1 ChartOrgHolder (org.kuali.kfs.sys.businessobject.ChartOrgHolder)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 FinancialSystemUserService (org.kuali.kfs.sys.service.FinancialSystemUserService)1