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:au.com.ish.derbydump.derbydump.main.DumpTest.java

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> setupTestMatrix() throws Exception {
    List<Object[]> result = new ArrayList<Object[]>();

    //testing numbers (BIGINT, DECIMAL, REAL, SMALLINT, INTEGER, DOUBLE)
    {//w  w  w  . j  a  va  2 s  . c  om
        //standard set of numbers
        String[] columns = new String[] { "c1 BIGINT", "c2 DECIMAL(10,2)", "c3 REAL", "c4 SMALLINT",
                "c5 INTEGER", "c6 DOUBLE" };
        Object[] row1 = new Object[] { new BigInteger("12"), new BigDecimal("12.12"), new Float("12.1"),
                Integer.valueOf(12), Integer.valueOf(24), Double.valueOf(12.12) };
        String validOutput1 = "(12,12.12,12.1,12,24,12.12),";
        Object[] row2 = new Object[] { new BigInteger("42"), new BigDecimal("42.12"), new Float("42.14"),
                Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.14) };
        String validOutput2 = "(42,42.12,42.14,42,64,42.14),";
        Object[] row3 = new Object[] { new BigInteger("42"), new BigDecimal("42"), new Float("42"),
                Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42) };
        String validOutput3 = "(42,42.00,42.0,42,64,42.0),";
        Object[] row4 = new Object[] { new BigInteger("42"), new BigDecimal("42.1234"), new Float("42.1434"),
                Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.1234) };
        String validOutput4 = "(42,42.12,42.1434,42,64,42.1234),";
        Object[] row5 = new Object[] { BigDecimal.ZERO, BigDecimal.ZERO, new Float("0"), Integer.valueOf(0),
                Integer.valueOf(0), Double.valueOf(0) };
        String validOutput5 = "(0,0.00,0.0,0,0,0.0),";
        //test nulls
        Object[] row6 = new Object[] { null, null, null, null, null, null };
        String validOutput6 = "(NULL,NULL,NULL,NULL,NULL,NULL);";
        Object[] values = new Object[] { row1, row2, row3, row4, row5, row6 };
        String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4,
                validOutput5, validOutput6 };

        result.add(new Object[] { "testNumbers", null, columns, values, validOutput, false, false });
    }

    //testing strings
    {
        String[] columns = new String[] { "c1 VARCHAR(20)", "c2 VARCHAR(20)", "c3 VARCHAR(20)" };
        //test normal characters
        Object[] row1 = new Object[] { "123", "abc", "" };
        String validOutput1 = "('123','abc',''),";
        //test nulls
        Object[] row2 = new Object[] { "%", null, "" };
        String validOutput2 = "('%',NULL,''),";
        //test quotes and tabs
        Object[] row3 = new Object[] { "'test'", "\"test\"", "\t" };
        String validOutput3 = "('\\'test\\'','\"test\"','\\t'),";
        //test new line chars
        Object[] row4 = new Object[] { "\n", "\r", "\n\r" };
        String validOutput4 = "('\\n','\\r','\\n\\r');";

        Object[] values = new Object[] { row1, row2, row3, row4 };
        String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4 };

        result.add(new Object[] { "testStrings", null, columns, values, validOutput, false, false });
    }

    //testing dates
    {
        String[] columns = new String[] { "c1 TIMESTAMP", "c2 TIMESTAMP" };
        // test standard dates
        Calendar c = Calendar.getInstance(TimeZone.getDefault());
        c.set(Calendar.YEAR, 2013);
        c.set(Calendar.MONTH, 5);
        c.set(Calendar.DAY_OF_MONTH, 6);
        c.set(Calendar.HOUR_OF_DAY, 11);
        c.set(Calendar.MINUTE, 10);
        c.set(Calendar.SECOND, 10);
        c.set(Calendar.MILLISECOND, 11);

        Calendar c2 = (Calendar) c.clone();
        c2.add(Calendar.DATE, -5000);

        Object[] row1 = new Object[] { c.getTime(), c2.getTime() };
        String validOutput1 = "('2013-06-06 11:10:10.011','1999-09-28 11:10:10.011'),";
        Object[] row2 = new Object[] { "2012-07-07 08:54:33", "1999-09-09 10:04:10" };
        String validOutput2 = "('2012-07-07 08:54:33.0','1999-09-09 10:04:10.0'),";
        Object[] row3 = new Object[] { null, null };
        String validOutput3 = "(NULL,NULL);";
        Object[] values = new Object[] { row1, row2, row3 };
        String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3 };

        result.add(new Object[] { "testDates", null, columns, values, validOutput, false, false });
    }

    //testing CLOB
    {
        String[] columns = new String[] { "c1 CLOB" };
        Object[] row1 = new Object[] { "<clob value here>" };
        String validOutput1 = "('<clob value here>'),";
        Object[] row2 = new Object[] { null };
        String validOutput2 = "(NULL);";
        Object[] values = new Object[] { row1, row2 };
        String[] validOutput = new String[] { validOutput1, validOutput2 };

        result.add(new Object[] { "testClob", null, columns, values, validOutput, false, false });
    }

    //testing BLOB
    {
        String[] columns = new String[] { "c1 BLOB" };
        Object[] row1 = new Object[] { getTestImage() };
        Blob serialBlob = new SerialBlob(IOUtils.toByteArray(getTestImage()));
        String validOutput1 = "(" + Column.processBinaryData(serialBlob) + "),";
        Object[] row2 = new Object[] { null };
        String validOutput2 = "(NULL);";
        Object[] values = new Object[] { row1, row2 };
        String[] validOutput = new String[] { validOutput1, validOutput2 };

        result.add(new Object[] { "testBlob", null, columns, values, validOutput, false, false });
    }

    //testing skipping table
    {
        String[] columns = new String[] { "c1 VARCHAR(5)" };
        Object[] row1 = new Object[] { "123" };
        String validOutput1 = "";
        Object[] row2 = new Object[] { null };
        String validOutput2 = "(NULL);";
        Object[] values = new Object[] { row1, row2 };
        String[] validOutput = new String[] { validOutput1, validOutput2 };

        result.add(new Object[] { "testSkip", null, columns, values, validOutput, true, false });
    }

    //testing renaming table
    {
        String[] columns = new String[] { "c1 VARCHAR(5)" };
        Object[] row1 = new Object[] { "123" };
        String validOutput1 = "('123'),";
        Object[] row2 = new Object[] { null };
        String validOutput2 = "(NULL);";
        Object[] values = new Object[] { row1, row2 };
        String[] validOutput = new String[] { validOutput1, validOutput2 };

        result.add(new Object[] { "testRename", "testRenameNew", columns, values, validOutput, false, false });
    }

    //testing empty table
    {
        String[] columns = new String[] { "c1 VARCHAR(5)" };
        Object[] values = new Object[] { new Object[] {} };
        String[] validOutput = new String[] {};

        result.add(new Object[] { "testEmptyTable", null, columns, values, validOutput, true, false });
    }

    //testing truncate table
    {
        String[] columns = new String[] { "c1 VARCHAR(5)" };
        Object[] values = new Object[] { new Object[] {} };
        String[] validOutput = new String[] {};

        result.add(new Object[] { "testTruncateTable", null, columns, values, validOutput, true, true });
    }

    return result;
}

