use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method adjustObjectCodeAmountsIfChanged.
/**
* If any of the current expenditures for the cost categories on the Contracts & Grants Invoice Document have
* changed, recalculate the Object Code amounts.
*
* @param contractsGrantsInvoiceDocument document containing cost categories to review
* @return true if expenditure value changed, false otherwise
*/
protected boolean adjustObjectCodeAmountsIfChanged(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
boolean isExpenditureValueChanged = false;
// put the invoiceDetailAccountObjectCode into a map based on category
List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes = contractsGrantsInvoiceDocument.getInvoiceDetailAccountObjectCodes();
Map<String, List<InvoiceDetailAccountObjectCode>> invoiceDetailAccountObjectCodeMap = new HashMap<>();
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
String categoryCode = invoiceDetailAccountObjectCode.getCategoryCode();
List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodeList = invoiceDetailAccountObjectCodeMap.get(categoryCode);
// if new category, create new list to put into map
if (invoiceDetailAccountObjectCodeList == null) {
List<InvoiceDetailAccountObjectCode> newInvoiceDetailAccountObjectCodeList = new ArrayList<>();
newInvoiceDetailAccountObjectCodeList.add(invoiceDetailAccountObjectCode);
invoiceDetailAccountObjectCodeMap.put(categoryCode, newInvoiceDetailAccountObjectCodeList);
} else {
// else, if list is found, add it to existing list
invoiceDetailAccountObjectCodeMap.get(categoryCode).add(invoiceDetailAccountObjectCode);
}
}
// invoiceDetailObjectCode and update account details
for (ContractsGrantsInvoiceDetail invoiceDetail : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
KualiDecimal total = getSumOfExpendituresOfCategory(invoiceDetailAccountObjectCodeMap.get(invoiceDetail.getCategoryCode()));
// To set expenditures to zero if its blank - to avoid exceptions.
if (ObjectUtils.isNull(invoiceDetail.getInvoiceAmount())) {
invoiceDetail.setInvoiceAmount(KualiDecimal.ZERO);
}
if (invoiceDetail.getInvoiceAmount().compareTo(total) != 0) {
recalculateObjectCodeByCategory(contractsGrantsInvoiceDocument, invoiceDetail, total, invoiceDetailAccountObjectCodeMap.get(invoiceDetail.getCategoryCode()));
isExpenditureValueChanged = true;
}
}
return isExpenditureValueChanged;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildTotalIndirectCostInvoiceDetailFieldsMap.
private Map<String, Object> buildTotalIndirectCostInvoiceDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> totalIndirectCostInvoiceDetailFieldsMap = new HashMap<>();
ContractsGrantsInvoiceDetail totalInDirectCostInvoiceDetail = document.getTotalIndirectCostInvoiceDetail();
if (ObjectUtils.isNotNull(totalInDirectCostInvoiceDetail)) {
final String prefix = ArPropertyConstants.IN_DIRECT_COST_INVOICE_DETAIL + ".";
totalIndirectCostInvoiceDetailFieldsMap.putAll(buildInvoiceDetailFieldMap(prefix, totalInDirectCostInvoiceDetail));
}
return totalIndirectCostInvoiceDetailFieldsMap;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildDirectCostInvoiceDetailFieldsMap.
private Map<String, Object> buildDirectCostInvoiceDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> directCostInvoiceDetailFieldsMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(document.getDirectCostInvoiceDetails())) {
ContractsGrantsInvoiceDetail firstInvoiceDetail = document.getDirectCostInvoiceDetails().get(0);
for (int i = 0; i < document.getDirectCostInvoiceDetails().size(); i++) {
final String prefix = ArPropertyConstants.INVOICE_DETAIL + "[" + i + "].";
directCostInvoiceDetailFieldsMap.put(prefix + ArPropertyConstants.CATEGORY, document.getDirectCostInvoiceDetails().get(i).getCostCategory().getCategoryName());
directCostInvoiceDetailFieldsMap.putAll(buildInvoiceDetailFieldMap(prefix, document.getDirectCostInvoiceDetails().get(i)));
directCostInvoiceDetailFieldsMap.put(prefix + ArPropertyConstants.AMOUNT_REMAINING_TO_BILL, firstInvoiceDetail.getAmountRemainingToBill());
}
}
return directCostInvoiceDetailFieldsMap;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildTotalDirectCostInvoiceDetailFieldsMap.
private Map<String, Object> buildTotalDirectCostInvoiceDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> totalDirectCostInvoiceDetailFieldsMap = new HashMap<>();
ContractsGrantsInvoiceDetail totalDirectCostInvoiceDetail = document.getTotalDirectCostInvoiceDetail();
if (ObjectUtils.isNotNull(totalDirectCostInvoiceDetail)) {
final String prefix = ArPropertyConstants.DIRECT_COST_INVOICE_DETAIL + ".";
totalDirectCostInvoiceDetailFieldsMap.putAll(buildInvoiceDetailFieldMap(prefix, totalDirectCostInvoiceDetail));
}
return totalDirectCostInvoiceDetailFieldsMap;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method prorateBill.
@Override
public void prorateBill(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
// Amount to be billed on this invoice
KualiDecimal totalCost = new KualiDecimal(0);
// must iterate through the invoice details because the user might have manually changed the value
for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
totalCost = totalCost.add(invD.getInvoiceAmount());
}
// Total Billed so far
KualiDecimal billedTotalCost = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getTotalPreviouslyBilled();
// AwardTotal
KualiDecimal accountAwardTotal = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAwardTotal();
if (accountAwardTotal.subtract(billedTotalCost).isGreaterEqual(new KualiDecimal(0))) {
KualiDecimal amountEligibleForBilling = accountAwardTotal.subtract(billedTotalCost);
if (totalCost.isGreaterThan(amountEligibleForBilling)) {
// use BigDecimal because percentage should not have only a scale of 2, we need more for accuracy
BigDecimal percentage = amountEligibleForBilling.bigDecimalValue().divide(totalCost.bigDecimalValue(), 10, RoundingMode.HALF_DOWN);
// use to check if rounding has left a few cents off
KualiDecimal amountToBill = new KualiDecimal(0);
ContractsGrantsInvoiceDetail largestCostCategory = null;
BigDecimal largestAmount = BigDecimal.ZERO;
for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
BigDecimal newValue = invD.getInvoiceAmount().bigDecimalValue().multiply(percentage);
KualiDecimal newKualiDecimalValue = new KualiDecimal(newValue.setScale(2, RoundingMode.DOWN));
invD.setInvoiceAmount(newKualiDecimalValue);
amountToBill = amountToBill.add(newKualiDecimalValue);
if (newValue.compareTo(largestAmount) > 0) {
largestAmount = newKualiDecimalValue.bigDecimalValue();
largestCostCategory = invD;
}
}
if (!amountToBill.equals(amountEligibleForBilling)) {
KualiDecimal remaining = amountEligibleForBilling.subtract(amountToBill);
if (ObjectUtils.isNull(largestCostCategory) && CollectionUtils.isNotEmpty(contractsGrantsInvoiceDocument.getInvoiceDetails())) {
largestCostCategory = contractsGrantsInvoiceDocument.getInvoiceDetails().get(0);
}
if (ObjectUtils.isNotNull(largestCostCategory)) {
largestCostCategory.setInvoiceAmount(largestCostCategory.getInvoiceAmount().add(remaining));
}
}
recalculateTotalAmountBilledToDate(contractsGrantsInvoiceDocument);
}
}
}
Aggregations