Search in sources :

Example 1 with SalesChannel

use of eu.ggnet.dwoss.rules.SalesChannel in project dwoss by gg-net.

the class ConverterUtil method mergeFromOld.

/**
 * Merges the old customer to a supplied new customer instance.
 * The new customer has all information of the old customer set to the first contact.
 * A Company may be added if the old.firma is not blank.
 * This Method also assumes, that there is exactly one Mandator used in creation with its defaults.
 * <p>
 * @param old               old customer
 * @param customer
 * @param mandatorMatchCode the mandatorMatchCode
 * @param defaults          the defaults as filter for specific mandator data.
 * @return new customer.
 */
public static Customer mergeFromOld(OldCustomer old, Customer customer, String mandatorMatchCode, DefaultCustomerSalesdata defaults) {
    customer.setComment(old.getAnmerkung());
    customer.getFlags().clear();
    for (CustomerFlag customerFlag : old.getFlags()) {
        customer.getFlags().add(customerFlag);
    }
    customer.getAdditionalCustomerIds().clear();
    customer.getAdditionalCustomerIds().putAll(old.getAdditionalCustomerIds());
    customer.setSource(old.getSource());
    customer.setKeyAccounter(old.getKeyAccounter());
    if (customer.getContacts().isEmpty())
        customer.getContacts().add(new Contact());
    Contact contact = customer.getContacts().get(0);
    contact.setFirstName(old.getVorname() == null ? "" : old.getVorname());
    contact.setLastName(old.getNachname() == null ? "" : old.getNachname());
    if (old.getTitel() != null) {
        switch(old.getTitel()) {
            case "Herr":
                contact.setSex(MALE);
                break;
            case "Frau":
                contact.setSex(FEMALE);
                break;
            default:
        }
    }
    contact.setPrefered(true);
    if (!StringUtils.isBlank(old.getFirma()) || !customer.getCompanies().isEmpty()) {
        if (customer.getCompanies().isEmpty())
            customer.getCompanies().add(new Company());
        Company company = customer.getCompanies().get(0);
        company.setName(old.getFirma());
        company.setLedger(old.getLedger());
        company.setTaxId(old.getTaxId());
        company.setPrefered(true);
    }
    for (Type t : EnumSet.of(EMAIL, FAX, PHONE, MOBILE)) {
        if (!StringUtils.isBlank(get(old, t)) || contact.prefered(t) != null) {
            if (contact.prefered(t) == null)
                contact.getCommunications().add(new Communication(t, true));
            contact.prefered(t).setIdentifier(get(old, t));
        }
    }
    if (!StringUtils.isBlank(old.getREAdresse()) || contact.prefered(INVOICE) != null) {
        if (contact.prefered(INVOICE) == null)
            contact.getAddresses().add(new Address(INVOICE));
        Address rad = contact.prefered(INVOICE);
        rad.setStreet(old.getREAdresse());
        rad.setCity(old.getREOrt() == null ? "" : old.getREOrt());
        rad.setZipCode(old.getREPlz() == null ? "" : old.getREPlz());
    }
    if (!StringUtils.isBlank(old.getLIAdresse()) || contact.prefered(SHIPPING) != null) {
        if (contact.prefered(SHIPPING) == null)
            contact.getAddresses().add(new Address(SHIPPING));
        Address sad = contact.prefered(SHIPPING);
        sad.setStreet(old.getLIAdresse());
        sad.setCity(old.getLIOrt() == null ? "" : old.getLIOrt());
        sad.setZipCode(old.getLIPlz() == null ? "" : old.getLIPlz());
    }
    MandatorMetadata m = customer.getMandatorMetadata(mandatorMatchCode);
    if (m == null)
        m = new MandatorMetadata();
    m.setMandatorMatchcode(mandatorMatchCode);
    m.clearSalesChannels();
    if (!old.getAllowedSalesChannels().equals(defaults.getAllowedSalesChannels())) {
        for (SalesChannel salesChannel : old.getAllowedSalesChannels()) {
            m.add(salesChannel);
        }
    }
    if (old.getPaymentCondition() == defaults.getPaymentCondition())
        m.setPaymentCondition(null);
    else
        m.setPaymentCondition(old.getPaymentCondition());
    if (old.getPaymentMethod() == defaults.getPaymentMethod())
        m.setPaymentMethod(null);
    else
        m.setPaymentMethod(old.getPaymentMethod());
    if (old.getShippingCondition() == defaults.getShippingCondition())
        m.setShippingCondition(null);
    else
        m.setShippingCondition(old.getShippingCondition());
    if (customer.getMandatorMetadata(mandatorMatchCode) == null && m.isSet())
        customer.getMandatorMetadata().add(m);
    return customer;
}
Also used : SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag)

