Search in sources :

Example 61 with UniqueUnit

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

the class AuditReporterOperation method onRollIn.

/**
 * Returns an audit report of units which are input between the dates.
 * <p/>
 * @return an audit report of units which are input between the dates.
 */
@Override
public FileJacket onRollIn() {
    SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
    m.message("loading UniqueUnits");
    m.start();
    List<StockTransaction> rollInTransactions = new StockTransactionEao(stocks.getEntityManager()).findByTypeAndStatus(StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    List<Integer> uuIds = toUniqueUnitIds(rollInTransactions);
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findByIds(uuIds);
    m.worked(5, "preparing Document");
    List<Object[]> rows = new ArrayList<>();
    for (UniqueUnit uu : uniqueUnits) {
        rows.add(new Object[] { uu.getRefurbishId(), uu.getProduct().getGroup().getNote(), uu.getProduct().getPartNo(), uu.getSerial(), ProductFormater.toName(uu.getProduct()), uu.getContractor(), UniqueUnitFormater.toSingleLineAccessories(uu), UniqueUnitFormater.toSingleLineComment(uu), UniqueUnitFormater.toSingleLineInternalComment(uu), uu.getCondition().getNote(), uu.getShipmentLabel(), uu.getProduct().getDescription(), "" });
    }
    CSheet sheet = new CSheet("Audit");
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("SopoNr", 7)).add(new STableColumn("Warengruppe", 13)).add(new STableColumn("ArtikelNr", 15)).add(new STableColumn("Seriennummer", 27));
    table.add(new STableColumn("Name", 30)).add(new STableColumn("Lieferant", 12)).add(new STableColumn("Zubehör", 50)).add(new STableColumn("Bemerkung", 50));
    table.add(new STableColumn("Interne Bemerkung", 30)).add(new STableColumn("Zustand", 12)).add(new STableColumn("Shipment", 12)).add(new STableColumn("Beschreibung", 50));
    table.setModel(new STableModelList(rows));
    sheet.addBelow(table);
    CCalcDocument document = new TempCalcDocument();
    document.add(sheet);
    FileJacket fj = new FileJacket("Audit", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document));
    m.finish();
    return fj;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ArrayList(java.util.ArrayList) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) CSheet(eu.ggnet.lucidcalc.CSheet) 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) CBorder(eu.ggnet.lucidcalc.CBorder) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 62 with UniqueUnit

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

the class AuditReporterOperation method byRange.

/**
 * Returns an audit report of units which are on a roll in transaction, but not yet rolled in.
 * <p/>
 * @return an audit report of units which are on a roll in transaction, but not yet rolled in.
 */
@Override
public FileJacket byRange(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
    m.message("loading UniqueUnits");
    m.start();
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findBetweenInputDates(start, end);
    m.worked(5, "preparing Document");
    List<Object[]> rows = new ArrayList<>();
    for (UniqueUnit uu : uniqueUnits) {
        rows.add(new Object[] { uu.getRefurbishId(), uu.getProduct().getGroup().getNote(), uu.getProduct().getPartNo(), uu.getSerial(), ProductFormater.toName(uu.getProduct()), uu.getContractor(), UniqueUnitFormater.toSingleLineAccessories(uu), UniqueUnitFormater.toSingleLineComment(uu), UniqueUnitFormater.toSingleLineInternalComment(uu), uu.getCondition().getNote(), uu.getShipmentLabel(), uu.getProduct().getDescription(), "" });
    }
    CSheet sheet = new CSheet("Audit");
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("SopoNr", 7)).add(new STableColumn("Warengruppe", 13)).add(new STableColumn("ArtikelNr", 15)).add(new STableColumn("Seriennummer", 27));
    table.add(new STableColumn("Name", 30)).add(new STableColumn("Lieferant", 12)).add(new STableColumn("Zubehör", 50)).add(new STableColumn("Bemerkung", 50));
    table.add(new STableColumn("Interne Bemerkung", 30)).add(new STableColumn("Zustand", 12)).add(new STableColumn("Shipment", 12)).add(new STableColumn("Beschreibung", 50));
    table.setModel(new STableModelList(rows));
    sheet.addBelow(table);
    CCalcDocument document = new TempCalcDocument();
    document.add(sheet);
    FileJacket fj = new FileJacket("Audit", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document));
    m.finish();
    return fj;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ArrayList(java.util.ArrayList) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) 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) CBorder(eu.ggnet.lucidcalc.CBorder)

Example 63 with UniqueUnit

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

the class ResolveRepaymentBeanIT method testResolve.

