Search in sources :

Example 6 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader 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

LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)6 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)4 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)4 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)3 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)3 File (java.io.File)2 Test (org.junit.Test)2 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)1 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)1 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)1 PartNoSupport (eu.ggnet.dwoss.rules.partno.PartNoSupport)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 Matcher (java.util.regex.Matcher)1