Search in sources :

Example 16 with UniqueUnitEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.

the class PriceCoreOperation method store.

/**
 * Stores the supplied Prices to units and the manufacturerPartNoPriceFixeds
 *
 * @param pers     results to store
 * @param comment  a comment for the price history
 * @param arranger a arranger for the price history
 * @param monitor  an optional monitor
 */
public void store(final List<PriceEngineResult> pers, String comment, String arranger, IMonitor monitor) {
    final SubMonitor m = SubMonitor.convert(monitor, pers.size() + 27);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductEao productEao = new ProductEao(uuEm);
    // preload sopo and unique units
    m.message("Preloading UniqueUnits");
    NavigableMap<String, UniqueUnit> uniqueUnits = UniqueUnit.asMapByRefurbishId(uniqueUnitEao.findByIdentifiers(REFURBISHED_ID, PriceEngineResult.toRefurbishIds(pers)));
    m.worked(5);
    for (PriceEngineResult per : pers) {
        String msg = "Storing Unit " + per.getRefurbishedId() + " HP:" + per.getRetailerPrice() + " EP:" + per.getCustomerPrice() + " UnitFix:" + per.getUnitPriceFixed() + " ProductFix:" + per.getManufacturerPartPriceFixed();
        L.info(msg);
        m.worked(1, msg);
        update(uniqueUnits.get(per.getRefurbishedId()), per, arranger, comment);
    }
    // Inferenced filtering for fixprices
    Map<String, PriceEngineResult> fixPriceImports = new HashMap<>();
    for (PriceEngineResult per : pers) {
        if (per.getManufacturerPartPriceFixed() == NO_CHANGE)
            continue;
        fixPriceImports.put(per.getManufacturerPartNo(), per);
    }
    m.worked(1, "Perloading Products");
    NavigableMap<String, Product> products = Product.asMapByPartNos(productEao.findByPartNos(PriceEngineResult.toPartNos(pers)));
    m.worked(3);
    m.setWorkRemaining(fixPriceImports.size());
    for (PriceEngineResult per : fixPriceImports.values()) {
        update(products.get(per.getManufacturerPartNo()), per, arranger, comment);
        String msg = "Storing ProductDescription Fixed Price " + per.getProductName() + " Retailer:" + per.getRetailerPrice() + " Customer:" + per.getCustomerPrice() + " Manual:" + per.getManufacturerPartPriceFixed();
        L.info(msg);
        m.worked(1, msg);
    }
    m.finish();
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 17 with UniqueUnitEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.

the class PriceCoreOperation method loadAndCalculate.

/**
 * Loads all AVAILABLE SopoUnits from the Sopodb an puts them trough the PriceEngine
 *
 * @param monitor
 * @return
 */
public List<PriceEngineResult> loadAndCalculate(IMonitor monitor) {
    L.info("Starting loadAndCalculate()");
    final SubMonitor m = SubMonitor.convert(monitor, 100);
    m.start();
    final StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    m.message("loading Units");
    List<Integer> uuids = stockUnitEao.findByNoLogicTransactionAsUniqueUnitId();
    List<UniqueUnit> uus = uniqueUnitEao.findByIds(uuids);
    m.worked(10, "updating Eols");
    updateEols(uus);
    m.worked(5, "loading ProductSpecs");
    Set<Product> products = toProducts(uus);
    List<ProductSpec> productSpecs = productSpecEao.findByProductIds(toProductIds(products));
    Map<Product, ProductSpec> productToSpecs = toProductProductSpec(products, productSpecs);
    m.worked(10);
    final List<PriceEngineResult> pers = new ArrayList<>();
    m.setWorkRemaining(uus.size() + 5);
    for (UniqueUnit uu : uus) {
        m.worked(1, "Calculating RefurbishId(" + uu.getRefurbishId() + ")");
        StockUnit su = stockUnitEao.findByUniqueUnitId(uu.getId());
        pers.add(priceEngine.estimate(uu, productToSpecs.get(uu.getProduct()), su.getStock() != null ? su.getStock().getName() : "kein Lager"));
    }
    m.finish();
    L.info("Finished loadAndCalculate(), estimated {} Units", pers.size());
    return pers;
}
Also used : PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 18 with UniqueUnitEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.

the class DocumentSupporterOperation method toXls.

@Override
public FileJacket toXls(String identifier) {
    DossierEao dossierEao = new DossierEao(redTapeEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    List<Dossier> dossiers = dossierEao.findByIdentifier(identifier);
    if (dossiers.isEmpty())
        return null;
    Map<String, List<Object[]>> datas = new HashMap<>();
    for (Dossier dossier : dossiers) {
        for (Document document : dossier.getActiveDocuments()) {
            List<Object[]> rows = new ArrayList<>();
            datas.put(dossier.getIdentifier() + "_" + document.getType().getName() + "_" + (document.getIdentifier() == null ? "" : document.getIdentifier()), rows);
            for (Position pos : document.getPositions().values()) {
                if (pos.getUniqueUnitId() > 0) {
                    UniqueUnit uu = uniqueUnitEao.findById(pos.getUniqueUnitId());
                    rows.add(new Object[] { pos.getType().getName(), pos.getAmount(), pos.getName(), pos.getPrice(), pos.toAfterTaxPrice(), DateFormats.ISO.format(uu.getMfgDate()), uu.getProduct().getPrice(PriceType.MANUFACTURER_COST) });
                } else {
                    rows.add(new Object[] { pos.getType().getName(), pos.getAmount(), pos.getName(), pos.getPrice(), pos.toAfterTaxPrice(), null, null });
                }
            }
        }
    }
    STable template = new STable();
    CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
    CFormat date = new CFormat(CENTER, SHORT_DATE);
    CFormat percent = new CFormat(ITALIC, BLUE, null, null, null, PERCENT_FLOAT);
    template.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    template.add(new STableColumn("Type", 7)).add(new STableColumn("Menge", 10)).add(new STableColumn("Name", 30)).add(new STableColumn("Preis", 15, euro)).add(new STableColumn("Preis inc. Mwst", 15, euro)).add(new STableColumn("MfgDate", 13, date)).add(new STableColumn("CostPrice", 12, euro)).add(new STableColumn("%Cost", 12, percent).setAction(new SFormulaAction(SR(3), "/", SR(6))));
    CCalcDocument document = new TempCalcDocument();
    for (Map.Entry<String, List<Object[]>> entry : datas.entrySet()) {
        CSheet sheet = new CSheet(entry.getKey());
        STable table = new STable(template);
        table.setModel(new STableModelList(entry.getValue()));
        sheet.addBelow(table);
        document.add(sheet);
    }
    FileJacket fj = new FileJacket("Dossiers", ".xls", new JExcelLucidCalcWriter().write(document));
    return fj;
}
Also used : DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)

Example 19 with UniqueUnitEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.

the class UniqueUnitEaoIT method testFindByProductPartNosInputDate.

@Test
public void testFindByProductPartNosInputDate() throws Exception {
    utx.begin();
    em.joinTransaction();
    UniqueUnitEao unitEao = new UniqueUnitEao(em);
    List<UniqueUnit> uus = unitEao.findByProductPartNosInputDate(Arrays.asList(PARTNO_1, PARTNO_2), _2012_12_02_, _2012_12_10_);
    assertFalse(uus.isEmpty());
    assertEquals(3, uus.size());
    utx.commit();
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 20 with UniqueUnitEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.

the class UniqueUnitEaoIT method testFindPartIdentifier.

@Test
public void testFindPartIdentifier() throws Exception {
    utx.begin();
    em.joinTransaction();
    UniqueUnitEao unitEao = new UniqueUnitEao(em);
    assertTrue(unitEao.findByPartialIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, "632*").isEmpty());
    assertTrue(unitEao.findByPartialIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, "623*").contains(unit_62325));
    utx.commit();
}
Also used : UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Aggregations

UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)49 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)38 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)21 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)19 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)17 FileJacket (eu.ggnet.dwoss.util.FileJacket)10 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)9 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)6 File (java.io.File)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)5 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)5 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)5 CFormat (eu.ggnet.lucidcalc.CFormat)5 CSheet (eu.ggnet.lucidcalc.CSheet)5 STable (eu.ggnet.lucidcalc.STable)5 STableColumn (eu.ggnet.lucidcalc.STableColumn)5 STableModelList (eu.ggnet.lucidcalc.STableModelList)5 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)5 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)4 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)4