Search in sources :

Example 26 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit 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 27 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UnitOverseerBean method toDetailedHtml.

/**
 * Find a Unit and its representative and return a html formated String representing it.
 * Ensure to add the html start/end tags manually
 * <p/>
 * @param uniqueUnitId the uniqueUnitId
 * @param username
 * @return a html formated String representing a Unit.
 */
@Override
public String toDetailedHtml(int uniqueUnitId, String username) {
    UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uuEao.findById(uniqueUnitId);
    if (uniqueUnit != null)
        return toDetailedHtmlUnit(uniqueUnit, hasRight(username, AtomicRight.VIEW_COST_AND_REFERENCE_PRICES));
    // Unique Unit is null, optional fallback to legacy system.
    return "<h1>Keine Informationen zu UniqueUnitId " + uniqueUnitId + "</h1>";
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 28 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit 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)

Example 29 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class CreditMemoReporterOperation method toXls.

@Override
public FileJacket toXls(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
    m.message("Loading Credit Memos");
    List<Position> creditMemoPositions = new ArrayList<>();
    for (Document document : new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.COMPLAINT, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE)) {
        for (Position position : document.getPositions().values()) {
            creditMemoPositions.add(position);
        }
    }
    m.setWorkRemaining(creditMemoPositions.size() * 2);
    UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
    m.message(null);
    List<Object[]> rows = new ArrayList<>();
    for (Position position : creditMemoPositions) {
        if (position.getType() == PositionType.COMMENT)
            continue;
        Document doc = position.getDocument();
        UiCustomer customer = customerService.asUiCustomer(position.getDocument().getDossier().getCustomerId());
        UniqueUnit unit = unitEao.findById(position.getUniqueUnitId());
        String error = "ERROR FINDING UNIT";
        String sopoNr = "-";
        String serial = "-";
        String contractor = "-";
        String fullOrPartial = "-";
        double customerPrice = 0;
        double retailerPrice = 0;
        if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
            if (unit == null) {
                sopoNr = error;
                serial = error;
                contractor = error;
            } else {
                sopoNr = unit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
                serial = unit.getIdentifier(UniqueUnit.Identifier.SERIAL);
                contractor = unit.getContractor().getName();
                customerPrice = unit.getPrice(PriceType.CUSTOMER);
                retailerPrice = unit.getPrice(PriceType.RETAILER);
                fullOrPartial = (position.getType() == PositionType.UNIT ? "V" : "T");
                if (position.getDocument().getType() == DocumentType.COMPLAINT)
                    fullOrPartial = "Rekla";
            }
        }
        rows.add(new Object[] { sopoNr, serial, position.getName(), contractor, fullOrPartial, position.getPrice(), position.toAfterTaxPrice(), position.getDocument().getDossier().getIdentifier(), doc.getActual(), position.getDocument().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), customerPrice, retailerPrice });
        m.worked(5);
    }
    Collections.sort(rows, comperator);
    m.message("Generating Document");
    m.setWorkRemaining(10);
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
    table.add(new STableColumn("SopoNr", 15)).add(new STableColumn("Seriennummer", 30)).add(new STableColumn("Name", 50)).add(new STableColumn("Contractor", 15)).add(new STableColumn("Voll/Teil", 10)).add(new STableColumn("Netto", 10, EURO)).add(new STableColumn("Brutto", 10, EURO)).add(new STableColumn("DossierId", 15)).add(new STableColumn("Belegdatum", 10, new CFormat(SHORT_DATE))).add(new STableColumn("DokumentId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Kunde", 50)).add(new STableColumn("Endkundenpreis(Netto)", 25, EURO)).add(new STableColumn("Händlerpreis(Netto)", 25, EURO));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
    cdoc.add(new CSheet("Sheet1", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    m.finish();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
    return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) 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) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) CBorder(eu.ggnet.lucidcalc.CBorder) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 30 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeCloserOperation method poluteReporting.

/**
 * Actually creating reportLines from the reportable documents.
 * For each position of a {@link Document} a {@link ReportLine} is created with all information supplied.
 * <p>
 * Exceptions are:
 * <ul>
 * <li>A {@link Document} with a {@link Condition#CANCELED} which is silently ignored</li>
 * <li>A {@link Document} with a {@link DocumentType#COMPLAINT} which sets all prices on the {@link ReportLine} to 0 and
 * <ul>
 * <li>If the {@link Document} has the {@link Condition#WITHDRAWN} or {@link Condition#REJECTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#DISCHARGED}</li>
 * <li>If the {@link Document} has the {@link Condition#ACCEPTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#CHARGED}</li>
 * <li>Otherwise set {@link ReportLine#workflowStatus} to {@link ReportLine.WorkflowStatus#UNDER_PROGRESS}</li>
 * </ul>
 * </li>
 * <li>A {@link Document} with a {@link DocumentType#CREDIT_MEMO} gets its prices inverted</li>
 * </ul>
 * <p/>
 * @param reportable the documents to create lines from
 * @param monitor    a optional monitor.
 * @return the amount of created lines.
 */
