Search in sources :

Example 6 with RequisitionItem

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

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

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

the class FavoriteAccountLineBuilderTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
    userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
    reqsAccounts = new ArrayList<PurApAccountingLine>();
    poAccounts = new ArrayList<PurApAccountingLine>();
    reqsItem = new RequisitionItem();
    poItem = new PurchaseOrderItem();
    reqsDoc = getMockedDocument(CuRequisitionDocument.class);
    poDoc = getMockedDocument(PurchaseOrderDocument.class);
    iwntDoc = getMockedDocument(IWantDocument.class);
    iwntDoc.setAccounts(new ArrayList<IWantAccount>());
    // Favorite Account with only some fields populated.
    testFavoriteAccount = new FavoriteAccount();
    testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
    testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
    testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
    testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
    // Favorite Account with all fields populated (except reference objects or object ID or version number).
    testAltFavoriteAccount = new FavoriteAccount();
    testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
    testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
    testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
    testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
    testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
    testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
    GlobalVariables.setMessageMap(new MessageMap());
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) UserProcurementProfileValidationServiceImpl(edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) BeforeClass(org.junit.BeforeClass)

Example 9 with RequisitionItem

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

the class CuB2BShoppingServiceImplTest method testCreateRequisitionItem.

public void testCreateRequisitionItem() {
    RequisitionItem requisitionItem = b2bShoppingService.createRequisitionItem(B2BShoppingCartItemFixture.B2B_ITEM_USING_VENDOR_ID.createB2BShoppingCartItem(), 0, "80141605");
    assertNotNull(requisitionItem);
    assertTrue(requisitionItem.isControlled());
    assertTrue(requisitionItem.isRadioactiveMinor());
    assertTrue(requisitionItem.isGreen());
    assertTrue(requisitionItem.isHazardous());
    assertTrue(requisitionItem.isSelectAgent());
    assertTrue(requisitionItem.isRadioactive());
    assertTrue(requisitionItem.isToxin());
    assertTrue(requisitionItem.isRecycled());
    assertTrue(requisitionItem.isEnergyStar());
}
Also used : RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem)

Example 10 with RequisitionItem

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

RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)10 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)3 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)3 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)3 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)2 BigDecimal (java.math.BigDecimal)2 Iterator (java.util.Iterator)2 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)2 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)2 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)2 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)2 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)2 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)2 Person (org.kuali.rice.kim.api.identity.Person)2 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)1 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)1 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)1 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)1