Search in sources :

Example 11 with PaymentRequestItem

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

the class CuElectronicInvoiceHelperServiceImpl method processItemsForDiscount.

protected void processItemsForDiscount(PaymentRequestDocument preqDocument, ElectronicInvoiceOrderHolder orderHolder) {
    LOG.info("Processing payment request items for discount");
    if (!orderHolder.isItemTypeAvailableInItemMapping(ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT)) {
        LOG.info("Skipping discount processing since there is no mapping of discount type for this vendor");
        return;
    }
    if (orderHolder.getInvoiceDiscountAmount() == null || orderHolder.getInvoiceDiscountAmount() == BigDecimal.ZERO) {
        LOG.info("Skipping discount processing since there is no discount amount found in the invoice file");
        return;
    }
    KualiDecimal discountValueToUse = new KualiDecimal(orderHolder.getInvoiceDiscountAmount().negate());
    List<PaymentRequestItem> preqItems = preqDocument.getItems();
    boolean alreadyProcessedInvoiceDiscount = false;
    boolean hasKualiPaymentTermsDiscountItem = false;
    // if e-invoice amount is negative... it is a penalty and we must pay extra
    for (int i = 0; i < preqItems.size(); i++) {
        PaymentRequestItem preqItem = preqItems.get(i);
        hasKualiPaymentTermsDiscountItem = hasKualiPaymentTermsDiscountItem || (StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE, preqItem.getItemTypeCode()));
        if (isItemValidForUpdation(preqItem.getItemTypeCode(), ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT, orderHolder)) {
            alreadyProcessedInvoiceDiscount = true;
            if (StringUtils.equals(preqItem.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE)) {
                // Item is kuali payment terms discount item... must perform calculation
                // if discount item exists on PREQ and discount dollar amount exists... use greater amount
                LOG.info("Discount Check - E-Invoice matches PREQ item type '" + preqItem.getItemTypeCode() + "'... now checking for amount");
                KualiDecimal preqExtendedPrice = preqItem.getExtendedPrice() == null ? KualiDecimal.ZERO : preqItem.getExtendedPrice();
                if ((discountValueToUse.compareTo(preqExtendedPrice)) < 0) {
                    LOG.info("Discount Check - Using E-Invoice amount (" + discountValueToUse + ") as it is more discount than current payment terms amount " + preqExtendedPrice);
                    preqItem.setItemUnitPrice(discountValueToUse.bigDecimalValue());
                    preqItem.setExtendedPrice(discountValueToUse);
                }
            } else {
                // item is not payment terms discount item... just add value
                // if discount item exists on PREQ and discount dollar amount exists... use greater amount
                LOG.info("Discount Check - E-Invoice matches PREQ item type '" + preqItem.getItemTypeCode() + "'");
                LOG.info("Discount Check - Using E-Invoice amount (" + discountValueToUse + ") as it is greater than payment terms amount");
                preqItem.addToUnitPrice(discountValueToUse.bigDecimalValue());
                preqItem.addToExtendedPrice(discountValueToUse);
            }
        }
    }
    if (!alreadyProcessedInvoiceDiscount) {
        String itemTypeRequired = PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE;
        if (hasKualiPaymentTermsDiscountItem || !orderHolder.isItemTypeAvailableInItemMapping(ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT)) {
            ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_DISCOUNT_ERROR, null, orderHolder.getFileName());
            orderHolder.addInvoiceOrderRejectReason(rejectReason);
            return;
        } else if (discountValueToUse.isNonZero()) {
            PaymentRequestItem newItem = new PaymentRequestItem();
            newItem.setItemUnitPrice(discountValueToUse.bigDecimalValue());
            // KFSUPGRADE-473
            // newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE);
            newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE);
            newItem.setItemDescription(CUPurapConstants.ElectronicInvoice.DISCOUNT_DESCRIPTION);
            newItem.setExtendedPrice(discountValueToUse);
            newItem.setPurapDocument(preqDocument);
            preqDocument.addItem(newItem);
        }
    }
    LOG.info("Completed processing payment request items for discount");
}
Also used : PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) ElectronicInvoiceRejectReason(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason)

Example 12 with PaymentRequestItem

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