@Test
public void testResolve() throws UserInfoException {
    List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
    assertThat(allStocks).isNotEmpty().hasSize(2);
    Stock activeStock = allStocks.get(0);
    assertThat(customerGenerator.makeCustomers(10)).isNotEmpty();
    assertThat(receiptGenerator.makeUniqueUnits(200, true, true)).isNotEmpty();
    assertThat(redTapeGenerator.makeSalesDossiers(30)).isNotEmpty();
    final TradeName TRADE_NAME = ACER;
    assertThat(TRADE_NAME.isManufacturer()).isTrue();
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(1, true, true);
    UniqueUnit uu = uus.get(0);
    uu = helper.changeContractors(uu.getId(), TRADE_NAME);
    String refurbishId = uu.getRefurbishId();
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    // order oder direct invoice
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    // Create Positions
    doc.append(Position.builder().type(UNIT).amount(1).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(uu.getPrice(CUSTOMER)).tax(doc.getSingleTax()).name(uu.getProduct().getName() + " | SN:" + uu.getSerial()).description(uu.getProduct().getDescription()).refurbishedId(refurbishId).build());
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu.getRefurbishId());
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeWorker.update(doc, null, "JUnit");
    // Now create an annulation Invoice
    doc.setType(ANNULATION_INVOICE);
    // ArrayList<Position> positions = new ArrayList<>();
    for (Position value : doc.getPositions().values()) {
        // if ( value.getType() == UNIT ) positions.add(value);
        value.setPrice(value.getPrice() * -1);
    }
    redTapeWorker.update(doc, activeStock.getId(), "JUnit Test");
    // Closing the Day. Creating report lines.
    redTapeCloser.executeManual("JUnitTest");
    // Ensure, that we have a Mirror Dossier on the repaymentcustomers.
    List<Dossier> repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
    assertThat(repaymentDossiers).as("RepaymentDossiers").isNotEmpty();
    Dossier repaymentDossier = repaymentDossiers.get(0);
    List<Document> activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
    assertThat(activeDocuments).isNotEmpty();
    assertThat(activeDocuments.get(0).getPositions(UNIT)).isNotEmpty();
    Report report = new Report("Test", TRADE_NAME, new Date(), new Date());
    List<ReportLine> reportLines = reportLineEao.findAll();
    List<Storeable> arrayList = new ArrayList<>();
    reportLines.stream().filter((line) -> (line.getDocumentType() == INVOICE)).forEach((line) -> {
        arrayList.add(line.toStorable());
    });
    report = reportAgent.store(report, arrayList);
    assertThat(report).isNotNull();
    assertThat(report.getLines()).isNotEmpty();
    List<ReportLine> notReported = report.getLines().stream().filter((l) -> reportLines.contains(l)).collect(Collectors.toList());
    final int uuId = uu.getId();
    ReportLine lineToUniqueUnit = notReported.stream().filter((line) -> line.getUniqueUnitId() == uuId).collect(Collectors.toList()).get(0);
    assertThat(lineToUniqueUnit).isNotNull();
    List<ReportLine> repaymentLines = bean.getRepaymentLines(lineToUniqueUnit.getContractor());
    ReportLine repaymentLine = repaymentLines.stream().filter((l) -> l.getRefurbishId().equals(refurbishId)).collect(Collectors.toList()).get(0);
    assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNotEmpty();
    // Resolving of the Unit.
    bean.resolveUnit(refurbishId, TRADE_NAME, "JUnit", "JUnit");
    List<Report> reports = reportAgent.findAll(Report.class);
    assertThat(reports).hasSize(2);
    Report repaymentReport = null;
    // Try to get Report with the Name that is generated in a Static method inside the ResolveRepaymentBean.
    if (reports.get(0).getName().equals(ResolveRepaymentBean.toReportName(TRADE_NAME)))
        repaymentReport = reports.get(0);
    else
        repaymentReport = reports.get(1);
    repaymentReport = reportAgent.findByIdEager(Report.class, repaymentReport.getId());
    assertThat(repaymentReport.getLines()).hasSize(1);
    assertThat(repaymentLines).contains(repaymentLine);
    // Ensure, that we the mirror Dossier has be cleared of the unit
    repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
    assertThat(repaymentDossiers).isNotEmpty();
    repaymentDossier = repaymentDossiers.get(0);
    activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
    assertThat(activeDocuments).isNotEmpty();
    assertThat(activeDocuments.get(0).getPositions(UNIT)).isEmpty();
    // We still should have comments there.
    assertThat(activeDocuments.get(0).getPositions(PositionType.COMMENT)).isNotEmpty();
    assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNullOrEmpty();
}
Also used : java.util(java.util) StockGeneratorOperation(eu.ggnet.dwoss.stock.ee.assist.gen.StockGeneratorOperation) Arquillian(org.jboss.arquillian.junit.Arquillian) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) 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) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) CUSTOMER(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CUSTOMER) RedTapeCloser(eu.ggnet.dwoss.redtapext.ee.reporting.RedTapeCloser) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) ResolveRepayment(eu.ggnet.dwoss.misc.ee.ResolveRepayment) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DocumentType(eu.ggnet.dwoss.rules.DocumentType) Report(eu.ggnet.dwoss.report.ee.entity.Report) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) RedTapeGeneratorOperation(eu.ggnet.dwoss.redtapext.ee.gen.RedTapeGeneratorOperation) EJB(javax.ejb.EJB) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) RepaymentCustomers(eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ReportAgent(eu.ggnet.dwoss.report.ee.ReportAgent) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) ACER(eu.ggnet.dwoss.rules.TradeName.ACER) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) RedTapeAgent(eu.ggnet.dwoss.redtape.ee.RedTapeAgent) ResolveRepaymentBean(eu.ggnet.dwoss.misc.ee.ResolveRepaymentBean) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Report(eu.ggnet.dwoss.report.ee.entity.Report) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 64 with UniqueUnit

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

