Search in sources :

Example 1 with Product

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

the class ProductProcessorOperation method create.

/**
 * Creates a new ProductSpec and the relating Product and SopoProduct.
 * <p>
 * The process has multiple steps:
 * <ol>
 * <li>Merge the ProductModel and set it in the Spec</li>
 * <li>If Spec is a DisplayAble its assumed the Display is either existent or new.<br />
 * In case it exists, the existent value will be set in the Spec</li>
 * <li>If Spec is a Desktop its assumed that the Cpu and Gpu are existent, and they are merged and set.</li>
 * <li>The Spec is persisted</li>
 * <li>A Product is created and persisted</li>
 * <li>The Spec.productId is set to Product.id (WeakReference)</li>
 * <li>A SopoProduct is searched. If found, it is updated, else a new one is created</li>
 * </ol>
 *
 * @param spec  the spec to persist, must not be null
 * @param model the model for the spec, must not be null or new
 * @param gtin  the value of gtin
 * @throws IllegalArgumentException if Cpu or Gpu in a Desktop are new.
 *
 * @return the eu.ggnet.dwoss.spec.entity.ProductSpec
 */
// TODO: Check if the model as parameter is still needed.
@Override
public ProductSpec create(ProductSpec spec, ProductModel model, long gtin) throws IllegalArgumentException {
    if (model == null)
        throw new NullPointerException("Model is null");
    if (spec == null)
        throw new NullPointerException("ProductSpec is null");
    // Hint: Normally the column unique option should do that, but HSQLDB somehow lost it.
    if (new ProductEao(uuEm).findByPartNo(spec.getPartNo()) != null)
        throw new IllegalArgumentException("PartNo=" + spec.getPartNo() + " exists allready, but create is calles");
    ProductModelEmo productModelEmo = new ProductModelEmo(specEm);
    model = productModelEmo.request(model.getFamily().getSeries().getBrand(), model.getFamily().getSeries().getGroup(), model.getFamily().getSeries().getName(), model.getFamily().getName(), model.getName());
    spec.setModel(model);
    if (spec instanceof DisplayAble) {
        DisplayAble da = (DisplayAble) spec;
        da.setDisplay(new DisplayEmo(specEm).weakRequest(da.getDisplay().getSize(), da.getDisplay().getResolution(), da.getDisplay().getType(), da.getDisplay().getRation()));
    }
    if (spec instanceof Desktop) {
        Desktop desktop = (Desktop) spec;
        if (desktop.getCpu() == null || desktop.getGpu() == null)
            throw new IllegalArgumentException("Cpu or Gpu of a Desktop are null. " + desktop);
        Cpu cpu = new CpuEao(specEm).findById(desktop.getCpu().getId());
        Gpu gpu = new GpuEao(specEm).findById(desktop.getGpu().getId());
        if (cpu != null)
            desktop.setCpu(cpu);
        if (gpu != null)
            desktop.setGpu(gpu);
    }
    if (spec instanceof DesktopBundle) {
        DesktopBundle bundle = (DesktopBundle) spec;
        if (bundle.getDesktop().getId() == 0 || bundle.getMonitor().getId() == 0)
            throw new IllegalArgumentException("Monitor or Desktop are new. Impossible");
        ProductSpecEao specEao = new ProductSpecEao(specEm);
        bundle.setDesktop(specEao.findById(bundle.getDesktop().getId()));
        bundle.setMonitor(specEao.findById(bundle.getMonitor().getId()));
    }
    L.info("Persisting {} including model change={}", SpecFormater.toDetailedName(spec), (model == spec.getModel()));
    specEm.persist(spec);
    // Ensuring Id generation.
    specEm.flush();
    ProductEao productEao = new ProductEao(uuEm);
    Product product = productEao.findByPartNo(spec.getPartNo());
    if (product == null)
        product = new Product();
    product.setGroup(spec.getModel().getFamily().getSeries().getGroup());
    product.setTradeName(spec.getModel().getFamily().getSeries().getBrand());
    product.setPartNo(spec.getPartNo());
    product.setName(spec.getModel().getName());
    product.setDescription(SpecFormater.toSingleLine(spec));
    product.setGtin(gtin);
    L.debug("persisting {}", product);
    if (!uuEm.contains(product)) {
        uuEm.persist(product);
        // Ensuring Id generation
        uuEm.flush();
    }
    L.debug("creating weak reference ProductSpec.productId=Product.id value ({})", product.getId());
    spec.setProductId(product.getId());
    return spec;
}
Also used : ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) Cpu(eu.ggnet.dwoss.spec.ee.entity.piece.Cpu) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) DisplayEmo(eu.ggnet.dwoss.spec.ee.emo.DisplayEmo) DesktopBundle(eu.ggnet.dwoss.spec.ee.entity.DesktopBundle) Gpu(eu.ggnet.dwoss.spec.ee.entity.piece.Gpu) GpuEao(eu.ggnet.dwoss.spec.ee.eao.GpuEao) DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Desktop(eu.ggnet.dwoss.spec.ee.entity.Desktop) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) CpuEao(eu.ggnet.dwoss.spec.ee.eao.CpuEao)

