use of org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method takeAPennyLeaveAPennyCGBStyle.
/**
* If the total of current expenditures within the list of InvoiceDetailAccountObjectCode business objects does
* not meet the amount to target, steal or give a penny from one of those business objects so that it does
*
* @param invoiceDetailAccountObjectCodes a List of InvoiceDetailAccountObjectCode business objects
* @param amountToTarget the amount which the sum of those objects should equal
*/
protected void takeAPennyLeaveAPennyCGBStyle(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, KualiDecimal amountToTarget) {
if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodes)) {
final KualiDecimal currentExpenditureTotal = sumInvoiceDetailAccountObjectCodes(invoiceDetailAccountObjectCodes).getCurrentExpenditures();
if (!currentExpenditureTotal.equals(amountToTarget)) {
final KualiDecimal difference = currentExpenditureTotal.subtract(amountToTarget);
InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = findFirstPositiveCurrentExpenditureInvoiceDetailAccountObjectCode(invoiceDetailAccountObjectCodes);
if (invoiceDetailAccountObjectCode != null) {
invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().subtract(difference));
}
}
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode 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);
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method addToAccountObjectCodeBilledTotal.
@Override
public void addToAccountObjectCodeBilledTotal(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes) {
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
Map<String, Object> totalBilledKeys = new HashMap<>();
totalBilledKeys.put(KFSPropertyConstants.PROPOSAL_NUMBER, invoiceDetailAccountObjectCode.getProposalNumber());
totalBilledKeys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, invoiceDetailAccountObjectCode.getChartOfAccountsCode());
totalBilledKeys.put(KFSPropertyConstants.ACCOUNT_NUMBER, invoiceDetailAccountObjectCode.getAccountNumber());
totalBilledKeys.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, invoiceDetailAccountObjectCode.getFinancialObjectCode());
List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilledList = (List<AwardAccountObjectCodeTotalBilled>) businessObjectService.findMatching(AwardAccountObjectCodeTotalBilled.class, totalBilledKeys);
AwardAccountObjectCodeTotalBilled awardAccountObjectCodeTotalBilled = new AwardAccountObjectCodeTotalBilled();
if (awardAccountObjectCodeTotalBilledList != null && !awardAccountObjectCodeTotalBilledList.isEmpty()) {
awardAccountObjectCodeTotalBilled = awardAccountObjectCodeTotalBilledList.get(0);
awardAccountObjectCodeTotalBilled.setTotalBilled(awardAccountObjectCodeTotalBilled.getTotalBilled().add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
} else {
awardAccountObjectCodeTotalBilled.setProposalNumber(invoiceDetailAccountObjectCode.getProposalNumber());
awardAccountObjectCodeTotalBilled.setChartOfAccountsCode(invoiceDetailAccountObjectCode.getChartOfAccountsCode());
awardAccountObjectCodeTotalBilled.setAccountNumber(invoiceDetailAccountObjectCode.getAccountNumber());
awardAccountObjectCodeTotalBilled.setFinancialObjectCode(invoiceDetailAccountObjectCode.getFinancialObjectCode());
awardAccountObjectCodeTotalBilled.setTotalBilled(invoiceDetailAccountObjectCode.getCurrentExpenditures());
}
getBusinessObjectService().save(awardAccountObjectCodeTotalBilled);
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method recalculateObjectCodeByCategory.
/**
* This method recalculates the invoiceDetailAccountObjectCode in one category that sits behind the scenes of the
* invoice document.
*
* @param contractsGrantsInvoiceDocument
* @param invoiceDetail
* @param total is the sum of the current expenditures from all the object codes in
* that category
* @param invoiceDetailAccountObjectCodes
*/
protected void recalculateObjectCodeByCategory(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument, ContractsGrantsInvoiceDetail invoiceDetail, KualiDecimal total, List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes) {
KualiDecimal currentExpenditure = invoiceDetail.getInvoiceAmount();
KualiDecimal newTotalAmount = KualiDecimal.ZERO;
// the category
if (total.compareTo(KualiDecimal.ZERO) == 0) {
if (invoiceDetailAccountObjectCodes != null) {
int numberOfObjectCodes = invoiceDetailAccountObjectCodes.size();
if (numberOfObjectCodes != 0) {
KualiDecimal newAmount = new KualiDecimal(currentExpenditure.bigDecimalValue().divide(new BigDecimal(numberOfObjectCodes), 10, RoundingMode.HALF_DOWN));
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
invoiceDetailAccountObjectCode.setCurrentExpenditures(newAmount);
newTotalAmount = newTotalAmount.add(newAmount);
}
}
} else {
// if the list is null, then there are no account/object code in the gl_balance_t. So assign the
// amount to the first object code in the category
assignCurrentExpenditureToNonExistingAccountObjectCode(contractsGrantsInvoiceDocument, invoiceDetail);
}
} else {
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
// this may rarely happen
// if the initial total is 0, that means none of the object codes in this category is set to bill.
// If this amount is changed, then just divide evenly among all object codes.
KualiDecimal newAmount = new KualiDecimal(invoiceDetailAccountObjectCode.getCurrentExpenditures().bigDecimalValue().divide(total.bigDecimalValue(), 10, RoundingMode.HALF_DOWN).multiply(currentExpenditure.bigDecimalValue()));
invoiceDetailAccountObjectCode.setCurrentExpenditures(newAmount);
newTotalAmount = newTotalAmount.add(newAmount);
}
int remainderFromRounding = currentExpenditure.subtract(newTotalAmount).multiply(new KualiDecimal(100)).intValue();
// add remainder from rounding
KualiDecimal addAmount = new KualiDecimal(0.01);
if (remainderFromRounding < 0) {
addAmount = new KualiDecimal(-0.01);
remainderFromRounding = Math.abs(remainderFromRounding);
}
int objectCodeIndex = 0;
for (int i = 0; i < remainderFromRounding; i++) {
InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = invoiceDetailAccountObjectCodes.get(objectCodeIndex);
invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().add(addAmount));
objectCodeIndex++;
if (objectCodeIndex >= invoiceDetailAccountObjectCodes.size()) {
objectCodeIndex = 0;
}
}
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method getCategoryExpenditureAmountsForInvoiceAccountDetail.
/**
* Totals the current expenditure amounts of any invoice detail account object codes on the document which have set
* categories by account numbers
*
* @param contractsGrantsInvoiceDocument the document holding invoice detail account object codes
* @return a Map where the key is the concatenation of chartOfAccountsCode-accountNumber and the value is the
* expenditure amount on that account
*/
protected Map<String, KualiDecimal> getCategoryExpenditureAmountsForInvoiceAccountDetail(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
Map<String, KualiDecimal> expenditureAmounts = new HashMap<>();
for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : contractsGrantsInvoiceDocument.getInvoiceDetailAccountObjectCodes()) {
final String accountKey = StringUtils.join(new String[] { invoiceDetailAccountObjectCode.getChartOfAccountsCode(), invoiceDetailAccountObjectCode.getAccountNumber() }, "-");
if (StringUtils.isNotBlank(invoiceDetailAccountObjectCode.getCategoryCode())) {
KualiDecimal total = expenditureAmounts.get(accountKey);
if (ObjectUtils.isNull(total)) {
total = KualiDecimal.ZERO;
}
expenditureAmounts.put(accountKey, total.add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
}
}
return expenditureAmounts;
}
Aggregations