use of org.kuali.kfs.module.ar.businessobject.InvoiceBill 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