List of usage examples for java.math BigDecimal signum
public int signum()
From source file:org.openvpms.archetype.rules.finance.account.CustomerAccountRules.java
/** * Calculates a new balance for a customer from the current outstanding * balance and a running total./*from ww w . j av a 2 s . co m*/ * If the new balance is: * <ul> * <li>< 0 returns 0.00 for payments, or -balance for refunds</li> * <li>> 0 returns 0.00 for refunds</li> * </ul> * * @param customer the customer * @param total the running total * @param payment if {@code true} indicates the total is for a payment, * if {@code false} indicates it is for a refund * @return the new balance * @throws ArchetypeServiceException for any archetype service error */ public BigDecimal getBalance(Party customer, BigDecimal total, boolean payment) { BigDecimal balance = getBalance(customer); BigDecimal result; if (payment) { result = balance.subtract(total); } else { result = balance.add(total); } if (result.signum() == -1) { result = (payment) ? BigDecimal.ZERO : result.negate(); } else if (result.signum() == 1 && !payment) { result = BigDecimal.ZERO; } return result; }
From source file:com.autentia.intra.validator.PeriodicalAccountEntryValidator.java
/** */ public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { log.info("validate - value = " + value); if (value != null) { // Check if value is a BigDecimal if (!(value instanceof BigDecimal)) { log.info("validate - value is not a BigDecimal (" + value.getClass().getName() + ")"); throw new ValidatorException( new FacesMessage("Las cantidades monetarias deben ser de tipo BigDecimal")); }// w w w . ja va2 s. com // Check if it has no more than 2 decimal digits BigDecimal bd = (BigDecimal) value; if (bd.scale() > 2) { log.info("validate - value has more than 2 decimals (" + value + ")"); throw new ValidatorException( new FacesMessage("Las cantidades monetarias no pueden tener mas de dos decimales")); } PeriodicalAccountEntryBean bean = (PeriodicalAccountEntryBean) FacesUtils .getBean("periodicalAccountEntryBean"); AccountEntryType type = bean.getType(); AccountEntryGroup group = type.getGroup(); if (group.getId() == ConfigurationUtil.getDefault().getCostId()) { if (bd.signum() != -1) { log.info("validate - value cost is negative (" + value + ")"); throw new ValidatorException(new FacesMessage("La cantidad debe ser negativa")); } } if (group.getId() == ConfigurationUtil.getDefault().getIncomeId()) { if (bd.signum() != 1) { log.info("validate - value incom is positive (" + value + ")"); throw new ValidatorException(new FacesMessage("La cantidad debe ser positiva")); } } } }
From source file:org.opentaps.dataimport.CustomerDecoder.java
/** * Checks if we can create a balance. The balance from the entry must be non zero and the * AR and offsetting accounts must exist. */// w w w . j a v a 2 s . c o m public boolean canCreateBalance(BigDecimal balance) { if (balance == null || balance.signum() == 0) { return false; } return (!UtilValidate.isEmpty(arGlAccountId)) && (!UtilValidate.isEmpty(offsettingGlAccountId)); }
From source file:org.openmrs.module.billing.web.controller.billingqueuedia.DueBillCollect.java
@RequestMapping(value = "/module/billing/dueCollect.htm", method = RequestMethod.POST) public String dueCollect(@RequestParam("patientId") Integer patientId, @RequestParam(value = "refDocId", required = false) Integer refDocId, @RequestParam(value = "rmpId", required = false) Integer rmpId, @RequestParam("billId") Integer billId, @RequestParam("indCount") Integer indCount, @RequestParam(value = "per", required = false) String discount, @RequestParam(value = "encounterId", required = false) String encounterId, HttpServletRequest request, Model model) throws ParseException { 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); User user = Context.getAuthenticatedUser(); BillableService service;/*from w w w. j a v a 2 s. c o m*/ BigDecimal totalBill = NumberUtils.createBigDecimal(request.getParameter("totalBill")); BigDecimal payableAmount = NumberUtils.createBigDecimal(request.getParameter("payableamount")); BigDecimal paidAmount = NumberUtils.createBigDecimal(request.getParameter("paidamount")); BigDecimal dueAmount = NumberUtils.createBigDecimal(request.getParameter("dueamount")); BigDecimal discountAmount = NumberUtils.createBigDecimal(request.getParameter("disAmounut")); BigDecimal secLess = NumberUtils.createBigDecimal(request.getParameter("secLess")); BigDecimal totDis = (discountAmount.add(secLess)); String due = null; if (dueAmount.signum() < 1) { due = "PAID"; } else { due = "DUE"; } DiaPatientServiceBill dpsb = ms.getDiaPatientServiceBillId(billId); dpsb.setDueAmount(dueAmount); dpsb.setBillingStatus(due); dpsb.setDiscountAmount(totDis); ms.reSaveDia(dpsb); model.addAttribute("billId", dpsb.getBillId()); model.addAttribute("paid", paidAmount); model.addAttribute("refDocId", refDocId); 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(payableAmount); dBillColl.setDueAmount(dueAmount); dBillColl.setDiscountAmount(secLess); dBillColl.setDuePaidStatus(true); // dBillColl.setDuePaid(duePaid); ms.saveDiaPatientServiceBillCollect(dBillColl); model.addAttribute("dBillCollect", dBillColl); BigDecimal totCom = BigDecimal.ZERO; BigDecimal servicePrice = BigDecimal.ZERO; String sername = null; /// Due collect amount, get commission calculation save in Dia Commission Cal for (Integer i = 1; i <= indCount; i++) { // String servicename = request.getParameter("service"); BigDecimal unitPrice = NumberUtils.createBigDecimal(request.getParameter(i.toString() + "unitprice")); // Quantity * unitPrice String 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); } // BigDecimal ind = NumberUtils.createBigDecimal(indCount.toString()); //BigDecimal da = discountAmount.divide(ind, 2, RoundingMode.CEILING); if (dpsb.getBillingStatus() == "PAID") { BigDecimal oneHundred = new BigDecimal(100); BigDecimal le = null; System.out.println("*******" + service.getCategory().getId()); if ((!StringUtils.equalsIgnoreCase(service.getCategory().getId().toString(), "5678"))) { 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); } } //if (!StringUtils.equalsIgnoreCase(service.getCommission(), "0")) { if ((!StringUtils.equalsIgnoreCase(service.getCategory().getId().toString(), "5678"))) { BigDecimal percentage = NumberUtils.createBigDecimal(service.getCommission()); BigDecimal com = (unitPrice.multiply(percentage)).divide(oneHundred); totCom = totCom.add(com); servicePrice = servicePrice.add(unitPrice); } 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(unitPrice); //diaComCal.setLessAmount(discountAmount); diaComCal.setLessAmount(le); diaComCal.setCommission(service.getCommission()); diaComCal.setCreatedDate(new Date()); diaComCal.setCreator(user.getId()); diaComCal.setRefId(refDocId); //// diaComCal.setRefRmpId(rmpId); ms.saveDiaComCal(diaComCal); } } } /// For diacommissionall 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(rmpId); ms.saveDiaComAll(diaAll); } return "redirect:/module/billing/dueprint.htm?patientId=" + patientId; //module/billing/directbillingqueue.form }
From source file:org.kuali.kpme.tklm.leave.payout.LeavePayout.java
public LeavePayout adjust(BigDecimal payoutAmount) { BigDecimal difference = this.payoutAmount.subtract(payoutAmount); //technically if there is forfeiture, then the transfer amount has already been maximized //via BalanceTransferService::initializeTransfer(...) //i.o.w. transfer amount cannot be increased. //this method is written with the intention of eventually allowing end user to adjust the transfer //amount as many times as they wish before submitting. Currently they cannot. if (difference.signum() < 0) { //transfer amount is being increased. if (forfeitedAmount.compareTo(BigDecimal.ZERO) > 0) { //transfer amount has already been maximized. if (forfeitedAmount.compareTo(difference.abs()) >= 0) // there is enough leave in the forfeited amount to take out the difference. forfeitedAmount = forfeitedAmount.subtract(difference.abs()); else//from w w w .j ava2 s. c om // the difference zero's the forfeited amount. forfeitedAmount = BigDecimal.ZERO; } // a forfeited amount equal to zero with an increase in the transfer amount // does not produce forfeiture. // forfeiture cannot be negative. } else if (difference.signum() > 0) { //transfer amount is being decreased forfeitedAmount = forfeitedAmount.add(difference); } this.payoutAmount = payoutAmount; return this; }
From source file:org.egov.wtms.application.service.collection.ConnectionBillService.java
/** * Creates the advance bill details//w ww.j a v a 2s .c o m * * @param billDetails * @param orderMap * @param currentInstallmentDemand * @param demandDetail * @param reason * @param installment */ private void createAdvanceBillDetails(List<EgBillDetails> billDetails, BigDecimal currentInstallmentDemand, EgDemand demand, Billable billable, List<Installment> advanceInstallments, Installment dmdDetInstallment) { /* * Advance will be created with current year second half installment. While fetching advance collection, we will pass * current year second half installment */ BigDecimal advanceCollection = demandGenericDAO.getBalanceByDmdMasterCodeInst(demand, DEMANDRSN_CODE_ADVANCE, moduleService.getModuleByName(MODULE_NAME), dmdDetInstallment); CFinancialYear finYear = financialYearDAO.getFinancialYearByDate(new Date()); if (advanceCollection.signum() < 0) advanceCollection = advanceCollection.abs(); BigDecimal partiallyCollectedAmount = ZERO; if (currentInstallmentDemand.signum() > 0) partiallyCollectedAmount = advanceCollection.remainder(currentInstallmentDemand); if (currentInstallmentDemand.signum() > 0) { Integer noOfAdvancesPaid = advanceCollection.subtract(partiallyCollectedAmount) .divide(currentInstallmentDemand).intValue(); if (LOG.isDebugEnabled()) LOG.debug("getBilldetails - advanceCollection = {}, noOfAdvancesPaid={}", advanceCollection, noOfAdvancesPaid); Installment installment; int j; if (noOfAdvancesPaid < MAX_ADVANCES_ALLOWED) for (int i = noOfAdvancesPaid; i < advanceInstallments.size(); i++) { installment = advanceInstallments.get(i); EgDemandReason reasonmaster = connectionDemandService .getDemandReasonByCodeAndInstallment(DEMANDRSN_CODE_ADVANCE, installment); if (reasonmaster != null) { EgBillDetails billdetail = new EgBillDetails(); billdetail.setDrAmount(ZERO); billdetail.setCrAmount(currentInstallmentDemand); billdetail.setGlcode(GLCODE_FOR_ADVANCE); billdetail.setEgDemandReason(reasonmaster); billdetail.setCreateDate(new Date()); billdetail.setModifiedDate(new Date()); j = billDetails.size() + 1; billdetail.setOrderNo(j); billdetail.setDescription(reasonmaster.getEgDemandReasonMaster().getReasonMaster() + " - " + installment.getDescription()); if (billdetail.getDescription().contains(DEMANDRSN_REASON_ADVANCE)) billdetail.setPurpose(PURPOSE.ADVANCE_AMOUNT.toString()); else if (billdetail.getEgDemandReason().getEgInstallmentMaster().getToDate() .compareTo(finYear.getStartingDate()) < 0) billdetail.setPurpose(PURPOSE.ARREAR_AMOUNT.toString()); else if (billdetail.getEgDemandReason().getEgInstallmentMaster().getFromDate() .compareTo(finYear.getStartingDate()) >= 0 && billdetail.getEgDemandReason().getEgInstallmentMaster().getToDate() .compareTo(finYear.getEndingDate()) >= 0) billdetail.setPurpose(PURPOSE.CURRENT_AMOUNT.toString()); else billdetail.setPurpose(PURPOSE.OTHERS.toString()); billdetail.setFunctionCode(STRING_WCMS_FUCNTION_CODE); billdetail.setAdditionalFlag(0); billDetails.add(billdetail); } } } else if (LOG.isDebugEnabled()) LOG.debug("getBillDetails - All advances are paid..."); }
From source file:com.heliumv.api.inventory.InventoryApi.java
private boolean updateInventurliste(ArtikelDto itemDto, BigDecimal newAmount, Boolean changeAmountTo, InventurlisteDto workListeDto) throws NamingException, RemoteException { if (!changeAmountTo) { BigDecimal oldAmount = workListeDto.getNInventurmenge(); newAmount = oldAmount.add(newAmount); }//from w ww . ja v a 2s . com if (newAmount.signum() < 0) { respondBadRequest("amount", "<0"); return false; } if (newAmount.signum() == 0) { inventurCall.removeInventurListe(workListeDto); } else { if (itemDto.isSeriennrtragend() && newAmount.compareTo(BigDecimal.ONE) > 0) { respondBadRequest("serialnr", "amount has to be 1"); return false; } workListeDto.setNInventurmenge(newAmount); inventurCall.updateInventurliste(workListeDto, false); } return true; }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
@Override public DecimalType getSensorsCpuTemperature() { BigDecimal cpuTemp = new BigDecimal(sensors.getCpuTemperature()); cpuTemp = cpuTemp.setScale(PRECISION_AFTER_DECIMAl_SIGN, BigDecimal.ROUND_HALF_UP); return cpuTemp.signum() == 1 ? new DecimalType(cpuTemp) : null; }
From source file:org.egov.wtms.application.service.collection.WaterTaxExternalService.java
private boolean thereIsCurrentBalanceToBePaid(EgBill bill) { List<AppConfigValues> demandreasonGlcode = waterTaxUtils .getAppConfigValueByModuleNameAndKeyName(MODULE_NAME, WaterTaxConstants.DEMANDREASONANDGLCODEMAP); Map<String, String> demandReasonGlCodePairmap = new HashMap<>(); for (AppConfigValues appConfig : demandreasonGlcode) { String[] rows = appConfig.getValue().split("="); demandReasonGlCodePairmap.put(rows[0], rows[1]); }/* ww w .j a v a 2 s. com*/ boolean result = false; BigDecimal currentBal = ZERO; for (Map.Entry<String, String> entry : demandReasonGlCodePairmap.entrySet()) currentBal = currentBal.add(bill.balanceForGLCode(entry.getValue())); if (currentBal.signum() > 0) result = true; return result; }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
@Override public DecimalType getSensorsCpuVoltage() { BigDecimal cpuVoltage = new BigDecimal(sensors.getCpuVoltage()); cpuVoltage = cpuVoltage.setScale(PRECISION_AFTER_DECIMAl_SIGN, BigDecimal.ROUND_HALF_UP); return cpuVoltage.signum() == 1 ? new DecimalType(cpuVoltage) : null; }