Example usage for java.math BigDecimal ROUND_HALF_EVEN

List of usage examples for java.math BigDecimal ROUND_HALF_EVEN

Introduction

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

Prototype

int ROUND_HALF_EVEN

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

Click Source Link

Document

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

Usage

From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java

private BigDecimal calculateMultipleRatesDifferences(BigDecimal _amount, String currencyIDFrom,
        String currencyIDTo, DocLine line, ConnectionProvider conn) {
    // _amount * ((TrxRate *
    // AccountingRateCurrencyFromCurrencyTo)-AccountingRateCurrencyDocCurrencyTo)
    String conversionDate = DateAcct;
    String strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
            .getProperty("dateFormat.java");
    final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat);
    // Calculate accountingRateCurrencyFromCurrencyTo
    BigDecimal accountingRateCurrencyFromCurrencyTo = BigDecimal.ONE;
    if (!currencyIDFrom.equals(currencyIDTo)) {
        ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID,
                currencyIDFrom, currencyIDTo);
        if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
                && line instanceof DocLine_FINReconciliation) {
            String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
            FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
                    transactionID);//from  w w  w  .j  ava  2s  . co  m
            conversionDate = dateFormat.format(transaction.getDateAcct());
            conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
                    currencyIDFrom, currencyIDTo);
        }
        if (conversionRateCurrentDoc != null) {
            accountingRateCurrencyFromCurrencyTo = conversionRateCurrentDoc.getRate();
        } else {
            // I try to find a reversal rate for the doc, if exists i apply it reversal as well
            if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
                    && line instanceof DocLine_FINReconciliation) {
                String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
                FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
                        transactionID);
                conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
                        currencyIDTo, currencyIDFrom);
            } else {
                conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo,
                        currencyIDFrom);
            }
            if (conversionRateCurrentDoc != null) {
                accountingRateCurrencyFromCurrencyTo = BigDecimal.ONE.divide(conversionRateCurrentDoc.getRate(),
                        MathContext.DECIMAL64);
            } else {
                accountingRateCurrencyFromCurrencyTo = getConvertionRate(currencyIDFrom, currencyIDTo,
                        conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
            }
        }
    }

    // Calculate accountingRateCurrencyFromCurrencyTo
    BigDecimal accountingRateCurrencyDocCurrencyTo = BigDecimal.ONE;
    if (!C_Currency_ID.equals(currencyIDTo)) {
        ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, C_Currency_ID,
                currencyIDTo);
        if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
                && line instanceof DocLine_FINReconciliation) {
            String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
            FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
                    transactionID);
            conversionDate = dateFormat.format(transaction.getTransactionDate());
            conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
                    C_Currency_ID, currencyIDTo);
        }
        if (conversionRateCurrentDoc != null) {
            accountingRateCurrencyDocCurrencyTo = conversionRateCurrentDoc.getRate();
        } else {
            // I try to find a reversal rate for the doc, if exists i apply it reversal as well
            if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
                    && line instanceof DocLine_FINReconciliation) {
                String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
                FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
                        transactionID);
                conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
                        currencyIDTo, C_Currency_ID);
            } else {
                conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo,
                        C_Currency_ID);
            }
            if (conversionRateCurrentDoc != null) {
                accountingRateCurrencyDocCurrencyTo = BigDecimal.ONE.divide(conversionRateCurrentDoc.getRate(),
                        MathContext.DECIMAL64);
            } else {
                accountingRateCurrencyDocCurrencyTo = getConvertionRate(C_Currency_ID, currencyIDTo,
                        conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
            }
        }
    }
    // Calculate transaction rate
    BigDecimal trxRate = BigDecimal.ONE;
    if (!C_Currency_ID.equals(currencyIDFrom)) {
        if (AD_Table_ID.equals(TABLEID_Payment)) {
            FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, Record_ID);
            trxRate = payment.getFinancialTransactionConvertRate();
        } else if (AD_Table_ID.equals(TABLEID_Transaction) || AD_Table_ID.equals(TABLEID_Reconciliation)) {
            String transactionID = Record_ID;
            // When TableID = Reconciliation info is loaded from transaction
            if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
                    && line instanceof DocLine_FINReconciliation) {
                transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
            }
            FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
                    transactionID);
            trxRate = transaction.getForeignConversionRate();
        }
    }
    Currency currencyFrom = OBDal.getInstance().get(Currency.class, currencyIDTo);
    return _amount
            .multiply(trxRate.multiply(accountingRateCurrencyDocCurrencyTo)
                    .subtract(accountingRateCurrencyFromCurrencyTo))
            .setScale(currencyFrom.getStandardPrecision().intValue(), BigDecimal.ROUND_HALF_EVEN);
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String cancelOfferProduct(HttpServletRequest req) {
    String val = "";
    double remain;

    db.getJdbc().execute("delete from market_product where id='" + req.getParameter("id") + "'");

    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage=(select id from storage where [user]='"
                    + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone")
                    + "') and desc_product.id=storage_product.[desc] and product=name"),
            srs2;// ww w .  ja  va 2s .c om

    srs1 = db.getJdbc().queryForRowSet(
            "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage=(select id from storage where [user]='"
                    + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone")
                    + "') and desc_product.id=storage_product.[desc] and product=name");
    ArrayList<StorageProduct> storageProducts = new ArrayList<StorageProduct>();
    ArrayList<MarketProduct> marketProducts = new ArrayList<MarketProduct>();
    while (srs1.next()) {
        remain = srs1.getDouble("size");
        srs2 = db.getJdbc().queryForRowSet(
                "select market_product.id,product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product,storage_product where storage_product_id='"
                        + srs1.getString("id")
                        + "' and storage_product_id=storage_product.id and desc_product.id=storage_product.[desc] and product=name");
        while (srs2.next()) {
            remain -= srs2.getDouble("size");
            marketProducts.add(new MarketProduct(srs2.getString("id"), "", srs2.getString("product"),
                    srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("size"),
                    srs2.getString("draw")));
        }
        if (remain > 0)
            storageProducts
                    .add(new StorageProduct(srs1.getString("id"), srs1.getString("product"),
                            srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain))
                                    .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(),
                            srs1.getString("draw")));
    }

    //      ArrayList<StorageProduct> products = new ArrayList<StorageProduct>();
    //      while(srs1.next()){
    //         remain = srs1.getDouble("size");
    //         srs2 = db.getJdbc().queryForRowSet("select size from market_product where storage_product_id='"+srs1.getString("id")+"'");
    //         while(srs2.next()){
    //            remain -= srs2.getDouble("size");
    //         }
    //         if(remain > 0)
    //            products.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs2.getString("draw")));
    //      }
    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(storageProducts));
    data.add(gson.toJson(marketProducts));
    val = gson.toJson(data);

    data = null;
    marketProducts = null;
    storageProducts = null;
    srs1 = null;
    srs2 = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

