Example usage for java.math BigDecimal ZERO

List of usage examples for java.math BigDecimal ZERO

Introduction

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

Prototype

BigDecimal ZERO

To view the source code for java.math BigDecimal ZERO.

Click Source Link

Document

The value 0, with a scale of 0.

Usage

From source file:com.iskyshop.manage.buyer.action.OrderBuyerAction.java

private List<Object> dataProcess(List<OrderForm> resultList) {
    List<Object> result = new ArrayList<Object>();
    if (resultList != null) {
        for (OrderForm form : resultList) {
            BigDecimal totleAmount = BigDecimal.ZERO;
            BigDecimal totleShipPrice = BigDecimal.ZERO;
            List<Object> list = new ArrayList<Object>();
            //??// w  w  w  .j  a v  a 2  s  . c o m
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", form.getId());
            map.put("order_id", form.getOrder_id());
            map.put("addTime", form.getAddTime());
            map.put("order_status", form.getOrder_status());
            map.put("ship_price", form.getShip_price());
            map.put("order_cat", form.getOrder_cat());
            if (form.getPayment() != null) {
                map.put("mark", form.getPayment().getMark());
            }

            //??
            Map<String, Object> mainstorinfo = new HashMap<String, Object>();
            mainstorinfo.put("receiver_Name", form.getReceiver_Name());
            mainstorinfo.put("id", form.getId());
            mainstorinfo.put("totalPrice", form.getTotalPrice());
            mainstorinfo.put("goods_amount", form.getGoods_amount());
            mainstorinfo.put("shipCode", form.getShipCode());
            mainstorinfo.put("order_id", form.getOrder_id());
            mainstorinfo.put("order_cat", form.getOrder_cat());
            mainstorinfo.put("ship_price", form.getShip_price());
            mainstorinfo.put("order_status", form.getOrder_status());

            totleAmount = totleAmount.add(form.getTotalPrice());
            totleShipPrice = totleShipPrice.add(form.getShip_price());

            //?????
            List<Map> maps = this.orderFormTools.queryGoodsInfo(form.getGoods_info());
            Map<String, Object> temmap = new HashMap<String, Object>();
            List<Object> temList = new ArrayList<Object>();
            for (Map tem : maps) {
                temmap = new HashMap<String, Object>();
                temmap.put("goods_mainphoto_path", tem.get("goods_mainphoto_path"));
                temmap.put("goods_domainPath", tem.get("goods_domainPath"));
                temmap.put("goods_name", tem.get("goods_name"));
                temList.add(temmap);
            }
            mainstorinfo.put("goods_info", temList);
            list.add(mainstorinfo);

            //????
            List<Map> maps2 = this.orderFormTools.queryGoodsInfo(form.getChild_order_detail());
            for (Map tem : maps2) {
                OrderForm orderForm = this.orderFormService
                        .getObjById(Long.parseLong((tem.get("order_id")).toString()));
                Map<String, Object> childstorInfo = new HashMap<String, Object>();
                childstorInfo.put("receiver_Name", form.getReceiver_Name());
                childstorInfo.put("totalPrice", orderForm.getTotalPrice());
                childstorInfo.put("id", orderForm.getId());
                childstorInfo.put("shipCode", orderForm.getShipCode());
                childstorInfo.put("goods_amount", orderForm.getGoods_amount());
                childstorInfo.put("order_id", orderForm.getOrder_id());
                childstorInfo.put("order_cat", orderForm.getOrder_cat());
                childstorInfo.put("ship_price", orderForm.getShip_price());
                childstorInfo.put("order_status", orderForm.getOrder_status());
                //????
                List<Map> maps_child_order_info = this.orderFormTools.queryGoodsInfo(orderForm.getGoods_info());
                Map<String, Object> temmap2 = null;
                List<Object> temList2 = new ArrayList<Object>();
                for (Map tem3 : maps_child_order_info) {//???
                    temmap2 = new HashMap<String, Object>();
                    temmap2.put("goods_mainphoto_path", tem3.get("goods_mainphoto_path"));
                    temmap2.put("goods_domainPath", tem3.get("goods_domainPath"));
                    temmap2.put("goods_name", tem3.get("goods_name"));
                    temList2.add(temmap2);
                }
                childstorInfo.put("goods_info", temList2);
                list.add(childstorInfo);
                totleAmount = totleAmount.add(orderForm.getTotalPrice());
                totleShipPrice = totleShipPrice.add(orderForm.getShip_price());
            }
            map.put("lists", list);
            map.put("totleAmount", totleAmount);
            map.put("totleShipPrice", totleShipPrice);
            result.add(map);
        }
    }
    return result;
}

