Search in sources :

Example 1 with SalesChannelLine

use of eu.ggnet.dwoss.stock.ee.model.SalesChannelLine 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 2 with SalesChannelLine

use of eu.ggnet.dwoss.stock.ee.model.SalesChannelLine 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 3 with SalesChannelLine

use of eu.ggnet.dwoss.stock.ee.model.SalesChannelLine in project dwoss by gg-net.

the class SalesChannelManager method testSalesChannelManager.

@Test
public void testSalesChannelManager() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ex) {
    }
    final Stock laden = new Stock(0, "Laden");
    final Stock lager = new Stock(1, "Lager");
    Dl.remote().add(StockAgent.class, new StockAgent() {

        @Override
        public <T> List<T> findAll(Class<T> entityClass) {
            if (entityClass.equals(Stock.class))
                return (List<T>) Arrays.asList(laden, lager);
            return null;
        }

        // <editor-fold defaultstate="collapsed" desc="properties">
        @Override
        public StockUnit findStockUnitByUniqueUnitIdEager(Integer uniqueUnitId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockUnit findStockUnitByRefurbishIdEager(String refurbishId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockUnit> findStockUnitsByRefurbishIdEager(List<String> refurbishIds) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T persist(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T merge(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> void delete(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockTransaction findOrCreateRollInTransaction(int stockId, String userName, String comment) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> long count(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    JFrame f = new JFrame();
    SalesChannelManagerDialog dialog = new SalesChannelManagerDialog(f);
    List<SalesChannelLine> lines = new ArrayList<>();
    lines.add(new SalesChannelLine(0, "22231", "Acer Aspire 3222-üäö", "gebraucht", 10, 10, "Lager", SalesChannel.UNKNOWN, lager.getId()));
    lines.add(new SalesChannelLine(1, "23212", "Acer Aspire 5102WLMi-€", "gebraucht", 10, 10, "Lager", SalesChannel.RETAILER, lager.getId()));
    lines.add(new SalesChannelLine(2, "43521", "Acer Aspire X3200", "gebraucht", 10, 10, "Lager", SalesChannel.RETAILER, lager.getId()));
    lines.add(new SalesChannelLine(4, "58247", "Acer Aspire One A150X blau", "gebraucht", 10, 10, "Lager", SalesChannel.CUSTOMER, laden.getId()));
    lines.add(new SalesChannelLine(5, "82235", "Acer Aspire 8930G-583G32Bn", "gebraucht", 10, 10, "Lager", SalesChannel.CUSTOMER, laden.getId()));
    lines.add(new SalesChannelLine(6, "19262", "Acer Aspire 8920G-834G32Bn", "gebraucht", 10, 10, "Lager", SalesChannel.CUSTOMER, lager.getId()));
    lines.add(new SalesChannelLine(7, "17239", "Acer Aspire 7330-572G16Mn", "Originalkarton, nahezu neuwertig", 10, 10, "Lager", SalesChannel.UNKNOWN, lager.getId()));
    Map<SalesChannel, Stock> stockToChannel = new EnumMap<>(SalesChannel.class);
    stockToChannel.put(CUSTOMER, laden);
    stockToChannel.put(RETAILER, lager);
    dialog.setModel(new SalesChannelTableModel(lines, stockToChannel));
    Dimension dim = dialog.getToolkit().getScreenSize();
    Rectangle abounds = dialog.getBounds();
    dialog.setLocation((int) ((dim.width - abounds.width) / 3), (dim.height - abounds.height) / 2);
    dialog.setVisible(true);
    System.out.println("OK = " + dialog.isOk());
    Map<Stock, List<String>> destinationsWithStockUnitIds = lines.stream().filter(// No Destination change
    l -> l.getDestination() != null).sorted(// Sort
    new LastCharsRefurbishIdSorter()).collect(Collectors.groupingBy(SalesChannelLine::getDestination, Collectors.mapping(SalesChannelLine::getRefurbishedId, Collectors.toList())));
    for (Entry<Stock, List<String>> entry : destinationsWithStockUnitIds.entrySet()) {
        System.out.println(entry.getKey().getName() + ",refurbishIds=" + entry.getValue());
    }
    f.dispose();
}
Also used : Rectangle(java.awt.Rectangle) LastCharsRefurbishIdSorter(eu.ggnet.dwoss.misc.ee.SalesChannelHandlerOperation.LastCharsRefurbishIdSorter) SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) SalesChannelTableModel(eu.ggnet.dwoss.misc.saleschannel.SalesChannelTableModel) StockTransactionType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionType) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) SalesChannelManagerDialog(eu.ggnet.dwoss.misc.saleschannel.SalesChannelManagerDialog) Dimension(java.awt.Dimension) SalesChannelLine(eu.ggnet.dwoss.stock.ee.model.SalesChannelLine) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) LockModeType(javax.persistence.LockModeType) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Aggregations

SalesChannelLine (eu.ggnet.dwoss.stock.ee.model.SalesChannelLine)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)2 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)2 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)2 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)2 LastCharsRefurbishIdSorter (eu.ggnet.dwoss.misc.ee.SalesChannelHandlerOperation.LastCharsRefurbishIdSorter)1 SalesChannelManagerDialog (eu.ggnet.dwoss.misc.saleschannel.SalesChannelManagerDialog)1 SalesChannelTableModel (eu.ggnet.dwoss.misc.saleschannel.SalesChannelTableModel)1 SalesChannel (eu.ggnet.dwoss.rules.SalesChannel)1 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)1 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)1 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)1 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)1 StockTransactionType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionType)1 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 LockModeType (javax.persistence.LockModeType)1 Test (org.junit.Test)1