use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildTotalCostInvoiceDetailFieldsMap.
private Map<String, Object> buildTotalCostInvoiceDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> totalCostInvoiceDetailFieldsMap = new HashMap<>();
ContractsGrantsInvoiceDetail totalCostInvoiceDetail = document.getTotalCostInvoiceDetail();
if (ObjectUtils.isNotNull(totalCostInvoiceDetail)) {
final String prefix = ArPropertyConstants.TOTAL_INVOICE_DETAIL + ".";
totalCostInvoiceDetailFieldsMap.putAll(buildInvoiceDetailFieldMap(prefix, totalCostInvoiceDetail));
}
return totalCostInvoiceDetailFieldsMap;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method generateValuesForCategories.
/**
* 1. This method is responsible to populate categories column for the ContractsGrantsInvoice Document. 2. The
* categories are retrieved from the Maintenance document as a collection and then a logic with conditions to
* handle ranges of Object Codes. 3. Once the object codes are retrieved and categories are set the
* performAccountingCalculations method of InvoiceDetail BO will do all the accounting calculations.
*
* @param documentNumber the number of the document we want to add invoice details to
* @param invoiceDetailAccountObjectCodes the List of InvoiceDetailAccountObjectCodes containing amounts to
* sum into our invoice details
* @param budgetAmountsByCostCategory the budget amounts, sorted by cost category
* @param awardAccountObjectCodeTotalBilleds the business objects containing what has been billed from the
* document's award accounts already
*/
public List<ContractsGrantsInvoiceDetail> generateValuesForCategories(String documentNumber, List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, Map<String, KualiDecimal> budgetAmountsByCostCategory, List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds) {
Collection<CostCategory> costCategories = retrieveAllBillingCategories();
List<ContractsGrantsInvoiceDetail> invoiceDetails = new ArrayList<>();
Map<String, List<InvoiceDetailAccountObjectCode>> invoiceDetailAccountObjectCodesMap = mapInvoiceDetailAccountObjectCodesByCategoryCode(invoiceDetailAccountObjectCodes);
Map<String, List<AwardAccountObjectCodeTotalBilled>> billedsMap = mapAwardAccountObjectCodeTotalBilledsByCategoryCode(awardAccountObjectCodeTotalBilleds);
for (CostCategory category : costCategories) {
ContractsGrantsInvoiceDetail invDetail = new ContractsGrantsInvoiceDetail();
invDetail.setDocumentNumber(documentNumber);
invDetail.setCategoryCode(category.getCategoryCode());
invDetail.setCostCategory(category);
invDetail.setIndirectCostIndicator(category.isIndirectCostIndicator());
// calculate total billed first
invDetail.setCumulativeExpenditures(KualiDecimal.ZERO);
invDetail.setInvoiceAmount(KualiDecimal.ZERO);
invDetail.setTotalPreviouslyBilled(KualiDecimal.ZERO);
List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodesForCategory = invoiceDetailAccountObjectCodesMap.get(category.getCategoryCode());
if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodesForCategory)) {
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodesForCategory) {
invDetail.setCumulativeExpenditures(invDetail.getCumulativeExpenditures().add(invoiceDetailAccountObjectCode.getCumulativeExpenditures()));
invDetail.setInvoiceAmount(invDetail.getInvoiceAmount().add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
}
}
List<AwardAccountObjectCodeTotalBilled> billedForCategory = billedsMap.get(category.getCategoryCode());
if (!CollectionUtils.isEmpty(billedForCategory)) {
for (AwardAccountObjectCodeTotalBilled accountObjectCodeTotalBilled : billedForCategory) {
// this adds up all the total billed based on object code into categories; sum for this category.
invDetail.setTotalPreviouslyBilled(invDetail.getTotalPreviouslyBilled().add(accountObjectCodeTotalBilled.getTotalBilled()));
}
}
// calculate the rest using billed to date
if (!ObjectUtils.isNull(budgetAmountsByCostCategory.get(category.getCategoryCode()))) {
invDetail.setTotalBudget(budgetAmountsByCostCategory.get(category.getCategoryCode()));
} else {
invDetail.setTotalBudget(KualiDecimal.ZERO);
}
invoiceDetails.add(invDetail);
}
return invoiceDetails;
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class CuContractsGrantsInvoiceDocumentServiceImpl method prorateBill.
@Override
public void prorateBill(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
LOG.debug("prorateBill, entering");
// Amount to be billed on
KualiDecimal totalCost = new KualiDecimal(0);
// manually changed the value
for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
totalCost = totalCost.add(invD.getInvoiceAmount());
}
// Total Billed so far
KualiDecimal billedTotalCost = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getTotalPreviouslyBilled();
// CU Customization, use award budget total, and not the award total
// KualiDecimal accountAwardTotal = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAwardTotal();
Award award = (Award) contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAward();
AwardExtendedAttribute awardExtension = (AwardExtendedAttribute) award.getExtension();
KualiDecimal accountAwardTotal = awardExtension.getBudgetTotalAmount();
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);
}
}
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class CuContractsGrantsInvoiceDocumentServiceImpl method getInstitutionTemplateParameters.
protected Map<String, String> getInstitutionTemplateParameters(ContractsGrantsInvoiceDocument document) {
Map<String, Object> localParameterMap = new HashMap<String, Object>();
if (document.getInvoiceGeneralDetail().isFinalBillIndicator()) {
localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.FINAL_BILL, CUKFSConstants.CAPITAL_X);
localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.PARTIAL_BILL, StringUtils.EMPTY);
} else {
localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.FINAL_BILL, StringUtils.EMPTY);
localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.PARTIAL_BILL, CUKFSConstants.CAPITAL_X);
}
ContractsGrantsInvoiceDetail totalCostInvoiceDetail = document.getTotalCostInvoiceDetail();
if (ObjectUtils.isNotNull(totalCostInvoiceDetail)) {
localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.TOTAL_PROGRAM_OUTLAYS_TO_DATE, totalCostInvoiceDetail.getTotalAmountBilledToDate().add(document.getInvoiceGeneralDetail().getCostShareAmount()));
}
setAwardExtendedAttributeValuesInParameterMap(document, localParameterMap);
setPurchaseOrderNumberFieldInParameterMap(document, localParameterMap);
if (!localParameterMap.isEmpty()) {
LOG.debug("getInstitutionTemplateParameters, there were local parameters, these will be in the returned map.");
}
return localParameterMap.keySet().stream().collect(Collectors.toMap(key -> key, key -> stringifyValue(localParameterMap.get(key)), (a, b) -> b));
}
use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method correctContractsGrantsInvoiceDocument.
@Override
public void correctContractsGrantsInvoiceDocument(ContractsGrantsInvoiceDocument document) {
// correct Direct Cost Invoice Details.
for (ContractsGrantsInvoiceDetail id : document.getDirectCostInvoiceDetails()) {
correctInvoiceDetail(id);
}
// correct Indirect Cost Invoice Details.
for (ContractsGrantsInvoiceDetail id : document.getIndirectCostInvoiceDetails()) {
correctInvoiceDetail(id);
}
// update correction to the InvoiceAccountDetail objects
for (InvoiceAccountDetail id : document.getAccountDetails()) {
correctInvoiceAccountDetail(id);
}
// correct invoiceDetailAccountObjectCode.
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : document.getInvoiceDetailAccountObjectCodes()) {
invoiceDetailAccountObjectCode.correctInvoiceDetailAccountObjectCodeExpenditureAmount();
}
// correct Bills
KualiDecimal totalBillingAmount = KualiDecimal.ZERO;
for (InvoiceBill bill : document.getInvoiceBills()) {
bill.setEstimatedAmount(bill.getEstimatedAmount().negated());
totalBillingAmount = totalBillingAmount.add(bill.getEstimatedAmount());
}
// correct Milestones
KualiDecimal totalMilestonesAmount = KualiDecimal.ZERO;
for (InvoiceMilestone milestone : document.getInvoiceMilestones()) {
milestone.setMilestoneAmount(milestone.getMilestoneAmount().negated());
totalMilestonesAmount = totalMilestonesAmount.add(milestone.getMilestoneAmount());
}
document.getInvoiceGeneralDetail().setTotalPreviouslyBilled(getAwardBilledToDateAmountExcludingDocument(document.getInvoiceGeneralDetail().getProposalNumber(), document.getDocumentNumber()));
if (ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceMilestones())) {
document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalMilestonesAmount));
} else if (ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceBills())) {
document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalBillingAmount));
} else {
KualiDecimal newTotalBilled = document.getTotalCostInvoiceDetail().getInvoiceAmount().add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
newTotalBilled = newTotalBilled.add(getOtherTotalBilledForAwardPeriod(document));
document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(newTotalBilled);
calculatePreviouslyBilledAmounts(document);
}
for (InvoiceAddressDetail invoiceAddressDetail : document.getInvoiceAddressDetails()) {
invoiceAddressDetail.setInitialTransmissionDate(null);
invoiceAddressDetail.setTransmittedByPrincipalId("");
invoiceAddressDetail.setTransmissionDate(null);
invoiceAddressDetail.setTransmissionStatusCode("");
invoiceAddressDetail.setTransmissionCount(0);
}
}
Aggregations