Search in sources :

Example 41 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitOverseerBean method lockStockUnit.

/**
 * Find an available StockUnit and locks it by add to a LogicTransaction via DossierId.
 * <p/>
 * If no unit is found a LayerEightException is thrown.
 * <p/>
 * @param dossierId     The Dossiers ID
 * @param refurbishedId The refurbished id for the Unique Unit search
 * @throws IllegalStateException if the refurbishId is not available
 */
@Override
public void lockStockUnit(long dossierId, String refurbishedId) throws IllegalStateException {
    if (!internalFind(refurbishedId).isAvailable())
        throw new IllegalStateException("Trying to lock refusbishId " + refurbishedId + ", but it is not available!");
    UniqueUnit uu = new UniqueUnitEao(uuEm).findByIdentifier(Identifier.REFURBISHED_ID, refurbishedId);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dossierId);
    lt.add(stockUnit);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 42 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitOverseerBean method toDetailedHtmlUnit.

private String toDetailedHtmlUnit(UniqueUnit uniqueUnit, boolean showPrices) {
    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyy");
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    List<ReportLine> reportLines = new ReportLineEao(reportEm).findByUniqueUnitId(uniqueUnit.getId());
    String re = UniqueUnitFormater.toHtmlDetailed(uniqueUnit);
    TreeSet<Dossier> dossiers = new TreeSet<>(Dossier.ORDER_INVERSE_ACTIVE_ACTUAL);
    for (Position pos : new PositionEao(redTapeEm).findByUniqueUnitId(uniqueUnit.getId())) {
        // For now we ignore all Dossiers which just had the unit in the history
        if (!pos.getDocument().isActive())
            continue;
        dossiers.add(pos.getDocument().getDossier());
    }
    re += "<hr />";
    re += "<b>Vorgänge:</b><ul>";
    if (dossiers.isEmpty())
        re += "<li>Keine Vorgänge vorhanden</li>";
    for (Dossier dossier : dossiers) {
        re += "<li>";
        re += customerService.asUiCustomer(dossier.getCustomerId()).toNameCompanyLine();
        re += DossierFormater.toHtmlSimpleWithDocument(dossier) + "<br /></li>";
    }
    re += "</ul>";
    re += "<hr />";
    if (uniqueUnit.getHistory() != null && !uniqueUnit.getHistory().isEmpty()) {
        re += "<b>Unit History:</b><ul>";
        for (UniqueUnitHistory history : new TreeSet<>(uniqueUnit.getHistory())) {
            re += "<li>" + df.format(history.getOccurence()) + " - " + history.getComment() + "</li>";
        }
        re += "</ul>";
    }
    re += "<hr />";
    re += "<p><b>Lagerinformationen</b><br />";
    if (stockUnit == null)
        re += "Kein Lagergerät vorhanden<br />";
    else
        re += StockUnitFormater.toHtml(stockUnit);
    re += "</p>";
    re += "<hr />";
    re += "<b>Reporting-Informationen</b>";
    if (reportLines == null || reportLines.isEmpty())
        re += "Keine Reporting-Informationen vorhanden<br />";
    else {
        re += "<table border=\"1\"><tr>";
        re += wrap("<th>", "</th>", "Id", "ReportDate", "Kid", "SopoNr", "Type", "Dossier", "Report");
        re += "</tr>";
        for (ReportLine l : reportLines) {
            re += "<tr>";
            re += wrap("<td>", "</td>", l.getId(), DateFormats.ISO.format(l.getReportingDate()), l.getCustomerId(), l.getRefurbishId(), l.getPositionType() == PRODUCT_BATCH && l.getReference(WARRANTY) != null ? "Garantieerweiterung" : l.getPositionType().getName(), l.getDossierIdentifier() + ", " + l.getDocumentType().getName() + l.getWorkflowStatus().getSign() + (l.getDocumentIdentifier() == null ? "" : ", " + l.getDocumentIdentifier()), l.getReports().stream().map(Report::getName).collect(Collectors.joining(",")));
        }
        re += "</table><br />";
    }
    if (!showPrices)
        return re;
    re += "<hr />";
    re += "<b>Geräte Preis-Informationen</b>";
    re += UniqueUnitFormater.toHtmlPriceInformation(uniqueUnit.getPrices(), uniqueUnit.getPriceHistory());
    re += "<b>Artikel Preis-Informationen</b>";
    re += UniqueUnitFormater.toHtmlPriceInformation(uniqueUnit.getProduct().getPrices(), uniqueUnit.getProduct().getPriceHistory());
    return Css.toHtml5WithStyle(re);
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) SimpleDateFormat(java.text.SimpleDateFormat) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitHistory(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnitHistory)

