Search in sources :

Example 1 with UnitHistory

use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.

the class ResolveRepaymentBean method resolveUnit.

@Override
public ResolveResult resolveUnit(String identifier, TradeName contractor, String arranger, String comment) throws UserInfoException {
    // search with refurbishid and serial number.
    List<SimpleReportLine> reportLines = reportLineEao.findReportLinesByIdentifiers(identifier.trim());
    List<ReportLine> repaymentLines = getRepaymentLines(contractor);
    ReportLine line = null;
    List<Long> repaymentIds = repaymentLines.stream().map((l) -> l.getId()).collect(Collectors.toList());
    for (SimpleReportLine reportLine : reportLines) {
        if (repaymentIds.contains(reportLine.getId())) {
            line = reportLineEao.findById(reportLine.getId());
        }
    }
    if (line == null)
        throw new UserInfoException("Es konnte keine ReportLine mit diesem Identifier gefunden werden");
    if (!line.getReports().isEmpty())
        throw new UserInfoException("ReportLine ist schon in einem Report.\nReports:" + line.getReports());
    ReportLine reference = line.getReference(SingleReferenceType.WARRANTY);
    // Rolling out the unit if still in Stock.
    StockUnit stockUnit = // Saftynet, e.g. unit annex shoud not clear units.
    line.getPositionType() == UNIT ? stockUnitEao.findByRefurbishId(line.getRefurbishId()) : null;
    if (stockUnit != null && stockUnit.isInTransaction())
        throw new UserInfoException("Unit is in einer StockTransaction. ID:" + stockUnit.getTransaction().getId());
    ResolveResult msgs = new ResolveResult();
    if (stockUnit == null) {
        msgs.stockMessage = "Es existiert keine Stock Unit (mehr) zu dem Gerät";
        msgs.redTapeMessage = "Keine StockUnit, Kein Vorgang";
    } else {
        LogicTransaction lt = stockUnit.getLogicTransaction();
        long dossierId = lt.getDossierId();
        Dossier dossier = dossierEao.findById(dossierId);
        if (!repaymentCustomers.get(contractor).isPresent() || !repaymentCustomers.get(contractor).get().equals(dossier.getCustomerId())) {
            throw new UserInfoException("Unit is nicht auf einem Auftrag eines Repayment Customers. DossierId:" + dossier.getId());
        }
        List<Document> activeDocuments = dossier.getActiveDocuments(DocumentType.BLOCK);
        if (activeDocuments.size() != 1) {
            throw new UserInfoException("Der Gutschriftsvorgang " + dossier.toSimpleLine() + " ist fehlerhaft, entweder kein oder zu viele akive Blocker");
        }
        Position pos = activeDocuments.get(0).getPositionByUniqueUnitId(stockUnit.getUniqueUnitId());
        if (pos == null) {
            throw new UserInfoException("Auf Gutschriftsvorgang " + dossier.toSimpleLine() + " ist das Gerät " + stockUnit.toSimple() + " nicht auffindbar");
        }
        msgs.redTapeMessage = "Kid: " + dossier.getCustomerId() + ", Vorgang:" + dossier.getIdentifier() + " wurde Gerät entfernt";
        convertToComment(pos, arranger, comment);
        lt.remove(stockUnit);
        StockTransaction st = stEmo.requestRollOutPrepared(stockUnit.getStock().getId(), arranger, "Resolved Repayment");
        st.addUnit(stockUnit);
        msgs.stockMessage = stockUnit.toSimple() + " aus Lager ausgerollt auf StockTransaction(id=" + st.getId() + ")";
        history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Resolved Repayment", arranger));
        stEmo.completeRollOut(arranger, Arrays.asList(st));
        stockEm.flush();
        if (lt.getUnits().isEmpty()) {
            msgs.stockMessage += ", LogicTransaction " + lt.getId() + " ist jetzt leer, wird gelöscht";
            stockEm.remove(lt);
        }
    }
    Date startOfYear = Date.from(LocalDate.of(LocalDate.now().getYear(), 1, 1).atStartOfDay(systemDefault()).toInstant());
    Date endOfYear = Date.from(LocalDate.of(LocalDate.now().getYear(), 12, 31).atStartOfDay(systemDefault()).toInstant());
    Report report = reportEmo.request(toReportName(contractor), contractor, startOfYear, endOfYear);
    line.setComment(comment);
    report.add(line);
    msgs.reportMessage = "Repayment Unit " + line.getRefurbishId() + " line " + line.getId() + " resolved in " + report.getName();
    if (reference != null) {
        L.info("Warrenty Reference exist. Putted also into the report. ReportLine ID of Warrenty:{}", reference.getId());
        reference.setComment(comment);
        report.add(reference);
        msgs.reportMessage += ", including warranty " + reference.getId();
    }
    return msgs;
}
Also used : java.util(java.util) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) LoggerFactory(org.slf4j.LoggerFactory) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) ZoneId.systemDefault(java.time.ZoneId.systemDefault) Stocks(eu.ggnet.dwoss.stock.ee.assist.Stocks) Inject(javax.inject.Inject) CREDIT_MEMO(eu.ggnet.dwoss.rules.DocumentType.CREDIT_MEMO) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) Report(eu.ggnet.dwoss.report.ee.entity.Report) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) SingleReferenceType(eu.ggnet.dwoss.report.ee.entity.ReportLine.SingleReferenceType) RepaymentCustomers(eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) ReportEmo(eu.ggnet.dwoss.report.ee.emo.ReportEmo) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ANNULATION_INVOICE(eu.ggnet.dwoss.rules.DocumentType.ANNULATION_INVOICE) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) LocalDate(java.time.LocalDate) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Report(eu.ggnet.dwoss.report.ee.entity.Report) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) LocalDate(java.time.LocalDate) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 2 with UnitHistory

