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 testCostingLC801() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("800.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("850.00");
    final BigDecimal quantity1 = new BigDecimal("25");
    final BigDecimal quantity2 = BigDecimal.ONE;
    final BigDecimal amount1 = new BigDecimal("1425.00");
    final BigDecimal amount2 = new BigDecimal("-65.00");
    final BigDecimal amount3 = new BigDecimal("-110.00");

    try {//  w w  w.  ja  v  a2s . co  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), 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(LANDEDCOSTTYPE1_ID, price5,
                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, 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", amount1, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList2
                .add(new CostAdjustmentAssert(transactionList.get(0), "LC", amount2, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList3 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList3
                .add(new CostAdjustmentAssert(transactionList.get(0), "LC", amount3, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList3);
        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 testCostingLC900() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("900.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("940.7143");
    final BigDecimal quantity1 = new BigDecimal("35");
    final BigDecimal quantity2 = BigDecimal.ONE;

    try {//  w  ww . j ava 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(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
        createPurchaseInvoiceLandedCost(LANDEDCOSTTYPE2_ID, price4, quantity2, day2);

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

        // Match invoice landed cost
        matchInvoiceLandedCost(landedCost.getLandedCostCostList().get(0), true,
                "The Landed Cost Cost does not have any matching available.");

        // Match invoice landed cost
        matchInvoiceLandedCost(landedCost.getLandedCostCostList().get(1), true,
                "The Landed Cost Cost does not have any matching available.");

        // 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 testCostingLC1000() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int year = -1;
    final BigDecimal price1 = new BigDecimal("1000.00");
    final BigDecimal price2 = new BigDecimal("650.00");
    final BigDecimal price3 = new BigDecimal("500.00");
    final BigDecimal price4 = new BigDecimal("1022.2222");
    final BigDecimal quantity1 = new BigDecimal("45");
    final BigDecimal quantity2 = new BigDecimal("7");
    final BigDecimal quantity3 = BigDecimal.ONE;
    final String productType = "S";
    final String costType = "STA";

    try {/*w  ww  .j a v a 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);

        // Create a new product for the test
        Product product2 = createProduct(productType, price2, price3, costType, year);

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

        // Create goods receipt, run costing background, post it and assert it
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(product2, price3, quantity2, day0);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity3.multiply(price1));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day1);

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

        // Assert product transactions 2
        assertTrue(getProductTransactions(product2.getId()).isEmpty());

        // 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, price4, quantity1));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2.add(new ProductCostingAssert(null, null, null, price3, null, costType, year));
        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), "LC",
                quantity1.multiply(price4).add(quantity1.multiply(price1).negate()), day1, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        assertEquals(getCostAdjustment(product2.getId()), null);

        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 sendOmejoraRespuesta(ActionEvent event) {
    try {/*from  w ww  . jav  a2 s .  c o m*/
        if (StringUtils.isBlank(this.getSelectedOmejora().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.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()
                    .setVmsjrespuesta(this.getSelectedOmejora().getVmsjrespuesta().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("10")));
            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")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService
                    .getCategoriaById(this.getSelectedOmejora().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.",
                    "Respuesta de la solicitud de informacin enviada.");
            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 testCostingLC802() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final BigDecimal price1 = new BigDecimal("800.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("850.00");
    final BigDecimal quantity1 = new BigDecimal("25");
    final BigDecimal quantity2 = BigDecimal.ONE;
    final BigDecimal amount1 = new BigDecimal("1425.00");
    final BigDecimal amount2 = new BigDecimal("-65.00");
    final BigDecimal amount3 = new BigDecimal("-110.00");

    try {//w w w.j av a  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(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), 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(LANDEDCOSTTYPE1_ID, price5,
                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, 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", amount1, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList1);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList2 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList2
                .add(new CostAdjustmentAssert(transactionList.get(0), "LC", amount2, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList2);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList3 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList3
                .add(new CostAdjustmentAssert(transactionList.get(0), "LC", amount3, day1, true, false));
        costAdjustmentAssertList.add(costAdjustmentAssertLineList3);
        assertCostAdjustment(costAdjustmentList, costAdjustmentAssertList);

        // Reactivate landed cost
        reactivateLandedCost(landedCost.getId(), "This document is posted");

        // Unpost landed cost
        unpostDocument(landedCost);

        // Reactivate landed cost
        reactivateLandedCost(landedCost.getId(), "This document is posted: tab Cost - line 10");

        // Unpost landed cost cost
        unpostDocument(landedCost.getLandedCostCostList().get(0));

        // Reactivate landed cost
        reactivateLandedCost(landedCost.getId(), "This document is posted: tab Cost - line 20");

        // Unpost landed cost cost
        unpostDocument(landedCost.getLandedCostCostList().get(1));

        // Reactivate landed cost
        reactivateLandedCost(landedCost.getId(), null);

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

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

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList21 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList21
                .add(new CostAdjustmentAssert(transactionList2.get(0), "LC", amount1, day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList21);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList22 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList22
                .add(new CostAdjustmentAssert(transactionList2.get(0), "LC", amount2, day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList22);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList23 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList23
                .add(new CostAdjustmentAssert(transactionList2.get(0), "LC", amount3, day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList23);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList24 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList24.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                amount1.negate(), day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList24);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList25 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList25.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                amount2.negate(), day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList25);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList26 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList26.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                amount3.negate(), day1, true, false, "VO"));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList26);
        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 testCostingLC702() 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 price7 = new BigDecimal("750.00");
    final BigDecimal quantity1 = new BigDecimal("25");
    final BigDecimal quantity2 = BigDecimal.ONE;
    final BigDecimal amount1 = new BigDecimal("-65.00");
    final BigDecimal amount2 = new BigDecimal("-110.00");

    try {/*from   w  w  w  . ja v a 2s  . 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);

        // Cancel landed cost cost
        cancelLandedCostCost(landedCost.getLandedCostCostList().get(0).getId(), "This document is posted");

        // Unpost landed cost cost
        unpostDocument(landedCost.getLandedCostCostList().get(0));

        // Cancel landed cost cost
        cancelLandedCostCost(landedCost.getLandedCostCostList().get(0).getId(), null);

        // Cancel landed cost cost
        cancelLandedCostCost(landedCost.getLandedCostCostList().get(1).getId(), "This document is posted");

        // Unpost landed cost cost
        unpostDocument(landedCost.getLandedCostCostList().get(1));

        // Cancel landed cost cost
        cancelLandedCostCost(landedCost.getLandedCostCostList().get(1).getId(), null);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost1.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(0),
                OBDal.getInstance().get(LandedCostCost.class, landedCost.getLandedCostCostList().get(0).getId())
                        .getLandedCostMatchedList().get(0),
                true);

        // Match invoice landed cost
        matchInvoiceLandedCost(purchaseInvoiceLandedCost2.getInvoiceLineList().get(0),
                landedCost.getLandedCostCostList().get(1),
                OBDal.getInstance().get(LandedCostCost.class, landedCost.getLandedCostCostList().get(1).getId())
                        .getLandedCostMatchedList().get(0),
                true);

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

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

        // Assert cost adjustment
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList21 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day1, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList21);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList22 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList22
                .add(new CostAdjustmentAssert(transactionList2.get(0), "LC", amount1, day1, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList22);
        List<CostAdjustmentAssert> costAdjustmentAssertLineList23 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList23
                .add(new CostAdjustmentAssert(transactionList2.get(0), "LC", amount2, day1, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList23);
        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 String publicarWiki() {
    String pagina = null;/*  w w  w . j  a  va  2 s .  c  o m*/
    try {
        //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().setNsituacionid(BigDecimal.valueOf((long) 6));
        this.getSelectedWiki().setDfechapublicacion(new Date());
        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("8")));
        serviceasig.saveOrUpdate(this.getSelectedAsignacion());

        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.", "Se public el wiki.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
    return pagina;
}

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

@Test
public void testCostingLC1111() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("113.1428");
    final BigDecimal price7 = new BigDecimal("111.9740");
    final BigDecimal price8 = new BigDecimal("226.2857");
    final BigDecimal price9 = new BigDecimal("224.8572");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {/* w w  w . j a v a  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);

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

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

        // 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 purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

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

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

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // 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(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        createLandedCost(landedCostTypeIdList, amountList, receiptList, null, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, 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(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // 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));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        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, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price9,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, null, price3, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, null, price3,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // 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), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, 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> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        assertEquals(getCostAdjustment(product3.getId()), null);

        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 publicarBpractica(ActionEvent event) {
    try {/*from w  w w .j  a  v a2  s  .  c o  m*/
        //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().setNsituacionid(BigDecimal.valueOf((long) 6));
        this.getSelectedBpractica().setDfechapublicacion(new Date());
        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("8")));
        serviceasig.saveOrUpdate(this.getSelectedAsignacion());

        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Se public la buena prctica.");
        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 testCostingLC1112() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("113.1428");
    final BigDecimal price7 = new BigDecimal("111.9740");
    final BigDecimal price8 = new BigDecimal("226.2857");
    final BigDecimal price9 = new BigDecimal("224.8572");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {//from   www .j  av  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 product1 = createProduct(price1);

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

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

        // 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 purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

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

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

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // 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(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt1);
        List<ShipmentInOutLine> receiptLineList = new ArrayList<ShipmentInOutLine>();
        receiptLineList.add(goodsReceipt1.getMaterialMgmtShipmentInOutLineList().get(0));
        receiptLineList.add(goodsReceipt1.getMaterialMgmtShipmentInOutLineList().get(1));
        createLandedCost(landedCostTypeIdList, amountList, receiptList, receiptLineList, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, 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(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // 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));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        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, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price9,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, null, price3, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, null, price3,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // 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), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, 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> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        assertEquals(getCostAdjustment(product3.getId()), null);

        OBDal.getInstance().commitAndClose();

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

    finally {
        OBContext.restorePreviousMode();
    }
}