From source file:net.shopxx.entity.Order.java

@Transient
public BigDecimal getAmountPayable() {
    if (!hasExpired() && !Order.Status.completed.equals(getStatus()) && !Order.Status.failed.equals(getStatus())
            && !Order.Status.canceled.equals(getStatus()) && !Order.Status.denied.equals(getStatus())) {
        BigDecimal amountPayable = getAmount().subtract(getAmountPaid());
        return amountPayable.compareTo(BigDecimal.ZERO) >= 0 ? amountPayable : BigDecimal.ZERO;
    }/*from ww w  . j ava  2s  .c om*/
    return BigDecimal.ZERO;
}

From source file:com.wso2telco.dep.reportingservice.northbound.NbHostObjectUtils.java

/**
 * Bill component./* w w  w .  j a v a  2  s  .  c  o  m*/
 *
 * @param rate the rate
 * @param rateCard the rate card
 * @param operatorSubscription the operator subscription
 * @param subsYear the subs year
 * @param subsMonth the subs month
 * @param application the application
 * @param ApiName the api name
 * @param apiVersion the api version
 * @param categoryEntry the category entry
 * @param appId the app id
 * @param apiId the api id
 * @param subsId the subs id
 * @throws Exception 
 */
private static void billComponent(ChargeRate rate, Map<RateKey, ChargeRate> rateCard,
        BillingSubscription.OperatorSubscription operatorSubscription, String subsYear, String subsMonth,
        Application application, String ApiName, String apiVersion,
        Map.Entry<CategoryCharge, BilledCharge> categoryEntry, int appId, int apiId, String subsId)
        throws Exception {

    String billCategory = categoryEntry.getKey().getCategory();
    String billSubCategory = categoryEntry.getKey().getSubcategory();
    BigDecimal billRate = rate.getValue();
    Object SubsRate = null;

    switch (rate.getType()) {

    case CONSTANT:

        SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
        if (SubsRate != null) {
            billRate = new BigDecimal((String) SubsRate);
        }
        categoryEntry.getValue().setPrice(billRate);
        applyTaxForBlockCharging(categoryEntry, rate, subsYear, subsMonth);
        break;

    case QUOTA:

        Map<String, String> rateAttributes = (Map<String, String>) rate.getRateAttributes();
        SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
        if (SubsRate != null) {
            rateAttributes = (Map<String, String>) SubsRate;
        }

        if (rateAttributes == null
                || !rateAttributes.containsKey(HostObjectConstants.RATE_ATTRIBUTE_MAX_COUNT.toString())
                || !rateAttributes.containsKey(HostObjectConstants.RATE_ATTRIBUTE_EXCESS_RATE.toString())
                || !rateAttributes.containsKey(HostObjectConstants.RATE_ATTRIBUTE_DEFAULT_RATE.toString())) {
            throw new APIManagementException(
                    "Attributes required for QUOTA charging are not specified in rate-card.xml");
        }
        int maxCount = Integer
                .parseInt(rateAttributes.get(HostObjectConstants.RATE_ATTRIBUTE_MAX_COUNT.toString()));
        BigDecimal excessRate = new BigDecimal(
                rateAttributes.get(HostObjectConstants.RATE_ATTRIBUTE_EXCESS_RATE.toString()));
        BigDecimal defaultRate = new BigDecimal(
                rateAttributes.get(HostObjectConstants.RATE_ATTRIBUTE_DEFAULT_RATE.toString()));

        if (categoryEntry.getValue().getCount() > maxCount) {
            int excess = categoryEntry.getValue().getCount() - maxCount;
            BigDecimal charge = excessRate.multiply(BigDecimal.valueOf(excess)).add(defaultRate);
            categoryEntry.getValue().setPrice(charge);
        } else {
            categoryEntry.getValue().setPrice(defaultRate);
        }
        applyTaxForBlockCharging(categoryEntry, rate, subsYear, subsMonth);
        break;

    case MULTITIER:
        int totalRequestCount = categoryEntry.getValue().getCount();

        BigDecimal price = BigDecimal.ZERO;
        int tierCount = 0;
        List<UsageTiers> usageTier = rate.getUsageTiers();
        SubsRate = getRateSubcategory(rate, billCategory, billSubCategory);
        if (SubsRate != null) {
            usageTier = (List<UsageTiers>) SubsRate;
        }

        calculateTiersCharges(usageTier, rateCard, totalRequestCount, tierCount, operatorSubscription, subsYear,
                subsMonth, application, ApiName, apiVersion, categoryEntry, appId, apiId, subsId);
        break;

    case PERCENTAGE:
        APIKey prodKey = getAppKey(application, APIConstants.API_KEY_TYPE_PRODUCTION);
        if (prodKey != null) {
            String consumerKey = prodKey.getConsumerKey();
            String api_version = ApiName + ":v" + apiVersion;
            BillingDAO billingDAO = new BillingDAO();
            Set<PaymentRequestDTO> paymentRequestSet = billingDAO.getNbPaymentAmounts(
                    Short.parseShort(subsYear), Short.parseShort(subsMonth), consumerKey, api_version,
                    operatorSubscription.getOperationId(), categoryEntry.getKey().getCategory(),
                    categoryEntry.getKey().getSubcategory());
            applyChargesForPaymentApi(operatorSubscription, paymentRequestSet, categoryEntry, appId, apiId,
                    subsId);
        }
        break;

    case SUBSCRIPTION:
        int noOfSubscribers = categoryEntry.getValue().getCount();
        if (SubsRate != null) {
            billRate = new BigDecimal((String) SubsRate);
        }
        categoryEntry.getValue().setPrice(billRate.multiply(new BigDecimal(noOfSubscribers)));
        applyTaxForBlockCharging(categoryEntry, rate, subsYear, subsMonth);
        break;

    case PER_REQUEST:
        applyChargesWithTax(subsYear, subsMonth, application, ApiName, apiVersion, operatorSubscription,
                categoryEntry, rate);
        break;

    default:
        break;
    }

}