Example 2 with SalesChannel

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

Example 3 with SalesChannel

use of eu.ggnet.dwoss.rules.SalesChannel in project dwoss by gg-net.

the class StockTransactionProcessorOperation method rollIn.

/**
 * Rolls all StockTransaction in, completing them and setting the Stock.
 *
 * @param detachtedTransactions the transactions
 * @param arranger              the arranger
 */
@Override
public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
    SubMonitor m = monitorFactory.newSubMonitor("RollIn", detachtedTransactions.size() * 2);
    StockTransactionEao stockTransactionEao = new StockTransactionEao(stockEm);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    List<StockTransaction> transactions = new ArrayList<>();
    m.message("loading Transactions");
    for (StockTransaction detachedTransaction : detachtedTransactions) {
        transactions.add(stockTransactionEao.findById(detachedTransaction.getId()));
        m.worked(1);
    }
    m.setWorkRemaining(3);
    m.message("rolling in");
    List<StockUnit> stockUnits = stockTransactionEmo.completeRollIn(arranger, transactions);
    m.worked(2, "adding History");
    for (StockUnit stockUnit : stockUnits) {
        if (mandator.isApplyDefaultChannelOnRollIn()) {
            SalesChannel channel = stockUnit.getStock().getPrimaryChannel();
            channelChanger.fire(new SalesChannelChange(stockUnit.getUniqueUnitId(), channel));
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName() + " with " + channel.getName(), arranger));
        } else {
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName(), arranger));
        }
    }
    m.finish();
    return stockUnits.stream().map(x -> x.getId()).collect(Collectors.toList());
}
Also used : SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) java.util(java.util) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LoggerFactory(org.slf4j.LoggerFactory) eu.ggnet.dwoss.stock.ee.emo(eu.ggnet.dwoss.stock.ee.emo) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) Mandator(eu.ggnet.dwoss.mandator.api.value.Mandator) ConstraintViolationFormater(eu.ggnet.dwoss.util.validation.ConstraintViolationFormater) StockTransactionParticipationType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipationType) Stocks(eu.ggnet.dwoss.stock.ee.assist.Stocks) Inject(javax.inject.Inject) SalesChannelChange(eu.ggnet.dwoss.event.SalesChannelChange) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) DateUtils(org.apache.commons.lang3.time.DateUtils) eu.ggnet.dwoss.stock.ee.entity(eu.ggnet.dwoss.stock.ee.entity) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) javax.validation(javax.validation) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) SalesChannelChange(eu.ggnet.dwoss.event.SalesChannelChange) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)

Aggregations

SalesChannel (eu.ggnet.dwoss.rules.SalesChannel)3 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)2 Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 SalesChannelChange (eu.ggnet.dwoss.event.SalesChannelChange)1 UnitHistory (eu.ggnet.dwoss.event.UnitHistory)1 Mandator (eu.ggnet.dwoss.mandator.api.value.Mandator)1 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 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)1 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 CustomerFlag (eu.ggnet.dwoss.rules.CustomerFlag)1 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)1 Stocks (eu.ggnet.dwoss.stock.ee.assist.Stocks)1 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)1 eu.ggnet.dwoss.stock.ee.emo (eu.ggnet.dwoss.stock.ee.emo)1 eu.ggnet.dwoss.stock.ee.entity (eu.ggnet.dwoss.stock.ee.entity)1 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)1 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)1