/**
 * Calculate the installment's details. More likely, a ratio of equipment, employee, input and
 * output provided in one installment.// www. j ava 2  s.  c  om
 * 
 * @param idInstallment The id of an installment being called.
 * @return List of information regarding the details of an installment. The output will come as
 * follow : (0) type installment, (1) calculated efficiency, (2) calculated effectivity,
 * (3) list of input, (4) list of input ratio, (5) list of output, (6) list of output ratio, 
 * (7) whether the installment is active/inactive state.
 * 
 */
private ArrayList<String> calculateInstallmentAndIOByIdInstallment(String idInstallment) {
    String hiElement = "";
    double hiVal = 0, efficiency = 0, effectivity = 0;
    int eff;
    SqlRowSet srs1 = db.getJdbc()
            .queryForRowSet("select type,active from installment where id='" + idInstallment + "'"), srs2, srs3;
    HashMap<String, Double> elementsRatio = new HashMap<String, Double>(),
            elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>();
    ArrayList<String> data = new ArrayList<String>(), input = new ArrayList<String>(),
            output = new ArrayList<String>();
    ArrayList<Double> inputVal = new ArrayList<Double>(), outputVal = new ArrayList<Double>();
    boolean pass = false;

    if (srs1.next()) {
        hiElement = "";
        hiVal = 0;
        elementsRatio.clear();
        elements.clear();
        elementsCalc.clear();
        pass = true;

        srs2 = db.getJdbc()
                .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='"
                        + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("equipment_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='"
                            + idInstallment + "' and desc_equipment.equipment='"
                            + srs2.getString("equipment_type")
                            + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id");
            srs3.next();
            elements.put(srs2.getString("equipment_type"), srs3.getDouble(1));
        }

        srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='"
                + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("employee_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='"
                            + idInstallment + "' and desc_employee.employee='" + srs2.getString("employee_type")
                            + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id");
            srs3.next();
            elements.put(srs2.getString("employee_type"), srs3.getDouble(1));
        }

        //calculating:
        while (true) {
            for (String element : elementsRatio.keySet()) {
                if (element.equals(hiElement)) {
                    elementsCalc.put(element, elements.get(element));
                } else {
                    elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement))
                            / elementsRatio.get(hiElement));
                }
            }

            for (String element : elements.keySet()) {
                if (elements.get(element) < elementsCalc.get(element)) {
                    pass = false;
                    hiElement = element;
                    hiVal = elements.get(element);
                    break;
                } else {
                    pass = true;
                }
            }
            if (pass) {
                eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue();
                if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) {
                    hiVal = (elementsRatio.get(hiElement) * (eff + 1));
                    if (hiVal > 0)
                        efficiency = new BigDecimal(Double.valueOf(
                                elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1))))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        efficiency = 0;
                    effectivity = eff + 1;
                } else {
                    hiVal = (elementsRatio.get(hiElement) * eff);
                    if (hiVal > 0)
                        efficiency = new BigDecimal(Double
                                .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff)))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        efficiency = 0;
                    effectivity = eff;
                }
                srs2 = db.getJdbc()
                        .queryForRowSet("select input_type,size from info_sector_input where sector='"
                                + srs1.getString("type") + "'");
                while (srs2.next()) {
                    input.add(srs2.getString("input_type"));
                    inputVal.add(
                            new BigDecimal(Double.valueOf(srs2.getDouble("size") * effectivity * efficiency))
                                    .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                }
                srs2 = db.getJdbc()
                        .queryForRowSet("select output_type,size from info_sector_output where sector='"
                                + srs1.getString("type") + "'");
                while (srs2.next()) {
                    output.add(srs2.getString("output_type"));
                    outputVal.add(
                            new BigDecimal(Double.valueOf(srs2.getDouble("size") * effectivity * efficiency))
                                    .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                }
                break;
            }
        }
    }
    data.add(srs1.getString("type"));
    data.add(gson.toJson(efficiency));
    data.add(gson.toJson(effectivity));
    data.add(gson.toJson(input));
    data.add(gson.toJson(inputVal));
    data.add(gson.toJson(output));
    data.add(gson.toJson(outputVal));
    data.add(gson.toJson(srs1.getBoolean("active")));

    input = null;
    inputVal = null;
    output = null;
    outputVal = null;
    srs1 = null;
    srs2 = null;
    srs3 = null;

    gc();

    return data;
}

From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java