From source file:net.shopxx.dao.impl.OrderDaoImpl.java

public Long count(Order.Type type, Order.Status status, Member member, Goods goods, Boolean isPendingReceive,
        Boolean isPendingRefunds, Boolean isUseCouponCode, Boolean isExchangePoint, Boolean isAllocatedStock,
        Boolean hasExpired) {// w ww  .  j a  va  2  s  .  c o m
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Order> criteriaQuery = criteriaBuilder.createQuery(Order.class);
    Root<Order> root = criteriaQuery.from(Order.class);
    criteriaQuery.select(root);
    Predicate restrictions = criteriaBuilder.conjunction();
    if (type != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("type"), type));
    }
    if (status != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("status"), status));
    }
    if (member != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member));
    }
    if (goods != null) {
        Subquery<Product> productSubquery = criteriaQuery.subquery(Product.class);
        Root<Product> productSubqueryRoot = productSubquery.from(Product.class);
        productSubquery.select(productSubqueryRoot);
        productSubquery.where(criteriaBuilder.equal(productSubqueryRoot.get("goods"), goods));

        Subquery<OrderItem> orderItemSubquery = criteriaQuery.subquery(OrderItem.class);
        Root<OrderItem> orderItemSubqueryRoot = orderItemSubquery.from(OrderItem.class);
        orderItemSubquery.select(orderItemSubqueryRoot);
        orderItemSubquery.where(criteriaBuilder.equal(orderItemSubqueryRoot.get("order"), root),
                criteriaBuilder.in(orderItemSubqueryRoot.get("product")).value(productSubquery));
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.exists(orderItemSubquery));
    }
    if (isPendingReceive != null) {
        Predicate predicate = criteriaBuilder.and(
                criteriaBuilder.or(root.get("expire").isNull(),
                        criteriaBuilder.greaterThan(root.<Date>get("expire"), new Date())),
                criteriaBuilder.equal(root.get("paymentMethodType"), PaymentMethod.Type.cashOnDelivery),
                criteriaBuilder.notEqual(root.get("status"), Order.Status.completed),
                criteriaBuilder.notEqual(root.get("status"), Order.Status.failed),
                criteriaBuilder.notEqual(root.get("status"), Order.Status.canceled),
                criteriaBuilder.notEqual(root.get("status"), Order.Status.denied),
                criteriaBuilder.lessThan(root.<BigDecimal>get("amountPaid"), root.<BigDecimal>get("amount")));
        if (isPendingReceive) {
            restrictions = criteriaBuilder.and(restrictions, predicate);
        } else {
            restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.not(predicate));
        }
    }
    if (isPendingRefunds != null) {
        Predicate predicate = criteriaBuilder.or(
                criteriaBuilder.and(
                        criteriaBuilder.or(
                                criteriaBuilder.and(root.get("expire").isNotNull(),
                                        criteriaBuilder.lessThanOrEqualTo(root.<Date>get("expire"),
                                                new Date())),
                                criteriaBuilder.equal(root.get("status"), Order.Status.failed),
                                criteriaBuilder.equal(root.get("status"), Order.Status.canceled),
                                criteriaBuilder.equal(root.get("status"), Order.Status.denied)),
                        criteriaBuilder.greaterThan(root.<BigDecimal>get("amountPaid"), BigDecimal.ZERO)),
                criteriaBuilder.and(criteriaBuilder.equal(root.get("status"), Order.Status.completed),
                        criteriaBuilder.greaterThan(root.<BigDecimal>get("amountPaid"),
                                root.<BigDecimal>get("amount"))));
        if (isPendingRefunds) {
            restrictions = criteriaBuilder.and(restrictions, predicate);
        } else {
            restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.not(predicate));
        }
    }
    if (isUseCouponCode != null) {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.equal(root.get("isUseCouponCode"), isUseCouponCode));
    }
    if (isExchangePoint != null) {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.equal(root.get("isExchangePoint"), isExchangePoint));
    }
    if (isAllocatedStock != null) {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.equal(root.get("isAllocatedStock"), isAllocatedStock));
    }
    if (hasExpired != null) {
        if (hasExpired) {
            restrictions = criteriaBuilder.and(restrictions, root.get("expire").isNotNull(),
                    criteriaBuilder.lessThanOrEqualTo(root.<Date>get("expire"), new Date()));
        } else {
            restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("expire").isNull(),
                    criteriaBuilder.greaterThan(root.<Date>get("expire"), new Date())));
        }
    }
    criteriaQuery.where(restrictions);
    return super.count(criteriaQuery, null);
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getFirstInvTotalFNAdminFee() {
    BigDecimal amount = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(firstInvs)) {
        for (int i = 0; i < firstInvs.length; i++) {
            if ("N".equals(firstInvs[i].getPaidIndicator())) {
                amount = amount.add(BigDecimalUtil.nullSafe(firstInvs[i].getInvoiceAdminFee()));
            }/*from www.  j a v a  2s  .  c o  m*/
        }
    }
    return amount;
}

