Search in sources :

Example 11 with ProductEao

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

the class ContractorPricePartNoImporterOperation method fromManufacturerXls.

@Override
public Reply<Void> fromManufacturerXls(TradeName contractorManufacturer, FileJacket inFile, String arranger) {
    if (!contractorManufacturer.isManufacturer())
        throw new RuntimeException(contractorManufacturer + " is not a Manufacturer");
    final SubMonitor m = monitorFactory.newSubMonitor(contractorManufacturer.getName() + " Costpreise importieren", 100);
    m.start().message("Reading File");
    ProductEao productEao = new ProductEao(uuEm);
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class).addColumn(1, Double.class);
    List<ManufacturerImport> imports = reader.read(inFile.toTemporaryFile(), ManufacturerImport.class);
    List<String> errors = reader.getErrors();
    m.worked(5);
    m.setWorkRemaining(imports.size());
    L.info("Imports: {}", imports);
    PartNoSupport partNoSupport = contractorManufacturer.getPartNoSupport();
    int databaseLines = 0;
    int newPrices = 0;
    int updatedPrices = 0;
    for (ManufacturerImport mi : imports) {
        m.worked(1);
        if (partNoSupport != null && !partNoSupport.isValid(mi.partNo)) {
            errors.add(partNoSupport.violationMessages(mi.partNo));
            continue;
        }
        if (mi.costPrice == null || mi.costPrice <= 0.01) {
            errors.add("PartNo " + mi.costPrice + " hat keinen Preis");
            continue;
        }
        m.message("Importing (" + mi.partNo + ")");
        Product p = productEao.findByPartNo(mi.partNo);
        if (p == null) {
            errors.add("No UniqueUnit Entity for PartNo " + mi.partNo);
            continue;
        }
        databaseLines++;
        if (mi.getCostPrice() > 0.01 && !TwoDigits.equals(mi.getCostPrice(), p.getPrice(MANUFACTURER_COST))) {
            if (p.hasPrice(MANUFACTURER_COST))
                updatedPrices++;
            else
                newPrices++;
            p.setPrice(PriceType.MANUFACTURER_COST, mi.costPrice, "Import by " + arranger);
        }
    }
    m.finish();
    String summary = "Zeilen, mit gefunden (db)Artikeln: " + databaseLines + " \n" + "Neue Preise hinterlegt: " + newPrices + "\n" + "Preise aktualisiert: " + updatedPrices;
    StringBuilder details = new StringBuilder();
    for (Object error : errors) {
        details.append(error.toString()).append("\n");
    }
    m.finish();
    if (newPrices + updatedPrices == 0)
        return Reply.failure(summary, details.toString());
    else
        return Reply.success(null, summary, details.toString());
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) PartNoSupport(eu.ggnet.dwoss.rules.partno.PartNoSupport)

Example 12 with ProductEao

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

the class ProductOperation method updatePrice.

/**
 * Update a price of a product by id.
 * <p/>
 * @param productId the product id
 * @param priceType the type of price to update
 * @param price     the price
 * @param comment   the comment for the price history
 * @return the updated product
 */
public Product updatePrice(long productId, PriceType priceType, double price, String comment) {
    Product product = new ProductEao(uus).findById(productId);
    if (product == null)
        return null;
    product.setPrice(priceType, price, comment);
    return product;
}
Also used : Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)

Aggregations

ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)12 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)11 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)5 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)4 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)3 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)3 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)2 DisplayAble (eu.ggnet.dwoss.spec.ee.entity.DisplayAble)2 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)1 WarrantyService (eu.ggnet.dwoss.mandator.api.service.WarrantyService)1 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)1 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 PartNoSupport (eu.ggnet.dwoss.rules.partno.PartNoSupport)1 CpuEao (eu.ggnet.dwoss.spec.ee.eao.CpuEao)1 DisplayEao (eu.ggnet.dwoss.spec.ee.eao.DisplayEao)1 GpuEao (eu.ggnet.dwoss.spec.ee.eao.GpuEao)1