Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java

public void createCashBasedJournalEntryForSharesCharges(final Office office, final String currencyCode,
        final CASH_ACCOUNTS_FOR_SHARES accountTypeToBeCredited, final Long shareProductId,
        final Long shareAccountId, final String transactionId, final Date transactionDate,
        final BigDecimal totalAmount, final List<ChargePaymentDTO> chargePaymentDTOs) {
    final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>();
    for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) {
        final GLAccount chargeSpecificAccount = getLinkedGLAccountForShareCharges(shareProductId,
                accountTypeToBeCredited.getValue(), chargePaymentDTO.getChargeId());
        BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount();

        // adjust net credit amount if the account is already present in the
        // map//from  ww w .  j  a  v a2 s  .co m
        if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
            final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount);
            chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
        }
        creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
    }

    BigDecimal totalCreditedAmount = BigDecimal.ZERO;
    for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) {
        final GLAccount account = entry.getKey();
        final BigDecimal amount = entry.getValue();
        totalCreditedAmount = totalCreditedAmount.add(amount);
        createCreditJournalEntryForShares(office, currencyCode, account, shareAccountId, transactionId,
                transactionDate, amount);
    }
    if (totalAmount.compareTo(totalCreditedAmount) != 0) {
        throw new PlatformDataIntegrityException(
                "Recent Portfolio changes w.r.t Charges for shares have Broken the accounting code",
                "Recent Portfolio changes w.r.t Charges for shares have Broken the accounting code");
    }
}

From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java

public void revertCashBasedJournalEntryForSharesCharges(final Office office, final String currencyCode,
        final CASH_ACCOUNTS_FOR_SHARES accountTypeToBeCredited, final Long shareProductId,
        final Long shareAccountId, final String transactionId, final Date transactionDate,
        final BigDecimal totalAmount, final List<ChargePaymentDTO> chargePaymentDTOs) {
    final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>();
    for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) {
        final GLAccount chargeSpecificAccount = getLinkedGLAccountForShareCharges(shareProductId,
                accountTypeToBeCredited.getValue(), chargePaymentDTO.getChargeId());
        BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount();

        // adjust net credit amount if the account is already present in the
        // map// ww w .  j  av  a2s  . co  m
        if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
            final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount);
            chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
        }
        creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
    }

    BigDecimal totalCreditedAmount = BigDecimal.ZERO;
    for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) {
        final GLAccount account = entry.getKey();
        final BigDecimal amount = entry.getValue();
        totalCreditedAmount = totalCreditedAmount.add(amount);
        createDebitJournalEntryForShares(office, currencyCode, account, shareAccountId, transactionId,
                transactionDate, amount);
    }
    if (totalAmount.compareTo(totalCreditedAmount) != 0) {
        throw new PlatformDataIntegrityException(
                "Recent Portfolio changes w.r.t Charges for shares have Broken the accounting code",
                "Recent Portfolio changes w.r.t Charges for shares have Broken the accounting code");
    }
}

From source file:com.esd.cs.audit.AuditsController.java

/**
 * ??/*w  w  w  . j  a  v a 2  s .c o m*/
 * 
 * @param calculateModel
 * @return
 */
