Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:org.kuali.coeus.s2sgen.impl.generate.support.SF424V2_0Generator.java

/**
 * /*w ww.  j  a v a 2 s  .c o  m*/
 * This method gets SF424 information for the form which includes informations regarding SubmissionTypeCode
 * ApplicationType,RevisionType,AgencyName,ApplicantID,CFDANumber,FederalEntityIdentifier,AuthorizedRepresentative.
 * 
 * @return sf424V2 object containing applicant and application details.
 */
private SF424 getSF424() {

    SF424 sf424V2 = SF424.Factory.newInstance();
    sf424V2.setFormVersion(FormVersion.v2_0.getVersion());
    boolean hasBudgetLineItem = false;
    S2sOpportunityContract s2sOpportunity = pdDoc.getDevelopmentProposal().getS2sOpportunity();
    if (s2sOpportunity != null && s2sOpportunity.getS2sSubmissionType() != null) {
        S2sSubmissionTypeContract submissionType = s2sOpportunity.getS2sSubmissionType();
        SubmissionType.Enum subEnum = SubmissionType.Enum.forInt(Integer.parseInt(submissionType.getCode()));
        sf424V2.setSubmissionType(subEnum);
        ApplicationType.Enum applicationTypeEnum = null;
        if (pdDoc.getDevelopmentProposal().getProposalType() != null) {
            String proposalTypeCode = pdDoc.getDevelopmentProposal().getProposalType().getCode();
            if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_NEW, proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.NEW;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RESUBMISSION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RENEWAL,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_CONTINUATION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_REVISION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            }
        }
        sf424V2.setApplicationType(applicationTypeEnum);
        String revisionType = s2sOpportunity.getS2sRevisionType() != null
                ? s2sOpportunity.getS2sRevisionType().getCode()
                : null;
        if (revisionType != null) {
            RevisionType.Enum revType = null;
            if (revisionType.equals(INCREASE_AWARD_CODE)) {
                revType = RevisionType.A_INCREASE_AWARD;
            } else if (revisionType.equals(DECREASE_AWARD_CODE)) {
                revType = RevisionType.B_DECREASE_AWARD;
            } else if (revisionType.equals(INCREASE_DURATION_CODE)) {
                revType = RevisionType.C_INCREASE_DURATION;
            } else if (revisionType.equals(DECREASE_DURATION_CODE)) {
                revType = RevisionType.D_DECREASE_DURATION;
            } else if (revisionType.equals(INCREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.AD_INCREASE_AWARD_DECREASE_DURATION;
            } else if (revisionType.equals(INCREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.AC_INCREASE_AWARD_INCREASE_DURATION;
            } else if (revisionType.equals(DECREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.BD_DECREASE_AWARD_DECREASE_DURATION;
            } else if (revisionType.equals(DECREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.BC_DECREASE_AWARD_INCREASE_DURATION;
            } else if (revisionType.equals(OTHER_SPECIFY_CODE)) {
                revType = RevisionType.E_OTHER_SPECIFY;
            }

            if (revType != null) {
                sf424V2.setRevisionType(revType);
            }
            if (revisionType.startsWith(REVISIONCODE_STARTS_WITH_E)) {
                sf424V2.setRevisionOtherSpecify(s2sOpportunity.getRevisionOtherDescription());
            }
        }
    }
    sf424V2.setDateReceived(Calendar.getInstance());
    sf424V2.setApplicantID(pdDoc.getDevelopmentProposal().getProposalNumber());
    String federalId = getSubmissionInfoService()
            .getFederalId(pdDoc.getDevelopmentProposal().getProposalNumber());
    if (federalId != null) {
        sf424V2.setFederalEntityIdentifier(federalId);
    }

    OrganizationContract organization = null;
    organization = pdDoc.getDevelopmentProposal().getApplicantOrganization().getOrganization();
    if (organization != null) {
        sf424V2.setOrganizationName(organization.getOrganizationName());
        sf424V2.setEmployerTaxpayerIdentificationNumber(organization.getFederalEmployerId());
        sf424V2.setDUNSNumber(organization.getDunsNumber());
        sf424V2.setOrganizationAffiliation(organization.getOrganizationName());
    } else {
        sf424V2.setOrganizationName(null);
        sf424V2.setEmployerTaxpayerIdentificationNumber(null);
        sf424V2.setDUNSNumber(null);
    }
    RolodexContract rolodex = null;
    rolodex = pdDoc.getDevelopmentProposal().getApplicantOrganization().getRolodex();
    sf424V2.setApplicant(globLibV20Generator.getAddressDataType(rolodex));
    String departmentName = null;
    if (pdDoc.getDevelopmentProposal().getOwnedByUnit() != null) {
        departmentName = pdDoc.getDevelopmentProposal().getOwnedByUnit().getUnitName();
    }
    if (departmentName != null) {
        sf424V2.setDepartmentName(StringUtils.substring(departmentName, 0, DEPARTMENT_NAME_MAX_LENGTH));
    }
    String divisionName = getDivisionName(pdDoc);
    if (divisionName != null) {
        sf424V2.setDivisionName(StringUtils.substring(divisionName, 0, DIVISION_NAME_MAX_LENGTH));
    }
    ProposalPersonContract personInfo = s2SProposalPersonService.getPrincipalInvestigator(pdDoc);
    if (personInfo != null) {
        sf424V2.setContactPerson(globLibV20Generator.getHumanNameDataType(personInfo));
        if (personInfo.getDirectoryTitle() != null) {
            String directoryTitle = personInfo.getDirectoryTitle();
            directoryTitle = directoryTitle.length() > 45 ? directoryTitle.substring(0, 44) : directoryTitle;
            sf424V2.setTitle(directoryTitle);
        }
        sf424V2.setPhoneNumber(personInfo.getOfficePhone());
        if (StringUtils.isNotEmpty(personInfo.getFaxNumber())) {
            sf424V2.setFax(personInfo.getFaxNumber());
        }
        sf424V2.setEmail(personInfo.getEmailAddress());
    } else {
        sf424V2.setPhoneNumber(null);
        sf424V2.setEmail(null);
    }

    setApplicatTypeCodes(sf424V2);

    if (pdDoc.getDevelopmentProposal().getSponsor() != null) {
        sf424V2.setAgencyName(pdDoc.getDevelopmentProposal().getSponsor().getSponsorName());
    }
    if (pdDoc.getDevelopmentProposal().getCfdaNumber() != null) {
        sf424V2.setCFDANumber(pdDoc.getDevelopmentProposal().getCfdaNumber());
    }
    if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle() != null) {
        String announcementTitle;
        if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle()
                .length() > PROGRAM_ANNOUNCEMENT_TITLE_LENGTH) {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle().substring(0,
                    PROGRAM_ANNOUNCEMENT_TITLE_LENGTH);
        } else {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle();
        }
        sf424V2.setCFDAProgramTitle(announcementTitle);
    }
    if (pdDoc.getDevelopmentProposal().getS2sOpportunity() != null) {
        sf424V2.setFundingOpportunityNumber(
                pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId());
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle() != null) {
            sf424V2.setFundingOpportunityTitle(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle());
        }
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId() != null) {
            sf424V2.setCompetitionIdentificationNumber(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId());
        }
    } else {
        sf424V2.setFundingOpportunityTitle(null);
    }
    String areasAffected = null;
    for (ProposalAbstractContract proposalAbstract : pdDoc.getDevelopmentProposal().getProposalAbstracts()) {
        if (proposalAbstract.getAbstractType().getCode() != null && Integer
                .parseInt(proposalAbstract.getAbstractType().getCode()) == ABSTRACTTYPE_CODE_AREAS_AFFECTED) {
            areasAffected = proposalAbstract.getAbstractDetails();
            if (areasAffected != null && areasAffected.length() > AREAS_AFFECTED_MAX_LENGTH) {
                sf424V2.setAffectedAreas(areasAffected.substring(0, AREAS_AFFECTED_MAX_LENGTH));
            } else {
                sf424V2.setAffectedAreas(areasAffected);
            }
        }
    }
    sf424V2.setProjectTitle(pdDoc.getDevelopmentProposal().getTitle());
    AttachmentGroupMin0Max100DataType attachedFileMin0Max100 = AttachmentGroupMin0Max100DataType.Factory
            .newInstance();
    attachedFileMin0Max100.setAttachedFileArray(getAttachedFileDataTypes());
    sf424V2.setAdditionalProjectTitle(attachedFileMin0Max100);
    String congressionalDistrict = organization.getCongressionalDistrict() == null
            ? FieldValueConstants.VALUE_UNKNOWN
            : organization.getCongressionalDistrict();
    if (congressionalDistrict.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
        sf424V2.setCongressionalDistrictApplicant(
                congressionalDistrict.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
    } else {
        sf424V2.setCongressionalDistrictApplicant(congressionalDistrict);
    }
    ProposalSiteContract perfOrganization = pdDoc.getDevelopmentProposal().getPerformingOrganization();
    if (perfOrganization != null) {
        String congDistrictProject = perfOrganization.getFirstCongressionalDistrictName() == null
                ? FieldValueConstants.VALUE_UNKNOWN
                : perfOrganization.getFirstCongressionalDistrictName();
        if (congDistrictProject.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
            sf424V2.setCongressionalDistrictProgramProject(
                    congDistrictProject.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
        } else {
            sf424V2.setCongressionalDistrictProgramProject(congDistrictProject);
        }
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null && Integer
                .parseInt(narrative.getNarrativeType().getCode()) == CONGRESSIONAL_DISTRICTS_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V2.setAdditionalCongressionalDistricts(attachedFileDataType);
                break;
            }
        }
    }
    if (pdDoc.getDevelopmentProposal().getRequestedStartDateInitial() != null) {
        sf424V2.setProjectStartDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedStartDateInitial()));
    } else {
        sf424V2.setProjectStartDate(null);
    }
    if (pdDoc.getDevelopmentProposal().getRequestedEndDateInitial() != null) {
        sf424V2.setProjectEndDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedEndDateInitial()));
    } else {
        sf424V2.setProjectEndDate(null);
    }
    ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService
            .getBudget(pdDoc.getDevelopmentProposal());

    if (budget != null) {
        if (budget.getTotalCost() != null) {
            sf424V2.setFederalEstimatedFunding(budget.getTotalCost().bigDecimalValue());
        }

        ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO;

        for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
            for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
                hasBudgetLineItem = true;
                if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) {
                    costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount());
                    List<? extends BudgetLineItemCalculatedAmountContract> calculatedAmounts = lineItem
                            .getBudgetLineItemCalculatedAmounts();
                    for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : calculatedAmounts) {
                        costSharingAmount = costSharingAmount
                                .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing());
                    }

                }
            }
        }
        if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) {
            costSharingAmount = budget.getCostSharingAmount();
        }

        sf424V2.setApplicantEstimatedFunding(costSharingAmount.bigDecimalValue());
        BigDecimal projectIncome = BigDecimal.ZERO;
        for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
            projectIncome = projectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
        }
        sf424V2.setProgramIncomeEstimatedFunding(projectIncome);

        ScaleTwoDecimal totalEstimatedAmount = ScaleTwoDecimal.ZERO;
        if (budget.getTotalCost() != null) {
            totalEstimatedAmount = totalEstimatedAmount.add(budget.getTotalCost());
        }
        totalEstimatedAmount = totalEstimatedAmount.add(costSharingAmount);
        totalEstimatedAmount = totalEstimatedAmount.add(new ScaleTwoDecimal(projectIncome));
        sf424V2.setTotalEstimatedFunding(totalEstimatedAmount.bigDecimalValue());
    } else {
        sf424V2.setFederalEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setApplicantEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setProgramIncomeEstimatedFunding(BigDecimal.ZERO);
        sf424V2.setTotalEstimatedFunding(BigDecimal.ZERO);
    }
    sf424V2.setStateEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setLocalEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setOtherEstimatedFunding(BigDecimal.ZERO);
    sf424V2.setStateReview(getStateReviewCode());
    if (strReview != null && strReview.equals(STATE_REVIEW_YES)) {
        Calendar reviewDate = null;
        reviewDate = s2SDateTimeService.convertDateStringToCalendar(stateReviewDate);
        sf424V2.setStateReviewAvailableDate(reviewDate);
    }
    YesNoDataType.Enum yesNo = YesNoDataType.N_NO;
    OrganizationContract applicantOrganization = pdDoc.getDevelopmentProposal().getApplicantOrganization()
            .getOrganization();
    if (applicantOrganization != null) {
        for (OrganizationYnqContract orgYnq : applicantOrganization.getOrganizationYnqs()) {
            if (orgYnq.getQuestionId() != null && orgYnq.getQuestionId().equals(PROPOSAL_YNQ_FEDERAL_DEBTS)) {
                String orgYnqanswer = orgYnq.getAnswer();
                if (orgYnqanswer != null) {
                    if (orgYnqanswer.equalsIgnoreCase(ORGANIZATION_YNQ_ANSWER_YES)) {
                        yesNo = YesNoDataType.Y_YES;
                    } else {
                        yesNo = YesNoDataType.N_NO;
                    }
                }
                federalDebtExp = orgYnq.getExplanation();
            }
        }
    }
    sf424V2.setDelinquentFederalDebt(yesNo);
    if (sf424V2.getDelinquentFederalDebt() != null
            && sf424V2.getDelinquentFederalDebt().equals(YesNoDataType.Y_YES)) {
        sf424V2.setDelinquentFederalDebtExplanation(federalDebtExp);
    }
    sf424V2.setCertificationAgree(YesNoDataType.Y_YES);
    sf424V2.setAuthorizedRepresentative(globLibV20Generator.getHumanNameDataType(aorInfo));
    if (aorInfo.getPrimaryTitle() != null) {
        if (aorInfo.getPrimaryTitle().length() > PRIMARY_TITLE_MAX_LENGTH) {
            sf424V2.setAuthorizedRepresentativeTitle(
                    aorInfo.getPrimaryTitle().substring(0, PRIMARY_TITLE_MAX_LENGTH));
        } else {
            sf424V2.setAuthorizedRepresentativeTitle(aorInfo.getPrimaryTitle());
        }
    } else {
        sf424V2.setAuthorizedRepresentativeTitle(null);
    }
    sf424V2.setAuthorizedRepresentativePhoneNumber(aorInfo.getOfficePhone());
    sf424V2.setAuthorizedRepresentativeEmail(aorInfo.getEmailAddress());
    sf424V2.setAuthorizedRepresentativeFax(aorInfo.getFaxNumber());
    sf424V2.setAORSignature(aorInfo.getFullName());
    sf424V2.setDateSigned(Calendar.getInstance());
    return sf424V2;
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperBigDecimal.java

