use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createInvoices.
/**
* This method iterates through awards and create cgInvoice documents
*
* @param awards used to create cgInvoice documents
* @param creationProcessType creation process type
* @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
* @return List of error messages (if any)
*/
protected List<ErrorMessage> createInvoices(Collection<ContractsAndGrantsBillingAward> awards, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
List<ErrorMessage> errorMessages = new ArrayList<>();
if (ObjectUtils.isNotNull(awards) && awards.size() > 0) {
for (ContractsAndGrantsBillingAward awd : awards) {
String invOpt = awd.getInvoicingOptionCode();
final ContractsAndGrantsOrganization awardOrganization = awd.getPrimaryAwardOrganization();
if (ObjectUtils.isNull(awardOrganization)) {
final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_ORGANIZATION_ON_AWARD, awd.getProposalNumber());
errorMessages.add(errorMessage);
} else {
switch(invOpt) {
case ArConstants.INV_ACCOUNT:
case ArConstants.INV_SCHEDULE:
createInvoicesByAccounts(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
break;
case ArConstants.INV_CONTRACT_CONTROL_ACCOUNT:
createInvoicesByContractControlAccounts(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
break;
case ArConstants.INV_AWARD:
createInvoicesByAward(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
break;
default:
break;
}
}
}
} else {
final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_AWARD);
errorMessages.add(errorMessage);
}
return errorMessages;
}
use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method storeValidationErrors.
protected void storeValidationErrors(Map<ContractsAndGrantsBillingAward, List<String>> invalidGroup, Collection<ContractsGrantsInvoiceDocumentErrorLog> contractsGrantsInvoiceDocumentErrorLogs, String creationProcessTypeCode) {
for (ContractsAndGrantsBillingAward award : invalidGroup.keySet()) {
KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
ContractsGrantsInvoiceDocumentErrorLog contractsGrantsInvoiceDocumentErrorLog = new ContractsGrantsInvoiceDocumentErrorLog();
if (ObjectUtils.isNotNull(award)) {
Date beginningDate = award.getAwardBeginningDate();
Date endingDate = award.getAwardEndingDate();
final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
contractsGrantsInvoiceDocumentErrorLog.setProposalNumber(award.getProposalNumber());
contractsGrantsInvoiceDocumentErrorLog.setAwardBeginningDate(beginningDate);
contractsGrantsInvoiceDocumentErrorLog.setAwardEndingDate(endingDate);
contractsGrantsInvoiceDocumentErrorLog.setAwardTotalAmount(award.getAwardTotalAmount().bigDecimalValue());
if (ObjectUtils.isNotNull(award.getAwardPrimaryFundManager())) {
contractsGrantsInvoiceDocumentErrorLog.setPrimaryFundManagerPrincipalId(award.getAwardPrimaryFundManager().getPrincipalId());
}
if (!CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
boolean firstLineFlag = true;
for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
if (firstLineFlag) {
firstLineFlag = false;
contractsGrantsInvoiceDocumentErrorLog.setAccounts(awardAccount.getAccountNumber());
} else {
contractsGrantsInvoiceDocumentErrorLog.setAccounts(contractsGrantsInvoiceDocumentErrorLog.getAccounts() + ";" + awardAccount.getAccountNumber());
}
}
}
contractsGrantsInvoiceDocumentErrorLog.setCumulativeExpensesAmount(cumulativeExpenses.bigDecimalValue());
}
for (String vCat : invalidGroup.get(award)) {
ContractsGrantsInvoiceDocumentErrorMessage contractsGrantsInvoiceDocumentErrorCategory = new ContractsGrantsInvoiceDocumentErrorMessage();
contractsGrantsInvoiceDocumentErrorCategory.setErrorMessageText(vCat);
contractsGrantsInvoiceDocumentErrorLog.getErrorMessages().add(contractsGrantsInvoiceDocumentErrorCategory);
}
int errorAccountsMax = dataDictionaryService.getAttributeMaxLength(ContractsGrantsInvoiceDocumentErrorLog.class, ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS);
contractsGrantsInvoiceDocumentErrorLog.setAccounts(StringUtils.left(contractsGrantsInvoiceDocumentErrorLog.getAccounts(), errorAccountsMax));
contractsGrantsInvoiceDocumentErrorLog.setErrorDate(dateTimeService.getCurrentTimestamp());
contractsGrantsInvoiceDocumentErrorLog.setCreationProcessTypeCode(creationProcessTypeCode);
businessObjectService.save(contractsGrantsInvoiceDocumentErrorLog);
contractsGrantsInvoiceDocumentErrorLogs.add(contractsGrantsInvoiceDocumentErrorLog);
}
}
use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildInvoiceGeneralDetailFieldsMap.
private Map<String, Object> buildInvoiceGeneralDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> invoiceGeneralDetailFieldsMap = new HashMap<>();
InvoiceGeneralDetail invoiceGeneralDetail = document.getInvoiceGeneralDetail();
if (ObjectUtils.isNotNull(invoiceGeneralDetail)) {
invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.ADVANCE_FLAG, ArConstants.BillingFrequencyValues.isPredeterminedBilling(invoiceGeneralDetail));
invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.REIMBURSEMENT_FLAG, !ArConstants.BillingFrequencyValues.isPredeterminedBilling(invoiceGeneralDetail));
invoiceGeneralDetailFieldsMap.put(KFSPropertyConstants.PROPOSAL_NUMBER, invoiceGeneralDetail.getProposalNumber());
final String prefix = ArPropertyConstants.INVOICE_GENERAL_DETAIL + ".";
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.AWARD_DATE_RANGE, invoiceGeneralDetail.getAwardDateRange());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.BILLING_FREQUENCY_CODE, invoiceGeneralDetail.getBillingFrequencyCode());
invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.FINAL_BILL, invoiceGeneralDetail.isFinalBillIndicator());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.BILLING_PERIOD, invoiceGeneralDetail.getBillingPeriod());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.INSTRUMENT_TYPE_CODE, invoiceGeneralDetail.getInstrumentTypeCode());
invoiceGeneralDetailFieldsMap.put(prefix + ArConstants.AWARD_TOTAL, invoiceGeneralDetail.getAwardTotal());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.AMOUNT_REMAINING_TO_BILL, invoiceGeneralDetail.getAmountRemainingToBill());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.COST_SHARE_AMOUNT, invoiceGeneralDetail.getCostShareAmount());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.LAST_BILLED_DATE, invoiceGeneralDetail.getLastBilledDate());
invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.TOTAL_PREVIOUSLY_BILLED, invoiceGeneralDetail.getTotalPreviouslyBilled());
invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.TOTAL_AMOUNT_DUE, getTotalAmountForInvoice(document));
invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER + "." + ArPropertyConstants.FULL_ADDRESS, contractsGrantsBillingUtilityService.buildFullAddress(invoiceGeneralDetail.getCustomerAddress()));
ContractsAndGrantsBillingAward award = invoiceGeneralDetail.getAward();
if (ObjectUtils.isNotNull(award)) {
invoiceGeneralDetailFieldsMap.putAll(buildAwardFieldsMap(award));
}
}
return invoiceGeneralDetailFieldsMap;
}
use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method determineContractControlAccountNumber.
// access relaxed for Cornell
protected String determineContractControlAccountNumber(ContractsGrantsInvoiceDocument document) {
final InvoiceGeneralDetail invoiceGeneralDetail = document.getInvoiceGeneralDetail();
if (ObjectUtils.isNotNull(invoiceGeneralDetail)) {
final ContractsAndGrantsBillingAward award = invoiceGeneralDetail.getAward();
if (ObjectUtils.isNotNull(award)) {
final List<Account> contractControlAccounts = getContractControlAccounts(award);
if (CollectionUtils.isNotEmpty(contractControlAccounts)) {
return contractControlAccounts.get(0).getAccountNumber();
}
}
}
final List<InvoiceAccountDetail> accountDetails = document.getAccountDetails();
if (CollectionUtils.isNotEmpty(accountDetails)) {
return accountDetails.get(0).getAccountNumber();
}
return null;
}
use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward in project cu-kfs by CU-CommunityApps.
the class CuContractsGrantsInvoiceCreateDocumentServiceImpl method storeValidationErrors.
/**
* Fixes NullPointerException that can occur when getting the award total amount.
* award.getAwardTotalAmount().bigDecimalValue() causes the NullPointerException if the total amount returned null.
*/
@Override
protected void storeValidationErrors(Map<ContractsAndGrantsBillingAward, List<String>> invalidGroup, Collection<ContractsGrantsInvoiceDocumentErrorLog> contractsGrantsInvoiceDocumentErrorLogs, String creationProcessTypeCode) {
for (ContractsAndGrantsBillingAward award : invalidGroup.keySet()) {
KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
ContractsGrantsInvoiceDocumentErrorLog contractsGrantsInvoiceDocumentErrorLog = new ContractsGrantsInvoiceDocumentErrorLog();
if (ObjectUtils.isNotNull(award)) {
Date beginningDate = award.getAwardBeginningDate();
Date endingDate = award.getAwardEndingDate();
final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
contractsGrantsInvoiceDocumentErrorLog.setProposalNumber(award.getProposalNumber());
contractsGrantsInvoiceDocumentErrorLog.setAwardBeginningDate(beginningDate);
contractsGrantsInvoiceDocumentErrorLog.setAwardEndingDate(endingDate);
KualiDecimal awardTotalAmount = award.getAwardTotalAmount() == null ? KualiDecimal.ZERO : award.getAwardTotalAmount();
contractsGrantsInvoiceDocumentErrorLog.setAwardTotalAmount(awardTotalAmount.bigDecimalValue());
if (ObjectUtils.isNotNull(award.getAwardPrimaryFundManager())) {
contractsGrantsInvoiceDocumentErrorLog.setPrimaryFundManagerPrincipalId(award.getAwardPrimaryFundManager().getPrincipalId());
}
if (!CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
boolean firstLineFlag = true;
for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
if (firstLineFlag) {
firstLineFlag = false;
contractsGrantsInvoiceDocumentErrorLog.setAccounts(awardAccount.getAccountNumber());
} else {
contractsGrantsInvoiceDocumentErrorLog.setAccounts(contractsGrantsInvoiceDocumentErrorLog.getAccounts() + ";" + awardAccount.getAccountNumber());
}
}
}
contractsGrantsInvoiceDocumentErrorLog.setCumulativeExpensesAmount(cumulativeExpenses.bigDecimalValue());
}
for (String vCat : invalidGroup.get(award)) {
ContractsGrantsInvoiceDocumentErrorMessage contractsGrantsInvoiceDocumentErrorCategory = new ContractsGrantsInvoiceDocumentErrorMessage();
contractsGrantsInvoiceDocumentErrorCategory.setErrorMessageText(vCat);
contractsGrantsInvoiceDocumentErrorLog.getErrorMessages().add(contractsGrantsInvoiceDocumentErrorCategory);
}
int errorAccountsMax = dataDictionaryService.getAttributeMaxLength(ContractsGrantsInvoiceDocumentErrorLog.class, ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS);
contractsGrantsInvoiceDocumentErrorLog.setAccounts(StringUtils.left(contractsGrantsInvoiceDocumentErrorLog.getAccounts(), errorAccountsMax));
contractsGrantsInvoiceDocumentErrorLog.setErrorDate(dateTimeService.getCurrentTimestamp());
contractsGrantsInvoiceDocumentErrorLog.setCreationProcessTypeCode(creationProcessTypeCode);
businessObjectService.save(contractsGrantsInvoiceDocumentErrorLog);
contractsGrantsInvoiceDocumentErrorLogs.add(contractsGrantsInvoiceDocumentErrorLog);
}
}
Aggregations