@RequestMapping(value = "/calculate", method = RequestMethod.POST)
@ResponseBody
public CalculateModel calculateModel(CalculateModel calculateModel) {
    logger.debug(calculateModel.toString());
    Integer companyId = calculateModel.getCompanyId();
    String year = calculateModel.getYear();
    AuditParameter auditParameter = auditParameterService.getByYear(year);

    // ?
    Integer zaiZhiYuanGongZongShu = calculateModel.getZaiZhiYuanGongZongShu();
    if (zaiZhiYuanGongZongShu == null) {
        zaiZhiYuanGongZongShu = 0;
    }
    // 
    BigDecimal putScale = auditParameter.getPutScale();
    // 
    // =????*
    BigDecimal yingAnPaiCanJiRen = putScale.multiply(new BigDecimal(zaiZhiYuanGongZongShu)).setScale(2,
            BigDecimal.ROUND_HALF_UP);
    calculateModel.setYingAnPaiCanJiRen(yingAnPaiCanJiRen);// 
    // ========================================================================================
    // 
    Integer yiLuRuCanJiRen = calculateModel.getYiLuRuCanJiRen();
    // ???
    List<WorkerCalculator> list = auditParameterService.getSpecialSetting(year);
    for (WorkerCalculator workerCalculator : list) {
        Integer per = workerCalculator.getPer().intValue();
        Integer type = workerCalculator.getType();
        Integer lvl = workerCalculator.getLvl();
        Integer num = auditParameterService.getSpecialCount(companyId, year, type, lvl);
        logger.debug("type:{},lvl:{},per:{}", type, lvl, per);
        yiLuRuCanJiRen = ((yiLuRuCanJiRen - num) + (num * per));
    }
    // 
    Integer yuDingCanJiRen = calculateModel.getYuDingCanJiRen();
    // 
    Integer yiAnPaiCanJiRen = yiLuRuCanJiRen + yuDingCanJiRen;
    calculateModel.setYiAnPaiCanJiRen(yiAnPaiCanJiRen);// ;
    // =========================================================================================
    // ??
    BigDecimal averageSalary = auditParameter.getAverageSalary();
    // ?
    // ??*()
    BigDecimal yingJiaoJinE = averageSalary
            .multiply(yingAnPaiCanJiRen.subtract(new BigDecimal(yiAnPaiCanJiRen)));
    if (yingJiaoJinE.signum() == 1) {//  0
        calculateModel.setYingJiaoJinE(yingJiaoJinE);
    } else {
        yingJiaoJinE = Constants.ZERO;
        calculateModel.setYingJiaoJinE(yingJiaoJinE);
    }
    // ??
    BigDecimal jianJiaoJinE = calculateModel.getJianJiaoJinE();
    // ?=?-??
    BigDecimal shiJiaoJinE = yingJiaoJinE.subtract(jianJiaoJinE);
    // ? --------?

    // ============================================================? 
    List<AccountModel> qianJiaoMingXi = new ArrayList<AccountModel>();
    BigDecimal qianJiao = getSectionPaid(year, companyId, qianJiaoMingXi);
    calculateModel.setQianJiaoMingXi(qianJiaoMingXi);
    // ============================================================
    List<AccountModel> weiShenMingXi = new ArrayList<AccountModel>();
    BigDecimal weiShen = getUnAudits(year, companyId, new BigDecimal(zaiZhiYuanGongZongShu), weiShenMingXi);
    calculateModel.setWeiShenMingXi(weiShenMingXi);
    // =============================================================
    List<AccountModel> weiJiaoMingXi = new ArrayList<AccountModel>();
    BigDecimal weiJiao = getUnpaid(year, companyId, weiJiaoMingXi);
    calculateModel.setWeiJiaoMingXi(weiJiaoMingXi);
    // ==================================================================?
    logger.debug("qianJiao:{} weiShen:{} weiJiao{}", qianJiao, weiShen, weiJiao);
    // ? =++
    BigDecimal shangNianDuWeiJiaoBaoZhangJin = qianJiao.add(weiShen).add(weiJiao);
    calculateModel.setShangNianDuWeiJiaoBaoZhangJin(shangNianDuWeiJiaoBaoZhangJin);
    // =====================================================================================================
    // ?=?-??+?+?
    BigDecimal real_yingJiaoJinE = shiJiaoJinE.add(shangNianDuWeiJiaoBaoZhangJin);
    // BigDecimal real_yingJiaoJinE = shiJiaoJinE;
    calculateModel.setShiJiaoJinE(real_yingJiaoJinE);// ?
    // ============================================================================================
    // 
    Date date = auditParameter.getAuditDelayDate();
    // 
    BigDecimal zhiNaJinBiLi = auditParameter.getAuditDelayRate();
    // 
    int zhiNanJinTianshu = CalendarUtil.getDaySub(date, new Date());
    if (zhiNanJinTianshu < 0) {
        zhiNanJinTianshu = 0;
    }
    calculateModel.setZhiNaJinTianShu(zhiNanJinTianshu);// 
    // 
    BigDecimal zhiNaJin = real_yingJiaoJinE.multiply(zhiNaJinBiLi).multiply(new BigDecimal(zhiNanJinTianshu));
    // ??
    Boolean mian = calculateModel.getMianZhiNaJin();
    if (mian) {
        zhiNaJin = new BigDecimal(0.00);
    }
    calculateModel.setZhiNaJin(zhiNaJin);// 
    // ===============================================================================================
    // ?=?+
    BigDecimal shiJiaoZongJinE = real_yingJiaoJinE.add(zhiNaJin);
    Boolean mianJiao = calculateModel.getMianJiao();// ???
    if (mianJiao) {
        shiJiaoZongJinE = new BigDecimal(0.00);
    }
    calculateModel.setShiJiaoZongJinE(shiJiaoZongJinE);
    return calculateModel;
}

From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java

public void createCreditJournalEntryOrReversalForLoanCharges(final Office office, final String currencyCode,
        final int accountMappingTypeId, final Long loanProductId, final Long loanId, final String transactionId,
        final Date transactionDate, final BigDecimal totalAmount, final Boolean isReversal,
        final List<ChargePaymentDTO> chargePaymentDTOs) {
    /***//  w w  w. j  a va 2s  . c  om
     * Map to track each account and the net credit to be made for a
     * particular account
     ***/
    final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>();
    for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) {
        final Long chargeId = chargePaymentDTO.getChargeId();
        final GLAccount chargeSpecificAccount = getLinkedGLAccountForLoanCharges(loanProductId,
                accountMappingTypeId, chargeId);
        BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount();

        // adjust net credit amount if the account is already present in the
        // map
        if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
            final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount);
            chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
        }
        creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
    }

    BigDecimal totalCreditedAmount = BigDecimal.ZERO;
    for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) {
        final GLAccount account = entry.getKey();
        final BigDecimal amount = entry.getValue();
        totalCreditedAmount = totalCreditedAmount.add(amount);
        if (isReversal) {
            createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId,
                    transactionDate, amount);
        } else {
            createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId,
                    transactionDate, amount);
        }
    }

    // TODO: Vishwas Temporary validation to be removed before moving to
    // release branch
    if (totalAmount.compareTo(totalCreditedAmount) != 0) {
        throw new PlatformDataIntegrityException(
                "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction",
                "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction",
                totalCreditedAmount, totalAmount);
    }
}

From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java

/**
 * Convenience method that creates a pair of related Debits and Credits for
 * Accrual Based accounting.// www .ja  v a 2  s  .co m
 * 
 * The target accounts for debits and credits are switched in case of a
 * reversal
 * 
 * @param office
 * @param accountTypeToBeDebited
 *            Enum of the placeholder GLAccount to be debited
 * @param accountTypeToBeCredited
 *            Enum of the placeholder of the GLAccount to be credited
 * @param loanProductId
 * @param paymentTypeId
 * @param loanId
 * @param transactionId
 * @param transactionDate
 * @param amount
 * @param isReversal
 */
