Search in sources :

Example 16 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class ExporterOperation method toXls.

/**
 * Creates a price compare sheet, expects a list of partNos and returns a xls File with last sales and estimated generated price
 *
 * @param partNos the partNos to inspect
 * @return the xls file with informations
 */
private FileJacket toXls(String... partNos) {
    // Create a Produkt with the part no;
    SubMonitor m = monitorFactory.newSubMonitor("Auswertung über PartNos", partNos.length + 10);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    StockUnitEao suEao = new StockUnitEao(stockEm);
    DocumentEao documentEao = new DocumentEao(redTapeEm);
    List<List<Object>> model = new ArrayList<>();
    for (String partNo : partNos) {
        m.worked(1, "loading: " + partNo);
        List<Object> line = new ArrayList<>();
        model.add(line);
        partNo = partNo.trim();
        line.add(partNo);
        List<UniqueUnit> uus = uniqueUnitEao.findByProductPartNo(partNo);
        if (uus.isEmpty()) {
            line.add("Keine Geräte oder Produkte im System.");
            for (int i = 0; i < 14; i++) line.add(null);
            continue;
        }
        Product product = uus.get(0).getProduct();
        line.add(ProductFormater.toName(product));
        line.add(uus.size());
        line.add(maxPrice(uus, PriceType.CUSTOMER));
        line.add(minPrice(uus, PriceType.RETAILER));
        List<Document> documents = documentEao.findInvoiceWithProdcutId(product.getId());
        for (int i = 0; i < 3; i++) {
            if (documents.size() > i) {
                // TODO: Was balancingId
                line.add(documents.get(i).getActual());
                line.add(priceByProductId(documents.get(i), product.getId()));
            } else {
                line.add(null);
                line.add(null);
            }
        }
        PriceEngineResult per = priceEngine.estimate(uus.get(0), productSpecEao.findByProductId(product.getId()), suEao.findByUniqueUnitId(uus.get(0).getId()).getStock().getName());
        line.add(per.getCostPrice());
        line.add(per.getRetailerPrice());
        line.add(per.getCustomerPrice());
        line.add(per.getRulesLog());
    }
    m.message("creating File");
    STable table = new STable();
    CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
    CFormat date = new CFormat(CENTER, SHORT_DATE);
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("PartNo", 15)).add(new STableColumn("Name", 30));
    table.add(new STableColumn("Menge im System", 12));
    table.add(new STableColumn("VP(Min)", 12, euro)).add(new STableColumn("VP(Max)", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Cp", 12, euro)).add(new STableColumn("Hp", 12, euro)).add(new STableColumn("Ep", 12, euro));
    table.add(new STableColumn("Rules", 40));
    table.setModel(new STableModelList(model));
    CCalcDocument cdoc = new TempCalcDocument("PartNoPrice_");
    cdoc.add(new CSheet("PartNoPrice", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("PartNoPrice", ".xls", file);
    m.finish();
    return result;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) File(java.io.File)

Example 17 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class ExporterOperation method onePrice.

/**
 * Calculates a Price for on Unit.
 *
 * @param refurbishId the refurbishId
 * @return The PriceEngineResult or Null if Id not found
 */
@Override
public PriceEngineResult onePrice(String refurbishId) {
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    final StockUnitEao suEao = new StockUnitEao(stockEm);
    L.info("Loading s.getUnit({})", refurbishId);
    UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uu == null)
        return null;
    ProductSpec spec = productSpecEao.findByProductId(uu.getProduct().getId());
    String stock = suEao.findByUniqueUnitId(uu.getId()).getStock().getName();
    return priceEngine.estimate(uu, spec, stock);
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 18 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao 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 19 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class SalesChannelHandlerOperation method findAvailableUnits.

/**
 * Returns all units, which are in a stock. Units which are on a transaction, are not displayed.
 *
 * TODO: Turn it around. Fist take all StockUnits, which are not in a transaction. Then filter them against the SopoUnit information
 * <p/>
 * @return all units, which are in a stock
 */
@Override
public List<SalesChannelLine> findAvailableUnits() {
    SubMonitor m = monitorFactory.newSubMonitor("Verkaufskanalmanager vorbereiten", 100);
    m.setLogger(L);
    m.start();
    final UniqueUnitEao uniqueUnitService = new UniqueUnitEao(uuEm);
    List<SalesChannelLine> lines = new ArrayList<>();
    m.message("Loading all available units.");
    List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoTransaction();
    m.worked(10);
    m.setWorkRemaining(stockUnits.size() + 5);
    for (StockUnit stockUnit : stockUnits) {
        m.worked(1, "Handling SopoNr " + stockUnit.getRefurbishId());
        UniqueUnit uniqueUnit = uniqueUnitService.findById(stockUnit.getUniqueUnitId());
        if (uniqueUnit == null)
            throw new RuntimeException("StockUnit(id=" + stockUnit.getId() + ",uniqueUnitId=" + stockUnit.getUniqueUnitId() + ") has no uniqueUnit");
        if (uniqueUnit.getProduct() == null)
            L.warn("UniqueUnit(id=" + uniqueUnit.getId() + ").product==null");
        lines.add(SalesChannelLine.builder().unitId(stockUnit.getId()).refurbishedId(uniqueUnit.getRefurbishId()).description(ProductFormater.toName(uniqueUnit.getProduct())).comment((uniqueUnit.getEquipments().contains(Equipment.ORIGINAL_BOXED) ? "Originalkarton, " : "") + (uniqueUnit.getCondition().getNote())).retailerPrice(uniqueUnit.getPrice(RETAILER)).customerPrice(uniqueUnit.getPrice(CUSTOMER)).stockName(stockUnit.getStock().getName()).salesChannel(uniqueUnit.getSalesChannel()).originalSalesChannel(uniqueUnit.getSalesChannel()).stockId(stockUnit.getStock().getId()).build());
        m.worked(1);
    }
    m.finish();
    return lines;
}
Also used : SalesChannelLine(eu.ggnet.dwoss.stock.ee.model.SalesChannelLine) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 20 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class SalesListingProducerOperation method generatePdfListings.

/**
 * Generates PDF files for units in a specific sales channel.
 * The lists are seperated by brand.
 * <p>
 * @param channel the saleschannel
 * @return PDF files for units in a specific sales channel.
 */
private Map<TradeName, Collection<FileJacket>> generatePdfListings(SalesChannel channel) throws UserInfoException {
    SubMonitor m = monitorFactory.newSubMonitor("Endkundenlisten erstellen", 10);
    m.message("lade Gerätedaten");
    m.start();
    List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransaction();
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits));
    PriceType priceType = (channel == SalesChannel.CUSTOMER ? PriceType.CUSTOMER : PriceType.RETAILER);
    m.worked(2, "prüfe und filtere Geräte");
    SortedMap<UniqueUnit, StockUnit> uusus = toSortedMap(uniqueUnits, stockUnits, new UniqueUnitComparator());
    for (Iterator<Map.Entry<UniqueUnit, StockUnit>> it = uusus.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<UniqueUnit, StockUnit> entry = it.next();
        UniqueUnit uu = entry.getKey();
        StockUnit su = entry.getValue();
        if (uu == null)
            throw new NullPointerException(su + " has no UniqueUnit, Database Error");
        if (uu.getSalesChannel() != channel || !uu.hasPrice(priceType) || su.isInTransaction()) {
            it.remove();
        }
    }
    L.info("Selected {} Units for the Lists", uusus.size());
    m.worked(1, "sortiere und bereite Geräte vor");
    Map<Product, Set<UniqueUnit>> stackedUnits = new HashMap<>();
    for (Map.Entry<UniqueUnit, StockUnit> entry : uusus.entrySet()) {
        Product p = entry.getKey().getProduct();
        if (!stackedUnits.containsKey(p))
            stackedUnits.put(p, new HashSet<>());
        stackedUnits.get(p).add(entry.getKey());
    }
    List<StackedLine> stackedLines = new ArrayList<>(stackedUnits.size());
    DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
    df.applyPattern("#,###,##0.00");
    for (Map.Entry<Product, Set<UniqueUnit>> entry : stackedUnits.entrySet()) {
        Product p = entry.getKey();
        StackedLine line = new StackedLine();
        line.setBrand(p.getTradeName());
        line.setGroup(p.getGroup());
        line.setCommodityGroupName(p.getGroup().getNote());
        line.setDescription(p.getDescription());
        line.setManufacturerName(p.getTradeName().getName());
        line.setManufacturerPartNo(p.getPartNo());
        line.setName(p.getName());
        line.setImageUrl(imageFinder.findImageUrl(p.getImageId()));
        boolean priceChanged = false;
        double customerPrice = 0;
        for (UniqueUnit uu : entry.getValue()) {
            StackedLineUnit elem = new StackedLineUnit();
            elem.setAccessories(UniqueUnitFormater.toSingleLineAccessories(uu));
            elem.setComment(UniqueUnitFormater.toSingleLineComment(uu));
            elem.setConditionLevelDescription(uu.getCondition().getNote());
            elem.setMfgDate(uu.getMfgDate());
            elem.setRefurbishedId(uu.getRefurbishId());
            elem.setSerial(uu.getSerial());
            elem.setWarranty(uu.getWarranty().getName());
            if (uu.getWarranty().equals(Warranty.WARRANTY_TILL_DATE))
                elem.setWarrentyTill(uu.getWarrentyValid());
            double uuPrice = uu.getPrice(priceType);
            elem.setCustomerPrice(uuPrice);
            elem.setRoundedTaxedCustomerPrice(TwoDigits.roundedApply(uuPrice, GlobalConfig.DEFAULT_TAX.getTax(), 0.02));
            // For the "ab € XXX" handler
            if (customerPrice == 0) {
                customerPrice = uuPrice;
            } else if (customerPrice > uuPrice) {
                customerPrice = uuPrice;
                priceChanged = true;
            } else if (customerPrice < uuPrice) {
                priceChanged = true;
            }
            elem.normaize();
            line.add(elem);
        }
        line.setAmount(line.getUnits().size());
        line.setCustomerPriceLabel((priceChanged ? "ab €" : "€") + df.format(TwoDigits.roundedApply(customerPrice, GlobalConfig.DEFAULT_TAX.getTax(), 0.02)));
        line.normaize();
        stackedLines.add(line);
    }
    L.info("Created {} Lines for the Lists", stackedLines.size());
    m.worked(1, "erzeuge listen");
    Set<ListingConfiguration> configs = new HashSet<>();
    if (listingService.isAmbiguous() || listingService.isUnsatisfied()) {
        for (TradeName brand : TradeName.values()) {
            for (ProductGroup value : ProductGroup.values()) {
                configs.add(ListingConfiguration.builder().filePrefix("Geräteliste ").name(brand.getName() + " " + value.getName()).brand(brand).groups(EnumSet.of(value)).headLeft("Beispieltext Links\nZeile 2").headCenter("Beispieltext Mitte\nZeile 2").headRight("Beispieltext Rechts\nZeile 2").footer("Fusszeilentext").build());
            }
        }
    } else {
        configs.addAll(listingService.get().listingConfigurations());
    }
    m.setWorkRemaining(configs.size() + 1);
    Map<TradeName, Collection<FileJacket>> jackets = new HashMap<>();
    for (ListingConfiguration config : configs) {
        m.worked(1, "erstelle Liste " + config.getName());
        if (StringUtils.isBlank(config.getJasperTemplateFile()))
            config.setJasperTemplateFile(compileReportToTempFile("CustomerSalesListing"));
        if (StringUtils.isBlank(config.getJasperTempleteUnitsFile()))
            config.setJasperTempleteUnitsFile(compileReportToTempFile("CustomerSalesListingUnits"));
        FileJacket fj = createListing(config, stackedLines);
        if (fj != null) {
            if (!jackets.containsKey(config.getBrand()))
                jackets.put(config.getBrand(), new HashSet<>());
            jackets.get(config.getBrand()).add(fj);
        }
    }
    m.finish();
    return jackets;
}
Also used : DecimalFormat(java.text.DecimalFormat) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)

Aggregations

StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)29 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)25 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)19 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)9 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)6 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)5 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)5 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)4 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)3 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)3 FileJacket (eu.ggnet.dwoss.util.FileJacket)3 Test (org.junit.Test)3 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)2