List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398FellowshipSupplementalV1_1Generator.java
private ScaleTwoDecimal getNumberOfMonths(Date dateStart, Date dateEnd) { BigDecimal monthCount = ScaleTwoDecimal.ZERO.bigDecimalValue(); int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart);/*from w w w. j a v a 2 s . co m*/ endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = new ScaleTwoDecimal(startMonthDays).bigDecimalValue() .divide(new ScaleTwoDecimal(startMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = new ScaleTwoDecimal(endMonthDays).bigDecimalValue() .divide(new ScaleTwoDecimal(endMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount).bigDecimalValue()).add(startMonthFraction) .add(endMonthFraction); return new ScaleTwoDecimal(monthCount); }
From source file:com.mg.merp.planning.support.MPSProcessorServiceBean.java
private RollUpMPSResult rollUpMPS(Mps mpsDst, MpsLine srcMpsLine, BigDecimal quan, Date countDay, int mpsSequence) { BigDecimal roundedQty = quan; if (srcMpsLine.getPlanningItem().getCatalog() != null) { Bom bom = bomService.findCurrentBOM(srcMpsLine.getPlanningItem().getCatalog().getId()); if (bom != null) { BigDecimal maxQty = bom.getMaxLotQty(); BigDecimal minQty = bom.getMinLotQty(); BigDecimal increment = bom.getLotIncrementQty(); if (!(MathUtils.compareToZeroOrNull(maxQty) == 0 || MathUtils.compareToZeroOrNull(minQty) == 0 || MathUtils.compareToZeroOrNull(increment) == 0)) { if (bom.getCatalog().getMeasure1().getId() != srcMpsLine.getPlanningItem().getMeasure() .getId()) {// w w w .ja v a2 s .c o m maxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), maxQty); minQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), minQty); increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), increment); } long numOfMax = roundedQty.divide(maxQty).longValue(); roundedQty = maxQty.multiply(new BigDecimal(numOfMax)); BigDecimal remainder = roundedQty.add(roundedQty); if (MathUtils.compareToZero(remainder) != 0) { if (remainder.compareTo(minQty) < 0) { roundedQty = roundedQty.add(minQty); } else { long numOfInc = remainder.subtract(minQty).divide(increment).longValue(); BigDecimal remInc = remainder.subtract(minQty) .subtract(increment.multiply(new BigDecimal(numOfInc))); if (MathUtils.compareToZero(remInc) != 0) roundedQty = roundedQty.add(minQty) .add(increment.multiply(new BigDecimal(numOfInc))).add(increment); else roundedQty = roundedQty.add(remainder); } } } } } short bucket = MfUtils.determineBucketOffset(mpsDst.getPlanningLevel().getId(), countDay); MpsLine mpsLine = null; for (MpsLine line : generatedMPSLines) { if (MathUtils.compareToZero(line.getProductionDemandQty()) <= 0 && line.getPlanningItem().getId() == srcMpsLine.getPlanningItem().getId() && line.getBucketOffset() == bucket) { mpsLine = line; break; } } if (mpsLine == null) { mpsLine = mpsLineService.initialize(); mpsLine.setPlanningItem(srcMpsLine.getPlanningItem()); mpsLine.setLevelCode(srcMpsLine.getPlanningItem().getLowLevelCode()); mpsLine.setMps(mpsDst); mpsLine.setBucketOffset(bucket); BucketRange bucketRange = MfUtils.determineBucketRange(mpsDst.getPlanningLevel().getId(), bucket); mpsLine.setBucketOffsetDate(bucketRange.getBucketStart()); mpsLine.setDemandFenceDate(srcMpsLine.getDemandFenceDate()); mpsLine.setMpsSequence(mpsSequence); mpsLine.setOutputMpsSequence(null); mpsLine.setMeasure(srcMpsLine.getMeasure()); mpsLine.setPlannedQty(roundedQty); generatedMPSLines.add(mpsLine); // ? MPS return new RollUpMPSResult(roundedQty, mpsSequence + 1); } else { mpsLine.setPlannedQty(mpsLine.getPlannedQty().add(roundedQty)); return new RollUpMPSResult(roundedQty, mpsSequence); } }
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
private Validator getPaymentValidator(final DoPaymentDTO payment) { final Validator validator = new Validator("transfer"); Collection<TransactionContext> possibleContexts = new ArrayList<TransactionContext>(); possibleContexts.add(TransactionContext.PAYMENT); if (LoggedUser.isWebService() || LoggedUser.isSystem()) { possibleContexts.add(TransactionContext.AUTOMATIC); } else {/*w w w .ja v a 2 s . c o m*/ possibleContexts.add(TransactionContext.SELF_PAYMENT); } validator.property("context").required().anyOf(possibleContexts); validator.property("to").required().key("payment.recipient"); // as currency is maybe not set on the DTO, we get it from the TT in stead of directly from the DTO final TransferType tt = fetchService.fetch(payment.getTransferType(), Relationships.TRANSACTION_FEES, RelationshipHelper.nested(TransferType.Relationships.FROM, TransferType.Relationships.TO, AccountType.Relationships.CURRENCY, Currency.Relationships.A_RATE_PARAMETERS), RelationshipHelper.nested(TransferType.Relationships.FROM, TransferType.Relationships.TO, AccountType.Relationships.CURRENCY, Currency.Relationships.D_RATE_PARAMETERS)); final Currency currency = tt == null ? null : tt.getCurrency(); if (currency != null && (currency.isEnableARate() || currency.isEnableDRate())) { // if the date is not null at this moment, it is in the past, which is not allowed with rates. if (payment.getDate() != null) { validator.general(new NoPastDateWithRatesValidator()); } } else { validator.property("date").key("payment.manualDate").past(); } validator.property("ticket").add(new TicketValidation()); addAmountValidator(validator, tt); validator.property("transferType").key("transfer.type").required(); validator.property("description").maxLength(1000); validator.general(new SchedulingValidator()); validator.general(new PendingContractValidator()); if (payment.getTransferType() != null && payment.getTo() != null && payment.getAmount() != null) { /* * For user validation, we need to check if the transaction amount is high enough to cover all fees. This depends on all fees, but only in * case of fixed fees it makes sense to increase the transaction amount. The formula for this is: given transactionamount > (sum of fixed * fees )/ (1 minus sum of percentage fees expressed as fractions). This of course only applies for fees with deductAmount; fees which are * not deducted are excluded from this calculation. */ final TransactionFeePreviewDTO preview = transactionFeeService.preview(payment.getFrom(), payment.getTo(), tt, payment.getAmount()); final Property amount = validator.property("amount"); final Collection<? extends TransactionFee> fees = preview.getFees().keySet(); BigDecimal sumOfFixedFees = BigDecimal.ZERO; BigDecimal sumOfPercentageFees = BigDecimal.ZERO; for (final TransactionFee fee : fees) { if (fee.isDeductAmount()) { if (fee.getChargeType() == ChargeType.FIXED) { sumOfFixedFees = sumOfFixedFees.add(preview.getFees().get(fee)); } else { sumOfPercentageFees = sumOfPercentageFees.add(preview.getFees().get(fee)); } } } // Show a warning if there are fixed fees and if the amount is not enough to cover them if (sumOfFixedFees.signum() == 1) { final int scale = LocalSettings.MAX_PRECISION; final MathContext mc = new MathContext(scale); final BigDecimal sumOfPercentages = sumOfPercentageFees.divide(payment.getAmount(), mc); final BigDecimal minimalAmount = sumOfFixedFees.divide((BigDecimal.ONE.subtract(sumOfPercentages)), mc); amount.comparable(minimalAmount, ">", new ValidationError("errors.greaterThan", messageResolver.message("transactionFee.invalidChargeValue", minimalAmount))); } else if (preview.getFinalAmount().signum() == -1) { validator.general(new FinalAmountValidator()); } // Custom fields validator.chained(new DelegatingValidator(new DelegatingValidator.DelegateSource() { @Override public Validator getValidator() { return paymentCustomFieldService.getValueValidator(payment.getTransferType()); } })); } return validator; }
From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java
/** * @param yearId/*from w w w . j a v a 2s. com*/ * @param monthId * @param costCentreId * @param empcntClientProjectDataVoList * @param empcntClientProjectDataList * @param employeeIdList * @param employeeMonthlyAssignmentCount */ private void ruleFour(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 { BigDecimal toatalHours = BigDecimal.ZERO; BigDecimal proportionToSpecificProject = BigDecimal.ZERO; for (Integer key : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key); List<BigDecimal> findByProjectId = executionDataDao .findByProjectId(empClientProjectTeamStruct.getProjectMaster().getProjectId()); toatalHours.add(findByProjectId.get(0)); } for (Integer key : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key); List<BigDecimal> projectIdList = executionDataDao .findByProjectId(empClientProjectTeamStruct.getProjectMaster().getProjectId()); proportionToSpecificProject = projectIdList.get(0).divide(toatalHours, 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:com.mg.merp.planning.support.MPSProcessorServiceBean.java
private void calculateProductionPlan(short lowLevelCode) { //? PlanningItem, BucketOffset desc Collections.sort(generatedMPSLines, new Comparator<MpsLine>() { public int compare(MpsLine o1, MpsLine o2) { if (o1.getPlanningItem().getId() < o2.getPlanningItem().getId()) return 1; else if (o1.getPlanningItem().getId() > o2.getPlanningItem().getId()) return -1; else { if (o1.getBucketOffset() < o2.getBucketOffset()) return 1; else if (o1.getBucketOffset() > o2.getBucketOffset()) return -1; else return 0; }/*from w w w . ja va 2s . c o m*/ } }); BigDecimal availableOnBeginBucket = BigDecimal.ZERO; GenericItem currentPlanningItem = null; for (MpsLine mpsLine : generatedMPSLines) { if (MathUtils.compareToZero(mpsLine.getProductionDemandQty()) <= 0 && mpsLine.getLevelCode() == lowLevelCode) { if (currentPlanningItem == null || currentPlanningItem.getId() != mpsLine.getPlanningItem().getId()) { currentPlanningItem = mpsLine.getPlanningItem(); availableOnBeginBucket = BigDecimal.ZERO; } BigDecimal plannedQty = mpsLine.calculatePlannedQuantity(availableOnBeginBucket); Bom bom = bomService.findCurrentBOM(currentPlanningItem.getCatalog().getId()); if (bom != null) { BigDecimal MaxQty = bom.getMaxLotQty(), MinQty = bom.getMinLotQty(), Increment = bom.getLotIncrementQty(), Remainder, RemInc; if (!(MathUtils.compareToZeroOrNull(MaxQty) == 0 || MathUtils.compareToZeroOrNull(MinQty) == 0 || MathUtils.compareToZeroOrNull(Increment) == 0)) { //? ? ? if (bom.getCatalog().getMeasure1().getId() != mpsLine.getMeasure().getId()) { MaxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MaxQty); MinQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MinQty); Increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), Increment); } long NumOfMax = plannedQty.divide(MaxQty).longValue(); Remainder = plannedQty.subtract(MaxQty.multiply(new BigDecimal(NumOfMax))); plannedQty = MaxQty.multiply(new BigDecimal(NumOfMax)); if (MathUtils.compareToZero(Remainder) != 0) { if (Remainder.compareTo(MinQty) == -1) plannedQty = plannedQty.add(MinQty); else { long NumOfInc = Remainder.subtract(MinQty).divide(Increment).longValue(); RemInc = Remainder.subtract(MinQty) .subtract(Increment.multiply(new BigDecimal(NumOfInc))); if (MathUtils.compareToZero(RemInc) != 0) plannedQty = plannedQty.add(MinQty) .add(Increment.multiply(new BigDecimal(NumOfInc))).add(Increment); else plannedQty = plannedQty.add(Remainder); } } } } availableOnBeginBucket = mpsLine.calculateAvailableQuantityOnEndBucket(plannedQty, availableOnBeginBucket); if (MathUtils.compareToZero(plannedQty) < 0) plannedQty = BigDecimal.ZERO; mpsLine.setPlannedQty(plannedQty); } } }
From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java
/** * @param yearId/*from www . j av a 2 s. c om*/ * @param monthId * @param costCentreId * @param empcntClientProjectDataVoList * @param empcntClientProjectDataList * @param employeeIdList * @param employeeMonthlyAssignmentCount */ private void ruleSix(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 constantHours = new BigDecimal(Constants.TOTAL_WORKING_HOURS); BigDecimal allignedTimeZero = BigDecimal.ZERO; 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 Total hours of existing project then do for profit centre // projects; Map<Integer, Set<Integer>> employeeIdProjectIdsMap = new HashMap<Integer, Set<Integer>>(); Map<Integer, Integer> projectIdCompanyIdsMap = new HashMap<Integer, Integer>(); for (EmpClientProjectTeamStruct empClientProjectTeamStruct : empClientProjectTeamStructList) { int employeeId = empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId(); Integer projectId = empClientProjectTeamStruct.getProjectMaster().getProjectId(); Integer companyId = empClientProjectTeamStruct.getCompanyMaster().getCompanyId(); if (employeeIdProjectIdsMap.containsKey(employeeId) && employeeIdProjectIdsMap.get(employeeId) != null) { employeeIdProjectIdsMap.get(employeeId).add(projectId); } else { Set<Integer> projectIds = new HashSet<Integer>(); projectIds.add(projectId); employeeIdProjectIdsMap.put(employeeId, projectIds); } projectIdCompanyIdsMap.put(projectId, companyId); } for (Integer employeeId : employeeIdProjectIdsMap.keySet()) { Set<Integer> projectIds = new HashSet<Integer>(); BigDecimal proportionOfCount = BigDecimal.ZERO; projectIds.addAll(employeeIdProjectIdsMap.get(employeeId)); for (Integer projectId : projectIds) { List<BigDecimal> totalHour = executionDataDao.findByProjectId(projectId); BigDecimal propotionOfProject = totalHour.get(0).divide(constantHours, 2, RoundingMode.HALF_EVEN); proportionOfCount = proportionOfCount.add(propotionOfProject); ProjectMaster pMaster = new ProjectMaster(); pMaster.setProjectId(projectId); CompanyMaster cMaster = new CompanyMaster(); cMaster.setCompanyId(projectIdCompanyIdsMap.get(projectId)); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster, cMaster, countClassification, tabMonth, pMaster, tabYear, costCentre, allignedTimeZero, propotionOfProject, apportionedTimeZero, propotionOfProject); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } List<Integer> projectIdList = new ArrayList<Integer>(projectIds); // get the EmpCntPcApportionApproach for the employee and type List<EmpCntPcApportionApproach> empCntPcApportionApproachList = empCntPcApportionApproachDao .findByYearIdMonthIdEmployeeIdTypeId(yearId, monthId, employeeId, countTypeId); // get the EmployeePcTagsTeamStruct for the employee and type List<EmployeePcTagsTeamStruct> employeePcTagsTeamStructList = employeePcTagsTeamStructDao .findByyearIdMonthIdEmployeeIdTypeId(yearId, monthId, employeeId, countTypeId); BigDecimal remainingCount = BigDecimal.ONE.subtract(proportionOfCount); if (empCntPcApportionApproachList.get(0).getApportionApproach() == 1) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdProfitCentreIdProjectIds(yearId, monthId, profitCentreId, projectIdList); BigDecimal projectCount = new BigDecimal(collageProjectRevenueList.size()); for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { BigDecimal projectValue = BigDecimal.ONE.divide(projectCount, 2, RoundingMode.HALF_EVEN); projectValue = projectValue.multiply(remainingCount); 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 .findByYearIdMonthIdCostCentreIdProfitCentreIdProjectIds(yearId, monthId, costCentreId, profitCentreId, projectIdList); 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(remainingCount); 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 .findByYearIdMonthIdProfitCentreIdProjectIds(yearId, monthId, profitCentreId, projectIdList); BigDecimal revenueSum = BigDecimal.ZERO; for (CollageProjectRevenue val : collageProjectRevenueList) { revenueSum.add(val.getRevenueValue()); } for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { BigDecimal revenueValue = collageProjectRevenue.getRevenueValue().divide(revenueSum); revenueValue = revenueValue.multiply(remainingCount); 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:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java
public BigDecimal getSpecialSeasonEcts(ExecutionYear executionYear) { Collection<Enrolment> specialSeasonEnrolments = getSpecialSeasonEnrolments(executionYear); BigDecimal result = BigDecimal.ZERO; for (Enrolment enrolment : specialSeasonEnrolments) { result = result.add(BigDecimal.valueOf(enrolment.getEctsCredits())); }//from w w w .j a v a 2 s .c o m return result; }
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * ???? list?,?// w w w. j av a 2 s . co m * * @param cartList * @return * @author jiaodongzhi */ @Override public List<ShoppingCart> getNobaoyouShoppingcarts(List<ShoppingCart> cartList) { // ??? List<ShoppingCart> nobaoyou = new ArrayList<>(); Marketing marketing = null; if (CollectionUtils.isNotEmpty(cartList)) { Map<String, Object> map = new HashMap<>(); // ?,? List<ShoppingCart> baoyou = new ArrayList<>(); for (int i = 0; i < cartList.size(); i++) { if (cartList.get(i) != null && cartList.get(i).getGoodsInfoId() != null) { // ?id,??,?()?; map.put(GOODSID, cartList.get(i).getGoodsInfoId()); map.put("codeType", "12"); marketing = marketingMapper.queryMarketingByGoodIdAndtype(map); // if (null != marketing) { cartList.get(i).setMarketing(marketing); baoyou.add(cartList.get(i)); } else { // ? nobaoyou.add(cartList.get(i)); } } } // id Map<Long, String> groups = new HashMap<Long, String>(); // ? boss?id0 List<List<ShoppingCart>> shopThirdList = new ArrayList<>(); Long thirdId = null; if (CollectionUtils.isNotEmpty(baoyou)) { for (ShoppingCart pd : baoyou) { thirdId = pd.getThirdId(); groups.put(thirdId, ""); } List<ShoppingCart> scart = null; if (groups != null && !groups.isEmpty()) { for (Long rawTypeId : groups.keySet()) { scart = new ArrayList<>(); for (ShoppingCart sc : baoyou) { if (rawTypeId.equals(sc.getThirdId())) { // ?thirdId scart.add(sc); } } shopThirdList.add(scart); } } BigDecimal aftermoney = BigDecimal.valueOf(0); Long countgoods = 0L; List<ShoppingCart> shop = new ArrayList<>(); for (int m = 0; m < shopThirdList.size(); m++) { // third? baoyou = shopThirdList.get(m); ShoppingCart sc = new ShoppingCart(); for (int j = 0; j < baoyou.size(); j++) { GoodsProduct goodsProduct = goodsProductMapper .queryByGoodsInfoDetail(baoyou.get(j).getGoodsInfoId()); BigDecimal goodsMoney = goodsProduct.getGoodsInfoPreferPrice(); Map<String, Object> mapGoods = new HashMap<String, Object>(); // id??,?()?; Marketing mark = marketingMapper.marketingDetail(baoyou.get(j).getMarketingId()); // ? if (null != mark) { mapGoods.put(MARKETINGID, mark.getMarketingId()); mapGoods.put(GOODSID, baoyou.get(j).getGoodsInfoId()); } countgoods = baoyou.get(j).getGoodsNum(); // ? aftermoney = aftermoney.add(goodsMoney.multiply(BigDecimal.valueOf(countgoods))); sc.setMarketgoodsPrice(aftermoney); sc.setThirdId(baoyou.get(j).getThirdId()); shop.add(sc); } // ? // Map<String, Object> app = new HashMap<>(); for (int k = 0; k < baoyou.size(); k++) { // ??? for (ShoppingCart scra : shop) { if (scra.getThirdId().equals(baoyou.get(k).getThirdId()) && scra.getMarketgoodsPrice() .compareTo(baoyou.get(k).getMarketing().getShippingMoney()) == -1) { // ?? nobaoyou.add(baoyou.get(k)); } } } } } } return nobaoyou; }
From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java
/** * @param empcntClientProjectDataList//from ww w .jav a 2 s . c o m * @param empClientProjectTeamStructList * @param employee * @param month * @param year * @param costCentre * @param countType * @param allignedTimeZero * @param assistedTimeZero * @param apportionedTimeZero * @param allignedTimeOne * @param totalTimeOne */ private void getSingleProjectDetail(List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpClientProjectTeamStruct> empClientProjectTeamStructList, EmployeeMaster employee, TabMonth month, TabYear year, CostCentre costCentre, CountClassification countType, BigDecimal allignedTimeZero, BigDecimal assistedTimeZero, BigDecimal apportionedTimeZero, BigDecimal allignedTimeOne, BigDecimal totalTimeOne, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { /* * Also assign to assisted if project detail present in both assigned * and unassigned list * * Note : Only in unassigned project . do the remaining count as per * revenue to apportion * * If not present in revenue table then go to zero project details */ logger.debug("<====getSingleProjectDetail START====>"); Integer employeeId = employee.getEmployeeId(); Integer yearId = year.getYearId(); Integer monthId = month.getMonthId(); String costCentreId = costCentre.getCostCentreId(); BigDecimal deviderHour = new BigDecimal(Constants.TOTAL_WORKING_HOURS); logger.debug("getSingleProjectDetail parameter===>" + employeeId + "::" + yearId + "::" + monthId + "::" + costCentreId + "::" + deviderHour); // 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()) { getZeroProjectsDetail(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, totalTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // Get list of project from execution data for that employee List<Integer> projectIdList = executionDataDao.findByPersonYearMonthCostCentre(employeeId, yearId, monthId, costCentreId); // logger.debug("execution data projects===>" + projectIdList.size()); if (projectIdList.isEmpty()) { // logger.debug("Contain InValid projects :(Assign count one)===>"); for (Integer projectId : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); // logger.debug("978: Contain InValid projects :(Assign count one)===>"+1); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, allignedTimeOne, assistedTimeZero, apportionedTimeZero, allignedTimeOne); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } else if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Else Contain Valid projects===>"); Integer validEmployeeProjectCount = validEmployeeProjectIds.size(); // Get valid projects list=>project is both revenue data and // execution data Set<Integer> validAllProjects = new HashSet<Integer>(); for (Integer projectId : projectIdList) { List<CollageProjectRevenue> listValues = collageProjectRevenueDao .findByYearIdMonthIdProjectIdCostCentreId(yearId, monthId, projectId, costCentreId); if (!listValues.isEmpty()) { validAllProjects.add(projectId); } } Integer validAllProjectCount = validAllProjects.size(); // logger.debug("validAllProjects :size===>" + // validAllProjects.size()); // Total hour worked by an Employee List<BigDecimal> toatalHours = executionDataDao.findByPersonIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); BigDecimal toatlTime = toatalHours.get(0); // logger.debug("ToatalHours===>" + toatlTime); // Separate assigned projects from execution data projects Map<Integer, BigDecimal> assignedProjects = new HashMap<Integer, BigDecimal>(); Map<Integer, BigDecimal> unAssignedProjects = new HashMap<Integer, BigDecimal>(); List<Object[]> allProjectTimeList = executionDataDao .findByEmployeeIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); for (Object[] result : allProjectTimeList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; if (validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("UnAssignedProjects===>" + // projectId+"::"+hour+"::"+companyId); assignedProjects.put(projectId, hour); } if (!validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("assignedProjects===>" + // projectId+"::"+hour+"::"+companyId); unAssignedProjects.put(projectId, hour); } } if (validEmployeeProjectCount == 1 && validAllProjectCount == 1 && validAllProjects.containsAll(validEmployeeProjectIds.keySet()) && unAssignedProjects.isEmpty()) { // logger.debug("validEmployeeProjectCount==validAllProjectCount :(Only in assigned projects)"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); // logger.debug("1034 :validEmployeeProjectCount==validAllProjectCount :(Only in assigned projects)===>1"); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, allignedTimeOne, assistedTimeZero, apportionedTimeZero, allignedTimeOne); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else if (!assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("1047 : Both in assigned and unassigned projects===>"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1056 :assigned:(Both in assigned and unassigned projects===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, workedHours, assistedTimeZero, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1073 :unassigned :(Both in assigned and unassigned projects===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // Assign to assisted count for unAssignedProjects Integer projectId = key; List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("769: Assisted hours (Both in assigned and unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } totalUnAssingnedHours = BigDecimal.ONE.subtract(totalUnAssingnedHours); // logger.debug("totalUnAssingnedHours===> "+totalUnAssingnedHours); for (Map.Entry<Integer, BigDecimal> entry : assignedProjects.entrySet()) { assingnedHours = assingnedHours.add(entry.getValue()); } // logger.debug("assingnedHours===> "+assingnedHours); for (Integer key : assignedProjects.keySet()) { Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); // logger.debug("1119 :projectId : timeByProject===> "+projectId+" : "+timeByProject); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal averageWorkedHours = timeByProject.divide(assingnedHours, 2, RoundingMode.HALF_EVEN); // logger.debug("1121 :assingnedHours : totalUnAssingnedHours===> "+assingnedHours+" : "+totalUnAssingnedHours); BigDecimal actualWorkedHours = averageWorkedHours.multiply(totalUnAssingnedHours); actualWorkedHours = actualWorkedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1124 :averageWorkedHours : actualWorkedHours===> "+averageWorkedHours+" : "+actualWorkedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, actualWorkedHours, assistedTimeZero, apportionedTimeZero, actualWorkedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } } else if (assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("In unassigned projects only===>"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1148 :In unassigned projects only===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); // Assign to assisted count for unAssignedProjects Integer projectId = key; List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("1173: Assisted hours (In unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } logger.debug("1209 totalUnAssingnedHours===> " + totalUnAssingnedHours); BigDecimal remainProportion = BigDecimal.ONE.subtract(totalUnAssingnedHours); logger.debug("remainProportion===> " + remainProportion); getRevenueCountProportion(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, remainProportion, unAssignedProjects, countTypeId, employeePcTagsTeamStructMap); } } } // logger.debug("<====getSingleProjectDetail END====>"); }