Example usage for java.math BigDecimal ONE

List of usage examples for java.math BigDecimal ONE

Introduction

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

Prototype

BigDecimal ONE

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

Click Source Link

Document

The value 1, with a scale of 0.

Usage

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC101LC201() throws Exception {

    final int day0 = 0;
    final BigDecimal price1 = new BigDecimal("150.00");
    final BigDecimal price2 = new BigDecimal("185.00");
    final BigDecimal price3 = new BigDecimal("535.00");
    final BigDecimal price4 = new BigDecimal("105.00");
    final BigDecimal price5 = new BigDecimal("20.00");
    final BigDecimal price6 = new BigDecimal("151.8693");
    final BigDecimal price7 = new BigDecimal("187.30535");
    final BigDecimal price8 = new BigDecimal("149.9423");
    final BigDecimal price9 = new BigDecimal("184.92885");
    final BigDecimal price10 = new BigDecimal("148.1538");
    final BigDecimal price11 = new BigDecimal("182.7231");
    final BigDecimal quantity1 = new BigDecimal("100");
    final BigDecimal quantity2 = new BigDecimal("200");
    final BigDecimal quantity3 = BigDecimal.ONE;

    try {/*from w  w  w.  j a va 2  s . co  m*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1);

        // Create a new product for the test
        Product product2 = createProduct(price2);

        // Create purchase order and book it
        Order purchaseOrder1 = createPurchaseOrder(product1, price1, quantity1, day0);

        // Create purchase order and book it
        Order purchaseOrder2 = createPurchaseOrder(product2, price2, quantity2, day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList = new ArrayList<Order>();
        purchaseOrderList.add(purchaseOrder1);
        purchaseOrderList.add(purchaseOrder2);
        ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrderList, null, quantity1.add(quantity2),
                day0);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE3_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity3.multiply(price3));
        amountList.add(quantity3.multiply(price4));
        amountList.add(quantity3.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt);
        createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day0);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price2, price7, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price6, quantity1));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price2, price2, price7, quantity2));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                quantity1.multiply(price1).add(quantity1.multiply(price8).negate()), day0, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                quantity2.multiply(price2).add(quantity2.multiply(price9).negate()), day0, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                quantity1.multiply(price1).add(quantity1.multiply(price10).negate()), day0, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                quantity2.multiply(price2).add(quantity2.multiply(price11).negate()), day0, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList21 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                quantity1.multiply(price1).add(quantity1.multiply(price8).negate()), day0, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                quantity2.multiply(price2).add(quantity2.multiply(price9).negate()), day0, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                quantity1.multiply(price1).add(quantity1.multiply(price10).negate()), day0, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                quantity2.multiply(price2).add(quantity2.multiply(price11).negate()), day0, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList21);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC400() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final int day4 = 20;
    final int day5 = 25;
    final BigDecimal price1 = new BigDecimal("150.00");
    final BigDecimal price2 = new BigDecimal("400.00");
    final BigDecimal price3 = new BigDecimal("535.00");
    final BigDecimal price4 = new BigDecimal("105.00");
    final BigDecimal price5 = new BigDecimal("20.00");
    final BigDecimal price6 = new BigDecimal("600.00");
    final BigDecimal price7 = new BigDecimal("150.00");
    final BigDecimal price8 = new BigDecimal("25.00");
    final BigDecimal price9 = new BigDecimal("153.7377");
    final BigDecimal price10 = new BigDecimal("160.00");
    final BigDecimal price11 = new BigDecimal("163.9868");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = BigDecimal.ONE;
    final BigDecimal amount1 = new BigDecimal("5.25");
    final BigDecimal amount2 = new BigDecimal("167.87");
    final BigDecimal amount3 = new BigDecimal("14.75");
    final BigDecimal amount4 = new BigDecimal("472.13");
    final BigDecimal amount5 = new BigDecimal("17.05");
    final BigDecimal amount6 = new BigDecimal("47.95");
    final BigDecimal amount7 = new BigDecimal("11.80");
    final BigDecimal amount8 = new BigDecimal("33.20");
    final BigDecimal amount9 = new BigDecimal("1.31");
    final BigDecimal amount10 = new BigDecimal("3.69");

    try {/*from   w ww . java  2  s. c  o  m*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1, CURRENCY1_ID);

        // Create a new product for the test
        Product product2 = createProduct(price2, CURRENCY2_ID);

        // Create purchase order and book it
        Order purchaseOrder = createPurchaseOrder(product2, price2, quantity1, day0);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrder, price2, quantity1, day1);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(product1, price1, quantity2, day2);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE3_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity3.multiply(price3));
        amountList.add(quantity3.multiply(price4));
        amountList.add(quantity3.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day3);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE1_ID, price6,
                quantity3, day4);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(0), true);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(0),
                purchaseInvoiceLandedCost1.getInvoiceLineList().get(0));

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost2 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price7,
                quantity3, day4);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost2.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(1), true);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(1),
                purchaseInvoiceLandedCost2.getInvoiceLineList().get(0));

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost3 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE3_ID, price8,
                quantity3, day5);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost3.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(2), true);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(2),
                purchaseInvoiceLandedCost3.getInvoiceLineList().get(0));

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price9, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price10, price11, price10));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price9, quantity2));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price10, price10, price11, quantity1));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                amount1, day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount2, day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                amount3, day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount4, day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount5, day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount6, day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList12);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList13 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount7, day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount8, day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList13);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList14 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList14.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                amount9, day3, true, false));
        costAdjustmentAssertLineList14.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                amount10, day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList14);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList21 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                amount1, day3, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount2, day3, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                amount3, day3, true, false));
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount4, day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList21);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList22 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount5, day3, true, false));
        costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount6, day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList22);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList23 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList23.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY1_ID, "LC",
                amount7, day3, true, false));
        costAdjustmentAssertLineList23.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY1_ID, "LC",
                amount8, day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList23);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList24 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList24.add(new CostAdjustmentAssert(transactionList2.get(0), CURRENCY2_ID, "LC",
                amount9, day3, true, false));
        costAdjustmentAssertLineList24.add(new CostAdjustmentAssert(transactionList1.get(0), CURRENCY2_ID, "LC",
                amount10, day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList24);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void sendOmejoraSolicita(ActionEvent event) {
    try {//  w w w  .  jav a 2  s.  co  m
        if (StringUtils.isBlank(this.getSelectedOmejora().getVmsjsolicita())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                    "Campo requerido. Ingrese el mensaje a enviar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        } else {
            //this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml"));
            if (this.getChkDestacado()) {
                ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService");
                HashMap filter = new HashMap();
                filter.put("ntipoconocimientoid", Constante.OPORTUNIDADMEJORA);
                BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter);
                if (cant.intValue() >= 10) {
                    this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter));
                    RequestContext.getCurrentInstance().execute("PF('destDialog').show();");
                    return;
                }
            }
            this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User usuario = loginMB.getUser();
            ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                    .findBean("ConocimientoService");
            this.getSelectedOmejora().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            this.getSelectedOmejora().setVtitulo(StringUtils.upperCase(this.getSelectedOmejora().getVtitulo()));
            this.getSelectedOmejora()
                    .setVdescripcion(StringUtils.upperCase(this.getSelectedOmejora().getVdescripcion()));
            if (this.getContenidoPlain().length() < 400) {
                this.getSelectedOmejora().setVcontenido(StringUtils.capitalize(this.getContenidoPlain()));
            } else {
                this.getSelectedOmejora()
                        .setVcontenido(StringUtils.capitalize(this.getContenidoPlain().substring(0, 399)));
            }
            this.getSelectedOmejora().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
            this.getSelectedOmejora().setDfechamodificacion(new Date());
            this.getSelectedOmejora().setVusuariomodificacion(usuario.getVlogin());
            this.getSelectedOmejora()
                    .setVmsjsolicita(this.getSelectedOmejora().getVmsjsolicita().toUpperCase());
            conocimientoService.saveOrUpdate(this.getSelectedOmejora());

            this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
            GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "html.txt",
                    this.getContenidoHtml());
            GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "plain.txt",
                    this.getContenidoPlain());

            HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
            Historial lastHistorial = historialService
                    .getLastHistorialByConocimiento(this.getSelectedOmejora().getNconocimientoid());
            int lastversion;
            if (lastHistorial != null) {
                lastversion = lastHistorial.getNnumversion().intValue();
            } else {
                lastversion = 0;
            }
            String url = this.pathom.concat(this.getSelectedOmejora().getNconocimientoid().toString())
                    .concat("/").concat(Integer.toString(lastversion + 1)).concat("/");

            ThistorialId thistorialId = new ThistorialId();
            thistorialId.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
            thistorialId.setNhistorialid(historialService.getNextPK());
            Historial historial = new Historial();
            historial.setId(thistorialId);
            historial.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
            historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            historial.setVtitulo(this.getSelectedOmejora().getVtitulo());
            historial.setVdescripcion(this.getSelectedOmejora().getVdescripcion());
            historial.setNactivo(BigDecimal.ONE);
            historial.setNsituacionid(this.getSelectedOmejora().getNsituacionid());
            historial.setVruta(url);
            historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
            historial.setDfechacreacion(new Date());
            historial.setVusuariocreacion(usuario.getVlogin());
            historial.setVmsjsolicita(this.getSelectedOmejora().getVmsjsolicita());
            historial.setVmsjrespuesta(this.getSelectedOmejora().getVmsjrespuesta());
            historialService.saveOrUpdate(historial);

            GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getContenidoHtml());
            GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getContenidoPlain());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
                String url0 = this.getSelectedOmejora().getVruta().concat("s");
                String url1 = url.concat("s");
                SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService");
                SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder
                        .findBean("SeccionHistService");
                for (Seccion seccion : this.getListaSeccion()) {
                    String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/");
                    seccion.setVruta(ruta0);
                    if (seccion.getNseccionid() != null) {
                        seccion.setDfechamodificacion(new Date());
                        seccion.setVusuariomodificacion(usuario.getVlogin());
                    } else {
                        seccion.setNseccionid(seccionService.getNextPK());
                        seccion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                        seccion.setDfechacreacion(new Date());
                        seccion.setVusuariocreacion(usuario.getVlogin());
                    }
                    seccionService.saveOrUpdate(seccion);

                    seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text());
                    GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain());

                    String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/");
                    TseccionHistId tseccionHistId = new TseccionHistId();
                    tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    tseccionHistId.setNhistorialid(thistorialId.getNhistorialid());
                    tseccionHistId.setNseccionhid(seccionHistService.getNextPK());
                    SeccionHist seccionHist = new SeccionHist();
                    seccionHist.setId(tseccionHistId);
                    seccionHist.setNorden(seccion.getNorden());
                    seccionHist.setVruta(ruta1);
                    seccionHist.setVtitulo(seccion.getVtitulo());
                    seccionHist.setVusuariocreacion(usuario.getVlogin());
                    seccionHist.setDfechacreacion(new Date());
                    seccionHistService.saveOrUpdate(seccionHist);

                    GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain());
                }
            }

            this.setListaTargetVinculos(new ArrayList());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
                VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                        .findBean("VinculoHistService");
                vinculoService.deleteByConocimiento(this.getSelectedOmejora().getNconocimientoid());
                for (Consulta consulta : this.getListaTargetVinculos()) {
                    Vinculo vinculo = new Vinculo();
                    vinculo.setNvinculoid(vinculoService.getNextPK());
                    vinculo.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                    vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                    vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                    vinculo.setDfechacreacion(new Date());
                    vinculo.setVusuariocreacion(usuario.getVlogin());
                    vinculoService.saveOrUpdate(vinculo);

                    TvinculoHistId vinculoHistId = new TvinculoHistId();
                    vinculoHistId.setNvinculohid(vinculoHistService.getNextPK());
                    vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    vinculoHistId.setNhistorialid(thistorialId.getNhistorialid());
                    VinculoHist vinculoHist = new VinculoHist();
                    vinculoHist.setId(vinculoHistId);
                    vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc());
                    vinculoHist.setDfechacreacion(new Date());
                    vinculoHist.setVusuariocreacion(usuario.getVlogin());
                    vinculoHistService.saveOrUpdate(vinculoHist);
                }
            }

            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("9")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
            asignacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            asignacion.setNusuarioid(
                    serviceasig.getUserCreacionByContenido(this.getSelectedOmejora().getNtipoconocimientoid(),
                            this.getSelectedOmejora().getNconocimientoid()));
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            loginMB.refreshNotifications();

            this.fSInfMod = "true";
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                    "Se envi la solicitud de informacin adicional.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");
        }

    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC300() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("300.00");
    final BigDecimal price2 = new BigDecimal("27.50");
    final BigDecimal price3 = new BigDecimal("105.00");
    final BigDecimal price4 = new BigDecimal("326.50");
    final BigDecimal quantity1 = new BigDecimal("5");
    final BigDecimal quantity2 = BigDecimal.ONE;

    try {//  w ww .j a va 2 s .  c  o m

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product = createProduct(price1);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity2.multiply(price2));
        amountList.add(quantity2.multiply(price3));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt);
        LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE1_ID, price2,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(0), true);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(0),
                purchaseInvoiceLandedCost1.getInvoiceLineList().get(0));

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost2 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price3,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost2.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(1), true);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(1),
                purchaseInvoiceLandedCost2.getInvoiceLineList().get(0));

        // Assert product transactions
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price4, price1));
        assertProductTransaction(product.getId(), productTransactionAssertList1);

        // Assert product costing
        List<MaterialTransaction> transactionList = getProductTransactions(product.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price4, quantity1));
        assertProductCosting(product.getId(), productCostingAssertList1);

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "LC",
                quantity1.multiply(price4).add(quantity1.multiply(price1).negate()), day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC500() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("500.00");
    final BigDecimal price2 = new BigDecimal("210.00");
    final BigDecimal price3 = new BigDecimal("300.00");
    final BigDecimal price4 = new BigDecimal("520.40");
    final BigDecimal quantity1 = new BigDecimal("25");
    final BigDecimal quantity2 = BigDecimal.ONE;

    try {//www.  j a  v a2  s  . c  om

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product = createProduct(price1);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price2,
                quantity2, day1);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost2 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE1_ID, price3,
                quantity2, day1);

        // Create Landed Cost
        List<Invoice> invoiceList = new ArrayList<Invoice>();
        invoiceList.add(purchaseInvoiceLandedCost1);
        invoiceList.add(purchaseInvoiceLandedCost2);
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt);
        createLandedCost(invoiceList, receiptList, day2);

        // Assert product transactions
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price4, price1));
        assertProductTransaction(product.getId(), productTransactionAssertList1);

        // Assert product costing
        List<MaterialTransaction> transactionList = getProductTransactions(product.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price4, quantity1));
        assertProductCosting(product.getId(), productCostingAssertList1);

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "LC",
                quantity1.multiply(price4).add(quantity1.multiply(price1).negate()), day2, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void sendWikiRespuesta(ActionEvent event) {
    try {/*  w ww. j  a v a  2  s. com*/
        if (StringUtils.isBlank(this.getSelectedWiki().getVmsjrespuesta())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                    "Campo requerido. Ingrese el mensaje a enviar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        } else {
            //this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml"));
            if (this.getChkDestacado()) {
                ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService");
                HashMap filter = new HashMap();
                filter.put("ntipoconocimientoid", Constante.WIKI);
                BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter);
                if (cant.intValue() >= 10) {
                    this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter));
                    RequestContext.getCurrentInstance().execute("PF('destDialog').show();");
                    return;
                }
            }
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User usuario = loginMB.getUser();
            ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                    .findBean("ConocimientoService");
            this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text());
            this.getSelectedWiki().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            this.getSelectedWiki().setVtitulo(StringUtils.upperCase(this.getSelectedWiki().getVtitulo()));
            if (this.getDescripcionPlain().length() < 400) {
                this.getSelectedWiki().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain()));
            } else {
                this.getSelectedWiki()
                        .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 399)));
            }
            this.getSelectedWiki().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
            this.getSelectedWiki().setDfechamodificacion(new Date());
            this.getSelectedWiki().setVusuariomodificacion(usuario.getVlogin());
            this.getSelectedWiki().setVmsjrespuesta(this.getSelectedWiki().getVmsjrespuesta().toUpperCase());
            conocimientoService.saveOrUpdate(this.getSelectedWiki());

            GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "html.txt",
                    this.getDescripcionHtml());
            GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "plain.txt",
                    this.getDescripcionPlain());

            HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
            Historial lastHistorial = historialService
                    .getLastHistorialByConocimiento(this.getSelectedWiki().getNconocimientoid());
            int lastversion;
            if (lastHistorial != null) {
                lastversion = lastHistorial.getNnumversion().intValue();
            } else {
                lastversion = 0;
            }
            String url = this.pathwk.concat(this.getSelectedWiki().getNconocimientoid().toString()).concat("/")
                    .concat(Integer.toString(lastversion + 1)).concat("/");

            ThistorialId thistorialId = new ThistorialId();
            thistorialId.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
            thistorialId.setNhistorialid(historialService.getNextPK());
            Historial historial = new Historial();
            historial.setId(thistorialId);
            historial.setNtipoconocimientoid(Constante.WIKI);
            historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            historial.setVtitulo(this.getSelectedWiki().getVtitulo());
            historial.setNactivo(BigDecimal.ONE);
            historial.setNsituacionid(this.getSelectedWiki().getNsituacionid());
            historial.setVruta(url);
            historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
            historial.setDfechacreacion(new Date());
            historial.setVusuariocreacion(usuario.getVlogin());
            historial.setVmsjsolicita(this.getSelectedWiki().getVmsjsolicita());
            historial.setVmsjrespuesta(this.getSelectedWiki().getVmsjrespuesta());
            historialService.saveOrUpdate(historial);

            GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml());
            GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
                String url0 = this.getSelectedWiki().getVruta().concat("s");
                String url1 = url.concat("s");
                SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService");
                SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder
                        .findBean("SeccionHistService");
                for (Seccion seccion : this.getListaSeccion()) {
                    String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/");
                    seccion.setVruta(ruta0);
                    if (seccion.getNseccionid() != null) {
                        seccion.setDfechamodificacion(new Date());
                        seccion.setVusuariomodificacion(usuario.getVlogin());
                    } else {
                        seccion.setNseccionid(seccionService.getNextPK());
                        seccion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
                        seccion.setDfechacreacion(new Date());
                        seccion.setVusuariocreacion(usuario.getVlogin());
                    }
                    seccionService.saveOrUpdate(seccion);

                    seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text());
                    GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain());

                    String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/");
                    TseccionHistId tseccionHistId = new TseccionHistId();
                    tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    tseccionHistId.setNhistorialid(thistorialId.getNhistorialid());
                    tseccionHistId.setNseccionhid(seccionHistService.getNextPK());
                    SeccionHist seccionHist = new SeccionHist();
                    seccionHist.setId(tseccionHistId);
                    seccionHist.setNorden(seccion.getNorden());
                    seccionHist.setVruta(ruta1);
                    seccionHist.setVtitulo(seccion.getVtitulo());
                    seccionHist.setVusuariocreacion(usuario.getVlogin());
                    seccionHist.setDfechacreacion(new Date());
                    seccionHistService.saveOrUpdate(seccionHist);

                    GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain());
                }
            }

            this.setListaTargetVinculos(new ArrayList());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
                VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                        .findBean("VinculoHistService");
                vinculoService.deleteByConocimiento(this.getSelectedWiki().getNconocimientoid());
                for (Consulta consulta : this.getListaTargetVinculos()) {
                    Vinculo vinculo = new Vinculo();
                    vinculo.setNvinculoid(vinculoService.getNextPK());
                    vinculo.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
                    vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                    vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                    vinculo.setDfechacreacion(new Date());
                    vinculo.setVusuariocreacion(usuario.getVlogin());
                    vinculoService.saveOrUpdate(vinculo);

                    TvinculoHistId vinculoHistId = new TvinculoHistId();
                    vinculoHistId.setNvinculohid(vinculoHistService.getNextPK());
                    vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    vinculoHistId.setNhistorialid(thistorialId.getNhistorialid());
                    VinculoHist vinculoHist = new VinculoHist();
                    vinculoHist.setId(vinculoHistId);
                    vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc());
                    vinculoHist.setDfechacreacion(new Date());
                    vinculoHist.setVusuariocreacion(usuario.getVlogin());
                    vinculoHistService.saveOrUpdate(vinculoHist);
                }
            }

            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("10")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.WIKI);
            asignacion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService.getCategoriaById(this.getSelectedWiki().getNcategoriaid())
                    .getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            loginMB.refreshNotifications();

            this.fSInfMod = "true";
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                    "Solicitud de informacin respondida.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.ofbiz.order.order.OrderServices.java