From source file:cz.muni.fi.dndtroops.test.HeroDaoImplTest.java

@Test
public void testFindHero() throws ConnectionException {
    Hero heroG = new Hero();
    heroG.setName("Hero");
    heroG.setLevel(1);/*from   ww  w  . j  ava 2 s . com*/
    heroG.setRole(RoleName.BARD);
    Troop troopG = new Troop();
    troopG.setName("Angels");
    troopG.setMoney(BigDecimal.ZERO);
    troopG.setMission("mise A");
    heroG.setTroop(troopG);

    troopDao.createTroop(troopG);
    heroDao.createHero(heroG);

    Hero h1 = heroDao.findById(heroG.getId());
    Hero h2 = heroDao.findByName("Hero");

    Assert.assertEquals(h1, heroG);
    Assert.assertEquals(h2, heroG);

}

From source file:com.zuora.api.UsageAdjInvoiceRegenerator.java

protected UsageAdjInvoiceRegenerator() throws Exception {

    //MAX_ITEMS_PER_CALL = AppParamManager.MAX_ZOBJECTS_PER_BATCH;

    // Initialize the API Client.
    zApiClient = new ApiClient(AppParamManager.API_URL, AppParamManager.USER_NAME,
            AppParamManager.USER_PASSWORD, AppParamManager.USER_SESSION);

    zApiClient.login();/*from   w w w. jav a2  s .co  m*/
    //Logger.print("logged in");

    /*
    threadDataArray = new ThreadData[AppParamManager.MAX_WORKING_THREADS];
            
    for (int i = 0; i < AppParamManager.MAX_WORKING_THREADS; i++) {
       threadDataArray[i] = new ThreadData(i);
    }
    */

    //int indexOfThreadDataArray = 0;
    int itemsCollectionIndex = 0;
    String savedRPId = "";
    String savedAccountId = "";
    String savedInvoiceId = "";
    String savedPRPCId = "";
    Calendar savedServiceEndDt = null;
    Calendar savedInvoiceDt = null;
    Calendar savedTargetDt = null;

    String savedBaseUOM = null;
    String savedOverUOM = null;
    String basePRPCId = null;

    List<Usage> deleteUOMs = null;

    boolean skipDelete = false;
    /*
    String InvoiceNumberDisplay = "";
    BufferedWriter  writer = new BufferedWriter(
    new FileWriter("C:\\Temp\\output"+output+".txt"));
    */

    //Logger.print("thread initiated, max objects: "+AppParamManager.MAX_ZOBJECTS_PER_BATCH+" Total number of Line Items: "+eInvoiceItemAll.size());
    //String rpcQuery1 = "SELECT Price, base_quantity__c from RatePlanCharge where ProductRatePlanChargeId = '";
    String rpcQuery1 = "SELECT Price from RatePlanCharge where ProductRatePlanChargeId = '";
    String rpcQuery2 = "' and RatePlanId = '";
    //String rpcQuery3 = "' and Base_Quantity__c <> '0'";
    String rpcQuery3 = "'";
    String finalquery = "";
    BigDecimal result = BigDecimal.ZERO;
    BigDecimal amountTotal = BigDecimal.ZERO;
    BigDecimal baseAmount = BigDecimal.ZERO;
    BigDecimal savedQuantity = BigDecimal.ZERO;

    InvoiceItemEntity baseEntity = null;
    InvoiceItemEntity overageEntity = null;

    //Logger.print("Before loop.");

    for (InvoiceItemEntity eInvoiceItem : eUsageItemsValid) {
        Logger.print("in loop0" + eInvoiceItem.getRPId());
        if (!eInvoiceItem.getRPId().equals(savedRPId)) {
            if (itemsCollectionIndex != 0) {
                Logger.print("in if 1");
                if (!skipDelete) {
                    /*
                    //add base usage
                    baseEntity = new InvoiceItemEntity();
                    baseEntity.setAccountId(savedAccountId);
                            
                    finalquery = rpcQuery1 + basePRPCId + rpcQuery2 + savedRPId + rpcQuery3;
                    results = zApiClient.getBaseQuantity(finalquery);
                    baseEntity.setQuantity(results[0]);
                    baseAmount = results[1];
                            
                    baseEntity.setUOM(savedBaseUOM);
                    baseEntity.setServiceEnddt(savedServiceEndDt);   
                    //Logger.print("setting invoice id base: "+savedInvoiceId);
                    baseEntity.setInvoiceId(savedInvoiceId);
                    baseEntity.setTargetDate(savedTargetDt);
                    baseEntity.setInvoicedate(savedInvoiceDt);
                    newUsageCollection.add(baseEntity);
                    */

                    //add overage usage
                    BigDecimal overageQnty = amountTotal.subtract(baseAmount);
                    if (overageQnty.compareTo(BigDecimal.ZERO) > 0) {
                        overageEntity = new InvoiceItemEntity();
                        overageEntity.setAccountId(savedAccountId);
                        Logger.print("setting invoice id over: " + savedInvoiceId);
                        overageEntity.setInvoiceId(savedInvoiceId);

                        overageEntity.setQuantity(overageQnty);

                        overageEntity.setUOM(savedOverUOM);
                        overageEntity.setServiceEnddt(savedServiceEndDt);
                        overageEntity.setTargetDate(savedTargetDt);
                        overageEntity.setInvoicedate(savedInvoiceDt);
                        Logger.print("added to collection, overage: " + overageEntity.getQuantity());
                        newUsageCollection.add(overageEntity);
                    }
                }

                skipDelete = false;
                amountTotal = BigDecimal.ZERO;
                baseAmount = BigDecimal.ZERO;
            }

            savedRPId = eInvoiceItem.getRPId();
            savedPRPCId = eInvoiceItem.getPRPCId();
            savedAccountId = eInvoiceItem.getAccountId();

            if (!eInvoiceItem.getInvoiceId().equals(savedInvoiceId)) {
                Logger.print("getting usage for invoice: " + eInvoiceItem.getInvoiceId());
                deleteUOMs = zApiClient.getUsageForDelete(
                        "select id, uom from usage where invoiceid = '" + eInvoiceItem.getInvoiceId() + "'");
                savedInvoiceId = eInvoiceItem.getInvoiceId();
            }
            savedInvoiceDt = eInvoiceItem.getInvoicedate();
            savedTargetDt = eInvoiceItem.getTargetDate();
            savedServiceEndDt = eInvoiceItem.getServiceEnddt();

            if (eInvoiceItem.getFeeFlag().equals("B")) {
                savedBaseUOM = eInvoiceItem.getUOM();
                basePRPCId = eInvoiceItem.getPRPCId();
            }
            if (eInvoiceItem.getFeeFlag().equals("O")) {
                savedOverUOM = eInvoiceItem.getUOM();
            }
            savedBaseUOM = null;
            savedOverUOM = null;
            savedQuantity = BigDecimal.ZERO;
        }

        Logger.print("In loop1");
        savedRPId = eInvoiceItem.getRPId();
        //Logger.print("In loop2");
        savedPRPCId = eInvoiceItem.getPRPCId();
        //Logger.print("In loop3");
        savedAccountId = eInvoiceItem.getAccountId();
        //Logger.print("In loop4");
        savedInvoiceDt = eInvoiceItem.getInvoicedate();
        //Logger.print("In loop6");
        savedTargetDt = eInvoiceItem.getTargetDate();
        //Logger.print("In loop7");
        savedServiceEndDt = eInvoiceItem.getServiceEnddt();
        //Logger.print("In loop8");

        if (eInvoiceItem.getFeeFlag().equals("B")) {
            Logger.print("setting base UOM");
            basePRPCId = eInvoiceItem.getPRPCId();

            //add base usage
            finalquery = rpcQuery1 + basePRPCId + rpcQuery2 + savedRPId + rpcQuery3;
            result = zApiClient.getBaseQuantity(finalquery);
            Logger.print("setting base UOM");
            Logger.print(
                    "curr line quantity: " + eInvoiceItem.getQuantity() + " base quantity: " + savedQuantity);
            if (result.compareTo(BigDecimal.ZERO) > 0
                    && eInvoiceItem.getQuantity().compareTo(savedQuantity) < 0) {
                //Logger.print("setting invoice id base1: ");
                savedBaseUOM = eInvoiceItem.getUOM();
                //Logger.print("setting invoice id base2: ");
                baseEntity = new InvoiceItemEntity();
                baseEntity.setAccountId(savedAccountId);
                //Logger.print("setting invoice id base3: ");
                //result
                baseEntity.setQuantity(savedQuantity);
                baseAmount = savedQuantity.multiply(result);
                baseEntity.setUOM(savedBaseUOM);
                baseEntity.setServiceEnddt(savedServiceEndDt);
                Logger.print("setting invoice id base: " + savedInvoiceId);
                baseEntity.setInvoiceId(savedInvoiceId);
                baseEntity.setTargetDate(savedTargetDt);
                baseEntity.setInvoicedate(savedInvoiceDt);
                newUsageCollection.add(baseEntity);
            }
        }

        if (eInvoiceItem.getLicenseFlag().equals("True")) {
            savedQuantity = eInvoiceItem.getQuantity();
            Logger.print("within license flag, quantity set to :" + savedQuantity);
        }

        if (eInvoiceItem.getFeeFlag().equals("O")) {
            Logger.print("setting over UOM");
            savedOverUOM = eInvoiceItem.getUOM();
        }
        if (eInvoiceItem.getFeeFlag().equals("") && eInvoiceItem.getLicenseFlag().equals("")) {
            Logger.print("setting usage " + savedBaseUOM);
            if (savedBaseUOM == null) {
                skipDelete = true;
            } else {
                Logger.print("setting usage1");
                amountTotal = amountTotal.add(eInvoiceItem.getAmount());
                Logger.print("setting usage2: " + eInvoiceItem.getInvoiceId() + " saved: " + savedInvoiceId);
                if (!eInvoiceItem.getInvoiceId().equals(savedInvoiceId)) {
                    Logger.print("setting usage3");
                    deleteUOMs = zApiClient.getUsageForDelete("select id, uom from usage where invoiceid = '"
                            + eInvoiceItem.getInvoiceId() + "'");
                    Logger.print("deleted list: " + deleteUOMs.size());
                    savedInvoiceId = eInvoiceItem.getInvoiceId();
                }
                Logger.print("before usage loop" + deleteUOMs.size());
                if (deleteUOMs.size() >= 1 && deleteUOMs.get(0).getUOM() != null) {
                    for (Usage usage : deleteUOMs) {
                        Logger.print("in loop, usage UOM: " + usage.getUOM() + " invoice UOM: "
                                + eInvoiceItem.getUOM());
                        if (usage.getUOM().equals(eInvoiceItem.getUOM())) {
                            deleteList.add(usage.getId());
                            Logger.print("added to delete list: " + usage.getUOM());
                            break;
                        }
                    }
                }
            }

        }
        itemsCollectionIndex++;
        Logger.print("done setting usage");
    }

    if (!skipDelete) {
        /*
        //add base usage
        baseEntity = new InvoiceItemEntity();
        baseEntity.setAccountId(savedAccountId);
        Logger.print("after loop1");
        finalquery = rpcQuery1 + basePRPCId + rpcQuery2 + savedRPId + rpcQuery3;
        results = zApiClient.getBaseQuantity(finalquery);
        baseEntity.setQuantity(results[0]);
        baseAmount = results[1];
        Logger.print("after loop2");
        baseEntity.setUOM(savedBaseUOM);
        baseEntity.setServiceEnddt(savedServiceEndDt);   
        Logger.print("setting invoice id base: "+savedInvoiceId);
        baseEntity.setInvoiceId(savedInvoiceId);
        baseEntity.setTargetDate(savedTargetDt);
        baseEntity.setInvoicedate(savedInvoiceDt);
        newUsageCollection.add(baseEntity);
        Logger.print("after loop3");
        //add overage usage
         */
        BigDecimal overageQnty = amountTotal.subtract(baseAmount);
        if (overageQnty.compareTo(BigDecimal.ZERO) > 0) {
            overageEntity = new InvoiceItemEntity();
            overageEntity.setAccountId(savedAccountId);
            Logger.print("after loop3.1");
            //Logger.print("setting invoice id over: "+savedInvoiceId);
            overageEntity.setInvoiceId(savedInvoiceId);
            //Logger.print("after loop3.2");

            //Logger.print("after loop3.3");
            overageEntity.setQuantity(overageQnty);
            //Logger.print("after loop4");
            overageEntity.setUOM(savedOverUOM);
            //Logger.print("after loop4.1");
            overageEntity.setServiceEnddt(savedServiceEndDt);
            //Logger.print("after loop4.2");
            overageEntity.setTargetDate(savedTargetDt);
            //Logger.print("after loop4.3");
            overageEntity.setInvoicedate(savedInvoiceDt);
            //Logger.print("after loop4.4");
            Logger.print("added to collection, overage: " + overageEntity.getQuantity());
            newUsageCollection.add(overageEntity);
            //Logger.print("after loop5");
        }
        skipDelete = false;
    }
    amountTotal = BigDecimal.ZERO;
    baseAmount = BigDecimal.ZERO;
    //writer.close();

}

