Example usage for java.math RoundingMode HALF_DOWN

List of usage examples for java.math RoundingMode HALF_DOWN

Introduction

In this page you can find the example usage for java.math RoundingMode HALF_DOWN.

Prototype

RoundingMode HALF_DOWN

To view the source code for java.math RoundingMode HALF_DOWN.

Click Source Link

Document

Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.

Usage

From source file:com.gollahalli.web.WebViewer.java

public void webReturnFortnightly() {
    Calculate calculate = new Calculate();

    double yearsTextMonth1 = yearsTextMonth / 2;
    // monthly payments output
    double weeklyOutputForFortnightly = calculate.fixedRateMortgageFortnightly(loanAmountText, yearsTextMonth1,
            interestText);//w  w  w  .  j a v a  2  s . c o m
    // total interest paid
    BigDecimal bd2 = new BigDecimal((weeklyOutputForFortnightly * yearsTextMonth1) - loanAmountText).setScale(2,
            RoundingMode.HALF_DOWN);
    System.out.println(weeklyOutputForFortnightly);
    System.out.println(bd2);

    double[][] monthlyChartYearly = calculate.fixedRateMortgageWeeklyChart(loanAmountText, interestText,
            yearsTextMonth);

    String[] property = propertyReader();

    double[][] newFortnightly = new double[5][(int) yearsTextMonth];
    newFortnightly[0][0] = monthlyChartYearly[2][0];
    newFortnightly[1][0] = monthlyChartYearly[1][0];
    newFortnightly[2][0] = monthlyChartYearly[3][0];
    for (int i = 1; i < yearsTextMonth; i++) {
        monthlyChartYearly = calculate.fixedRateMortgageWeeklyChart(monthlyChartYearly[3][0], interestText,
                yearsTextMonth - i);
        newFortnightly[0][i] = monthlyChartYearly[2][0];
        newFortnightly[1][i] = monthlyChartYearly[1][0];
        newFortnightly[2][i] = monthlyChartYearly[3][0];
    }

    String html = "";
    int someNumber = 1;

    double yearlyPrincipal = 0.0;
    double yearlyInterest = 0.0;
    double yearlyBalance = loanAmountText;
    for (int i = 0; i < newFortnightly[0].length; i++) {
        if (i % 2 == 0 && i != 0) {
            html += "<tr><td>" + String.valueOf(someNumber++) + "</td>" + "<td class=\"text-center\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyPrincipal).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td>" + "<td class=\"text-center\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyInterest).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td>" + "<td class=\"text-right\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyBalance).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td></tr>";
            yearlyPrincipal = 0;
            yearlyInterest = 0;
        }
        yearlyPrincipal += newFortnightly[0][i];
        yearlyInterest += newFortnightly[1][i];
        yearlyBalance -= newFortnightly[0][i];
        if (i == newFortnightly[0].length - 1 && i != 0) {
            html += "<tr><td>" + String.valueOf(someNumber++) + "</td>" + "<td class=\"text-center\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyPrincipal).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td>" + "<td class=\"text-center\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyInterest).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td>" + "<td class=\"text-right\">"
                    + currencyMaker(
                            String.valueOf(new BigDecimal(yearlyBalance).setScale(2, RoundingMode.HALF_DOWN)))
                    + "</td></tr>";

        }

    }

    general.templateMaker(WordUtils.capitalize(property[0]), WordUtils.capitalize(this.custName),
            WordUtils.capitalize(this.custAddress), general.getDate(), currencyMaker(loanAmount), years, months,
            " type of payment", currencyMaker(String.valueOf(weeklyOutputForFortnightly)),
            currencyMaker(String.valueOf(bd2.doubleValue())),
            currencyMaker(String.valueOf(bd2.doubleValue() + loanAmountText)), "type of time", html,
            property[5], WordUtils.capitalize(property[1]), WordUtils.capitalize(property[2]), property[3],
            property[4]);

}

From source file:org.openvpms.archetype.rules.product.ProductPriceRules.java

/**
 * Calculates the maximum discount that can be applied for a given markup.
 * <p/>//from ww  w  .j  a v a  2s .co m
 * Uses the equation:
 * <code>(markup / (100 + markup)) * 100</code>
 *
 * @param markup the markup expressed as a percentage
 * @return the discount as a percentage rounded down
 */
public BigDecimal calcMaxDiscount(BigDecimal markup) {
    BigDecimal discount = DEFAULT_MAX_DISCOUNT;
    if (markup.compareTo(BigDecimal.ZERO) > 0) {
        discount = markup.divide(ONE_HUNDRED.add(markup), 3, RoundingMode.HALF_DOWN).multiply(ONE_HUNDRED);
    }
    return discount;
}

From source file:com.wirecard.ezlinkwebservices.services.impl.DebitCommandServiceImpl.java