public static Map<String, Object> createAlsoBoughtProductAssocsForOrder(DispatchContext dctx,
        Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    String orderId = (String) context.get("orderId");
    OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
    List<GenericValue> orderItems = orh.getOrderItems();
    // In order to improve efficiency a little bit, we will always create the ProductAssoc records
    // with productId < productIdTo when the two are compared.  This way when checking for an existing
    // record we don't have to check both possible combinations of productIds
    TreeSet<String> productIdSet = new TreeSet<String>();
    if (orderItems != null) {
        for (GenericValue orderItem : orderItems) {
            String productId = orderItem.getString("productId");
            if (productId != null) {
                GenericValue parentProduct = ProductWorker.getParentProduct(productId, delegator);
                if (parentProduct != null)
                    productId = parentProduct.getString("productId");
                productIdSet.add(productId);
            }/*  www  . j av a2 s.co m*/
        }
    }
    TreeSet<String> productIdToSet = new TreeSet<String>(productIdSet);
    for (String productId : productIdSet) {
        productIdToSet.remove(productId);
        for (String productIdTo : productIdToSet) {
            EntityCondition cond = EntityCondition
                    .makeCondition(UtilMisc.toList(EntityCondition.makeCondition("productId", productId),
                            EntityCondition.makeCondition("productIdTo", productIdTo),
                            EntityCondition.makeCondition("productAssocTypeId", "ALSO_BOUGHT"),
                            EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO,
                                    UtilDateTime.nowTimestamp()),
                            EntityCondition.makeCondition("thruDate", null)));
            GenericValue existingProductAssoc = null;
            try {
                // No point in using the cache because of the filterByDateExpr
                existingProductAssoc = EntityUtil.getFirst(delegator.findList("ProductAssoc", cond, null,
                        UtilMisc.toList("fromDate DESC"), null, false));
            } catch (GenericEntityException e) {
                Debug.logError(e, module);
            }
            try {
                if (existingProductAssoc != null) {
                    BigDecimal newQuantity = existingProductAssoc.getBigDecimal("quantity");
                    if (newQuantity == null || newQuantity.compareTo(BigDecimal.ZERO) < 0) {
                        newQuantity = BigDecimal.ZERO;
                    }
                    newQuantity = newQuantity.add(BigDecimal.ONE);
                    ModelService updateProductAssoc = dctx.getModelService("updateProductAssoc");
                    Map<String, Object> updateCtx = updateProductAssoc.makeValid(context, ModelService.IN_PARAM,
                            true, null);
                    updateCtx.putAll(updateProductAssoc.makeValid(existingProductAssoc, ModelService.IN_PARAM));
                    updateCtx.put("quantity", newQuantity);
                    dispatcher.runSync("updateProductAssoc", updateCtx);
                } else {
                    Map<String, Object> createCtx = FastMap.newInstance();
                    createCtx.put("userLogin", context.get("userLogin"));
                    createCtx.put("productId", productId);
                    createCtx.put("productIdTo", productIdTo);
                    createCtx.put("productAssocTypeId", "ALSO_BOUGHT");
                    createCtx.put("fromDate", UtilDateTime.nowTimestamp());
                    createCtx.put("quantity", BigDecimal.ONE);
                    dispatcher.runSync("createProductAssoc", createCtx);
                }
            } catch (GenericServiceException e) {
                Debug.logError(e, module);
            }
        }
    }

    return ServiceUtil.returnSuccess();
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC600() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("600.00");
    final BigDecimal price2 = new BigDecimal("315.00");
    final BigDecimal price3 = new BigDecimal("1110.00");
    final BigDecimal price4 = new BigDecimal("350.00");
    final BigDecimal price5 = new BigDecimal("1500.00");
    final BigDecimal price6 = new BigDecimal("643.1818");
    final BigDecimal quantity1 = new BigDecimal("33");
    final BigDecimal quantity2 = BigDecimal.ONE;

    try {//w w w.j  a v a2  s.c o  m

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product = createProduct(price1);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity2.multiply(price2));
        amountList.add(quantity2.multiply(price3));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt);
        LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price4,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(0), false);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(0),
                purchaseInvoiceLandedCost1.getInvoiceLineList().get(0));

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost2 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE1_ID, price5,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost2.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(1), false);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(1),
                purchaseInvoiceLandedCost2.getInvoiceLineList().get(0));

        // Assert product transactions
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        assertProductTransaction(product.getId(), productTransactionAssertList1);

        // Assert product costing
        List<MaterialTransaction> transactionList = getProductTransactions(product.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price6, quantity1));
        assertProductCosting(product.getId(), productCostingAssertList1);

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC701() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("700.00");
    final BigDecimal price2 = new BigDecimal("315.00");
    final BigDecimal price3 = new BigDecimal("1110.00");
    final BigDecimal price4 = new BigDecimal("250.00");
    final BigDecimal price5 = new BigDecimal("1000.00");
    final BigDecimal price6 = new BigDecimal("757.00");
    final BigDecimal quantity1 = new BigDecimal("25");
    final BigDecimal quantity2 = BigDecimal.ONE;

    try {/*from  w ww .ja  v a 2 s.  com*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product = createProduct(price1);

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt = createGoodsReceipt(product, price1, quantity1, day0);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity2.multiply(price2));
        amountList.add(quantity2.multiply(price3));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt);
        LandedCost landedCost = createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1);

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost1 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price4,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(0), false);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(0),
                purchaseInvoiceLandedCost1.getInvoiceLineList().get(0));

        // Create purchase invoice with landed cost, post it and assert it
        Invoice purchaseInvoiceLandedCost2 = createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE1_ID, price5,
                quantity2, day2);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost2.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(1), false);

        // Post landed cost cost and assert it
        postLandedCostLine(landedCost.getLandedCostCostList().get(1),
                purchaseInvoiceLandedCost2.getInvoiceLineList().get(0));

        // Assert product transactions
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        assertProductTransaction(product.getId(), productTransactionAssertList1);

        // Assert product costing
        List<MaterialTransaction> transactionList = getProductTransactions(product.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList.get(0), price1, price1, price6, quantity1));
        assertProductCosting(product.getId(), productCostingAssertList1);

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList1 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList1.add(new CostAdjustmentAssert(transactionList.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void sendBpracticaRespuesta(ActionEvent event) {
    try {/*from   ww  w . j a  v a  2 s  .  co  m*/
        if (StringUtils.isBlank(this.getSelectedBpractica().getVmsjrespuesta())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                    "Campo requerido. Ingrese el mensaje a enviar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        } else {
            //this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml"));
            if (this.getChkDestacado()) {
                ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService");
                HashMap filter = new HashMap();
                filter.put("ntipoconocimientoid", Constante.BUENAPRACTICA);
                BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter);
                if (cant.intValue() >= 10) {
                    this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter));
                    RequestContext.getCurrentInstance().execute("PF('destDialog').show();");
                    return;
                }
            }
            this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text());
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User usuario = loginMB.getUser();
            ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                    .findBean("ConocimientoService");
            this.getSelectedBpractica().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            this.getSelectedBpractica()
                    .setVtitulo(StringUtils.upperCase(this.getSelectedBpractica().getVtitulo().trim()));
            if (this.getDescripcionPlain().length() < 400) {
                this.getSelectedBpractica().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain()));
            } else {
                this.getSelectedBpractica()
                        .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 399)));
            }
            this.getSelectedBpractica()
                    .setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
            this.getSelectedBpractica().setDfechamodificacion(new Date());
            this.getSelectedBpractica().setVusuariomodificacion(usuario.getVlogin());
            this.getSelectedBpractica()
                    .setVmsjrespuesta(this.getSelectedBpractica().getVmsjrespuesta().toUpperCase());
            conocimientoService.saveOrUpdate(this.getSelectedBpractica());

            GcmFileUtils.writeStringToFileServer(this.getSelectedBpractica().getVruta(), "html.txt",
                    this.getDescripcionHtml());
            GcmFileUtils.writeStringToFileServer(this.getSelectedBpractica().getVruta(), "plain.txt",
                    this.getDescripcionPlain());

            HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
            Historial lastHistorial = historialService
                    .getLastHistorialByConocimiento(this.getSelectedBpractica().getNconocimientoid());
            int lastversion;
            if (lastHistorial != null) {
                lastversion = lastHistorial.getNnumversion().intValue();
            } else {
                lastversion = 0;
            }
            String url = this.pathbp.concat(this.getSelectedBpractica().getNconocimientoid().toString())
                    .concat("/").concat(Integer.toString(lastversion + 1)).concat("/");

            ThistorialId thistorialId = new ThistorialId();
            thistorialId.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
            thistorialId.setNhistorialid(historialService.getNextPK());
            Historial historial = new Historial();
            historial.setId(thistorialId);
            historial.setNtipoconocimientoid(Constante.BUENAPRACTICA);
            historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
            historial.setVtitulo(this.getSelectedBpractica().getVtitulo());
            historial.setNactivo(BigDecimal.ONE);
            historial.setNsituacionid(this.getSelectedBpractica().getNsituacionid());
            historial.setVruta(url);
            historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
            historial.setDfechacreacion(new Date());
            historial.setVusuariocreacion(usuario.getVlogin());
            historial.setVmsjsolicita(this.getSelectedBpractica().getVmsjsolicita());
            historial.setVmsjrespuesta(this.getSelectedBpractica().getVmsjrespuesta());
            historialService.saveOrUpdate(historial);

            GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml());
            GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
                String url0 = this.getSelectedBpractica().getVruta().concat("s");
                String url1 = url.concat("s");
                SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService");
                SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder
                        .findBean("SeccionHistService");
                for (Seccion seccion : this.getListaSeccion()) {
                    String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/");
                    seccion.setVruta(ruta0);
                    if (seccion.getNseccionid() != null) {
                        seccion.setDfechamodificacion(new Date());
                        seccion.setVusuariomodificacion(usuario.getVlogin());
                    } else {
                        seccion.setNseccionid(seccionService.getNextPK());
                        seccion.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
                        seccion.setDfechacreacion(new Date());
                        seccion.setVusuariocreacion(usuario.getVlogin());
                    }
                    seccionService.saveOrUpdate(seccion);

                    seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text());
                    GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain());

                    String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/");
                    TseccionHistId tseccionHistId = new TseccionHistId();
                    tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    tseccionHistId.setNhistorialid(thistorialId.getNhistorialid());
                    tseccionHistId.setNseccionhid(seccionHistService.getNextPK());
                    SeccionHist seccionHist = new SeccionHist();
                    seccionHist.setId(tseccionHistId);
                    seccionHist.setNorden(seccion.getNorden());
                    seccionHist.setVruta(ruta1);
                    seccionHist.setVtitulo(seccion.getVtitulo());
                    seccionHist.setVusuariocreacion(usuario.getVlogin());
                    seccionHist.setDfechacreacion(new Date());
                    seccionHistService.saveOrUpdate(seccionHist);

                    GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml());
                    GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain());
                }
            }

            this.setListaTargetVinculos(new ArrayList());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
            this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());

            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
                VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                        .findBean("VinculoHistService");
                vinculoService.deleteByConocimiento(this.getSelectedBpractica().getNconocimientoid());
                for (Consulta consulta : this.getListaTargetVinculos()) {
                    Vinculo vinculo = new Vinculo();
                    vinculo.setNvinculoid(vinculoService.getNextPK());
                    vinculo.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
                    vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                    vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                    vinculo.setDfechacreacion(new Date());
                    vinculo.setVusuariocreacion(usuario.getVlogin());
                    vinculoService.saveOrUpdate(vinculo);

                    TvinculoHistId vinculoHistId = new TvinculoHistId();
                    vinculoHistId.setNvinculohid(vinculoHistService.getNextPK());
                    vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid());
                    vinculoHistId.setNhistorialid(thistorialId.getNhistorialid());
                    VinculoHist vinculoHist = new VinculoHist();
                    vinculoHist.setId(vinculoHistId);
                    vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc());
                    vinculoHist.setDfechacreacion(new Date());
                    vinculoHist.setVusuariocreacion(usuario.getVlogin());
                    vinculoHistService.saveOrUpdate(vinculoHist);
                }
            }

            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("10")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.BUENAPRACTICA);
            asignacion.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService
                    .getCategoriaById(this.getSelectedBpractica().getNcategoriaid()).getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            loginMB.refreshNotifications();

            this.fSInfMod = "true";
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                    "Se respondi la solicitud de informacin.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}