use of org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method mapAwardAccountObjectCodeTotalBilledsByCategoryCode.
/**
* Converts a List of AwardAccountObjectCodeTotalBilled into a Map, keyed by the Cost Category which most closely
* matches them
*
* @param awardAccountObjectCodeTotalBilleds the List of AwardAccountObjectCodeTotalBilled business objects to Map
* @return the Mapped AwardAccountObjectCodeTotalBilled records
*/
protected Map<String, List<AwardAccountObjectCodeTotalBilled>> mapAwardAccountObjectCodeTotalBilledsByCategoryCode(List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds) {
Integer fiscalYear = getUniversityDateService().getCurrentFiscalYear();
Map<String, List<AwardAccountObjectCodeTotalBilled>> billedsMap = new HashMap<>();
for (AwardAccountObjectCodeTotalBilled billed : awardAccountObjectCodeTotalBilleds) {
final CostCategory category = getCostCategoryService().getCostCategoryForObjectCode(fiscalYear, billed.getChartOfAccountsCode(), billed.getFinancialObjectCode());
if (!ObjectUtils.isNull(category)) {
List<AwardAccountObjectCodeTotalBilled> billedForCategory = billedsMap.get(category.getCategoryCode());
if (billedForCategory == null) {
billedForCategory = new ArrayList<>();
}
billedForCategory.add(billed);
billedsMap.put(category.getCategoryCode(), billedForCategory);
} else {
LOG.warn("Could not find cost category for AwardAccountObjectCodeTotalBilled, fiscal year = " + fiscalYear + " " + billed.getChartOfAccountsCode() + " " + billed.getFinancialObjectCode());
}
}
return billedsMap;
}
use of org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled 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.AwardAccountObjectCodeTotalBilled 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.AwardAccountObjectCodeTotalBilled in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method populateInvoiceFromAward.
/*
* CU Customization (KFSPTS-23675):
* Added creationProcessType argument and its usage of it.
*/
/**
* This method takes all the applicable attributes from the associated award object and sets those attributes into
* their corresponding invoice attributes.
*
* @param award The associated award that the invoice will be linked to.
* @param awardAccounts
* @param document
* @param accountDetails letter of credit details if we're creating via loc
* @param locCreationType letter of credit creation type if we're creating via loc
* @param creationProcessType The creation process type for the related invoice
*/
protected void populateInvoiceFromAward(ContractsAndGrantsBillingAward award, List<ContractsAndGrantsBillingAwardAccount> awardAccounts, ContractsGrantsInvoiceDocument document, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
if (ObjectUtils.isNotNull(award)) {
InvoiceGeneralDetail invoiceGeneralDetail = new InvoiceGeneralDetail();
invoiceGeneralDetail.setDocumentNumber(document.getDocumentNumber());
invoiceGeneralDetail.setProposalNumber(award.getProposalNumber());
invoiceGeneralDetail.setAward(award);
Timestamp ts = new Timestamp(new java.util.Date().getTime());
java.sql.Date today = new java.sql.Date(ts.getTime());
AccountingPeriod currPeriod = accountingPeriodService.getByDate(today);
BillingPeriod billingPeriod = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod, creationProcessType);
invoiceGeneralDetail.setBillingPeriod(getDateTimeService().toDateString(billingPeriod.getStartDate()) + " to " + getDateTimeService().toDateString(billingPeriod.getEndDate()));
invoiceGeneralDetail.setLastBilledDate(billingPeriod.getEndDate());
populateInvoiceDetailFromAward(invoiceGeneralDetail, award);
document.setInvoiceGeneralDetail(invoiceGeneralDetail);
// To set Bill by address identifier because it is a required field - set the value to 1 as it is never
// being used.
document.setCustomerBillToAddressIdentifier(1);
// Set Invoice due date to current date as it is required field and never used.
document.setInvoiceDueDate(dateTimeService.getCurrentSqlDateMidnight());
document.getInvoiceAddressDetails().clear();
ContractsAndGrantsBillingAgency agency = award.getAgency();
if (ObjectUtils.isNotNull(agency)) {
final List<InvoiceAddressDetail> invoiceAddressDetails = buildInvoiceAddressDetails(award, document);
document.getInvoiceAddressDetails().addAll(invoiceAddressDetails);
}
if (ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail())) {
ContractsAndGrantsBillingAwardAccount awardAccount = awardAccounts.get(0);
final List<Milestone> milestones = getContractsGrantsBillingUtilityService().getActiveMilestonesForProposalNumber(award.getProposalNumber(), awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber());
if (!CollectionUtils.isEmpty(milestones)) {
document.getInvoiceMilestones().clear();
document.getInvoiceMilestones().addAll(buildInvoiceMilestones(milestones));
}
} else if (ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail())) {
ContractsAndGrantsBillingAwardAccount awardAccount = awardAccounts.get(0);
final List<Bill> bills = getContractsGrantsBillingUtilityService().getActiveBillsForAwardAccount(award.getProposalNumber(), awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber());
if (!CollectionUtils.isEmpty(bills)) {
document.getInvoiceBills().clear();
document.getInvoiceBills().addAll(buildInvoiceBills(bills));
}
}
document.getAccountDetails().clear();
final List<InvoiceAccountDetail> invoiceAccountDetails = new ArrayList<>();
List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectsCodes = new ArrayList<>();
Map<String, KualiDecimal> budgetAmountsByCostCategory = new HashMap<>();
Integer currentYear = getUniversityDateService().getCurrentFiscalYear();
final boolean firstFiscalPeriod = isFirstFiscalPeriod();
final Integer fiscalYear = firstFiscalPeriod && ArConstants.BillingFrequencyValues.isTimeBased(document.getInvoiceGeneralDetail()) ? currentYear - 1 : currentYear;
final SystemOptions systemOptions = optionsService.getOptions(fiscalYear);
List<String> balanceTypeCodeList = new ArrayList<>();
balanceTypeCodeList.add(systemOptions.getBudgetCheckingBalanceTypeCd());
balanceTypeCodeList.add(systemOptions.getActualFinancialBalanceTypeCd());
for (ContractsAndGrantsBillingAwardAccount awardAccount : awardAccounts) {
InvoiceAccountDetail invoiceAccountDetail = buildInvoiceAccountDetailForAwardAccount(awardAccount, document.getDocumentNumber());
final ContractsGrantsLetterOfCreditReviewDetail locReviewDetail = retrieveMatchingLetterOfCreditReviewDetail(awardAccount, accountDetails);
List<Balance> glBalances = retrieveBalances(fiscalYear, awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber(), balanceTypeCodeList);
KualiDecimal awardAccountBudgetAmount = KualiDecimal.ZERO;
KualiDecimal awardAccountCumulativeAmount = KualiDecimal.ZERO;
for (Balance balance : glBalances) {
if (!isBalanceCostShare(balance)) {
if (balance.getBalanceTypeCode().equalsIgnoreCase(systemOptions.getBudgetCheckingBalanceTypeCd())) {
awardAccountBudgetAmount = addBalanceToAwardAccountBudgetAmount(balance, awardAccountBudgetAmount, firstFiscalPeriod);
updateCategoryBudgetAmountsByBalance(balance, budgetAmountsByCostCategory, firstFiscalPeriod);
} else if (balance.getBalanceTypeCode().equalsIgnoreCase(systemOptions.getActualFinancialBalanceTypeCd())) {
awardAccountCumulativeAmount = addBalanceToAwardAccountCumulativeAmount(document, balance, award, awardAccountCumulativeAmount, firstFiscalPeriod);
updateCategoryActualAmountsByBalance(document, balance, award, invoiceDetailAccountObjectsCodes, firstFiscalPeriod);
}
}
invoiceAccountDetail.setTotalBudget(awardAccountBudgetAmount);
invoiceAccountDetail.setCumulativeExpenditures(awardAccountCumulativeAmount);
}
invoiceAccountDetails.add(invoiceAccountDetail);
if (!ObjectUtils.isNull(locReviewDetail) && !locReviewDetail.getClaimOnCashBalance().negated().equals(locReviewDetail.getAmountToDraw()) && ArConstants.BillingFrequencyValues.isLetterOfCredit(award)) {
distributeAmountAmongAllAccountObjectCodes(document, awardAccount, invoiceDetailAccountObjectsCodes, locReviewDetail);
} else {
updateInvoiceDetailAccountObjectCodesByBilledAmount(awardAccount, invoiceDetailAccountObjectsCodes);
}
}
document.getAccountDetails().addAll(invoiceAccountDetails);
if (!ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail()) && !ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail())) {
document.getInvoiceDetailAccountObjectCodes().addAll(invoiceDetailAccountObjectsCodes);
List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds = getAwardAccountObjectCodeTotalBilledDao().getAwardAccountObjectCodeTotalBuildByProposalNumberAndAccount(awardAccounts);
List<ContractsGrantsInvoiceDetail> invoiceDetails = generateValuesForCategories(document.getDocumentNumber(), document.getInvoiceDetailAccountObjectCodes(), budgetAmountsByCostCategory, awardAccountObjectCodeTotalBilleds);
document.getInvoiceDetails().addAll(invoiceDetails);
}
populateContractsGrantsInvoiceDocument(award, document, accountDetails, locCreationType);
}
}
Aggregations