Search in sources :

Example 51 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class RedTapeCloserOperation method closeing.

/**
 * The closing selects and closes all dossiers and documents in a closable state. This includes production of appropriated values for report.
 * <p/>
 * The workflow:
 * <ol>
 * <li>Load all open {@link Dossiers}, and filter them by the closing states of the associated {@link Documents}.See
 * {@link #findReportable(de.dw.progress.IMonitor)}</li>
 * <li>Filter out all Document, which have {@link StockUnit}'s on open {@link StockTransaction}.</li>
 * <li>Create the resulting {@link ReportLine}'s and persist them in the report database. See
 * {@link #poluteReporting(java.util.Set, java.util.Date, de.dw.progress.IMonitor)} </li>
 * <li>Close the selected {@link Dossier}'s and {@link Document}'s in redTape. See {@link #closeRedTape(java.util.Set, de.dw.progress.IMonitor)}</li>
 * <li>Find all associated {@link StockUnit}'s and roll them out. See
 * {@link #closeStock(java.util.Set, java.lang.String, java.lang.String, de.dw.progress.IMonitor)}</li>
 * </ol>
 * <p>
 * <p/>
 * @param arranger the arranger
 * @param manual   is this called manual or automatic
 */
private void closeing(String arranger, boolean manual) {
    Date now = new Date();
    String msg = (manual ? "Manueller" : "Automatischer") + " (Tages)abschluss vom " + DateFormats.ISO.format(now) + " ausgeführt durch " + arranger;
    L.info("closing:{}", msg);
    SubMonitor m = monitorFactory.newSubMonitor((manual ? "Manueller" : "Automatischer") + " (Tages)abschluss", 100);
    m.start();
    L.info("closing:week persisted");
    Set<Document> reportable = findReportable(m.newChild(30));
    L.info("closing:documents selected");
    reportable = filterOpenStockTransactions(reportable, m.newChild(5));
    L.info("closing:documents filtered");
    poluteReporting(reportable, DateUtils.truncate(new Date(), Calendar.DATE), m.newChild(15));
    L.info("closing:repoting poluted");
    closeRedTape(reportable, m.newChild(10));
    L.info("closed:redTape:reportables");
    closeRedTape(findCloseableBlocker(), m.newChild(10));
    L.info("closed:redTape:nonreportables");
    closeStock(reportable.stream().map(Document::getDossier).map(Dossier::getId).collect(Collectors.toSet()), "Rollout by " + (manual ? "manuel" : "automatic") + " closing on " + DateFormats.ISO.format(now), arranger, m);
    L.info("closed:stock");
    m.finish();
}
Also used : Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 52 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor 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 53 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class ReceiptGeneratorOperation method makeUniqueUnits.

/**
 * Generates an amount of UniquUnits and receipts them.
 *
 * @param amount               the amount to generate.
 * @param generateSalesChannel
 * @param generatePrice        if true a random customer and retailer price is set
 * @return the generated and receipted UniquUnits.
 */
// TODO: Create more Shipments on multiple contractors.
public List<UniqueUnit> makeUniqueUnits(int amount, boolean generateSalesChannel, boolean generatePrice) {
    final int minProducts = 5;
    final int maxProducts = 450;
    int amountProducts = (amount / 25);
    if (amountProducts <= minProducts)
        amountProducts = minProducts;
    if (amountProducts >= maxProducts)
        amountProducts = maxProducts;
    L.info("Generating {} Units", amount);
    SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Units", amount);
    m.start();
    List<ProductSpec> productSpecs = makeProductSpecs(amountProducts, generatePrice);
    List<UniqueUnit> units = new ArrayList<>();
    Stock stock = findOrMakeStock();
    TradeName contractor = new ArrayList<>(contractors.all()).get(R.nextInt(contractors.all().size()));
    Shipment shipment = new Shipment("TEST-SHIPMENT-" + R.nextInt(10), contractor, TradeName.ACER, Shipment.Status.OPENED);
    stockEm.persist(shipment);
    StockTransaction transaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "SampleGenerator", "Rollin via make UniqueUnits");
    L.debug("Transaction prepared {}", transaction);
    for (int i = 0; i < amount; i++) {
        ProductSpec productSpec = productSpecs.get(R.nextInt(productSpecs.size()));
        Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
        UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
        m.worked(1, "created SopoNr " + unit.getRefurbishId());
        if (generatePrice) {
            int price = R.nextInt(1000) + 1;
            unit.setPrice(PriceType.CUSTOMER, price, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
            unit.setPrice(PriceType.RETAILER, price * 1.08, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
        }
        if (generateSalesChannel)
            unit.setSalesChannel(R.nextBoolean() ? SalesChannel.CUSTOMER : SalesChannel.RETAILER);
        unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
        // Ad the now persisted instance.
        units.add(uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId()));
    }
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    m.finish();
    return units;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 54 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor 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)

Example 55 with SubMonitor

use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.

the class AuditReporterOperation method byRange.

/**
 * Returns an audit report of units which are on a roll in transaction, but not yet rolled in.
 * <p/>
 * @return an audit report of units which are on a roll in transaction, but not yet rolled in.
 */
@Override
public FileJacket byRange(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
    m.message("loading UniqueUnits");
    m.start();
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findBetweenInputDates(start, end);
    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) 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)

Aggregations

SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)63 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)23 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)21 FileJacket (eu.ggnet.dwoss.util.FileJacket)18 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)16 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)14 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)12 File (java.io.File)12 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)11 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)9 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)8 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)7 Inject (javax.inject.Inject)7 Test (org.junit.Test)7 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)6 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)6 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)6 CFormat (eu.ggnet.lucidcalc.CFormat)6 CSheet (eu.ggnet.lucidcalc.CSheet)6 STable (eu.ggnet.lucidcalc.STable)6