From source file:com.roncoo.pay.account.service.impl.RpAccountTransactionServiceImpl.java

/**
 * :?//from  w  w w.  j  a  va  2 s  . com
 * 
 * @param userNo
 *            ?
 * @param amount
 *            ?
 * @param requestNo
 *            ?
 * @param trxType
 *            
 * @param remark
 *            
 */
@Transactional(rollbackFor = Exception.class)
public RpAccount creditToAccount(String userNo, BigDecimal amount, String requestNo, String bankTrxNo,
        String trxType, String remark) {
    RpAccount account = this.getByUserNo_IsPessimist(userNo, true);
    if (account == null) {
        throw AccountBizException.ACCOUNT_NOT_EXIT;
    }

    Date lastModifyDate = account.getEditTime();
    // ??0
    if (!DateUtils.isSameDayWithToday(lastModifyDate)) {
        account.setTodayExpend(BigDecimal.ZERO);
        account.setTodayIncome(BigDecimal.ZERO);
    }

    // 
    if (TrxTypeEnum.EXPENSE.name().equals(trxType)) {// 
        account.setTotalIncome(account.getTotalIncome().add(amount));

        /***** ? *******/
        if (DateUtils.isSameDayWithToday(lastModifyDate)) {
            // ?
            account.setTodayIncome(account.getTodayIncome().add(amount));
        } else {
            // ??
            account.setTodayIncome(amount);
        }
        /************************************/
    }

    String completeSett = PublicEnum.NO.name();
    String isAllowSett = PublicEnum.YES.name();

    /** ? **/
    account.setBalance(account.getBalance().add(amount));
    account.setEditTime(new Date());

    // ?
    RpAccountHistory accountHistoryEntity = new RpAccountHistory();
    accountHistoryEntity.setCreateTime(new Date());
    accountHistoryEntity.setEditTime(new Date());
    accountHistoryEntity.setIsAllowSett(isAllowSett);
    accountHistoryEntity.setAmount(amount);
    accountHistoryEntity.setBalance(account.getBalance());
    accountHistoryEntity.setRequestNo(requestNo);
    accountHistoryEntity.setBankTrxNo(bankTrxNo);
    accountHistoryEntity.setIsCompleteSett(completeSett);
    accountHistoryEntity.setRemark(remark);
    accountHistoryEntity.setFundDirection(AccountFundDirectionEnum.ADD.name());
    accountHistoryEntity.setAccountNo(account.getAccountNo());
    accountHistoryEntity.setTrxType(trxType);
    accountHistoryEntity.setId(StringUtil.get32UUID());
    accountHistoryEntity.setUserNo(userNo);

    this.rpAccountHistoryDao.insert(accountHistoryEntity);
    this.rpAccountDao.update(account);
    LOG.info("??");
    return account;
}