/** {@inheritDoc} */
@Override//from w  ww. ja va2s  . c om
public String indexValue(String name, Object value) {

    // Check not null
    if (value == null) {
        return null;
    }

    // Parse big decimal
    String svalue = value.toString();
    BigDecimal bd;
    try {
        bd = new BigDecimal(value.toString());
    } catch (NumberFormatException e) {
        String message = String.format("Field %s requires a base 10 decimal, but found \"%s\"", name, svalue);
        throw new IllegalArgumentException(message);
    }

    // Split integer and decimal part
    bd = bd.stripTrailingZeros();
    String[] parts = bd.toPlainString().split("\\.");
    String integerPart = parts[0];
    String decimalPart = parts.length == 1 ? "0" : parts[1];

    if (integerPart.replaceFirst("-", "").length() > integerDigits) {
        throw new IllegalArgumentException("Too much digits in integer part");
    }
    if (decimalPart.length() > decimalDigits) {
        throw new IllegalArgumentException("Too much digits in decimal part");
    }

    BigDecimal complemented = bd.add(complement);
    String bds[] = complemented.toString().split("\\.");
    integerPart = bds[0];
    decimalPart = bds.length == 2 ? bds[1] : "0";
    integerPart = StringUtils.leftPad(integerPart, integerDigits + 1, '0');

    return integerPart + "." + decimalPart;
}

