Search in sources :

Example 21 with StockUnit

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

the class UnitProcessorOperation method receipt.

/**
 * Receipts a new Unit.
 * Multiphase Process:
 * <ol>
 * <li>Validation and throw IllegalArgumentException if
 * <ul>
 * <li>Supplied UniqueUnit is already persistent</li>
 * <li>RefurbishedId is already taken</li>
 * <li>Serial is already taken and Unit is in Stock [UniqueUnit &amp; Stock]</li>
 * </ul>
 * </li>
 * <li>If serial is taken update existing Unit else persist Unit[UniqueUnit]<br />
 * (At this point it implies that the Unit is not in Stock)</li>
 * <li>Create, weak reference StockUnit and prepare for rollIn [Stock]</li>
 * </ol>
 * <p/>
 * @param shipment         the shipment
 * @param receiptUnit      the UniqueUnit to be receipt, must not be null
 * @param operation        the Operation to do
 * @param transaction
 * @param arranger
 * @param operationComment
 * @throws IllegalArgumentException if validation fails
 */
@Override
public void receipt(UniqueUnit receiptUnit, Product product, Shipment shipment, StockTransaction transaction, ReceiptOperation operation, String operationComment, String arranger) throws IllegalArgumentException {
    L.info("Receiping Unit(id={},refurbishId={},name={}) on StockTransaction(id={}) with {} by {}", receiptUnit.getId(), receiptUnit.getRefurbishId(), ProductFormater.toNameWithPartNo(product), transaction.getId(), operation, arranger);
    validateReceipt(receiptUnit);
    UniqueUnit uniqueUnit = receiptUniqueUnit(receiptUnit, Objects.requireNonNull(product, "Product == null, not allowed"), shipment);
    StockUnit stockUnit = receiptAndAddStockUnit(uniqueUnit, transaction);
    // Nothing to do
    if (operation == ReceiptOperation.SALEABLE)
        return;
    executeOperation(uniqueUnit, stockUnit, operation, operationComment, arranger);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 22 with StockUnit

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

the class RedTapeWorkerOperation method toDetailedHtml.

/**
 * Create a HTML formated String representing the detailed information from a {@link Dossier}.
 * <p/>
 * @param dossierId The Dossier
 * @return a HTML formated String representing the detailed information from a {@link Dossier}.
 */
@Override
public String toDetailedHtml(long dossierId) {
    Dossier dos = redTapeEm.find(Dossier.class, dossierId);
    if (dos == null)
        return "<strong>No Dossier with Id: " + dossierId + " found</strong>";
    String detailedHtmlCustomer = customerService.asHtmlHighDetailed(dos.getCustomerId());
    String stockInfo = "StockUnits:<ul>";
    for (StockUnit stockUnit : new StockUnitEao(stockEm).findByUniqueUnitIds(dos.getRelevantUniqueUnitIds())) stockInfo += "<li>" + stockUnit + "</li>";
    stockInfo += "</ul>";
    return "<html>" + detailedHtmlCustomer + "<br />" + DossierFormater.toHtmlDetailed(dos) + "<br />" + stockInfo + "</html>";
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 23 with StockUnit

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

the class UnitOverseerBean method internalFind.

private UnitShard internalFind(String refurbishId) {
    L.debug("find({})", refurbishId);
    UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
    UniqueUnit uu = uuEao.findByIdentifier(Identifier.REFURBISHED_ID, refurbishId);
    String oldRefurbishedOd = null;
    L.debug("find({}) uniqueUnit={}", refurbishId, uu);
    if (uu == null) {
        uu = uuEao.findByRefurbishedIdInHistory(refurbishId);
        if (uu == null) {
            if (!bridgeInstance.isUnsatisfied() && !bridgeInstance.get().isUnitIdentifierAvailable(refurbishId)) {
                return new UnitShard(refurbishId, 0, toHtmlDescription(refurbishId, null, "Nicht Verfügbar", "", "(Auskunft aus Sopo)"), false, null);
            } else {
                return new UnitShard(refurbishId, 0, "<html>SopoNr.:<b>" + refurbishId + "<u> existiert nicht.</u><br /><br /></b></html>", null, null);
            }
        } else {
            oldRefurbishedOd = "(Frühere SopoNr: " + refurbishId + ")";
            refurbishId = uu.getIdentifier(REFURBISHED_ID);
        }
    }
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    L.debug("find({}) stockUnit={}", refurbishId, stockUnit);
    Integer stockId = null;
    if (stockUnit != null && stockUnit.isInStock())
        stockId = stockUnit.getStock().getId();
    if (stockUnit == null) {
        return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", "", null), false, null);
    }
    if (stockUnit.getLogicTransaction() != null) {
        return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, null), false, stockId);
    }
    // If the Database is clean, the Unit is available, but we make some safty checks here.
    if (new DossierEao(redTapeEm).isUnitBlocked(uu.getId())) {
        L.warn("find({}) Database Error RedTape sanity check", refurbishId);
        return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, "(Datenbankfehler, RedTape sanity check!)"), false, stockId);
    }
    // Now we are shure.
    return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Verfügbar", stockUnit, null), true, stockId);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UnitShard(eu.ggnet.dwoss.uniqueunit.api.UnitShard) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 24 with StockUnit

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