public void bucheTOPSArtikelAufHauptLager(Integer losIId, TheClientDto theClientDto,
        BigDecimal zuzubuchendeSatzgroesse) {
    LossollmaterialDto[] dtos = lossollmaterialFindByLosIId(losIId);
    try {/*w w w  .  j a  v a2  s  . co m*/
        Integer hauptlagerIId = getLagerFac().getHauptlagerDesMandanten(theClientDto).getIId();

        LosDto losDto = losFindByPrimaryKey(losIId);

        for (int i = 0; i < dtos.length; i++) {
            Integer artklaIId = null;

            ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKeySmall(dtos[i].getArtikelIId(),
                    theClientDto);
            artklaIId = artikelDto.getArtklaIId();

            if (artklaIId != null) {
                boolean bTops = Helper.short2boolean(
                        getArtikelFac().artklaFindByPrimaryKey(artklaIId, theClientDto).getBTops());

                if (bTops == true) {

                    BigDecimal sollsatzgroesse = dtos[i].getNMenge().divide(losDto.getNLosgroesse(), 4,
                            BigDecimal.ROUND_HALF_EVEN);
                    BigDecimal zuzubuchendeMenge = null;

                    if (zuzubuchendeSatzgroesse == null) {
                        zuzubuchendeMenge = dtos[i].getNMenge()
                                .subtract(getAusgegebeneMenge(dtos[i].getIId(), null, theClientDto));
                    } else {
                        zuzubuchendeMenge = sollsatzgroesse.multiply(zuzubuchendeSatzgroesse);
                    }

                    if (zuzubuchendeMenge.doubleValue() > 0) {

                        HandlagerbewegungDto handDto = new HandlagerbewegungDto();
                        handDto.setArtikelIId(dtos[i].getArtikelIId());
                        handDto.setNMenge(zuzubuchendeMenge);
                        handDto.setBAbgang(Helper.boolean2Short(false));
                        handDto.setCKommentar("TOPS " + losDto.getCNr());
                        handDto.setLagerIId(hauptlagerIId);
                        handDto.setNEinstandspreis(getLagerFac().getGemittelterGestehungspreisDesHauptlagers(
                                dtos[i].getArtikelIId(), theClientDto));
                        getLagerFac().createHandlagerbewegung(handDto, theClientDto);
                        // CK:13872
                        // Dann aufs Los buchen

                        LosistmaterialDto istmat = new LosistmaterialDto();
                        istmat.setLagerIId(hauptlagerIId);
                        istmat.setLossollmaterialIId(dtos[i].getIId());
                        istmat.setNMenge(zuzubuchendeMenge);
                        istmat.setBAbgang(Helper.boolean2Short(true));
                        // ist-wert anlegen und lagerbuchung
                        // durchfuehren
                        createLosistmaterial(istmat, null, theClientDto);

                        // Reservierung loeschen
                        removeReservierung(artikelDto, dtos[i].getIId());
                        // Fehlmenge anlegen
                        getFehlmengeFac().aktualisiereFehlmenge(LocaleFac.BELEGART_LOS, dtos[i].getIId(), false,
                                theClientDto);

                    }
                }
            }
        }
    } catch (RemoteException ex) {
        throwEJBExceptionLPRespectOld(ex);
    }
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

/**
 * Getting all user's installments, regardless of its type (or sector, in specifically)..
 * @param user/*from  www .  j a  v  a 2  s .  c  o  m*/
 * @return list of installment in ArrayList<Installment>
 */
private ArrayList<Installment> getUserInstallments(String user) {
    String hiElement = "";

    double hiVal = 0, tmpd1, tmpd2;
    int eff;
    SqlRowSet srs1 = db.getJdbc()
            .queryForRowSet("select id,[zone],type,draw,active from installment,info_sector where [user]='"
                    + user + "' and [zone]=(select [zone] from businessgame.dbo.[user] where name='" + user
                    + "') and name=type"),
            srs2, srs3;
    HashMap<String, Double> elementsRatio = new HashMap<String, Double>(),
            elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>();
    ArrayList<Installment> installments = new ArrayList<Installment>();
    boolean pass = false;

    while (srs1.next()) {
        hiElement = "";
        hiVal = 0;
        elementsRatio.clear();
        elements.clear();
        elementsCalc.clear();
        pass = true;

        srs2 = db.getJdbc()
                .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='"
                        + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("equipment_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='"
                            + srs1.getString("id") + "' and desc_equipment.equipment='"
                            + srs2.getString("equipment_type")
                            + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id");
            srs3.next();
            elements.put(srs2.getString("equipment_type"), srs3.getDouble(1));
        }

        srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='"
                + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("employee_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='"
                            + srs1.getString("id") + "' and desc_employee.employee='"
                            + srs2.getString("employee_type")
                            + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id");
            srs3.next();
            elements.put(srs2.getString("employee_type"), srs3.getDouble(1));
        }

        //calculating:
        while (true) {
            for (String element : elementsRatio.keySet()) {
                if (element.equals(hiElement)) {
                    elementsCalc.put(element, elements.get(element));
                } else {
                    elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement))
                            / elementsRatio.get(hiElement));
                }
            }

            for (String element : elements.keySet()) {
                if (elements.get(element) < elementsCalc.get(element)) {
                    pass = false;
                    hiElement = element;
                    hiVal = elements.get(element);
                    break;
                } else {
                    pass = true;
                }
            }
            if (pass) {
                eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue();
                if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) {
                    hiVal = (elementsRatio.get(hiElement) * (eff + 1));
                    if (hiVal > 0)
                        tmpd1 = new BigDecimal(Double.valueOf(
                                elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1))))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        tmpd1 = 0;
                    tmpd2 = eff + 1;
                } else {
                    hiVal = (elementsRatio.get(hiElement) * eff);
                    if (hiVal > 0)
                        tmpd1 = new BigDecimal(Double
                                .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff)))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        tmpd1 = 0;
                    tmpd2 = eff;
                }
                installments.add(
                        new Installment(srs1.getString("id"), srs1.getString("type"), srs1.getString("zone"),
                                tmpd1, tmpd2, srs1.getString("draw"), srs1.getBoolean("active")));
                break;
            }
        }
    }

    hiElement = null;
    srs1 = null;
    srs2 = null;
    srs3 = null;
    elements = null;
    elementsCalc = null;
    elementsRatio = null;

    gc();

    return installments;
}

