List of usage examples for java.math RoundingMode HALF_EVEN
RoundingMode HALF_EVEN
To view the source code for java.math RoundingMode HALF_EVEN.
Click Source Link
From source file:com.artivisi.biller.simulator.gateway.pln.PlnGateway.java
private boolean handleInquiryPostpaid(ISOSource src, ISOMsg msg, ISOMsg response) throws ISOException, IOException, VetoException { String bit48Request = msg.getString(48); if (bit48Request.length() != 19) { logger.error("[POSTPAID] - [INQ-REQ] - Invalid bit 48 [{}]", bit48Request); response.set(39, ResponseCode.ERROR_INVALID_MESSAGE); src.send(response);/*www . j av a 2 s .co m*/ return true; } String mitra = bit48Request.substring(0, 7); if (billerSimulatorService.findMitraByKode(mitra.trim()) == null) { logger.debug("[POSTPAID] - [INQ-REQ] - Mitra [{}]", mitra); logger.error("[POSTPAID] - [INQ-REQ] - Kode mitra tidak ditemukan [{}]", mitra); response.set(39, ResponseCode.ERROR_UNREGISTERED_SWITCHING); src.send(response); return true; } String idpel = bit48Request.substring(7); Pelanggan p = plnSimulatorService.findPelangganByIdpel(idpel); if (p == null) { logger.error("[POSTPAID] - [INQ-REQ] - IDPEL tidak ditemukan [{}]", idpel); response.set(39, ResponseCode.ERROR_UNKNOWN_SUBSCRIBER); src.send(response); return true; } if (!ResponseCode.SUCCESSFUL.equals(p.getResponseCode())) { logger.error("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk RC [{}]", p.getResponseCode()); response.set(39, p.getResponseCode()); src.send(response); return true; } List<TagihanPascabayar> daftarTagihan = plnSimulatorService.findTagihan(p); if (daftarTagihan.size() < 1) { logger.error("[POSTPAID] - [INQ-REQ] - Tagihan untuk idpel [{}] tidak ada", idpel); response.set(39, ResponseCode.ERROR_CURRENT_BILL_IS_NOT_AVAILABLE); src.send(response); return true; } List<TagihanPascabayar> tagihanDikirim; if (daftarTagihan.size() > 4) { tagihanDikirim = daftarTagihan.subList(0, 4); } else { tagihanDikirim = daftarTagihan; } BigDecimal amount = BigDecimal.ZERO; for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) { amount = amount.add(tagihanPascabayar.getBill()); amount = amount.add(tagihanPascabayar.getDenda()); } response.set(4, "360" + "0" + StringUtils.leftPad(amount.setScale(0, RoundingMode.HALF_EVEN).toString(), 12, "0")); InquiryPostpaidResponse ipr = new InquiryPostpaidResponse(); ipr.setBank(msg.getString(32)); ipr.setSwitcher(mitra); ipr.setStan(msg.getString(11)); for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) { InquiryPostpaidResponseDetail detail = new InquiryPostpaidResponseDetail(); detail.setTagihanPascabayar(tagihanPascabayar); detail.setInquiryPostpaidResponse(ipr); ipr.getDetails().add(detail); } plnService.save(ipr); StringBuffer bit48Response = createBit48InquiryPostpaidResponse(bit48Request, p, daftarTagihan, tagihanDikirim, ipr); response.set(39, ResponseCode.SUCCESSFUL); response.set(48, bit48Response.toString()); try { logger.info("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk hold [{}]", p.getHoldResponse()); Thread.sleep(p.getHoldResponse()); } catch (Exception e) { logger.error(e.getMessage(), e); } src.send(response); return true; }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java
/** * When comment is selected, additional information is displayed in the form * of location coordinates and action buttons. * This method sets that location field TextView in * the view.// ww w . ja v a 2s. co m * * @param view The View of the Comment that was selected. * @param comment The Comment itself that was selected by the user. */ public void setLocationField(View view, Comment comment) { TextView replyLocationText = (TextView) view.findViewById(R.id.thread_view_comment_location); GeoLocation repLocCom = comment.getLocation(); if (repLocCom != null) { if (repLocCom.getLocationDescription() != null) { replyLocationText.setText("near: " + repLocCom.getLocationDescription()); } else { DecimalFormat format = new DecimalFormat(); format.setRoundingMode(RoundingMode.HALF_EVEN); format.setMinimumFractionDigits(0); format.setMaximumFractionDigits(4); replyLocationText.setText("Latitude: " + format.format(repLocCom.getLatitude()) + " Longitude: " + format.format(repLocCom.getLongitude())); } } else { replyLocationText.setText("Error: No location found"); } }
From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java
/** * Displays the accounts' movements balances by period * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted *///w ww . j av a 2 s.c om private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Movements' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the movements' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphMovementsBalancesTopComponent.class, "GraphMovementsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelMovementsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>( balances.get(moneyContainer).keySet()); for (SearchCriteria searchCriteria : sortedSearchFilters) { BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria); accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN); dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelMovementsBalances.removeAll(); jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER); jPanelMovementsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:com.github.rinde.rinsim.scenario.measure.MetricsTest.java
@Test public void dynamismTest2() { final double[] ordersPerHour = { 15d };// , 20d, 50d, 100d, 1000d }; final StandardDeviation sd = new StandardDeviation(); final RandomGenerator rng = new MersenneTwister(123L); final List<Times> times = newArrayList(); // for (int i = 0; i < 10; i++) { // times.add(generateTimes(rng)); // }/*from w ww.ja v a 2 s. c o m*/ times.add(asTimes(1000, 250L, 500L, 750L)); times.add(asTimes(1000, 100L, 500L, 750L)); times.add(asTimes(1000, 100L, 200L, 300L, 400L, 500L, 600L, 700L, 800L, 900L)); times.add(asTimes(1000, 100L, 200L, 300L, 399L, 500L, 600L, 700L, 800L, 900L)); times.add(asTimes(1000, 10L, 150L, 250L, 350L, 450L, 550L, 650L, 750L, 850L, 950L)); times.add(asTimes(1000, 50L, 150L, 250L, 350L, 450L, 551L, 650L, 750L, 850L, 950L)); times.add(asTimes(1000, 250L, 500L, 750L)); times.add(asTimes(1000, 0L, 50L, 55L, 57L, 59L, 60L, 100L, 150L, 750L)); times.add(asTimes(1000, 5L, 5L, 5L, 5L)); times.add(asTimes(1000, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L)); times.add(asTimes(1000, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L)); times.add(asTimes(1000, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 999L)); times.add(asTimes(1000, 500L, 500L, 500L, 500L)); times.add(asTimes(1000, 5L, 5L, 5L, 5L, 400L, 410L, 430L, 440L, 800L, 810L, 820L, 830L)); times.add(asTimes(1000, 0L, 0L, 0L)); times.add(asTimes(1000, 1L, 1L, 1L)); times.add(asTimes(1000, 999L, 999L, 999L)); times.add(asTimes(1000, 0L, 0L, 500L, 500L, 999L, 999L)); times.add(asTimes(1000, 250L, 250L, 500L, 500L, 750L, 750L)); times.add(asTimes(1000, 250L, 250L, 250L, 500L, 500L, 500L, 750L, 750L, 750L)); for (int i = 0; i < 10; i++) { times.add(generateTimes(rng, 10d)); } for (int i = 0; i < 10; i++) { times.add(generateTimes(rng, 30d)); } for (int i = 0; i < 5; i++) { final List<Double> ts = generateTimes(rng, 50d).list; final List<Double> newTs = newArrayList(); for (final double l : ts) { newTs.add(l); newTs.add(Math.min(999, Math.max(0, l + DoubleMath.roundToLong(rng.nextDouble() * 6d - 3d, RoundingMode.HALF_EVEN)))); } times.add(asTimesDouble(1000, newTs)); } for (int i = 0; i < 5; i++) { final List<Double> ts = generateTimes(rng, 100d).list; final List<Double> newTs = newArrayList(); System.out.println("num events: " + ts.size()); for (final double l : ts) { newTs.add(l); newTs.add(Math.min(999, Math.max(0, l + DoubleMath.roundToLong(rng.nextDouble() * 2d - 1d, RoundingMode.HALF_EVEN)))); newTs.add(Math.min(999, Math.max(0, l + DoubleMath.roundToLong(rng.nextDouble() * 2d - 1d, RoundingMode.HALF_EVEN)))); } times.add(asTimesDouble(1000, newTs)); } final List<Long> t2 = asList(10L, 30L, 50L, 70L, 90L); for (int i = 0; i < 5; i++) { final List<Long> c = newArrayList(); for (int j = 0; j < i + 1; j++) { c.addAll(t2); } Collections.sort(c); times.add(asTimes(100, c)); } final List<Long> t = asList(100L, 300L, 500L, 700L, 900L); for (int i = 0; i < 15; i++) { final List<Long> c = newArrayList(); for (int j = 0; j < i + 1; j++) { c.addAll(t); } Collections.sort(c); times.add(asTimes(1000, c)); } final List<Long> variant = newArrayList(); variant.addAll(t); for (int i = 0; i < 70; i++) { variant.add(100L); } Collections.sort(variant); times.add(asTimes(1000, variant)); checkState(variant.size() == 75); checkState(times.get(times.size() - 2).list.size() == 75, "", times.get(times.size() - 2).list.size()); for (int i = 0; i < 10; i++) { times.add(generateTimes(rng, (i + 1) * 100d)); } final ImmutableList<Long> all = ContiguousSet.create(Range.closedOpen(0L, 1000L), DiscreteDomain.longs()) .asList(); times.add(asTimes(1000, all)); final List<Long> more = newArrayList(all); for (final long l : all) { if (l % 2 == 0) { more.add(l); } } Collections.sort(more); times.add(asTimes(1000, more)); final List<Long> more2 = newArrayList(all); for (int i = 0; i < 200; i++) { more2.add(100L); } for (int i = 0; i < 100; i++) { more2.add(200L); } Collections.sort(more2); final List<Long> newMore = newArrayList(); for (int i = 0; i < more2.size(); i++) { newMore.add(more2.get(i) * 10L); } times.add(asTimes(1000, more2)); times.add(asTimes(10000, newMore)); for (int k = 0; k < 5; k++) { final List<Double> ts = newArrayList(generateTimes(rng, 20).list); final List<Double> additions = newArrayList(); for (int i = 0; i < ts.size(); i++) { if (i % 3 == 0) { for (int j = 0; j < k; j++) { additions.add(ts.get(i) + rng.nextDouble() * 10); } } } ts.addAll(additions); Collections.sort(ts); times.add(asTimesDouble(1000, ts)); } final Times regular = asTimes(10, 0L, 1L, 2L, 5L, 6L, 7L, 8L, 9L); for (int i = 1; i < 4; i++) { final List<Double> newList = newArrayList(); for (final double l : regular.list) { newList.add(l * Math.pow(10, i)); } times.add(asTimesDouble((int) (regular.length * Math.pow(10, i)), newList)); } times.add(asTimes(1000, 250L, 250L, 250L, 500L, 500L, 500L, 750L, 750L, 750L)); times.add(asTimes(1000, 250L, 500L, 500L, 500L, 500L, 500L, 500L, 500L, 750L)); times.add(asTimes(1000, 100L, 100L, 200L, 200L, 300L, 300L, 400L, 400L, 500L, 500L, 600L, 600L, 700L, 700L, 800L, 800L, 900L, 900L)); times.add(asTimes(1000, 100L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 200L, 300L, 400L, 500L, 600L, 700L, 800L, 900L)); times.add(asTimes(1000, 100L, 200L, 300L, 400L, 500L, 600L, 700L, 800L, 800L, 800L, 800L, 800L, 800L, 800L, 800L, 800L, 800L, 900L)); // times.subList(1, times.size()).clear(); for (int j = 0; j < ordersPerHour.length; j++) { System.out.println("=========" + ordersPerHour[j] + "========="); for (int i = 0; i < times.size(); i++) { System.out.println("----- " + i + " -----"); // System.out.println(times.get(i).length + " " + times.get(i).list); // final double dod2 = measureDynamismDistr(times.get(i).list, // times.get(i).length); final double dod8 = measureDynamism(times.get(i).list, times.get(i).length); // final double dod5 = measureDynamism2ndDerivative(times.get(i).list, // times.get(i).length); // final double dod6 = measureDynDeviationCount(times.get(i).list, // times.get(i).length); // final double dod7 = chi(times.get(i).list, // times.get(i).length); // System.out.println(dod); // System.out.printf("%1.3f%%\n", dod2 * 100d); System.out.printf("%1.3f%%\n", dod8 * 100d); // System.out.printf("%1.3f%%\n", dod5 * 100d); // System.out.printf("%1.3f%%\n", dod6 * 100d); // System.out.printf("%1.3f%%\n", dod7); final double name = Math.round(dod8 * 100000d) / 1000d; try { final File dest = new File("files/generator/times/orders" + Strings.padStart(Integer.toString(i), 3, '0') + "-" + name + ".times"); Files.createParentDirs(dest); Files.write(times.get(i).length + "\n" + Joiner.on("\n").join(times.get(i).list) + "\n", dest, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalArgumentException(); } } } }
From source file:org.apache.cloudstack.api.response.QuotaResponseBuilderImpl.java
@Override public QuotaStatementResponse createQuotaStatementResponse(final List<QuotaUsageVO> quotaUsage) { if (quotaUsage == null || quotaUsage.isEmpty()) { throw new InvalidParameterValueException("There is no usage data found for period mentioned."); }// ww w. j a v a 2s. c om QuotaStatementResponse statement = new QuotaStatementResponse(); HashMap<Integer, QuotaTypes> quotaTariffMap = new HashMap<Integer, QuotaTypes>(); Collection<QuotaTypes> result = QuotaTypes.listQuotaTypes().values(); for (QuotaTypes quotaTariff : result) { quotaTariffMap.put(quotaTariff.getQuotaType(), quotaTariff); // add dummy record for each usage type QuotaUsageVO dummy = new QuotaUsageVO(quotaUsage.get(0)); dummy.setUsageType(quotaTariff.getQuotaType()); dummy.setQuotaUsed(new BigDecimal(0)); quotaUsage.add(dummy); } if (s_logger.isDebugEnabled()) { s_logger.debug("createQuotaStatementResponse Type=" + quotaUsage.get(0).getUsageType() + " usage=" + quotaUsage.get(0).getQuotaUsed().setScale(2, RoundingMode.HALF_EVEN) + " rec.id=" + quotaUsage.get(0).getUsageItemId() + " SD=" + quotaUsage.get(0).getStartDate() + " ED=" + quotaUsage.get(0).getEndDate()); } Collections.sort(quotaUsage, new Comparator<QuotaUsageVO>() { public int compare(QuotaUsageVO o1, QuotaUsageVO o2) { if (o1.getUsageType() == o2.getUsageType()) return 0; return o1.getUsageType() < o2.getUsageType() ? -1 : 1; } }); List<QuotaStatementItemResponse> items = new ArrayList<QuotaStatementItemResponse>(); QuotaStatementItemResponse lineitem; int type = -1; BigDecimal usage = new BigDecimal(0); BigDecimal totalUsage = new BigDecimal(0); quotaUsage.add(new QuotaUsageVO());// boundary QuotaUsageVO prev = quotaUsage.get(0); if (s_logger.isDebugEnabled()) { s_logger.debug("createQuotaStatementResponse record count=" + quotaUsage.size()); } for (final QuotaUsageVO quotaRecord : quotaUsage) { if (type != quotaRecord.getUsageType()) { if (type != -1) { lineitem = new QuotaStatementItemResponse(type); lineitem.setQuotaUsed(usage); lineitem.setAccountId(prev.getAccountId()); lineitem.setDomainId(prev.getDomainId()); lineitem.setUsageUnit(quotaTariffMap.get(type).getQuotaUnit()); lineitem.setUsageName(quotaTariffMap.get(type).getQuotaName()); lineitem.setObjectName("quotausage"); items.add(lineitem); totalUsage = totalUsage.add(usage); usage = new BigDecimal(0); } type = quotaRecord.getUsageType(); } prev = quotaRecord; usage = usage.add(quotaRecord.getQuotaUsed()); } statement.setLineItem(items); statement.setTotalQuota(totalUsage); statement.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); statement.setObjectName("statement"); return statement; }
From source file:pt.ist.fenixedu.teacher.domain.teacher.TeacherService.java
public static Double getAvailableShiftPercentage(Shift shift, Professorship professorship) { Double availablePercentage = 100.0; for (DegreeTeachingService degreeTeachingService : shift.getDegreeTeachingServicesSet()) { if (degreeTeachingService.getProfessorship() != professorship) { availablePercentage -= degreeTeachingService.getPercentage(); }/*from ww w. ja v a 2 s . c o m*/ } return new BigDecimal(availablePercentage).divide(new BigDecimal(1), 2, RoundingMode.HALF_EVEN) .doubleValue(); }
From source file:org.openmrs.module.billing.web.controller.billingqueuedia.BillingService.java
@RequestMapping(value = "/module/billing/orderStoreSave.form", method = RequestMethod.POST) public String billSaveOrder(@RequestParam("patientId") Integer patientId, @RequestParam(value = "refDocId", required = false) Integer refDocId, @RequestParam(value = "refMarId", required = false) Integer refMarId, @RequestParam(value = "orderId", required = false) Integer orderId, @RequestParam(value = "refRmpId", required = false) Integer refRmpId, @RequestParam(value = "dDate", required = false) String dDate, @RequestParam(value = "dTime", required = false) String dTime, @RequestParam(value = "rem", required = false) String remarks, // @RequestParam(value = "discount", required = false) BigDecimal discount, @RequestParam(value = "discount", required = false) String discount, @RequestParam("indCount") Integer indCount, @RequestParam(value = "encounterId", required = false) String encounterId, HttpServletRequest request, Model model) throws ParseException, Exception { Patient patient = Context.getPatientService().getPatient(patientId); MedisunService ms = Context.getService(MedisunService.class); org.openmrs.module.hospitalcore.BillingService billingService = Context .getService(org.openmrs.module.hospitalcore.BillingService.class); //Date birthday = patient.getBirthdate(); // model.addAttribute("age", PatientUtils.estimateAge(birthday)); String fullPaid = request.getParameter("paid"); String fullFree = request.getParameter("free"); String freeReason = request.getParameter("freeReason"); BigDecimal doctorGivenPer = NumberUtils.createBigDecimal(request.getParameter("docGivPer")); BigDecimal p = new BigDecimal("0.00"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date deDate = null;//w w w . ja v a2s . c om if (StringUtils.isNotBlank(dDate)) { deDate = sdf.parse(dDate); } // System.out.println("***********ddddd"+doctorGivenPer); // if (doctorGivenPer == null) { // doctorGivenPer=p; // } // else{ // doctorGivenPer=doctorGivenPer; // } // DiaBillingQueue dbq = ms.getDiaBillingQueue(orderId); DiaReceipt dr = new DiaReceipt(); dr.setPaidDate(new Date()); dr.setDeliveryDate(deDate); dr.setDeliveryTime(dTime); dr.setServiceId(orderId); dr.setDoctorGiven(doctorGivenPer); // ms.saveDiaReceipt(dr); User user = Context.getAuthenticatedUser(); BillableService service; BigDecimal totalBill = NumberUtils.createBigDecimal(request.getParameter("totalBill")); BigDecimal netAmount = NumberUtils.createBigDecimal(request.getParameter("netamount")); BigDecimal paidAmount = NumberUtils.createBigDecimal(request.getParameter("paidamount")); BigDecimal payableAmount = NumberUtils.createBigDecimal(request.getParameter("payableamount")); BigDecimal dueAmount = NumberUtils.createBigDecimal(request.getParameter("dueamount")); BigDecimal discountAmount = NumberUtils.createBigDecimal(request.getParameter("discountamount")); BigDecimal unitPrice = NumberUtils.createBigDecimal(request.getParameter("unitprice")); // BigDecimal discount = NumberUtils.createBigDecimal(request.getParameter("discount")); if (paidAmount == null) { paidAmount = p; } else { paidAmount = paidAmount; } String due = null; boolean status; if ((StringUtils.equals(fullPaid, "1")) && (dueAmount.signum() < 1)) { due = "PAID"; status = false; totalBill = totalBill; } else if ((StringUtils.equals(fullPaid, null)) && (StringUtils.equals(fullFree, null)) && (dueAmount.signum() < 1)) { due = "PAID"; status = false; totalBill = totalBill; } else if ((!StringUtils.equalsIgnoreCase(fullFree, null))) { due = "FREE"; status = true; totalBill = p; } else { due = "DUE"; status = false; totalBill = totalBill; } DiaPatientServiceBill dpsb = new DiaPatientServiceBill(); dpsb.setPatient(patient); dpsb.setCreatedDate(new Date()); dpsb.setCreator(user); dpsb.setAmount(netAmount); dpsb.setPrinted(Boolean.FALSE); dpsb.setReceipt(dr); dpsb.setVoided(Boolean.FALSE); dpsb.setActualAmount(totalBill); /// if free actual amount is 0.00 dpsb.setDueAmount(dueAmount); dpsb.setBillingStatus(due); dpsb.setRefDocId(refDocId); dpsb.setRefMarId(refMarId); dpsb.setRefRmpId(refRmpId); dpsb.setComment(remarks); dpsb.setDiscountAmount(discountAmount); dpsb.setFreeReason(freeReason); //if (paidAmount.signum() > 0) { dpsb = ms.saveDiaPatientServiceBill(dpsb); //} // if (dpsb != null && dpsb.getBillId() != null ) { if (dpsb != null && dpsb.getBillId() != null && orderId != 0) { ms.removeDiaBillingQueue(dbq); } model.addAttribute("billId", dpsb.getBillId()); model.addAttribute("orderId", orderId); model.addAttribute("refDocId", refDocId); model.addAttribute("refRmpId", refRmpId); model.addAttribute("paid", paidAmount); model.addAttribute("dDate", dDate); model.addAttribute("dTime", dTime); DiaPatientServiceBillCollect dBillColl = new DiaPatientServiceBillCollect(); dBillColl.setPatientId(patientId); dBillColl.setDiaPatientServiceBill(dpsb); dBillColl.setUser(user); dBillColl.setCreatedDate(new Date()); dBillColl.setActualAmount(totalBill); dBillColl.setPaidAmount(paidAmount); dBillColl.setPayableAmount(netAmount); dBillColl.setDueAmount(dueAmount); dBillColl.setDiscountAmount(discountAmount); dBillColl.setDuePaidStatus(status); dBillColl.setDuePaid(0); //if (paidAmount.signum() > 0) { ms.saveDiaPatientServiceBillCollect(dBillColl); //} String sername = null; BigDecimal totCom = BigDecimal.ZERO; BigDecimal servicePrice = BigDecimal.ZERO; for (Integer i = 1; i <= indCount; i++) { String servicename = request.getParameter("service"); unitPrice = NumberUtils.createBigDecimal(request.getParameter(i.toString() + "unitprice")); // Quantity * unitPrice BigDecimal serviceprice = NumberUtils .createBigDecimal(request.getParameter(i.toString() + "serviceprice")); // Unit Price Integer qty = NumberUtils.createInteger(request.getParameter(i.toString() + "servicequantity")); // Quantity servicename = request.getParameter(i.toString() + "service"); service = billingService.getServiceByConceptName(servicename); if (((!StringUtils.equalsIgnoreCase(service.getCategory().getId().toString(), "5678")))) { sername = servicename + "," + sername; // for commison servicePrice = servicePrice.add(unitPrice); } DiaPatientServiceBillItem dBillItem = new DiaPatientServiceBillItem(); dBillItem.setService(service); dBillItem.setDiaPatientServiceBill(dpsb); dBillItem.setUnitPrice(serviceprice); dBillItem.setAmount(unitPrice); dBillItem.setQuantity(qty); dBillItem.setName(servicename); dBillItem.setCreatedDate(new Date()); dBillItem.setCreator(user.getId()); dBillItem.setVoided(Boolean.FALSE); dBillItem.setActualAmount(unitPrice); // if (paidAmount.signum() > 0) { ms.saveDiaPatientServiceBillItem(dBillItem); //} BigDecimal ind = NumberUtils.createBigDecimal(indCount.toString()); BigDecimal da = discountAmount.divide(ind, 2, RoundingMode.CEILING); BigDecimal oneHundred = new BigDecimal(100); BigDecimal le = null; if (!StringUtils.isBlank(discount)) { BigDecimal dis; dis = new BigDecimal(discount); BigDecimal less = (unitPrice.multiply(dis)).divide(oneHundred, 0, RoundingMode.HALF_EVEN); le = less; } else { le = new BigDecimal(0); } //BigDecimal less = (unitPrice.multiply(discount)).divide(oneHundred, 0, RoundingMode.HALF_EVEN); if (dpsb.getBillingStatus() == "PAID") { if ((!StringUtils.equalsIgnoreCase(service.getCategory().getId().toString(), "5678"))) { DiaCommissionCal diaComCal = new DiaCommissionCal(); diaComCal.setDiaPatientServiceBill(dpsb); diaComCal.setPatient(patient); diaComCal.setServiceName(service.getName()); diaComCal.setServiceId(service.getServiceId()); diaComCal.setServicePrice(serviceprice); //diaComCal.setLessAmount(discountAmount); diaComCal.setLessAmount(le); diaComCal.setCommission(service.getCommission()); diaComCal.setCreatedDate(new Date()); diaComCal.setCreator(user.getId()); diaComCal.setRefId(dpsb.getRefDocId()); diaComCal.setRefRmpId(dpsb.getRefRmpId()); diaComCal.setHsStatus(Boolean.FALSE); ms.saveDiaComCal(diaComCal); } } DiaLabSampleid dls = new DiaLabSampleid(); dls.setPatient(patient); dls.setDiaPatientServiceBill(dpsb); dls.setSampleId(generateBarcode()); ms.saveDiaLabSam(dls); } if (sername != null && dpsb.getBillingStatus() == "PAID") { sername = sername.replace(",null", ""); DiaCommissionCalAll diaAll = new DiaCommissionCalAll(); diaAll.setDiaPatientServiceBill(dpsb); diaAll.setPatient(patient); //diaAll.setServiceName(sername); diaAll.setServicePrice(servicePrice); diaAll.setLessAmount(discountAmount); diaAll.setComAmount(totCom); diaAll.setCreatedDate(new Date()); diaAll.setCreator(Context.getAuthenticatedUser().getId()); diaAll.setRefId(refDocId); diaAll.setRefRmp(refRmpId); diaAll.setRefMar(refMarId); ms.saveDiaComAll(diaAll); } //// Generate Patient Id Barcode4j Code128Bean cod = new Code128Bean(); final int reso = 128; cod.setModuleWidth(UnitConv.in2mm(1.0f / reso)); //makes the narrow bar //width exactly one pixel cod.setHeight(10); cod.setFontSize(3); cod.setFontName("Times New Roman"); // cod.doQuietZone(true); cod.getBarWidth(2); // bean.setVerticalQuietZone(1); cod.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM); File outputFilePatId = new File( request.getSession().getServletContext().getRealPath("/barcode/" + patient.getId() + ".png")); // File outputFilePatId = new File("C:\\tomcat6\\webapps\\MEDISUN_HEALTH_CARE_V2_Final\\barcode/" + patient.getId() + ".png"); //Mostofa bhi OutputStream out1 = new FileOutputStream(outputFilePatId); try { BitmapCanvasProvider canvas = new BitmapCanvasProvider(out1, "image/x-png", reso, BufferedImage.TYPE_BYTE_BINARY, false, 0); cod.generateBarcode(canvas, patient.getPatientIdentifier().getIdentifier()); canvas.finish(); } finally { out1.close(); } //// Generate Bill Id Barcode4j Code128Bean codBil = new Code128Bean(); final int resou = 128; codBil.setModuleWidth(UnitConv.in2mm(1.0f / resou)); //makes the narrow bar //width exactly one pixel codBil.setHeight(10); codBil.setFontSize(2); codBil.setFontName("Helvetica"); // cod.doQuietZone(true); codBil.getBarWidth(2); // bean.setVerticalQuietZone(1); codBil.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM); // File outputFileBillId = new File("C:\\tomcat6\\webapps\\MEDISUN_HEALTH_CARE_V2_Final\\barcode/" + dpsb.getBillId() + ".png"); // Mostofa bhi File outputFileBillId = new File( request.getSession().getServletContext().getRealPath("/barcode/" + dpsb.getBillId() + ".png")); OutputStream outB = new FileOutputStream(outputFileBillId); try { BitmapCanvasProvider canvas = new BitmapCanvasProvider(outB, "image/x-png", reso, BufferedImage.TYPE_BYTE_BINARY, false, 0); codBil.generateBarcode(canvas, dpsb.getBillId().toString()); canvas.finish(); } finally { outB.close(); } ///// End model.addAttribute("discountAount", dBillColl.getDiscountAmount()); return "redirect:/module/billing/billprint.htm?patientId=" + patientId; //module/billing/directbillingqueue.form }
From source file:net.alexjf.tmm.fragments.ImmedTransactionStatsFragment.java
@Override public void onAsyncTaskResultSuccess(String taskId, Bundle resultData) { for (SimpleSeriesRenderer simpleRenderer : renderer.getSeriesRenderers()) { renderer.removeSeriesRenderer(simpleRenderer); }//ww w. jav a2 s . c o m dataSet.clear(); catPercentageAdapter.clear(); catPercentageAdapter.setNotifyOnChange(false); String currencyCode = resultData.getString(KEY_CURRENCY); CurrencyUnit currency; if (currencyCode == null) { currency = CurrencyUnit.EUR; } else { currency = CurrencyUnit.getInstance(currencyCode); } Category[] categories = (Category[]) resultData.getParcelableArray(KEY_CATEGORIES); double[] values = resultData.getDoubleArray(KEY_VALUES); double totalValue = resultData.getDouble(KEY_TOTALVALUE); for (int i = 0; i < categories.length; i++) { Category category = categories[i]; double categoryTotalValue = values[i]; int color = colors[(categories.length - i - 1) % colors.length]; dataSet.add(category.getName(), categoryTotalValue); catPercentageAdapter.add(new CategoryPercentageInfo(category, Money.of(currency, categoryTotalValue, RoundingMode.HALF_EVEN), categoryTotalValue / totalValue, color)); SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer(); seriesRenderer.setColor(color); renderer.addSeriesRenderer(seriesRenderer); } catPercentageAdapter.sort(new CategoryPercentageInfo.PercentageComparator(true)); catPercentageAdapter.notifyDataSetChanged(); if (chartView != null) { chartView.repaint(); } categoryStatsTask = null; Utils.allowOrientationChanges(getActivity()); }
From source file:com.aegiswallet.utils.WalletUtils.java
public static String getBTCCurrencryValue(Context context, SharedPreferences prefs, BigDecimal amount) { String result = ""; File file = context.getApplicationContext().getFileStreamPath(Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); if (file.exists()) { JSONObject jsonObject = BasicUtils.parseJSONData(context, Constants.BLOCKCHAIN_CURRENCY_FILE_NAME); try {/* w w w. j a v a 2 s . c o m*/ if (jsonObject != null) { JSONObject newObject = jsonObject .getJSONObject(prefs.getString(Constants.CURRENCY_PREF_KEY, null)); Double doubleVal = newObject.getDouble("last"); BigDecimal decimal = BigDecimal.valueOf(doubleVal); result = newObject.getString("symbol") + decimal.multiply(amount).setScale(2, RoundingMode.HALF_EVEN).toString(); } } catch (JSONException e) { Log.e("Wallet Utils", "JSON Exception " + e.getMessage()); } } return result; }
From source file:net.sourceforge.fenixedu.domain.Shift.java
public Double getAvailableShiftPercentage(Professorship professorship) { Double availablePercentage = 100.0; for (DegreeTeachingService degreeTeachingService : getDegreeTeachingServicesSet()) { if (degreeTeachingService.getProfessorship() != professorship) { availablePercentage -= degreeTeachingService.getPercentage(); }/*from w w w. j a v a2 s .com*/ } for (NonRegularTeachingService nonRegularTeachingService : getNonRegularTeachingServicesSet()) { if (nonRegularTeachingService.getProfessorship() != professorship && (getCourseLoadsSet().size() != 1 || !containsType(ShiftType.LABORATORIAL))) { availablePercentage -= nonRegularTeachingService.getPercentage(); } } return new BigDecimal(availablePercentage).divide(new BigDecimal(1), 2, RoundingMode.HALF_EVEN) .doubleValue(); }