the class CuPaymentRequestServiceImplTest method testRemoveIneligibleAdditionalCharges_WithEligibleItems.

public void testRemoveIneligibleAdditionalCharges_WithEligibleItems() throws Exception {
    changeCurrentUser(UserNameFixture.ccs1);
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN_TRADE_IN_ITEMS.createPurchaseOrderdDocument(SpringContext.getBean(DocumentService.class));
    changeCurrentUser(UserNameFixture.mo14);
    PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(po.getPurapDocumentIdentifier());
    paymentRequestDocument.initiateDocument();
    paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(po);
    PaymentRequestItem preqItem = new PaymentRequestItem();
    preqItem.setItemTypeCode(ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE);
    preqItem.setItemDescription("test");
    preqItem.setItemUnitOfMeasureCode("EA");
    paymentRequestDocument.addItem(preqItem);
    int numberOfItems = paymentRequestDocument.getItems().size();
    paymentRequestService.removeIneligibleAdditionalCharges(paymentRequestDocument);
    assertFalse(numberOfItems == paymentRequestDocument.getItems().size());
}
Also used : PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 13 with PaymentRequestItem

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

the class CuPaymentRequestServiceImplTest method testClearTax.

public void testClearTax() throws Exception {
    changeCurrentUser(UserNameFixture.ccs1);
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN.createPurchaseOrderdDocument(SpringContext.getBean(DocumentService.class));
    po.setVendorShippingPaymentTermsCode("AL");
    po.setVendorPaymentTermsCode("00N30");
    po.refreshNonUpdateableReferences();
    changeCurrentUser(UserNameFixture.mo14);
    CuPaymentRequestDocument paymentRequestDocument = (CuPaymentRequestDocument) PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(po.getPurapDocumentIdentifier());
    paymentRequestDocument.initiateDocument();
    paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(po);
    paymentRequestDocument.setTaxClassificationCode("XX");
    paymentRequestDocument.setTaxFederalPercent(new BigDecimal(30));
    paymentRequestDocument.setTaxStatePercent(new BigDecimal(10));
    paymentRequestDocument.setTaxCountryCode("US");
    paymentRequestDocument.setTaxNQIId(null);
    paymentRequestDocument.setTaxForeignSourceIndicator(true);
    paymentRequestDocument.setTaxExemptTreatyIndicator(true);
    paymentRequestDocument.setTaxOtherExemptIndicator(true);
    paymentRequestDocument.setTaxGrossUpIndicator(true);
    paymentRequestDocument.setTaxUSAIDPerDiemIndicator(true);
    paymentRequestDocument.setTaxSpecialW4Amount(new KualiDecimal(10));
    PaymentRequestItem paymentRequestItem = new PaymentRequestItem();
    paymentRequestItem.setItemTypeCode(ItemTypeCodes.ITEM_TYPE_FEDERAL_TAX_CODE);
    paymentRequestService.clearTax(paymentRequestDocument);
    assertNull(paymentRequestDocument.getTaxClassificationCode());
    assertNull(paymentRequestDocument.getTaxFederalPercent());
    assertNull(paymentRequestDocument.getTaxStatePercent());
    assertNull(paymentRequestDocument.getTaxCountryCode());
    assertNull(paymentRequestDocument.getTaxNQIId());
    assertFalse(paymentRequestDocument.getTaxForeignSourceIndicator());
    assertFalse(paymentRequestDocument.getTaxExemptTreatyIndicator());
    assertFalse(paymentRequestDocument.getTaxOtherExemptIndicator());
    assertFalse(paymentRequestDocument.getTaxGrossUpIndicator());
    assertFalse(paymentRequestDocument.getTaxUSAIDPerDiemIndicator());
    assertNull(paymentRequestDocument.getTaxSpecialW4Amount());
}
Also used : PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) DocumentService(org.kuali.kfs.krad.service.DocumentService) BigDecimal(java.math.BigDecimal)

Example 14 with PaymentRequestItem

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

the class CuPurapGeneralLedgerServiceImplTest method testGenerateEntriesPaymentRequest.

