List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
/** * Validates the max amount per day// w w w.ja v a 2 s . co m */ @Override public void validateMaxAmountAtDate(final Calendar date, final Account account, final TransferType transferType, BigDecimal maxAmountPerDay, final BigDecimal amount) { // Test the max amount per day maxAmountPerDay = maxAmountPerDay == null ? transferType.getMaxAmountPerDay() : maxAmountPerDay; if (maxAmountPerDay != null && maxAmountPerDay.floatValue() > PRECISION_DELTA) { // Get the amount on today BigDecimal amountOnDay = transferDao.getTransactionedAmountAt(date, account, transferType); // Validate if (amountOnDay.add(amount).compareTo(maxAmountPerDay) > 0) { throw new MaxAmountPerDayExceededException(date, transferType, account, amount); } } // Test the operator max amount per day if (LoggedUser.hasUser() && LoggedUser.isOperator()) { final Operator operator = LoggedUser.element(); OperatorGroup group = operator.getOperatorGroup(); group = fetchService.fetch(group, OperatorGroup.Relationships.MAX_AMOUNT_PER_DAY_BY_TRANSFER_TYPE); final BigDecimal maxAmount = group.getMaxAmountPerDayByTransferType().get(transferType); if (maxAmount != null && maxAmount.floatValue() > PRECISION_DELTA) { // Get the amount on today BigDecimal amountOnDay = transferDao.getTransactionedAmountAt(date, operator, account, transferType); // Validate if (amountOnDay.add(amount).compareTo(maxAmount) == 1) { throw new MaxAmountPerDayExceededException(date, transferType, account, amount); } } } }
From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java
/** * @param yearId// w w w .ja va 2s. com * @param monthId * @param costCentreId * @param empcntClientProjectDataVoList * @param empcntClientProjectDataList * @param employeeIdList * @param employeeMonthlyAssignmentCount */ private void ruleThree(Integer yearId, Integer monthId, String costCentreId, List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList, EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { BigDecimal assistedTimeZero = BigDecimal.ZERO; BigDecimal apportionedTimeZero = BigDecimal.ZERO; EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster(); TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth(); TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear(); CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre(); CountClassification countClassification = new CountClassification(); countClassification.setId(countTypeId); // get the employee aligned project for opening count List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList); // Get project details Map<Integer, EmpClientProjectTeamStruct> employeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>(); Map<Integer, EmpClientProjectTeamStruct> validEmployeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>(); for (EmpClientProjectTeamStruct empClientProjectTeamStructThree : empClientProjectTeamStructList) { employeeProjectIds.put(empClientProjectTeamStructThree.getProjectMaster().getProjectId(), empClientProjectTeamStructThree); } validEmployeeProjectIds.putAll(employeeProjectIds); // logger.debug("validEmployeeProjectIds 1:size===>" + // validEmployeeProjectIds.size()); // check in revenue table for (Integer key : employeeProjectIds.keySet()) { EmpClientProjectTeamStruct mapValues = employeeProjectIds.get(key); List<CollageProjectRevenue> listValues = collageProjectRevenueDao .findByYearIdMonthIdProjectIdCostCentreId(mapValues.getTabYear().getYearId(), mapValues.getTabMonth().getMonthId(), mapValues.getProjectMaster().getProjectId(), costCentre.getCostCentreId()); if (listValues.isEmpty()) { validEmployeeProjectIds.remove(key); } } // logger.debug("validEmployeeProjectIds 2:size===>" + // validEmployeeProjectIds.size()); if (validEmployeeProjectIds.isEmpty()) { ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, employeeMonthlyAssignmentCount, countTypeId, employeePcTagsTeamStructMap); } else { List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthId(yearId, monthId); BigDecimal sumOfRevenue = BigDecimal.ZERO; for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { sumOfRevenue.add(collageProjectRevenue.getRevenueValue()); } for (Integer key : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key); collageProjectRevenueList = new ArrayList<CollageProjectRevenue>(); collageProjectRevenueList = collageProjectRevenueDao.findByYearIdMonthIdProjectId(yearId, monthId, empClientProjectTeamStruct.getProjectMaster().getProjectId()); BigDecimal proportionToSpecificProject = collageProjectRevenueList.get(0).getRevenueValue() .divide(sumOfRevenue, 2, RoundingMode.HALF_EVEN); CompanyMaster companyMaster = empClientProjectTeamStruct.getCompanyMaster(); ProjectMaster projectMaster = empClientProjectTeamStruct.getProjectMaster(); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster, companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre, proportionToSpecificProject, assistedTimeZero, apportionedTimeZero, proportionToSpecificProject); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.SF424AV1_0Generator.java
/** * //w ww . j a va 2s.c o m * This method gives the information of BudgetForecastedCashNeeds which consists of budgetFirstYearAmounts, * budgetFirstQuarterAmounts budgetSecondQuarterAmounts, budgetThirdQuarterAmounts, budgetFourthQuarterAmounts * * @return budgetForecastedCashNeeds budget calculated for every quarter. */ private BudgetForecastedCashNeeds getBudgetForecastedCashNeeds() { ScaleTwoDecimal totalFedCost = ScaleTwoDecimal.ZERO; ScaleTwoDecimal costSharing = ScaleTwoDecimal.ZERO; BigDecimal totalEstimation = ScaleTwoDecimal.ZERO.bigDecimalValue(); BigDecimal costShareEstimation = ScaleTwoDecimal.ZERO.bigDecimalValue(); BigDecimal totalFedEstimation = ScaleTwoDecimal.ZERO.bigDecimalValue(); BudgetForecastedCashNeeds budgetForecastedCashNeeds = BudgetForecastedCashNeeds.Factory.newInstance(); if (budget != null) { BudgetFirstYearAmounts budgetFirstYearAmounts = BudgetFirstYearAmounts.Factory.newInstance(); BudgetFirstQuarterAmounts budgetFirstQuarterAmounts = BudgetFirstQuarterAmounts.Factory.newInstance(); BudgetSecondQuarterAmounts budgetSecondQuarterAmounts = BudgetSecondQuarterAmounts.Factory .newInstance(); BudgetThirdQuarterAmounts budgetThirdQuarterAmounts = BudgetThirdQuarterAmounts.Factory.newInstance(); BudgetFourthQuarterAmounts budgetFourthQuarterAmounts = BudgetFourthQuarterAmounts.Factory .newInstance(); for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) { for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) { if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) { if (budgetPeriod.getBudgetPeriod() == BudgetPeriodNum.P1.getNum()) { costSharing = costSharing.add(lineItem.getCostSharingAmount()); for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : lineItem .getBudgetLineItemCalculatedAmounts()) { costSharing = costSharing .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing()); } } } } if (budgetPeriod.getBudgetPeriod() == BudgetPeriodNum.P1.getNum()) { totalFedCost = budgetPeriod.getTotalCost(); totalFedEstimation = totalFedCost.bigDecimalValue() .divide(new ScaleTwoDecimal(4).bigDecimalValue(), RoundingMode.HALF_UP); costShareEstimation = costSharing.bigDecimalValue() .divide(new ScaleTwoDecimal(4).bigDecimalValue(), RoundingMode.HALF_UP); totalEstimation = totalFedEstimation.add(costShareEstimation); } } budgetFirstYearAmounts.setBudgetFederalForecastedAmount(totalFedCost.bigDecimalValue()); budgetFirstYearAmounts.setBudgetNonFederalForecastedAmount(costSharing.bigDecimalValue()); budgetFirstYearAmounts.setBudgetTotalForecastedAmount(costSharing.add(totalFedCost).bigDecimalValue()); budgetForecastedCashNeeds.setBudgetFirstYearAmounts(budgetFirstYearAmounts); budgetFirstQuarterAmounts.setBudgetFederalForecastedAmount(totalFedEstimation); budgetFirstQuarterAmounts.setBudgetNonFederalForecastedAmount(costShareEstimation); budgetFirstQuarterAmounts.setBudgetTotalForecastedAmount(totalEstimation); budgetForecastedCashNeeds.setBudgetFirstQuarterAmounts(budgetFirstQuarterAmounts); budgetSecondQuarterAmounts.setBudgetFederalForecastedAmount(totalFedEstimation); budgetSecondQuarterAmounts.setBudgetNonFederalForecastedAmount(costShareEstimation); budgetSecondQuarterAmounts.setBudgetTotalForecastedAmount(totalEstimation); budgetForecastedCashNeeds.setBudgetSecondQuarterAmounts(budgetSecondQuarterAmounts); budgetThirdQuarterAmounts.setBudgetFederalForecastedAmount(totalFedEstimation); budgetThirdQuarterAmounts.setBudgetNonFederalForecastedAmount(costShareEstimation); budgetThirdQuarterAmounts.setBudgetTotalForecastedAmount(totalEstimation); budgetForecastedCashNeeds.setBudgetThirdQuarterAmounts(budgetThirdQuarterAmounts); budgetFourthQuarterAmounts.setBudgetFederalForecastedAmount(totalFedEstimation); budgetFourthQuarterAmounts.setBudgetNonFederalForecastedAmount(costShareEstimation); budgetFourthQuarterAmounts.setBudgetTotalForecastedAmount(totalEstimation); budgetForecastedCashNeeds.setBudgetFourthQuarterAmounts(budgetFourthQuarterAmounts); } return budgetForecastedCashNeeds; }
From source file:com.nkapps.billing.dao.OverpaymentDaoImpl.java
private void returnStateRevert(Session session, BankStatement bs, BigDecimal overpaymentSum, Long issuerSerialNumber, String issuerIp, LocalDateTime dateTime) throws Exception { if (!bs.getBankStatementPayments().isEmpty()) { // if bankstatement has payments String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p JOIN p.bankStatementPayment bsp " + " WHERE p.claim = 0 " + " AND bsp.id.bankStatement = :bs" + " ORDER BY p.paymentDate, p.paymentNum "; Query query = session.createQuery(q); query.setParameter("bs", bs); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); List<Payment> paymentList = query.list(); int listSize = paymentList.size(); int currentIndex = 0; BigDecimal keyCost = new BigDecimal(bankStatementDao.getKeyCost()); for (Payment payment : paymentList) { currentIndex++;//w w w. j ava2 s .co m overpaymentSum = overpaymentSum.subtract(payment.getOverSum()); if (currentIndex == listSize) { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(payment.getPaymentSum().add(overpaymentSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = BigDecimal.ZERO; } else { if (payment.getPaymentSum().compareTo(keyCost) < 0) { BigDecimal paymentSum = payment.getPaymentSum(); if (overpaymentSum.add(paymentSum).compareTo(keyCost) <= 0) { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(overpaymentSum.add(paymentSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = BigDecimal.ZERO; } else { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(keyCost); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = overpaymentSum.add(paymentSum).subtract(keyCost); } } } if (overpaymentSum.compareTo(BigDecimal.ZERO) <= 0) { break; } } } }
From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java
/** * @param yearId/*from w w w . j a v a2 s. c o m*/ * @param monthId * @param costCentreId * @param empcntClientProjectDataVoList * @param empcntClientProjectDataList * @param employeeIdList * @param employeeMonthlyAssignmentCount */ private void ruleFive(Integer yearId, Integer monthId, String costCentreId, List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList, EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { BigDecimal assistedTimeZero = BigDecimal.ZERO; BigDecimal allignedTimeZero = BigDecimal.ZERO; EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster(); TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth(); TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear(); CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre(); CountClassification countClassification = new CountClassification(); countClassification.setId(countTypeId); // get the employee aligned project for opening count List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList); for (EmpClientProjectTeamStruct empClientProjectTeamStruct : empClientProjectTeamStructList) { // get the EmpCntPcApportionApproach for the employee and type List<EmpCntPcApportionApproach> empCntPcApportionApproachList = empCntPcApportionApproachDao .findByYearIdMonthIdEmployeeIdTypeId(yearId, monthId, empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId(), countTypeId); // get the EmployeePcTagsTeamStruct for the employee and type List<EmployeePcTagsTeamStruct> employeePcTagsTeamStructList = employeePcTagsTeamStructDao .findByyearIdMonthIdEmployeeIdTypeId(yearId, monthId, empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId(), countTypeId); if (empCntPcApportionApproachList.get(0).getApportionApproach() == 1) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdProfitCentreId(yearId, monthId, profitCentreId); BigDecimal projectCount = new BigDecimal(collageProjectRevenueList.size()); for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { BigDecimal projectValue = BigDecimal.ONE.divide(projectCount, 2, RoundingMode.HALF_EVEN); projectValue = projectValue.multiply(BigDecimal.ONE); projectValue = projectValue.multiply(employeePcTagsTeamStruct.getProportion()); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData( employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(), countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear, costCentre, allignedTimeZero, assistedTimeZero, projectValue, projectValue); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-" + profitCentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(projectValue); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 2) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); List<Object[]> objectList = executionDataDao.findByYearIdMonthIdCostCentreIdProfitCentreId( yearId, monthId, costCentreId, profitCentreId); BigDecimal hoursSum = BigDecimal.ZERO; for (Object[] hours : objectList) { BigDecimal hour = (BigDecimal) hours[1]; hoursSum.add(hour); } for (Object[] result : objectList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; ProjectMaster projectMaster = new ProjectMaster(); projectMaster.setProjectId(projectId); CompanyMaster companyMaster = new CompanyMaster(); companyMaster.setCompanyId(companyId); BigDecimal resultHour = hour.divide(hoursSum, 2, RoundingMode.HALF_EVEN); resultHour = resultHour.multiply(BigDecimal.ONE); resultHour = resultHour.multiply(employeePcTagsTeamStruct.getProportion()); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData( employeeMaster, companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre, allignedTimeZero, assistedTimeZero, resultHour, resultHour); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-" + profitCentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(resultHour); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 3) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdProfitCentreId(yearId, monthId, profitCentreId); BigDecimal revenueSum = BigDecimal.ZERO; for (CollageProjectRevenue val : collageProjectRevenueList) { revenueSum.add(val.getRevenueValue()); } for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { BigDecimal revenueValue = collageProjectRevenue.getRevenueValue().divide(revenueSum, 2, RoundingMode.HALF_EVEN); revenueValue = revenueValue.multiply(BigDecimal.ONE); revenueValue = revenueValue.multiply(employeePcTagsTeamStruct.getProportion()); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData( employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(), countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear, costCentre, allignedTimeZero, assistedTimeZero, revenueValue, revenueValue); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-" + profitCentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(revenueValue); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } } }
From source file:controllers.core.RoadmapController.java
/** * Return the HTML fragment of the KPIs for "scenario simulator". * // w w w . jav a 2s. c om * @throws AccountManagementException */ @Restrict({ @Group(IMafConstants.ROADMAP_SIMULATOR_PERMISSION) }) public Result simulatorKpisFragment() throws AccountManagementException { List<String> ids = FilterConfig.getIdsFromRequest(request()); BigDecimal allocation = BigDecimal.ZERO; BigDecimal allocationConfirmed = BigDecimal.ZERO; BigDecimal allocationNotConfirmed = BigDecimal.ZERO; BigDecimal budget = BigDecimal.ZERO; BigDecimal budgetCapex = BigDecimal.ZERO; BigDecimal budgetOpex = BigDecimal.ZERO; BigDecimal forecast = BigDecimal.ZERO; BigDecimal forecastCapex = BigDecimal.ZERO; BigDecimal forecastOpex = BigDecimal.ZERO; BigDecimal engaged = BigDecimal.ZERO; BigDecimal engagedCapex = BigDecimal.ZERO; BigDecimal engagedOpex = BigDecimal.ZERO; for (String idString : ids) { Long id = Long.valueOf(idString); PortfolioEntry portfolioEntry = PortfolioEntryDao.getPEById(id); // allocation BigDecimal entryAllocatedActorDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEPlanAllocatedActorAsDaysByPEAndConfirmed(portfolioEntry, true); BigDecimal entryAllocatedActorDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEPlanAllocatedActorAsDaysByPEAndConfirmed(portfolioEntry, false); BigDecimal entryAllocatedOrgUnitDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedOrgUnitAsDaysByPE(portfolioEntry, true); BigDecimal entryAllocatedOrgUnitDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedOrgUnitAsDaysByPE(portfolioEntry, false); BigDecimal entryAllocatedCompetencyDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedCompetencyAsDaysByPortfolioEntry(portfolioEntry, true); BigDecimal entryAllocatedCompetencyDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedCompetencyAsDaysByPortfolioEntry(portfolioEntry, false); BigDecimal entryAllocationDaysConfirmed = entryAllocatedActorDaysConfirmed .add(entryAllocatedOrgUnitDaysConfirmed).add(entryAllocatedCompetencyDaysConfirmed); BigDecimal entryAllocationDaysNotConfirmed = entryAllocatedActorDaysNotConfirmed .add(entryAllocatedOrgUnitDaysNotConfirmed).add(entryAllocatedCompetencyDaysNotConfirmed); allocation = allocation.add(entryAllocationDaysConfirmed).add(entryAllocationDaysNotConfirmed); allocationConfirmed = allocationConfirmed.add(entryAllocationDaysConfirmed); allocationNotConfirmed = allocationNotConfirmed.add(entryAllocationDaysNotConfirmed); if (getSecurityService().restrict(IMafConstants.PORTFOLIO_ENTRY_VIEW_FINANCIAL_INFO_ALL_PERMISSION)) { // budget Double entryBudgetCapex = PortfolioEntryDao.getPEAsBudgetAmountByOpex(id, false); Double entryBudgetOpex = PortfolioEntryDao.getPEAsBudgetAmountByOpex(id, true); budget = budget.add(new BigDecimal(entryBudgetCapex + entryBudgetOpex)); budgetCapex = budgetCapex.add(new BigDecimal(entryBudgetCapex)); budgetOpex = budgetOpex.add(new BigDecimal(entryBudgetOpex)); // forecast Double entryCostToCompleteCapex = PortfolioEntryDao .getPEAsCostToCompleteAmountByOpex(this.getPreferenceManagerPlugin(), id, false); Double entryCostToCompleteOpex = PortfolioEntryDao .getPEAsCostToCompleteAmountByOpex(this.getPreferenceManagerPlugin(), id, true); Double entryEngagedCapex = PortfolioEntryDao .getPEAsEngagedAmountByOpex(this.getPreferenceManagerPlugin(), id, false); Double entryEngagedOpex = PortfolioEntryDao .getPEAsEngagedAmountByOpex(this.getPreferenceManagerPlugin(), id, true); forecast = forecast.add(new BigDecimal( entryCostToCompleteCapex + entryCostToCompleteOpex + entryEngagedCapex + entryEngagedOpex)); forecastCapex = forecastCapex.add(new BigDecimal(entryCostToCompleteCapex + entryEngagedCapex)); forecastOpex = forecastOpex.add(new BigDecimal(entryCostToCompleteOpex + entryEngagedOpex)); // engaged engaged = engaged.add(new BigDecimal(entryEngagedCapex + entryEngagedOpex)); engagedCapex = engagedCapex.add(new BigDecimal(entryEngagedCapex)); engagedOpex = engagedOpex.add(new BigDecimal(entryEngagedOpex)); } } budget = budget.setScale(2, RoundingMode.HALF_UP); budgetCapex = budgetCapex.setScale(2, RoundingMode.HALF_UP); budgetOpex = budgetOpex.setScale(2, RoundingMode.HALF_UP); forecast = forecast.setScale(2, RoundingMode.HALF_UP); forecastCapex = forecastCapex.setScale(2, RoundingMode.HALF_UP); forecastOpex = forecastOpex.setScale(2, RoundingMode.HALF_UP); engaged = engaged.setScale(2, RoundingMode.HALF_UP); engagedCapex = engagedCapex.setScale(2, RoundingMode.HALF_UP); engagedOpex = engagedOpex.setScale(2, RoundingMode.HALF_UP); return ok(views.html.core.roadmap.roadmap_simulator_kpis_fragment.render(allocation, allocationConfirmed, allocationNotConfirmed, budget, budgetCapex, budgetOpex, forecast, forecastCapex, forecastOpex, engaged, engagedCapex, engagedOpex)); }
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
public BigDecimal getAllShiftUnitHours(ShiftType shiftType) { BigDecimal totalTime = BigDecimal.ZERO; for (Shift shift : getAssociatedShifts()) { if (shift.containsType(shiftType)) { totalTime = totalTime.add(shift.getUnitHours()); }/*w w w .j a v a 2 s. c om*/ } return totalTime; }
From source file:org.openmrs.module.billing.web.controller.main.BillableServiceBillEditForBDController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, Object command, BindingResult bindingResult, HttpServletRequest request, @RequestParam("cons") Integer[] cons, @RequestParam("patientId") Integer patientId, @RequestParam("billId") Integer billId, @RequestParam("action") String action, @RequestParam(value = "description", required = false) String description) { validate(cons, bindingResult, request); if (bindingResult.hasErrors()) { model.addAttribute("errors", bindingResult.getAllErrors()); return "module/billing/main/patientServiceBillEdit"; }//from www .j av a 2 s . c o m BillingService billingService = Context.getService(BillingService.class); PatientServiceBill bill = billingService.getPatientServiceBillById(billId); // Get the BillCalculator to calculate the rate of bill item the patient // has to pay Patient patient = Context.getPatientService().getPatient(patientId); Map<String, String> attributes = PatientUtils.getAttributes(patient); BillCalculatorForBDService calculator = new BillCalculatorForBDService(); if (!"".equals(description)) bill.setDescription(description); if ("void".equalsIgnoreCase(action)) { bill.setVoided(true); bill.setVoidedDate(new Date()); for (PatientServiceBillItem item : bill.getBillItems()) { item.setVoided(true); item.setVoidedDate(new Date()); /*ghanshyam 7-sept-2012 these 5 lines of code written only due to voided item is being updated in "billing_patient_service_bill_item" table but not being updated in "orders" table */ Order ord = item.getOrder(); if (ord != null) { ord.setVoided(true); ord.setDateVoided(new Date()); } item.setOrder(ord); } billingService.savePatientServiceBill(bill); //ghanshyam 7-sept-2012 Support #343 [Billing][3.2.7-SNAPSHOT]No Queue to be generated from Old bill return "redirect:/module/billing/patientServiceBillEditForBD.list?patientId=" + patientId; } // void old items and reset amount Map<Integer, PatientServiceBillItem> mapOldItems = new HashMap<Integer, PatientServiceBillItem>(); for (PatientServiceBillItem item : bill.getBillItems()) { item.setVoided(true); item.setVoidedDate(new Date()); //ghanshyam-kesav 16-08-2012 Bug #323 [BILLING] When a bill with a lab\radiology order is edited the order is re-sent Order ord = item.getOrder(); /*ghanshyam 18-08-2012 [Billing - Bug #337] [3.2.7 snap shot][billing(DDU,DDU SDMX,Tanda,mohali)]error in edit bill. the problem was while we are editing the bill of other than lab and radiology. */ if (ord != null) { ord.setVoided(true); ord.setDateVoided(new Date()); } item.setOrder(ord); mapOldItems.put(item.getPatientServiceBillItemId(), item); } bill.setAmount(BigDecimal.ZERO); bill.setPrinted(false); PatientServiceBillItem item; int quantity = 0; Money itemAmount; Money mUnitPrice; Money totalAmount = new Money(BigDecimal.ZERO); BigDecimal totalActualAmount = new BigDecimal(0); BigDecimal unitPrice; String name; BillableService service; for (int conceptId : cons) { unitPrice = NumberUtils.createBigDecimal(request.getParameter(conceptId + "_unitPrice")); quantity = NumberUtils.createInteger(request.getParameter(conceptId + "_qty")); name = request.getParameter(conceptId + "_name"); service = billingService.getServiceByConceptId(conceptId); mUnitPrice = new Money(unitPrice); itemAmount = mUnitPrice.times(quantity); totalAmount = totalAmount.plus(itemAmount); String sItemId = request.getParameter(conceptId + "_itemId"); if (sItemId == null) { item = new PatientServiceBillItem(); // Get the ratio for each bill item Map<String, Object> parameters = HospitalCoreUtils.buildParameters("patient", patient, "attributes", attributes, "billItem", item); BigDecimal rate; //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue if (bill.getFreeBill().equals(1)) { String billType = "free"; rate = calculator.getRate(parameters, billType); } else if (bill.getFreeBill().equals(2)) { String billType = "mixed"; PatientServiceBillItem patientServiceBillItem = billingService.getPatientServiceBillItem(billId, name); String psbi = patientServiceBillItem.getActualAmount().toString(); if (psbi.equals("0.00")) { rate = new BigDecimal(0); } else { rate = new BigDecimal(1); } item.setActualAmount(item.getAmount().multiply(rate)); } else { String billType = "paid"; rate = calculator.getRate(parameters, billType); } item.setAmount(itemAmount.getAmount()); item.setActualAmount(item.getAmount().multiply(rate)); totalActualAmount = totalActualAmount.add(item.getActualAmount()); item.setCreatedDate(new Date()); item.setName(name); item.setPatientServiceBill(bill); item.setQuantity(quantity); item.setService(service); item.setUnitPrice(unitPrice); bill.addBillItem(item); } else { item = mapOldItems.get(Integer.parseInt(sItemId)); // Get the ratio for each bill item Map<String, Object> parameters = HospitalCoreUtils.buildParameters("patient", patient, "attributes", attributes, "billItem", item); BigDecimal rate; //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue if (bill.getFreeBill().equals(1)) { String billType = "free"; rate = calculator.getRate(parameters, billType); } else if (bill.getFreeBill().equals(2)) { String billType = "mixed"; PatientServiceBillItem patientServiceBillItem = billingService.getPatientServiceBillItem(billId, name); String psbi = patientServiceBillItem.getActualAmount().toString(); if (psbi.equals("0.00")) { rate = new BigDecimal(0); } else { rate = new BigDecimal(1); } item.setActualAmount(item.getAmount().multiply(rate)); } else { String billType = "paid"; rate = calculator.getRate(parameters, billType); } //ghanshyam 5-oct-2012 [Billing - Support #344] [Billing] Edited Quantity and Amount information is lost in database if (quantity != item.getQuantity()) { item.setVoided(true); item.setVoidedDate(new Date()); } else { item.setVoided(false); item.setVoidedDate(null); } // ghanshyam-kesav 16-08-2012 Bug #323 [BILLING] When a bill with a lab\radiology order is edited the order is re-sent Order ord = item.getOrder(); if (ord != null) { ord.setVoided(false); ord.setDateVoided(null); } item.setOrder(ord); //ghanshyam 5-oct-2012 [Billing - Support #344] [Billing] Edited Quantity and Amount information is lost in database if (quantity != item.getQuantity()) { item = new PatientServiceBillItem(); item.setService(service); item.setUnitPrice(unitPrice); item.setQuantity(quantity); item.setName(name); item.setCreatedDate(new Date()); item.setOrder(ord); bill.addBillItem(item); } item.setAmount(itemAmount.getAmount()); item.setActualAmount(item.getAmount().multiply(rate)); totalActualAmount = totalActualAmount.add(item.getActualAmount()); } } bill.setAmount(totalAmount.getAmount()); bill.setActualAmount(totalActualAmount); // Determine whether the bill is free or not //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue if (bill.getFreeBill().equals(1)) { String billType = "free"; bill.setFreeBill(calculator.isFreeBill(billType)); } else if (bill.getFreeBill().equals(2)) { String billType = "mixed"; bill.setFreeBill(2); } else { String billType = "paid"; bill.setFreeBill(calculator.isFreeBill(billType)); } logger.info("Is free bill: " + bill.getFreeBill()); bill = billingService.savePatientServiceBill(bill); //ghanshyam 7-sept-2012 Support #343 [Billing][3.2.7-SNAPSHOT]No Queue to be generated from Old bill return "redirect:/module/billing/patientServiceBillEditForBD.list?patientId=" + patientId + "&billId=" + billId; }
From source file:com.salesmanager.core.service.order.OrderService.java
/** * Creates a jasper report for Order List * @param report//from w w w . ja v a 2s .c o m * @param locale * @param os * @throws Exception */ public void prepareOrderListReport(OrderReport report, Locale locale, ByteArrayOutputStream os) throws Exception { //calculate all totals Collection orders = report.getOrders(); if (orders == null || orders.size() == 0) return; Map<String, OrderTotal> orderTotals = new HashMap(); List ots = new ArrayList(); for (Object o : orders) { Order order = (Order) o; Set totals = order.getOrderTotal(); for (Object t : totals) { OrderTotal orderTotal = (OrderTotal) t; if (orderTotal.getModule().equalsIgnoreCase(OrderConstants.OT_CREDITS)) { continue; } OrderTotal globalTotal = orderTotals.get(orderTotal.getTitle()); BigDecimal amount = null; if (globalTotal == null) { globalTotal = new OrderTotal(); globalTotal.setModule(orderTotal.getModule()); globalTotal.setOrderId(orderTotal.getOrderId()); globalTotal.setOrderTotalId(orderTotal.getOrderTotalId()); globalTotal.setSortOrder(orderTotal.getSortOrder()); globalTotal.setTitle(orderTotal.getTitle()); orderTotals.put(orderTotal.getTitle(), globalTotal); amount = new BigDecimal("0"); globalTotal.setValue(amount); ots.add(globalTotal); } amount = globalTotal.getValue(); amount = amount.add(orderTotal.getValue()); globalTotal.setValue(amount); globalTotal.setText(CurrencyUtil.displayFormatedAmountWithCurrency(amount, order.getCurrency())); } } report.setTotals(ots); List<OrderReport> reportList = new ArrayList<OrderReport>(); reportList.add(report); Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(JRParameter.REPORT_LOCALE, locale); parameters.put("BASE_DIR", JASPERREPORT_DIR); JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(reportList); JasperPrint jprint = JasperFillManager.fillReport(this.getClass().getClassLoader().getResourceAsStream( JASPERREPORT_DIR + conf.getString("core.report.orders")), parameters, dataSource); JasperExportManager.exportReportToPdfStream(jprint, os); }
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
/** * Resolve the first authorization level for the given payment, if any. When the payment wouldn't be authorizable, return null *///from w w w . j a v a 2 s.c o m private AuthorizationLevel firstAuthorizationLevel(TransferType transferType, final BigDecimal amount, AccountOwner from) { transferType = fetchService.fetch(transferType, TransferType.Relationships.AUTHORIZATION_LEVELS); if (transferType.isRequiresAuthorization() && CollectionUtils.isNotEmpty(transferType.getAuthorizationLevels())) { if (from == null) { from = LoggedUser.accountOwner(); } final Account account = accountService.getAccount(new AccountDTO(from, transferType.getFrom())); BigDecimal amountSoFarToday = transferDao.getTransactionedAmountAt(null, account, transferType); final AuthorizationLevel authorization = transferType.getAuthorizationLevels().iterator().next(); // When the amount is greater than the authorization, return true final BigDecimal amountToTest = amountSoFarToday.add(amount); if (amountToTest.compareTo(authorization.getAmount()) >= 0) { return transferType.getAuthorizationLevels().iterator().next(); } } return null; }