From source file:com.jlfex.hermes.main.AccountPersonalController.java

/**
 * ?/*from  w  ww.j a v a2s . c o  m*/
 * 
 * @param model
 * @return
 */
@RequestMapping("/getUserInfo")
public String getUserInfo(Model model) {
    AppUser curUser = App.current().getUser();
    App.checkUser();
    User user = userInfoService.findByUserId(curUser.getId());

    List<UserAccount> userAccounts = userInfoService.findAccountByUserId(curUser.getId());
    BigDecimal allBalance = BigDecimal.ZERO;// ?
    BigDecimal cashBalance = BigDecimal.ZERO;// ?
    BigDecimal freezeBalance = BigDecimal.ZERO;// ?
    for (UserAccount userAcc : userAccounts) {
        if (userAcc.getType().equals(Type.CASH)) {
            cashBalance = userAcc.getBalance();// ?
        } else {
            freezeBalance = userAcc.getBalance();// ?

        }
        allBalance = allBalance.add(userAcc.getBalance());
    }
    model.addAttribute("cashBalance", cashBalance);// ?
    model.addAttribute("freezeBalance", freezeBalance);// ?
    model.addAttribute("allBalance", allBalance);
    model.addAttribute("email", curUser.getAccount());
    // model.addAttribute("email", user.getEmail());
    // ??
    UserImage avatar = new UserImage();
    avatar = userInfoService.findImageByUserIdAndType(curUser.getId(),
            com.jlfex.hermes.model.UserImage.Type.AVATAR_LG);
    model.addAttribute("avatar", avatar);

    // ?
    UserProperties userPro = userInfoService.getProByUser(user);
    model.addAttribute("userPro", userPro);

    return "account/personalnew";
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.SF424V2_1Generator.java

/**
 * //from w  w w.ja  v  a  2 s  .  com
 * This method gets SF42421 information for the form which includes informations regarding SubmissionTypeCode
 * ApplicationType,RevisionType,AgencyName,ApplicantID,CFDANumber,FederalEntityIdentifier,AuthorizedRepresentative.
 * 
 * @return sf424V21 object containing applicant and application details.
 */
private SF42421 getSF42421() {

    SF42421 sf424V21 = SF42421.Factory.newInstance();
    sf424V21.setFormVersion(FormVersion.v2_1.getVersion());
    boolean hasBudgetLineItem = false;
    S2sOpportunityContract s2sOpportunity = pdDoc.getDevelopmentProposal().getS2sOpportunity();
    if (s2sOpportunity != null && s2sOpportunity.getS2sSubmissionType() != null) {
        S2sSubmissionTypeContract submissionType = s2sOpportunity.getS2sSubmissionType();
        SubmissionType.Enum subEnum = SubmissionType.Enum.forInt(Integer.parseInt(submissionType.getCode()));
        sf424V21.setSubmissionType(subEnum);
        ApplicationType.Enum applicationTypeEnum = null;
        if (pdDoc.getDevelopmentProposal().getProposalType() != null) {
            String proposalTypeCode = pdDoc.getDevelopmentProposal().getProposalType().getCode();
            if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_NEW, proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.NEW;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RESUBMISSION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_RENEWAL,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_CONTINUATION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.CONTINUATION;
            } else if (doesParameterContainCode(ConfigurationConstants.PROPOSAL_TYPE_CODE_REVISION,
                    proposalTypeCode)) {
                applicationTypeEnum = ApplicationType.REVISION;
            }
        }
        sf424V21.setApplicationType(applicationTypeEnum);

        String revisionType = s2sOpportunity.getS2sRevisionType() != null
                ? s2sOpportunity.getS2sRevisionType().getCode()
                : null;
        if (revisionType != null) {
            RevisionType.Enum revType = null;
            if (revisionType.equals(INCREASE_AWARD_CODE)) {
                revType = RevisionType.A_INCREASE_AWARD;

            } else if (revisionType.equals(DECREASE_AWARD_CODE)) {
                revType = RevisionType.B_DECREASE_AWARD;

            } else if (revisionType.equals(INCREASE_DURATION_CODE)) {
                revType = RevisionType.C_INCREASE_DURATION;

            } else if (revisionType.equals(DECREASE_DURATION_CODE)) {
                revType = RevisionType.D_DECREASE_DURATION;

            } else if (revisionType.equals(INCREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.AD_INCREASE_AWARD_DECREASE_DURATION;

            } else if (revisionType.equals(INCREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.AC_INCREASE_AWARD_INCREASE_DURATION;

            } else if (revisionType.equals(DECREASE_AWARD_DECREASE_DURATION_CODE)) {
                revType = RevisionType.BD_DECREASE_AWARD_DECREASE_DURATION;

            } else if (revisionType.equals(DECREASE_AWARD_INCREASE_DURATION_CODE)) {
                revType = RevisionType.BC_DECREASE_AWARD_INCREASE_DURATION;

            } else if (revisionType.equals(OTHER_SPECIFY_CODE)) {
                revType = RevisionType.E_OTHER_SPECIFY;
            }

            if (revType != null) {
                sf424V21.setRevisionType(revType);
            }
            if (revisionType.startsWith(REVISIONCODE_STARTS_WITH_E)) {
                sf424V21.setRevisionOtherSpecify(s2sOpportunity.getRevisionOtherDescription());
            }
        }
    }
    sf424V21.setDateReceived(Calendar.getInstance());
    sf424V21.setApplicantID(pdDoc.getDevelopmentProposal().getProposalNumber());
    String federalId = getSubmissionInfoService()
            .getFederalId(pdDoc.getDevelopmentProposal().getProposalNumber());
    if (federalId != null) {
        sf424V21.setFederalEntityIdentifier(federalId);
    }

    OrganizationContract organization = null;
    organization = pdDoc.getDevelopmentProposal().getApplicantOrganization().getOrganization();
    if (organization != null) {
        sf424V21.setOrganizationName(organization.getOrganizationName());
        sf424V21.setEmployerTaxpayerIdentificationNumber(organization.getFederalEmployerId());
        sf424V21.setDUNSNumber(organization.getDunsNumber());
        sf424V21.setOrganizationAffiliation(organization.getOrganizationName());
    } else {
        sf424V21.setOrganizationName(null);
        sf424V21.setEmployerTaxpayerIdentificationNumber(null);
        sf424V21.setDUNSNumber(null);
    }
    RolodexContract rolodex = null;
    rolodex = pdDoc.getDevelopmentProposal().getApplicantOrganization().getRolodex();
    sf424V21.setApplicant(globLibV20Generator.getAddressDataType(rolodex));
    String departmentName = null;
    if (pdDoc.getDevelopmentProposal().getOwnedByUnit() != null) {
        departmentName = pdDoc.getDevelopmentProposal().getOwnedByUnit().getUnitName();
    }
    if (departmentName != null) {
        sf424V21.setDepartmentName(StringUtils.substring(departmentName, 0, DEPARTMENT_NAME_MAX_LENGTH));
    }
    String divisionName = getDivisionName(pdDoc);
    if (divisionName != null) {
        sf424V21.setDivisionName(StringUtils.substring(divisionName, 0, DIVISION_NAME_MAX_LENGTH));
    }
    ProposalPersonContract personInfo = s2SProposalPersonService.getPrincipalInvestigator(pdDoc);
    if (personInfo != null) {
        sf424V21.setContactPerson(globLibV20Generator.getHumanNameDataType(personInfo));
        if (personInfo.getDirectoryTitle() != null) {
            String directoryTitle = personInfo.getDirectoryTitle();
            directoryTitle = directoryTitle.length() > 45 ? directoryTitle.substring(0, 44) : directoryTitle;
            sf424V21.setTitle(directoryTitle);
        }
        sf424V21.setPhoneNumber(personInfo.getOfficePhone());
        if (StringUtils.isNotEmpty(personInfo.getFaxNumber())) {
            sf424V21.setFax(personInfo.getFaxNumber());
        }
        sf424V21.setEmail(personInfo.getEmailAddress());
    } else {
        sf424V21.setPhoneNumber(null);
        sf424V21.setEmail(null);
    }

    setApplicatTypeCodes(sf424V21);

    if (pdDoc.getDevelopmentProposal().getSponsor() != null) {
        sf424V21.setAgencyName(pdDoc.getDevelopmentProposal().getSponsor().getSponsorName());
    }
    if (pdDoc.getDevelopmentProposal().getCfdaNumber() != null) {
        sf424V21.setCFDANumber(pdDoc.getDevelopmentProposal().getCfdaNumber());
    }
    if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle() != null) {
        String announcementTitle;
        if (pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle()
                .length() > PROGRAM_ANNOUNCEMENT_TITLE_LENGTH) {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle().substring(0,
                    PROGRAM_ANNOUNCEMENT_TITLE_LENGTH);
        } else {
            announcementTitle = pdDoc.getDevelopmentProposal().getProgramAnnouncementTitle();
        }
        sf424V21.setCFDAProgramTitle(announcementTitle);
    }
    if (pdDoc.getDevelopmentProposal().getS2sOpportunity() != null) {
        sf424V21.setFundingOpportunityNumber(
                pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId());
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle() != null) {
            sf424V21.setFundingOpportunityTitle(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityTitle());
        }
        if (pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId() != null) {
            sf424V21.setCompetitionIdentificationNumber(
                    pdDoc.getDevelopmentProposal().getS2sOpportunity().getCompetetionId());
        }
    } else {
        sf424V21.setFundingOpportunityTitle(null);
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null
                && Integer.parseInt(narrative.getNarrativeType().getCode()) == AREAS_AFFECTED_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setAreasAffected(attachedFileDataType);
                break;
            }
        }
    }
    sf424V21.setProjectTitle(pdDoc.getDevelopmentProposal().getTitle());
    AttachmentGroupMin0Max100DataType attachedFileMin0Max100 = AttachmentGroupMin0Max100DataType.Factory
            .newInstance();
    attachedFileMin0Max100.setAttachedFileArray(getAttachedFileDataTypes());
    sf424V21.setAdditionalProjectTitle(attachedFileMin0Max100);
    String congressionalDistrict = organization.getCongressionalDistrict() == null
            ? FieldValueConstants.VALUE_UNKNOWN
            : organization.getCongressionalDistrict();
    if (congressionalDistrict.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
        sf424V21.setCongressionalDistrictApplicant(
                congressionalDistrict.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
    } else {
        sf424V21.setCongressionalDistrictApplicant(congressionalDistrict);
    }
    ProposalSiteContract perfOrganization = pdDoc.getDevelopmentProposal().getPerformingOrganization();
    if (perfOrganization != null) {
        String congDistrictProject = perfOrganization.getFirstCongressionalDistrictName() == null
                ? FieldValueConstants.VALUE_UNKNOWN
                : perfOrganization.getFirstCongressionalDistrictName();
        if (congDistrictProject.length() > CONGRESSIONAL_DISTRICT_MAX_LENGTH) {
            sf424V21.setCongressionalDistrictProgramProject(
                    congDistrictProject.substring(0, CONGRESSIONAL_DISTRICT_MAX_LENGTH));
        } else {
            sf424V21.setCongressionalDistrictProgramProject(congDistrictProject);
        }
    }
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null && Integer.parseInt(
                narrative.getNarrativeType().getCode()) == ADDITIONAL_CONGRESSIONAL_DISTRICTS_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setAdditionalCongressionalDistricts(attachedFileDataType);
                break;
            }
        }
    }
    if (pdDoc.getDevelopmentProposal().getRequestedStartDateInitial() != null) {
        sf424V21.setProjectStartDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedStartDateInitial()));
    } else {
        sf424V21.setProjectStartDate(null);
    }
    if (pdDoc.getDevelopmentProposal().getRequestedEndDateInitial() != null) {
        sf424V21.setProjectEndDate(s2SDateTimeService
                .convertDateToCalendar(pdDoc.getDevelopmentProposal().getRequestedEndDateInitial()));
    } else {
        sf424V21.setProjectEndDate(null);
    }
    ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService
            .getBudget(pdDoc.getDevelopmentProposal());

    if (budget != null) {
        if (budget.getTotalCost() != null) {
            sf424V21.setFederalEstimatedFunding(budget.getTotalCost().bigDecimalValue());
        }
        ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO;

        for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
            for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
                hasBudgetLineItem = true;
                if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) {
                    costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount());
                    List<? extends BudgetLineItemCalculatedAmountContract> calculatedAmounts = lineItem
                            .getBudgetLineItemCalculatedAmounts();
                    for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : calculatedAmounts) {
                        costSharingAmount = costSharingAmount
                                .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing());
                    }
                }
            }
        }
        if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) {
            costSharingAmount = budget.getCostSharingAmount();
        }
        sf424V21.setApplicantEstimatedFunding(costSharingAmount.bigDecimalValue());
        BigDecimal projectIncome = BigDecimal.ZERO;
        for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
            projectIncome = projectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
        }
        sf424V21.setProgramIncomeEstimatedFunding(projectIncome);

        ScaleTwoDecimal totalEstimatedAmount = ScaleTwoDecimal.ZERO;
        if (budget.getTotalCost() != null) {
            totalEstimatedAmount = totalEstimatedAmount.add(budget.getTotalCost());
        }
        totalEstimatedAmount = totalEstimatedAmount.add(costSharingAmount);
        totalEstimatedAmount = totalEstimatedAmount.add(new ScaleTwoDecimal(projectIncome));
        sf424V21.setTotalEstimatedFunding(totalEstimatedAmount.bigDecimalValue());
    } else {
        sf424V21.setFederalEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setApplicantEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setProgramIncomeEstimatedFunding(BigDecimal.ZERO);
        sf424V21.setTotalEstimatedFunding(BigDecimal.ZERO);
    }
    sf424V21.setStateEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setLocalEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setOtherEstimatedFunding(BigDecimal.ZERO);
    sf424V21.setStateReview(getStateReviewCode());
    if (strReview != null && strReview.equals(STATE_REVIEW_YES)) {
        Calendar reviewDate = null;
        reviewDate = s2SDateTimeService.convertDateStringToCalendar(stateReviewDate);
        sf424V21.setStateReviewAvailableDate(reviewDate);
    }
    YesNoDataType.Enum yesNo = YesNoDataType.N_NO;
    OrganizationContract applicantOrganization = pdDoc.getDevelopmentProposal().getApplicantOrganization()
            .getOrganization();
    if (applicantOrganization != null) {
        for (OrganizationYnqContract orgYnq : applicantOrganization.getOrganizationYnqs()) {
            if (orgYnq.getQuestionId() != null && orgYnq.getQuestionId().equals(PROPOSAL_YNQ_FEDERAL_DEBTS)) {
                String orgYnqanswer = orgYnq.getAnswer();
                if (orgYnqanswer != null) {
                    if (orgYnqanswer.equalsIgnoreCase(ORGANIZATION_YNQ_ANSWER_YES)) {
                        yesNo = YesNoDataType.Y_YES;
                    } else {
                        yesNo = YesNoDataType.N_NO;
                    }
                }
            }
        }
    }
    sf424V21.setDelinquentFederalDebt(yesNo);
    for (NarrativeContract narrative : pdDoc.getDevelopmentProposal().getNarratives()) {
        if (narrative.getNarrativeType().getCode() != null
                && Integer.parseInt(narrative.getNarrativeType().getCode()) == DEBT_EXPLANATION_ATTACHMENT) {
            AttachedFileDataType attachedFileDataType = getAttachedFileType(narrative);
            if (attachedFileDataType != null) {
                sf424V21.setDebtExplanation(attachedFileDataType);
                break;
            }
        }
    }

    sf424V21.setCertificationAgree(YesNoDataType.Y_YES);
    sf424V21.setAuthorizedRepresentative(globLibV20Generator.getHumanNameDataType(aorInfo));
    if (aorInfo.getPrimaryTitle() != null) {
        if (aorInfo.getPrimaryTitle().length() > PRIMARY_TITLE_MAX_LENGTH) {
            sf424V21.setAuthorizedRepresentativeTitle(
                    aorInfo.getPrimaryTitle().substring(0, PRIMARY_TITLE_MAX_LENGTH));
        } else {
            sf424V21.setAuthorizedRepresentativeTitle(aorInfo.getPrimaryTitle());
        }
    } else {
        sf424V21.setAuthorizedRepresentativeTitle(null);
    }
    sf424V21.setAuthorizedRepresentativePhoneNumber(aorInfo.getOfficePhone());
    sf424V21.setAuthorizedRepresentativeEmail(aorInfo.getEmailAddress());
    sf424V21.setAuthorizedRepresentativeFax(aorInfo.getFaxNumber());
    sf424V21.setAORSignature(aorInfo.getFullName());
    sf424V21.setDateSigned(Calendar.getInstance());
    return sf424V21;
}

