Search in sources :

Example 11 with StockUnit

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

the class PersistenceValidatorOperation method validateDatabase.

/**
 * This Method Validate all Databases.
 * It's validate:
 * - RedTape
 * - UniqueUnit
 * - Sopo
 * - Stock
 * <p/>
 * @return a Filejacket where a xls from the JExcel api is, that contains all Errors.
 */
@Override
public Optional<FileJacket> validateDatabase() {
    List<Vm> vms = new ArrayList<>();
    UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
    DossierEao dossierEao = new DossierEao(redTapeEm);
    LogicTransactionEao logicEao = new LogicTransactionEao(stockEm);
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    int uuMax = uuEao.count();
    int dossierMax = dossierEao.count();
    int logicMax = logicEao.count();
    int stockUnitMax = stockUnitEao.count();
    SubMonitor m = monitorFactory.newSubMonitor("DatenbankValidation", 100);
    // All Listen
    List<Dossier> dossiers;
    List<UniqueUnit> uniqueUnits;
    List<LogicTransaction> logicTransactions;
    List<StockUnit> stockUnits;
    m.message("Hole alle Unique Units. " + uuMax);
    uniqueUnits = uuEao.findAll();
    m.worked(10, "Hole Alle Dossiers. " + dossierMax);
    dossiers = dossierEao.findAll();
    m.worked(10, "Hole Alle LogicTransaction. " + logicMax);
    logicTransactions = logicEao.findAll();
    m.worked(10, "Hole Alle StockUnit. " + stockUnitMax);
    stockUnits = stockUnitEao.findAll();
    m.worked(10, "Validieren.");
    validateRedTape(vms, dossiers, convertUnitListToMap(uniqueUnits), m.newChild(10));
    validateUniqueUnit(vms, uniqueUnits, m.newChild(10));
    validateLogicTransaction(vms, logicTransactions, dossiers, m.newChild(10));
    // TODO: split:
    // 1. Sopo Validation <-> RedTape
    // 2. Sopo Only.
    m.finish();
    return createFileJacket(vms);
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 12 with StockUnit

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

the class MovementListingProducerOperation method generateList.

@Override
public JasperPrint generateList(ListType listType, Stock stock) {
    SubMonitor m = monitorFactory.newSubMonitor("Versand und Abholung", 100);
    m.message("lade Vorgänge");
    m.start();
    LogicTransactionEao ltEao = new LogicTransactionEao(stockEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    List<Document> documents = new DocumentEao(redTapeEm).findActiveByDirective(listType.getDirective());
    m.worked(5);
    m.setWorkRemaining(documents.size() + 2);
    List<MovementLine> lines = new ArrayList<>();
    List<String> dossierids = new ArrayList<>();
    List<Long> systemCustomers = customerService.allSystemCustomerIds();
    for (Document document : documents) {
        if (systemCustomers.contains(document.getDossier().getCustomerId()))
            continue;
        m.worked(1, "verarbeite " + document.getDossier().getIdentifier());
        LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
        // Filter by stock
        if (!hasUnitOnStock(lt, stock))
            continue;
        MovementLine line = new MovementLine();
        line.setCustomerId(document.getDossier().getCustomerId());
        line.setCustomerComment(customerService.findComment(document.getDossier().getCustomerId()));
        line.setComment(document.getDossier().getComment());
        line.setInvoiceAddress(document.getInvoiceAddress().getDescription());
        line.setDeliveryAddress(document.getShippingAddress().getDescription());
        line.setDossierIdentifier(document.getDossier().getIdentifier());
        dossierids.add(document.getDossier().getIdentifier());
        line.setPaymentMethod(document.getDossier().getPaymentMethod().getNote());
        for (StockUnit stockUnit : lt.getUnits()) {
            UniqueUnit uniqueUnit = uniqueUnitEao.findById(stockUnit.getUniqueUnitId());
            Product p = uniqueUnit.getProduct();
            MovementSubline elem = new MovementSubline(1, (p == null ? "Kein Produkt" : ProductFormater.toName(p) + " (" + p.getGroup().getNote() + ")"), uniqueUnit.getRefurbishId(), (stockUnit.getStock() == null ? stockUnit.getTransaction().toString() : stockUnit.getStock().getName()), uniqueUnit.getInternalComments().contains(UniqueUnit.StaticInternalComment.PREPARED_SHIPMENT));
            line.addMovementSubline(elem);
        }
        lines.add(line);
    }
    String title = listType.getName() + " - " + stock.getName();
    L.info("generateList {} containing {}", title, dossierids);
    m.message("erzeuge Report");
    Map<String, Object> reportParameter = new HashMap<>();
    reportParameter.put("TITLE", title);
    JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(lines);
    String name = "MovementList.jrxml";
    URL url = Objects.requireNonNull(getClass().getResource(name), "The Resource " + getClass().getPackage() + "/" + name + " not found.");
    try (InputStream is = url.openStream()) {
        JasperReport jasperReport = JasperCompileManager.compileReport(is);
        JasperPrint result = JasperFillManager.fillReport(jasperReport, reportParameter, datasource);
        return result;
    } catch (IOException | JRException e) {
        L.error("Exception during movementList", e);
        throw new RuntimeException(e);
    } finally {
        m.finish();
    }
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) URL(java.net.URL) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 13 with StockUnit

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

the class LogicTransactionEmo method optionalRemoveUnits.

/**
 * Removes StockUnits identified by UniqueUnitIds from a LogicTransaction, if it exists.
 *
 * @param dossierId     the dossierId of the LogicTransaction
 * @param uniqueUnitIds the uniqueUnitIds
 * @return the LogicTransaction after the removal, always returns a list.
 */
// TODO: Test
public List<StockUnit> optionalRemoveUnits(long dossierId, Collection<Integer> uniqueUnitIds) {
    if (uniqueUnitIds == null)
        throw new NullPointerException("uniqueUnitIds must not be null");
    // Null is possible
    LogicTransaction logicTransaction = new LogicTransactionEao(em).findByDossierId(dossierId);
    if (logicTransaction == null)
        return new ArrayList<>();
    List<StockUnit> stockUnits = new ArrayList<>();
    for (Integer uniqueUnitId : uniqueUnitIds) {
        // check stockunit if not in LogicTransaction.
        StockUnit unit = new StockUnitEao(em).findByUniqueUnitId(uniqueUnitId);
        if (unit == null)
            continue;
        if (unit.getLogicTransaction() == null)
            throw new IllegalStateException(unit + " is not on a LogicTransaction, shoud be on " + logicTransaction);
        if (!logicTransaction.equals(unit.getLogicTransaction()))
            throw new IllegalStateException(unit + " is on a different LogicTransaction than " + logicTransaction);
        logicTransaction.remove(unit);
        stockUnits.add(unit);
    }
    return stockUnits;
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 14 with StockUnit

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

the class LogicTransactionEmo method equilibrate.

/**
 * Brings the LogicTransaction identified by the dossierId and the supplied uniqueUnitIds in equilibrium.
 * <p/>
 * Handles the following states:
 * <ul>
 * <li>If uniqueUnitIds is empty a possible LogicTransaction is emptied and removed</li>
 * <li>Otherwise the LogicTransaction is synchronised with the uniqueUnitIds. possibly creating the LogicTransaction</li>
 * </ul>
 * TODO: Test (is Tested in RedTapeOperationTest)
 * <p/>
 * @param dossierId        the id of the dossier
 * @param newUniqueUnitIds List of uniqueUnitIds may not be null
 * @return a Result containing uniqueUnitIds which have been added an removed, or null if nothing happend.
 * @throws NullPointerException     if uniqueUnitIds is null
 * @throws IllegalArgumentException if a uniqueUnitId has no StockUnit
 * @throws IllegalStateException    if a StockUnit, that should be free, is already on a LogicTransaction.
 */
// TODO: Return removed, added.
public EquilibrationResult equilibrate(long dossierId, final Collection<Integer> newUniqueUnitIds) throws IllegalArgumentException, IllegalStateException, NullPointerException {
    L.debug("equilibrate dossierId={}, uniqueUnitIds={}", dossierId, newUniqueUnitIds);
    if (newUniqueUnitIds == null)
        throw new NullPointerException("uniqueUnitIds must not be null");
    // Null is possible
    LogicTransaction logicTransaction = new LogicTransactionEao(em).findByDossierId(dossierId, LockModeType.PESSIMISTIC_WRITE);
    if (logicTransaction == null && newUniqueUnitIds.isEmpty()) {
        L.debug("Both are empty, nothing to equilibrate");
        return null;
    }
    NavigableSet<Integer> adding = new TreeSet<>(newUniqueUnitIds);
    Map<Integer, StockUnit> oldStockUnits = new HashMap<>();
    NavigableSet<Integer> removal = new TreeSet<>();
    // Remove possible old stockuntis
    if (logicTransaction != null) {
        for (StockUnit stockUnit : logicTransaction.getUnits()) {
            oldStockUnits.put(stockUnit.getUniqueUnitId(), stockUnit);
        }
        removal.addAll(oldStockUnits.keySet());
        removal.removeAll(newUniqueUnitIds);
        // newUniqueUnitIds - oldUniqueUnitIds = notJetAdded
        adding.removeAll(oldStockUnits.keySet());
        L.debug("Removal: removing StockUnits with UniqueUnit.ids={} ", removal);
        for (Integer uniqueUnitId : removal) {
            logicTransaction.remove(oldStockUnits.get(uniqueUnitId));
        }
        if (newUniqueUnitIds.isEmpty()) {
            L.debug("Rqmoval: removing empty {}", logicTransaction);
            em.remove(logicTransaction);
            return null;
        }
    }
    // Non LT exists, but we need one.
    if (logicTransaction == null) {
        L.debug("Request: New LogicTransaction needed");
        logicTransaction = request(dossierId, LockModeType.PESSIMISTIC_WRITE);
        L.debug("Request: Result={}", logicTransaction);
    }
    L.debug("Adding: StockUnits with UniqueUnit.ids={}", adding);
    for (Integer uniqueUnitId : adding) {
        // check stockunit if not in LogicTransaction.
        StockUnit unit = new StockUnitEao(em).findByUniqueUnitId(uniqueUnitId);
        if (unit == null)
            throw new IllegalArgumentException("The supplied uniqueUnitId=" + uniqueUnitId + " has no StockUnit");
        if (unit.getLogicTransaction() != null)
            throw new IllegalStateException(unit + " is already in a LogicTransaction");
        else
            logicTransaction.add(unit);
    }
    L.debug("Adding: Result = {}", logicTransaction);
    return new EquilibrationResult(adding, removal, logicTransaction);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 15 with StockUnit

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

the class UnitDestroyerOperation method scrapDelete.

private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
    UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
    Dossier dos = doc.getDossier();
    doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
    doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
    st.addUnit(stockUnit);
    stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
    uu.addHistory(operation + " of Unit via " + st);
    uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
    uu.setSalesChannel(UNKNOWN);
    L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

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