use of org.kuali.rice.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CuPaymentFileValidationServiceImpl method processGroupValidation.
@Override
protected void processGroupValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
int groupCount = 0;
for (PaymentGroup paymentGroup : paymentFile.getPaymentGroups()) {
groupCount++;
int noteLineCount = 0;
int detailCount = 0;
// We've encountered Payment Files that have address lines exceeding the column size in DB table;
// so adding extra validation on payment group BO, especially the max length, based on DD definitions.
// Check that PaymentGroup String properties don't exceed maximum allowed length
checkPaymentGroupPropertyMaxLength(paymentGroup, errorMap);
// verify payee id and owner code if customer requires them to be filled in
if (paymentFile.getCustomer().getPayeeIdRequired() && StringUtils.isBlank(paymentGroup.getPayeeId())) {
LOG.debug("processGroupValidation, No payee");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_ID_REQUIRED, Integer.toString(groupCount));
}
if (paymentFile.getCustomer().getOwnershipCodeRequired() && StringUtils.isBlank(paymentGroup.getPayeeOwnerCd())) {
LOG.debug("processGroupValidation, no ownership code");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_OWNER_CODE, Integer.toString(groupCount));
}
// validate payee id type
if (StringUtils.isNotBlank(paymentGroup.getPayeeIdTypeCd())) {
PayeeType payeeType = businessObjectService.findBySinglePrimaryKey(PayeeType.class, paymentGroup.getPayeeIdTypeCd());
if (payeeType == null) {
LOG.debug("processGroupValidation, no payee type");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_PAYEE_ID_TYPE, Integer.toString(groupCount), paymentGroup.getPayeeIdTypeCd());
}
}
// validate vendor id and customer institution number
if (paymentGroup.getPayeeId().split("-").length > 1) {
try {
paymentGroup.validateVendorIdAndCustomerInstitutionIdentifier();
} catch (RuntimeException e1) {
LOG.error("processGroupValidation, there was an error validating customer institution information", e1);
errorMap.putError(KFSConstants.GLOBAL_ERRORS, CUKFSKeyConstants.ERROR_BATCH_UPLOAD_PARSING_XML, new String[] { e1.getMessage() });
}
} else {
LOG.debug("processGroupValidation, found a non vendor number payee ID: " + paymentGroup.getPayeeId());
if (cuPdpEmployeeService.shouldPayeeBeProcessedAsEmployeeForThisCustomer(paymentFile)) {
Person employee = findPerson(paymentGroup.getPayeeId());
if (ObjectUtils.isNull(employee)) {
LOG.error("processGroupValidation, unable to get a person from the employee id");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, CUPdpKeyConstants.ERROR_PDP_PAYMENTLOAD_INVALID_EMPLOYEE_ID, paymentGroup.getPayeeId());
}
}
}
// validate bank
String bankCode = paymentGroup.getBankCode();
if (StringUtils.isNotBlank(bankCode)) {
Bank bank = bankService.getByPrimaryId(bankCode);
if (bank == null) {
LOG.debug("processGroupValidation, no bank");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_BANK_CODE, Integer.toString(groupCount), bankCode);
} else if (!bank.isActive()) {
LOG.debug("processGroupValidation, bank isn't active");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INACTIVE_BANK_CODE, Integer.toString(groupCount), bankCode);
}
}
KualiDecimal groupTotal = KualiDecimal.ZERO;
for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
detailCount++;
// Add a line to print the invoice number
noteLineCount++;
noteLineCount = noteLineCount + paymentDetail.getNotes().size();
if ((paymentDetail.getNetPaymentAmount() == null) && (!paymentDetail.isDetailAmountProvided())) {
paymentDetail.setNetPaymentAmount(paymentDetail.getAccountTotal());
} else if ((paymentDetail.getNetPaymentAmount() == null) && (paymentDetail.isDetailAmountProvided())) {
paymentDetail.setNetPaymentAmount(paymentDetail.getCalculatedPaymentAmount());
}
// compare net to accounting segments
if (paymentDetail.getAccountTotal().compareTo(paymentDetail.getNetPaymentAmount()) != 0) {
LOG.debug("processGroupValidation, account total (" + paymentDetail.getAccountTotal() + ") not equal to net amount total (" + paymentDetail.getNetPaymentAmount() + ")");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_DETAIL_TOTAL_MISMATCH, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getAccountTotal().toString(), paymentDetail.getNetPaymentAmount().toString());
}
// validate origin code if given
if (StringUtils.isNotBlank(paymentDetail.getFinancialSystemOriginCode())) {
OriginationCode originationCode = originationCodeService.getByPrimaryKey(paymentDetail.getFinancialSystemOriginCode());
if (originationCode == null) {
LOG.debug("processGroupValidation, origination code is null");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_ORIGIN_CODE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialSystemOriginCode());
}
}
// validate doc type if given
if (StringUtils.isNotBlank(paymentDetail.getFinancialDocumentTypeCode())) {
if (!documentTypeService.isActiveByName(paymentDetail.getFinancialDocumentTypeCode())) {
LOG.debug("processGroupValidation, " + paymentDetail.getFinancialDocumentTypeCode() + " is not active.");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_DOC_TYPE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialDocumentTypeCode());
}
}
groupTotal = groupTotal.add(paymentDetail.getNetPaymentAmount());
}
// verify total for group is not negative
if (groupTotal.doubleValue() < 0) {
LOG.debug("processGroupValidation, group total less than zero");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_NEGATIVE_GROUP_TOTAL, Integer.toString(groupCount));
}
// check that the number of detail items and note lines will fit on a check stub
if (noteLineCount > getMaxNoteLines()) {
LOG.debug("processGroupValidation, too many notes");
errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_MAX_NOTE_LINES, Integer.toString(groupCount), Integer.toString(noteLineCount), Integer.toString(getMaxNoteLines()));
}
if (LOG.isDebugEnabled()) {
LOG.debug("After processGroupValidation: " + printErrorMap(errorMap));
}
}
}
use of org.kuali.rice.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method calculateQuantityChange.
/**
* Calculate quantity change for creating Credit Memo entries
*
* @param cancel Boolean indicating whether entries are for creation or cancellation of credit memo
* @param poItem Purchase Order Item
* @param cmQuantity Quantity on credit memo item
* @return Calculated change
*/
protected KualiDecimal calculateQuantityChange(PurchaseOrderItem poItem, KualiDecimal cmQuantity) {
LOG.debug("calculateQuantityChange() started");
// Calculate quantity change & adjust invoiced quantity & outstanding encumbered quantity
KualiDecimal encumbranceQuantityChange = null;
encumbranceQuantityChange = cmQuantity.multiply(new KualiDecimal("-1"));
poItem.setItemInvoicedTotalQuantity(poItem.getItemInvoicedTotalQuantity().subtract(encumbranceQuantityChange));
poItem.setItemOutstandingEncumberedQuantity(poItem.getItemOutstandingEncumberedQuantity().add(encumbranceQuantityChange));
// Check for overflows
if (poItem.getItemOutstandingEncumberedQuantity().doubleValue() < 0) {
LOG.debug("calculateQuantityChange() Cancel overflow");
KualiDecimal difference = poItem.getItemOutstandingEncumberedQuantity().abs();
poItem.setItemOutstandingEncumberedQuantity(ZERO);
poItem.setItemInvoicedTotalQuantity(poItem.getItemQuantity());
encumbranceQuantityChange = encumbranceQuantityChange.add(difference);
}
return encumbranceQuantityChange;
}
use of org.kuali.rice.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method reencumberEncumbrance.
/**
* Re-encumber the Encumbrance on a PO based on values in a PREQ. This is used when a PREQ is cancelled. Note: This modifies the
* encumbrance values on the PO and saves the PO
*
* @param preq PREQ for invoice
* @return List of accounting lines to use to create the pending general ledger entries
*/
protected List<SourceAccountingLine> reencumberEncumbrance(PaymentRequestDocument preq) {
LOG.debug("reencumberEncumbrance() started");
PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(preq.getPurchaseOrderIdentifier());
Map encumbranceAccountMap = new HashMap();
// Get each item one by one
for (Iterator items = preq.getItems().iterator(); items.hasNext(); ) {
PaymentRequestItem payRequestItem = (PaymentRequestItem) items.next();
PurchaseOrderItem poItem = getPoItem(po, payRequestItem.getItemLineNumber(), payRequestItem.getItemType());
// Amount to reencumber for this item
KualiDecimal itemReEncumber = null;
String logItmNbr = "Item # " + payRequestItem.getItemLineNumber();
LOG.debug("reencumberEncumbrance() " + logItmNbr);
// If there isn't a PO item or the total amount is 0, we don't need encumbrances
final KualiDecimal preqItemTotalAmount = (payRequestItem.getTotalAmount() == null) ? KualiDecimal.ZERO : payRequestItem.getTotalAmount();
if ((poItem == null) || (preqItemTotalAmount.doubleValue() == 0)) {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " No encumbrances required");
} else {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
// Do we calculate the encumbrance amount based on quantity or amount?
if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
// Do disencumbrance calculations based on quantity
KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
itemReEncumber = preqQuantity.multiply(new KualiDecimal(poItem.getItemUnitPrice()));
// add tax for encumbrance
KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
KualiDecimal encumbranceTaxAmount = preqQuantity.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
itemReEncumber = itemReEncumber.add(encumbranceTaxAmount);
} else {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
itemReEncumber = preqItemTotalAmount;
// this prevents negative encumbrance
if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() < 0)) {
// po item extended cost is negative
if ((poItem.getTotalAmount().compareTo(itemReEncumber)) > 0) {
itemReEncumber = poItem.getTotalAmount();
}
} else if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() >= 0)) {
// po item extended cost is positive
if ((poItem.getTotalAmount().compareTo(itemReEncumber)) < 0) {
itemReEncumber = poItem.getTotalAmount();
}
}
}
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Amount to reencumber: " + itemReEncumber);
KualiDecimal outstandingEncumberedAmount = poItem.getItemOutstandingEncumberedAmount() == null ? ZERO : poItem.getItemOutstandingEncumberedAmount();
LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Outstanding Encumbrance Amount set to: " + outstandingEncumberedAmount);
KualiDecimal newOutstandingEncumberedAmount = outstandingEncumberedAmount.add(itemReEncumber);
LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Outstanding Encumbrance Amount to set: " + newOutstandingEncumberedAmount);
poItem.setItemOutstandingEncumberedAmount(newOutstandingEncumberedAmount);
KualiDecimal invoicedTotalAmount = poItem.getItemInvoicedTotalAmount() == null ? ZERO : poItem.getItemInvoicedTotalAmount();
LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Invoiced Total Amount set to: " + invoicedTotalAmount);
KualiDecimal newInvoicedTotalAmount = invoicedTotalAmount.subtract(preqItemTotalAmount);
LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Invoiced Total Amount to set: " + newInvoicedTotalAmount);
poItem.setItemInvoicedTotalAmount(newInvoicedTotalAmount);
// make the list of accounts for the reencumbrance entry
PurchaseOrderAccount lastAccount = null;
KualiDecimal accountTotal = ZERO;
// Sort accounts
Collections.sort((List) poItem.getSourceAccountingLines());
for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
if (!account.isEmpty()) {
SourceAccountingLine acctString = account.generateSourceAccountingLine();
// amount = item reencumber * account percent / 100
KualiDecimal reencumbranceAmount = itemReEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(HUNDRED);
account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(reencumbranceAmount));
// For rounding check at the end
accountTotal = accountTotal.add(reencumbranceAmount);
lastAccount = account;
LOG.debug("reencumberEncumbrance() " + logItmNbr + " " + acctString + " = " + reencumbranceAmount);
if (encumbranceAccountMap.containsKey(acctString)) {
KualiDecimal currentAmount = (KualiDecimal) encumbranceAccountMap.get(acctString);
encumbranceAccountMap.put(acctString, reencumbranceAmount.add(currentAmount));
} else {
encumbranceAccountMap.put(acctString, reencumbranceAmount);
}
}
}
// account for rounding by adjusting last account as needed
if (lastAccount != null) {
KualiDecimal difference = itemReEncumber.subtract(accountTotal);
LOG.debug("reencumberEncumbrance() difference: " + logItmNbr + " " + difference);
SourceAccountingLine acctString = lastAccount.generateSourceAccountingLine();
KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
if (amount == null) {
encumbranceAccountMap.put(acctString, difference);
} else {
encumbranceAccountMap.put(acctString, amount.add(difference));
}
lastAccount.setItemAccountOutstandingEncumbranceAmount(lastAccount.getItemAccountOutstandingEncumbranceAmount().add(difference));
}
}
}
List<SourceAccountingLine> encumbranceAccounts = new ArrayList<SourceAccountingLine>();
for (Iterator<SourceAccountingLine> iter = encumbranceAccountMap.keySet().iterator(); iter.hasNext(); ) {
SourceAccountingLine acctString = (SourceAccountingLine) iter.next();
KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
if (amount.doubleValue() != 0) {
acctString.setAmount(amount);
encumbranceAccounts.add(acctString);
}
}
return encumbranceAccounts;
}
use of org.kuali.rice.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class DebitDeterminerServiceImplTest method test.
public void test() {
CuDisbursementVoucherDocument dv = null;
try {
dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
} catch (WorkflowException e) {
throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
}
if (dv != null) {
dv.getDocumentHeader().setDocumentDescription("Test Document Description");
dv.getDocumentHeader().setExplanation("Stuff");
dv.initiateDocument();
VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
System.out.println(vendoraddress.getVendorCityName() + "\n");
dv.templateVendor(vendor, vendoraddress);
dv.setPayeeAssigned(true);
dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
dv.setDisbVchrPaymentMethodCode("P");
dv.setDisbVchrCheckStubText("check text");
SourceAccountingLine accountingLine = new SourceAccountingLine();
accountingLine.setChartOfAccountsCode("IT");
accountingLine.setAccountNumber("G081040");
accountingLine.setFinancialObjectCode("2045");
accountingLine.setAmount((new KualiDecimal(-14.00)));
accountingLine.setPostingYear(dv.getPostingYear());
accountingLine.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine);
SourceAccountingLine accountingLine2 = new SourceAccountingLine();
accountingLine2.setChartOfAccountsCode("IT");
accountingLine2.setAccountNumber("1453611");
accountingLine2.setFinancialObjectCode("8462");
accountingLine2.setAmount((new KualiDecimal(100.00)));
accountingLine2.setPostingYear(dv.getPostingYear());
accountingLine2.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine2);
try {
documentService.saveDocument(dv);
} catch (WorkflowException e) {
throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
}
}
List<GeneralLedgerPendingEntrySourceDetail> glpeS = dv.getGeneralLedgerPendingEntrySourceDetails();
GeneralLedgerPendingEntrySourceDetail postable = glpeS.get(0);
System.out.println("GL Detail" + postable.toString() + "\n");
assertFalse(debitDeterminerService.isDebitConsideringNothingPositiveOnly(dv, postable));
}
use of org.kuali.rice.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class AmazonWebServicesBillingServiceImplTest method testConvertCostStringToKualiDecimal5.
@Test
public void testConvertCostStringToKualiDecimal5() {
KualiDecimal results = amazonService.convertCostStringToKualiDecimal("");
double expected = 0;
assertEquals(expected, results.doubleValue(), allowableVarianceAmount);
}
Aggregations