Search in sources :

Example 1 with Balance

use of org.kuali.kfs.gl.businessobject.Balance in project cu-kfs by CU-CommunityApps.

the class ReversionProcessBase method reversionProcess.

/**
 * This evilly named method actually runs the  reversion process.
 */
public void reversionProcess(Map jobParameters, Map<String, Integer> reversionCounts) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("organizationReversionProcess() started");
    }
    this.jobParameters = jobParameters;
    this.reversionCounts = reversionCounts;
    LOG.info("Initializing the process");
    initializeProcess();
    // create files
    File outputFile = new File(outputFileName);
    try {
        outputPs = new PrintStream(outputFile);
        Iterator<Balance> balances = getBalanceService().findReversionBalancesForFiscalYear((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR), usePriorYearInformation);
        processBalances(balances);
        outputPs.close();
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Reversion File doesn't exist " + outputFileName);
    }
}
Also used : PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) Balance(org.kuali.kfs.gl.businessobject.Balance)

Example 2 with Balance

use of org.kuali.kfs.gl.businessobject.Balance in project cu-kfs by CU-CommunityApps.

the class AccountReversionProcessImpl method processBalances.

/**
 * Given a list of balances, this method generates the origin entries for the organization reversion/carry forward process, and saves those
 * to an initialized origin entry group
 *
 * @param balances an iterator of balances to process; each balance returned by the iterator will be processed by this method
 */
public void processBalances(Iterator<Balance> balances) {
    boolean skipToNextUnitOfWork = false;
    unitOfWork = new ReversionUnitOfWork();
    unitOfWork.setCategories(categoryList);
    int brokenCodeCount = 0;
    Balance bal;
    while (balances.hasNext()) {
        bal = balances.next();
        // we only want AC balance types so we will limit them here rather than in the query used for both Account Reversion and Organization Reversion.
        if (!bal.getBalanceTypeCode().equals(KFSConstants.BALANCE_TYPE_ACTUAL)) {
            continue;
        }
        String acctNumber = bal.getAccountNumber();
        if (LOG.isDebugEnabled()) {
            LOG.debug("BALANCE SELECTED: " + bal.getUniversityFiscalYear() + bal.getChartOfAccountsCode() + bal.getAccountNumber() + bal.getSubAccountNumber() + bal.getObjectCode() + bal.getSubObjectCode() + bal.getBalanceTypeCode() + bal.getObjectTypeCode() + " " + bal.getAccountLineAnnualBalanceAmount().add(bal.getBeginningBalanceLineAmount()));
        }
        try {
            if (!unitOfWork.isInitialized()) {
                unitOfWork.setFields(bal.getChartOfAccountsCode(), bal.getAccountNumber(), bal.getSubAccountNumber());
                retrieveCurrentReversionAndAccount(bal);
            } else // just gonna leave this broken code here....
            if (!unitOfWork.wouldHold(bal)) {
                if (!skipToNextUnitOfWork) {
                    calculateTotals();
                    List<OriginEntryFull> originEntriesToWrite = generateOutputOriginEntries();
                    summarizeOriginEntries(originEntriesToWrite);
                    if (holdGeneratedOriginEntries) {
                        generatedOriginEntries.addAll(originEntriesToWrite);
                    }
                    int recordsWritten = writeOriginEntries(originEntriesToWrite);
                    incrementCount("recordsWritten", recordsWritten);
                    getReversionUnitOfWorkService().save(unitOfWork);
                }
                unitOfWork.setFields(bal.getChartOfAccountsCode(), bal.getAccountNumber(), bal.getSubAccountNumber());
                retrieveCurrentReversionAndAccount(bal);
                brokenCodeCount++;
                skipToNextUnitOfWork = false;
            }
            if (skipToNextUnitOfWork) {
                // if there is no org reversion or an org reversion detail is missing or the balances are off for
                continue;
            // this unit of work,
            // just skip all the balances until we change unit of work
            }
            calculateBucketAmounts(bal);
        } catch (FatalErrorException fee) {
            LOG.info(fee.getMessage());
            skipToNextUnitOfWork = true;
        }
    }
    System.out.println("Total broken code balances processed: " + brokenCodeCount);
    // save the final unit of work
    if (!skipToNextUnitOfWork && getBalancesSelected() > 0) {
        try {
            calculateTotals();
            List<OriginEntryFull> originEntriesToWrite = generateOutputOriginEntries();
            summarizeOriginEntries(originEntriesToWrite);
            if (holdGeneratedOriginEntries) {
                generatedOriginEntries.addAll(originEntriesToWrite);
            }
            int recordsWritten = writeOriginEntries(originEntriesToWrite);
            incrementCount("recordsWritten", recordsWritten);
            getReversionUnitOfWorkService().save(unitOfWork);
        } catch (FatalErrorException fee) {
            LOG.info(fee.getMessage());
        }
    }
}
Also used : ReversionUnitOfWork(edu.cornell.kfs.gl.businessobject.ReversionUnitOfWork) List(java.util.List) FatalErrorException(org.kuali.kfs.gl.batch.service.impl.exception.FatalErrorException) Balance(org.kuali.kfs.gl.businessobject.Balance) OriginEntryFull(org.kuali.kfs.gl.businessobject.OriginEntryFull)