From source file:com.ar.dev.tierra.api.controller.MetodoPagoFacturaController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
@SuppressWarnings("StringEquality")
public ResponseEntity<?> add(OAuth2Authentication authentication, @RequestBody MetodoPagoFactura pagoFactura)
        throws Exception {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    boolean control = true;
    JsonResponse msg = new JsonResponse();
    @SuppressWarnings("UnusedAssignment")
    NotaCredito notaCredito = null;//  w ww  .j a va 2 s .  co  m
    switch (pagoFactura.getPlanPago().getIdPlanesPago()) {
    case 1:
        PlanPago plan = facadeService.getPlanPagoDAO().searchById(1);
        pagoFactura.setPlanPago(plan);
        break;
    case 4:
        PlanPago planNota = facadeService.getPlanPagoDAO().searchById(2);
        notaCredito = facadeService.getNotaCreditoDAO().getByNumero(pagoFactura.getComprobante());
        if (notaCredito != null) {
            if (pagoFactura.getMontoPago().compareTo(notaCredito.getMontoTotal()) == 0) {
                if (notaCredito.getEstadoUso().equals("SIN USO")) {
                    pagoFactura.setPlanPago(planNota);
                } else if (notaCredito.getEstadoUso().equals("CANCELADO")) {
                    msg = new JsonResponse("Error", "Nota de credito cancelada.");
                    control = false;
                } else {
                    msg = new JsonResponse("Error", "Ya ha sido usada la nota de credito.");
                    control = false;
                }
            } else {
                msg = new JsonResponse("Error", "Monto de la nota de credito invalido.");
                control = false;
            }
        } else {
            msg = new JsonResponse("Error", "Nota de credito invalida.");
            control = false;
        }
    }
    if (control) {
        Factura factura = facadeService.getFacturaDAO().searchById(pagoFactura.getFactura().getIdFactura());
        List<MetodoPagoFactura> list = facadeService.getMetodoPagoFacturaDAO()
                .getFacturaMetodo(factura.getIdFactura());
        /*POSIBLE FALLA, DECIMAL INMUTABLE NO SE SUMAN ENTRE SI, NECESITA TEST*/
        BigDecimal totalFactura = BigDecimal.ZERO;
        for (MetodoPagoFactura metodoPagoFactura : list) {
            totalFactura = totalFactura.add(metodoPagoFactura.getMontoPago());
        }
        if (factura.getTotal().longValue() > totalFactura.longValue()) {
            pagoFactura.setUsuarioCreacion(user.getIdUsuario());
            pagoFactura.setFechaCreacion(new Date());
            pagoFactura.setEstado(true);
            if (notaCredito != null) {
                notaCredito.setFacturaUso(pagoFactura.getFactura().getIdFactura());
                notaCredito.setEstadoUso("USADO");
                facadeService.getNotaCreditoDAO().update(notaCredito);
            }
            facadeService.getMetodoPagoFacturaDAO().add(pagoFactura);
            msg = new JsonResponse("Success", "Metodo de pago agregado con exito");
            return new ResponseEntity<>(msg, HttpStatus.OK);
        } else {
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
    } else {
        return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST);
    }
}

