Search in sources :

Example 16 with ContractsGrantsInvoiceDocument

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;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)

Example 17 with ContractsGrantsInvoiceDocument

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);
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) Award(org.kuali.kfs.module.cg.businessobject.Award) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) AwardExtendedAttribute(edu.cornell.kfs.module.cg.businessobject.AwardExtendedAttribute) DocumentBase(org.kuali.kfs.krad.document.DocumentBase)

Example 18 with 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);
}
Also used : ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)

Aggregations

ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)18 HashMap (java.util.HashMap)8 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)7 AwardExtendedAttribute (edu.cornell.kfs.module.cg.businessobject.AwardExtendedAttribute)5 Award (org.kuali.kfs.module.cg.businessobject.Award)5 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)4 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)4 DocumentBase (org.kuali.kfs.krad.document.DocumentBase)3 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)2 ErrorMessage (org.kuali.kfs.krad.util.ErrorMessage)2 AccountsReceivableDocumentHeader (org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader)2 ContractsGrantsInvoiceDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail)2 InvoiceGeneralDetail (org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)2 CuArParameterKeyConstants (edu.cornell.kfs.module.ar.CuArParameterKeyConstants)1 CuArPropertyConstants (edu.cornell.kfs.module.ar.CuArPropertyConstants)1 CustomerExtendedAttribute (edu.cornell.kfs.module.ar.businessobject.CustomerExtendedAttribute)1 CuContractsGrantsInvoiceDocumentService (edu.cornell.kfs.module.ar.document.service.CuContractsGrantsInvoiceDocumentService)1