Example 2 with Product

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

the class ProductProcessorOperation method update.

/**
 * Updates an existing ProductSpec and the relating Product and SopoProduct.
 * <p>
 * The process has multiple steps:
 * <ol>
 * <li>Validate and throw IllegalArgumentException:
 * <ul>
 * <li>if the ProductSpec.productId == null</li>
 * <li>if there does not exist a Product with ProductSpec.productId</li>
 * <li>if there does not exist a SopoProduct with Product.partNo (unchanged)</li>
 * </ul>
 * </li>
 * <li>If Spec is a DisplayAble its assumed the Display is either existent or new.<br />
 * In case it exists, the existent value will be set in the Spec</li>
 * <li>if the supplied ProductModel is different from ProductSpec.getModel it is merged and set</li>
 * <li>Overwrite all changes in Product</li>
 * <li>Overwrite all changes in SopoProduct</li>
 * <li> If PartNo change propagate to all matching SopoUnits</li>
 * </ol>
 *
 * @param spec the spec to be updated, must not be null and not new
 * @param gtin the value of gtin
 * @throws IllegalArgumentException if spec.productId == null
 * @return the eu.ggnet.dwoss.spec.entity.ProductSpec
 */
@Override
public ProductSpec update(ProductSpec spec, long gtin) throws IllegalArgumentException {
    // 1. Validation
    if (spec.getProductId() == null)
        throw new IllegalArgumentException("ProductSpec has no productId, violation ! " + spec);
    ProductEao productEao = new ProductEao(uuEm);
    Product product = productEao.findById(spec.getProductId());
    if (product == null)
        throw new IllegalArgumentException("ProductSpec.productId=" + spec.getProductId() + " does not have a Product");
    // 2. + 3. Update Spec
    if (spec instanceof DisplayAble && ((DisplayAble) spec).getDisplay().getId() == 0) {
        DisplayAble monitor = (DisplayAble) spec;
        DisplayEao displayEao = new DisplayEao(specEm);
        Display display = monitor.getDisplay();
        display = displayEao.find(display.getSize(), display.getResolution(), display.getType(), display.getRation());
        if (display != null)
            monitor.setDisplay(display);
    }
    L.info("updateing {}", SpecFormater.toDetailedName(spec));
    spec = specEm.merge(spec);
    // 4. overwrite Product
    product.setGroup(spec.getModel().getFamily().getSeries().getGroup());
    product.setTradeName(spec.getModel().getFamily().getSeries().getBrand());
    product.setPartNo(spec.getPartNo());
    product.setName(spec.getModel().getName());
    product.setDescription(SpecFormater.toSingleLine(spec));
    product.setGtin(gtin);
    L.debug("updateing {}", product);
    return spec;
}
Also used : DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) DisplayEao(eu.ggnet.dwoss.spec.ee.eao.DisplayEao) Display(eu.ggnet.dwoss.spec.ee.entity.piece.Display)

Example 3 with Product

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

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

Example 5 with Product

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

the class CreditMemoReportIT method testCreditMemoReportOperation.