From source file:it.govpay.core.utils.RtUtils.java

public static Rpt acquisisciRT(String codDominio, String iuv, String ccp, String tipoFirma, byte[] rtByte,
        BasicBD bd) throws ServiceException, NdpException {
    bd.setAutoCommit(false);/*from w  w  w . ja va2s . co  m*/
    bd.enableSelectForUpdate();

    RptBD rptBD = new RptBD(bd);
    Rpt rpt = null;
    try {
        rpt = rptBD.getRpt(codDominio, iuv, ccp);
    } catch (NotFoundException e) {
        throw new NdpException(FaultPa.PAA_RPT_SCONOSCIUTA, codDominio, null);
    }

    if (rpt.getStato().equals(StatoRpt.RT_ACCETTATA_PA)) {
        throw new NdpException(FaultPa.PAA_RT_DUPLICATA, rpt.getCodDominio());
    }

    if (!rpt.getFirmaRichiesta().equals(FirmaRichiesta.toEnum(tipoFirma)))
        throw new NdpException(FaultPa.PAA_FIRMA_ERRATA, codDominio, "Richiesta RT con firma ["
                + rpt.getFirmaRichiesta().getCodifica() + "], ricevuta RT con firma [" + tipoFirma + "]");

    CtRicevutaTelematica ctRt = null;
    CtRichiestaPagamentoTelematico ctRpt = null;
    // Validazione RT
    try {
        // Validazione Firma
        byte[] rtByteValidato = RtUtils.validaFirma(tipoFirma, rtByte, codDominio);

        // Validazione Sintattica
        try {
            ctRt = JaxbUtils.toRT(rtByteValidato);
        } catch (Exception e) {
            log.warn("Errore durante la validazione sintattica della Ricevuta Telematica.", e);
            if (e.getCause() != null)
                throw new NdpException(FaultPa.PAA_SINTASSI_XSD, codDominio, e.getCause().getMessage());
            else
                throw new NdpException(FaultPa.PAA_SINTASSI_XSD, codDominio, e.getMessage());
        }
    } catch (NdpException e) {
        log.warn("Rt rifiutata: " + e.getDescrizione());
        rpt.setStato(StatoRpt.RT_RIFIUTATA_PA);
        rpt.setDescrizioneStato(e.getDescrizione());
        rpt.setXmlRt(rtByte);
        rptBD.updateRpt(rpt.getId(), rpt);
        bd.commit();
        bd.disableSelectForUpdate();
        throw e;
    }

    // Validazione Semantica
    RtUtils.EsitoValidazione esito = null;
    try {
        ctRpt = JaxbUtils.toRPT(rpt.getXmlRpt());
        esito = RtUtils.validaSemantica(ctRpt, ctRt);
    } catch (JAXBException e) {
        throw new ServiceException(e);
    } catch (SAXException e) {
        throw new ServiceException(e);
    }

    GpContext ctx = GpThreadLocal.get();

    if (esito.validato && esito.errori.size() > 0) {
        ctx.log("pagamento.validazioneRtWarn", esito.getDiagnostico());
    }

    if (!esito.validato) {
        ctx.log("pagamento.validazioneRtFail", esito.getDiagnostico());
        rpt.setStato(StatoRpt.RT_RIFIUTATA_PA);
        rpt.setDescrizioneStato(esito.getFatal());
        rpt.setXmlRt(rtByte);
        rptBD.updateRpt(rpt.getId(), rpt);
        bd.commit();
        bd.disableSelectForUpdate();
        throw new NdpException(FaultPa.PAA_SEMANTICA, codDominio, esito.getFatal());
    }

    log.info("Acquisizione RT per un importo di " + ctRt.getDatiPagamento().getImportoTotalePagato());

    ctx.getContext().getRequest().addGenericProperty(
            new Property("codMessaggioRicevuta", ctRt.getIdentificativoMessaggioRicevuta()));
    ctx.getContext().getRequest().addGenericProperty(
            new Property("importo", ctRt.getDatiPagamento().getImportoTotalePagato().toString()));
    ctx.getContext().getRequest().addGenericProperty(new Property("codEsitoPagamento",
            Rpt.EsitoPagamento.toEnum(ctRt.getDatiPagamento().getCodiceEsitoPagamento()).toString()));
    ctx.log("rt.acquisizione");

    // Rileggo per avere la lettura dello stato rpt in transazione
    rpt.setCodMsgRicevuta(ctRt.getIdentificativoMessaggioRicevuta());
    rpt.setDataMsgRicevuta(ctRt.getDataOraMessaggioRicevuta());
    rpt.setEsitoPagamento(Rpt.EsitoPagamento.toEnum(ctRt.getDatiPagamento().getCodiceEsitoPagamento()));
    rpt.setImportoTotalePagato(ctRt.getDatiPagamento().getImportoTotalePagato());
    rpt.setStato(StatoRpt.RT_ACCETTATA_PA);
    rpt.setXmlRt(rtByte);
    rpt.setIdTransazioneRt(GpThreadLocal.get().getTransactionId());
    // Aggiorno l'RPT con i dati dell'RT
    rptBD.updateRpt(rpt.getId(), rpt);

    Versamento versamento = rpt.getVersamento(bd);
    VersamentiBD versamentiBD = new VersamentiBD(bd);

    List<CtDatiSingoloPagamentoRT> datiSingoliPagamenti = ctRt.getDatiPagamento().getDatiSingoloPagamento();
    List<SingoloVersamento> singoliVersamenti = versamento.getSingoliVersamenti(bd);

    PagamentiBD pagamentiBD = new PagamentiBD(bd);

    boolean irregolare = false;
    for (int indice = 0; indice < datiSingoliPagamenti.size(); indice++) {
        CtDatiSingoloPagamentoRT ctDatiSingoloPagamentoRT = datiSingoliPagamenti.get(indice);
        CtDatiSingoloVersamentoRPT ctDatiSingoloVersamentoRPT = ctRpt.getDatiVersamento()
                .getDatiSingoloVersamento().get(indice);
        // Se non e' stato completato un pagamento, non faccio niente.
        if (ctDatiSingoloPagamentoRT.getSingoloImportoPagato().compareTo(BigDecimal.ZERO) == 0)
            continue;

        SingoloVersamento singoloVersamento = singoliVersamenti.get(indice);

        Pagamento pagamento = new Pagamento();
        pagamento.setDataPagamento(ctDatiSingoloPagamentoRT.getDataEsitoSingoloPagamento());
        pagamento.setRpt(rpt);
        pagamento.setSingoloVersamento(singoloVersamento);
        pagamento.setImportoPagato(ctDatiSingoloPagamentoRT.getSingoloImportoPagato());
        pagamento.setIur(ctDatiSingoloPagamentoRT.getIdentificativoUnivocoRiscossione());
        pagamento.setIbanAccredito(ctDatiSingoloVersamentoRPT.getIbanAccredito());
        pagamento.setCodDominio(rpt.getCodDominio());
        pagamento.setIuv(rpt.getIuv());

        if (ctDatiSingoloPagamentoRT.getAllegatoRicevuta() != null) {
            pagamento.setTipoAllegato(Pagamento.TipoAllegato.valueOf(
                    ctDatiSingoloPagamentoRT.getAllegatoRicevuta().getTipoAllegatoRicevuta().toString()));
            pagamento.setAllegato(ctDatiSingoloPagamentoRT.getAllegatoRicevuta().getTestoAllegato());
        }

        // Se gli importi corrispondono e lo stato era da pagare, il singoloVersamento e' eseguito. Altrimenti irregolare.
        if (singoloVersamento.getStatoSingoloVersamento().equals(StatoSingoloVersamento.NON_ESEGUITO)
                && singoloVersamento.getImportoSingoloVersamento().compareTo(pagamento.getImportoPagato()) == 0)
            singoloVersamento.setStatoSingoloVersamento(StatoSingoloVersamento.ESEGUITO);
        else {
            List<String> anomalie = new ArrayList<String>();

            if (!singoloVersamento.getStatoSingoloVersamento().equals(StatoSingoloVersamento.NON_ESEGUITO)) {
                anomalie.add("La voce del versamento [CodVersamentoEnte:"
                        + singoloVersamento.getVersamento(bd).getCodVersamentoEnte()
                        + " CodSingoloVersamentoEnte:" + singoloVersamento.getCodSingoloVersamentoEnte()
                        + "] a cui riferisce il pagamento e' in stato ["
                        + singoloVersamento.getStatoSingoloVersamento().toString() + "].");
                log.warn("La voce del versamento [CodVersamentoEnte:"
                        + singoloVersamento.getVersamento(bd).getCodVersamentoEnte()
                        + " CodSingoloVersamentoEnte:" + singoloVersamento.getCodSingoloVersamentoEnte()
                        + "] a cui riferisce il pagamento e' in stato ["
                        + singoloVersamento.getStatoSingoloVersamento().toString() + "].");
            }

            if (singoloVersamento.getImportoSingoloVersamento().compareTo(pagamento.getImportoPagato()) != 0) {
                anomalie.add("La voce del versamento [CodVersamentoEnte:"
                        + singoloVersamento.getVersamento(bd).getCodVersamentoEnte()
                        + " CodSingoloVersamentoEnte:" + singoloVersamento.getCodSingoloVersamentoEnte()
                        + "] a cui riferisce il pagamento presenta un importo ["
                        + singoloVersamento.getImportoSingoloVersamento()
                        + "] che non corrisponde a quanto pagato [" + pagamento.getImportoPagato() + "].");
                log.warn("La voce del versamento [CodVersamentoEnte:"
                        + singoloVersamento.getVersamento(bd).getCodVersamentoEnte()
                        + " CodSingoloVersamentoEnte:" + singoloVersamento.getCodSingoloVersamentoEnte()
                        + "] a cui riferisce il pagamento presenta un importo ["
                        + singoloVersamento.getImportoSingoloVersamento()
                        + "] che non corrisponde a quanto pagato [" + pagamento.getImportoPagato() + "].");
            }
            ctx.log("pagamento.acquisizionePagamentoAnomalo",
                    ctDatiSingoloPagamentoRT.getIdentificativoUnivocoRiscossione(),
                    StringUtils.join(anomalie, "\n"));

            singoloVersamento.setStatoSingoloVersamento(StatoSingoloVersamento.ANOMALO);
            irregolare = true;
        }

        ctx.log("rt.acquisizionePagamento", pagamento.getIur(), pagamento.getImportoPagato().toString(),
                singoloVersamento.getCodSingoloVersamentoEnte(),
                singoloVersamento.getStatoSingoloVersamento().toString());

        versamentiBD.updateStatoSingoloVersamento(singoloVersamento.getId(),
                singoloVersamento.getStatoSingoloVersamento());
        pagamentiBD.insertPagamento(pagamento);
    }

    switch (rpt.getEsitoPagamento()) {
    case PAGAMENTO_ESEGUITO:
        switch (versamento.getStatoVersamento()) {
        case ANNULLATO:
        case NON_ESEGUITO:
            if (!irregolare) {
                versamento.setStatoVersamento(StatoVersamento.ESEGUITO);
                versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            } else {
                versamento.setStatoVersamento(StatoVersamento.ANOMALO);
                versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            }
            break;
        default:
            versamento.setStatoVersamento(StatoVersamento.ANOMALO);
            versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            break;
        }
        break;

    case PAGAMENTO_PARZIALMENTE_ESEGUITO:
    case DECORRENZA_TERMINI_PARZIALE:
        switch (versamento.getStatoVersamento()) {
        case ANNULLATO:
        case NON_ESEGUITO:
            if (!irregolare) {
                versamento.setStatoVersamento(StatoVersamento.PARZIALMENTE_ESEGUITO);
                versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            } else {
                versamento.setStatoVersamento(StatoVersamento.ANOMALO);
                versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            }
        default:
            versamento.setStatoVersamento(StatoVersamento.ANOMALO);
            versamentiBD.updateStatoVersamento(versamento.getId(), versamento.getStatoVersamento(), null);
            break;
        }
    case DECORRENZA_TERMINI:
    case PAGAMENTO_NON_ESEGUITO:
        break;
    }

    Notifica notifica = new Notifica(rpt, TipoNotifica.RICEVUTA, bd);
    NotificheBD notificheBD = new NotificheBD(bd);
    notificheBD.insertNotifica(notifica);

    bd.commit();
    bd.disableSelectForUpdate();

    ThreadExecutorManager.getClientPoolExecutor().execute(new InviaNotificaThread(notifica, bd));

    ctx.log("rt.acquisizioneOk", versamento.getCodVersamentoEnte(), versamento.getStatoVersamento().toString());
    log.info("RT acquisita con successo.");

    return rpt;
}

