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;
}
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;
}
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();
}
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;
}
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()));
}
Aggregations