use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createCGInvoiceDocumentByAwardInfo.
/*
* CU Customization (KFSPTS-23675):
* Added creationProcessType argument and its usage of it.
*/
@Override
public ContractsGrantsInvoiceDocument createCGInvoiceDocumentByAwardInfo(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> accounts, String chartOfAccountsCode, String organizationCode, List<ErrorMessage> errorMessages, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
ContractsGrantsInvoiceDocument cgInvoiceDocument = null;
if (ObjectUtils.isNotNull(accounts) && !accounts.isEmpty()) {
if (chartOfAccountsCode != null && organizationCode != null) {
try {
cgInvoiceDocument = (ContractsGrantsInvoiceDocument) documentService.getNewDocument(ContractsGrantsInvoiceDocument.class);
// Set description to the document created.
cgInvoiceDocument.getDocumentHeader().setDocumentDescription(buildDocumentDescription(awd, accounts));
// setup several Default Values for CGInvoice document which extends from Customer Invoice Document
// a) set billing org and chart code
cgInvoiceDocument.setBillByChartOfAccountCode(chartOfAccountsCode);
cgInvoiceDocument.setBilledByOrganizationCode(organizationCode);
// b) set processing org and chart code
List<String> procCodes = getContractsGrantsInvoiceDocumentService().getProcessingFromBillingCodes(chartOfAccountsCode, organizationCode);
AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = new AccountsReceivableDocumentHeader();
accountsReceivableDocumentHeader.setDocumentNumber(cgInvoiceDocument.getDocumentNumber());
// Set processing chart and org codes
if (procCodes != null) {
int procCodesSize = procCodes.size();
// Set processing chart
if (procCodesSize > 0) {
accountsReceivableDocumentHeader.setProcessingChartOfAccountCode(procCodes.get(0));
}
// Set processing org code
if (procCodesSize > 1) {
accountsReceivableDocumentHeader.setProcessingOrganizationCode(procCodes.get(1));
}
}
cgInvoiceDocument.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
populateInvoiceFromAward(awd, accounts, cgInvoiceDocument, accountDetails, locCreationType, creationProcessType);
contractsGrantsInvoiceDocumentService.createSourceAccountingLines(cgInvoiceDocument, accounts);
if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail().getAward())) {
contractsGrantsInvoiceDocumentService.updateSuspensionCategoriesOnDocument(cgInvoiceDocument);
}
LOG.info("Created Contracts & Grants Invoice Document " + cgInvoiceDocument.getDocumentNumber());
} catch (WorkflowException ex) {
LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
}
} else {
// if chart of account code or organization code is not available, output the error
final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_CHART_OR_ORG, awd.getProposalNumber());
errorMessages.add(errorMessage);
}
}
return cgInvoiceDocument;
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class CuContractsGrantsInvoiceDocumentServiceImplTest method prepareCinvDocumentAndProrate.
private void prepareCinvDocumentAndProrate(KualiDecimal totalAmountBilledToDate, KualiDecimal budgetTotal, double... invoiceAmounts) throws Exception {
PowerMockito.doReturn(totalAmountBilledToDate).when(cuContractsGrantsInvoiceDocumentServiceImpl, "getAwardBilledToDateAmount", Mockito.any());
PowerMockito.doReturn(totalAmountBilledToDate).when(cuContractsGrantsInvoiceDocumentServiceImpl, "getOtherTotalBilledForAwardPeriod", Mockito.any());
PowerMockito.suppress(PowerMockito.constructor(DocumentBase.class));
contractsGrantsInvoiceDocument = PowerMockito.spy(new ContractsGrantsInvoiceDocument());
PowerMockito.doReturn(true).when(contractsGrantsInvoiceDocument, "isCorrectionDocument");
Award award = new Award();
AwardExtendedAttribute attribute = new AwardExtendedAttribute();
attribute.setBudgetTotalAmount(budgetTotal);
award.setExtension(attribute);
InvoiceGeneralDetail invoiceGeneralDetail = Mockito.mock(InvoiceGeneralDetail.class);
Mockito.when(invoiceGeneralDetail.getTotalAmountBilledToDate()).thenReturn(totalAmountBilledToDate);
Mockito.when(invoiceGeneralDetail.getTotalPreviouslyBilled()).thenReturn(totalAmountBilledToDate);
Mockito.when(invoiceGeneralDetail.getAward()).thenReturn(award);
for (double invoiceAmount : invoiceAmounts) {
ContractsGrantsInvoiceDetail detail = new ContractsGrantsInvoiceDetail();
detail.setInvoiceAmount(new KualiDecimal(invoiceAmount));
detail.setCategoryCode("tst");
contractsGrantsInvoiceDocument.getInvoiceDetails().add(detail);
}
contractsGrantsInvoiceDocument.setInvoiceGeneralDetail(invoiceGeneralDetail);
cuContractsGrantsInvoiceDocumentServiceImpl.prorateBill(contractsGrantsInvoiceDocument);
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class FirstInvoiceForAwardSuspensionCategoryTest method assertDocumentProducesExpectedSuspendResult.
protected void assertDocumentProducesExpectedSuspendResult(boolean expectedSuspendResult, ContractsGrantsInvoiceDocumentFixture fixture) {
ContractsGrantsInvoiceDocument testDocument = buildMockContractsGrantsInvoiceDocument(fixture);
boolean actualSuspendResult = suspensionCategory.shouldSuspend(testDocument);
assertEquals("Wrong suspension result for document " + fixture.name(), expectedSuspendResult, actualSuspendResult);
}
Aggregations