Search in sources :

Example 1 with JExcelLucidCalcReader

use of eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader 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 2 with JExcelLucidCalcReader

use of eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader in project dwoss by gg-net.

the class ExporterOperation method toXlsByXls.

/**
 * Creates a price compare sheet, expects an xls file with the first column filed with partNos.
 *
 * @param inFile the infile
 * @return the price compare xls outfile.
 */
@Override
public FileJacket toXlsByXls(FileJacket inFile) {
    File f = inFile.toTemporaryFile();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    List<String> partNos = new ArrayList<>();
    List<List<? extends Object>> readXls = reader.read(f);
    for (List<? extends Object> list : readXls) {
        if (list == null || list.isEmpty())
            continue;
        partNos.add(list.get(0).toString());
    }
    return toXls(partNos.toArray(new String[0]));
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) File(java.io.File)

Example 3 with JExcelLucidCalcReader

use of eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader in project dwoss by gg-net.

the class ImageIdHandlerOperation method importMissing.

@Override
public Reply<Void> importMissing(FileJacket inFile) {
    final SubMonitor m = monitorFactory.newSubMonitor("Image Ids importieren", 100);
    m.message("Reading File");
    m.start();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class);
    reader.addColumn(1, String.class);
    reader.addColumn(2, String.class);
    reader.addColumn(3, String.class);
    reader.addColumn(4, Integer.class);
    reader.setHeadline(true);
    reader.setTrim(true);
    File f = inFile.toTemporaryFile();
    List<ImageIdLine> lines = reader.read(f, ImageIdLine.class);
    List<String> errors = reader.getErrors();
    ProductEao productEao = new ProductEao(uuEm);
    m.message("Importing Data");
    m.setWorkRemaining(lines.size());
    for (ImageIdLine line : lines) {
        m.worked(1, "importing " + line.getPartNo());
        if (line.getImageId() == null) {
            errors.add("No ImageId for " + line.getPartNo());
            continue;
        }
        Product p = productEao.findByPartNo(line.getPartNo());
        if (p != null) {
            p.setImageId(line.getImageId());
        } else {
            errors.add("No Product for '" + line.getPartNo() + "'");
        }
    }
    m.finish();
    if (!errors.isEmpty())
        return Reply.failure(errors.toString());
    return Reply.success(null);
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) File(java.io.File)

Example 4 with JExcelLucidCalcReader

use of eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader in project dwoss by gg-net.

the class StockTakingOperation method xlsToList.

ReaderResult xlsToList(FileJacket inFile) {
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class);
    reader.setHeadline(true);
    reader.setTrim(true);
    File f = inFile.toTemporaryFile();
    return new ReaderResult(reader.read(f), reader.getErrors());
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) File(java.io.File)

Example 5 with JExcelLucidCalcReader

use of eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader in project dwoss by gg-net.

the class ImporterOperation method fromXls.

/**
 * Imports the Pricemanagement from an XLS file with a defined form.
 * The Form is as follows
 * <ul>
 * <li>Column 1 (A) = Refurbished Id, Type:Integer</li>
 * <li>Column 2 (C) = Manufacturer PartNo, Type:String</li>
 * <li>Column 4 (E) = Retailer Price, Type:Double</li>
 * <li>Column 7 (H) = Customer Price without Tax, Type:Double</li>
 * <li>Column 9 (J) = Set/Unset PartNoFixed Price, Type:Integer</li>
 * <li>Column 10 (K) = Warranty Id, Type:Integer</li>
 * </ul>
 *
 * @param jacket  the file in a jacket
 * @param arranger
 * @return a Reply of FileJacket
 * @throws UserInfoException
 */
@Override
public Reply<File> fromXls(FileJacket jacket, String arranger) throws UserInfoException {
    final SubMonitor m = monitorFactory.newSubMonitor("Import from Xls", 10);
    m.start();
    File f = jacket.toTemporaryFile();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    // RefurbishedId
    reader.addColumn(0, String.class);
    // PartNo
    reader.addColumn(2, String.class);
    // RetailerPrice
    reader.addColumn(4, Double.class);
    // CustomerPrice
    reader.addColumn(7, Double.class);
    // UnitFixPrice
    reader.addColumn(9, Integer.class);
    // PartFixPrice
    reader.addColumn(10, Integer.class);
    // WarrantyId
    reader.addColumn(11, Integer.class);
    List<PriceEngineResult> imports = reader.read(f, new PriceEngineResult());
    m.worked(2);
    if (reader.isError()) {
        m.finish();
        throw new UserInfoException(reader.getErrors());
    }
    core.store(imports, "ImportPriceManagementOperation.fromXls()", arranger, m);
    return Reply.success(f);
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) File(java.io.File)

Aggregations

JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)7 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)4 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)4 LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)4 File (java.io.File)4 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)3 CustomerGeneratorOperation (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation)1 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)1 ReceiptGeneratorOperation (eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation)1 eu.ggnet.dwoss.redtape.ee.entity (eu.ggnet.dwoss.redtape.ee.entity)1 RedTapeWorker (eu.ggnet.dwoss.redtapext.ee.RedTapeWorker)1 UnitOverseer (eu.ggnet.dwoss.redtapext.ee.UnitOverseer)1 CreditMemoReporter (eu.ggnet.dwoss.redtapext.ee.reporting.CreditMemoReporter)1 ArquillianProjectArchive (eu.ggnet.dwoss.redtapext.op.itest.support.ArquillianProjectArchive)1 NaivBuilderUtil (eu.ggnet.dwoss.redtapext.op.itest.support.NaivBuilderUtil)1 SupportBean (eu.ggnet.dwoss.redtapext.op.itest.support.SupportBean)1 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)1 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)1 DocumentType (eu.ggnet.dwoss.rules.DocumentType)1 PRODUCT_BATCH (eu.ggnet.dwoss.rules.PositionType.PRODUCT_BATCH)1