public void createAccrualBasedJournalEntriesAndReversalsForLoanCharges(final Office office,
        final String currencyCode, final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited,
        final Long loanProductId, final Long loanId, final String transactionId, final Date transactionDate,
        final BigDecimal totalAmount, final Boolean isReversal,
        final List<ChargePaymentDTO> chargePaymentDTOs) {

    GLAccount receivableAccount = getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeDebited, null);
    final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>();
    for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) {
        final Long chargeId = chargePaymentDTO.getChargeId();
        final GLAccount chargeSpecificAccount = getLinkedGLAccountForLoanCharges(loanProductId,
                accountTypeToBeCredited, chargeId);
        BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount();

        // adjust net credit amount if the account is already present in the
        // map
        if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
            final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount);
            chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
        }
        creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
    }

    BigDecimal totalCreditedAmount = BigDecimal.ZERO;
    for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) {
        final GLAccount account = entry.getKey();
        final BigDecimal amount = entry.getValue();
        totalCreditedAmount = totalCreditedAmount.add(amount);
        if (isReversal) {
            createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId,
                    transactionDate, amount);
            createCreditJournalEntryForLoan(office, currencyCode, receivableAccount, loanId, transactionId,
                    transactionDate, amount);
        } else {
            createDebitJournalEntryForLoan(office, currencyCode, receivableAccount, loanId, transactionId,
                    transactionDate, amount);
            createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId,
                    transactionDate, amount);
        }
    }

    if (totalAmount.compareTo(totalCreditedAmount) != 0) {
        throw new PlatformDataIntegrityException(
                "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction",
                "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction",
                totalCreditedAmount, totalAmount);
    }
}

From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java

public BigDecimal createCreditJournalEntryOrReversalForClientPayments(final Office office,
        final String currencyCode, final Long clientId, final Long transactionId, final Date transactionDate,
        final Boolean isReversal, final List<ClientChargePaymentDTO> clientChargePaymentDTOs) {
    /***/*from  w w w. j  a va  2s  .  c o m*/
     * Map to track each account affected and the net credit to be made for
     * a particular account
     ***/
    final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>();
    for (final ClientChargePaymentDTO clientChargePaymentDTO : clientChargePaymentDTOs) {
        if (clientChargePaymentDTO.getIncomeAccountId() != null) {
            final GLAccount chargeSpecificAccount = getGLAccountById(
                    clientChargePaymentDTO.getIncomeAccountId());
            BigDecimal chargeSpecificAmount = clientChargePaymentDTO.getAmount();

            // adjust net credit amount if the account is already present in
            // the map
            if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
                final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount);
                chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
            }
            creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
        }
    }

    BigDecimal totalCreditedAmount = BigDecimal.ZERO;
    for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) {
        final GLAccount account = entry.getKey();
        final BigDecimal amount = entry.getValue();
        totalCreditedAmount = totalCreditedAmount.add(amount);
        if (isReversal) {
            createDebitJournalEntryForClientPayments(office, currencyCode, account, clientId, transactionId,
                    transactionDate, amount);
        } else {
            createCreditJournalEntryForClientPayments(office, currencyCode, account, clientId, transactionId,
                    transactionDate, amount);
        }
    }
    return totalCreditedAmount;
}

From source file:com.jeans.iservlet.controller.impl.ExportController.java

/**
 * ???//  w  w  w .ja  va2s  .c om
 * 
 * @return
 * @throws IOException
 */