From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java

@Override
@Transactional/*w  w w .j  a va2  s.  c om*/
public OverzichtGroepBedragenTotal rapportOverzichtGroepBedragen(Integer typeGroepId,
        Integer typeGroepKostOpbrengst, Date beginDate, Date eindDate, Integer showBedragPublicGroep,
        OverzichtGroepBedragenTotal overzichtGroepBedragenTotal) {
    List<? extends Bedragen> lstBedragenInPeriode = bedragenDao.BedragInPeriode(beginDate, eindDate, null,
            showBedragPublicGroep, userInfo.getPersoon().getPk_id());

    Groepen groepenSrv = groepenDao.findOne(typeGroepId);

    Integer negatief = new Integer(0);

    if (typeGroepKostOpbrengst.equals(1)) {
        negatief = 0;
    } else {
        negatief = 1;
    }
    List<? extends Bedragen> lstBedragen = getBedragenInGroep(lstBedragenInPeriode, groepenSrv, negatief);

    List<OverzichtGroepBedragen> overzichtGroepBedragen = new ArrayList<OverzichtGroepBedragen>();

    BigDecimal somOverzicht = new BigDecimal(0);

    for (Bedragen bedrag : lstBedragen) {
        OverzichtGroepBedragen overzichtGroepBedrag = new OverzichtGroepBedragen();
        overzichtGroepBedrag.setWithBedrag(bedrag);

        overzichtGroepBedragen.add(overzichtGroepBedrag);
        somOverzicht = somOverzicht.add(overzichtGroepBedrag.getBedrag());
    }
    overzichtGroepBedragenTotal.setSomBedrag(somOverzicht);

    overzichtGroepBedragenTotal.setOverzichtGroepBedragen(overzichtGroepBedragen);

    return overzichtGroepBedragenTotal;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.java

private BigDecimal costoPromedio(LoteEntrada lote) {
    Producto producto = lote.getProducto();

    BigDecimal cantidad = lote.getCantidad();
    BigDecimal viejoBalance = producto.getPrecioUnitario().multiply(producto.getExistencia());
    BigDecimal nuevoBalance = lote.getPrecioUnitario().multiply(cantidad);

    BigDecimal balanceTotal = viejoBalance.add(nuevoBalance);
    BigDecimal articulos = cantidad.add(producto.getExistencia());
    return balanceTotal.divide(articulos, 10, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
}

From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java

@Override
public void build() {
    setEditable(true);//  w  ww . j  ava2 s .  com
    setSizeFull();

    // retrieve the rows to display
    final List<V> parentCollection = getParentCollection();

    addContainerProperties();
    int nrOfProperties = getContainerPropertyIds().size();

    String[] sumColumns = getSumColumns();

    // adds a style generator that highlights the parent rows in bold
    setCellStyleGenerator(new CellStyleGenerator() {

        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            if (itemId.toString().startsWith(PREFIX_PARENTROW)) {
                return "parentRow";
            } else {
                return getCustomStyle(itemId, propertyId);
            }
        }
    });

    // custom field factory for creating editable fields for certain
    // properties
    this.setTableFieldFactory(new TableFieldFactory() {
        private boolean editAllowed = isEditAllowed();

        @Override
        public Field<?> createField(Container container, Object itemId, final Object propertyId,
                Component uiContext) {
            if (!isViewMode() && editAllowed && isEditable(propertyId.toString())
                    && itemId.toString().startsWith(PREFIX_CHILDROW)) {
                final TextField tf = new TextField();
                tf.setData(itemId);
                tf.setNullRepresentation("");
                tf.setNullSettingAllowed(true);
                // set the appropriate converter
                tf.setConverter(createConverter(propertyId.toString()));
                tf.addFocusListener(new FocusListener() {

                    @Override
                    public void focus(FocusEvent event) {
                        clickedColumn = propertyId.toString();
                    }
                });

                // add a value change listener (for responding to paste
                // events and normal changes)
                tf.addValueChangeListener(new Property.ValueChangeListener() {

                    @Override
                    public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
                        if (propagateChanges) {
                            handleChange(tf, propertyId.toString(), (String) event.getProperty().getValue());
                        }
                    }
                });

                // align all text field to the right
                tf.setStyleName(DynamoConstants.CSS_NUMERICAL);

                postProcessField(propertyId, itemId, tf);
                return tf;
            }
            return null;
        }
    });

    int parentCounter = 0;
    int childCounter = 0;

    // footer sums
    Map<String, BigDecimal> totalSumMap = new HashMap<>();

    for (String s : sumColumns) {
        totalSumMap.put(s, BigDecimal.ZERO);
    }

    for (V v : parentCollection) {

        // sum on the parent level
        Map<String, BigDecimal> sumMap = new HashMap<>();
        for (String s : sumColumns) {
            sumMap.put(s, BigDecimal.ZERO);
        }

        Object[] parentRow = new Object[nrOfProperties];
        fillParentRow(parentRow, v);

        Object parentId = this.addItem(parentRow, PREFIX_PARENTROW + parentCounter);
        this.setChildrenAllowed(parentId, true);
        this.setCollapsed(parentId, false);

        List<U> rowCollection = getRowCollection(v);
        for (U u : rowCollection) {
            Object[] childRow = new Object[nrOfProperties];
            fillChildRow(childRow, u, v);

            // add the child and set the connection to the parent
            Object childId = this.addItem(childRow, PREFIX_CHILDROW + childCounter);
            this.setParent(childId, parentId);
            this.setChildrenAllowed(childId, false);

            // update the sum columns on the parent level
            for (String column : sumColumns) {
                Number value = (Number) this.getItem(childId).getItemProperty(column).getValue();
                BigDecimal sum = sumMap.get(column);
                sumMap.put(column, sum.add(value == null ? BigDecimal.ZERO : toBigDecimal(value)));
            }
            childCounter++;
        }

        // set the sum on the parent level and update the grand total
        for (String s : sumColumns) {
            BigDecimal sum = sumMap.get(s);
            this.getItem(parentId).getItemProperty(s).setValue(convertNumber(sum, s));
            BigDecimal totalSum = totalSumMap.get(s);
            totalSumMap.put(s, totalSum.add(sum));
        }

        parentCounter++;
    }

    // update the footer sums
    for (String column : sumColumns) {
        BigDecimal bd = totalSumMap.get(column);
        this.setColumnFooter(column, convertToString(bd, column));
    }
    setFooterVisible(true);

    // right align certain columns
    for (Object propertyId : this.getContainerPropertyIds()) {
        if (isRightAligned(propertyId.toString())) {
            this.setColumnAlignment(propertyId, Table.Align.RIGHT);
        }
    }

    // respond to a click by storing the column ID
    this.addItemClickListener(new ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) {
            if (MouseButton.RIGHT.equals(event.getButton())) {
                clickedColumn = (String) event.getPropertyId();
            }
        }
    });

    if (isShowActionMenu()) {
        constructActionMenu(parentCollection);
    }
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSF424V1_0Generator.java

