use of org.kuali.kfs.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.kfs.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.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class UserFavoriteAccountServiceImpl method populateIWantAccountingLine.
protected void populateIWantAccountingLine(FavoriteAccount account, IWantAccount acctLine) {
final int ONE_HUNDRED = 100;
acctLine.setAccountNumber(account.getAccountNumber());
acctLine.setChartOfAccountsCode(account.getChartOfAccountsCode());
acctLine.setSubAccountNumber(account.getSubAccountNumber());
acctLine.setFinancialObjectCode(account.getFinancialObjectCode());
acctLine.setFinancialSubObjectCode(account.getFinancialSubObjectCode());
acctLine.setProjectCode(account.getProjectCode());
acctLine.setOrganizationReferenceId(account.getOrganizationReferenceId());
acctLine.setUseAmountOrPercent(CUPurapConstants.PERCENT);
acctLine.setAmountOrPercent(new KualiDecimal(ONE_HUNDRED));
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class DisbursementVoucherDocument method templateEmployee.
/**
* Convenience method to set dv payee detail fields based on a given Employee.
*
* @param employee
*/
public void templateEmployee(Person employee) {
if (employee == null) {
return;
}
this.getDvPayeeDetail().setDisbursementVoucherPayeeTypeCode(KFSConstants.PaymentPayeeTypes.EMPLOYEE);
this.getDvPayeeDetail().setDisbVchrPayeeIdNumber(employee.getEmployeeId());
this.getDvPayeeDetail().setDisbVchrPayeePersonName(employee.getName());
final ParameterService parameterService = this.getParameterService();
if (parameterService.parameterExists(DisbursementVoucherDocument.class, FPParameterConstants.USE_DEFAULT_EMPLOYEE_ADDRESS) && parameterService.getParameterValueAsBoolean(DisbursementVoucherDocument.class, FPParameterConstants.USE_DEFAULT_EMPLOYEE_ADDRESS)) {
this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(employee.getAddressLine1Unmasked());
this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(employee.getAddressLine2Unmasked());
this.getDvPayeeDetail().setDisbVchrPayeeCityName(employee.getAddressCityUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeStateCode(employee.getAddressStateProvinceCodeUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeZipCode(employee.getAddressPostalCodeUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(employee.getAddressCountryCodeUnmasked());
} else {
final EntityAddress address = getNonDefaultAddress(employee);
if (address != null) {
this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(address.getLine1Unmasked());
this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(address.getLine2Unmasked());
this.getDvPayeeDetail().setDisbVchrPayeeCityName(address.getCityUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeStateCode(address.getStateProvinceCodeUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeZipCode(address.getPostalCodeUnmasked());
this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(address.getCountryCodeUnmasked());
} else {
this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr("");
this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr("");
this.getDvPayeeDetail().setDisbVchrPayeeCityName("");
this.getDvPayeeDetail().setDisbVchrPayeeStateCode("");
this.getDvPayeeDetail().setDisbVchrPayeeZipCode("");
this.getDvPayeeDetail().setDisbVchrPayeeCountryCode("");
}
}
// "Is this payee an employee" = No
if (employee.isActive()) {
this.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(true);
} else {
this.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(false);
}
// I'm assuming that if a tax id type code other than 'TAX' is present, then the employee must be foreign
for (String externalIdentifierTypeCode : employee.getExternalIdentifiers().keySet()) {
if (KimConstants.PersonExternalIdentifierTypes.TAX.equals(externalIdentifierTypeCode)) {
this.getDvPayeeDetail().setDisbVchrNonresidentPaymentCode(false);
}
}
// Determine if employee is a research subject
ParameterEvaluator researchPaymentReasonCodeEvaluator = /*REFACTORME*/
SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_PAYMENT_REASONS, this.getDvPayeeDetail().getDisbVchrPaymentReasonCode());
if (researchPaymentReasonCodeEvaluator.evaluationSucceeds()) {
if (getParameterService().parameterExists(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT)) {
String researchPayLimit = getParameterService().getParameterValueAsString(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT);
if (StringUtils.isNotBlank(researchPayLimit)) {
KualiDecimal payLimit = new KualiDecimal(researchPayLimit);
if (getDisbVchrCheckTotalAmount().isLessThan(payLimit)) {
this.getDvPayeeDetail().setDvPayeeSubjectPaymentCode(true);
}
}
}
}
this.disbVchrPayeeTaxControlCode = "";
this.disbVchrPayeeW9CompleteCode = true;
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CapitalAssetInformationActionBase method capitalAccountingLineAmountDistributed.
/**
* Checks to see if all the capital assets' distributed amount is the same as
* the capital accounting lines (there is only one lines, of course).
*
* @param capitalAccountingLine
* @param capitalAssetsInformation
* @return true if accounting line amount equals to capital asset amount, else false.
*/
protected boolean capitalAccountingLineAmountDistributed(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetsInformation) {
KualiDecimal amountDistributed = KualiDecimal.ZERO;
for (CapitalAssetInformation capitalAsset : capitalAssetsInformation) {
amountDistributed = amountDistributed.add(getAccountingLineAmount(capitalAsset, capitalAccountingLine));
}
KualiDecimal capitalAccountingLineAmount = capitalAccountingLine.getAmount();
return amountDistributed.equals(capitalAccountingLineAmount);
}
Aggregations