@RequestMapping(method = RequestMethod.POST, value = "/systems")
public ResponseEntity<byte[]> exportITSystems() throws IOException {
    StringBuilder fn = new StringBuilder(getCurrentCompany().getName());
    fn.append(" - ??(");
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("?");
    // ?
    // 
    // ?10??
    Font tFont = sheet.getWorkbook().createFont();
    tFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    tFont.setFontName("");
    tFont.setFontHeightInPoints((short) 10);
    // ?????????
    CellStyle cellStyleTitle = sheet.getWorkbook().createCellStyle();
    cellStyleTitle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleTitle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleTitle.setFont(tFont);
    cellStyleTitle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    cellStyleTitle.setWrapText(false);
    // 20
    Row row = sheet.createRow(0);
    row.setHeightInPoints(20);
    Cell cell = null;
    for (int i = 0; i < ITSYSTEM_HEADERS.length; i++) {
        cell = row.createCell(i, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleTitle);
        cell.setCellValue(ITSYSTEM_HEADERS[i]);
        sheet.setColumnWidth(i, ITSYSTEM_HEADERS_WIDTH[i] * 256);
    }
    // ?????->?->????
    List<ITSystem> systems = new ArrayList<ITSystem>(systService.listSystems(getCurrentCompany(), null, null));
    Collections.sort(systems, new Comparator<ITSystem>() {

        @Override
        public int compare(ITSystem o1, ITSystem o2) {
            int ret = o1.getType().ordinal() - o2.getType().ordinal();
            if (ret == 0) {
                ret = Long.compare(o1.getOwner().getId(), o2.getOwner().getId());
                if (ret == 0) {
                    ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getName(), o2.getName());
                }
            }
            return ret;
        }

    });
    // ??
    DataFormat df = sheet.getWorkbook().createDataFormat();
    // ?10?
    Font font = sheet.getWorkbook().createFont();
    font.setFontName("");
    font.setFontHeightInPoints((short) 10);
    // ?1???????
    CellStyle cellStyleString = sheet.getWorkbook().createCellStyle();
    cellStyleString.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleString.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleString.setFont(font);
    cellStyleString.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    cellStyleString.setWrapText(false);
    // ?2????(yyyyMMdd)???
    CellStyle cellStyleDate = sheet.getWorkbook().createCellStyle();
    cellStyleDate.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleDate.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleDate.setFont(font);
    cellStyleDate.setDataFormat(df.getFormat("yyyyMMdd"));
    cellStyleDate.setWrapText(false);
    // ?3??????(#)???
    CellStyle cellStyleQuantity = sheet.getWorkbook().createCellStyle();
    cellStyleQuantity.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleQuantity.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleQuantity.setFont(font);
    cellStyleQuantity.setDataFormat(df.getFormat("0"));
    cellStyleQuantity.setWrapText(false);
    // ?4?????(#,##0.00_ )???
    CellStyle cellStyleCost = sheet.getWorkbook().createCellStyle();
    cellStyleCost.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyleCost.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleCost.setFont(font);
    cellStyleCost.setDataFormat(df.getFormat("#,##0.00_ "));
    cellStyleCost.setWrapText(false);
    // sheet
    int rowNumber = 1;
    for (ITSystem system : systems) {
        // 20
        row = sheet.createRow(rowNumber);
        row.setHeightInPoints(20);
        // ?
        Set<SystemBranch> branches = system.getBranches();
        SystemBranch localBranch = null; // ??
        long localId = 0;
        if (getCurrentCompany().getLevel() == Company.BRANCH) {
            localId = getCurrentCompany().getSuperior().getId();
        } else {
            localId = getCurrentCompany().getId();
        }
        BigDecimal cost = new BigDecimal("0.0"); // 
        for (SystemBranch branch : branches) {
            cost.add(branch.getCost());
            if (branch.getCompany().getId() == localId) {
                localBranch = branch;
            }
        }
        boolean branched = (localBranch != null); // ?
        boolean owned = system.getOwner().getId() == getCurrentCompany().getId(); // ?????
        // 
        // 
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getType().getTitle());
        // ??
        cell = row.createCell(1, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getName());
        // 
        cell = row.createCell(2, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getAlias());
        // /?
        cell = row.createCell(3, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getModelOrVersion());
        // 
        cell = row.createCell(4, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getBrief());
        // ?
        cell = row.createCell(5, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(ITSYSTEM_sLevel[system.getSecurityLevel()]);
        // ???
        cell = row.createCell(6, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getSecurityCode());
        // ?
        cell = row.createCell(7, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getUsersBrief());
        // 
        cell = row.createCell(8, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(null == system.getProvider() ? "" : system.getProvider().getAlias());
        // ?
        cell = row.createCell(9, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getOwner().getAlias());
        // 
        cell = row.createCell(10, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getScope().getTitle(system.getOwner().getLevel()));
        // 
        cell = row.createCell(11, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(system.getDeploy().getTitle());
        // 
        cell = row.createCell(12, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyleString);
        cell.setCellValue(branched ? "" : "");
        if (branched) {
            // ?()
            cell = row.createCell(13, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleCost);
            cell.setCellValue(localBranch.getCost().doubleValue());
            // ?
            cell = row.createCell(14, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(cellStyleString);
            cell.setCellValue(localBranch.getStage().getTitle());
            // ?
            cell = row.createCell(15, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleDate);
            Date ct = localBranch.getConstructedTime();
            if (null != ct) {
                cell.setCellValue(ct);
            }
            // ?
            cell = row.createCell(16, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleDate);
            Date at = localBranch.getAbandonedTime();
            if (null != at) {
                cell.setCellValue(at);
            }
        }
        // ??
        cell = row.createCell(17, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(cellStyleQuantity);
        cell.setCellValue(system.getFreeMaintainMonths());
        if (owned) {
            // 
            cell = row.createCell(18, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleQuantity);
            cell.setCellValue(branches.size());
            // ?)
            cell = row.createCell(19, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleCost);
            cell.setCellValue(cost.doubleValue());
            // ??
            cell = row.createCell(20, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(cellStyleString);
            cell.setCellValue(system.getStage().getTitle());
            // ?
            cell = row.createCell(21, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleDate);
            Date ct = system.getConstructedTime();
            if (null != ct) {
                cell.setCellValue(ct);
            }
            // ?
            cell = row.createCell(22, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(cellStyleDate);
            Date at = system.getAbandonedTime();
            if (null != at) {
                cell.setCellValue(at);
            }
        }
        rowNumber++;
    }

    fn.append((new SimpleDateFormat("yyyyMMdd")).format(new Date())).append(").xlsx");
    String filename = null;
    if (isIE()) {
        filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20");
    } else {
        filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1");
    }
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096);
    wb.write(out);
    wb.close();
    out.close();
    return null;
}

From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java

@Override
@Transactional//ww w  . j av  a2  s .co  m
public FinanceOverzichtGroep graphiekOverzichtGroep(Date beginDate, Date eindDate,
        Integer showBedragPublicGroep) {
    List<? extends Bedragen> bedragInPeriode = bedragenDao.BedragInPeriode(beginDate, eindDate, null,
            showBedragPublicGroep, userInfo.getPersoon().getPk_id());

    FinanceOverzichtGroep financeOverzichtGroep = new FinanceOverzichtGroep();

    List<? extends Bedragen> lstBedragen = bedragInPeriode;

    Map<Groepen, Map<String, BigDecimal>> bedragenOverzicht = OverviewRekeningGroep(bedragInPeriode);

    BigDecimal totaalKosten = new BigDecimal(0);
    BigDecimal totaalOpbrengsten = new BigDecimal(0);

    List<OverzichtGroep> overzichtGroepen = new ArrayList<OverzichtGroep>();
    for (Entry entry : bedragenOverzicht.entrySet()) {

        GroepenSrvPojo groep = new GroepenSrvPojo((Groepen) entry.getKey());

        if (groep.getCodeId() == null) {
            groep.setCodeId("NULL");
        }

        if (!groep.getCodeId().equals("INTER_REKENING")) {
            OverzichtGroep overzichtGroep = new OverzichtGroep();
            overzichtGroep.setGroepId(groep.getPk_id());
            overzichtGroep.setNaam(groep.getNaam());

            Map<String, BigDecimal> bedragen = (Map<String, BigDecimal>) entry.getValue();
            overzichtGroep.setTotaal_kosten(bedragen.get(NEGATIEF).doubleValue());
            overzichtGroep.setTotaal_opbrengsten(bedragen.get(POSITIEF).doubleValue());

            overzichtGroepen.add(overzichtGroep);

            totaalKosten = totaalKosten.add(bedragen.get(NEGATIEF));
            totaalOpbrengsten = totaalOpbrengsten.add(bedragen.get(POSITIEF));
        }
    }
    financeOverzichtGroep.setTotaal_kosten(totaalKosten.doubleValue());
    financeOverzichtGroep.setTotaal_opbrengsten(totaalOpbrengsten.doubleValue());

    financeOverzichtGroep.setOverzichtGroep(overzichtGroepen);

    return financeOverzichtGroep;
}

From source file:com.mb.ext.core.service.impl.UserServiceImpl.java

@Override
public BigDecimal getTotalIncomeByUser(String loginId) throws BusinessException {
    BigDecimal totalIncome = new BigDecimal(0);
    try {/*w w w  .  j  a  v  a2s.c  om*/
        List<IncomeDTO> incomeEntityList = getIncomesByUser(loginId);
        for (Iterator<IncomeDTO> iterator = incomeEntityList.iterator(); iterator.hasNext();) {
            BigDecimal amount = iterator.next().getAmount();
            totalIncome = totalIncome.add(amount);
        }

    } catch (BusinessException e) {
        throw e;
    }
    return totalIncome;

}

From source file:com.salesmanager.core.service.shipping.ShippingService.java

/**
 * Calculates shipping cost based on shipping modules configured Will return
 * ShippingOptions/*from   w  ww. ja  va 2  s.c o  m*/
 */
@Transactional
public ShippingInformation getShippingQuote(Collection<OrderProduct> orderProducts, Customer customer,
        int merchantId, Locale locale, String currency) throws Exception {

    LabelUtil label = LabelUtil.getInstance();
    label.setLocale(locale);

    ShippingInformation shippingInfo = new ShippingInformation();

    String shippingType = ShippingConstants.DOMESTIC_SHIPPING;

    Collection<ShippingMethod> shippingMethods = null;

    double shippingWeight = 0;
    int quoteMethodCount = 0;

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(merchantId);

    Map allCountries = RefCache.getCountriesMap();
    // origin country
    Country c = (Country) allCountries.get(store.getCountry());
    if (c == null) {
        LogMerchantUtil.log(merchantId, "Cannot identify country id " + store.getCountry()
                + " please make sure it is configured in Store menu option.");
        log.error("Cannot identify origin countryId " + store.getCountry());
        String message = label.getText(locale, "error.cart.origincountry");
        shippingInfo.setMessage(message);
        return shippingInfo;
    }

    int customerCountryId = customer.getCustomerCountryId();
    // destination
    Country customerCountry = (Country) allCountries.get(customerCountryId);
    if (customerCountry == null) {
        log.error("Cannot identify destination countryId " + customerCountryId);
        String message = label.getText(locale, "error.cart.destinationcountry");
        shippingInfo.setMessage(message);
        return shippingInfo;
    }

    if (store.getCountry() != customer.getCustomerCountryId()) {
        shippingType = ShippingConstants.INTERNATIONAL_SHIPPING;
    }

    // get shipping informations
    ConfigurationRequest request = new ConfigurationRequest(merchantId, true, "SHP_");
    ConfigurationResponse response = mservice.getConfiguration(request);

    // are there any module configured
    MerchantConfiguration rtconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME);
    MerchantConfiguration custconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_INDIC_COUNTRIES_COSTS);

    if ((rtconf == null && custconf == null)
            || (rtconf != null && !StringUtils.isBlank(rtconf.getConfigurationValue())
                    && rtconf.getConfigurationValue().equals("false"))
                    && (custconf != null && !StringUtils.isBlank(custconf.getConfigurationValue())
                            && custconf != null && custconf.getConfigurationValue().equals("false"))) {// no module
        // configured
        LogMerchantUtil.log(merchantId, "No shipping module configured yet");
        String message = label.getText(locale, "error.cart.noshippingconfigured");
        shippingInfo.setMessage(message);
        return shippingInfo;
    }

    // get shipping type
    // national or international
    MerchantConfiguration shippingTypeConf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_ZONES_SHIPPING);
    if (shippingType != null && StringUtils.isBlank(shippingTypeConf.getConfigurationValue())) {
        String sType = shippingTypeConf.getConfigurationValue();

        if (sType.equals(ShippingConstants.DOMESTIC_SHIPPING)
                && store.getCountry() != customer.getCustomerCountryId()) {
            // set shipping message
            String message = label.getText(locale, "error.cart.noshippinginternational");
            shippingInfo.setMessage(message);
            return shippingInfo;
        }

    }

    // is the shipping country from the exclusion list
    MerchantConfiguration excluconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_ZONES_SKIPPED);
    if (excluconf != null && !StringUtils.isBlank(excluconf.getConfigurationValue())) {
        Map excludeMap = StringUtil.parseTokenLine(excluconf.getConfigurationValue(), ";");

        if (excludeMap.containsKey(customerCountry.getCountryIsoCode2())) {
            String message = label.getText(locale, "error.cart.noshippinginternational");
            shippingInfo.setMessage(message);
            return shippingInfo;
        }
    }

    // Calculate orderTotal for items to be shipped
    BigDecimal orderTotal = new BigDecimal("0");
    Iterator orderProductsIterator = orderProducts.iterator();
    while (orderProductsIterator.hasNext()) {
        OrderProduct op = (OrderProduct) orderProductsIterator.next();
        if (op.isShipping()) {
            BigDecimal finalPrice = op.getFinalPrice();
            BigDecimal priceTax = op.getProductTax();
            orderTotal = orderTotal.add(finalPrice).add(priceTax);
        }
    }

    // invoke packing module for getting details on the packages
    Collection<PackageDetail> packages = null;

    MerchantConfiguration conf = response.getMerchantConfiguration(ShippingConstants.PACKING_CONFIGURATION_KEY);
    if (conf != null) {

        String packingModule = conf.getConfigurationValue();
        if (!StringUtils.isBlank(packingModule)) {
            CalculatePackingModule module = (CalculatePackingModule) SpringUtil.getBean(packingModule);
            try {
                packages = module.calculatePacking(orderProducts, conf, merchantId);
            } catch (Exception e) {

                // use standard packing
                if (!packingModule.equals(ShippingConstants.DEFAULT_PACKING_MODULE)) {
                    module = (CalculatePackingModule) SpringUtil
                            .getBean(ShippingConstants.DEFAULT_PACKING_MODULE);
                    packages = module.calculatePacking(orderProducts, conf, merchantId);
                }
            }
        }
    }

    if (packages == null) {// calculate packages per item
        packages = new ArrayList();
        orderProductsIterator = orderProducts.iterator();
        while (orderProductsIterator.hasNext()) {
            OrderProduct op = (OrderProduct) orderProductsIterator.next();

            if (!op.isShipping()) {
                continue;
            }

            BigDecimal weight = op.getProductWeight();
            Set attributes = op.getOrderattributes();
            if (attributes != null && attributes.size() > 0) {
                Iterator attributesIterator = attributes.iterator();
                OrderProductAttribute opa = (OrderProductAttribute) attributesIterator.next();
                weight = weight.add(opa.getProductAttributeWeight());
            }

            if (op.getProductQuantity() == 1) {
                PackageDetail detail = new PackageDetail();

                detail.setCurrency(currency);
                detail.setShippingHeight(op.getProductHeight().doubleValue());
                detail.setShippingLength(op.getProductLength().doubleValue());
                detail.setShippingWeight(weight.doubleValue());
                detail.setShippingWidth(op.getProductWidth().doubleValue());
                detail.setShippingQuantity(op.getProductQuantity());
                detail.setProductName(op.getProductName());
                packages.add(detail);
            } else if (op.getProductQuantity() > 1) {
                for (int i = 0; i < op.getProductQuantity(); i++) {
                    PackageDetail inner = new PackageDetail();
                    inner.setCurrency(currency);
                    inner.setShippingHeight(op.getProductHeight().doubleValue());
                    inner.setShippingLength(op.getProductLength().doubleValue());
                    inner.setShippingWeight(weight.doubleValue());
                    inner.setShippingWidth(op.getProductWidth().doubleValue());
                    inner.setShippingQuantity(op.getProductQuantity());
                    inner.setProductName(op.getProductName());
                    packages.add(inner);
                }
            }
        }
    }

    if (packages != null) {
        Iterator packIter = packages.iterator();
        while (packIter.hasNext()) {
            PackageDetail detail = (PackageDetail) packIter.next();
            detail.setProductName("N/A");
            shippingWeight = shippingWeight + detail.getShippingWeight();
        }
    }

    // tax
    MerchantConfiguration taxconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_TAX_CLASS);
    if (taxconf != null && !StringUtils.isBlank(taxconf.getConfigurationValue())) {

        long taxClassId = Long.parseLong(taxconf.getConfigurationValue());
        shippingInfo.setTaxClass(taxClassId);

    }

    // handling fee
    BigDecimal handling = new BigDecimal("0");
    MerchantConfiguration handlingconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_HANDLING_FEES);
    if (handlingconf != null && !StringUtils.isBlank(handlingconf.getConfigurationValue())) {

        String shandling = handlingconf.getConfigurationValue();
        try {
            handling = new BigDecimal(shandling);
            if (handling.doubleValue() > 0) {
                shippingInfo.setHandlingCost(handling);
                shippingInfo.setHandlingCostText(
                        CurrencyUtil.displayFormatedAmountWithCurrency(handling, currency));
            }
        } catch (Exception e) {
            log.error("Cannot parse handling fee to BigDecimal " + shandling);
        }

    }

    // invoke configured modules
    List configList = response.getMerchantConfigurationList();
    Iterator configListIterator = configList.iterator();
    while (configListIterator.hasNext()) {

        MerchantConfiguration gatewayconf = (MerchantConfiguration) configListIterator.next();
        if (gatewayconf.getConfigurationKey().equals(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME)) {
            if (gatewayconf != null && !StringUtils.isBlank(gatewayconf.getConfigurationValue())
                    && gatewayconf.getConfigurationValue().equals("true")) {

                String module = gatewayconf.getConfigurationValue1();
                if (StringUtils.isBlank(module)) {
                    log.warn(
                            "RT Shipping module is not configured appropriatly, the column module should contain module name, see configuration id "
                                    + gatewayconf.getConfigurationId());
                } else {
                    ShippingQuotesModule shippingModule = (ShippingQuotesModule) SpringUtil.getBean(module);
                    if (shippingModule == null) {
                        log.error("Shipping module " + module + " is not defined in sm-modules.xml");
                    } else {

                        // check if module can be applied to store
                        CoreModuleService cms = getRealTimeQuoteShippingService(
                                CountryUtil.getCountryIsoCodeById(store.getCountry()), module);

                        if (cms != null) {// this shipping method cannot be
                                          // used

                            Collection rtOptions = shippingModule.getShippingQuote(response, orderTotal,
                                    packages, customer, store, locale);

                            if (rtOptions != null) {

                                // check for quote comparaison
                                MerchantConfiguration rtdetails = response.getMerchantConfiguration(
                                        ShippingConstants.MODULE_SHIPPING_DISPLAY_REALTIME_QUOTES);
                                int quoteDisplayType = ShippingConstants.ALL_QUOTES_DISPLAYED;
                                if (rtdetails != null) {

                                    if (!StringUtils.isBlank(rtdetails.getConfigurationValue2())) {// display
                                        // or
                                        // not
                                        // quotes
                                        try {
                                            quoteDisplayType = Integer
                                                    .parseInt(rtdetails.getConfigurationValue2());

                                        } catch (Exception e) {
                                            log.error("Display quote types is not an integer value ["
                                                    + rtdetails.getConfigurationValue2() + "]");
                                        }
                                    }
                                }

                                if (quoteDisplayType == ShippingConstants.LESS_EXPENSIVE_QUOTE_DISPLAYED
                                        || quoteDisplayType == ShippingConstants.MAX_EXPENSIVE_QUOTE_DISPLAYED) {

                                    Iterator rtOptionsIterator = rtOptions.iterator();
                                    ShippingOption currentOption = null;
                                    while (rtOptionsIterator.hasNext()) {
                                        ShippingOption option = (ShippingOption) rtOptionsIterator.next();
                                        if (currentOption == null) {
                                            currentOption = option;
                                        }
                                        if (quoteDisplayType == ShippingConstants.LESS_EXPENSIVE_QUOTE_DISPLAYED) {
                                            if (option.getOptionPrice().longValue() < currentOption
                                                    .getOptionPrice().longValue()) {
                                                currentOption = option;
                                            }
                                        } else if (quoteDisplayType == ShippingConstants.MAX_EXPENSIVE_QUOTE_DISPLAYED) {
                                            if (option.getOptionPrice().longValue() > currentOption
                                                    .getOptionPrice().longValue()) {
                                                currentOption = option;
                                            }
                                        }

                                    }
                                    rtOptions = new ArrayList();
                                    rtOptions.add(currentOption);
                                }

                                ShippingMethod method = new ShippingMethod();
                                method.setShippingModule(module);
                                method.setShippingMethodName(
                                        shippingModule.getShippingMethodDescription(locale));

                                quoteMethodCount++;
                                if (shippingMethods == null) {
                                    shippingMethods = new ArrayList();
                                }
                                method.setOptions(rtOptions);
                                method.setImage(cms.getCoreModuleServiceLogoPath());
                                method.setPriority(0);

                                shippingMethods.add(method);
                            }

                        }
                    }
                }
            }
        }
    }

    // invoke custom module
    MerchantConfiguration customconf = response
            .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_INDIC_COUNTRIES_COSTS);
    if (customconf != null && !StringUtils.isBlank(customconf.getConfigurationValue())
            && customconf.getConfigurationValue().equals("true")) {

        // parse first column
        Map cs = StringUtil.parseTokenLine(customconf.getConfigurationValue1(), "|");

        Map countries = new HashMap();

        if (cs != null && cs.size() > 0) {

            for (Object o : cs.keySet()) {
                String k = (String) o;
                if (!k.contains(";")) {
                    countries.put(k, (Integer) cs.get(k));
                    continue;
                }
                StringTokenizer st = new StringTokenizer(k, ";");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    countries.put(t, (Integer) cs.get(k));
                }
            }
        }

        if (countries.containsKey(customerCountry.getCountryIsoCode2())) {

            // get estimate
            String shippingEstimateLine = null;
            String shippingCostLine = customconf.getConfigurationValue1();
            MerchantConfiguration estimateCountryConf = response
                    .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_ESTIMATE_BYCOUNTRY);
            if (estimateCountryConf != null
                    && !StringUtils.isBlank(estimateCountryConf.getConfigurationValue1())) {
                shippingEstimateLine = estimateCountryConf.getConfigurationValue1();
            }
            // contains index - ShippingPriceRegion
            Map priceTimeMap = ShippingUtil.buildShippingPriceRegionMap("", shippingCostLine,
                    shippingEstimateLine);

            // determine index
            int index = -1;
            if (!StringUtils.isBlank(shippingCostLine)) {
                StringTokenizer cvtk = new StringTokenizer(shippingCostLine, "|");
                int count = 1;
                while (cvtk.hasMoreTokens()) {
                    if (index != -1) {
                        break;
                    }
                    String countryline = cvtk.nextToken();// maxpound:price,maxpound:price...|
                    if (!countryline.equals("*")) {
                        StringTokenizer countrystk = new StringTokenizer(countryline, ";");
                        String country = null;
                        while (countrystk.hasMoreTokens()) {
                            country = countrystk.nextToken();
                            if (customerCountry.getCountryIsoCode2() != null
                                    && country.equals(customerCountry.getCountryIsoCode2())) {
                                index = count;
                                break;
                            }
                        }
                    }
                    count++;
                }
            }

            int iposition = (Integer) countries.get(customerCountry.getCountryIsoCode2());// index
            // need to get the prices / pounds
            Map data = StringUtil.parseTokenLine(customconf.getConfigurationValue2(), "|");
            Map swapedData = ((BidiMap) data).inverseBidiMap();
            String countryData = (String) swapedData.get(iposition);

            // this line is in the form [MAX_POUND:PRICE;MAX_POUND2:PRICE]
            // get boundaries
            ShippingMethod method = new ShippingMethod();
            method.setShippingModule("custom");
            String description = label.getText(locale, "message.cart.sellershippingcost") + " "
                    + customerCountry.getCountryName() + " " + customer.getCustomerPostalCode();
            method.setPriority(1);

            if (shippingMethods == null || shippingMethods.size() == 0) {
                method.setPriority(0);
            }

            method.setShippingMethodName(description);
            StringTokenizer st = new StringTokenizer(countryData, ";");
            int lowBoundary = 0;
            while (st.hasMoreTokens()) {
                String token = st.nextToken();// should have MAX_POUND:PRICE
                try {
                    int position = token.indexOf(":");
                    if (position > -1) {
                        String spound = token.substring(0, token.indexOf(":"));
                        if (spound != null) {
                            int highBoundary = Integer.parseInt(spound);
                            if (lowBoundary <= shippingWeight && highBoundary >= shippingWeight) {
                                String sprice = token.substring(position + 1, token.length());
                                ShippingOption option = new ShippingOption();
                                option.setCurrency(store.getCurrency());
                                option.setOptionCode("custom");
                                option.setOptionId("custom-" + lowBoundary);
                                option.setOptionPrice(new BigDecimal(sprice));
                                option.setDescription(description);
                                method.addOption(option);
                                if (shippingMethods == null) {
                                    shippingMethods = new ArrayList();
                                }
                                shippingMethods.add(method);

                                // get the estimate
                                if (priceTimeMap != null && priceTimeMap.size() > 0) {

                                    ShippingPriceRegion spr = (ShippingPriceRegion) priceTimeMap.get(index);
                                    if (spr != null && spr.getMinDays() != -1 && spr.getMaxDays() != -1) {
                                        String returnText = "";

                                        if (locale == null) {
                                            locale = LocaleUtil.getDefaultLocale();
                                        }

                                        try {

                                            if (spr.getMinDays() == spr.getMaxDays()) {
                                                List parameters = new ArrayList();
                                                parameters.add(customerCountry.getCountryIsoCode2());
                                                parameters.add(spr.getMaxDays());
                                                returnText = label.getText(locale,
                                                        "message.delivery.estimate.precise", parameters);
                                            } else {
                                                List parameters = new ArrayList();
                                                parameters.add(customerCountry.getCountryIsoCode2());
                                                parameters.add(spr.getMinDays());
                                                parameters.add(spr.getMaxDays());
                                                returnText = label.getText(locale,
                                                        "message.delivery.estimate.range", parameters);
                                            }
                                            option.setEstimatedNumberOfDays(returnText);

                                        } catch (Exception e) {
                                            log.error("Error assigning parameters for shipping");
                                        }

                                    }
                                }

                                quoteMethodCount++;
                                break;
                            }
                            lowBoundary = highBoundary;
                        }
                    }
                } catch (Exception e) {
                    log.error("Price Pound parsing error " + e);
                }
            }
        }

    }

    if (quoteMethodCount == 0) {
        String message = LabelUtil.getInstance().getText(locale, "error.cart.noshippingconfigured");
        shippingInfo.setMessage(message);
        return shippingInfo;
    }

    if (quoteMethodCount > 0) {

        // is it free ?
        MerchantConfiguration freeconf = response
                .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_FREE_IND_DEST_AMNT);
        if (freeconf != null && !StringUtils.isBlank(freeconf.getConfigurationValue())
                && freeconf.getConfigurationValue().equals("true")) {
            // get national or international
            String freeShippingType = freeconf.getConfigurationValue1();
            if (!StringUtils.isBlank(freeShippingType)) {
                // if shipping is domestic and free ship is domestic, then
                // ok
                // if shipping is domestic and free ship is intl, then ok
                // if shipping is intl and free ship is intl, then ok
                if (shippingType.equals(ShippingConstants.DOMESTIC_SHIPPING)
                        || freeShippingType.equals(shippingType)) {
                    // get amount
                    if (!StringUtils.isBlank(freeconf.getConfigurationValue2())) {
                        BigDecimal freeAmount = new BigDecimal(freeconf.getConfigurationValue2()).setScale(2);
                        if (orderTotal.floatValue() - freeAmount.floatValue() > 0) {

                            // remove live quotes
                            shippingInfo.setShippingMethods(null);

                            String message = LabelUtil.getInstance().getText(locale,
                                    "message.cart.freeshipping") + " "
                                    + CurrencyUtil.displayFormatedAmountWithCurrency(freeAmount, currency);
                            shippingInfo.setMessage(message);
                            BigDecimal freeShippingCost = new BigDecimal("0");

                            List optList = new ArrayList();

                            ShippingMethod method = new ShippingMethod();
                            method.setShippingMethodName(
                                    LabelUtil.getInstance().getText(locale, "label.cart.freeshipping"));
                            method.setShippingModule("free");
                            method.setPriority(0);
                            ShippingOption option = new ShippingOption();
                            option.setOptionId("free");
                            option.setCurrency(currency);
                            option.setOptionCode("free");
                            option.setModule("free");
                            option.setOptionPrice(new BigDecimal("0"));
                            option.setDescription(
                                    LabelUtil.getInstance().getText(locale, "label.cart.freeshipping") + " "
                                            + customerCountry.getCountryName() + " "
                                            + customer.getCustomerPostalCode());
                            optList.add(option);
                            method.setOptions(optList);

                            shippingMethods = new ArrayList();

                            shippingMethods.add(method);

                            shippingInfo.setShippingCost(freeShippingCost);
                            shippingInfo.setShippingCostText(
                                    CurrencyUtil.displayFormatedAmountWithCurrency(freeShippingCost, currency));
                            shippingInfo.setFreeShipping(true);

                            // no handling fee
                            shippingInfo.setHandlingCost(new BigDecimal("0"));

                        }
                    }

                }
            }

        }

    }

    if (shippingMethods != null) {
        shippingInfo.setShippingMethods(shippingMethods);
    }

    return shippingInfo;

}