Example 43 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class ReceiptUnitOperationIT method asserts.

private void asserts(UniqueUnit receiptUnit, StockTransaction stockTransaction, ReceiptOperation receiptOperation, TradeName contractor) {
    String head = "(" + contractor + "," + receiptOperation + "):";
    // Verify the UniqueUnit
    UniqueUnit uniqueUnit = uniqueUnitAgent.findUnitByIdentifierEager(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
    assertNotNull(head + "Receipt Unit should exist", uniqueUnit);
    assertEquals(head + "Serial not equal", receiptUnit.getIdentifier(Identifier.SERIAL), uniqueUnit.getIdentifier(Identifier.SERIAL));
    // Verify the StockUnit
    StockUnit stockUnit = stockAgent.findStockUnitByUniqueUnitIdEager(uniqueUnit.getId());
    assertNotNull(head + "StockUnit should exist", stockUnit);
    assertEquals(head + "RefurbishId of UniqueUnit and StockUnit must be equal", receiptUnit.getIdentifier(Identifier.REFURBISHED_ID), stockUnit.getRefurbishId());
    assertEquals(head + "StockTransaction must be the same", stockTransaction.getId(), stockUnit.getTransaction().getId());
    if (!ReceiptOperation.valuesBackedByCustomer().contains(receiptOperation)) {
        // If unspecial Operation, no more verification needed.
        assertNull(head + "StockUnit.logicTransaction for " + receiptOperation, stockUnit.getLogicTransaction());
        return;
    }
    // Verify RedTape
    LogicTransaction logicTransaction = stockUnit.getLogicTransaction();
    assertNotNull(head + "StockUnit.logicTransaction for " + receiptOperation, logicTransaction);
    Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit.getLogicTransaction().getDossierId());
    assertNotNull(head + "Dossier for LogicTransaction must exist", dossier);
    assertEquals(head + "Dossier.customerId for " + contractor + " with " + receiptOperation, receiptCustomers.getCustomerId(contractor, receiptOperation), dossier.getCustomerId());
    assertEquals(head + "Dossier.activeDocuments", 1, dossier.getActiveDocuments().size());
    Document document = dossier.getActiveDocuments().get(0);
    assertEquals(head + "Document.type", DocumentType.BLOCK, document.getType());
    assertEquals(head + "LogicTransaction.stockUnits and Document.positions.uniqueUnitIds", toUniqueUnitIds(logicTransaction), document.getPositionsUniqueUnitIds());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 44 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit 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 45 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitProcessorOperation method validateReceipt.

private void validateReceipt(UniqueUnit receiptUnit) throws IllegalArgumentException {
    if (receiptUnit.getId() > 0)
        throw new IllegalArgumentException("UniqueUnit has already been persisted " + receiptUnit);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
    if (uniqueUnit != null)
        throw new IllegalArgumentException("Unit with refurbishedId=" + receiptUnit.getRefurbishId() + " exists.\n- Supplied Unit:" + receiptUnit + "\n- Database Unit:" + uniqueUnit);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(receiptUnit.getRefurbishId());
    if (stockUnit != null)
        throw new IllegalArgumentException(stockUnit + " exists");
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Aggregations

StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)63 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)27 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)22 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)20 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)20 Test (org.junit.Test)19 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)18 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)13 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)11 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)9 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)8 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)6 java.util (java.util)6 Inject (javax.inject.Inject)6 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)5