the class ResolveRepaymentBeanITHelper method changeContractors.

public UniqueUnit changeContractors(int uniqueUnitID, TradeName name) {
    UniqueUnit uu = uniqueUniteao.findById(uniqueUnitID);
    uu.fetchEager();
    uu.setContractor(name);
    return uu;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 65 with UniqueUnit

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

the class UniqueUnitEaoFindsIT method testFinds.

/**
 * Multiple tests on find.
 *
 * @throws Exception
 */
@Test
public void testFinds() throws Exception {
    Product p = new Product(ProductGroup.MONITOR, TradeName.FUJITSU, PARTNO_1, "The Notebook");
    UniqueUnitEao eao = new UniqueUnitEao(em);
    UniqueUnit unit1 = new UniqueUnit();
    unit1.setMfgDate(new Date());
    unit1.setIdentifier(SERIAL, "ROFFFLAASSS");
    unit1.setIdentifier(REFURBISHED_ID, "22223");
    unit1.setContractor(TradeName.ONESELF);
    unit1.setCondition(Condition.AS_NEW);
    unit1.setProduct(p);
    UniqueUnit unit2 = new UniqueUnit();
    unit2.setIdentifier(SERIAL, "FASREAGFSGSWE");
    unit2.setIdentifier(REFURBISHED_ID, "54422");
    unit2.setContractor(TradeName.ONESELF);
    unit2.setCondition(Condition.AS_NEW);
    unit2.setProduct(p);
    UniqueUnit unit3 = new UniqueUnit();
    unit3.setIdentifier(SERIAL, "FHASKHFUAERHFAGTQ5");
    unit3.setIdentifier(REFURBISHED_ID, "33323");
    unit3.setContractor(TradeName.ONESELF);
    unit3.setCondition(Condition.AS_NEW);
    unit3.setProduct(p);
    UniqueUnit unit4 = new UniqueUnit();
    unit4.setIdentifier(SERIAL, "GFSKLFDIACVHDAIERQ");
    unit4.setIdentifier(REFURBISHED_ID, "54142");
    unit4.setContractor(TradeName.ONESELF);
    unit4.setCondition(Condition.AS_NEW);
    unit4.setProduct(p);
    UniqueUnit unit5 = new UniqueUnit();
    unit5.setIdentifier(SERIAL, "FDALOIFUOWE");
    unit5.setIdentifier(REFURBISHED_ID, "29471");
    unit5.setContractor(TradeName.ONESELF);
    unit5.setCondition(Condition.AS_NEW);
    unit5.setProduct(p);
    Set<ConstraintViolation<UniqueUnit>> validate = Validation.buildDefaultValidatorFactory().getValidator().validate(unit1);
    assertTrue(ConstraintViolationFormater.toMultiLine(new HashSet<>(validate), true), validate.isEmpty());
    utx.begin();
    em.joinTransaction();
    em.persist(p);
    em.persist(unit1);
    em.persist(unit2);
    em.persist(unit3);
    em.persist(unit4);
    em.persist(unit5);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    assertThat(eao.findByIdentifier(REFURBISHED_ID, "22223").getId()).as("Id of Unit1 via findByIdentifier 22223").isEqualTo(unit1.getId());
    assertThat(eao.findByIdentifier(REFURBISHED_ID, "54422").getId()).as("Id of Unit2 via findByIdentifier 54422").isEqualTo(unit2.getId());
    assertThat(eao.findByPartialIdentifier(REFURBISHED_ID, "54*")).as("Result of 54* should contation unit2 and unit4").contains(unit2, unit4);
    assertThat(eao.findByPartialIdentifier(REFURBISHED_ID, "*22*")).as("Result of *22* should contation unit1 and unit2").contains(unit1, unit2);
    assertThat(eao.countFind("*5*")).as("Counting *5*").isEqualTo(3);
    assertThat(eao.find("*5*")).as("Find of *5*").contains(unit2, unit3, unit4);
    utx.commit();
    SearchProvider search = null;
    for (Iterator<SearchProvider> iterator = searchProviders.iterator(); iterator.hasNext(); ) {
        SearchProvider next = iterator.next();
        if (next.getSource() == UNIQUE_UNIT)
            search = next;
    }
    assertThat(search.estimateMaxResults(new SearchRequest("*5*"))).as("Counting via Searchprovider *5*").isEqualTo(3);
    assertThat(search.search(new SearchRequest("*5*"), 0, 1000)).as("Find of *5*").extracting(ShortSearchResult::getKey).contains(new GlobalKey(GlobalKey.Component.UNIQUE_UNIT, unit2.getId()), new GlobalKey(GlobalKey.Component.UNIQUE_UNIT, unit3.getId()), new GlobalKey(GlobalKey.Component.UNIQUE_UNIT, unit4.getId()));
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) ConstraintViolation(javax.validation.ConstraintViolation) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) 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