the class UnitOverseerBean method throwNotAvailable.

/**
 * Build and throw an exception for a not available unit.
 * <p>
 * @param refurbishId the refurbished id of the unit
 * @param us          the unit shard
 * @throws UserInfoException
 */
private void throwNotAvailable(String refurbishId, UnitShard us) throws UserInfoException {
    // <- auch in di auslagerung...
    if (us.getAvailable() == null)
        throw new UserInfoException("SopoNr " + refurbishId + " existiert nicht");
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(us.getUniqueUnitId());
    if (stockUnit != null && stockUnit.getLogicTransaction() != null) {
        Dossier dos = new DossierEao(redTapeEm).findById(stockUnit.getLogicTransaction().getDossierId());
        if (dos == null)
            throw new UserInfoException("SopoNr " + refurbishId + " is on a LogicTransaction, but there is no Dossier, inform Team Software");
        UiCustomer customer = customerService.asUiCustomer(dos.getCustomerId());
        if (customer == null)
            throw new UserInfoException("SopoNr " + refurbishId + " is on Dossier " + dos.getIdentifier() + ", but Customer " + dos.getCustomerId() + " does not exist.");
        throw new UserInfoException("SopoNr " + refurbishId + " ist schon vergeben" + "\nKID = " + customer.getId() + "\nKunde = " + customer.toTitleNameLine() + "\n\nVorgang = " + dos.getIdentifier());
    }
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer)

Example 25 with StockUnit

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

the class RedTapeGeneratorOperation method makeSalesDossiers.

/**
 * Generates a random amount of dossiers in a random valid state using already persisted elements like available units and product batches.
 * <p/>
 * @param amount
 * @return the list of generated dossiers.
 */
