Search in sources :

Example 31 with UniqueUnit

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

Example 32 with UniqueUnit

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

the class UnitSupporterOperation method isSerialAvailable.

@Override
public boolean isSerialAvailable(String serial) {
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.SERIAL, serial);
    if (uu != null) {
        StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uu.getId());
        if (stockUnit != null) {
            return false;
        }
    }
    return true;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 33 with UniqueUnit

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

the class ReceiptGeneratorOperation method makeUniqueUnit.

/**
 * Generates one UniquUnits and receipts it.
 *
 * @return the generated UniquUnits.
 */
public UniqueUnit makeUniqueUnit() {
    Stock stock = findOrMakeStock();
    TradeName contractor = new ArrayList<>(contractors.all()).get(R.nextInt(contractors.all().size()));
    Shipment shipment = new Shipment("TEST-SHIPMENT-" + R.nextInt(10), contractor, TradeName.ACER, Shipment.Status.OPENED);
    stockEm.persist(shipment);
    StockTransaction transaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "SampleGenerator", "Rollin via makeUniqueUnit");
    ProductSpec productSpec = makeProductSpec();
    Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
    UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
    unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    return uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 34 with UniqueUnit

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

the class RefurbishmentReporterOperation method toXls.

/**
 * Generates the report between two dates for the contractor.
 *
 * @param contractor the contractor to report about.
 * @param start      the starting date
 * @param end        the end date
 * @return an XLS document as FileJacket
 */
@Override
public FileJacket toXls(TradeName contractor, Date start, Date end) {
    // TODO: Init me from contractor
    double singleRefurbishPrice = 0.;
    // TODO: Init me from contractor.
    double singleRefillPrice = 0.;
    double refurbishedPriceSum = 0.;
    double refilledPriceSum = 0.;
    SubMonitor m = monitorFactory.newSubMonitor("Refurbishment Abrechnung", 100);
    m.message("Loading Units");
    List<Object[]> refurbishedSopoUnits = new ArrayList<>();
    List<Object[]> refilledSopoUnits = new ArrayList<>();
    List<UniqueUnit> units = new UniqueUnitEao(uuem).findBetweenInputDatesAndContractor(start, end, contractor);
    m.worked(10);
    m.setWorkRemaining(units.size() + 10);
    for (UniqueUnit uu : units) {
        if (uu.getInternalComments().contains(StaticInternalComment.REFILLED)) {
            refilledSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
            refilledPriceSum += singleRefillPrice;
        } else if (uu.getInternalComments().contains(StaticInternalComment.RECOVERT)) {
            refurbishedSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
            refurbishedPriceSum += singleRefurbishPrice;
        }
    }
    double tax = (refilledPriceSum + refurbishedPriceSum) * GlobalConfig.DEFAULT_TAX.getTax();
    CSheet summary = new CSheet("Summery", 5, 30, 15, 15, 15);
    SBlock headerAndDate = new SBlock();
    SBlock data = new SBlock();
    SBlock prices = new SBlock();
    headerAndDate.setFormat(new CFormat(BOLD, Color.BLACK, Color.WHITE, LEFT, new CBorder(Color.LIGHT_GRAY, CBorder.LineStyle.HAIR)));
    headerAndDate.add("Report über recoverte und wiederaufgefüllte Geräte");
    headerAndDate.add("Reportzeitraum:", DATE_FORMAT.format(start) + " - " + DATE_FORMAT.format(end));
    summary.addBelow(1, 1, headerAndDate);
    data.add("", "Anzahl", "Einzelpreis", "Summe");
    data.add("Recoverte Geräte", refurbishedSopoUnits.size(), singleRefurbishPrice, EURO_FORMAT, refurbishedPriceSum, EURO_FORMAT);
    data.add("Wiederaufgefüllte Geräte", refilledSopoUnits.size(), singleRefillPrice, EURO_FORMAT, refilledPriceSum, EURO_FORMAT);
    summary.addBelow(1, 1, data);
    prices.add("", "", "netto", refilledPriceSum + refurbishedPriceSum, EURO_FORMAT);
    prices.add("", "", "Mwst", tax, EURO_FORMAT);
    prices.add("", "", "Mwst", refilledPriceSum + refurbishedPriceSum + tax, EURO_FORMAT);
    summary.addBelow(1, 1, prices);
    STable refurbishedTable = new STable();
    refurbishedTable.setHeadlineFormat(new CFormat(BOLD, Color.BLACK, Color.YELLOW, RIGHT, new CBorder(Color.BLACK)));
    refurbishedTable.add(new STableColumn("Seriennummer", 22)).add(new STableColumn("Bezeichnnung", 40));
    refurbishedTable.setModel(new STableModelList(refurbishedSopoUnits));
    STable refilledTable = new STable(refurbishedTable);
    refilledTable.setModel(new STableModelList(refilledSopoUnits));
    CCalcDocument cdoc = new TempCalcDocument("RefurbishedReport_" + contractor);
    cdoc.add(summary);
    cdoc.add(new CSheet("Refurbished", refurbishedTable));
    cdoc.add(new CSheet("Aufgefüllt", refilledTable));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("RefurbishedReport_" + contractor, ".xls", file);
    m.finish();
    return result;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) File(java.io.File)

Example 35 with UniqueUnit

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

the class ReceiptGeneratorOperationIT method testMakeProductSpecsAndUniqueUnits.

@Test
public void testMakeProductSpecsAndUniqueUnits() throws Exception {
    List<ProductSpec> specs = receiptGenerator.makeProductSpecs(20, true);
    assertThat(specs).as("Generated ProductSpecs").isNotEmpty().hasSize(20);
    for (ProductSpec spec : specs) {
        assertThat(spec.getId()).as("ProductSpec.id").isGreaterThan(0);
        assertThat(spec.getProductId()).as("ProductSpec.productId").isGreaterThan(0);
        Product product = productEao.findById(spec.getProductId());
        assertThat(product).as("uniqueunit.Product of spec.ProductSpec").isNotNull();
    }
    List<UniqueUnit> uniqueunits = receiptGenerator.makeUniqueUnits(20, true, true);
    assertThat(uniqueunits).as("Generated UniqueUnits").isNotEmpty().hasSize(20);
    for (UniqueUnit uniqueunit : uniqueunits) {
        assertThat(uniqueunit.getId()).as("UniqueUnit.id").isGreaterThan(0);
        StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uniqueunit.getId());
        assertThat(stockUnit).describedAs("StockUnit of generated UniqueUnit").isNotNull();
        assertThat(stockUnit.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
    }
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test)

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