Search in sources :

Example 1 with PartNoSupport

use of eu.ggnet.dwoss.rules.partno.PartNoSupport 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)

Aggregations

SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 PartNoSupport (eu.ggnet.dwoss.rules.partno.PartNoSupport)1 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1 LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)1 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)1