/**
 *
 * This method is to get estimated project funds for RRSF424
 *
 * @return EstimatedProjectFunding estimated total cost for the project.
 *///from ww w.  j  av  a2 s.  com
private EstimatedProjectFunding getProjectFunding() throws S2SException {
    ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService
            .getBudget(pdDoc.getDevelopmentProposal());

    EstimatedProjectFunding funding = EstimatedProjectFunding.Factory.newInstance();
    funding.setTotalEstimatedAmount(BigDecimal.ZERO);
    funding.setTotalfedNonfedrequested(BigDecimal.ZERO);
    funding.setEstimatedProgramIncome(BigDecimal.ZERO);

    ScaleTwoDecimal totalCost = ScaleTwoDecimal.ZERO;
    if (budget != null) {
        if (budget.getModularBudgetFlag()) {
            ScaleTwoDecimal fundsRequested = ScaleTwoDecimal.ZERO;
            ScaleTwoDecimal totalDirectCost = ScaleTwoDecimal.ZERO;

            // get modular budget amounts instead of budget detail amounts
            for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) {
                totalDirectCost = totalDirectCost.add(budgetPeriod.getBudgetModular().getTotalDirectCost());
                for (BudgetModularIdcContract budgetModularIdc : budgetPeriod.getBudgetModular()
                        .getBudgetModularIdcs()) {
                    fundsRequested = fundsRequested.add(budgetModularIdc.getFundsRequested());
                }
            }
            totalCost = totalCost.add(totalDirectCost);
            totalCost = totalCost.add(fundsRequested);
        } else {
            totalCost = budget.getTotalCost();
        }

        ScaleTwoDecimal fedNonFedCost = ScaleTwoDecimal.ZERO;
        fedNonFedCost = fedNonFedCost.add(totalCost);
        fedNonFedCost = fedNonFedCost.add(budget.getCostSharingAmount());

        BigDecimal totalProjectIncome = BigDecimal.ZERO;
        for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
            if (budgetProjectIncome.getProjectIncome() != null) {
                totalProjectIncome = totalProjectIncome
                        .add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
            }
        }
        funding.setTotalEstimatedAmount(totalCost.bigDecimalValue());
        funding.setTotalfedNonfedrequested(fedNonFedCost.bigDecimalValue());
        funding.setEstimatedProgramIncome(totalProjectIncome);
    }
    return funding;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.java