@Test
public void testCreditMemoReportOperation() throws IOException, InterruptedException {
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
    UniqueUnit uu1 = uus.get(0);
    UniqueUnit uu2 = uus.get(1);
    UniqueUnit uu3 = uus.get(2);
    UniqueUnit uu4 = uus.get(3);
    Product uuProduct1 = uu1.getProduct();
    assertThat(uu1).describedAs("First generated UniqueUnit").isNotNull();
    StockUnit su1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
    assertThat(su1).describedAs("StockUnit of generated UniqueUnit").isNotNull();
    assertThat(su1.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
    int stockIdOfUU1 = su1.getStock().getId();
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    doc.append(unit(uu1));
    doc.append(unit(uu2));
    doc.append(unit(uu3));
    doc.append(comment());
    doc.append(service());
    doc.append(batch(uuProduct1));
    doc.append(shippingcost());
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    doc = redTapeWorker.update(doc, null, "JUnit");
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeWorker.update(doc, null, "JUnit");
    LogicTransaction lt = support.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
    // A CreditMemo for Unit1, negate prices on Annulation Invoice.
    for (Position pos : new ArrayList<>(doc.getPositions().values())) {
        if (pos.getUniqueUnitId() == uu1.getId() || pos.getType() == PRODUCT_BATCH || pos.getType() == SHIPPING_COST) {
            pos.setPrice(pos.getPrice() * -1);
        } else {
            doc.remove(pos);
        }
    }
    assertEquals("Document should have exactly one possition", 3, doc.getPositions().size());
    doc.setType(DocumentType.ANNULATION_INVOICE);
    doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
    Collection<Position> positions = doc.getPositions().values();
    // Report somethere in the past till now.
    FileJacket jacket = reportOperation.toXls(new Date(1352115909), new Date());
    assertNotNull(jacket);
    assertEquals(".xls", jacket.getSuffix());
    assertTrue(jacket.getContent().length > 0);
    List<LoadContainer> read = new JExcelLucidCalcReader().addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, String.class).addColumn(4, String.class).addColumn(5, Double.class).addColumn(6, Double.class).read(jacket.toTemporaryFile(), LoadContainer.class);
    // HINT: Not a complete test, but some fileds at least.
    assertThat(positions.stream().map(Position::getPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.netto).toArray((v) -> new Double[v]));
    assertThat(positions.stream().map(Position::toAfterTaxPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.brutto).toArray((v) -> new Double[v]));
    assertThat(positions.stream().map(Position::getName).collect(toSet())).containsOnly(read.stream().map(l -> l.name).toArray((v) -> new String[v]));
}
Also used : java.util(java.util) CreditMemoReporter(eu.ggnet.dwoss.redtapext.ee.reporting.CreditMemoReporter) Arquillian(org.jboss.arquillian.junit.Arquillian) CustomerGeneratorOperation(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) SupportBean(eu.ggnet.dwoss.redtapext.op.itest.support.SupportBean) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) DocumentType(eu.ggnet.dwoss.rules.DocumentType) ToString(lombok.ToString) NaivBuilderUtil(eu.ggnet.dwoss.redtapext.op.itest.support.NaivBuilderUtil) EJB(javax.ejb.EJB) Collectors.toSet(java.util.stream.Collectors.toSet) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) FileJacket(eu.ggnet.dwoss.util.FileJacket) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) IOException(java.io.IOException) Test(org.junit.Test) SHIPPING_COST(eu.ggnet.dwoss.rules.PositionType.SHIPPING_COST) PRODUCT_BATCH(eu.ggnet.dwoss.rules.PositionType.PRODUCT_BATCH) eu.ggnet.dwoss.redtape.ee.entity(eu.ggnet.dwoss.redtape.ee.entity) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ArquillianProjectArchive(eu.ggnet.dwoss.redtapext.op.itest.support.ArquillianProjectArchive) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) AllArgsConstructor(lombok.AllArgsConstructor) Assert(org.junit.Assert) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ToString(lombok.ToString) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test)

Aggregations

Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)50 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 Test (org.junit.Test)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)13 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)11 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)11 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)9 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)8 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)5 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)5 PriceType (eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)5 java.util (java.util)5 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)4 CategoryProduct (eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct)4 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)4 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)4 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)3 TradeName (eu.ggnet.dwoss.rules.TradeName)3 CustomerMetaData (eu.ggnet.dwoss.customer.opi.CustomerMetaData)2