private int poluteReporting(Set<Document> reportable, Date reporting, IMonitor monitor) {
    WarrantyService warrantyService = null;
    if (!warrantyServiceInstance.isUnsatisfied()) {
        warrantyService = warrantyServiceInstance.get();
    }
    SubMonitor m = SubMonitor.convert(monitor, reportable.size() + 10);
    m.start();
    ReportLineEao reportLineEao = new ReportLineEao(reportEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductEao productEao = new ProductEao(uuEm);
    int amountCreate = 0;
    List<ReportLine> newLines = new ArrayList<>(reportable.size());
    for (Document document : reportable) {
        m.worked(1, "reported " + document.getIdentifier());
        // A canceled document must be closed, but must not create a reportline.
        if (document.getConditions().contains(Condition.CANCELED))
            continue;
        ReportLine l;
        for (Position position : document.getPositions().values()) {
            amountCreate++;
            l = new ReportLine();
            l.setActual(document.getActual());
            l.setAmount(position.getAmount());
            l.setBookingAccount(position.getBookingAccount().map(Ledger::getValue).orElse(-1));
            l.setCustomerId(document.getDossier().getCustomerId());
            l.setDescription(normalizeSpace(position.getDescription()));
            l.setDocumentId(document.getId());
            l.setDocumentIdentifier(document.getIdentifier());
            l.setDocumentType(document.getType());
            l.setDossierId(document.getDossier().getId());
            l.setDossierIdentifier(document.getDossier().getIdentifier());
            // TODO: We could use something else for a separator, but keep in mind that we want to avoid name, , , something.
            l.setInvoiceAddress(normalizeSpace(document.getInvoiceAddress().getDescription()));
            l.setName(normalizeSpace(position.getName()));
            l.setPositionType(position.getType());
            l.setPrice(position.getPrice());
            l.setReportingDate(reporting);
            l.setTax(position.getTax());
            // Set via Report afterwards
            l.setMarginPercentage(0);
            // Set via Report afterwards
            l.setPurchasePrice(0);
            UiCustomer c = customerService.asUiCustomer(document.getDossier().getCustomerId());
            if (c != null) {
                l.setCustomerCompany(c.getCompany());
                l.setCustomerName(c.toTitleNameLine());
                l.setCustomerEmail(c.getEmail());
            }
            // A Credit Memo gets its prices inverted
            if (document.getType() == DocumentType.CREDIT_MEMO) {
                l.setPrice(position.getPrice() * (-1));
            }
            // Special handling of complaints.
            if (document.getType() == DocumentType.COMPLAINT) {
                // A Complaint position has "tagging" effect, but shall never result in a plus or minus.
                l.setPrice(0);
                if (document.getConditions().contains(Condition.REJECTED) || document.getConditions().contains(Condition.WITHDRAWN)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.DISCHARGED);
                } else if (document.getConditions().contains(Condition.ACCEPTED)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.CHARGED);
                } else {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.UNDER_PROGRESS);
                }
            }
            // Extra information for Type Position
            if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
                UniqueUnit uu = Objects.requireNonNull(uniqueUnitEao.findById(position.getUniqueUnitId()), "No UniqueUnit with id=" + position.getUniqueUnitId());
                Product p = uu.getProduct();
                if (uu.getContractor() == p.getTradeName().getManufacturer()) {
                    l.setContractorPartNo(p.getPartNo());
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                } else {
                    l.setContractorPartNo(p.getAdditionalPartNo(uu.getContractor()));
                    l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                }
                l.setManufacturerCostPrice(p.getPrice(MANUFACTURER_COST));
                l.setContractor(uu.getContractor());
                l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                if (Math.abs(l.getContractorReferencePrice()) < 0.001)
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                l.setMfgDate(uu.getMfgDate());
                l.setRefurbishId(uu.getRefurbishId());
                l.setSerial(uu.getSerial());
                l.setUniqueUnitId(uu.getId());
                l.setSalesChannel(uu.getSalesChannel());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductName(p.getName());
                l.setProductGroup(p.getGroup());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
            // Extra Information for Type Product Batch
            } else if (position.getType() == PositionType.PRODUCT_BATCH) {
                Product p = Objects.requireNonNull(productEao.findById(position.getUniqueUnitProductId()), "No Product for id=" + position.getUniqueUnitProductId());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductGroup(p.getGroup());
                l.setProductName(p.getName());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
                l.setUniqueUnitId(position.getUniqueUnitId());
                l.setSerial(position.getSerial());
                l.setRefurbishId(position.getRefurbishedId());
                if (warrantyService != null) {
                    // If this is no warranty Partno, this will return null ;-)
                    l.setContractor(warrantyService.warrantyContractor(p.getPartNo()));
                }
            }
            reportEm.persist(l);
            newLines.add(l);
        }
    }
    reportEm.flush();
    m.message("Updateing References");
    for (ReportLine newLine : newLines) {
        // Not Refs for Product_Batches or Versandkosten jet.
        if (newLine.getUniqueUnitId() < 1)
            continue;
        if (newLine.getPositionType() == PositionType.PRODUCT_BATCH) {
            // TODO: also evaluate the productId.
            newLine.addAll(reportLineEao.findBySerialAndPositionTypeAndDossierId(newLine.getSerial(), newLine.getPositionType(), newLine.getDossierId()));
        } else {
            newLine.addAll(reportLineEao.findUnitsAlike(newLine.getUniqueUnitId(), newLine.getDossierId()));
        }
    }
    updateSingleReferences(newLines);
    m.worked(5);
    m.finish();
    return amountCreate;
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) WarrantyService(eu.ggnet.dwoss.mandator.api.service.WarrantyService) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer)

Aggregations

UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)88 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)38 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)31 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)27 Test (org.junit.Test)21 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)20 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)16 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)13 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)7 java.util (java.util)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)6 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)6 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 UniqueUnitAgent (eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 DocumentType (eu.ggnet.dwoss.rules.DocumentType)5 Collectors (java.util.stream.Collectors)5