// TODO: Some usefull repayments would be nice.
public List<Dossier> makeSalesDossiers(int amount) {
    SubMonitor m = monitorFactory.newSubMonitor("Erzeuge " + amount + " Dossiers", amount);
    m.start();
    if (amount < 1)
        return Collections.EMPTY_LIST;
    List<CustomerMetaData> customers = customerService.allAsCustomerMetaData().stream().filter(c -> !c.getFlags().contains(SYSTEM_CUSTOMER)).collect(toList());
    if (customers.isEmpty())
        throw new RuntimeException("No Customers found, obviously there are non in the database");
    List<UniqueUnit> freeUniqueUnits = uniqueUnitAgent.findAllEager(UniqueUnit.class);
    List<Product> products = uniqueUnitAgent.findAllEager(Product.class);
    List<Dossier> dossiers = new ArrayList<>();
    for (int i = 0; i <= amount; i++) {
        CustomerMetaData customer = customers.get(R.nextInt(customers.size()));
        // Create a dossier on a random customer.
        Dossier dos = redTapeWorker.create(customer.getId(), R.nextBoolean(), "Generated by RedTapeGeneratorOperation.makeSalesDossiers()");
        Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
        // At least two positions.
        int noOfPositions = R.nextInt(10) + 2;
        Set<Long> productIds = new HashSet<>();
        for (int j = 0; j < noOfPositions; j++) {
            // Add Some units, but make sure, not only units are added.
            if (j < (noOfPositions - 2) && !freeUniqueUnits.isEmpty()) {
                UniqueUnit uu = null;
                while (uu == null && !freeUniqueUnits.isEmpty()) {
                    uu = freeUniqueUnits.remove(0);
                    StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uu.getId());
                    // Saftynet, so no unit is set double.
                    if (su == null || su.getLogicTransaction() != null)
                        uu = null;
                }
                if (uu == null)
                    continue;
                double price = uu.getPrice(PriceType.CUSTOMER);
                if (price < 0.001)
                    price = uu.getPrice(PriceType.RETAILER);
                if (price < 0.001)
                    price = 1111.11;
                Position pos = Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(price).tax(doc.getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).refurbishedId(uu.getIdentifier(REFURBISHED_ID)).build();
                doc.append(pos);
                continue;
            }
            double price = (R.nextInt(100000) + 100) / 100;
            switch(// Add a random position
            R.nextInt(3)) {
                case // Add a Product Batch
                0:
                    Product p;
                    int k = 0;
                    do {
                        p = products.get(R.nextInt(products.size()));
                        k++;
                        if (k > 10)
                            throw new RuntimeException("Could find a alternative product : p.size=" + products.size() + ", pids.size=" + productIds.size());
                    } while (productIds.contains(p.getId()));
                    productIds.add(p.getId());
                    doc.append(Position.builder().amount(R.nextInt(10) + 1).type(PositionType.PRODUCT_BATCH).uniqueUnitProductId(p.getId()).price(price).tax(doc.getSingleTax()).name(p.getName()).description(p.getDescription()).bookingAccount(postLedger.get(PositionType.PRODUCT_BATCH, doc.getTaxType()).orElse(null)).build());
                    break;
                case // Add a Service
                1:
                    doc.append(Position.builder().amount((R.nextInt(100) + 1) / 4.0).type(PositionType.SERVICE).price(price).tax(doc.getSingleTax()).name("Service").description("Service").bookingAccount(postLedger.get(PositionType.SERVICE, doc.getTaxType()).orElse(null)).build());
                    break;
                case // Add a comment
                2:
                    doc.append(Position.builder().amount(1).type(PositionType.COMMENT).name("Comment").description("Comment").bookingAccount(postLedger.get(PositionType.COMMENT, doc.getTaxType()).orElse(null)).build());
                    break;
            }
        }
        if (dos.isDispatch()) {
            // add the shipping costs.
            double price = (R.nextInt(10) + 1) * 10;
            doc.append(Position.builder().amount(1).type(PositionType.SHIPPING_COST).price(price).tax(doc.getSingleTax()).name("Versandkosten").description("Versandkosten").bookingAccount(postLedger.get(PositionType.SHIPPING_COST, doc.getTaxType()).orElse(null)).build());
        }
        // Break, if what we build is wrong.
        ValidationUtil.validate(doc);
        LOG.info("Preupdate document.id={}", doc.getId());
        doc = redTapeWorker.update(doc, null, "JUnit");
        for (int j = 0; j <= R.nextInt(4); j++) {
            CustomerDocument cd = new CustomerDocument(customer.getFlags(), doc, customer.getShippingCondition(), customer.getPaymentMethod());
            List<StateTransition<CustomerDocument>> transitions = redTapeWorker.getPossibleTransitions(cd);
            if (transitions.isEmpty())
                break;
            RedTapeStateTransition transition = (RedTapeStateTransition) transitions.get(R.nextInt(transitions.size()));
            if (transition.getHints().contains(RedTapeStateTransition.Hint.CREATES_ANNULATION_INVOICE) || transition.getHints().contains(RedTapeStateTransition.Hint.CREATES_CREDIT_MEMO))
                break;
            // Never fails.
            Reply<Document> reply = redTapeWorker.stateChange(cd, transition, "JUnit");
            if (reply.hasSucceded())
                doc = reply.getPayload();
            else {
                LOG.error("Fail on startChange {}", reply.getSummary());
                break;
            }
        }
        dossiers.add(doc.getDossier());
        m.worked(1, doc.getDossier().getIdentifier());
    }
    m.finish();
    return dossiers;
}
Also used : java.util(java.util) CustomerServiceBean(eu.ggnet.dwoss.customer.ee.CustomerServiceBean) PostLedger(eu.ggnet.dwoss.mandator.api.value.PostLedger) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LoggerFactory(org.slf4j.LoggerFactory) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StateTransition(eu.ggnet.statemachine.StateTransition) SYSTEM_CUSTOMER(eu.ggnet.dwoss.rules.CustomerFlag.SYSTEM_CUSTOMER) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) REQUIRES_NEW(javax.ejb.TransactionAttributeType.REQUIRES_NEW) DocumentType(eu.ggnet.dwoss.rules.DocumentType) ValidationUtil(eu.ggnet.dwoss.util.validation.ValidationUtil) UniqueUnitFormater(eu.ggnet.dwoss.uniqueunit.ee.format.UniqueUnitFormater) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) Logger(org.slf4j.Logger) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) PositionType(eu.ggnet.dwoss.rules.PositionType) REFURBISHED_ID(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit.Identifier.REFURBISHED_ID) Collectors.toList(java.util.stream.Collectors.toList) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) eu.ggnet.dwoss.redtape.ee.entity(eu.ggnet.dwoss.redtape.ee.entity) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) Reply(eu.ggnet.saft.api.Reply) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument) javax.ejb(javax.ejb) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) StateTransition(eu.ggnet.statemachine.StateTransition) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)

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