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");
}
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());
}
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());
}
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);
}
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());
}
Aggregations