@Override
public DebitCommandRes getDebitCommand(EZLINGWSREQENV parameters) throws DebitCommandFault_Exception {

    ezlink.info("DC Request received in " + DebitCommandServiceImpl.class.getName());

    String merchantNo, merchantTranxRefNo, orderNo, cardNo, termRndNo, CardRndNo, purseData;
    String xorAmount;/*  w  w  w.  ja v a2 s  . c o m*/
    double amount;
    int result;
    boolean debitTraxValidationFlag = false;
    ETranxLogDto objETranxLogDto;
    EMerchantDetailsDto objEMerchantDetailsDto;
    int hostRepeatedCounter = 0;
    List<ETerminalDataDto> ETerminalDataDtolist;
    Date updatedDate = new Date();
    ETerminalDataDto objAvailableETerminalDataDto;
    ETerminalDataDto objTerminalDataFromTerminal;
    TerminalUtil objTerminalUtil;
    DebitCommandRes objDebitCommandRes = new DebitCommandRes();

    //MerchantDtoMapper objMerchantDtoMapper=new MerchantDtoMapper(); 
    try {
        merchantNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getMERCHANTNO();
        merchantTranxRefNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getMERCHANTREFNO();
        orderNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getORDERNO();
        amount = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getAMOUNT().doubleValue();
        cardNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getCAN();
        termRndNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getTERMINALRANDOMNO();
        //termRndNo = "CF549C2B7520389C";
        CardRndNo = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getCARDRANDOMNO();
        purseData = parameters.getEZLINGWSREQBODY().getDebitCommandReq().getPURSEDATA();

        // log the response send time and parameters
        ezlink.info("\n-------DC----REQUEST----------------------------------------------");
        ezlink.info("SOURCE ID : " + parameters.getEZLINGWSHEADER().getSOURCEID());
        ezlink.info("IP : " + parameters.getEZLINGWSHEADER().getIPADDRESS());
        ezlink.info("SEC LEVEL : " + parameters.getEZLINGWSHEADER().getSECURITYLEVEL());
        ezlink.info("BODY+++ getDebitCommand : " + new Date());
        ezlink.info("merchantNo : " + merchantNo);
        ezlink.info("merchantTranxRefNo : " + merchantTranxRefNo);
        ezlink.info("orderNo : " + orderNo);
        ezlink.info("amount : " + amount);
        ezlink.info("cardNo : " + cardNo);
        ezlink.info("Terminal Rnd No : " + termRndNo);
        ezlink.info("card Rnd No : " + CardRndNo);
        ezlink.info("Purse Data : " + purseData);
        ezlink.info("\n-------DC-----REQUEST----------------------------------------------");

    } catch (Exception ex) {
        ezlink.error(new Object(), ex);
        Logger.getLogger(DebitCommandServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
        ezlink.error(new Object(), ex);

        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.REQUIRED_FIELD_MISSING);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.REQUIRED_FIELD_MISSING_INFO);

        ezlink.info("\n-----DC------EXCEPTION------------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n------DC---------EXCEPTION--------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    try {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        objEMerchantDetailsDto = objEMerchantDetailsDtoMapper.getMerchantByMerchantId(merchantNo);
    } catch (SQLException ex) {
        Logger.getLogger(DebitCommandServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
        ezlink.error(new Object(), ex);
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO);

        ezlink.info("\n------DC-------EXCEPTION----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n-------DC---------EXCEPTION-------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    if (objEMerchantDetailsDto == null) {
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.NO_MERCHANT_AVAILABLE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.NO_MERCHANT_AVAILABLE_INFO);

        ezlink.info("\n-------DC-------EXCEPTION---------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n--------DC-------EXCEPTION--------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    if ((!objEMerchantDetailsDto.getSecurityLevel()
            .equalsIgnoreCase(parameters.getEZLINGWSHEADER().getSECURITYLEVEL()))) {
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.INVALID_SECURITY_LEVEL_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.INVALID_SECURITY_LEVEL_MESSAGE_INFO);

        ezlink.info("\n-------DC------EXCEPTION----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n-------DC--------EXCEPTION--------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    if ((!objEMerchantDetailsDto.getAccessCode()
            .equalsIgnoreCase(parameters.getEZLINGWSHEADER().getACCESSCODE()))) {
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.INVALID_ACCESS_CODE_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.INVALID_ACCESS_CODE_MESSAGE_INFO);

        ezlink.info("\n-------DC--------EXCEPTION--------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n--------DC---------EXCEPTION------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    try {
        //Check transaction available in ETranxLog 

        objETranxLogDto = objETranxLogDtoMapper.validateTransactionLog(merchantNo, merchantTranxRefNo, orderNo,
                amount);

    } catch (Exception ex) {

        Logger.getLogger(DebitCommandServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
        ezlink.error(new Object(), ex);
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO);

        ezlink.info("\n--------DC-------EXCEPTION--------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n---------DC-------EXCEPTION-------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }

    //if source id WD..
    if (parameters.getEZLINGWSHEADER().getSOURCEID().equals(StringConstants.Common.SOURCE_ID)) {
        ezlink.info("\n-------DC-------SOURCE ID WD---------------------");
        if (null == objETranxLogDto) {
            DebitCommandFault objDebitCommandFault = new DebitCommandFault();
            objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.NO_TRANSACTION_AVAILABLE_MESSAGE);
            objDebitCommandFault
                    .setFaultInfo(StringConstants.ExceptionInfo.NO_TRANSACTION_AVAILABLE_MESSAGE_INFO);

            ezlink.info("\n------DC------EXCEPTION-----------------------");
            ezlink.info("Response sent from getDebitCommand : " + new Date());
            ezlink.info("Status : " + objDebitCommandFault.getMessage());
            ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
            ezlink.info("\n--------DC-------EXCEPTION--------------------");

            throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
        }
        //check status not "Completed"
        System.out.println("+++++++++++++++Tranx Status from DB : " + objETranxLogDto.getTranxStatus());
        System.out.println("+++++++++++++++Response Code from DB : " + objETranxLogDto.getResponseCode());
        ezlink.info("++Transaction Status in DB ++: " + objETranxLogDto.getTranxStatus());
        ezlink.info("++Response Code in DB ++: " + objETranxLogDto.getResponseCode());

        debitTraxValidationFlag = TerminalUtil.ValidateDebitTransaction(objETranxLogDto);

        if (!debitTraxValidationFlag) {
            DebitCommandFault objDebitCommandFault = new DebitCommandFault();
            objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.TRANX_COMPLETED_MESSAGE);
            objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.TRANX_COMPLETED_MESSAGE_INFO);

            ezlink.info("\n-----DC--------EXCEPTION----------------------");
            ezlink.info("Response sent from getDebitCommand : " + new Date());
            ezlink.info("Status : " + objDebitCommandFault.getMessage());
            ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
            ezlink.info("\n---------DC---------EXCEPTION-----------------");

            throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
        }

    } //Source ID WD
    else {
        //Source ID not 'WD'
        ezlink.info("\n-------DC-------SOURCE ID NOT WD---------------------");

        if (objETranxLogDto != null) {
            //Record available 
            System.out.println("++++++NOT WD BUT RECORD AVAILABLE++++Tranx Status from DB : "
                    + objETranxLogDto.getTranxStatus());
            System.out.println("+++++++++++++++Response Code from DB : " + objETranxLogDto.getResponseCode());
            ezlink.info("++Transaction Status in DB ++: " + objETranxLogDto.getTranxStatus());
            ezlink.info("++Response Code in DB ++: " + objETranxLogDto.getResponseCode());

            debitTraxValidationFlag = TerminalUtil.ValidateDebitTransaction(objETranxLogDto);
            if (!debitTraxValidationFlag) {

                insertFaiedTranxDetail(objETranxLogDto.getTranxlogid(),
                        StringConstants.ResponseCode.TRANX_COMPLETED_ALREADY,
                        StringConstants.ExceptionInfo.TRANX_COMPLETED_MESSAGE);

                DebitCommandFault objDebitCommandFault = new DebitCommandFault();
                objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.TRANX_COMPLETED_MESSAGE);
                objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.TRANX_COMPLETED_MESSAGE_INFO);

                ezlink.info("\n-----DC--------EXCEPTION----------------------");
                ezlink.info("Response sent from getDebitCommand : " + new Date());
                ezlink.info("Status : " + objDebitCommandFault.getMessage());
                ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
                ezlink.info("\n---------DC---------EXCEPTION-----------------");

                throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
            }
        } else {
            //NOT WD but record not available in tranxlog table in our DB
            objTerminalUtil = new TerminalUtil();
            objETranxLogDto = objTerminalUtil.insertNonWDTransaction(merchantNo, merchantTranxRefNo, orderNo,
                    amount);
            if (null == objETranxLogDto) {
                ezlink.info("\n-----NON WC--------TRANXLOG INSERTION FAILED------------");
                DebitCommandFault objDebitCommandFault = new DebitCommandFault();
                objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.DB_INSERTION_FAILED_MESSAGE);
                objDebitCommandFault
                        .setFaultInfo(StringConstants.ExceptionInfo.DB_INSERTION_FAILED_MESSAGE_INFO);

                ezlink.info("\n-------DC-----EXCEPTION-----------------------");
                ezlink.info("Response sent from getDebitCommand : " + new Date());
                ezlink.info("Status : " + objDebitCommandFault.getMessage());
                ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
                ezlink.info("\n--------DC------EXCEPTION---------------------");

                throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
            }

        }
    }

    //--------------------------------------------------------------------------------------------------
    //Checking get debit command time from when generating qrcode
    try {
        Date generateQrcode = objETranxLogDto.getDatetime();
        Date timeout = new Date(generateQrcode.getTime() + 2 * 60 * 1000);
        if (updatedDate.after(timeout)) {
            objETranxLogDto.setDatetime(updatedDate);
            objETranxLogDto.setResponseCode(StringConstants.ResponseCode.TIME_OUT);
            result = objETranxLogDtoMapper.updateResponseCode(objETranxLogDto);
            System.out.println(" tranxlog Updation Result : " + result);
            if (result != 1) {
                DebitCommandFault objDebitCommandFault = new DebitCommandFault();
                objDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
                objDebitCommandFault.setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

                ezlink.info("\n------DC------EXCEPTION-----------------------");
                ezlink.info("Response sent from getDebitCommand : " + new Date());
                ezlink.info("Status : " + objDebitCommandFault.getMessage());
                ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
                ezlink.info("\n---------DC-------EXCEPTION-------------------");

                throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
            }

            objDebitCommandRes.setORDERNO(objETerminalDataDto.getOrderNo());
            objDebitCommandRes.setMERCHANTREFNO(objETerminalDataDto.getMerchantTranxRefNo());
            objDebitCommandRes.setCAN(objETerminalDataDto.getCan());
            return objDebitCommandRes;
        }
    }

    catch (DebitCommandFault_Exception e) {
        throw e;
    }

    catch (Exception e) {
        e.printStackTrace();
    }

    try {
        //Repeated host Count
        objAvailableETerminalDataDto = objETerminalDataDtoMapper.isRepeatedMerchantTranxRefNo(merchantNo,
                merchantTranxRefNo, orderNo);

    } catch (Exception ex) {
        Logger.getLogger(DebitCommandServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
        ezlink.error(new Object(), ex);
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO);

        ezlink.info("\n-------DC-----EXCEPTION-----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n--------DC------EXCEPTION---------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    if (objAvailableETerminalDataDto != null) {
        hostRepeatedCounter = objAvailableETerminalDataDto.getHostCounter();
        hostRepeatedCounter++;
    }

    objETerminalDataDto.setMerchantNo(merchantNo);
    objETerminalDataDto.setCan(cardNo);
    objETerminalDataDto.setOrderNo(orderNo);
    objETerminalDataDto.setMerchantTranxRefNo(merchantTranxRefNo);
    objETerminalDataDto.setHostCounter(hostRepeatedCounter);
    objETerminalDataDto.setAmount(amount);
    objETerminalDataDto.setUpdatedBy(StringConstants.Common.DBT_CMD_USER);
    objETerminalDataDto.setUpdatedDate(updatedDate);
    objETerminalDataDto.setTerminalRndNo(termRndNo);
    objETerminalDataDto.setCardRndNo(CardRndNo);
    objETerminalDataDto.setPurseData(purseData);
    objETerminalDataDto.setTranxlogId(objETranxLogDto.getTranxlogid());
    //----------------------------------------------------------------------------------------------------
    /*
     //Updating tranxlog status D
    try {
    objETranxLogDto.setDatetime(updatedDate);
    //objETranxLogDto.setResponseCode(StringConstants.ResponseCode.SUCCESS);
    result = objETranxLogDtoMapper.updateDebitCommandStatus(objETranxLogDto);
    System.out.println(" tranxlog Updation Result : " + result);
    if (result == 0) {
        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);
            
        ezlink.info("\n------DC------EXCEPTION-----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n---------DC-------EXCEPTION-------------------");
            
        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    } catch (Exception e) {
    DebitCommandFault objDebitCommandFault = new DebitCommandFault();
    objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE);
    objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE_INFO);
    e.printStackTrace();
    ezlink.error(new Object(), e);
            
    ezlink.info("\n-------DC-----EXCEPTION-----------------------");
    ezlink.info("Response sent from getDebitCommand : " + new Date());
    ezlink.info("Status : " + objDebitCommandFault.getMessage());
    ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
    ezlink.info("\n-------DC-------EXCEPTION---------------------");
            
    throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    */

    //----------------------------------------------------------------------------------------------------
    try {
        //objETerminalDataDto = TerminalUtil.getDebitCommandFromTerminal(objETerminalDataDto);

        SerialManager objSerialManager = new SerialManager();
        //String xorAmount="FFFFFE";
        BigDecimal beforeAmt = new BigDecimal(
                parameters.getEZLINGWSREQBODY().getDebitCommandReq().getAMOUNT().doubleValue()).setScale(2,
                        RoundingMode.HALF_DOWN);
        System.out.println("AMOUNT BEFORE : " + beforeAmt);
        BigDecimal amt = new BigDecimal(
                parameters.getEZLINGWSREQBODY().getDebitCommandReq().getAMOUNT().doubleValue())
                        .setScale(2, RoundingMode.HALF_DOWN).subtract(new BigDecimal("0.01"));
        System.out.println("AMOUNT After -0.01 : " + amt);
        String amountForXor = String.valueOf(amt).replace(".", "");
        String amountForHexXor = Long.toHexString(Long.valueOf(amountForXor));

        ezlink.info("Amount for HEX XOR : " + amountForHexXor);
        System.out.println("AMOUNT For Hex XOR : " + amountForHexXor);
        xorAmount = TerminalUtil.strXor(amountForHexXor, StringConstants.Common.XOR_FORMAT);
        ezlink.info("Amount in XOR : " + xorAmount);
        System.out.println("AMOUNT IN XOR : " + xorAmount);

        ezlink.info("\n-----DC----------START of Serial Manager--------------------");
        System.out.println(
                "---------------START of Serial Manager -----------------------------------------------------------");
        System.out.println("++++++++++TERMINAL RANDOM NO++++++++++++++++++++++++++++ : " + termRndNo);
        ezlink.info("---------------TERMINAL RANDOM NO -----------: " + termRndNo);
        long serialReqTime = System.currentTimeMillis();
        System.out.println("++++++++SerialManager REQUEST time :+++++ " + serialReqTime);
        synchronized (this) {
            objTerminalDataFromTerminal = objSerialManager.getDebitCmd(CardRndNo, termRndNo, xorAmount,
                    purseData);
        }
        long serialResTime = System.currentTimeMillis();
        System.out.println("+++++++SerialManager Response time :++++++++ " + serialResTime);
        long timeTaken = serialResTime - serialReqTime;
        System.out.println("+++++++++Time taken to Serve within SERIALMANAGER +++++++ : " + timeTaken);
        if (null == objTerminalDataFromTerminal) {

            insertFaiedTranxDetail(objETranxLogDto.getTranxlogid(),
                    StringConstants.ResponseCode.TERMINAL_CONNECTION_FAILED,
                    StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE);

            System.out.println("---------------Not recieving Debit Command from terminal -----------");
            ezlink.info("---------------Not recieving Debit Command from terminal -----------");
            DebitCommandFault objDebitCommandFault = new DebitCommandFault();
            objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE);
            objDebitCommandFault
                    .setFaultInfo(StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE_INFO);

            ezlink.info("\n------DC----EXCEPTION-------------------------");
            ezlink.info("Response sent from getDebitCommand : " + new Date());
            ezlink.info("Status : " + objDebitCommandFault.getMessage());
            ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
            ezlink.info("\n-------DC-----EXCEPTION-----------------------");

            throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
        }
        System.out.println(
                "---------------END of Serial Manager -----------------------------------------------------------");
        ezlink.info("\n-----DC----------END of Serial Manager--------------------");
        System.out.println("+++Debit Command ++++" + objTerminalDataFromTerminal.getDebitCmd());
        objETerminalDataDto.setDebitCmd(objTerminalDataFromTerminal.getDebitCmd());
        objETerminalDataDto.setTerminalSessionKey(objTerminalDataFromTerminal.getTerminalSessionKey());
        objETerminalDataDto.setDebitSessionKey(objTerminalDataFromTerminal.getDebitSessionKey());
        objETerminalDataDto.setEzLinkString(objTerminalDataFromTerminal.getEzLinkString());

        System.out.println("++++" + objETerminalDataDto.toString());
        ETerminalDataDtolist = objETerminalDataDtoMapper.isRecordAvailable(merchantNo, merchantTranxRefNo,
                orderNo);
        System.out.println("SIZE : " + ETerminalDataDtolist.size());
        if (ETerminalDataDtolist.isEmpty()) {
            result = objETerminalDataDtoMapper.insert(objETerminalDataDto);
            System.out.println(" Insertion Result : " + result);
        } else {
            objETerminalDataDto.setSno(ETerminalDataDtolist.get(0).getSno());
            result = objETerminalDataDtoMapper.updateETerminalDataBySNo(objETerminalDataDto);
            System.out.println(" Updation Result : " + result);
        }

    } catch (Exception e) {

        insertFaiedTranxDetail(objETranxLogDto.getTranxlogid(),
                StringConstants.ResponseCode.TERMINAL_CONNECTION_FAILED,
                StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE);

        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.TERMINAL_CONNECTION_ERROR_MESSAGE_INFO);
        e.printStackTrace();
        ezlink.error(new Object(), e);

        ezlink.info("\n------DC----EXCEPTION-------------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n-------DC-----EXCEPTION-----------------------");

        //---------------------------------------------------------------------------------------------------
        //Updating Terminal COnnection failed response code
        try {
            objETranxLogDto.setDatetime(updatedDate);
            objETranxLogDto.setResponseCode(StringConstants.ResponseCode.TERMINAL_CONNECTION_FAILED);
            result = objETranxLogDtoMapper.updateResponseCode(objETranxLogDto);
            System.out.println(" tranxlog Updation Result : " + result);
            if (result != 1) {
                DebitCommandFault objTerminalFailedDebitCommandFault = new DebitCommandFault();
                objTerminalFailedDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
                objTerminalFailedDebitCommandFault
                        .setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

                ezlink.info("\n------DC------EXCEPTION-----------------------");
                ezlink.info("Response sent from getDebitCommand : " + new Date());
                ezlink.info("Status : " + objTerminalFailedDebitCommandFault.getMessage());
                ezlink.info("Remarks : " + objTerminalFailedDebitCommandFault.getFaultInfo());
                ezlink.info("\n---------DC-------EXCEPTION-------------------");

                throw new DebitCommandFault_Exception(objTerminalFailedDebitCommandFault.getMessage(),
                        objTerminalFailedDebitCommandFault);
            }

            else {
                objTerminalUtil = new TerminalUtil();
                if (result != 1) {
                    DebitCommandFault objTranxDetailDebitCommandFault = new DebitCommandFault();
                    objTranxDetailDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
                    objTranxDetailDebitCommandFault
                            .setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

                    ezlink.info("\n------DC--TRANX DETAIL----EXCEPTION-----------------------");
                    ezlink.info("Response sent from getDebitCommand : " + new Date());
                    ezlink.info("Status : " + objDebitCommandFault.getMessage());
                    ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
                    ezlink.info("\n---------DC-------EXCEPTION-------------------");

                    throw new DebitCommandFault_Exception(objTranxDetailDebitCommandFault.getMessage(),
                            objTranxDetailDebitCommandFault);
                }
            }

        }

        catch (DebitCommandFault_Exception ex) {
            throw ex;
        }

        catch (Exception ex) {
            DebitCommandFault objSQLDebitCommandFault = new DebitCommandFault();
            objSQLDebitCommandFault.setMessage(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE);
            objSQLDebitCommandFault
                    .setFaultInfo(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE_INFO);
            ex.printStackTrace();
            ezlink.error(new Object(), ex);

            ezlink.info("\n-------DC-----EXCEPTION-----------------------");
            ezlink.info("Response sent from getDebitCommand : " + new Date());
            ezlink.info("Status : " + objSQLDebitCommandFault.getMessage());
            ezlink.info("Remarks : " + objSQLDebitCommandFault.getFaultInfo());
            ezlink.info("\n-------DC-------EXCEPTION---------------------");

            throw new DebitCommandFault_Exception(objSQLDebitCommandFault.getMessage(),
                    objSQLDebitCommandFault);
        }

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }
    //Transaction detail insertion failed
    if (result == 0) {

        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

        ezlink.info("\n-----DC-------EXCEPTION-----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n-----DC--------EXCEPTION----------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }

    //---------------------------------------------------------------------------------------------------
    //Updating success response code
    try {
        objETranxLogDto.setDatetime(updatedDate);
        objETranxLogDto.setResponseCode(StringConstants.ResponseCode.SUCCESS);
        result = objETranxLogDtoMapper.updateDebitCommandStatus(objETranxLogDto);
        System.out.println(" tranxlog Updation Result : " + result);
        if (result != 1) {
            DebitCommandFault objDebitCommandFault = new DebitCommandFault();
            objDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
            objDebitCommandFault.setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

            ezlink.info("\n------DC------EXCEPTION-----------------------");
            ezlink.info("Response sent from getDebitCommand : " + new Date());
            ezlink.info("Status : " + objDebitCommandFault.getMessage());
            ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
            ezlink.info("\n---------DC-------EXCEPTION-------------------");

            throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
        }

        else {
            objTerminalUtil = new TerminalUtil();
            result = objTerminalUtil.insertTransactionDetail(objETranxLogDto.getTranxlogid(),
                    StringConstants.Common.TRANX_TYPE_DEBIT, StringConstants.ResponseCode.SUCCESS,
                    StringConstants.Common.STATUS_SUCCESS);
            if (result != 1) {
                DebitCommandFault objDebitCommandFault = new DebitCommandFault();
                objDebitCommandFault.setMessage(StringConstants.Common.INSERTION_FAILED_MESSAGE);
                objDebitCommandFault.setFaultInfo(StringConstants.Common.INSERTION_FAILED_MESSAGE_INFO);

                ezlink.info("\n------DC--TRANX DETAIL----EXCEPTION-----------------------");
                ezlink.info("Response sent from getDebitCommand : " + new Date());
                ezlink.info("Status : " + objDebitCommandFault.getMessage());
                ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
                ezlink.info("\n---------DC-------EXCEPTION-------------------");

                throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
            }
        }

    }

    catch (DebitCommandFault_Exception e) {
        throw e;
    }

    catch (Exception e) {

        DebitCommandFault objDebitCommandFault = new DebitCommandFault();
        objDebitCommandFault.setMessage(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE);
        objDebitCommandFault.setFaultInfo(StringConstants.ExceptionInfo.DB_CONNECTION_ERROR_MESSAGE_INFO);
        e.printStackTrace();
        ezlink.error(new Object(), e);

        ezlink.info("\n-------DC-----EXCEPTION-----------------------");
        ezlink.info("Response sent from getDebitCommand : " + new Date());
        ezlink.info("Status : " + objDebitCommandFault.getMessage());
        ezlink.info("Remarks : " + objDebitCommandFault.getFaultInfo());
        ezlink.info("\n-------DC-------EXCEPTION---------------------");

        throw new DebitCommandFault_Exception(objDebitCommandFault.getMessage(), objDebitCommandFault);
    }

    objDebitCommandRes.setORDERNO(objETerminalDataDto.getOrderNo());
    objDebitCommandRes.setMERCHANTREFNO(objETerminalDataDto.getMerchantTranxRefNo());
    objDebitCommandRes.setCAN(objETerminalDataDto.getCan());
    objDebitCommandRes.setDEBITCOMMAND(objETerminalDataDto.getDebitCmd());

    ezlink.info("\n-------DC-------RESPONSE---------------------");
    ezlink.info("Response sent from getDebitCommand : " + new Date());
    ezlink.info("Order No : " + objDebitCommandRes.getORDERNO());
    ezlink.info("Merchant Ref no : " + objDebitCommandRes.getMERCHANTREFNO());
    ezlink.info("CAN: " + objDebitCommandRes.getCAN());
    ezlink.info("Debit Command : " + objDebitCommandRes.getDEBITCOMMAND());
    ezlink.info("\n-------DC-------RESPONSE---------------------");
    ezlink.info("\n-------DC-------PURSE DATA---------------" + purseData);

    result = objTerminalUtil.insertTransactionDetail(objETranxLogDto.getTranxlogid(),
            StringConstants.Common.TRANX_TYPE_DEBIT, StringConstants.ResponseCode.SUCCESS,
            StringConstants.Common.STATUS_SUCCESS);

    return objDebitCommandRes;
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static int divide(int b0, BigDecimal b1) {
    return BigDecimal.valueOf(b0).divide(b1, RoundingMode.HALF_DOWN).intValue();
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static long divide(long b0, BigDecimal b1) {
    return BigDecimal.valueOf(b0).divide(b1, RoundingMode.HALF_DOWN).longValue();
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.GeometricMeanBigDecimalTest.java

/**
 * Corrects any rounding errors due to differences in the implementation of
 * the statistic between the Apache and MicroFlex libraries
 * @param    BigDecimal    the first result
 * @param    BigDecimal    the second result
 * @return                 corrected results
 *//*  ww  w  .  j  av a2s  . c  o  m*/
private static BigDecimal[] correctRoundingErrors(BigDecimal bd1, BigDecimal bd2) {

    BigDecimal[] array = new BigDecimal[2];
    int scale = mc.getPrecision();

    while (!bd1.equals(bd2) && scale > mc.getPrecision() / 4) {

        bd1 = bd1.setScale(scale, RoundingMode.HALF_DOWN);
        bd2 = bd2.setScale(scale, RoundingMode.HALF_DOWN);

        if (bd1.subtract(bd1.ulp()).equals(bd2)) {
            bd1 = bd1.subtract(bd1.ulp());
        }

        if (bd1.add(bd1.ulp()).equals(bd2)) {
            bd1 = bd1.add(bd1.ulp());
        }

        scale--;
    }

    array[0] = bd1;
    array[1] = bd2;

    return array;
}

From source file:com.t2tierp.controller.nfe.NfeCabecalhoController.java

private void defineTributacao() throws Exception {
    TributOperacaoFiscal operacaoFiscal = getObjeto().getTributOperacaoFiscal();
    Empresa empresa = FacesContextUtil.getEmpresaUsuario();
    NfeDestinatario destinatario = getObjeto().getDestinatario();
    nfeDetalhe.setNfeDetalheImpostoIssqn(new NfeDetalheImpostoIssqn());
    nfeDetalhe.getNfeDetalheImpostoIssqn().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setNfeDetalheImpostoPis(new NfeDetalheImpostoPis());
    nfeDetalhe.getNfeDetalheImpostoPis().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setNfeDetalheImpostoCofins(new NfeDetalheImpostoCofins());
    nfeDetalhe.getNfeDetalheImpostoCofins().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setNfeDetalheImpostoIcms(new NfeDetalheImpostoIcms());
    nfeDetalhe.getNfeDetalheImpostoIcms().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setNfeDetalheImpostoIpi(new NfeDetalheImpostoIpi());
    nfeDetalhe.getNfeDetalheImpostoIpi().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setNfeDetalheImpostoIi(new NfeDetalheImpostoIi());
    nfeDetalhe.getNfeDetalheImpostoIi().setNfeDetalhe(nfeDetalhe);
    nfeDetalhe.setListaArmamento(new HashSet<NfeDetEspecificoArmamento>());
    nfeDetalhe.setListaMedicamento(new HashSet<NfeDetEspecificoMedicamento>());
    nfeDetalhe.setListaDeclaracaoImportacao(new HashSet<NfeDeclaracaoImportacao>());

    // Se houver CFOP cadastrado na Operao Fiscal, a nota  de servios
    if (operacaoFiscal.getCfop() != null) {
        nfeDetalhe.setCfop(operacaoFiscal.getCfop());

        // ISSQN/*from   w  w w  .j  ava2  s.c  o  m*/
        TributIss iss = operacaoFiscal.getListaIss().get(0);
        nfeDetalhe.getNfeDetalheImpostoIssqn().setBaseCalculoIssqn(nfeDetalhe.getValorBrutoProduto());
        nfeDetalhe.getNfeDetalheImpostoIssqn().setAliquotaIssqn(iss.getAliquotaPorcento());
        nfeDetalhe.getNfeDetalheImpostoIssqn()
                .setValorIssqn(nfeDetalhe.getNfeDetalheImpostoIssqn().getBaseCalculoIssqn().multiply(
                        iss.getAliquotaPorcento().divide(BigDecimal.valueOf(100), RoundingMode.HALF_DOWN)));
        nfeDetalhe.getNfeDetalheImpostoIssqn().setMunicipioIssqn(empresa.getCodigoIbgeCidade());
        nfeDetalhe.getNfeDetalheImpostoIssqn().setItemListaServicos(iss.getItemListaServico());
        // nfeDetalhe.getNfeDetalheImpostoIssqn().setTributacaoIssqn(iss.getCodigoTributacao());

        // PIS ISSQN
        nfeDetalhe.getNfeDetalheImpostoPis().setAliquotaPisPercentual(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoPis().setAliquotaPisReais(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoPis().setValorBaseCalculoPis(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoPis().setValorPis(BigDecimal.ZERO);

        // COFINS ISSQN
        nfeDetalhe.getNfeDetalheImpostoCofins().setAliquotaCofinsPercentual(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoCofins().setAliquotaCofinsReais(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoCofins().setBaseCalculoCofins(BigDecimal.ZERO);
        nfeDetalhe.getNfeDetalheImpostoCofins().setValorCofins(BigDecimal.ZERO);
    } else {
        // ICMS
        // Se o Produto estiver vinculado a uma configurao de Operao
        // Fiscal + Grupo Tributrio, carrega esses dados
        if (nfeDetalhe.getProduto().getTributGrupoTributario() != null) {
            List<Filtro> listaFiltro = new ArrayList<>();

            listaFiltro.add(new Filtro("AND", "idTributOperacaoFiscal", "=", operacaoFiscal.getId()));
            listaFiltro.add(new Filtro("AND", "idTributGrupoTributario", "=",
                    nfeDetalhe.getProduto().getTributGrupoTributario().getId()));
            listaFiltro.add(new Filtro("AND", "ufDestino", "=", destinatario.getUf()));

            ViewTributacaoIcms icms = icmsDao.getBean(ViewTributacaoIcms.class, listaFiltro);
            if (icms != null) {
                nfeDetalhe.setCfop(icms.getCfop());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setOrigemMercadoria(Integer.valueOf(icms.getOrigemMercadoria()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setCstIcms(icms.getCstB());
                nfeDetalhe.getNfeDetalheImpostoIcms().setCsosn(icms.getCsosnB());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setModalidadeBcIcms(Integer.valueOf(icms.getModalidadeBc()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setTaxaReducaoBcIcms(icms.getPorcentoBc());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaIcms(icms.getAliquota());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setModalidadeBcIcmsSt(Integer.valueOf(icms.getModalidadeBcSt()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setPercentualMvaIcmsSt(icms.getMva());
                nfeDetalhe.getNfeDetalheImpostoIcms().setPercentualReducaoBcIcmsSt(icms.getPorcentoBcSt());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaIcmsSt(icms.getAliquotaIcmsSt());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaCreditoIcmsSn(BigDecimal.ZERO);
            } else {
                throw new Exception(
                        "No existe tributao de ICMS definida para os parmetros informados. Operao no realizada.");
            }

            // IPI
            listaFiltro.clear();
            listaFiltro.add(new Filtro("AND", "idTributOperacaoFiscal", "=", operacaoFiscal.getId()));
            listaFiltro.add(new Filtro("AND", "idTributGrupoTributario", "=",
                    nfeDetalhe.getProduto().getTributGrupoTributario().getId()));

            ViewTributacaoIpi ipi = ipiDao.getBean(ViewTributacaoIpi.class, listaFiltro);
            if (ipi != null) {
                nfeDetalhe.getNfeDetalheImpostoIpi().setCstIpi(ipi.getCstIpi());
                nfeDetalhe.getNfeDetalheImpostoIpi().setAliquotaIpi(ipi.getAliquotaPorcento());
            }

            // PIS ICMS
            listaFiltro.clear();
            listaFiltro.add(new Filtro("AND", "idTributOperacaoFiscal", "=", operacaoFiscal.getId()));
            listaFiltro.add(new Filtro("AND", "idTributGrupoTributario", "=",
                    nfeDetalhe.getProduto().getTributGrupoTributario().getId()));

            ViewTributacaoPis pis = pisDao.getBean(ViewTributacaoPis.class, listaFiltro);
            if (pis != null) {
                nfeDetalhe.getNfeDetalheImpostoPis().setCstPis(pis.getCstPis());
                nfeDetalhe.getNfeDetalheImpostoPis().setAliquotaPisPercentual(pis.getAliquotaPorcento());
                nfeDetalhe.getNfeDetalheImpostoPis().setAliquotaPisReais(pis.getAliquotaUnidade());
            }

            // COFINS ICMS
            listaFiltro.clear();
            listaFiltro.add(new Filtro("AND", "idTributOperacaoFiscal", "=", operacaoFiscal.getId()));
            listaFiltro.add(new Filtro("AND", "idTributGrupoTributario", "=",
                    nfeDetalhe.getProduto().getTributGrupoTributario().getId()));

            ViewTributacaoCofins cofins = cofinsDao.getBean(ViewTributacaoCofins.class, listaFiltro);
            if (cofins != null) {
                nfeDetalhe.getNfeDetalheImpostoCofins().setNfeDetalhe(nfeDetalhe);
                nfeDetalhe.getNfeDetalheImpostoCofins().setCstCofins(cofins.getCstCofins());
                nfeDetalhe.getNfeDetalheImpostoCofins()
                        .setAliquotaCofinsPercentual(cofins.getAliquotaPorcento());
                nfeDetalhe.getNfeDetalheImpostoCofins().setAliquotaCofinsReais(cofins.getAliquotaUnidade());
            }
        } else if (nfeDetalhe.getProduto().getTributIcmsCustomCab() != null) {
            // Seno pega do ICMS Customizado
            List<Filtro> listaFiltro = new ArrayList<>();

            listaFiltro.add(
                    new Filtro("AND", "id", "=", nfeDetalhe.getProduto().getTributIcmsCustomCab().getId()));
            listaFiltro.add(new Filtro("AND", "ufDestino", "=", destinatario.getUf()));

            ViewTributacaoIcmsCustom icms = icmsCustomDao.getBean(ViewTributacaoIcmsCustom.class, listaFiltro);
            if (icms != null) {
                nfeDetalhe.getNfeDetalheImpostoIcms().setNfeDetalhe(nfeDetalhe);
                nfeDetalhe.setCfop(icms.getCfop());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setOrigemMercadoria(Integer.valueOf(icms.getOrigemMercadoria()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setCstIcms(icms.getCstB());
                nfeDetalhe.getNfeDetalheImpostoIcms().setCsosn(icms.getCsosnB());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setModalidadeBcIcms(Integer.valueOf(icms.getModalidadeBc()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setTaxaReducaoBcIcms(icms.getPorcentoBc());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaIcms(icms.getAliquota());
                nfeDetalhe.getNfeDetalheImpostoIcms()
                        .setModalidadeBcIcmsSt(Integer.valueOf(icms.getModalidadeBcSt()));
                nfeDetalhe.getNfeDetalheImpostoIcms().setPercentualMvaIcmsSt(icms.getMva());
                nfeDetalhe.getNfeDetalheImpostoIcms().setPercentualReducaoBcIcmsSt(icms.getPorcentoBcSt());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaIcmsSt(icms.getAliquotaIcmsSt());
                nfeDetalhe.getNfeDetalheImpostoIcms().setAliquotaCreditoIcmsSn(BigDecimal.ZERO);
            } else {
                throw new Exception(
                        "No existe tributao de ICMS definida para os parmetros informados. Operao no realizada.");
            }
        }

        NfeCalculo calculo = NfeCalculoController.calculo(nfeDetalhe, empresa, destinatario);

        // Valores ICMS
        nfeDetalhe.getNfeDetalheImpostoIcms().setBaseCalculoIcms(calculo.getBaseCalculoIcms());
        nfeDetalhe.getNfeDetalheImpostoIcms().setPercentualReducaoBcIcmsSt(calculo.getReducaoBcIcmsSt());
        nfeDetalhe.getNfeDetalheImpostoIcms().setValorIcms(calculo.getValorIcms());
        // valores de icms st
        nfeDetalhe.getNfeDetalheImpostoIcms().setValorBaseCalculoIcmsSt(calculo.getBaseCalculoIcmsSt());
        nfeDetalhe.getNfeDetalheImpostoIcms().setValorIcmsSt(calculo.getValorIcmsSt());
        // credito de icmssn
        nfeDetalhe.getNfeDetalheImpostoIcms().setValorCreditoIcmsSn(calculo.getValorCreditoIcmsSn());

        // Valores IPI
        nfeDetalhe.getNfeDetalheImpostoIpi().setValorBaseCalculoIpi(calculo.getBaseCalculoIpi());
        nfeDetalhe.getNfeDetalheImpostoIpi().setValorIpi(calculo.getValorIpi());

        // Valores PIS
        nfeDetalhe.getNfeDetalheImpostoPis().setValorBaseCalculoPis(calculo.getBaseCalculoPis());
        nfeDetalhe.getNfeDetalheImpostoPis().setValorPis(calculo.getValorPis());

        // Valores COFINS
        nfeDetalhe.getNfeDetalheImpostoCofins().setBaseCalculoCofins(calculo.getBaseCalculoCofins());
        nfeDetalhe.getNfeDetalheImpostoCofins().setValorCofins(calculo.getValorCofins());
    }
}

From source file:com.wasteofplastic.acidisland.commands.IslandCmd.java

private void resetMoney(Player player) {
    if (!Settings.useEconomy) {
        return;//from   w  w w .  j a va  2  s  .  co m
    }
    // Set player's balance in acid island to the starting balance
    try {
        // plugin.getLogger().info("DEBUG: " + player.getName() + " " +
        // Settings.general_worldName);
        if (VaultHelper.econ == null) {
            // plugin.getLogger().warning("DEBUG: econ is null!");
            VaultHelper.setupEconomy();
        }
        Double playerBalance = VaultHelper.econ.getBalance(player, Settings.worldName);
        // plugin.getLogger().info("DEBUG: playerbalance = " +
        // playerBalance);
        // Round the balance to 2 decimal places and slightly down to
        // avoid issues when withdrawing the amount later
        BigDecimal bd = new BigDecimal(playerBalance);
        bd = bd.setScale(2, RoundingMode.HALF_DOWN);
        playerBalance = bd.doubleValue();
        // plugin.getLogger().info("DEBUG: playerbalance after rounding = "
        // + playerBalance);
        if (playerBalance != Settings.startingMoney) {
            if (playerBalance > Settings.startingMoney) {
                Double difference = playerBalance - Settings.startingMoney;
                EconomyResponse response = VaultHelper.econ.withdrawPlayer(player, Settings.worldName,
                        difference);
                // plugin.getLogger().info("DEBUG: withdrawn");
                if (response.transactionSuccess()) {
                    plugin.getLogger()
                            .info("FYI:" + player.getName() + " had " + VaultHelper.econ.format(playerBalance)
                                    + " when they typed /island and it was set to " + Settings.startingMoney);
                } else {
                    plugin.getLogger().warning("Problem trying to withdraw " + playerBalance + " from "
                            + player.getName() + "'s account when they typed /island!");
                    plugin.getLogger().warning("Error from economy was: " + response.errorMessage);
                }
            } else {
                Double difference = Settings.startingMoney - playerBalance;
                EconomyResponse response = VaultHelper.econ.depositPlayer(player, Settings.worldName,
                        difference);
                if (response.transactionSuccess()) {
                    plugin.getLogger()
                            .info("FYI:" + player.getName() + " had " + VaultHelper.econ.format(playerBalance)
                                    + " when they typed /island and it was set to " + Settings.startingMoney);
                } else {
                    plugin.getLogger().warning("Problem trying to deposit " + playerBalance + " from "
                            + player.getName() + "'s account when they typed /island!");
                    plugin.getLogger().warning("Error from economy was: " + response.errorMessage);
                }

            }
        }
    } catch (final Exception e) {
        plugin.getLogger()
                .severe("Error trying to zero " + player.getName() + "'s account when they typed /island!");
        plugin.getLogger().severe(e.getMessage());
    }

}