public void testGenerateEntriesPaymentRequest() throws Exception {
    changeCurrentUser(UserNameFixture.ccs1);
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN_WITH_ITEMS.createPurchaseOrderdDocument(SpringContext.getBean(DocumentService.class));
    po.setVendorShippingPaymentTermsCode("AL");
    po.setVendorPaymentTermsCode("00N30");
    po.refreshNonUpdateableReferences();
    changeCurrentUser(UserNameFixture.mo14);
    CuPaymentRequestDocument preq = (CuPaymentRequestDocument) PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(po.getPurapDocumentIdentifier());
    preq.initiateDocument();
    preq.populatePaymentRequestFromPurchaseOrder(po);
    preq.setPaymentMethodCode("F");
    preq.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW);
    ((PaymentRequestItem) (preq.getItems().get(0))).setExtendedPrice(new KualiDecimal(1));
    AccountingDocumentTestUtils.saveDocument(preq, SpringContext.getBean(DocumentService.class));
    List<SummaryAccount> summaryAccounts = purapAccountingService.generateSummaryAccountsWithNoZeroTotalsNoUseTax(preq);
    cuPurapGeneralLedgerServiceImpl.generateEntriesPaymentRequest(preq, null, summaryAccounts, "create");
    boolean noBankOffsetGenerated = true;
    for (GeneralLedgerPendingEntry pe : preq.getGeneralLedgerPendingEntries()) {
        if (KFSKeyConstants.Bank.DESCRIPTION_GLPE_BANK_OFFSET.equalsIgnoreCase(pe.getTransactionLedgerEntryDescription())) {
            noBankOffsetGenerated = false;
            break;
        }
    }
    assertEquals(2, preq.getGeneralLedgerPendingEntries().size());
    assertTrue(noBankOffsetGenerated);
}
Also used : SummaryAccount(org.kuali.kfs.module.purap.util.SummaryAccount) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 15 with PaymentRequestItem

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

the class CuPurapGeneralLedgerServiceImplTest method testReencumberEncumbrance.

public void testReencumberEncumbrance() throws Exception {
    changeCurrentUser(UserNameFixture.ccs1);
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN_WITH_ITEMS.createPurchaseOrderdDocument(SpringContext.getBean(DocumentService.class));
    po.setVendorShippingPaymentTermsCode("AL");
    po.setVendorPaymentTermsCode("00N30");
    po.getItem(0).setItemQuantity(new KualiDecimal(6));
    ((PurchaseOrderItem) po.getItem(0)).setItemInvoicedTotalQuantity(new KualiDecimal(4));
    po.refreshNonUpdateableReferences();
    AccountingDocumentTestUtils.saveDocument(po, SpringContext.getBean(DocumentService.class));
    changeCurrentUser(UserNameFixture.mo14);
    CuPaymentRequestDocument preq = (CuPaymentRequestDocument) PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(po.getPurapDocumentIdentifier());
    preq.initiateDocument();
    preq.populatePaymentRequestFromPurchaseOrder(po);
    preq.setPaymentMethodCode("F");
    preq.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW);
    ((PaymentRequestItem) (preq.getItems().get(0))).setExtendedPrice(KualiDecimal.ZERO);
    ((PaymentRequestItem) (preq.getItems().get(0))).setItemUnitPrice(BigDecimal.ZERO);
    ((PaymentRequestItem) (preq.getItems().get(0))).setItemQuantity(new KualiDecimal(2));
    AccountingDocumentTestUtils.saveDocument(preq, SpringContext.getBean(DocumentService.class));
    cuPurapGeneralLedgerServiceImpl.reencumberEncumbrance(preq);
    PurchaseOrderDocument po2 = purchaseOrderService.getCurrentPurchaseOrder(preq.getPurchaseOrderIdentifier());
    assertEquals(new KualiDecimal(2), ((PurchaseOrderItem) po2.getItem(0)).getItemInvoicedTotalQuantity());
}
Also used : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Aggregations

PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)16 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)11 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)9 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)6 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)5 DocumentService (org.kuali.kfs.krad.service.DocumentService)5 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)4 CuPaymentRequestItemExtension (edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)3 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ElectronicInvoiceRejectReason (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason)2 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)2 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)2 PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)2 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2