Search in sources :

Example 36 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class ContractorPricePartNoExporterOperation method toManufacturerMissingXls.

@Override
public FileJacket toManufacturerMissingXls(TradeName contractorManufacturer) {
    if (!contractorManufacturer.isManufacturer())
        throw new RuntimeException(contractorManufacturer + " is not a Manufacturer, wrong exporter");
    SubMonitor m = monitorFactory.newSubMonitor("Lieferanten und Hersteller Exporter");
    m.message("Loading Units").start();
    List<Object[]> rows = productEao.findByTradeNames(contractorManufacturer.getBrands()).stream().filter(p -> p.getPrice(MANUFACTURER_COST) <= 0.01).sorted().map(p -> new Object[] { p.getPartNo(), 0.0, ProductFormater.toName(p) }).collect(Collectors.toList());
    m.setWorkRemaining(rows.size() + 10).message("Filtering");
    m.message("Generating Document");
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC));
    table.add(new STableColumn("Artikelnummer", 18)).add(new STableColumn("Kostpreis", 12, new CFormat(CURRENCY_EURO))).add(new STableColumn("Name", 45));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument();
    cdoc.add(new CSheet("Kostpreise", table));
    FileJacket result = new FileJacket("Fehlende " + contractorManufacturer.getName() + " Kostpreise vom " + ISO.format(new Date()), ".xls", new JExcelLucidCalcWriter().write(cdoc));
    m.finish();
    return result;
}
Also used : Stateless(javax.ejb.Stateless) CURRENCY_EURO(eu.ggnet.lucidcalc.CFormat.Representation.CURRENCY_EURO) TradeName(eu.ggnet.dwoss.rules.TradeName) ProductFormater(eu.ggnet.dwoss.uniqueunit.ee.format.ProductFormater) Date(java.util.Date) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) WHITE(java.awt.Color.WHITE) Collectors(java.util.stream.Collectors) ISO(eu.ggnet.dwoss.util.DateFormats.ISO) CONTRACTOR_REFERENCE(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CONTRACTOR_REFERENCE) Inject(javax.inject.Inject) BLACK(java.awt.Color.BLACK) List(java.util.List) MANUFACTURER_COST(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.MANUFACTURER_COST) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) eu.ggnet.lucidcalc(eu.ggnet.lucidcalc) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) BOLD_ITALIC(eu.ggnet.lucidcalc.CFormat.FontStyle.BOLD_ITALIC) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) Date(java.util.Date) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)

Example 37 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class SalesChannelHandlerOperation method update.

/**
 * Updates the salesChanel of all supplied units
 * <p/>
 * @param lines              a list of salesChannelLines, must not be null.
 * @param arranger
 * @param transactionComment
 * @return true if something was changed.
 * @throws de.dw.util.UserInfoException
 */
@Override
public boolean update(final List<SalesChannelLine> lines, String arranger, String transactionComment) throws UserInfoException {
    SubMonitor m = monitorFactory.newSubMonitor("Import der Verkaufskanäle", 100);
    m.start();
    Map<Stock, List<Integer>> destinationsWithStockUnitIds = lines.stream().filter(// No Destination change
    l -> l.getDestination() != null).sorted(// Sort
    new LastCharsRefurbishIdSorter()).collect(Collectors.groupingBy(SalesChannelLine::getDestination, Collectors.mapping(SalesChannelLine::getUnitId, Collectors.toList())));
    StockTransactionEmo emo = new StockTransactionEmo(stockEm);
    SortedMap<Integer, String> histories = new TreeMap<>();
    for (Entry<Stock, List<Integer>> entry : destinationsWithStockUnitIds.entrySet()) {
        histories.putAll(emo.prepare(Transfer.builder().destinationStockId(entry.getKey().getId()).stockUnitIds(entry.getValue()).arranger(arranger).comment(transactionComment).maxTransactionSize(10).build(), m));
    }
    m.setWorkRemaining(lines.size());
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    boolean hasChanged = false;
    for (SalesChannelLine line : lines) {
        m.worked(1, "verarbeite " + line.getRefurbishedId());
        if (!line.hasChanged())
            continue;
        hasChanged = true;
        UniqueUnit uu = uniqueUnitEao.findByIdentifier(Identifier.REFURBISHED_ID, line.getRefurbishedId());
        uu.setSalesChannel(line.getSalesChannel());
        uu.addHistory("SalesChannel set to " + line.getSalesChannel() + " by " + arranger);
        if (histories.containsKey(uu.getId()))
            uu.addHistory(histories.get(uu.getId()));
    }
    m.finish();
    return hasChanged;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) SalesChannelLine(eu.ggnet.dwoss.stock.ee.model.SalesChannelLine) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)

Example 38 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor 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 39 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class FtpTransfer method upload.

/**
 * Uploads a some files to a remove ftp host.
 * <p/>
 * @param config  the config for he connection.
 * @param uploads the upload commands
 * @param monitor an optional monitor.
 * @throws java.net.SocketException
 * @throws java.io.IOException
 */
public static void upload(ConnectionConfig config, IMonitor monitor, UploadCommand... uploads) throws SocketException, IOException {
    if (uploads == null || uploads.length == 0)
        return;
    SubMonitor m = SubMonitor.convert(monitor, "FTP Transfer", toWorkSize(uploads) + 4);
    m.message("verbinde");
    m.start();
    FTPClient ftp = new FTPClient();
    ftp.addProtocolCommandListener(PROTOCOL_TO_LOGGER);
    try {
        ftp.connect(config.getHost(), config.getPort());
        if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()))
            throw new IOException("FTPReply.isPositiveCompletion(ftp.getReplyCode()) = false");
        if (!ftp.login(config.getUser(), config.getPass()))
            throw new IOException("Login with " + config.getUser() + " not successful");
        L.info("Connected to {} idenfied by {}", config.getHost(), ftp.getSystemType());
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
        for (UploadCommand upload : uploads) {
            m.worked(1, "uploading to " + upload.getPath());
            ftp.changeWorkingDirectory(upload.getPath());
            deleteFilesByType(ftp, upload.getDeleteFileTypes());
            for (File file : upload.getFiles()) {
                m.worked(1, "uploading to " + upload.getPath() + " file " + file.getName());
                try (InputStream input = new FileInputStream(file)) {
                    if (!ftp.storeFile(file.getName(), input))
                        throw new IOException("Cannot store file " + file + " on server!");
                }
            }
        }
        m.finish();
    } finally {
        // just cleaning up
        try {
            ftp.logout();
        } catch (IOException e) {
        }
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
            }
        }
    }
}
Also used : UploadCommand(eu.ggnet.dwoss.mandator.api.service.FtpConfiguration.UploadCommand) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) IOException(java.io.IOException) File(java.io.File) FTPFile(org.apache.commons.net.ftp.FTPFile) FTPClient(org.apache.commons.net.ftp.FTPClient) FileInputStream(java.io.FileInputStream)

Example 40 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor 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

SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)63 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)23 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)21 FileJacket (eu.ggnet.dwoss.util.FileJacket)18 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)16 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)14 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)12 File (java.io.File)12 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)11 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)9 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)8 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)7 Inject (javax.inject.Inject)7 Test (org.junit.Test)7 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)6 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)6 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)6 CFormat (eu.ggnet.lucidcalc.CFormat)6 CSheet (eu.ggnet.lucidcalc.CSheet)6 STable (eu.ggnet.lucidcalc.STable)6