private Entrada preparaParaCerrar(Entrada entrada, Usuario usuario, Date fecha)
        throws NoCuadraException, NoSePuedeCerrarEnCeroException {
    BigDecimal iva = entrada.getIva();
    BigDecimal total = entrada.getTotal();
    entrada.setIva(BigDecimal.ZERO);
    entrada.setTotal(BigDecimal.ZERO);
    for (LoteEntrada lote : entrada.getLotes()) {
        Producto producto = lote.getProducto();
        producto.setPrecioUnitario(costoPromedio(lote));
        if (!entrada.getDevolucion()) {
            producto.setUltimoPrecio(lote.getPrecioUnitario());
        }//from   ww  w  .  ja va 2s  .  c  om
        producto.setExistencia(producto.getExistencia().add(lote.getCantidad()));
        producto.setFechaModificacion(fecha);
        currentSession().update(producto);
        auditaProducto(producto, usuario, Constantes.ACTUALIZAR, entrada.getId(), null, fecha);

        BigDecimal subtotal = lote.getPrecioUnitario().multiply(lote.getCantidad());
        entrada.setIva(entrada.getIva().add(lote.getIva()));
        entrada.setTotal(entrada.getTotal().add(subtotal.add(lote.getIva())));
    }
    if (total.equals(BigDecimal.ZERO)) {
        throw new NoSePuedeCerrarEnCeroException("No se puede cerrar la entrada en cero");
    }
    // Si tanto el iva o el total difieren mas de un 5% del valor que
    // viene en la factura lanzar excepcion
    if (iva.compareTo(entrada.getIva()) != 0 || total.compareTo(entrada.getTotal()) != 0) {
        BigDecimal variacion = new BigDecimal("0.05");
        BigDecimal topeIva = entrada.getIva().multiply(variacion);
        BigDecimal topeTotal = entrada.getTotal().multiply(variacion);
        if (iva.compareTo(entrada.getIva()) < 0 || total.compareTo(entrada.getTotal()) < 0) {
            if (iva.compareTo(entrada.getIva().subtract(topeIva)) >= 0
                    && total.compareTo(entrada.getTotal().subtract(topeTotal)) >= 0) {
                // todavia puede pasar
            } else {
                throw new NoCuadraException("No se puede cerrar porque no cuadran los totales");
            }
        } else {
            if (iva.compareTo(entrada.getIva().add(topeIva)) <= 0
                    && total.compareTo(entrada.getTotal().add(topeTotal)) <= 0) {
                // todavia puede pasar
            } else {
                throw new NoCuadraException("No se puede cerrar porque no cuadran los totales");
            }
        }
    }

    return entrada;
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java

BigDecimal decodeBinDecimal(ByteBuf cb, int bufferLen, boolean isIntegerPortion) throws PEException {
    BigDecimal decimalPortion = new BigDecimal(0);
    if (bufferLen > 0) {

        ByteBuf decimalPortionBuf = cb.readBytes(bufferLen);

        if (isIntegerPortion) {
            int initialBytes = bufferLen % 4;
            if (initialBytes > 0) {
                long intValue = readValue(decimalPortionBuf, initialBytes);
                decimalPortion = BigDecimal.valueOf(intValue);
            }//  w  w  w .  j a v a2 s.  c  o m
        }

        int decimalPortionLen = decimalPortionBuf.readableBytes();

        while (decimalPortionLen > 0) {
            int nextLen = (decimalPortionLen < 4) ? decimalPortionLen : 4;
            long intValue = readValue(decimalPortionBuf, nextLen);

            if (intValue > 0) {
                if (decimalPortion.longValue() == 0) {
                    decimalPortion = decimalPortion.add(BigDecimal.valueOf(intValue));
                } else {
                    int digits = (int) (Math.log10(intValue) + 1);
                    decimalPortion = decimalPortion.movePointRight(digits).add(BigDecimal.valueOf(intValue));
                }
            }

            decimalPortionLen = decimalPortionBuf.readableBytes();
        }
    }
    return decimalPortion;
}