From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public HashMap<Integer, StuecklistepositionDto> holeAlleLossollmaterialFuerStuecklistenAktualisierung(
        Integer stuecklisteIId, BigDecimal bdLosgroesse, int iEbene,
        HashMap<Integer, StuecklistepositionDto> hmPositionen, TheClientDto theClientDto) {
    iEbene++;//from www.ja v a  2  s. com

    if (hmPositionen == null) {
        hmPositionen = new HashMap<Integer, StuecklistepositionDto>();
    }
    try {
        StuecklistepositionDto[] stkPos = getStuecklisteFac()
                .stuecklistepositionFindByStuecklisteIId(stuecklisteIId, theClientDto);

        StuecklisteDto stklDto = getStuecklisteFac().stuecklisteFindByPrimaryKey(stuecklisteIId, theClientDto);

        for (int i = 0; i < stkPos.length; i++) {
            // alle stuecklistenpositionen ins los uebernehmen

            // W02451
            if (stkPos[i].getArtikelIId() == 6093) {
                int u = 0;
            }

            // Einheit umrechnen
            ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKeySmall(stkPos[i].getArtikelIId(),
                    theClientDto);

            BigDecimal bdFaktor = getSystemFac().rechneUmInAndereEinheit(new BigDecimal(1),
                    stkPos[i].getEinheitCNr(), artikelDto.getEinheitCNr(), stkPos[i].getIId(), theClientDto);

            // nun die Dimensionen
            BigDecimal bdDimProdukt = new BigDecimal(1);
            EinheitDto einheitDto = getSystemFac().einheitFindByPrimaryKey(stkPos[i].getEinheitCNr(),
                    theClientDto);
            if (einheitDto.getIDimension().intValue() >= 1) {
                if (stkPos[i].getFDimension1() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension1().floatValue()));
                }
            }
            if (einheitDto.getIDimension().intValue() >= 2) {
                if (stkPos[i].getFDimension2() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension2().floatValue()));
                }
            }
            if (einheitDto.getIDimension().intValue() >= 3) {
                if (stkPos[i].getFDimension3() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension3().floatValue()));
                }
            }
            // verschnitt
            BigDecimal bdMenge = Helper.berechneMengeInklusiveVerschnitt(stkPos[i].getNMenge(),
                    artikelDto.getFVerschnittfaktor(), artikelDto.getFVerschnittbasis(), bdLosgroesse);

            // endgueltige Menge berechnen
            BigDecimal posMenge = bdMenge.multiply(bdDimProdukt).multiply(bdLosgroesse).multiply(bdFaktor)
                    .divide(new BigDecimal(stklDto.getIErfassungsfaktor().doubleValue()),
                            BigDecimal.ROUND_HALF_EVEN);

            if (posMenge.doubleValue() < 0.001 && posMenge.doubleValue() > 0.000001) {
                posMenge = new BigDecimal("0.001");
                posMenge = posMenge.setScale(3, BigDecimal.ROUND_HALF_EVEN);
            } else {
                posMenge = posMenge.setScale(3, BigDecimal.ROUND_HALF_EVEN);
            }

            stkPos[i].setNMenge(posMenge);

            StuecklisteDto stuecklisteDto = getStuecklisteFac()
                    .stuecklisteFindByMandantCNrArtikelIIdOhneExc(stkPos[i].getArtikelIId(), theClientDto);

            if (stuecklisteDto != null && stuecklisteDto.getStuecklisteartCNr()
                    .equals(StuecklisteFac.STUECKLISTEART_HILFSSTUECKLISTE)) {
                if (iEbene < 10) {
                    holeAlleLossollmaterialFuerStuecklistenAktualisierung(stuecklisteDto.getIId(), posMenge,
                            iEbene, hmPositionen, theClientDto);
                }

            } else {

                if (stkPos[i].getNMenge().doubleValue() > 0) {

                    if (hmPositionen.containsKey(stkPos[i].getArtikelIId())) {

                        StuecklistepositionDto p = hmPositionen.get(stkPos[i].getArtikelIId());
                        p.setNMenge(stkPos[i].getNMenge().add(p.getNMenge()));
                        hmPositionen.put(stkPos[i].getArtikelIId(), p);
                    } else {
                        hmPositionen.put(stkPos[i].getArtikelIId(), stkPos[i]);
                    }
                }

            }
        }
    } catch (RemoteException ex1) {
        throwEJBExceptionLPRespectOld(ex1);
    }

    return hmPositionen;

}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

