Search in sources :

Example 6 with StockTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao in project dwoss by gg-net.

the class StockTransactionEmo method request.

/**
 * Request a StockTransaction with the selected parameters.
 *
 * @param transactionType the type
 * @param statusType      the status
 * @param sourceId        the source, if null only the destination is used.
 * @param destinationId   the destination, if null only the source is used
 * @param arrangerName    the arranger
 * @param comment         the comment
 * @return always a persisted transactions with the supplied parameters
 */
// TODO: Still not implemented to findByTypeAndStatus a transaction with source an destination. (For Transfer)
private StockTransaction request(StockTransactionType transactionType, StockTransactionStatusType statusType, Integer sourceId, Integer destinationId, String arrangerName, String comment) {
    StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
    List<StockTransaction> stockTransactions;
    if (sourceId != null)
        stockTransactions = stockTransactionEao.findBySource(sourceId, transactionType, statusType, arrangerName, comment);
    else
        stockTransactions = stockTransactionEao.findByDestination(destinationId, transactionType, statusType, arrangerName, comment);
    if (!stockTransactions.isEmpty())
        return stockTransactions.get(0);
    DefaultEao<Stock> stockEao = new DefaultEao<>(Stock.class, em);
    StockTransaction st = new StockTransaction(transactionType);
    st.setComment(comment);
    StockTransactionStatus status = new StockTransactionStatus(statusType, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arrangerName));
    st.addStatus(status);
    if (sourceId != null)
        st.setSource(stockEao.findById(sourceId));
    if (destinationId != null)
        st.setDestination(stockEao.findById(destinationId));
    em.persist(st);
    return st;
}
Also used : DefaultEao(eu.ggnet.dwoss.util.persistence.eao.DefaultEao) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)

Aggregations

StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)6 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)2 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)2 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)2 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)2 SalesChannelChange (eu.ggnet.dwoss.event.SalesChannelChange)1 UnitHistory (eu.ggnet.dwoss.event.UnitHistory)1 Mandator (eu.ggnet.dwoss.mandator.api.value.Mandator)1 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)1 SalesChannel (eu.ggnet.dwoss.rules.SalesChannel)1 Stocks (eu.ggnet.dwoss.stock.ee.assist.Stocks)1 eu.ggnet.dwoss.stock.ee.emo (eu.ggnet.dwoss.stock.ee.emo)1 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)1 eu.ggnet.dwoss.stock.ee.entity (eu.ggnet.dwoss.stock.ee.entity)1 StockTransactionParticipation (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation)1 StockTransactionParticipationType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipationType)1 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)1 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)1