use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail 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.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method createSourceAccountingLinesByAward.
/**
* Generates the source accounting lines for a Contracts & Grants Invoice from the award accounts associated with
* an award (in the form of the pre-generated invoice account details)
*
* @param contractsGrantsInvoiceDocument the Contracts & Grants Invoice to create invoice details for
* @return a List of generated accounting lines
*/
protected List<CustomerInvoiceDetail> createSourceAccountingLinesByAward(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
List<CustomerInvoiceDetail> awardAccountingLines = new ArrayList<>();
if (!CollectionUtils.isEmpty(contractsGrantsInvoiceDocument.getAccountDetails())) {
final Map<String, KualiDecimal> accountExpenditureAmounts = getCategoryExpenditureAmountsForInvoiceAccountDetail(contractsGrantsInvoiceDocument);
final Map<String, KualiDecimal> accountTotalBilledAmounts = getCategoryTotalBilledAmountsForInvoiceAccountDetail(contractsGrantsInvoiceDocument);
for (InvoiceAccountDetail invAcctD : contractsGrantsInvoiceDocument.getAccountDetails()) {
final String proposalNumber = invAcctD.getProposalNumber();
final String chartOfAccountsCode = invAcctD.getChartOfAccountsCode();
final String accountNumber = invAcctD.getAccountNumber();
if (invAcctD.getAccount() == null) {
invAcctD.refreshReferenceObject(KFSPropertyConstants.ACCOUNT);
}
final SubFundGroup subFundGroup = invAcctD.getAccount().getSubFundGroup();
final Integer sequenceNumber = contractsGrantsInvoiceDocument.getAccountDetails().indexOf(invAcctD) + 1;
final String accountKey = StringUtils.join(new String[] { chartOfAccountsCode, accountNumber }, "-");
KualiDecimal totalAmount = accountExpenditureAmounts.getOrDefault(accountKey, KualiDecimal.ZERO);
if (invAcctD.getTotalPreviouslyBilled().isZero()) {
KualiDecimal previouslyBilledAmount = getPredeterminedBillingBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber);
previouslyBilledAmount = previouslyBilledAmount.add(getMilestonesBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber));
KualiDecimal totalBilledAmount = accountTotalBilledAmounts.getOrDefault(accountKey, KualiDecimal.ZERO);
previouslyBilledAmount = previouslyBilledAmount.subtract(totalBilledAmount);
if (previouslyBilledAmount.isGreaterThan(KualiDecimal.ZERO)) {
totalAmount = totalAmount.subtract(previouslyBilledAmount);
}
}
CustomerInvoiceDetail cide = createSourceAccountingLine(contractsGrantsInvoiceDocument.getDocumentNumber(), chartOfAccountsCode, accountNumber, subFundGroup, totalAmount, sequenceNumber);
awardAccountingLines.add(cide);
}
}
return awardAccountingLines;
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method generateAndSaveContractsAndGrantsInvoiceDocument.
/**
* FINP-5295 This method was modified for the backport.
*
* Generates and then saves a Contracts & Grants Invoice Document
*
* @param awd the award for the document
* @param validAwardAccounts the award accounts which should appear on the document
* @param errorMessages a List of error messages, to be appended to if there are errors in document generation
* @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
*/
protected void generateAndSaveContractsAndGrantsInvoiceDocument(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> validAwardAccounts, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
ChartOrgHolder chartOrgHolder = financialSystemUserService.getPrimaryOrganization(awd.getAwardPrimaryFundManager().getFundManager().getPrincipalId(), KFSConstants.OptionalModuleNamespaces.ACCOUNTS_RECEIVABLE);
/*
* CU Customization (KFSPTS-23675):
* Include creationProcessType in the method call.
*/
ContractsGrantsInvoiceDocument cgInvoiceDocument = createCGInvoiceDocumentByAwardInfo(awd, validAwardAccounts, chartOrgHolder.getChartOfAccountsCode(), chartOrgHolder.getOrganizationCode(), errorMessages, accountDetails, locCreationType, creationProcessType);
if (ObjectUtils.isNotNull(cgInvoiceDocument)) {
if (cgInvoiceDocument.getTotalInvoiceAmount().isPositive() || getContractsGrantsInvoiceDocumentService().getInvoiceMilestoneTotal(cgInvoiceDocument).isPositive() || getContractsGrantsInvoiceDocumentService().getBillAmountTotal(cgInvoiceDocument).isPositive() || (ArConstants.BillingFrequencyValues.isTimeBased(awd) && ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL.equals(creationProcessType))) {
try {
documentService.saveDocument(cgInvoiceDocument, DocumentSystemSaveEvent.class);
} catch (WorkflowException ex) {
LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
}
} else {
ErrorMessage errorMessage;
List<InvoiceAccountDetail> invoiceAccounts = cgInvoiceDocument.getAccountDetails();
if (!invoiceAccounts.isEmpty()) {
errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, invoiceAccounts.get(0).getAccountNumber(), awd.getProposalNumber());
} else {
errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, null, awd.getProposalNumber());
}
errorMessages.add(errorMessage);
}
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail 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.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method updateInvoiceSourceAccountingLines.
protected void updateInvoiceSourceAccountingLines(List<InvoiceAccountDetail> invoiceAccountDetails, List sourceAccountingLines) {
if (sourceAccountingLines.size() > 1) {
// Invoice By Award
for (CustomerInvoiceDetail cide : (List<CustomerInvoiceDetail>) sourceAccountingLines) {
for (InvoiceAccountDetail invoiceAccountDetail : invoiceAccountDetails) {
if (cide.getAccountNumber().equals(invoiceAccountDetail.getAccountNumber())) {
cide.setInvoiceItemUnitPrice(invoiceAccountDetail.getInvoiceAmount());
cide.setAmount(invoiceAccountDetail.getInvoiceAmount());
}
}
}
} else if (sourceAccountingLines.size() == 1) {
// This would be a case where the invoice is generated by Contract Control Account or Invoice By Account.
KualiDecimal totalExpenditureAmount = KualiDecimal.ZERO;
if (invoiceAccountDetails.size() == 1) {
// Invoice By Account
// update source accounting lines
CustomerInvoiceDetail cide = (CustomerInvoiceDetail) sourceAccountingLines.get(0);
cide.setInvoiceItemUnitPrice(invoiceAccountDetails.get(0).getInvoiceAmount());
cide.setAmount(invoiceAccountDetails.get(0).getInvoiceAmount());
} else {
// Invoice By Contract Control Account
for (InvoiceAccountDetail invoiceAccountDetail : invoiceAccountDetails) {
totalExpenditureAmount = totalExpenditureAmount.add(invoiceAccountDetail.getInvoiceAmount());
}
// update source accounting lines
CustomerInvoiceDetail cide = (CustomerInvoiceDetail) sourceAccountingLines.get(0);
cide.setInvoiceItemUnitPrice(totalExpenditureAmount);
cide.setAmount(totalExpenditureAmount);
}
}
}
Aggregations