From source file:fragment.web.AbstractSubscriptionControllerTest.java

@Test
public void testGetTaxableAmountNegative() {
    try {/*from  ww  w  .j a v  a  2s.co  m*/
        String amount = "-100.00";
        String taxableamount = controller.getTaxableAmount(amount);
        Assert.assertEquals(BigDecimal.ZERO.toString(), taxableamount);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:edu.byu.softwareDist.manager.impl.PurchaseManagerImpl.java

@Override
public PurchaseHelper purchase(PurchaseHelper purchaseHelper) {
    Purchase purchase = new Purchase();
    boolean purchaseCreated = false;
    final PersonInfo personInfo = loadPersonInfo();
    if (purchaseHelper.getFreeItems().size() > 0) {
        LOG.debug("Purchasing free items size=" + purchaseHelper.getFreeItems().size());
        final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses(purchaseHelper.getFreeItems());
        purchase = createPurchase(purchase, personInfo, null);
        purchaseCreated = true;/*from   w ww  .  j  ava 2 s .  c om*/
        purchaseHelper = updatePurchase(purchase, acquireLicensesList, personInfo);
        purchaseDao.update(purchaseHelper.getCheckOutResults().getPurchase());
    }
    if (purchaseHelper.getAccountCodeItems().size() > 0) {
        LOG.debug("Purchasing account code items, size=" + purchaseHelper.getAccountCodeItems().size());
        final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses(
                purchaseHelper.getAccountCodeItems());
        if (!purchaseCreated) {
            purchase = createPurchase(purchase, personInfo, purchaseHelper.getAccountCode());
            purchaseCreated = true;
        } else {
            purchase.setAccountCode(purchaseHelper.getAccountCode());
        }
        final List<AcquireLicenses> success = new LinkedList<AcquireLicenses>();
        for (final AcquireLicenses al : acquireLicensesList) {
            final LineItem lineItem = soaMgr.submitOITOrderRequest(al.getLineItem(),
                    purchaseHelper.getAccountCode(), personInfo);
            al.getLineItem().setOrderId(lineItem.getOrderId());
            success.add(al);
        }
        purchaseHelper = updatePurchase(purchase, success, personInfo);
        purchaseDao.update(purchaseHelper.getCheckOutResults().getPurchase());
    }
    if (purchaseHelper.getCreditCardItems().size() > 0) {
        LOG.debug("Purchasing credit card items, size=" + purchaseHelper.getCreditCardItems().size());
        final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses(
                purchaseHelper.getCreditCardItems());
        final PendingPurchase pendingPurchase = createPendingPurchase(purchase.getPurchaseId(),
                personInfo.getPersonId());
        purchaseHelper.setPendingPurchase(pendingPurchase);
        BigDecimal totalAmount = BigDecimal.ZERO;
        final List<Items> itemTypes = new ArrayList<Items>();
        for (final AcquireLicenses al : acquireLicensesList) {
            final PendingLineItem pendingLineItem = createPendingLineItem(
                    purchaseHelper.getPendingPurchase().getPendingPurchaseId(), al.getLineItem(), CASHNET,
                    null);
            createPendingPurchaseKey(al.getLicenseList(), pendingLineItem.getPendingLineItemId(),
                    al.getLineItem().getQty());
            final BigDecimal quantity = new BigDecimal(al.getLineItem().getQty());
            final BigDecimal costLineItem = al.getLineItem().getTotalPrice().multiply(quantity);
            totalAmount = totalAmount.add(costLineItem);
            itemTypes.add(setItemType(totalAmount, al.getLineItem().getQty()));
        }
        final CheckoutURL checkoutURL = ccpClient.getCheckoutURL(
                createCheckoutURL(personInfo, itemTypes, pendingPurchase.getPendingPurchaseId().toString()));
        purchaseHelper.setCreditCardUrl("redirect:" + checkoutURL.getCompleteURL());
    }
    purchaseHelper.setCheckOutResults(new CheckOutResults(purchase, null));
    try {
        final LicenseCountRunner runner = new LicenseCountRunner(purchaseHelper, licenseCountChecker);
        executor.submit(runner);
    } catch (final Throwable t) {
    }
    return purchaseHelper;
}

From source file:net.shopxx.controller.shop.OrderController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> create(String cartToken, Long receiverId, Long paymentMethodId,
        Long shippingMethodId, String code, String invoiceTitle, BigDecimal balance, String memo) {
    Map<String, Object> data = new HashMap<String, Object>();
    Cart cart = cartService.getCurrent();
    if (cart == null || cart.isEmpty()) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }//  w w w.  j av  a 2 s.c  o  m
    if (!StringUtils.equals(cart.getToken(), cartToken)) {
        data.put("message", Message.warn("shop.order.cartHasChanged"));
        return data;
    }
    if (cart.hasNotMarketable()) {
        data.put("message", Message.warn("shop.order.hasNotMarketable"));
        return data;
    }
    if (cart.getIsLowStock()) {
        data.put("message", Message.warn("shop.order.cartLowStock"));
        return data;
    }
    Member member = memberService.getCurrent();
    Receiver receiver = null;
    ShippingMethod shippingMethod = null;
    PaymentMethod paymentMethod = paymentMethodService.find(paymentMethodId);
    if (cart.getIsDelivery()) {
        receiver = receiverService.find(receiverId);
        if (receiver == null || !member.equals(receiver.getMember())) {
            data.put("message", ERROR_MESSAGE);
            return data;
        }
        shippingMethod = shippingMethodService.find(shippingMethodId);
        if (shippingMethod == null) {
            data.put("message", ERROR_MESSAGE);
            return data;
        }
    }
    CouponCode couponCode = couponCodeService.findByCode(code);
    if (couponCode != null && !cart.isValid(couponCode)) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }
    if (balance != null && balance.compareTo(BigDecimal.ZERO) < 0) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }
    if (balance != null && balance.compareTo(member.getBalance()) > 0) {
        data.put("message", Message.warn("shop.order.insufficientBalance"));
        return data;
    }
    Invoice invoice = StringUtils.isNotEmpty(invoiceTitle) ? new Invoice(invoiceTitle, null) : null;
    Order order = orderService.create(Order.Type.general, cart, receiver, paymentMethod, shippingMethod,
            couponCode, invoice, balance, memo);

    data.put("message", SUCCESS_MESSAGE);
    data.put("sn", order.getSn());
    return data;
}