From source file:com.haulmont.timesheets.service.StatisticServiceBean.java

@Override
public Map<Integer, Map<String, Object>> getStatisticsByProjects(Date start, Date end) {
    LoadContext<TimeEntry> loadContext = new LoadContext<>(TimeEntry.class)
            .setQuery(new LoadContext.Query(
                    "select t from ts$TimeEntry t where t.date >= :start and t.date <= :end order by t.date")
                            .setParameter("start", start).setParameter("end", end))
            .setView(new View(TimeEntry.class)
                    .addProperty("task",
                            new View(Task.class).addProperty("name").addProperty("project",
                                    viewRepository.getView(Project.class, View.MINIMAL)))
                    .addProperty("timeInMinutes").addProperty("date"));
    List<TimeEntry> timeEntries = dataManager.loadList(loadContext);

    Map<WeekAndProject, BigDecimal> statistic = new LinkedHashMap<>();
    Calendar calendar = Calendar.getInstance();
    for (TimeEntry timeEntry : timeEntries) {
        calendar.setTime(timeEntry.getDate());
        int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
        WeekAndProject key = new WeekAndProject(weekOfYear, timeEntry.getTask().getProject());

        BigDecimal sum = statistic.get(key);
        if (sum == null) {
            sum = BigDecimal.ZERO;
        }//w  w w  . j a  v  a 2 s. c  o  m

        sum = sum.add(HoursAndMinutes.fromTimeEntry(timeEntry).toBigDecimal());
        statistic.put(key, sum);
    }

    Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
    for (Map.Entry<WeekAndProject, BigDecimal> entry : statistic.entrySet()) {
        Integer week = entry.getKey().week;
        Map<String, Object> projectsByWeek = result.get(week);
        if (projectsByWeek == null) {
            projectsByWeek = new HashMap<>();
            calendar.set(Calendar.WEEK_OF_YEAR, week);
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            projectsByWeek.put("week", DateTimeUtils.getDateFormat().format(calendar.getTime()));

        }
        projectsByWeek.put(entry.getKey().project.getName(), entry.getValue());
        result.put(week, projectsByWeek);
    }

    return result;
}

