diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java index 0614ee5d5e..e2a8c0ed65 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java @@ -1,17 +1,18 @@ package org.kuali.ole.oleng.service; +import org.kuali.ole.coa.businessobject.Account; +import org.kuali.ole.coa.businessobject.OleFundCode; import org.kuali.ole.module.purap.businessobject.ItemType; import org.kuali.ole.module.purap.businessobject.PurchaseOrderType; import org.kuali.ole.module.purap.document.service.OlePurapService; import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; import org.kuali.ole.oleng.common.service.OleNgCommonMemorizeService; import org.kuali.ole.select.bo.OLEDonor; +import org.kuali.ole.select.bo.OleVendorAccountInfo; import org.kuali.ole.sys.businessobject.Building; import org.kuali.ole.sys.businessobject.Room; import org.kuali.ole.utility.LocationUtil; -import org.kuali.ole.vnd.businessobject.VendorAddress; -import org.kuali.ole.vnd.businessobject.VendorAlias; -import org.kuali.ole.vnd.businessobject.VendorDetail; +import org.kuali.ole.vnd.businessobject.*; import org.kuali.ole.vnd.document.service.VendorService; import java.util.List; @@ -37,4 +38,10 @@ public interface OleNGMemorizeService { public Integer getRequestSourceTypeId(String requestSourceType); public OLEDonor getDonorCode(String donorCode); public BatchProcessProfile fetchBatchProcessProfile(String profileName, String type); + + public List getExchangeRate(String currencyTypeId); + public OleCurrencyType getCurrencyType(String currencyTypeId); + public List getVendorAccountInfo(String code); + public List getAccount(String accountNumber); + public List getFundCode(String fundCode); } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java index 73699f6d33..dac79dd5dc 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java @@ -17,6 +17,7 @@ import org.kuali.ole.module.purap.document.validation.event.AttributedCalculateAccountsPayableEvent; import org.kuali.ole.module.purap.service.PurapAccountingService; import org.kuali.ole.oleng.service.OleNGInvoiceService; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.pojo.OleInvoiceRecord; import org.kuali.ole.select.OleSelectConstant; import org.kuali.ole.select.bo.OleVendorAccountInfo; @@ -33,6 +34,7 @@ import org.kuali.ole.sys.service.UniversityDateService; import org.kuali.ole.vnd.businessobject.OleCurrencyType; import org.kuali.ole.vnd.businessobject.OleExchangeRate; +import org.kuali.ole.vnd.businessobject.VendorAddress; import org.kuali.ole.vnd.businessobject.VendorDetail; import org.kuali.rice.core.api.util.type.KualiDecimal; import org.kuali.rice.core.api.util.type.KualiInteger; @@ -46,6 +48,7 @@ import org.kuali.rice.krad.util.GlobalVariables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -64,6 +67,8 @@ public class OleNGInvoiceServiceImpl implements OleNGInvoiceService { private OlePurapService olePurapService; private OleInvoiceService oleInvoiceService; private BatchUtil batchUtil; + @Autowired + private OleNGMemorizeService oleNGMemorizeService; @Override public OleInvoiceDocument createNewInvoiceDocument() throws Exception { @@ -89,7 +94,7 @@ public OleInvoiceDocument populateInvoiceDocWithOrderInformation(OleInvoiceDocum oleInvoiceDocument.setInvoiceNumber(oleInvoiceRecord.getInvoiceNumber()); String vendorNumber = oleInvoiceRecord.getVendorNumber(); - getInvoiceService().populateVendorDetail(vendorNumber, oleInvoiceDocument); + populateVendorDetail(vendorNumber, oleInvoiceDocument); oleInvoiceDocument.setVendorCustomerNumber(oleInvoiceRecord.getBillToCustomerID()); if(!StringUtils.isBlank(oleInvoiceRecord.getCurrencyTypeId())){ @@ -275,18 +280,19 @@ private OleInvoiceDocument initiateInvoiceDocument(OleInvoiceDocument invoiceDoc private void setDocumentForeignDetails(OleInvoiceDocument invoiceDocument, OleInvoiceRecord invoiceRecord){ - OleCurrencyType oleCurrencyType = getBusinessObjectService().findBySinglePrimaryKey(OleCurrencyType.class,invoiceRecord.getCurrencyTypeId()); - invoiceDocument.setInvoiceCurrencyType(oleCurrencyType.getCurrencyTypeId().toString()); - if(!oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){ - Map documentNumberMap = new HashMap(); - documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, invoiceRecord.getCurrencyTypeId()); - List exchangeRateList = (List) getBusinessObjectService().findMatchingOrderBy( - OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); - Iterator iterator = exchangeRateList.iterator(); - if (iterator.hasNext()) { - invoiceDocument.setForeignVendorInvoiceAmount(new BigDecimal(0.00)); - invoiceDocument.setInvoiceCurrencyTypeId(new Long(invoiceRecord.getCurrencyTypeId())); - invoiceDocument.setInvoiceCurrencyExchangeRate(invoiceRecord.getInvoiceCurrencyExchangeRate()); + OleCurrencyType oleCurrencyType = getOleNGMemorizeService().getCurrencyType(invoiceRecord.getCurrencyTypeId()); + if (null != oleCurrencyType) { + invoiceDocument.setInvoiceCurrencyType(oleCurrencyType.getCurrencyTypeId().toString()); + if(!oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){ + List exchangeRateList = getOleNGMemorizeService().getExchangeRate(invoiceRecord.getCurrencyTypeId()); + if (CollectionUtils.isNotEmpty(exchangeRateList)) { + Iterator iterator = exchangeRateList.iterator(); + if (iterator.hasNext()) { + invoiceDocument.setForeignVendorInvoiceAmount(new BigDecimal(0.00)); + invoiceDocument.setInvoiceCurrencyTypeId(new Long(invoiceRecord.getCurrencyTypeId())); + invoiceDocument.setInvoiceCurrencyExchangeRate(invoiceRecord.getInvoiceCurrencyExchangeRate()); + } + } } } } @@ -439,9 +445,10 @@ private InvoiceAccount createInvoiceAccountFromVendorAccountInfo(OleInvoiceRecor invoiceAccount.setAccountLinePercent(new BigDecimal("100")); // TODO: Need to get from edifact. invoiceAccount.setPurapItem(oleInvoiceItem); invoiceAccount.setItemIdentifier(oleInvoiceItem.getItemIdentifier()); + String chartOfAccount = populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()); invoiceAccount.setChartOfAccountsCode( - populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()) != null ? - populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()) : invoiceRecord.getItemChartCode()); // TODO: Need to get chart of Account based on account number and object code. + chartOfAccount != null ? + chartOfAccount : invoiceRecord.getItemChartCode()); // TODO: Need to get chart of Account based on account number and object code. return invoiceAccount; } @@ -483,24 +490,18 @@ private OleInvoiceItem createNewInvoiceItem(OleInvoiceRecord invoiceRecord) { private OleVendorAccountInfo populateBFN(String code) { - Map matchBFN = new HashMap(); - matchBFN.put("vendorRefNumber", code); - List oleVendorAccountInfo = (List) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN); - return oleVendorAccountInfo != null && oleVendorAccountInfo.size() > 0 ? oleVendorAccountInfo.get(0) : null; + List oleVendorAccountInfo = getOleNGMemorizeService().getVendorAccountInfo(code); + return CollectionUtils.isNotEmpty(oleVendorAccountInfo) ? oleVendorAccountInfo.get(0) : null; } private String populateChartOfAccount(String accountNumber) { - Map matchChartCode = new HashMap(); - matchChartCode.put("accountNumber", accountNumber); - List accountList = (List) getBusinessObjectService().findMatching(Account.class, matchChartCode); - return accountList != null && accountList.size() > 0 ? accountList.get(0).getChartOfAccountsCode() : null; + List accountList = getOleNGMemorizeService().getAccount(accountNumber); + return CollectionUtils.isNotEmpty(accountList)? accountList.get(0).getChartOfAccountsCode() : null; } private List getAccountingLinesFromFundCode(OleInvoiceRecord invoiceRecord, OleInvoiceItem oleInvoiceItem) { List accountingLine = new ArrayList(); - Map fundCodeMap = new HashMap<>(); - fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, invoiceRecord.getFundCode()); - List fundCodeList = (List) getBusinessObjectService().findMatching(OleFundCode.class, fundCodeMap); + List fundCodeList = getOleNGMemorizeService().getFundCode(invoiceRecord.getFundCode()); if (CollectionUtils.isNotEmpty(fundCodeList)) { OleFundCode oleFundCode = fundCodeList.get(0); List fundCodeAccountingLineList = oleFundCode.getOleFundCodeAccountingLineList(); @@ -569,6 +570,56 @@ public void updatePrice(OleInvoiceDocument oleInvoiceDocument) { } } + public OleInvoiceDocument populateVendorDetail(String vendorNumber, OleInvoiceDocument oleInvoiceDocument) { + String[] vendorIds = vendorNumber != null ? vendorNumber.split("-") : new String[0]; + VendorDetail vendorDetail = getOleNGMemorizeService().getVendorDetail(Integer.valueOf(vendorIds[0]),Integer.valueOf(vendorIds[1])); + if (vendorDetail != null) { + oleInvoiceDocument.setVendorDetail(vendorDetail); + oleInvoiceDocument.setVendorName(vendorDetail.getVendorName()); + oleInvoiceDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier()); + oleInvoiceDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier()); + oleInvoiceDocument.setVendorNumber(vendorDetail.getVendorNumber()); + oleInvoiceDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier()); + oleInvoiceDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier()); + oleInvoiceDocument.setVendorFaxNumber(vendorDetail.getDefaultFaxNumber()); + //oleInvoiceDocument. + if (vendorDetail.getPaymentMethodId() != null) { + oleInvoiceDocument.setPaymentMethodIdentifier(vendorDetail.getPaymentMethodId().toString()); + oleInvoiceDocument.setPaymentMethodId(vendorDetail.getPaymentMethodId()); + } + + if (vendorDetail.getVendorPaymentTerms() != null) { + oleInvoiceDocument.setVendorPaymentTerms(vendorDetail.getVendorPaymentTerms()); + oleInvoiceDocument.setVendorPaymentTermsCode(vendorDetail.getVendorPaymentTerms().getVendorPaymentTermsCode()); + + } + if (vendorDetail.getVendorShippingTitle() != null) { + oleInvoiceDocument.setVendorShippingTitleCode(vendorDetail.getVendorShippingTitle().getVendorShippingTitleCode()); + } + if (vendorDetail.getVendorShippingPaymentTerms() != null) { + oleInvoiceDocument.setVendorShippingPaymentTerms(vendorDetail.getVendorShippingPaymentTerms()); + } + + for (VendorAddress vendorAddress : vendorDetail.getVendorAddresses()) { + if (vendorAddress.isVendorDefaultAddressIndicator()) { + oleInvoiceDocument.setVendorCityName(vendorAddress.getVendorCityName()); + oleInvoiceDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address()); + oleInvoiceDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address()); + oleInvoiceDocument.setVendorAttentionName(vendorAddress.getVendorAttentionName()); + oleInvoiceDocument.setVendorPostalCode(vendorAddress.getVendorZipCode()); + oleInvoiceDocument.setVendorStateCode(vendorAddress.getVendorStateCode()); + oleInvoiceDocument.setVendorAttentionName(vendorAddress.getVendorAttentionName()); + oleInvoiceDocument.setVendorAddressInternationalProvinceName(vendorAddress.getVendorAddressInternationalProvinceName()); + oleInvoiceDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode()); + oleInvoiceDocument.setVendorCountry(vendorAddress.getVendorCountry()); + //oleInvoiceDocument.setNoteLine1Text(vendorAddress.getNoteLine2Text + } + } + } + + return oleInvoiceDocument; + } + static class InvoiceItemDetail { private String subscriptionPeriod; private Integer poNumber; @@ -659,4 +710,14 @@ public void setBatchUtil(BatchUtil batchUtil) { this.batchUtil = batchUtil; } + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java index d15c4c1e90..2a5090633e 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java @@ -6,6 +6,8 @@ import org.codehaus.jackson.map.ObjectMapper; import org.kuali.ole.OLEConstants; import org.kuali.ole.cache.Memoize; +import org.kuali.ole.coa.businessobject.Account; +import org.kuali.ole.coa.businessobject.OleFundCode; import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; import org.kuali.ole.module.purap.businessobject.ItemType; import org.kuali.ole.module.purap.businessobject.PurchaseOrderTransmissionMethod; @@ -15,16 +17,16 @@ import org.kuali.ole.oleng.common.service.OleNgCommonMemorizeService; import org.kuali.ole.oleng.common.service.impl.OleNgCommonMemorizeServiceImpl; import org.kuali.ole.oleng.service.OleNGMemorizeService; +import org.kuali.ole.select.OleSelectConstant; import org.kuali.ole.select.bo.OLEDonor; +import org.kuali.ole.select.bo.OleVendorAccountInfo; import org.kuali.ole.select.businessobject.OleRequestSourceType; import org.kuali.ole.select.document.service.OleDocstoreHelperService; import org.kuali.ole.sys.businessobject.Building; import org.kuali.ole.sys.businessobject.Room; import org.kuali.ole.sys.context.SpringContext; import org.kuali.ole.utility.LocationUtil; -import org.kuali.ole.vnd.businessobject.VendorAddress; -import org.kuali.ole.vnd.businessobject.VendorAlias; -import org.kuali.ole.vnd.businessobject.VendorDetail; +import org.kuali.ole.vnd.businessobject.*; import org.kuali.ole.vnd.document.service.VendorService; import org.kuali.rice.krad.service.KRADServiceLocator; import org.kuali.rice.krad.service.KRADServiceLocatorWeb; @@ -159,6 +161,40 @@ public BatchProcessProfile fetchBatchProcessProfile(String profileName, String t return batchProcessProfile; } + @Memoize + public List getExchangeRate(String currencyTypeId) { + Map documentNumberMap = new HashMap(); + documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId); + return (List) getBusinessObjectService().findMatchingOrderBy( + OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); + } + + @Memoize + public OleCurrencyType getCurrencyType(String currencyTypeId) { + return getBusinessObjectService().findBySinglePrimaryKey(OleCurrencyType.class,currencyTypeId); + } + + @Memoize + public List getVendorAccountInfo(String code) { + Map matchBFN = new HashMap(); + matchBFN.put("vendorRefNumber", code); + return (List) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN); + } + + @Memoize + public List getAccount(String accountNumber) { + Map matchChartCode = new HashMap(); + matchChartCode.put("accountNumber", accountNumber); + return (List) getBusinessObjectService().findMatching(Account.class, matchChartCode); + } + + @Memoize + public List getFundCode(String fundCode) { + Map fundCodeMap = new HashMap<>(); + fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, fundCode); + return (List) getBusinessObjectService().findMatching(OleFundCode.class, fundCodeMap); + } + @Override public LocationUtil getLocationUtil() { if(null == locationUtil){ diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java index dec8bad3ee..fdde058e9b 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java @@ -42,9 +42,9 @@ public boolean validateOleInvoiceRecord(OleInvoiceRecord oleInvoiceRecord, Excha private boolean validateInvoiceNumber(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { String invoiceNumber = oleInvoiceRecord.getInvoiceNumber(); - if (StringUtils.isBlank(invoiceNumber) || !NumberUtils.isDigits(invoiceNumber)){ + if (StringUtils.isBlank(invoiceNumber)){ getBatchUtil().addInvoiceFaiureResponseToExchange( - new ValidationException("Invoice number cannot be blank or null and it should be round number"), recordIndex, exchange); + new ValidationException("Invoice number cannot be blank or null"), recordIndex, exchange); return false; } return true;