use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.

the class RedTapeCloserOperation method closeStock.

/**
 * Rolling out the units from the stocks. For this, a {@link StockTransaction} with {@link StockTransactionType#ROLL_OUT} is created,
 * all {@link StockUnit}<code>s</code> which are on a {@link LogicTransaction} with matching dossierId are added to this {@link StockTransaction} and
 * it gets {@link StockTransactionStatusType#COMPLETED}.
 * <p/>
 * @param dossierIds the dossierId as reference.
 * @param msg        a msg for the stocktransaction.
 * @param arranger   the arranger.
 * @param monitor    a optional monitor.
 * @return the amount of rolled out units.
 */
private int closeStock(Set<Long> dossierIds, String msg, String arranger, IMonitor monitor) {
    SubMonitor m = SubMonitor.convert(monitor, 100);
    final String h = "Stock:";
    m.message(h + "lade logische Transaktionen");
    // Rolling out
    List<LogicTransaction> lts = ltEao.findByDossierIds(dossierIds);
    m.worked(3, h + "sortiere Geräte nach Lager");
    stockEao.findAll();
    Map<Stock, List<StockUnit>> unitsByStock = lts.stream().flatMap((t) -> t.getUnits().stream()).collect(Collectors.groupingBy(StockUnit::getStock));
    validateStockUnits(unitsByStock);
    m.setWorkRemaining((int) unitsByStock.values().stream().count());
    List<StockTransaction> stockTransactions = new ArrayList<>();
    for (Entry<Stock, List<StockUnit>> entry : unitsByStock.entrySet()) {
        StockTransaction st = stEmo.requestRollOutPrepared(entry.getKey().getId(), arranger, msg);
        for (StockUnit stockUnit : entry.getValue()) {
            m.worked(1, h + "verbuche (refurbishId=" + stockUnit.getRefurbishId() + ",uniqueUnitId=" + stockUnit.getUniqueUnitId() + ")");
            st.addUnit(stockUnit);
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), msg, arranger));
        }
        stockTransactions.add(st);
    }
    m.message(h + "auslagern");
    if (!stockTransactions.isEmpty())
        stEmo.completeRollOut(arranger, stockTransactions);
    m.finish();
    return (int) unitsByStock.values().stream().count();
}
Also used : CustomerServiceBean(eu.ggnet.dwoss.customer.ee.CustomerServiceBean) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) RedTapeWorkflow(eu.ggnet.dwoss.redtapext.ee.workflow.RedTapeWorkflow) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LoggerFactory(org.slf4j.LoggerFactory) BLOCK(eu.ggnet.dwoss.rules.DocumentType.BLOCK) StringUtils(org.apache.commons.lang3.StringUtils) ReceiptCustomers(eu.ggnet.dwoss.mandator.api.value.ReceiptCustomers) CONTRACTOR_REFERENCE(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CONTRACTOR_REFERENCE) Directive(eu.ggnet.dwoss.redtape.ee.entity.Document.Directive) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) RedTapes(eu.ggnet.dwoss.redtape.ee.assist.RedTapes) Schedule(javax.ejb.Schedule) Reports(eu.ggnet.dwoss.report.ee.assist.Reports) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Instance(javax.enterprise.inject.Instance) COMMENT(eu.ggnet.dwoss.rules.PositionType.COMMENT) DateFormats(eu.ggnet.dwoss.util.DateFormats) PositionType(eu.ggnet.dwoss.rules.PositionType) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) PaymentMethod(eu.ggnet.dwoss.rules.PaymentMethod) Collectors(java.util.stream.Collectors) MANUFACTURER_COST(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.MANUFACTURER_COST) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Singleton(javax.ejb.Singleton) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) Entry(java.util.Map.Entry) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) WarrantyService(eu.ggnet.dwoss.mandator.api.service.WarrantyService) java.util(java.util) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) StockEao(eu.ggnet.dwoss.stock.ee.eao.StockEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Inject(javax.inject.Inject) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DocumentType(eu.ggnet.dwoss.rules.DocumentType) WARRANTY(eu.ggnet.dwoss.report.ee.entity.ReportLine.SingleReferenceType.WARRANTY) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnits(eu.ggnet.dwoss.uniqueunit.ee.assist.UniqueUnits) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) IMonitor(eu.ggnet.saft.api.progress.IMonitor) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) EntityManager(javax.persistence.EntityManager) Type(eu.ggnet.statemachine.State.Type) DateUtils(org.apache.commons.lang3.time.DateUtils) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) Condition(eu.ggnet.dwoss.redtape.ee.entity.Document.Condition) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StringUtils.normalizeSpace(org.apache.commons.lang3.StringUtils.normalizeSpace) javax.validation(javax.validation) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 3 with UnitHistory