From source file:pe.gob.mef.gescon.web.ui.PoliticaMB.java

public void cleanAttributes() {
    this.setId(BigDecimal.ZERO);
    this.setModuloid(null);
    this.setDescripcion(StringUtils.EMPTY);
    this.setNombre(StringUtils.EMPTY);
    this.setActivo(BigDecimal.ONE);
    this.setSelectedPolitica(null);
    Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
    if (iter.hasNext() == true) {
        iter.remove();//from  w  ww  .  ja  va  2 s . com
        FacesContext.getCurrentInstance().renderResponse();
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java

private static String getRemainingCreditsInfo(final ICurriculum curriculum) {
    final BigDecimal remainingCredits = curriculum.getRemainingCredits();

    final StringBuilder result = new StringBuilder();
    if (remainingCredits != BigDecimal.ZERO) {
        result.append(LINE_BREAK);//from   w w  w.j a  v  a2s . c om

        final String remainingCreditsInfo = BundleUtil.getString(Bundle.ACADEMIC,
                "documents.remainingCreditsInfo");
        result.append(remainingCreditsInfo + ":" + remainingCredits);

        result.append(LINE_BREAK);
    }

    return result.toString();
}

From source file:cz.muni.fi.dndtroops.test.TroopDaoImplTest.java

@Test
public void testFindTroopById() {
    Troop troopD = new Troop();
    troopD.setName("Devils");
    troopD.setMoney(BigDecimal.ZERO);
    troopD.setMission("mise D");
    troopDao.createTroop(troopD);// w ww .  j  a  va  2s  .  c o  m
    Troop t1 = troopDao.findTroopById(troopD.getId());

    Assert.assertEquals(t1.getName(), "Devils");
    Assert.assertEquals(t1.getMission(), "mise D");

}

From source file:mx.edu.um.mateo.rh.dao.EmpleadoDaoTest.java

/**
 * Test of obtiene method, of class EmpleadoDao.
 */// w  w  w. ja v  a2  s  .c o m
@Test
public void debieraObtenerEmpleado() {
    log.debug("Debiera obtener empleado");
    Organizacion organizacion = new Organizacion("tst-01", "test-01", "test-01");
    currentSession().save(organizacion);
    Empresa empresa = new Empresa("tst-01", "test-01", "test-01", "000000000001", organizacion);
    currentSession().save(empresa);
    Empleado empleado = new Empleado("test001", "test", "test", "test", "M", "address", "A", "curp", "rfc",
            "cuenta", "imss", 10, 100, BigDecimal.ZERO, "mo", "ife", "ra", Boolean.TRUE, "padre", "madre", "Ca",
            "Conyugue", Boolean.TRUE, Boolean.TRUE, "iglesia", "responsabilidad", empresa);
    instance.graba(empleado);
    Long id = empleado.getId();
    Empleado result = instance.obtiene(id);
    assertEquals("test", result.getNombre());
}