private Installment getSingleUserInstallments(String id) {
    String hiElement = "";

    double hiVal = 0, tmpd1, tmpd2;
    int eff;/*w w  w .  j  a  v  a 2s .  co m*/
    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select [zone],type,draw,active from installment,info_sector where id='" + id + "' and name=type"),
            srs2, srs3;
    HashMap<String, Double> elementsRatio = new HashMap<String, Double>(),
            elements = new HashMap<String, Double>(), elementsCalc = new HashMap<String, Double>();
    Installment installment = null;
    boolean pass = false;

    if (srs1.next()) {
        hiElement = "";
        hiVal = 0;
        elementsRatio.clear();
        elements.clear();
        elementsCalc.clear();
        pass = true;

        srs2 = db.getJdbc()
                .queryForRowSet("select equipment_type,items from info_sector_equipment where sector='"
                        + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("equipment_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("equipment_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_equipment.id) from installment_equipment,list_equipment,desc_equipment where installment='"
                            + id + "' and desc_equipment.equipment='" + srs2.getString("equipment_type")
                            + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id");
            srs3.next();
            elements.put(srs2.getString("equipment_type"), srs3.getDouble(1));
        }

        srs2 = db.getJdbc().queryForRowSet("select employee_type,items from info_sector_employee where sector='"
                + srs1.getString("type") + "'");
        while (srs2.next()) {
            elementsRatio.put(srs2.getString("employee_type"), srs2.getDouble("items"));
            if (hiVal < srs2.getDouble("items")) {
                hiElement = srs2.getString("employee_type");
                hiVal = srs2.getDouble("items");
            }
            srs3 = db.getJdbc().queryForRowSet(
                    "select count(installment_employee.id) from installment_employee,list_employee,desc_employee where installment='"
                            + id + "' and desc_employee.employee='" + srs2.getString("employee_type")
                            + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id");
            srs3.next();
            elements.put(srs2.getString("employee_type"), srs3.getDouble(1));
        }

        //calculating:
        while (true) {
            for (String element : elementsRatio.keySet()) {
                if (element.equals(hiElement)) {
                    elementsCalc.put(element, elements.get(element));
                } else {
                    elementsCalc.put(element, (elementsRatio.get(element) * elements.get(hiElement))
                            / elementsRatio.get(hiElement));
                }
            }

            for (String element : elements.keySet()) {
                if (elements.get(element) < elementsCalc.get(element)) {
                    pass = false;
                    hiElement = element;
                    hiVal = elements.get(element);
                    break;
                } else {
                    pass = true;
                }
            }
            if (pass) {
                eff = elements.get(hiElement).intValue() / elementsRatio.get(hiElement).intValue();
                if (elements.get(hiElement) % elementsRatio.get(hiElement) > 0) {
                    hiVal = (elementsRatio.get(hiElement) * (eff + 1));
                    if (hiVal > 0)
                        tmpd1 = new BigDecimal(Double.valueOf(
                                elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * (eff + 1))))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        tmpd1 = 0;
                    tmpd2 = eff + 1;
                } else {
                    hiVal = (elementsRatio.get(hiElement) * eff);
                    if (hiVal > 0)
                        tmpd1 = new BigDecimal(Double
                                .valueOf(elementsCalc.get(hiElement) / (elementsRatio.get(hiElement) * eff)))
                                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    else
                        tmpd1 = 0;
                    tmpd2 = eff;
                }
                installment = new Installment(id, srs1.getString("type"), srs1.getString("zone"), tmpd1, tmpd2,
                        srs1.getString("draw"), srs1.getBoolean("active"));
                break;
            }
        }
    }

    hiElement = null;
    srs1 = null;
    srs2 = null;
    srs3 = null;
    elements = null;
    elementsCalc = null;
    elementsRatio = null;

    gc();

    return installment;
}

From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java