use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.

the class StockTransactionProcessorOperation method removeFromPreparedTransaction.

/**
 * Remove the stockUnit represented by the refurbishId from a stock transaction, if that transaction exists and is in state prepared.
 * <p/>
 * @param refurbishId the refurbishId
 * @param arranger    the arranger
 * @param comment     a optional comment
 * @throws UserInfoException if no unit exists, the unit is not on a transaction or the transaction has another state then prepared.
 */
@Override
public void removeFromPreparedTransaction(final String refurbishId, final String arranger, final String comment) throws UserInfoException {
    StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(refurbishId);
    if (stockUnit == null)
        throw new UserInfoException("SopoNr: " + refurbishId + " existiert nicht.");
    if (!stockUnit.isInTransaction())
        throw new UserInfoException("SopoNr: " + refurbishId + " nicht in Transaction.");
    StockTransaction transaction = stockUnit.getTransaction();
    if (transaction.getStatus().getType() != PREPARED) {
        throw new UserInfoException("SopoNr: " + refurbishId + " auf Transaction, aber Transaction(" + transaction.getId() + ") not in Status prepared");
    }
    // The one case we remove the position as well, but dont need to set the stock because of beeing in status prepared
    StockTransactionPosition position = stockUnit.getPosition();
    stockEm.remove(position);
    transaction.setComment(transaction.getComment() + ", Unit " + stockUnit.getRefurbishId() + " removed by " + arranger + ", cause=" + comment);
    history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit returned to Stock(" + transaction.getSource().getId() + ") " + transaction.getSource().getName() + ", removed from Transaction, cause: " + comment, arranger));
    L.info("{} removed from {}", stockUnit, transaction);
}
Also used : UnitHistory(eu.ggnet.dwoss.event.UnitHistory) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException)

Example 4 with UnitHistory

use of eu.ggnet.dwoss.event.UnitHistory in project dwoss by gg-net.

the class StockTransactionProcessorOperation method receive.

/**
 * Receive a list of transactions in the destination stock.
 * <p/>
 * @param transactions the transactions to receive.
 * @param deliverer    the deliverer
 * @param reciever     the receiver
 */
@Override
public void receive(List<StockTransaction> transactions, String deliverer, String reciever) {
    StockLocationDiscoverer discoverer = new StockLocationDiscoverer(stockEm);
    for (StockTransaction transaction : transactions) {
        transaction = stockEm.find(StockTransaction.class, transaction.getId());
        transaction.addStatus(RECEIVED, DELIVERER, deliverer, RECEIVER, reciever);
        L.info("Receiving {} in {}", transaction, transaction.getDestination());
        Stock destination = transaction.getDestination();
        for (StockUnit stockUnit : transaction.getUnits()) {
            stockUnit.setPosition(null);
            discoverer.discoverAndSetLocation(stockUnit, destination);
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit received in Stock(" + destination.getId() + ") " + destination.getName(), reciever));
        }
    }
}
Also used : UnitHistory(eu.ggnet.dwoss.event.UnitHistory)

Example 5 with UnitHistory

use of eu.ggnet.dwoss.event.UnitHistory 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

UnitHistory (eu.ggnet.dwoss.event.UnitHistory)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Event (javax.enterprise.event.Event)3 Inject (javax.inject.Inject)3 EntityManager (javax.persistence.EntityManager)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)2 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)2 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)2 UNIT (eu.ggnet.dwoss.rules.PositionType.UNIT)2 javax.validation (javax.validation)2