Search in sources :

Example 1 with StockTransactionEao

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

the class StockTransactionEaoIT method testfind.

@Test
public void testfind() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s1 = new Stock(0, "TEEEEEEEST");
    Stock s2 = new Stock(1, "TEEEEEEEST");
    em.persist(s1);
    em.persist(s2);
    StockTransaction st1 = new StockTransaction(StockTransactionType.ROLL_IN);
    st1.setDestination(s1);
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date()));
    StockTransaction st2 = new StockTransaction(StockTransactionType.ROLL_IN);
    st2.setDestination(s1);
    st2.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st3 = new StockTransaction(StockTransactionType.DESTROY);
    st3.setSource(s1);
    st3.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st4 = new StockTransaction(StockTransactionType.ROLL_IN);
    st4.setDestination(s2);
    StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.PICKER, "Hugo"));
    st4.addStatus(status);
    st4.setComment("Muh");
    em.persist(st1);
    em.persist(st2);
    em.persist(st3);
    em.persist(st4);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
    List<StockTransaction> sts = stockTransactionEao.findByDestination(s1.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st2.getId(), sts.get(0).getId());
    sts = stockTransactionEao.findByDestination(s2.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED, "Hugo", "Muh");
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st4.getId(), sts.get(0).getId());
    utx.commit();
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 2 with StockTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao 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)

Example 3 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)

Example 4 with StockTransactionEao

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

the class UnitProcessorOperation method receiptAndAddStockUnit.

private StockUnit receiptAndAddStockUnit(UniqueUnit uniqueUnit, StockTransaction transaction) {
    StockUnit stockUnit = new StockUnit();
    stockUnit.setUniqueUnitId(uniqueUnit.getId());
    stockUnit.setRefurbishId(uniqueUnit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    stockUnit.setName(uniqueUnit.getProduct().getTradeName().getName() + " " + uniqueUnit.getProduct().getName());
    transaction = new StockTransactionEao(stockEm).findById(transaction.getId());
    transaction.addPosition(new StockTransactionPosition(stockUnit));
    // implies persist on transaction commit
    L.debug("adding {} to {}", stockUnit, transaction);
    return stockUnit;
}
Also used : StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 5 with StockTransactionEao

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

the class AuditReporterOperation method onRollIn.

/**
 * Returns an audit report of units which are input between the dates.
 * <p/>
 * @return an audit report of units which are input between the dates.
 */
@Override
public FileJacket onRollIn() {
    SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
    m.message("loading UniqueUnits");
    m.start();
    List<StockTransaction> rollInTransactions = new StockTransactionEao(stocks.getEntityManager()).findByTypeAndStatus(StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    List<Integer> uuIds = toUniqueUnitIds(rollInTransactions);
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findByIds(uuIds);
    m.worked(5, "preparing Document");
    List<Object[]> rows = new ArrayList<>();
    for (UniqueUnit uu : uniqueUnits) {
        rows.add(new Object[] { uu.getRefurbishId(), uu.getProduct().getGroup().getNote(), uu.getProduct().getPartNo(), uu.getSerial(), ProductFormater.toName(uu.getProduct()), uu.getContractor(), UniqueUnitFormater.toSingleLineAccessories(uu), UniqueUnitFormater.toSingleLineComment(uu), UniqueUnitFormater.toSingleLineInternalComment(uu), uu.getCondition().getNote(), uu.getShipmentLabel(), uu.getProduct().getDescription(), "" });
    }
    CSheet sheet = new CSheet("Audit");
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("SopoNr", 7)).add(new STableColumn("Warengruppe", 13)).add(new STableColumn("ArtikelNr", 15)).add(new STableColumn("Seriennummer", 27));
    table.add(new STableColumn("Name", 30)).add(new STableColumn("Lieferant", 12)).add(new STableColumn("Zubehör", 50)).add(new STableColumn("Bemerkung", 50));
    table.add(new STableColumn("Interne Bemerkung", 30)).add(new STableColumn("Zustand", 12)).add(new STableColumn("Shipment", 12)).add(new STableColumn("Beschreibung", 50));
    table.setModel(new STableModelList(rows));
    sheet.addBelow(table);
    CCalcDocument document = new TempCalcDocument();
    document.add(sheet);
    FileJacket fj = new FileJacket("Audit", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document));
    m.finish();
    return fj;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ArrayList(java.util.ArrayList) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) CSheet(eu.ggnet.lucidcalc.CSheet) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) STableColumn(eu.ggnet.lucidcalc.STableColumn) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat) CBorder(eu.ggnet.lucidcalc.CBorder) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

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