private void erstelleLossollmaterial(Integer losIId, Integer stuecklisteIId, BigDecimal bdPositionsMenge,
        Integer lagerIId_Hauptlager, boolean bFlachdruecken, int iEbene, TheClientDto theClientDto) {
    iEbene++;//from  ww w.j  a va  2s .co m
    try {
        StuecklistepositionDto[] stkPos = getStuecklisteFac()
                .stuecklistepositionFindByStuecklisteIId(stuecklisteIId, theClientDto);

        StuecklisteDto stklDto = getStuecklisteFac().stuecklisteFindByPrimaryKey(stuecklisteIId, theClientDto);

        for (int i = 0; i < stkPos.length; i++) {
            // alle stuecklistenpositionen ins los uebernehmen

            LossollmaterialDto losMatDto = new LossollmaterialDto();
            losMatDto.setArtikelIId(stkPos[i].getArtikelIId());
            losMatDto.setBNachtraeglich(Helper.boolean2Short(false));
            losMatDto.setCKommentar(stkPos[i].getCKommentar());
            losMatDto.setCPosition(stkPos[i].getCPosition());
            losMatDto.setFDimension1(stkPos[i].getFDimension1());
            losMatDto.setFDimension2(stkPos[i].getFDimension2());
            losMatDto.setFDimension3(stkPos[i].getFDimension3());
            losMatDto.setILfdnummer(stkPos[i].getILfdnummer());
            losMatDto.setIBeginnterminoffset(stkPos[i].getIBeginnterminoffset());
            losMatDto.setISort(stkPos[i].getISort());
            losMatDto.setLosIId(losIId);
            losMatDto.setMontageartIId(stkPos[i].getMontageartIId());
            // Einheit umrechnen
            ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKey(stkPos[i].getArtikelIId(),
                    theClientDto);
            losMatDto.setEinheitCNr(artikelDto.getEinheitCNr());
            BigDecimal bdFaktor = getSystemFac().rechneUmInAndereEinheit(new BigDecimal(1),
                    artikelDto.getEinheitCNr(), stkPos[i].getEinheitCNr(), stkPos[i].getIId(), theClientDto);

            // nun die Dimensionen
            BigDecimal bdDimProdukt = new BigDecimal(1);
            EinheitDto einheitDto = getSystemFac().einheitFindByPrimaryKey(stkPos[i].getEinheitCNr(),
                    theClientDto);
            if (einheitDto.getIDimension().intValue() >= 1) {
                if (stkPos[i].getFDimension1() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension1().floatValue()));
                }
            }
            if (einheitDto.getIDimension().intValue() >= 2) {
                if (stkPos[i].getFDimension2() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension2().floatValue()));
                }
            }
            if (einheitDto.getIDimension().intValue() >= 3) {
                if (stkPos[i].getFDimension3() != null) {
                    bdDimProdukt = bdDimProdukt
                            .multiply(new BigDecimal(stkPos[i].getFDimension3().floatValue()));
                }
            }
            // verschnitt
            BigDecimal bdMenge = Helper.berechneMengeInklusiveVerschnitt(stkPos[i].getNMenge(),
                    artikelDto.getFVerschnittfaktor(), artikelDto.getFVerschnittbasis(), bdPositionsMenge);

            // endgueltige Menge berechnen
            if (bdFaktor.doubleValue() != 0) {

                bdMenge = bdMenge.divide(bdFaktor, BigDecimal.ROUND_HALF_EVEN);

                BigDecimal losSollMenge = bdMenge.multiply(bdDimProdukt).multiply(bdPositionsMenge).divide(
                        new BigDecimal(stklDto.getIErfassungsfaktor().doubleValue()),
                        BigDecimal.ROUND_HALF_EVEN);

                if (losSollMenge.doubleValue() < 0.001 && losSollMenge.doubleValue() > 0.000001) {
                    losSollMenge = new BigDecimal("0.001");
                    losSollMenge = losSollMenge.setScale(3, BigDecimal.ROUND_HALF_EVEN);
                } else {
                    losSollMenge = losSollMenge.setScale(3, BigDecimal.ROUND_HALF_EVEN);
                }

                losMatDto.setNMenge(losSollMenge);

            }

            BigDecimal bdSollpreis = getLagerFac().getGemittelterGestehungspreisEinesLagers(
                    stkPos[i].getArtikelIId(), lagerIId_Hauptlager, theClientDto);
            losMatDto.setNSollpreis(bdSollpreis);
            // Datensatz speichern

            // Wenn Unterstueckliste und Hilfsstueckliste:

            StuecklisteDto stuecklisteDto = getStuecklisteFac()
                    .stuecklisteFindByMandantCNrArtikelIIdOhneExc(stkPos[i].getArtikelIId(), theClientDto);

            if (stuecklisteDto != null && stuecklisteDto.getArtikelIId() == 3376) {
                int u = 0;

            }

            if (stuecklisteDto != null && stuecklisteDto.getStuecklisteartCNr()
                    .equals(StuecklisteFac.STUECKLISTEART_HILFSSTUECKLISTE) && bFlachdruecken == true) {
                if (iEbene < 10) {
                    erstelleLossollmaterial(losIId, stuecklisteDto.getIId(), losMatDto.getNMenge(),
                            lagerIId_Hauptlager, true, iEbene, theClientDto);

                }

            } else {

                LossollmaterialDto lossollmaterialDto = createLossollmaterial(losMatDto, theClientDto);

                Integer iOriginal_IId = new Integer(lossollmaterialDto.getIId());

                // Ersatztypen anlegen
                PosersatzDto[] posersatzDtos = getStuecklisteFac()
                        .posersatzFindByStuecklistepositionIId(stkPos[i].getIId());
                if (iEbene < 10) {
                    for (int k = 0; k < posersatzDtos.length; k++) {

                        losMatDto.setArtikelIId(posersatzDtos[k].getArtikelIIdErsatz());
                        losMatDto.setNMenge(new BigDecimal(0));
                        losMatDto.setLossollmaterialIIdOriginal(iOriginal_IId);
                        createLossollmaterial(losMatDto, theClientDto);

                    }
                }
            }
        }
    } catch (RemoteException ex1) {
        throwEJBExceptionLPRespectOld(ex1);
    }
}

From source file:org.egov.services.payment.PaymentService.java

public List<PaymentBean> getCSList(final List<EgBillregister> billList,
        final Map<Long, BigDecimal> deductionAmtMap, final Map<Long, BigDecimal> paidAmtMap) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Starting getCSList...");
    final List<PaymentBean> contractorList = new ArrayList<PaymentBean>();
    PaymentBean paymentBean = null;//from  w w  w  .  j a va 2 s  .  com
    if (billList != null && !billList.isEmpty())
        for (final EgBillregister billregister : billList) {
            paymentBean = new PaymentBean();
            paymentBean.setCsBillId(billregister.getId());
            paymentBean.setBillNumber(billregister.getBillnumber());
            paymentBean.setBillDate(billregister.getBilldate());
            paymentBean.setExpType(billregister.getExpendituretype());

            if (billregister.getExpendituretype()
                    .equals(FinancialConstants.STANDARD_EXPENDITURETYPE_CONTINGENT)) {
                if (billregister.getEgBillregistermis().getEgBillSubType() != null) {
                    if (billregister.getEgBillregistermis().getEgBillSubType().getName()
                            .equalsIgnoreCase("TNEB"))
                        paymentBean.setPayTo(billregister.getEgBillregistermis().getPayto());
                    else
                        paymentBean.setPayTo(getPayeeNameForCBill(billregister));
                } else
                    paymentBean.setPayTo(getPayeeNameForCBill(billregister));
            } else
                paymentBean.setPayTo(billregister.getEgBillregistermis().getPayto());
            paymentBean.setDeductionAmt(deductionAmtMap.get(paymentBean.getCsBillId()) == null ? BigDecimal.ZERO
                    : deductionAmtMap.get(paymentBean.getCsBillId()));
            final BigDecimal passedamount = billregister.getPassedamount() == null ? BigDecimal.ZERO
                    : billregister.getPassedamount().setScale(2, BigDecimal.ROUND_HALF_EVEN);
            paymentBean.setNetAmt(passedamount.subtract(
                    paymentBean.getDeductionAmt() == null ? BigDecimal.ZERO : paymentBean.getDeductionAmt()));
            paymentBean.setEarlierPaymentAmt(paidAmtMap.get(paymentBean.getCsBillId()) == null ? BigDecimal.ZERO
                    : paidAmtMap.get(paymentBean.getCsBillId()));
            paymentBean.setPayableAmt(paymentBean.getNetAmt().subtract(paymentBean.getEarlierPaymentAmt()));
            paymentBean.setPaymentAmt(paymentBean.getPayableAmt());
            if (paymentBean.getPaymentAmt().compareTo(BigDecimal.ZERO) == 0)
                continue;
            if (billregister.getEgBillregistermis().getFund() != null)
                paymentBean.setFundName(billregister.getEgBillregistermis().getFund().getName());
            if (billregister.getEgBillregistermis().getEgDepartment() != null)
                paymentBean.setDeptName(billregister.getEgBillregistermis().getEgDepartment().getName());
            if (billregister.getEgBillregistermis().getScheme() != null)
                paymentBean.setSchemeName(billregister.getEgBillregistermis().getScheme().getName());
            if (billregister.getEgBillregistermis().getSubScheme() != null)
                paymentBean.setSubschemeName(billregister.getEgBillregistermis().getSubScheme().getName());
            if (billregister.getEgBillregistermis().getFunctionaryid() != null)
                paymentBean
                        .setFunctionaryName(billregister.getEgBillregistermis().getFunctionaryid().getName());
            if (billregister.getEgBillregistermis().getFunction() != null)
                paymentBean.setFunctionName(billregister.getEgBillregistermis().getFunction().getName());
            if (billregister.getEgBillregistermis().getFundsource() != null)
                paymentBean.setFundsourceName(billregister.getEgBillregistermis().getFundsource().getName());
            if (billregister.getEgBillregistermis().getFieldid() != null)
                paymentBean.setFieldName(billregister.getEgBillregistermis().getFieldid().getName());
            if (billregister.getEgBillregistermis().getVoucherHeader() != null) {
                paymentBean.setBillVoucherNumber(
                        billregister.getEgBillregistermis().getVoucherHeader().getVoucherNumber());
                paymentBean.setBillVoucherDate(
                        billregister.getEgBillregistermis().getVoucherHeader().getVoucherDate());
                paymentBean.setBillVoucherId(billregister.getEgBillregistermis().getVoucherHeader().getId());
            }
            if (billregister.getEgBillregistermis().getEgBillSubType() != null)
                if (billregister.getEgBillregistermis().getEgBillSubType().getName().equalsIgnoreCase("TNEB")) {
                    final String region = (String) persistenceService.find(
                            "select region from EBDetails where egBillregister.id = ?", billregister.getId());

                    if (region != null)
                        paymentBean.setRegion(region);
                }

            contractorList.add(paymentBean);
        }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Completed getCSList.");
    return contractorList;
}