Example 3 with Balance

use of org.kuali.kfs.gl.businessobject.Balance 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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) Timestamp(java.sql.Timestamp) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ArrayList(java.util.ArrayList) List(java.util.List) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) InvoiceAddressDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail) ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) BillingPeriod(org.kuali.kfs.module.ar.businessobject.BillingPeriod) InvoiceMilestone(org.kuali.kfs.module.ar.businessobject.InvoiceMilestone) Milestone(org.kuali.kfs.module.ar.businessobject.Milestone) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) ContractsAndGrantsBillingAgency(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAgency) AwardAccountObjectCodeTotalBilled(org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled) Date(java.sql.Date) Date(java.sql.Date) ContractsGrantsLetterOfCreditReviewDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Balance(org.kuali.kfs.gl.businessobject.Balance) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 4 with Balance

use of org.kuali.kfs.gl.businessobject.Balance in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method getBudgetAndActualsForAwardAccount.

@Override
public KualiDecimal getBudgetAndActualsForAwardAccount(ContractsAndGrantsBillingAwardAccount awardAccount, String balanceTypeCode) {
    KualiDecimal balanceAmount = KualiDecimal.ZERO;
    Integer currentFiscalYear = universityDateService.getCurrentFiscalYear();
    final SystemOptions systemOption = optionsService.getCurrentYearOptions();
    final String expenditureExpenseObjectTypeCode = systemOption.getFinObjTypeExpenditureexp().getCode();
    final String chartOfAccountsCode = awardAccount.getChartOfAccountsCode();
    final String accountNumber = awardAccount.getAccountNumber();
    Map<String, Object> balanceKeys = new HashMap<>();
    balanceKeys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
    balanceKeys.put(KFSPropertyConstants.ACCOUNT_NUMBER, accountNumber);
    balanceKeys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, currentFiscalYear);
    balanceKeys.put(KFSPropertyConstants.BALANCE_TYPE_CODE, balanceTypeCode);
    balanceKeys.put(KFSPropertyConstants.OBJECT_TYPE_CODE, expenditureExpenseObjectTypeCode);
    for (Balance balance : businessObjectService.findMatching(Balance.class, balanceKeys)) {
        if (ObjectUtils.isNull(balance.getSubAccount()) || ObjectUtils.isNull(balance.getSubAccount().getA21SubAccount()) || !StringUtils.equalsIgnoreCase(balance.getSubAccount().getA21SubAccount().getSubAccountTypeCode(), KFSConstants.SubAccountType.COST_SHARE)) {
            balanceAmount = balanceAmount.add(balance.getContractsGrantsBeginningBalanceAmount().add(balance.getAccountLineAnnualBalanceAmount()));
        }
    }
    return balanceAmount;
}
Also used : HashMap(java.util.HashMap) AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) Balance(org.kuali.kfs.gl.businessobject.Balance)

Aggregations

Balance (org.kuali.kfs.gl.businessobject.Balance)4 HashMap (java.util.HashMap)2 List (java.util.List)2 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)2 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)2 ReversionUnitOfWork (edu.cornell.kfs.gl.businessobject.ReversionUnitOfWork)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)1 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)1 FatalErrorException (org.kuali.kfs.gl.batch.service.impl.exception.FatalErrorException)1 OriginEntryFull (org.kuali.kfs.gl.businessobject.OriginEntryFull)1 ContractsAndGrantsBillingAgency (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAgency)1 ContractsAndGrantsBillingAwardAccount (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)1 AwardAccountObjectCodeTotalBilled (org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled)1