From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java

public void bucheMaterialAufLos(LosDto losDto, BigDecimal menge, boolean bHandausgabe,
        boolean bNurFehlmengenAnlegenUndReservierungenLoeschen, boolean bUnterstuecklistenAbbuchen,
        TheClientDto theClientDto, ArrayList<BucheSerienChnrAufLosDto> bucheSerienChnrAufLosDtos,
        boolean throwExceptionWhenCreate) {
    try {/*from w  w w .  j a  v a  2  s . c  om*/

        Query query = em.createNamedQuery("LossollmaterialfindByLosIId");
        query.setParameter(1, losDto.getIId());
        Collection<?> cl = query.getResultList();
        // if (cl.isEmpty()) {
        // throw new EJBExceptionLP(EJBExceptionLP.FEHLER_BEI_FIND, null);
        // }
        LossollmaterialDto[] sollmat = assembleLossollmaterialDtos(cl);
        LosablieferungDto[] dtos = losablieferungFindByLosIId(losDto.getIId(), false, theClientDto);
        BigDecimal bdBereitsabgeliefert = new BigDecimal(0);
        for (int i = 0; i < dtos.length; i++) {
            bdBereitsabgeliefert = bdBereitsabgeliefert.add(dtos[i].getNMenge());
        }

        // PJ18216
        boolean bNichtLagerbewSofortAusgeben = false;
        try {
            ParametermandantDto parameterM = getParameterFac().getMandantparameter(theClientDto.getMandant(),
                    ParameterFac.KATEGORIE_FERTIGUNG,
                    ParameterFac.PARAMETER_NICHT_LAGERBEWIRTSCHAFTETE_SOFORT_AUSGEBEN);
            bNichtLagerbewSofortAusgeben = ((Boolean) parameterM.getCWertAsObject()).booleanValue();

        } catch (RemoteException ex) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex);
        }

        // Laeger des Loses
        LoslagerentnahmeDto[] laeger = loslagerentnahmeFindByLosIId(losDto.getIId());
        // nun vom lager abbuchen
        for (int i = 0; i < sollmat.length; i++) {
            ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKey(sollmat[i].getArtikelIId(),
                    theClientDto);
            // seriennummerntragende werden jetzt gar nicht gebucht

            if (!bNurFehlmengenAnlegenUndReservierungenLoeschen) {
                if (!bHandausgabe || (bHandausgabe == true && bNichtLagerbewSofortAusgeben == true)) {

                    // PJ18216
                    if (bHandausgabe == true && bNichtLagerbewSofortAusgeben == true) {

                        if (Helper.short2boolean(artikelDto.getBLagerbewirtschaftet())) {
                            continue;
                        }

                    }

                    StuecklisteDto stuecklisteDto = getStuecklisteFac()
                            .stuecklisteFindByMandantCNrArtikelIIdOhneExc(artikelDto.getIId(), theClientDto);
                    if (bUnterstuecklistenAbbuchen == false && stuecklisteDto != null) {
                    } else {

                        BigDecimal bdAbzubuchendeMenge = new BigDecimal(0.0000);
                        if (menge == null) {
                            bdAbzubuchendeMenge = sollmat[i].getNMenge();
                        } else {
                            if (losDto.getNLosgroesse().doubleValue() != 0) {
                                BigDecimal sollsatzGroesse = sollmat[i].getNMenge()
                                        .divide(losDto.getNLosgroesse(), 10, BigDecimal.ROUND_HALF_EVEN);

                                sollsatzGroesse = Helper.rundeKaufmaennisch(sollsatzGroesse, 3);

                                BigDecimal bdBereitsausgegeben = getAusgegebeneMenge(sollmat[i].getIId(), null,
                                        theClientDto);
                                BigDecimal bdGesamtmenge = Helper.rundeKaufmaennisch(
                                        bdBereitsabgeliefert.add(menge).multiply(sollsatzGroesse), 4);
                                if (bdGesamtmenge.subtract(bdBereitsausgegeben).doubleValue() > 0) {
                                    bdAbzubuchendeMenge = bdGesamtmenge.subtract(bdBereitsausgegeben);
                                } else {
                                    if (bdGesamtmenge.doubleValue() < 0) {
                                        bdAbzubuchendeMenge = bdGesamtmenge.subtract(bdBereitsausgegeben).abs();

                                    }
                                }
                            }
                        }

                        // wg. PJ 15370
                        if (sollmat[i].getNMenge().doubleValue() > 0) {

                            if (!Helper.short2boolean(artikelDto.getBSeriennrtragend())
                                    && !Helper.short2boolean(artikelDto.getBChargennrtragend())) {
                                for (int j = 0; j < laeger.length; j++) {
                                    // wenn noch was abzubuchen ist (Menge >
                                    // 0)
                                    if (bdAbzubuchendeMenge.compareTo(new BigDecimal(0)) == 1) {
                                        BigDecimal bdLagerstand = null;
                                        if (Helper.short2boolean(artikelDto.getBLagerbewirtschaftet())) {

                                            // PJ18290
                                            boolean bImmerAusreichendVerfuegbar = false;
                                            try {
                                                ParametermandantDto parameterM = getParameterFac()
                                                        .getMandantparameter(theClientDto.getMandant(),
                                                                ParameterFac.KATEGORIE_ARTIKEL,
                                                                ParameterFac.PARAMETER_LAGER_IMMER_AUSREICHEND_VERFUEGBAR);
                                                bImmerAusreichendVerfuegbar = ((Boolean) parameterM
                                                        .getCWertAsObject()).booleanValue();

                                            } catch (RemoteException ex) {
                                                throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex);
                                            }
                                            if (bImmerAusreichendVerfuegbar == true) {
                                                bdLagerstand = new BigDecimal(999999999);
                                            } else {
                                                bdLagerstand = getLagerFac().getLagerstand(artikelDto.getIId(),
                                                        laeger[j].getLagerIId(), theClientDto);

                                            }

                                        } else {
                                            bdLagerstand = new BigDecimal(999999999);
                                        }
                                        // wenn ein lagerstand da ist
                                        if (bdLagerstand.compareTo(new BigDecimal(0)) == 1) {
                                            BigDecimal bdMengeVonLager;
                                            if (bdLagerstand.compareTo(bdAbzubuchendeMenge) == 1) {
                                                // wenn mehr als ausreichend
                                                // auf
                                                // lager
                                                bdMengeVonLager = bdAbzubuchendeMenge;
                                            } else {
                                                // dann nur den lagerstand
                                                // entnehmen
                                                bdMengeVonLager = bdLagerstand;
                                            }
                                            LosistmaterialDto istmat = new LosistmaterialDto();
                                            istmat.setLagerIId(laeger[j].getLagerIId());
                                            istmat.setLossollmaterialIId(sollmat[i].getIId());
                                            istmat.setNMenge(bdMengeVonLager);

                                            if (sollmat[i].getNMenge().doubleValue() > 0) {
                                                istmat.setBAbgang(Helper.boolean2Short(true));
                                            } else {
                                                istmat.setBAbgang(Helper.boolean2Short(false));
                                            }

                                            // ist-wert anlegen und
                                            // lagerbuchung
                                            // durchfuehren
                                            createLosistmaterial(istmat, null, theClientDto);
                                            // menge reduzieren
                                            bdAbzubuchendeMenge = bdAbzubuchendeMenge.subtract(bdMengeVonLager);
                                        }
                                    }
                                }

                            } else {
                                if (bucheSerienChnrAufLosDtos != null) {
                                    for (int j = 0; j < bucheSerienChnrAufLosDtos.size(); j++) {
                                        BucheSerienChnrAufLosDto dtoTemp = bucheSerienChnrAufLosDtos.get(j);

                                        if (dtoTemp.getLossollmaterialIId().equals(sollmat[i].getIId())) {

                                            LosistmaterialDto istmat = new LosistmaterialDto();
                                            istmat.setLagerIId(dtoTemp.getLagerIId());
                                            istmat.setLossollmaterialIId(dtoTemp.getLossollmaterialIId());
                                            istmat.setNMenge(dtoTemp.getNMenge());
                                            if (sollmat[i].getNMenge().doubleValue() > 0) {
                                                istmat.setBAbgang(Helper.boolean2Short(true));
                                            } else {
                                                istmat.setBAbgang(Helper.boolean2Short(false));
                                            }
                                            // ist-wert anlegen und
                                            // lagerbuchung
                                            // durchfuehren
                                            createLosistmaterial(istmat, dtoTemp.getCSeriennrChargennr(),
                                                    theClientDto);

                                        }

                                    }
                                }
                            }
                        }
                    }

                }
            }

            // Reservierung loeschen
            removeReservierung(artikelDto, sollmat[i].getIId());
            // Fehlmenge anlegen
            getFehlmengeFac().aktualisiereFehlmenge(LocaleFac.BELEGART_LOS, sollmat[i].getIId(),
                    throwExceptionWhenCreate, theClientDto);
        }

    }
    // catch (FinderException ex) {
    // throw new EJBExceptionLP(EJBExceptionLP.FEHLER_BEI_FIND, ex);
    // }
    catch (RemoteException ex) {
        throwEJBExceptionLPRespectOld(ex);
    }

}